Made LED code also a thread

master
Ebbe Baß 2022-01-04 10:51:16 +01:00
parent fda9df2e3d
commit f9ad7f54ea
1 changed files with 21 additions and 18 deletions

37
main.py
View File

@ -73,23 +73,7 @@ def power_toggle(channel):
power_button_pressed = 'True' power_button_pressed = 'True'
print('Toggle Power executed') print('Toggle Power executed')
#Web API def led_main():
app = Flask(__name__)
@app.route('/')
def index():
command = str(request.args.get('command'))
if command == "switch-ilde-mode":
print('Switched Idlemode via API')
change_idle_mode
elif command == "switch-toggle-on-off":
print('Toggled Power via API')
power_toggle
return command
if __name__ == '__main__':
threading.Thread(target=lambda: app.run(host="0.0.0.0", port=80, debug=True, use_reloader=False)).start()
led_power = 'True' led_power = 'True'
idle_mode = 1 idle_mode = 1
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
@ -139,3 +123,22 @@ if __name__ == '__main__':
except KeyboardInterrupt: except KeyboardInterrupt:
setColor(strip, Color(0,0,0)) setColor(strip, Color(0,0,0))
GPIO.cleanup() GPIO.cleanup()
#Web API
app = Flask(__name__)
@app.route('/')
def index():
command = str(request.args.get('command'))
if command == "switch-ilde-mode":
print('Switched Idlemode via API')
change_idle_mode
elif command == "switch-toggle-on-off":
print('Toggled Power via API')
power_toggle
return command
if __name__ == '__main__':
threading.Thread(target=lambda: app.run(host="0.0.0.0", port=80, debug=True, use_reloader=False)).start()
threading.Thread(target=lambda: led_main).start()