From fc31141394fab40e946074583b35b09c27df6a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Fri, 11 Mar 2022 11:38:02 +0100 Subject: [PATCH] Added idle mode saver --- main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 3618a80..cac07f4 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ from rpi_ws281x import * import RPi.GPIO as GPIO import os from datetime import datetime +current_path = os.path.dirname(os.path.abspath(__file__)) led_power = 'True' idle_mode = 1 @@ -74,6 +75,10 @@ def change_idle_mode(channel): if idle_mode == 8: idle_mode = 1 debug_print('Change Idlemode executed') + with open(current_path+'/settings.txt', 'w') as f: + f.write(str(idle_mode)) + debug_print('Saved idle mode') + def power_toggle(channel): global power_button_pressed @@ -87,7 +92,9 @@ if __name__ == '__main__': GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.add_event_detect(13, GPIO.RISING, callback=power_toggle, bouncetime=300) - GPIO.add_event_detect(19, GPIO.RISING, callback=change_idle_mode, bouncetime=300) + GPIO.add_event_detect(19, GPIO.RISING, callback=change_idle_mode, bouncetime=300) + with open(current_path+'/settings.txt', 'r') as f: + idle_mode = int(f.readlines()) try: while True: