From 71cc164bd43714363432d39165c95017ec0943af Mon Sep 17 00:00:00 2001 From: Ingar Date: Sun, 6 Feb 2022 16:37:35 +0100 Subject: Fixed a major bug while reading the state file. --- ledctl.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'ledctl.py') diff --git a/ledctl.py b/ledctl.py index 38d28fa..2c226e0 100644 --- a/ledctl.py +++ b/ledctl.py @@ -27,14 +27,14 @@ leds_array = neopixel.NeoPixel(board.D18, leds_max) statefile = '/tmp/ledctl.state' if exists(statefile): - print('reading ' + statefile) + #print('reading ' + statefile) with open(statefile, 'r') as f: lines = f.readlines() i = 0; for line in lines: - values = line.split(' ') - if (i < leds_num): + values = [ int(number) for number in line.rstrip().split(' ')] + if (i < leds_max): leds_array[i] = (values[0], values[1], values[2]); i = i + 1 f.close() @@ -63,21 +63,21 @@ def rgbval(colorname): return switch.get(colorname, 'Valid colors are black, white, ired, green, blue, yellow, on, off') if args.color: - print('color ' + args.color) + #print('color ' + args.color) leds_color = rgbval(args.color); if (leds_num > 0): - print('setting LED ' + leds_num) + #print('setting LED %d' % leds_num) - leds_array[leds_num] = leds_color + leds_array[leds_num - 1] = leds_color else: - print('setting all LEDs') + #print('setting all LEDs') leds_array.fill(leds_color) # write LED array to state file -print('writing ' + statefile) +#print('writing ' + statefile) with open(statefile, 'w') as f: for i in range(leds_max): -- cgit v1.2.3