From ad383a76ac258f0a5734d9f02711c7af04b5d5a4 Mon Sep 17 00:00:00 2001 From: true Date: Wed, 1 Nov 2023 06:05:40 -0700 Subject: [PATCH] Changed error flash routine Need to add other features that involve flashing the error code lights, so made it possible to do this with different colors and without interfering with running programs --- include/rgbprog.h | 5 +++++ src/rgbprog.c | 36 +++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/include/rgbprog.h b/include/rgbprog.h index 9a5b281..60141ee 100644 --- a/include/rgbprog.h +++ b/include/rgbprog.h @@ -8,9 +8,14 @@ #define _INC_RGBPROG_H +#include + + void rgbprog_run(); +void rgbprog_error_flasher(uint8_t r, uint8_t g, uint8_t b); + #endif /* _INC_RGBPROG_H */ \ No newline at end of file diff --git a/src/rgbprog.c b/src/rgbprog.c index a585675..bd135b9 100644 --- a/src/rgbprog.c +++ b/src/rgbprog.c @@ -23,6 +23,8 @@ */ +#include "rgbprog.h" + #include "led.h" #include "hsv2rgb.h" #include "rand.h" @@ -43,8 +45,6 @@ void rgbprog_randcolor(uint8_t k0); void rgbprog_randcolorfadeinout(uint8_t k0); void rgbprog_prog7(uint8_t k0); -void rgbprog_set1_error(); - static void (*proglist[8])(uint8_t) = { rgbprog_rainbow, rgbprog_rainbow_offset, @@ -117,7 +117,7 @@ void rgbprog_run() // if SET1 is out of range, indicate that instead of // running the normal program if (userio_get_set1_limit()) { - rgbprog_set1_error(); + rgbprog_error_flasher(120, 0, 0); return; } @@ -405,20 +405,22 @@ void rgbprog_prog7(uint8_t k0) * * flashes LEDs, indicating a SET1 knob error. */ -void rgbprog_set1_error() +static uint8_t err_ctr; +static uint8_t err_tog = 0; +void rgbprog_error_flasher(uint8_t r, uint8_t g, uint8_t b) { - hsv[1].s++; - if (!hsv[1].s) { - hsv[1].v++; - hsv[1].v &= 1; - hsv[0].v = hsv[1].v ^ 1; - - rgb[0].r = 255; - rgb[0].g = 0; - rgb[0].b = 0; - rgb_setled(hsv[1].v, &rgb[0]); - - rgb[0].r = 0; - rgb_setled(hsv[0].v, &rgb[0]); + err_ctr++; + if (!err_ctr) { + err_tog ^= 1; } + + rgb[0].r = r; + rgb[0].g = g; + rgb[0].b = b; + rgb_setled(err_tog, &rgb[0]); + + rgb[0].r = 0; + rgb[0].g = 0; + rgb[0].b = 0; + rgb_setled(err_tog ^ 1, &rgb[0]); } \ No newline at end of file