-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
60 lines (45 loc) · 1.27 KB
/
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
60
from flask import Flask
from flask import render_template
from flask import url_for
from flask import json
import elm
import test_elm
import obdii
import random
random.seed()
app = Flask(__name__)
class ObdiiSim(obdii.Obdii):
def get_current_engine_rpm(self):
return random.randint(600, 4000)
def get_throttle_position(self):
return random.randint(0, 100)
def get_vehicle_speed(self):
return random.randint(0, 120)
elm_interface = elm.Elm(test_elm.MockElm327())
#interface = obdii.Obdii(elm_interface)
interface = ObdiiSim(elm_interface)
@app.route("/")
def home():
return render_template('home.html')
@app.route('/api/engine/speed')
def engine_speed():
x = interface.get_current_engine_rpm()
return json.jsonify(rpm=x)
@app.route('/api/engine')
def engine():
rpm = interface.get_current_engine_rpm()
throttle = interface.get_throttle_position()
#throttle = 0
return json.jsonify(rpm=rpm, throttle=throttle)
@app.route('/api/vehicle')
def vehicle():
speed = interface.get_vehicle_speed()
return json.jsonify(speed=speed)
@app.route('/api/ports')
def ports():
return json.jsonify(ports=elm.available_ports())
def elm_initialize():
pass
if __name__ == "__main__":
elm_initialize()
app.run(debug=True)