-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathira.py
executable file
·51 lines (40 loc) · 1.6 KB
/
ira.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
#!/usr/local/bin/python3.7
from fastapi import FastAPI, Query
from starlette.responses import HTMLResponse
from starlette.staticfiles import StaticFiles
from starlette.templating import Jinja2Templates
# from async_exec import run
from typing import List, Tuple
from requests import post
from json import dumps
import uvicorn
import packet
app = FastAPI(template_directory='templates')
# app.mount('/static', StaticFiles(directory='static'), name='static')
templates = Jinja2Templates('templates')
current = ''
channels = ['program', 'red', 'green', 'blue', 'speed', 'hue', 'eyesize', 'tail']
@app.get('/ira')
async def ira(program: List[int] = Query(None)):
print('ira got ', program)
# resp = post('http://192.168.1.66/', data=dumps({'dmx':program}), headers={'Content-Type': 'application/json'})
# if resp.status_code == 200:
# return program
# else: return resp.status_code
return packet.send(*program)
# @app.get('/upload')
# async def upload():
# arduinoType = 'nano:cpu=atmega328old'
# compiled = f'arduino-cli compile -b arduino:avr:{arduinoType} generator'
# results = await run(compiled.split(' '))
# uploaded = f'arduino-cli upload -b arduino:avr:{arduinoType} -p /dev/tty.usbserial-1430 -v generator'
# results += await run(uploaded.split(' '))
# return results
@app.get('/')
async def home():
return HTMLResponse(templates.get_template('home.html').render(channels=channels))
@app.get('/paper')
async def paper():
return HTMLResponse(templates.get_template('paper.html').render())
if __name__ == '__main__':
uvicorn.run(app, host='0.0.0.0', port=8000)