Removing troubleshooting artifacts
This commit is contained in:
@@ -313,37 +313,87 @@ _bl_dirty_since = None
|
|||||||
_BL_SAVE_DELAY_MS = 5000
|
_BL_SAVE_DELAY_MS = 5000
|
||||||
|
|
||||||
|
|
||||||
def set_backlight_color(i, r, g, b, brightness):
|
def _backlight_changed(gauge_idx, new_color, new_on, new_brightness):
|
||||||
backlight_color[i] = (r, g, b)
|
return (
|
||||||
backlight_brightness[i] = brightness
|
new_color != backlight_color[gauge_idx]
|
||||||
backlight_on[i] = True
|
or new_on != backlight_on[gauge_idx]
|
||||||
_update_backlight(i)
|
or (new_on and new_brightness != backlight_brightness[gauge_idx])
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def set_backlight_brightness(i, brightness):
|
def _mark_bl_dirty():
|
||||||
backlight_brightness[i] = brightness
|
global _bl_dirty_since
|
||||||
backlight_on[i] = brightness > 0
|
_bl_dirty_since = utime.ticks_ms()
|
||||||
_update_backlight(i)
|
|
||||||
|
|
||||||
|
|
||||||
def set_status_led(i, color, state):
|
def set_backlight_color(gauge_idx, r, g, b, brightness=None):
|
||||||
if color == "red":
|
global backlight_color, backlight_brightness, backlight_on
|
||||||
status_led_red[i] = state
|
if brightness is None:
|
||||||
idx = i * (BACKLIGHT_LEDS_PER_GAUGE + STATUS_LEDS_PER_GAUGE) + BACKLIGHT_LEDS_PER_GAUGE
|
brightness = backlight_brightness[gauge_idx]
|
||||||
else:
|
new_on = brightness > 0
|
||||||
status_led_green[i] = state
|
if not _backlight_changed(gauge_idx, (r, g, b), new_on, brightness):
|
||||||
idx = i * (BACKLIGHT_LEDS_PER_GAUGE + STATUS_LEDS_PER_GAUGE) + BACKLIGHT_LEDS_PER_GAUGE + 1
|
return
|
||||||
leds_bl[idx] = (255 if state else 0, 0, 0) if color == "red" else (0, 255 if state else 0, 0)
|
backlight_color[gauge_idx] = (r, g, b)
|
||||||
leds_bl.write()
|
if brightness > 0:
|
||||||
|
backlight_brightness[gauge_idx] = brightness
|
||||||
|
backlight_on[gauge_idx] = new_on
|
||||||
|
|
||||||
|
scale = brightness / 100
|
||||||
def _update_backlight(i):
|
leds_per_gauge = BACKLIGHT_LEDS_PER_GAUGE + STATUS_LEDS_PER_GAUGE
|
||||||
r, g, b = backlight_color[i]
|
base_idx = gauge_idx * leds_per_gauge
|
||||||
br = backlight_brightness[i]
|
|
||||||
scaled_br = (br * 255 + 127) // 100
|
|
||||||
base = i * (BACKLIGHT_LEDS_PER_GAUGE + STATUS_LEDS_PER_GAUGE)
|
|
||||||
for j in range(BACKLIGHT_LEDS_PER_GAUGE):
|
for j in range(BACKLIGHT_LEDS_PER_GAUGE):
|
||||||
leds_bl[base + j] = (g if j < 2 else b, r if j < 1 else g, b)
|
leds_bl[base_idx + j] = (int(g * scale), int(r * scale), int(b * scale))
|
||||||
|
_update_status_leds(gauge_idx)
|
||||||
|
leds_bl.write()
|
||||||
|
_mark_bl_dirty()
|
||||||
|
|
||||||
|
|
||||||
|
def set_backlight_brightness(gauge_idx, brightness):
|
||||||
|
global backlight_brightness, backlight_on
|
||||||
|
clamped = max(0, min(100, brightness))
|
||||||
|
new_on = clamped > 0
|
||||||
|
if not _backlight_changed(gauge_idx, backlight_color[gauge_idx], new_on, clamped):
|
||||||
|
return
|
||||||
|
if clamped > 0:
|
||||||
|
backlight_brightness[gauge_idx] = clamped
|
||||||
|
backlight_on[gauge_idx] = new_on
|
||||||
|
r, g, b = backlight_color[gauge_idx]
|
||||||
|
scale = clamped / 100
|
||||||
|
leds_per_gauge = BACKLIGHT_LEDS_PER_GAUGE + STATUS_LEDS_PER_GAUGE
|
||||||
|
base_idx = gauge_idx * leds_per_gauge
|
||||||
|
for j in range(BACKLIGHT_LEDS_PER_GAUGE):
|
||||||
|
leds_bl[base_idx + j] = (int(g * scale), int(r * scale), int(b * scale))
|
||||||
|
_update_status_leds(gauge_idx)
|
||||||
|
leds_bl.write()
|
||||||
|
_mark_bl_dirty()
|
||||||
|
|
||||||
|
|
||||||
|
def _update_status_leds(gauge_idx):
|
||||||
|
leds_per_gauge = BACKLIGHT_LEDS_PER_GAUGE + STATUS_LEDS_PER_GAUGE
|
||||||
|
base_idx = gauge_idx * leds_per_gauge + BACKLIGHT_LEDS_PER_GAUGE
|
||||||
|
|
||||||
|
g_cfg = gauges[gauge_idx]
|
||||||
|
red_color = g_cfg["ws2812_red"]
|
||||||
|
green_color = g_cfg["ws2812_green"]
|
||||||
|
|
||||||
|
if status_led_red[gauge_idx]:
|
||||||
|
leds_bl[base_idx] = (red_color[1], red_color[0], red_color[2])
|
||||||
|
else:
|
||||||
|
leds_bl[base_idx] = (0, 0, 0)
|
||||||
|
|
||||||
|
if status_led_green[gauge_idx]:
|
||||||
|
leds_bl[base_idx + 1] = (green_color[1], green_color[0], green_color[2])
|
||||||
|
else:
|
||||||
|
leds_bl[base_idx + 1] = (0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
def set_status_led(gauge_idx, led_type, state):
|
||||||
|
global status_led_red, status_led_green
|
||||||
|
if led_type == "red":
|
||||||
|
status_led_red[gauge_idx] = state
|
||||||
|
elif led_type == "green":
|
||||||
|
status_led_green[gauge_idx] = state
|
||||||
|
_update_status_leds(gauge_idx)
|
||||||
leds_bl.write()
|
leds_bl.write()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user