2016-10-12 23:50:00 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
import socket
|
|
|
|
import numpy as np
|
2016-10-14 07:27:45 +02:00
|
|
|
import config
|
|
|
|
|
|
|
|
_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
2016-11-08 02:44:23 +01:00
|
|
|
_gamma = np.load(config.GAMMA_TABLE_PATH)
|
2016-11-13 10:10:44 +01:00
|
|
|
_prev_pixels = np.tile(253, (3, config.N_PIXELS))
|
2016-10-14 07:27:45 +02:00
|
|
|
|
2016-11-13 10:10:44 +01:00
|
|
|
pixels = np.tile(1, (3, config.N_PIXELS))
|
2016-10-14 07:27:45 +02:00
|
|
|
"""Array containing the pixel values for the LED strip"""
|
|
|
|
|
|
|
|
|
|
|
|
def update():
|
|
|
|
global pixels, _prev_pixels
|
|
|
|
pixels = np.clip(pixels, 0, 255)
|
|
|
|
m = ''
|
2016-11-08 02:44:23 +01:00
|
|
|
p = _gamma[pixels] if config.GAMMA_CORRECTION else np.copy(pixels)
|
2016-10-14 07:27:45 +02:00
|
|
|
for i in range(config.N_PIXELS):
|
|
|
|
# Ignore pixels if they haven't changed (saves bandwidth)
|
2016-11-13 10:10:44 +01:00
|
|
|
if np.array_equal(p[:, i], _prev_pixels[:, i]):
|
2016-10-14 07:27:45 +02:00
|
|
|
continue
|
2016-11-13 10:10:44 +01:00
|
|
|
m += chr(i) + chr(p[0][i]) + chr(p[1][i]) + chr(p[2][i])
|
2016-11-12 00:51:41 +01:00
|
|
|
_prev_pixels = np.copy(p)
|
2016-10-14 07:27:45 +02:00
|
|
|
_sock.sendto(m, (config.UDP_IP, config.UDP_PORT))
|
|
|
|
|
|
|
|
|
2016-10-12 23:50:00 +02:00
|
|
|
if __name__ == '__main__':
|
2016-10-23 07:16:08 +02:00
|
|
|
pixels = pixels * 0
|
2016-11-08 02:44:23 +01:00
|
|
|
pixels = pixels
|
2016-10-23 06:55:22 +02:00
|
|
|
update()
|
2016-11-08 02:44:23 +01:00
|
|
|
|