From dfbbdeb6d5564ed812895542cf9acd40fa70bfa4 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Wed, 7 May 2025 16:41:16 +0800 Subject: Scan while breathing. --- r503.c | 47 ++++++++++------------------------------------- 1 file changed, 10 insertions(+), 37 deletions(-) (limited to 'r503.c') diff --git a/r503.c b/r503.c index 500cf5c..25e7560 100644 --- a/r503.c +++ b/r503.c @@ -110,18 +110,19 @@ bad_pkt: return; } -static inline void aura_breathe(COLOR color) +static inline void led_ctrl(uint8_t mode, COLOR color) { uint16_t n; - uint8_t buf[5]; + uint8_t buf[MAXPDLEN]; buf[0] = 0x35; - buf[1] = 0x01; - buf[2] = 0x20; + buf[1] = mode; + buf[2] = 0x40; buf[3] = color; buf[4] = 0x00; send(0x01, buf, 5); + recv(buf, &n); } static inline uint8_t check_pwd(void) @@ -143,12 +144,10 @@ static inline uint8_t check_pwd(void) static inline uint8_t scan(void) { uint16_t n, retries; - uint8_t buf[MAXPDLEN], led; + uint8_t buf[MAXPDLEN]; retries = 0; - fpm_led_on(PURPLE); - led = 1; - _delay_ms(500); + led_ctrl(0x01, PURPLE); do { buf[0] = 0x01; @@ -156,48 +155,22 @@ static inline uint8_t scan(void) recv(buf, &n); if (buf[0] != OK) { retries++; - if (led) { - fpm_led_off(); - led = 0; - } else { - fpm_led_on(PURPLE); - led = 1; - } - _delay_ms(500); + _delay_ms(100); } } while(buf[0] != OK && retries < 100); fpm_led_off(); - led = 0; return buf[0] == OK; } void fpm_led_on(COLOR color) { - uint16_t n; - uint8_t buf[MAXPDLEN]; - - buf[0] = 0x35; - buf[1] = 0x03; - buf[2] = 0x00; - buf[3] = color; - buf[4] = 0x00; - - send(0x01, buf, 5); + led_ctrl(0x03, color); } void fpm_led_off(void) { - uint16_t n; - uint8_t buf[MAXPDLEN]; - - buf[0] = 0x35; - buf[1] = 0x04; - buf[2] = 0x00; - buf[3] = 0x00; - buf[4] = 0x00; - - send(0x01, buf, 5); + led_ctrl(0x04, 0x00); } uint8_t fpm_init(void) -- cgit v1.2.3