Skip to content

Commit

Permalink
untangle color order in fast and fadecandy
Browse files Browse the repository at this point in the history
  • Loading branch information
jabdoa2 committed Mar 11, 2017
1 parent 0efcd87 commit 7be667c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
4 changes: 3 additions & 1 deletion mpf/platforms/fast/fast_led.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def current_color(self):
"""Return current color."""
result = ""
self.dirty = False
for color in self.colors:
# send this as grb because the hardware will twist it again
for index in [1, 0, 2]:
color = self.colors[index]
if callable(color):
brightness, fade_ms = color(self.hardware_fade_ms)
result += hex(int(brightness * 255))[2:].zfill(2)
Expand Down
19 changes: 14 additions & 5 deletions mpf/platforms/openpixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ def tick(self, dt):

self.dirty = False

def _add_pixel(self, msg, max_fade_ms, brightness):
if callable(brightness):
brightness = brightness(max_fade_ms)[0] * 255
brightness = min(255, max(0, int(brightness)))
msg.append(brightness)

def update_pixels(self, pixels, channel=0):
"""Send the list of pixel colors to the OPC server.
Expand All @@ -209,11 +215,14 @@ def update_pixels(self, pixels, channel=0):
len_lo_byte = (len(pixels)) % 256
header = bytes([channel, 0, len_hi_byte, len_lo_byte])
msg.extend(header)
for brightness in pixels:
if callable(brightness):
brightness = brightness(max_fade_ms)[0] * 255
brightness = min(255, max(0, int(brightness)))
msg.append(brightness)
for i in range(int(len(pixels) / 3)):
# send GRB because that is the default color order for WS2812

self._add_pixel(msg, max_fade_ms, pixels[i * 3 + 1])
self._add_pixel(msg, max_fade_ms, pixels[i * 3])
self._add_pixel(msg, max_fade_ms, pixels[i * 3 + 2])


self.send(bytes(msg))

def send(self, message):
Expand Down
4 changes: 3 additions & 1 deletion mpf/tests/machine_files/fast/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,7 @@ lights:
subtype: gi
test_led:
number: 2-23
type: grb
test_led2:
number: 2-25
number: 2-25
type: grb
5 changes: 4 additions & 1 deletion mpf/tests/machine_files/openpixel/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
lights:
test_led:
number: 99
type: grb
test_led2:
number: 0-20
type: grb
test_led3:
number: 1-99
number: 1-99
type: grb

0 comments on commit 7be667c

Please sign in to comment.