summaryrefslogtreecommitdiffstats
path: root/r503.c
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2025-05-07 16:41:16 +0800
committerSadeep Madurange <sadeep@asciimx.com>2025-05-07 16:41:16 +0800
commitdfbbdeb6d5564ed812895542cf9acd40fa70bfa4 (patch)
treec5437594ae7f8e9a24f147a16ece773592eb6af1 /r503.c
parentcb47f6fe368a0b3e22291396ef09d770e7364e71 (diff)
downloadavr-fpm-drivers-dfbbdeb6d5564ed812895542cf9acd40fa70bfa4.tar.gz
Scan while breathing.
Diffstat (limited to 'r503.c')
-rw-r--r--r503.c47
1 files changed, 10 insertions, 37 deletions
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)