void lb_process() { if(lb_state == LB_S_WAIT_HIGH && check_timer(&lb_timer)) { // Waiting to go high, and timer is up digitalwrite(LB_LED_PIN, HIGH); start_ms_timer(&lb_timer, 1000); lb_state = LB_S_WAIT_LOW; } if(lb_state == LB_S_WAIT_LOW && check_timer(&lb_timer)) { // Waiting to go high, and timer is up digitalwrite(LB_LED_PIN, LOW); start_ms_timer(&lb_timer, 500); lb_state = LB_S_WAIT_HIGH; } }
void dataLink_process() { u32 i; if(anim_state == ANIM_S_WAIT_EVEN && check_timer(&dataLink_timer)) { // Waiting to light up EVEN for(i=0; i < LEDS; i++) { u32 lidx = i*3; // if( (i % 2) == 0) { pixels[lidx] = ON_COLOR_G; pixels[lidx + 1] = ON_COLOR_R; pixels[lidx + 2] = ON_COLOR_B; // } else { // pixels[lidx] = OFF_COLOR_G; // pixels[lidx + 1] = OFF_COLOR_R; // pixels[lidx + 2] = OFF_COLOR_B; // } } switch_buffers(); start_ms_timer(&dataLink_timer, 1000); anim_state = ANIM_S_WAIT_ODD; } if(anim_state == ANIM_S_WAIT_ODD && check_timer(&dataLink_timer)) { // Waiting to light up ODD for(i=0; i < LEDS; i++) { u32 lidx = i*3; // if( (i % 2) == 0) { pixels[lidx] = OFF_COLOR_G; pixels[lidx + 1] = OFF_COLOR_R; pixels[lidx + 2] = OFF_COLOR_B; // } else { // pixels[lidx] = ON_COLOR_G; // pixels[lidx + 1] = ON_COLOR_R; // pixels[lidx + 2] = ON_COLOR_B; // } } switch_buffers(); start_ms_timer(&dataLink_timer, 1000); anim_state = ANIM_S_WAIT_EVEN; } }
void obsvr_interval(void){ leds_on(LED_RGB_RED); packet_count = 0; uint32_t temp = NRF_RADIO->FREQUENCY; temp = (temp == 2)?26 : ((temp == 26)?80:2); NRF_RADIO->FREQUENCY = temp; NRF_RADIO->DATAWHITEIV = (temp == 2)?37 : ((temp == 26)?38:39); NRF_RADIO->EVENTS_READY = 0UL; NRF_RADIO->TASKS_RXEN = 1UL; start_ms_timer(MS_TIMER1, SINGLE_CALL, RTC_TICKS(SCAN_WINDOW), &obsvr_window); }
/** * @dot * digraph uart_handler_flow { * a [shape = oval, label = "Called with unsigned char pointer as argument"] * b [shape = diamond, label ="Is the received string 'START?"] * c [shape = diamond, label ="Is the received string 'STOP?"] * d [shape = diamond, label ="Is the Scan-Window Timer running?"] * g [shape = box, label ="Start the repetitive timer with duration of scan window "] * e [shape = box, label ="1. Disable the Radio\n2. Stop the Scan-Window Timer\n3. Stop the Scan-Interval Timer"] * f [shape = oval, label ="Return"] * a -> b; * b -> c [label ="false"]; * b -> d [label ="true"]; * c -> e [label ="true"]; * c -> f [label ="false"]; * d -> g [label ="false"]; * d -> f [label ="true"]; * e -> f; * g -> f; * } * @enddot */ static void obsvr_req(uint8_t * ptr){ /* Check if the string starts with 'ST' */ if(strncmp((const char *)ptr,"ST",2)==0){ /* if 'START' is received, start the scan_window repetitive timer */ if(strcmp((const char *)ptr+2,"ART")==0){ if(is_ms_timer_on(MS_TIMER0) == false){ start_ms_timer(MS_TIMER0, REPEATED_CALL, RTC_TICKS(SCAN_INTERVAL), &obsvr_interval); } } /* if 'STOP' is received, disable the Radio and stop both the timers*/ else if(strcmp((const char *)ptr+2,"OP")==0){ NRF_RADIO->EVENTS_DISABLED = 0UL; NRF_RADIO->TASKS_DISABLE = 1UL; while (NRF_RADIO->EVENTS_DISABLED == 0UL); stop_ms_timer(MS_TIMER0); stop_ms_timer(MS_TIMER1); } } }
void ll_start_adv(void){ radio_init(); start_ms_timer(MS_TIMER1, MS_REPEATED_CALL, RTC_TICKS_625(ll_ctx.adv_intvl), adv_intvl_handler); adv_intvl_handler(); }
////////////////////////////////////////////////////////////////////////////////// // Animator ////////////////////////////////////////////////////////////////////////////////// void dataLink_setup() { anim_state = ANIM_S_WAIT_EVEN; start_ms_timer(&dataLink_timer, 50); }
////////////////////////////////////////////////////////////////////////////////// // LED Blinker ////////////////////////////////////////////////////////////////////////////////// void lb_setup() { // LED_Blinker setup pinmode(LB_LED_PIN,OUTPUT); lb_state = LB_S_WAIT_HIGH; start_ms_timer(&lb_timer, 1000); }