-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
47 lines (37 loc) · 1.05 KB
/
server.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
from flask import Flask, jsonify, render_template, request
from ML.deploy import DeployModel
from Headset.ports import get_ports
from Headset.device import Device
import time
board_type = 0 # Cyton board
dm = DeployModel()
app = Flask(__name__)
device = None
bluetooth_device = ""
@app.route('/')
def index():
return render_template('index.html')
@app.route('/connected')
def connected():
return render_template('connected.html')
@app.route('/api/model_data')
def model_data():
return jsonify(result=dm.get_data_and_output()[0])
@app.route('/api/model_output')
def model_output():
return jsonify(result=dm.get_data_and_output()[1])
@app.route('/api/ports')
def ports():
return get_ports()
@app.route('/api/connect', methods=['GET', 'POST'])
def connect():
print("CONNECTING")
port = request.form.get('port')
if (port != None):
device = Device(board_type, port)
# connected = device.connect()
connected = True # For testing purposes
time.sleep(0.6)
return {"connected": connected}
return {"connected": False}
# @app.route('/api/')