Clear base station signal LEDs if node is offline

This commit is contained in:
Rihards Skuja 2018-01-21 20:27:37 +02:00
parent 1322a84c35
commit b3ce179b66
No known key found for this signature in database
GPG Key ID: 53FA13A3F7F8571B

View File

@ -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;
}