Commit ed1fe9e2 authored by Fjen Undso's avatar Fjen Undso
Browse files

nchl: add keys to turn all lights on/off

parent 64d07cf8
......@@ -14,21 +14,12 @@ SOCKET.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
SOCKET.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
def send_broadcast(data):
"""Send data via broadcast.
Args:
data (bytes): the data to send.
"""
send(data, UDP_IP)
def send(data, send_rate=SEND_RATE, host_id=0):
"""Send data to the ESP listening at host:UDP_PORT.
Args:
data (bytes): the data to send.
host (string): the host name or IP to send the data to.
host (string): the host name or IP to send the data to. Default 0 (all)
send_rate (float): the time in seconds to wait after sending.
"""
global SEQUENCES
......@@ -85,14 +76,14 @@ def make_stripe_data(pixellist):
def test(colors):
"""Test colors by bruteforcing sequence numbers."""
for i in range(128):
send_broadcast(colors)
for i in range(2):
send(colors)
if __name__ == '__main__':
test(make_stripe_data([255, 0, 0, 0] * LED_NUM))
time.sleep(1)
time.sleep(0.5)
test(make_stripe_data([0, 255, 0, 0] * LED_NUM))
time.sleep(1)
time.sleep(0.5)
test(make_stripe_data([0, 0, 255, 0] * LED_NUM))
time.sleep(1)
time.sleep(0.5)
test(make_stripe_data([0, 0, 0, 255] * LED_NUM))
......@@ -102,8 +102,8 @@ def main(stdscr):
col=scr_center_x - 12,
row=18,
toggle_key_unfocused='c',
text='(C)ontinuous updating')
stdscr.addstr(19, scr_center_x - 10, 'S to send, Q to quit', curses.color_pair(curses.COLOR_YELLOW))
text='(c)ontinuous updating')
stdscr.addstr(19, scr_center_x - 20, '(s)end | all (o)ff | all (w)hite | (q)uit', curses.color_pair(curses.COLOR_YELLOW))
# focusswitcher
fs_n_cb = FocusSwitcher(elements=[fs_n, fs_cb], prev_key='\t')
......@@ -120,6 +120,18 @@ def main(stdscr):
if k == 'q':
break
# all off:
if k == 'o':
colors = lights.make_stripe_data([0, 0, 0, 0] * 42)
lights.send(colors)
continue
# all white
if k == 'w':
colors = lights.make_stripe_data([255, 0, 100, 255] * 42)
lights.send(colors)
continue
# send values to ESPs
if k == 's' or continous.active:
colors = lights.make_stripe_data(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment