diff --git a/base_station/src/main.c b/base_station/src/main.c index 927a652..ede4f6e 100644 --- a/base_station/src/main.c +++ b/base_station/src/main.c @@ -11,6 +11,8 @@ #include "debug.h" #endif /* DEBUG */ +volatile uint8_t conn_lost; + int main(void) { uint8_t *rx_raw; @@ -34,6 +36,14 @@ int main(void) // will arrive /* SET(LED_PORT, LED_GREEN_BIT); */ + // Set up TIMER1 + TCNT1 = 0; + SET(TCCR1B, CS12); // Prescaler = 1024 + SET(TIMSK1, TOIE1); // Enable overflow interrupts + ICR1 = 15625; // Interrupt after 0.25s + + sei(); + while (1) { if (nrf24_dataReady()) { memset(rx_raw, 0, sizeof(data_packet_t)); @@ -49,14 +59,26 @@ int main(void) SET(LED_PORT, LED_GREEN_BIT); else CLR(LED_PORT, LED_GREEN_BIT); - } else { - CLR(LED_PORT, LED_GREEN_BIT); - CLR(LED_PORT, LED_BLUE_BIT); + + conn_lost = 0; } } + cli(); + free(rx_data); free(rx_raw); return 0; } + +ISR(TIMER1_OVF_vect) +{ + // Node hasn't responded for a while, turn off all signal LEDs + if (conn_lost == 1) { + CLR(LED_PORT, LED_GREEN_BIT); + CLR(LED_PORT, LED_BLUE_BIT); + } + + conn_lost = 1; +}