void tdma_error(void) { static uint16_t debounce; debounce++; if(debounce>50) debounce=50; if(debounce==50 ) { if((PIND & 0x1) == 0 ) { debounce=0; if(socket_0_active==1) { plug_led_green_clr(); power_socket_disable(0); } else { plug_led_green_set(); power_socket_enable(0); } } } if(tdma_sync_ok()==0) plug_led_red_set(); else plug_led_red_clr(); }
// This function gets called in a loop if sync is lost. // It is passed a counter indicating how long it has gone since the last synchronization. int8_t tdma_error(uint16_t cons_error_cnt) { // TDMA error handler just controls the LED in this case. // Button is still handled by interrupt if(tdma_sync_ok()==0) plug_led_red_set(); else plug_led_red_clr(); // Return NRK_OK to force the error counter to be reset return NRK_ERROR; }
// This function gets called in a loop if sync is lost. // It is passed a counter indicating how long it has gone since the last synchronization. int8_t tdma_error(uint16_t cons_err_cnt) { if(tdma_sync_ok()==0) nrk_led_set(1); else nrk_led_clr(1); // If there has been enough cycles without sync then snooze if(cons_err_cnt>400) { //nrk_kprintf(PSTR("Entering TDMA snooze...\r\n" )); nrk_wait_until_next_period(); tdma_snooze(); return NRK_OK; } return NRK_ERROR; }
void io_task() { DDRD=0; while(cal_done==0) nrk_wait_until_next_period(); // Crappy polling IO task that reads the button to toggle the outlet while(1) { if(tdma_sync_ok()==0) plug_led_red_set(); else plug_led_red_clr(); if((PIND & 0x1) == 0 ) { if(socket_0_active==1) { plug_led_green_clr(); power_socket_disable(0); } else { plug_led_green_set(); power_socket_enable(0); } // After press, wait until user lets go do { nrk_wait_until_next_period(); } while((PIND & 0x1) == 0 ); } nrk_wait_until_next_period(); } }
void tdma_error() { if(tdma_sync_ok()==0) nrk_led_set(RED_LED); else nrk_led_clr(RED_LED); }