diff --git a/examples/streaming.py b/examples/streaming.py index fda90ed3c..d63d8e64e 100644 --- a/examples/streaming.py +++ b/examples/streaming.py @@ -1,6 +1,8 @@ import time from chromatron import * +MODE = 'hsv' +# MODE = 'rgb' if __name__ == '__main__': @@ -8,7 +10,7 @@ print "Discovering..." # query for devices - devices = DeviceGroup('test') + devices = DeviceGroup('motion2') print "Found %d devices" % (len(devices)) @@ -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) diff --git a/python/catbus/catbus/client.py b/python/catbus/catbus/client.py index 84300d8ac..cdf80a9f0 100644 --- a/python/catbus/catbus/client.py +++ b/python/catbus/catbus/client.py @@ -449,7 +449,6 @@ def read_file(self, filename, progress=None): i = 3 while i > 0: - i -= 1 try: response, host = self._exchange(msg) @@ -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 diff --git a/python/chromatron/chromatron/streamer.py b/python/chromatron/chromatron/streamer.py index 5700ffdd4..c756cc935 100644 --- a/python/chromatron/chromatron/streamer.py +++ b/python/chromatron/chromatron/streamer.py @@ -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 @@ -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 @@ -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) @@ -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: diff --git a/python/chromatron/setup.py b/python/chromatron/setup.py index c8994c80d..2bb5c90e1 100644 --- a/python/chromatron/setup.py +++ b/python/chromatron/setup.py @@ -25,7 +25,7 @@ setup( name='chromatron', - version='1.0.0', + version='1.0.1', packages=['chromatron', 'chromatron.midi', @@ -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", diff --git a/src/chromatron/buildnumber.txt b/src/chromatron/buildnumber.txt index 54776fde4..210523b17 100644 --- a/src/chromatron/buildnumber.txt +++ b/src/chromatron/buildnumber.txt @@ -1 +1 @@ -3710 \ No newline at end of file +3715 \ No newline at end of file diff --git a/src/chromatron_recovery/buildnumber.txt b/src/chromatron_recovery/buildnumber.txt index 104fcf5b4..030d25b28 100644 --- a/src/chromatron_recovery/buildnumber.txt +++ b/src/chromatron_recovery/buildnumber.txt @@ -1 +1 @@ -243 \ No newline at end of file +248 \ No newline at end of file diff --git a/src/hal/xmega128a4u/buildnumber.txt b/src/hal/xmega128a4u/buildnumber.txt index 865760f64..198f2b040 100644 --- a/src/hal/xmega128a4u/buildnumber.txt +++ b/src/hal/xmega128a4u/buildnumber.txt @@ -1 +1 @@ -9218 \ No newline at end of file +9223 \ No newline at end of file diff --git a/src/lib_chromatron/buildnumber.txt b/src/lib_chromatron/buildnumber.txt index 1a3f2890a..ea9412b02 100644 --- a/src/lib_chromatron/buildnumber.txt +++ b/src/lib_chromatron/buildnumber.txt @@ -1 +1 @@ -2977 \ No newline at end of file +2982 \ No newline at end of file diff --git a/src/lib_chromatron/server.c b/src/lib_chromatron/server.c index 24122a20b..0d288d12b 100644 --- a/src/lib_chromatron/server.c +++ b/src/lib_chromatron/server.c @@ -76,6 +76,12 @@ PT_BEGIN( pt ); continue; } + // check if pixel driver is off + if( pixel_u8_get_mode() == PIX_MODE_OFF ){ + + continue; + } + uint8_t *data = sock_vp_get_data( sock ); uint8_t type = *data; @@ -93,68 +99,164 @@ PT_BEGIN( pt ); continue; } - uint8_t array_r[CHROMA_SVR_MAX_PIXELS]; - uint8_t array_g[CHROMA_SVR_MAX_PIXELS]; - uint8_t array_b[CHROMA_SVR_MAX_PIXELS]; - uint8_t array_d[CHROMA_SVR_MAX_PIXELS]; - - // check if HSV - if( type == CHROMA_MSG_TYPE_HSV ){ + if( pixel_u8_get_mode() == PIX_MODE_ANALOG ){ - // unpack HSV pointers - uint16_t *h = &msg->data0; - uint16_t *s = h + 1; - uint16_t *v = s + 1; + uint16_t r, g, b; - // convert to RGB - for( uint8_t i = 0; i < msg->count; i++ ){ + // check if HSV + if( type == CHROMA_MSG_TYPE_HSV ){ - // update in place - gfx_v_hsv_to_rgb( *h, *s, *v, h, s, v ); + // unpack HSV pointers + uint16_t *h = &msg->data0; + uint16_t *s = h + 1; + uint16_t *v = s + 1; - h += 3; - s += 3; - v += 3; + // convert to RGB + gfx_v_hsv_to_rgb( *h, *s, *v, &r, &g, &b ); } - } + else{ - // unpack RGB pointers - uint16_t *r = &msg->data0; - uint16_t *g = r + 1; - uint16_t *b = g + 1; - uint8_t dither; - - for( uint8_t i = 0; i < msg->count; i++ ){ - - *r /= 64; - *g /= 64; - *b /= 64; - - dither = ( *r & 0x0003 ) << 4; - dither |= ( *g & 0x0003 ) << 2; - dither |= ( *b & 0x0003 ); - - *r /= 4; - *g /= 4; - *b /= 4; - - array_r[i] = *r; - array_g[i] = *g; - array_b[i] = *b; - array_d[i] = dither; - - r += 3; - g += 3; - b += 3; + r = msg->data0; + g = *( &msg->data0 + 1 ); + b = *( &msg->data0 + 2 ); + } + + pixel_v_set_analog_rgb( r, g, b ); } + else{ + + uint8_t array_r[CHROMA_SVR_MAX_PIXELS]; + uint8_t array_g[CHROMA_SVR_MAX_PIXELS]; + uint8_t array_b[CHROMA_SVR_MAX_PIXELS]; + uint8_t array_d[CHROMA_SVR_MAX_PIXELS]; + + // check if HSV + if( type == CHROMA_MSG_TYPE_HSV ){ + + uint16_t r, g, b, w; + + // unpack HSV pointers + uint16_t *h = &msg->data0; + uint16_t *s = h + 1; + uint16_t *v = s + 1; + + // convert to RGBW + if( pixel_u8_get_mode() == PIX_MODE_SK6812_RGBW ){ + + // RGBW mode doesn't support dithering, it uses this + // channel for white instead. + for( uint8_t i = 0; i < msg->count; i++ ){ + + gfx_v_hsv_to_rgbw( *h, *s, *v, &r, &g, &b, &w ); + + h += 3; + s += 3; + v += 3; + + array_r[i] = r / 256; + array_g[i] = g / 256; + array_b[i] = b / 256; + array_d[i] = w / 256; + } + } + // convert to RGB + else{ + + uint8_t dither; + + for( uint8_t i = 0; i < msg->count; i++ ){ + + // update in place + gfx_v_hsv_to_rgb( *h, *s, *v, &r, &g, &b ); + + h += 3; + s += 3; + v += 3; + + r /= 64; + g /= 64; + b /= 64; + + dither = ( r & 0x0003 ) << 4; + dither |= ( g & 0x0003 ) << 2; + dither |= ( b & 0x0003 ); + + r /= 4; + g /= 4; + b /= 4; + + array_r[i] = r; + array_g[i] = g; + array_b[i] = b; + array_d[i] = dither; + } + } + } + // RGB + else{ + + // unpack RGB pointers + uint16_t *r = &msg->data0; + uint16_t *g = r + 1; + uint16_t *b = g + 1; + uint8_t dither; + + if( pixel_u8_get_mode() == PIX_MODE_SK6812_RGBW ){ + + for( uint8_t i = 0; i < msg->count; i++ ){ + + *r /= 256; + *g /= 256; + *b /= 256; + + dither = 0; + + array_r[i] = *r; + array_g[i] = *g; + array_b[i] = *b; + array_d[i] = dither; + + r += 3; + g += 3; + b += 3; + } + } + else{ + + for( uint8_t i = 0; i < msg->count; i++ ){ + + *r /= 64; + *g /= 64; + *b /= 64; + + dither = ( *r & 0x0003 ) << 4; + dither |= ( *g & 0x0003 ) << 2; + dither |= ( *b & 0x0003 ); + + *r /= 4; + *g /= 4; + *b /= 4; + + array_r[i] = *r; + array_g[i] = *g; + array_b[i] = *b; + array_d[i] = dither; + + r += 3; + g += 3; + b += 3; + } + } + } - pixel_v_load_rgb( - msg->index, - msg->count, - array_r, - array_g, - array_b, - array_d ); + pixel_v_load_rgb( + msg->index, + msg->count, + array_r, + array_g, + array_b, + array_d ); + } } } diff --git a/src/lib_dns/buildnumber.txt b/src/lib_dns/buildnumber.txt index 04721971d..dab8073c1 100644 --- a/src/lib_dns/buildnumber.txt +++ b/src/lib_dns/buildnumber.txt @@ -1 +1 @@ -2817 \ No newline at end of file +2822 \ No newline at end of file diff --git a/src/lib_sntp/buildnumber.txt b/src/lib_sntp/buildnumber.txt index f3409cd61..5ed88a623 100644 --- a/src/lib_sntp/buildnumber.txt +++ b/src/lib_sntp/buildnumber.txt @@ -1 +1 @@ -2204 \ No newline at end of file +2209 \ No newline at end of file diff --git a/src/sapphireos/buildnumber.txt b/src/sapphireos/buildnumber.txt index 1615bb71b..44ce3fea8 100644 --- a/src/sapphireos/buildnumber.txt +++ b/src/sapphireos/buildnumber.txt @@ -1 +1 @@ -17631 \ No newline at end of file +17636 \ No newline at end of file