Added support for blinkstick pro devices.

This commit is contained in:
Kevin Kellner 2017-01-06 15:03:37 +01:00
parent 133c65d9b5
commit 67323cc1e5
2 changed files with 40 additions and 2 deletions

View File

@ -4,13 +4,16 @@ from __future__ import division
import os
DEVICE = 'esp8266'
"""Device used to control LED strip. Must be 'pi' or 'esp8266'
"""Device used to control LED strip. Must be 'pi', 'esp8266' or 'blinkstick'
'esp8266' means that you are using an ESP8266 module to control the LED strip
and commands will be sent to the ESP8266 over WiFi.
'pi' means that you are using a Raspberry Pi as a standalone unit to process
audio input and control the LED strip directly.
'blinkstick' means that a BlinkstickPro is connected to this PC which will be used
to control the leds connected to it.
"""
if DEVICE == 'esp8266':
@ -35,6 +38,10 @@ if DEVICE == 'pi':
SOFTWARE_GAMMA_CORRECTION = True
"""Set to True because Raspberry Pi doesn't use hardware dithering"""
if DEVICE == 'blinkstick':
SOFTWARE_GAMMA_CORRECTION = True
"""Set to True because blinkstick doesn't use hardware dithering"""
USE_GUI = True
"""Whether or not to display a PyQtGraph GUI plot of visualization"""
@ -69,7 +76,7 @@ depends on how long the LED strip is.
_max_led_FPS = int(((N_PIXELS * 30e-6) + 50e-6)**-1.0)
assert FPS <= _max_led_FPS, 'FPS must be <= {}'.format(_max_led_FPS)
MIN_FREQUENCY = 200
MIN_FREQUENCY = 100
"""Frequencies below this value will be removed during audio processing"""
MAX_FREQUENCY = 12000

View File

@ -16,6 +16,9 @@ elif config.DEVICE == 'pi':
config.LED_FREQ_HZ, config.LED_DMA,
config.LED_INVERT, config.BRIGHTNESS)
strip.begin()
elif config.DEVICE == 'blinkstick':
from blinkstick import blinkstick
stick = blinkstick.find_first()
_gamma = np.load(config.GAMMA_TABLE_PATH)
"""Gamma lookup table used for nonlinear brightness correction"""
@ -91,6 +94,32 @@ def _update_pi():
_prev_pixels = np.copy(p)
strip.show()
def _update_blinkstick():
"""Writes new LED values to the Blinkstick.
This function updates the LED strip with new values.
"""
global pixels
# Truncate values and cast to integer
pixels = np.clip(pixels, 0, 255).astype(long)
# Optional gamma correction
p = _gamma[pixels] if config.SOFTWARE_GAMMA_CORRECTION else np.copy(pixels)
# Read the rgb values
r = p[0][:].astype(int)
g = p[1][:].astype(int)
b = p[2][:].astype(int)
#create array in which we will store the led states
newstrip = [None]*(config.N_PIXELS*3)
for i in range(config.N_PIXELS):
# blinkstick uses GRB format
newstrip[i*3] = g[i]
newstrip[i*3+1] = r[i]
newstrip[i*3+2] = b[i]
#send the data to the blinkstick
stick.set_led_data(0, newstrip)
def update():
"""Updates the LED strip values"""
@ -98,6 +127,8 @@ def update():
_update_esp8266()
elif config.DEVICE == 'pi':
_update_pi()
elif config.DEVICE == 'blinkstick':
_update_blinkstick()
else:
raise ValueError('Invalid device selected')