/***********************************************************************************
* LOCAL FUNCTIONS
*/
static void appSwitch();
/***********************************************************************************
* @fn appSwitch
*
* @brief Application code for switch application. Puts MCU in
* endless loop to wait for commands from from switch
*
* @param basicRfConfig - file scope variable. Basic RF configuration data
* pTxData - file scope variable. Pointer to buffer for TX
* payload
* appState - file scope variable. Holds application state
*
* @return none
*/
static void appSwitch()
{
halLcdWriteLine(HAL_LCD_LINE_1, "Switch");
halLcdWriteLine(HAL_LCD_LINE_2, "Joystick Push");
halLcdWriteLine(HAL_LCD_LINE_3, "Send Command");
#ifdef ASSY_EXP4618_CC2420
halLcdClearLine(1);
halLcdWriteSymbol(HAL_LCD_SYMBOL_TX, 1);
#endif
pTxData[0] = LIGHT_TOGGLE_CMD;
// Initialize BasicRF
basicRfConfig.myAddr = SWITCH_ADDR;
if(basicRfInit(&basicRfConfig)==FAILED)
{
HAL_ASSERT(FALSE);
}
// Keep Receiver off when not needed to save power
basicRfReceiveOff();
// Main loop
while (TRUE)
{
if( halJoystickPushed() )
{
basicRfSendPacket(LIGHT_ADDR, pTxData, APP_PAYLOAD_LENGTH);//发送数据
// Put MCU to sleep. It will wake up on joystick interrupt
halIntOff();
halMcuSetLowPowerMode(HAL_MCU_LPM_3); // Will turn on global
// interrupt enable
halIntOn();
}
}
}
/***********************************************************************************
* @fn main
*
* @brief This is the main entry of the "Light Switch" application.
* After the application modes are chosen the switch can
* send toggle commands to a light device.
*
* @param basicRfConfig - file scope variable. Basic RF configuration
* data
* appState - file scope variable. Holds application state
*
* @return none
*/
void main(void)
{
uint8 appMode=NONE;
// Config basicRF
basicRfConfig.panId = PAN_ID;
basicRfConfig.channel = RF_CHANNEL;
basicRfConfig.ackRequest = TRUE;
#ifdef SECURITY_CCM
basicRfConfig.securityKey = key;
#endif
// Indicate that device is powered
halLedSet(2);
halLedClear(1);
// Wait for user to press S1 to enter menu
while (halButtonPushed()!=HAL_BUTTON_1);
halMcuWaitMs(350);
halLcdClear();
appSwitch();//按键发送数据
// Role is undefined. This code should not be reached
HAL_ASSERT(FALSE);
}