Refactored led module and fixed a gamma table bug

This commit is contained in:
Scott Lawson 2016-11-07 17:44:23 -08:00
parent ea8b381c8a
commit 83453ed436

View File

@ -4,8 +4,8 @@ import numpy as np
import config
_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
_gamma = np.load('gamma_table.npy')
_prev_pixels = np.tile(255, (config.N_PIXELS, 3))
_gamma = np.load(config.GAMMA_TABLE_PATH)
_prev_pixels = np.tile(253, (config.N_PIXELS, 3))
pixels = np.tile(1, (config.N_PIXELS, 3))
"""Array containing the pixel values for the LED strip"""
@ -15,18 +15,18 @@ def update():
global pixels, _prev_pixels
pixels = np.clip(pixels, 0, 255)
m = ''
p = _gamma[pixels] if config.GAMMA_CORRECTION else np.copy(pixels)
for i in range(config.N_PIXELS):
# Ignore pixels if they haven't changed (saves bandwidth)
if np.array_equal(pixels[i], _prev_pixels[i]):
continue
r = _gamma[pixels[i][0]] if config.GAMMA_CORRECTION else pixels[i][0]
g = _gamma[pixels[i][1]] if config.GAMMA_CORRECTION else pixels[i][1]
b = _gamma[pixels[i][2]] if config.GAMMA_CORRECTION else pixels[i][2]
m += chr(i) + chr(r) + chr(g) + chr(b)
m += chr(i) + chr(p[i][0]) + chr(p[i][1]) + chr(p[i][2])
_prev_pixels = np.copy(pixels)
_sock.sendto(m, (config.UDP_IP, config.UDP_PORT))
if __name__ == '__main__':
pixels = pixels * 0
pixels = pixels
update()