-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
executable file
·44 lines (29 loc) · 976 Bytes
/
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
from flask import Flask, request
import subprocess
import arduino_serial
# import arduino_firmata
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
# cribbed from https://github.com/amperka/ino/blob/f23ee5cb14edc30ec087d3eab7b301736da42362/ino/commands/upload.py
def load_hex(hexfile):
subprocess.call('avrdude -p atmega2560 -P /dev/ttyACM0 -c wiring -b 115200 -D -U flash:w:%s:i' % hexfile, shell=True)
@app.route('/test')
def test_load():
hexfile = '/home/pi/test_sketch2/.build/mega2560/firmware.hex'
load_hex(hexfile)
return 'loaded'
@app.route('/test2')
def test_load2():
hexfile = '/home/pi/test_sketch/.build/mega2560/firmware.hex'
load_hex(hexfile)
return 'loaded'
@app.route('/color', methods=['GET'])
def color():
hue = request.args.get('hue')
arduino_serial.send(bytes(chr(int(hue))))
return 'loaded'
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0')