在light_switch-srf05_cc2530的例程中。原本是一个switch控制一个light。
我尝试着增加了switch的个数和对应的light设备个数进行led开关控制。
发现传输距离短了很多。不知道是不是哪里的配置需要做出相应的调整?
下面给出修改后的appSwitch()函数,
static void appSwitch()
{
// halLcdWriteLine(HAL_LCD_LINE_1, "Switch");
// halLcdWriteLine(HAL_LCD_LINE_2, "Joystick Push");
// halLcdWriteLine(HAL_LCD_LINE_3, "Send Command");
int a=0,b=0,c=0,d=0;
InitKeyswi();
#ifdef ASSY_EXP4618_CC2420
halLcdClearLine(1);
halLcdWriteSymbol(HAL_LCD_SYMBOL_TX, 1);
#endif
{
// halLcdWriteLine(HAL_LCD_LINE_1, "Switch");
// halLcdWriteLine(HAL_LCD_LINE_2, "Joystick Push");
// halLcdWriteLine(HAL_LCD_LINE_3, "Send Command");
int a=0,b=0,c=0,d=0;
InitKeyswi();
#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);
}
basicRfConfig.myAddr = SWITCH_ADDR;
if(basicRfInit(&basicRfConfig)==FAILED) {
HAL_ASSERT(FALSE);
}
// Keep Receiver off when not needed to save power
basicRfReceiveOff();
basicRfReceiveOff();
// Main loop
while (TRUE) {
// if( halJoystickPushed() ) { //bu qiujie tech
a=KeyScan1();
b=KeyScan2();
c=KeyScan3();
d=KeyScan4();
if(a){
while (TRUE) {
// if( halJoystickPushed() ) { //bu qiujie tech
a=KeyScan1();
b=KeyScan2();
c=KeyScan3();
d=KeyScan4();
if(a){
basicRfSendPacket(LIGHT_ADDR1, 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();
halIntOff();
halMcuSetLowPowerMode(HAL_MCU_LPM_3); // Will turn on global
// interrupt enable
halIntOn();
}
if(b){
if(b){
basicRfSendPacket(LIGHT_ADDR2, 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();
halIntOff();
halMcuSetLowPowerMode(HAL_MCU_LPM_3); // Will turn on global
// interrupt enable
halIntOn();
}
if(c){
if(c){
basicRfSendPacket(LIGHT_ADDR3, 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();
halIntOff();
halMcuSetLowPowerMode(HAL_MCU_LPM_3); // Will turn on global
// interrupt enable
halIntOn();
}
if(d){
basicRfSendPacket(LIGHT_ADDR1, pTxData, APP_PAYLOAD_LENGTH);
if(d){
basicRfSendPacket(LIGHT_ADDR1, 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();
basicRfSendPacket(LIGHT_ADDR2, pTxData, APP_PAYLOAD_LENGTH);
halIntOff();
halMcuSetLowPowerMode(HAL_MCU_LPM_3); // Will turn on global
// interrupt enable
halIntOn();
basicRfSendPacket(LIGHT_ADDR2, 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();
halIntOff();
halMcuSetLowPowerMode(HAL_MCU_LPM_3); // Will turn on global
// interrupt enable
halIntOn();
basicRfSendPacket(LIGHT_ADDR3, 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();
halIntOff();
halMcuSetLowPowerMode(HAL_MCU_LPM_3); // Will turn on global
// interrupt enable
halIntOn();
}
}
}
}
}