Removing troubleshooting artifacts
This commit is contained in:
@@ -313,37 +313,87 @@ _bl_dirty_since = None
|
||||
_BL_SAVE_DELAY_MS = 5000
|
||||
|
||||
|
||||
def set_backlight_color(i, r, g, b, brightness):
|
||||
backlight_color[i] = (r, g, b)
|
||||
backlight_brightness[i] = brightness
|
||||
backlight_on[i] = True
|
||||
_update_backlight(i)
|
||||
def _backlight_changed(gauge_idx, new_color, new_on, new_brightness):
|
||||
return (
|
||||
new_color != backlight_color[gauge_idx]
|
||||
or new_on != backlight_on[gauge_idx]
|
||||
or (new_on and new_brightness != backlight_brightness[gauge_idx])
|
||||
)
|
||||
|
||||
|
||||
def set_backlight_brightness(i, brightness):
|
||||
backlight_brightness[i] = brightness
|
||||
backlight_on[i] = brightness > 0
|
||||
_update_backlight(i)
|
||||
def _mark_bl_dirty():
|
||||
global _bl_dirty_since
|
||||
_bl_dirty_since = utime.ticks_ms()
|
||||
|
||||
|
||||
def set_status_led(i, color, state):
|
||||
if color == "red":
|
||||
status_led_red[i] = state
|
||||
idx = i * (BACKLIGHT_LEDS_PER_GAUGE + STATUS_LEDS_PER_GAUGE) + BACKLIGHT_LEDS_PER_GAUGE
|
||||
else:
|
||||
status_led_green[i] = state
|
||||
idx = i * (BACKLIGHT_LEDS_PER_GAUGE + STATUS_LEDS_PER_GAUGE) + BACKLIGHT_LEDS_PER_GAUGE + 1
|
||||
leds_bl[idx] = (255 if state else 0, 0, 0) if color == "red" else (0, 255 if state else 0, 0)
|
||||
leds_bl.write()
|
||||
def set_backlight_color(gauge_idx, r, g, b, brightness=None):
|
||||
global backlight_color, backlight_brightness, backlight_on
|
||||
if brightness is None:
|
||||
brightness = backlight_brightness[gauge_idx]
|
||||
new_on = brightness > 0
|
||||
if not _backlight_changed(gauge_idx, (r, g, b), new_on, brightness):
|
||||
return
|
||||
backlight_color[gauge_idx] = (r, g, b)
|
||||
if brightness > 0:
|
||||
backlight_brightness[gauge_idx] = brightness
|
||||
backlight_on[gauge_idx] = new_on
|
||||
|
||||
|
||||
def _update_backlight(i):
|
||||
r, g, b = backlight_color[i]
|
||||
br = backlight_brightness[i]
|
||||
scaled_br = (br * 255 + 127) // 100
|
||||
base = i * (BACKLIGHT_LEDS_PER_GAUGE + STATUS_LEDS_PER_GAUGE)
|
||||
scale = brightness / 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 + 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()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user