Added support for blinkstick pro devices.
This commit is contained in:
parent
133c65d9b5
commit
67323cc1e5
@ -4,13 +4,16 @@ from __future__ import division
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
DEVICE = 'esp8266'
|
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
|
'esp8266' means that you are using an ESP8266 module to control the LED strip
|
||||||
and commands will be sent to the ESP8266 over WiFi.
|
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
|
'pi' means that you are using a Raspberry Pi as a standalone unit to process
|
||||||
audio input and control the LED strip directly.
|
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':
|
if DEVICE == 'esp8266':
|
||||||
@ -35,6 +38,10 @@ if DEVICE == 'pi':
|
|||||||
SOFTWARE_GAMMA_CORRECTION = True
|
SOFTWARE_GAMMA_CORRECTION = True
|
||||||
"""Set to True because Raspberry Pi doesn't use hardware dithering"""
|
"""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
|
USE_GUI = True
|
||||||
"""Whether or not to display a PyQtGraph GUI plot of visualization"""
|
"""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)
|
_max_led_FPS = int(((N_PIXELS * 30e-6) + 50e-6)**-1.0)
|
||||||
assert FPS <= _max_led_FPS, 'FPS must be <= {}'.format(_max_led_FPS)
|
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"""
|
"""Frequencies below this value will be removed during audio processing"""
|
||||||
|
|
||||||
MAX_FREQUENCY = 12000
|
MAX_FREQUENCY = 12000
|
||||||
|
@ -16,6 +16,9 @@ elif config.DEVICE == 'pi':
|
|||||||
config.LED_FREQ_HZ, config.LED_DMA,
|
config.LED_FREQ_HZ, config.LED_DMA,
|
||||||
config.LED_INVERT, config.BRIGHTNESS)
|
config.LED_INVERT, config.BRIGHTNESS)
|
||||||
strip.begin()
|
strip.begin()
|
||||||
|
elif config.DEVICE == 'blinkstick':
|
||||||
|
from blinkstick import blinkstick
|
||||||
|
stick = blinkstick.find_first()
|
||||||
|
|
||||||
_gamma = np.load(config.GAMMA_TABLE_PATH)
|
_gamma = np.load(config.GAMMA_TABLE_PATH)
|
||||||
"""Gamma lookup table used for nonlinear brightness correction"""
|
"""Gamma lookup table used for nonlinear brightness correction"""
|
||||||
@ -91,6 +94,32 @@ def _update_pi():
|
|||||||
_prev_pixels = np.copy(p)
|
_prev_pixels = np.copy(p)
|
||||||
strip.show()
|
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():
|
def update():
|
||||||
"""Updates the LED strip values"""
|
"""Updates the LED strip values"""
|
||||||
@ -98,6 +127,8 @@ def update():
|
|||||||
_update_esp8266()
|
_update_esp8266()
|
||||||
elif config.DEVICE == 'pi':
|
elif config.DEVICE == 'pi':
|
||||||
_update_pi()
|
_update_pi()
|
||||||
|
elif config.DEVICE == 'blinkstick':
|
||||||
|
_update_blinkstick()
|
||||||
else:
|
else:
|
||||||
raise ValueError('Invalid device selected')
|
raise ValueError('Invalid device selected')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user