aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2019-07-30 20:16:16 -0600
committerSelene ToyKeeper2019-07-30 20:16:16 -0600
commit319fbbcb6de77d26fd5d3e935dea47cd4c12ed07 (patch)
treeab5a7bdf171b6ac8eb4f67674ee075cc0ec58933 /spaghetti-monster
parentfsm-ramping: turn opamp chip on and off automatically based on ramp level (diff)
downloadanduril-319fbbcb6de77d26fd5d3e935dea47cd4c12ed07.tar.gz
anduril-319fbbcb6de77d26fd5d3e935dea47cd4c12ed07.tar.bz2
anduril-319fbbcb6de77d26fd5d3e935dea47cd4c12ed07.zip
anduril: allow RGB LEDs to stay on (in voltage mode) while main LEDs are on
(also, refactored RGB aux LED code a little; moved color table to ROM)
Diffstat (limited to 'spaghetti-monster')
-rw-r--r--spaghetti-monster/anduril/anduril.c61
1 files changed, 46 insertions, 15 deletions
diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c
index 9853878..a82ba4b 100644
--- a/spaghetti-monster/anduril/anduril.c
+++ b/spaghetti-monster/anduril/anduril.c
@@ -310,6 +310,7 @@ void indicator_blink(uint8_t arg);
#endif
#if defined(USE_AUX_RGB_LEDS) && defined(TICK_DURING_STANDBY)
void rgb_led_update(uint8_t mode, uint8_t arg);
+void rgb_led_voltage_readout(uint8_t bright);
/*
* 0: R
* 1: RG
@@ -321,6 +322,15 @@ void rgb_led_update(uint8_t mode, uint8_t arg);
* 7: rainbow
* 8: voltage
*/
+const PROGMEM uint8_t rgb_led_colors[] = {
+ 0b00000001, // 0: red
+ 0b00000101, // 1: yellow
+ 0b00000100, // 2: green
+ 0b00010100, // 3: cyan
+ 0b00010000, // 4: blue
+ 0b00010001, // 5: purple
+ 0b00010101, // 6: white
+};
#define RGB_LED_NUM_COLORS 10
#define RGB_LED_NUM_PATTERNS 4
#ifndef RGB_LED_OFF_DEFAULT
@@ -2269,36 +2279,28 @@ void rgb_led_update(uint8_t mode, uint8_t arg) {
if ((! go_to_standby) && (pattern > 2)) { pattern = 2; }
- uint8_t colors[] = {
- 0b00000001, // 0: red
- 0b00000101, // 1: yellow
- 0b00000100, // 2: green
- 0b00010100, // 3: cyan
- 0b00010000, // 4: blue
- 0b00010001, // 5: purple
- 0b00010101, // 6: white
- };
+ const uint8_t *colors = rgb_led_colors;
uint8_t actual_color = 0;
if (color < 7) { // normal color
- actual_color = colors[color];
+ actual_color = pgm_read_byte(colors + color);
}
else if (color == 7) { // rainbow
if (0 == (arg & 0x03)) {
rainbow = (rainbow + 1) % 6;
}
- actual_color = colors[rainbow];
+ actual_color = pgm_read_byte(colors + rainbow);
}
else { // voltage
// show actual voltage while asleep...
if (go_to_standby) {
// choose a color based on battery voltage
- if (volts >= 38) actual_color = colors[4];
- else if (volts >= 33) actual_color = colors[2];
- else actual_color = colors[0];
+ if (volts >= 38) actual_color = pgm_read_byte(colors + 4);
+ else if (volts >= 33) actual_color = pgm_read_byte(colors + 2);
+ else actual_color = pgm_read_byte(colors + 0);
}
// ... but during preview, cycle colors quickly
else {
- actual_color = colors[((arg>>1) % 3) << 1];
+ actual_color = pgm_read_byte(colors + (((arg>>1) % 3) << 1));
}
}
@@ -2322,6 +2324,31 @@ void rgb_led_update(uint8_t mode, uint8_t arg) {
break;
}
}
+
+void rgb_led_voltage_readout(uint8_t bright) {
+ uint8_t volts = voltage;
+ if (volts < 29) {
+ rgb_led_set(0);
+ }
+ else {
+ uint8_t levels[] = {
+ 30, 0,
+ 33, 1,
+ 35, 2,
+ 37, 3,
+ 39, 4,
+ 40, 5,
+ 255, 6,
+ };
+ uint8_t i;
+ for (i = 0; volts > levels[i]; i += 2) {
+ if (levels[i] >= volts) break;
+ }
+ uint8_t color = pgm_read_byte(rgb_led_colors + i);
+ if (bright) color = color << 1;
+ rgb_led_set(color);
+ }
+}
#endif
@@ -2559,6 +2586,10 @@ void loop() {
StatePtr state = current_state;
+ #ifdef USE_AUX_RGB_LEDS_WHILE_RAMPING
+ rgb_led_voltage_readout(1);
+ #endif
+
if (0) {}
#ifdef USE_STROBE_STATE
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.