diff --git a/app.py b/app.py index 1d51b97..191dfc6 100644 --- a/app.py +++ b/app.py @@ -14,6 +14,10 @@ def index(): print("hello "+account.name) return render_template('index.html', account = account) +@app.route('/dtc') +def dtc(): + return render_template('dtc.html') + # not sure if im gonna use this @app.route('/api/obd_speed/') def data(): diff --git a/app_obd.py b/app_obd.py index acb83f9..29a0fe6 100644 --- a/app_obd.py +++ b/app_obd.py @@ -15,6 +15,7 @@ class OBD: obd_status = ["Disconnected", "Connected", "Connection...", "wtf"] obd_speed_lock = threading.Lock() +obd_speed_rpm = threading.Lock() try: print(obd_status[2]) @@ -31,24 +32,30 @@ def get_speedtime(): return [str(time_now), speed] @socketio.on('obd') -def obd_connection(): - +def obd_connection(): if connection.is_connected(): print(obd_status[1]) socketio.emit('obd_status', obd_status[1]) print("OBD connection established.") else: + print("OBD connection failed.") print(obd_status[0]) + socketio.emit('obd_status', obd_status[0]) socketio.emit('obd_speed', "-") - socketio.emit('obd_error', "-") + socketio.emit('obm_error', "-") + socketio.emit('obd_rpm', "-") - # test speed while offline - print("OBD connection failed.") - thread = Thread(target=obd_speed) - thread.daemon = True - thread.start() + # debug speed for testing + thread_speed = Thread(target=obd_speed) + thread_speed.daemon = True + thread_speed.start() + + # debug rpm for testing + thread_rpm = Thread(target=obd_rpm) + thread_rpm.daemon = True + thread_rpm.start() def obd_speed(): obd_speed_lock.acquire() @@ -70,4 +77,27 @@ def obd_speed(): finally: obd_speed_lock.release() +def obd_rpm(): + obd_speed_lock.acquire() + cmd = obd.commands.RPM # select an OBD command (sensor) + response = connection.query(cmd) # send the command and parse the response + loop = True + try: + while loop == True: + global rpm + speed = speed + 1 + time.sleep(1) + if response.is_null(): + print("No data received. #"+ str(get_speedtime())) + socketio.emit('obd_speed', get_speedtime()) + else: + print("RPM:", response.value) + socketio.emit('obd_speed', response.value.to("kph")) + finally: + obd_rpm_lock.release() +def kill_obd(obd_type): + if obd_type == "speed": + obd_speed.loop = False + elif obd_type == "rpm": + obd_rpm.loop = False diff --git a/static/js/yaris.js b/static/js/yaris.js index b7186b3..50feb9e 100644 --- a/static/js/yaris.js +++ b/static/js/yaris.js @@ -13,6 +13,7 @@ chart = new Chart(ctx, { }] }, options: { + responsive: true, scales: { x: { reverse: true, @@ -64,13 +65,18 @@ socket.on('obd_speed', function(data) { } // Update the chart - chart.update(); }); +socket.on('obd_rpm', function(data) { + console.log("obd rpm "+data); + const status = document.getElementById('obd-rpm'); + status.innerHTML = data; +}); + socket.on('obd_error', function(data) { - console.log(data); + console.log("obd errors "+data); const status = document.getElementById('obd-error'); status.innerHTML = data; }); diff --git a/static/yaris.css b/static/yaris.css index 92b2ad5..90b9b33 100644 --- a/static/yaris.css +++ b/static/yaris.css @@ -1 +1 @@ -#map { height: 460px; } \ No newline at end of file +#map { height: 20rem; } \ No newline at end of file diff --git a/templates/dtc.html b/templates/dtc.html new file mode 100644 index 0000000..ba74135 --- /dev/null +++ b/templates/dtc.html @@ -0,0 +1,78 @@ + + + + + + + Table - yaris vroom vroom de course + + + + + + +
+ +
+
+ +
+

DTC Codes

+
+
+

Output

+
+
+
+
+
+
+
+ +
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 0458fca..860b9dd 100644 --- a/templates/index.html +++ b/templates/index.html @@ -17,15 +17,13 @@