2 Commits
Author SHA1 Message Date
[email protected] 0d55d9e9de fix things, thread loop 2024-09-15 22:50:22 -04:00
Mathieu Moran 7fbd427516 Merge pull request #1 from quoije/main
working branch
2024-09-15 21:25:49 -04:00
14 changed files with 28 additions and 15 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+10 -3
View File
@@ -5,6 +5,7 @@ import time, threading
socketio = SocketIO()
uptime_lock = threading.Lock()
thread_uptime = None
@socketio.on('connect')
def connect_event():
@@ -14,9 +15,15 @@ def connect_event():
uptime()
def uptime():
thread = Thread(target=loop_uptime)
thread.daemon = True
thread.start()
global thread_uptime
if thread_uptime is None or not thread_uptime.is_alive():
thread_uptime = Thread(target=loop_uptime)
thread_uptime.daemon = True
thread_uptime.start()
print(f"Uptime thread started, alive: {thread_uptime.is_alive()}")
else:
print(f"Uptime thread already running, alive: {thread_uptime.is_alive()}")
def loop_uptime():
uptime_lock.acquire()
+16 -10
View File
@@ -16,6 +16,8 @@ class OBD:
obd_status = ["Disconnected", "Connected", "Connection...", "wtf"]
obd_speed_lock = threading.Lock()
obd_rpm_lock = threading.Lock()
thread_speed = None
thread_rpm = None
try:
print(obd_status[2])
@@ -31,12 +33,14 @@ def get_speedtime():
time_now = str(date.strftime("%H:%M:%S"))
return [str(time_now), speed]
def obd_connection():
global thread_speed, thread_rpm
if connection.is_connected():
print(obd_status[1])
app_events.socketio.emit('obd_status', obd_status[1])
print("OBD connection established.")
else:
print("OBD connection failed.")
print(obd_status[0])
@@ -46,15 +50,17 @@ def obd_connection():
app_events.socketio.emit('obm_error', "-")
app_events.socketio.emit('obd_rpm', "-")
# debug speed for testing
thread_speed = Thread(target=obd_speed)
thread_speed.daemon = True
thread_speed.start()
if thread_speed is None or not thread_speed.is_alive():
thread_speed = Thread(target=obd_speed)
print(f'thread_speed alive? {thread_speed.is_alive()}')
thread_speed.daemon = True
thread_speed.start()
# debug rpm for testing
thread_rpm = Thread(target=obd_rpm)
thread_rpm.daemon = True
thread_rpm.start()
if thread_rpm is None or not thread_rpm.is_alive():
thread_rpm = Thread(target=obd_rpm)
print(f'thread_rpm alive? {thread_rpm.is_alive()}')
thread_rpm.daemon = True
thread_rpm.start()
def obd_speed():
obd_speed_lock.acquire()
@@ -65,7 +71,7 @@ def obd_speed():
while loop == True:
global speed
speed = speed + 1
time.sleep(10)
time.sleep(2)
if response.is_null():
print("No data received. #"+ str(get_speedtime()))
print(app_gps.get_gps())