static void
performPeriodicTask(void)
{
t_cnt++;
if (t_cnt == 5) {
load_state_ON;
}
if (t_cnt == 10) {
load_state_OFF;
t_cnt=0;
}
if (load_state == ON) {
RelayONOff(1);
} else if (load_state == OFF) {
RelayONOff(0);
}
}
YiKai Chen:
你的程序不用這個複雜吧,直接用osal_start_timerEx 開個週期性(周期为1s)事件去控制继电器控制灯开关就好了不是
user5995095:
回复 YiKai Chen:
osal_start_timerEx 我也用过,但是发现没反应啊,后来用的osal_start_reload_timer开的定时器
user5995095:
回复 YiKai Chen:
if (events & SBP_START_DEVICE_EVT) {// Start the DeviceVOID GAPRole_StartDevice(&simpleBLEPeripheral_PeripheralCBs);
// Start Bond ManagerVOID GAPBondMgr_Register(&simpleBLEPeripheral_BondMgrCBs);
// Set timer for first periodic eventosal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT,SBP_PERIODIC_EVT_PERIOD );
//osal_start_reload_timer(//simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD);return (events ^ SBP_START_DEVICE_EVT);}
if (events & SBP_PERIODIC_EVT) {osal_start_reload_timer(simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD);performPeriodicTask();
return (events ^ SBP_PERIODIC_EVT);}
YiKai Chen:
回复 user5995095:
osal_start_timerEx 我也用过,但是发现没反应啊把你的程序貼上來看看
YiKai Chen:
回复 YiKai Chen:
先查一下你的performPeriodicTask是不是每秒被觸發一次
user5995095:
回复 YiKai Chen:
我用io口取反的方式试了,并不是一秒一次,正常几次之后机会来几下不正常的
user5995095:
回复 user5995095:
if (events & SBP_PERIODIC_EVT) {
osal_start_timerEx(simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD);performPeriodicTask();
return (events ^ SBP_PERIODIC_EVT);}static void
performPeriodicTask(void)
{
t_cnt++;if (t_cnt == 5) {
load_state_ON;
}if (t_cnt == 10) {
load_state_OFF;
t_cnt=0;
}if (load_state == ON) {
RelayONOff(1);
} else if (load_state == OFF) {
RelayONOff(0);
}}
user5995095:
回复 YiKai Chen:
if (events & SBP_PERIODIC_EVT) {
osal_start_timerEx(simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD);
performPeriodicTask();return (events ^ SBP_PERIODIC_EVT);
}static void
performPeriodicTask(void)
{
t_cnt++;if (t_cnt == 5) {
load_state_ON;
}if (t_cnt == 10) {
load_state_OFF;
t_cnt=0;
}if (load_state == ON) {
RelayONOff(1);
} else if (load_state == OFF) {
RelayONOff(0);
}}