Skip to content

Commit

Permalink
update streaming to support RGB, analog, and SK6812 RGBW
Browse files Browse the repository at this point in the history
  • Loading branch information
readmodifywrite committed Mar 30, 2018
1 parent de3f8ff commit 22b1381
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 82 deletions.
25 changes: 16 additions & 9 deletions examples/streaming.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import time
from chromatron import *

MODE = 'hsv'
# MODE = 'rgb'

if __name__ == '__main__':

try:
print "Discovering..."

# query for devices
devices = DeviceGroup('test')
devices = DeviceGroup('motion2')

print "Found %d devices" % (len(devices))

Expand All @@ -17,19 +19,24 @@
# iterate through devices
for d in devices.itervalues():

# set brightness
d.val = 0.25
if MODE == 'hsv':
# set brightness
d.val = 0.25

# set saturated colors
d.sat = 1.0
# set saturated colors
d.sat = 1.0

# set hue
for i in xrange(len(d.hue)):
d.hue[i] += (0.0001 * i)
# set hue
for i in xrange(len(d.hue)):
d.hue[i] += (0.001 * (i + 1))

elif MODE == 'rgb':
d.r = 0.0
d.g = 0.1
d.b = 0.1

# send updated pixel data to devices
devices.update_pixels()
devices.update_pixels(mode=MODE)

time.sleep(0.02)

Expand Down
6 changes: 5 additions & 1 deletion python/catbus/catbus/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ def read_file(self, filename, progress=None):

i = 3
while i > 0:
i -= 1
try:
response, host = self._exchange(msg)

Expand All @@ -469,6 +468,11 @@ def read_file(self, filename, progress=None):

else:
raise

i -= 1

if i == 0:
raise ProtocolErrorException

session_id = response.session_id
requested_offset = 0
Expand Down
61 changes: 52 additions & 9 deletions python/chromatron/chromatron/streamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ def __init__(self, **kwargs):

super(PixelHSVMsg, self).__init__(_name="pixel_hsv_msg", _fields=fields, **kwargs)

# self.count = len(self.pixels)

# assert self.count <= PIXEL_MSG_MAX_LEN

self.type = CHROMA_MSG_TYPE_HSV

CHROMA_MSG_TYPE_RGB = 2
Expand All @@ -81,10 +77,6 @@ def __init__(self, **kwargs):

super(PixelRGBMsg, self).__init__(_name="pixel_rgb_msg", _fields=fields, **kwargs)

# self.count = len(self.pixels)

# assert self.count <= PIXEL_MSG_MAX_LEN

self.type = CHROMA_MSG_TYPE_RGB


Expand Down Expand Up @@ -198,7 +190,6 @@ def __init__(self, *args, **kwargs):
super(RGBArray, self).__init__(*args, **kwargs)



class Streamer(object):
def __init__(self, host=None):
self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Expand Down Expand Up @@ -273,6 +264,58 @@ def update(self):
msg += struct.pack('<%dH' % (len(pixels)), *pixels)

msgs.append(msg)

# rgb mode
elif self.mode == 'rgb':
r = self.arrays['r']
g = self.arrays['g']
b = self.arrays['b']

r._lock()
g._lock()
b._lock()

r_list = r._get_list()
g_list = g._get_list()
b_list = b._get_list()

pixels = []

i = 0
index = 0
for i in xrange(len(r_list)):
pix_r = r_list[i]
pix_g = g_list[i]
pix_b = b_list[i]

# convert to 16 bit integers
pix_r *= 65535
pix_g *= 65535
pix_b *= 65535

pixels.append(int(pix_r))
pixels.append(int(pix_g))
pixels.append(int(pix_b))

if len(pixels) >= PIXEL_MSG_MAX_LEN * 3:
msg = PixelRGBMsg(index=index, count=len(pixels) / 3).pack()
msg += struct.pack('<%dH' % (len(pixels)), *pixels)

msgs.append(msg)
index += (len(pixels) / 3)

pixels = []

r._release()
g._release()
b._release()

# get last message
if len(pixels) >= 3:
msg = PixelRGBMsg(pixels=pixels, index=index, count=len(pixels) / 3).pack()
msg += struct.pack('<%dH' % (len(pixels)), *pixels)

msgs.append(msg)

# transmit!
for msg in msgs:
Expand Down
4 changes: 2 additions & 2 deletions python/chromatron/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
setup(
name='chromatron',

version='1.0.0',
version='1.0.1',

packages=['chromatron',
'chromatron.midi',
Expand All @@ -45,7 +45,7 @@
long_description=open('README.txt').read(),

install_requires=[
"catbus",
"catbus >= 1.0.1",
"crcmod == 1.7",
"click >= 6.6",
"sapphire >= 0.5",
Expand Down
2 changes: 1 addition & 1 deletion src/chromatron/buildnumber.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3710
3715
2 changes: 1 addition & 1 deletion src/chromatron_recovery/buildnumber.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
243
248
2 changes: 1 addition & 1 deletion src/hal/xmega128a4u/buildnumber.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9218
9223
2 changes: 1 addition & 1 deletion src/lib_chromatron/buildnumber.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2977
2982
Loading

0 comments on commit 22b1381

Please sign in to comment.