-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflask-app.py
59 lines (45 loc) · 1.32 KB
/
flask-app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from arg_parser import ArgParser
from flask import Flask, request
from pixel_service import PixelService
import clients_page
DESCRIPTION = """
Web server for remote control of neopixels.
"""
NUM_PIXELS = 43
app = Flask(__name__, static_url_path='')
app.config.from_object(__name__)
pixelservice = None
@app.route('/')
def root():
return app.send_static_file('index.html')
@app.route('/clients')
def clients():
return clients_page.clients()
@app.route('/alloff', methods=['POST'])
def all_off():
pixelservice.set_all(0, 0, 0)
return "OK"
@app.route('/setall', methods=['POST'])
def set_all():
color = request.args.get('color')
if color == 'red':
pixelservice.set_all(200, 0, 0)
else:
r = request.args.get('r') or 0
g = request.args.get('g') or 0
b = request.args.get('b') or 0
pixelservice.set_all(int(r), int(g), int(b))
return "OK"
@app.route('/setpattern', methods=['POST'])
def set_pattern():
name = request.args.get('name')
if not name:
return 'invalid pattern name', 400
pixelservice.set_pattern(name)
return "OK"
if __name__ == '__main__':
args = ArgParser(DESCRIPTION).parse_args()
host = args.host if args.host else None
pixelservice = PixelService(NUM_PIXELS)
pixelservice.start_displayer(args.device)
app.run(host)