Commit 9b5ba248 authored by Fjen Undso's avatar Fjen Undso
Browse files

nchl: add continous setting and quit key

parent 41f110c0
......@@ -25,6 +25,7 @@ def main(stdscr):
curses.init_pair(curses.COLOR_GREEN, 0, curses.COLOR_GREEN)
curses.init_pair(curses.COLOR_BLUE, 0, curses.COLOR_BLUE)
curses.init_pair(curses.COLOR_WHITE, 0, curses.COLOR_WHITE)
curses.init_pair(curses.COLOR_YELLOW, curses.COLOR_YELLOW, -1)
# logging
logger = logging.getLogger(__name__)
......@@ -33,6 +34,7 @@ def main(stdscr):
stdscr.addstr(0, 2, "nchl - ncurses HoneyLight control", curses.A_BOLD)
# draw colors
numbers_text = [
('R', curses.COLOR_RED),
('G', curses.COLOR_GREEN),
......@@ -66,6 +68,7 @@ def main(stdscr):
prev_key='KEY_LEFT',
next_key='KEY_RIGHT')
# draw hosts
checkboxes_top = [
CheckBox(
window=stdscr,
......@@ -82,13 +85,18 @@ def main(stdscr):
toggle_key=' ',
toggle_key_unfocused=str(i),
text='ESP' + str(i)) for i in [2, 4, 6, 8]]
fs_cb = FocusSwitcher(
elements=checkboxes_top + checkboxes_bottom,
prev_key='KEY_LEFT',
next_key='KEY_RIGHT')
fs_main = FocusSwitcher(elements=[fs_n, fs_cb], prev_key='\t')
# draw settings
continous = CheckBox(window=stdscr, col=6, row=18, toggle_key_unfocused='c', text='(C)ontinuous updating')
stdscr.addstr(20, 8, 'S to send, Q to quit', curses.color_pair(curses.COLOR_YELLOW))
# focusswitcher
fs_n_cb = FocusSwitcher(elements=[fs_n, fs_cb], prev_key='\t')
fs_main = FocusSwitcher(elements=[fs_n_cb, continous])
fs_main.toggle_focus()
stdscr.refresh()
......@@ -97,11 +105,16 @@ def main(stdscr):
logger.info(k)
fs_main.send_key(k)
# quit
if k == 'q':
break
# send values to ESPs
colors = lights.make_stripe_data(
[numbers[1].value, numbers[0].value, numbers[2].value, numbers[3].value] * 42)
esps = [e.text for e in checkboxes_top + checkboxes_bottom if e.active]
lights.send_to_many(colors, esps)
if k == 's' or continous.active:
colors = lights.make_stripe_data(
[numbers[1].value, numbers[0].value, numbers[2].value, numbers[3].value] * 42)
esps = [e.text for e in checkboxes_top + checkboxes_bottom if e.active]
lights.send_to_many(colors, esps)
if __name__ == '__main__':
......
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