Skip to content

Commit 4f2a4ed

Browse files
committed
Refactor LED deck examples to use WRGB ordering to match packet format
Changed the color type from rgbw to wrgb and reordered parameters to (w, r, g, b) to better reflect the actual data packet structure (0xWWRRGGBB).
1 parent 30bfe06 commit 4f2a4ed

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

examples/color_led_deck/color_led_cycle.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
URI = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')
3232

3333

34-
class rgbw:
35-
def __init__(self, r: int, g: int, b: int, w: int = 0):
34+
class wrgb:
35+
def __init__(self, w: int, r: int, g: int, b: int):
36+
self.w = w
3637
self.r = r
3738
self.g = g
3839
self.b = b
39-
self.w = w
4040

4141

4242
class hsv:
@@ -46,7 +46,7 @@ def __init__(self, h: int, s: int, v: int):
4646
self.v = v
4747

4848

49-
def hsv_to_rgbw(input: hsv) -> rgbw:
49+
def hsv_to_wrgb(input: hsv) -> wrgb:
5050
h, s, v = input.h, input.s / 255.0, input.v / 255.0
5151

5252
if s == 0:
@@ -72,18 +72,18 @@ def hsv_to_rgbw(input: hsv) -> rgbw:
7272
else:
7373
r, g, b = v, p, q
7474

75-
return rgbw(int(r * 255), int(g * 255), int(b * 255), 0)
75+
return wrgb(0, int(r * 255), int(g * 255), int(b * 255))
7676

7777

78-
def cycle_colors(step: int) -> rgbw:
78+
def cycle_colors(step: int) -> wrgb:
7979
h = step % 360
8080
s = 255
8181
v = 255
82-
return hsv_to_rgbw(hsv(h, s, v))
82+
return hsv_to_wrgb(hsv(h, s, v))
8383

8484

85-
def pack_rgbw(input: rgbw) -> int:
86-
"""Pack RGBW values into uint32 format: 0xWWRRGGBB"""
85+
def pack_wrgb(input: wrgb) -> int:
86+
"""Pack WRGB values into uint32 format: 0xWWRRGGBB"""
8787
return (input.w << 24) | (input.r << 16) | (input.g << 8) | input.b
8888

8989

@@ -110,7 +110,7 @@ def thermal_status_callback(timestamp, data, logconf):
110110
log_conf.data_received_cb.add_callback(thermal_status_callback)
111111
log_conf.start()
112112

113-
# Brightness correction: balances luminance across R/G/B/W channels
113+
# Brightness correction: balances luminance across W/R/G/B channels
114114
# Set to 1 (enabled, default) for perceptually uniform colors
115115
# Set to 0 (disabled) for maximum brightness per channel
116116
cf.param.set_value('colorled.brightnessCorr', 1)
@@ -120,12 +120,12 @@ def thermal_status_callback(timestamp, data, logconf):
120120
print('Cycling through colors. Press Ctrl-C to stop.')
121121
while True:
122122
for i in range(0, 360, 1):
123-
color: rgbw = cycle_colors(i)
123+
color: wrgb = cycle_colors(i)
124124
# print(color.r, color.g, color.b)
125-
color_uint32 = pack_rgbw(color)
126-
cf.param.set_value('colorled.rgbw8888', str(color_uint32))
125+
color_uint32 = pack_wrgb(color)
126+
cf.param.set_value('colorled.wrgb8888', str(color_uint32))
127127
time.sleep(0.01)
128128
except KeyboardInterrupt:
129129
print('\nStopping and turning off LED...')
130-
cf.param.set_value('colorled.rgbw8888', '0')
130+
cf.param.set_value('colorled.wrgb8888', '0')
131131
time.sleep(0.1)

examples/color_led_deck/color_led_set.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
URI = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')
3232

3333

34-
class rgbw:
35-
def __init__(self, r: int, g: int, b: int, w: int = 0):
34+
class wrgb:
35+
def __init__(self, w: int, r: int, g: int, b: int):
36+
self.w = w
3637
self.r = r
3738
self.g = g
3839
self.b = b
39-
self.w = w
4040

4141

4242
class rgb:
@@ -47,8 +47,8 @@ def __init__(self, r: int, g: int, b: int):
4747
self.b = b - self.w
4848

4949

50-
def pack_rgbw(input: rgbw | rgb) -> int:
51-
"""Pack RGBW values into uint32 format: 0xWWRRGGBB"""
50+
def pack_wrgb(input: wrgb | rgb) -> int:
51+
"""Pack WRGB values into uint32 format: 0xWWRRGGBB"""
5252
return (input.w << 24) | (input.r << 16) | (input.g << 8) | input.b
5353

5454

@@ -86,24 +86,24 @@ def thermal_status_callback(timestamp, data, logconf):
8686
# Set your desired color here:
8787
# ========================================
8888
# Examples:
89-
# color = rgbw(r=255, g=0, b=0, w=0) # Pure red
90-
# color = rgbw(r=0, g=255, b=0, w=0) # Pure green
91-
# color = rgbw(r=0, g=0, b=255, w=0) # Pure blue
92-
# color = rgbw(r=0, g=0, b=0, w=255) # Pure white LED
93-
# color = rgbw(r=255, g=128, b=0, w=50) # Orange + white
89+
# color = wrgb(w=0, r=255, g=0, b=0) # Pure red
90+
# color = wrgb(w=0, r=0, g=255, b=0) # Pure green
91+
# color = wrgb(w=0, r=0, g=0, b=255) # Pure blue
92+
# color = wrgb(w=255, r=0, g=0, b=0) # Pure white LED
93+
# color = wrgb(w=50, r=255, g=128, b=0) # Orange + white
9494
# color = rgb(r=255, g=255, b=255) # White (auto W extraction)
9595

96-
color = rgbw(r=255, g=0, b=100, w=0)
96+
color = wrgb(w=0, r=255, g=0, b=100)
9797
# ========================================
9898

99-
color_uint32 = pack_rgbw(color)
100-
cf.param.set_value('colorled.rgbw8888', color_uint32)
99+
color_uint32 = pack_wrgb(color)
100+
cf.param.set_value('colorled.wrgb8888', color_uint32)
101101
time.sleep(0.01)
102102
print(f'Setting LED to R={color.r}, G={color.g}, B={color.b}, W={color.w}')
103103
print('Press Ctrl-C to turn off LED and exit.')
104104
while True:
105105
time.sleep(0.1)
106106
except KeyboardInterrupt:
107107
print('\nStopping and turning off LED...')
108-
cf.param.set_value('colorled.rgbw8888', 0)
108+
cf.param.set_value('colorled.wrgb8888', 0)
109109
time.sleep(0.1)

0 commit comments

Comments
 (0)