From 14d4c6d56c0f999bbd7d8a2331e463192155dc7e Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Thu, 1 May 2025 14:27:06 +0800 Subject: Battery check for front end and increase thresh for backend. --- lock/bend.c | 2 +- lock/fend.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'lock') diff --git a/lock/bend.c b/lock/bend.c index 2c18996..da8f2e6 100644 --- a/lock/bend.c +++ b/lock/bend.c @@ -29,7 +29,7 @@ #define RX_PCMSK PCMSK2 #define RX_PCINTVEC PCINT2_vect -#define VCC_MIN 4810 /* servo min voltage. */ +#define VCC_MIN 4900 #define LOCK_LED PC3 #define UNLOCK_LED PC4 diff --git a/lock/fend.c b/lock/fend.c index 7177e72..39854c6 100644 --- a/lock/fend.c +++ b/lock/fend.c @@ -23,6 +23,14 @@ #define RX_PCMSK PCMSK2 #define RX_PCINTVEC PCINT2_vect +#define VCC_MIN 4000 + +#define LOCK_LED PC3 +#define UNLOCK_LED PC4 +#define BATLOW_LED PC5 +#define LED_DDR DDRC +#define LED_PORT PORTC + static volatile uint8_t rxd = 0; static volatile uint8_t sync = 0; static volatile uint8_t islock = 0; @@ -54,8 +62,19 @@ static inline void init_btns(void) EIMSK = (1 << INT0) | (1 << INT1); } +static inline void init_leds(void) +{ + LED_DDR |= (1 << LOCK_LED) | (1 << UNLOCK_LED); + LED_DDR |= (1 << BATLOW_LED); + + LED_PORT &= ~(1 << LOCK_LED); + LED_PORT &= ~(1 << UNLOCK_LED); + LED_PORT &= ~(1 << BATLOW_LED); +} + int main(void) { + int i; uint8_t rxaddr[ADDRLEN] = { 194, 178, 82 }; uint8_t txaddr[ADDRLEN] = { 194, 178, 83 }; @@ -63,6 +82,7 @@ int main(void) wdt_off(); init_rx(); + init_leds(); init_btns(); uart_init(); @@ -99,6 +119,13 @@ int main(void) } if (!sync) { + if (getvcc() < VCC_MIN) { + for (i = 0; i < 5; i++) { + LED_PORT ^= (1 << BATLOW_LED); + _delay_ms(100); + } + } + radio_pwr_dwn(); sleep_enable(); sleep_bod_disable(); -- cgit v1.2.3