Skip to content

Commit

Permalink
aux-led: add a temperature mode in standby
Browse files Browse the repository at this point in the history
Add a temperature mode which can be used to show current (ambient)
temperature during standby using the AUX led.

In this temperature mode, the preview (7H when iterating through
each mode) will blink AUX LED with the current temperature mapping
(and also button LED if there is button LED).
  • Loading branch information
starryalley committed Apr 24, 2021
1 parent 51f906e commit 665e660
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
29 changes: 28 additions & 1 deletion spaghetti-monster/anduril/aux-leds.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ uint8_t voltage_to_rgb() {
return pgm_read_byte(rgb_led_colors + color_num);
}

uint8_t temperature_to_rgb() {
static const uint8_t temp_levels[] = {
// temperature in Celsius, color
0, 5, // 5, R + B =>pink/purple <=12 C
12, 4, // 4, B (12,16] C
16, 3, // 3, G+B =>cyan (16,20] C
20, 2, // 2, G (20,25] C
25, 1, // 1, R+G =>yellow (25,28] C
28, 0, // 0, R >28 C
255, 0, // 0, R
};
int16_t temps = temperature;
if (temps < 0) return 0;

uint8_t i;
for (i = 0; temps >= temp_levels[i]; i += 2) {}
uint8_t color_num = temp_levels[(i - 2) + 1];
return pgm_read_byte(rgb_led_colors + color_num);
}

// do fancy stuff with the RGB aux LEDs
// mode: 0bPPPPCCCC where PPPP is the pattern and CCCC is the color
// arg: time slice number
Expand Down Expand Up @@ -122,7 +142,7 @@ void rgb_led_update(uint8_t mode, uint8_t arg) {
}
actual_color = pgm_read_byte(colors + rainbow);
}
else { // voltage
else if (color == 9) { // voltage
// show actual voltage while asleep...
if (go_to_standby) {
actual_color = voltage_to_rgb();
Expand All @@ -136,6 +156,13 @@ void rgb_led_update(uint8_t mode, uint8_t arg) {
actual_color = pgm_read_byte(colors + (((arg>>1) % 3) << 1));
}
}
else { // temperature
actual_color = temperature_to_rgb();
if (!go_to_standby) {
// during preview, flash current temperature's colors quickly
pattern = (arg >> 1) % 3;
}
}

// pick a brightness from the animation sequence
if (pattern == 3) {
Expand Down
8 changes: 4 additions & 4 deletions spaghetti-monster/anduril/aux-leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ void rgb_led_voltage_readout(uint8_t bright);
* 4: B
* 5: R B
* 6: RGB
* 7: rainbow
* 8: voltage
* 7: disco
* 8: rainbow
* 9: voltage
* 10: temperature
*/
const PROGMEM uint8_t rgb_led_colors[] = {
0b00000001, // 0: red
Expand All @@ -64,8 +66,6 @@ const PROGMEM uint8_t rgb_led_colors[] = {
0b00010001, // 5: purple
0b00010101, // 6: white
};
// intentionally 1 higher than total modes, to make "voltage" easier to reach
// (at Hank's request)
#define RGB_LED_NUM_COLORS 11
#define RGB_LED_NUM_PATTERNS 4
#ifndef RGB_LED_OFF_DEFAULT
Expand Down

0 comments on commit 665e660

Please sign in to comment.