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() socketio = SocketIO()
uptime_lock = threading.Lock() uptime_lock = threading.Lock()
thread_uptime = None
@socketio.on('connect') @socketio.on('connect')
def connect_event(): def connect_event():
@@ -14,9 +15,15 @@ def connect_event():
uptime() uptime()
def uptime(): def uptime():
thread = Thread(target=loop_uptime) global thread_uptime
thread.daemon = True
thread.start() 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(): def loop_uptime():
uptime_lock.acquire() uptime_lock.acquire()
+16 -10
View File
@@ -16,6 +16,8 @@ class OBD:
obd_status = ["Disconnected", "Connected", "Connection...", "wtf"] obd_status = ["Disconnected", "Connected", "Connection...", "wtf"]
obd_speed_lock = threading.Lock() obd_speed_lock = threading.Lock()
obd_rpm_lock = threading.Lock() obd_rpm_lock = threading.Lock()
thread_speed = None
thread_rpm = None
try: try:
print(obd_status[2]) print(obd_status[2])
@@ -31,12 +33,14 @@ def get_speedtime():
time_now = str(date.strftime("%H:%M:%S")) time_now = str(date.strftime("%H:%M:%S"))
return [str(time_now), speed] return [str(time_now), speed]
def obd_connection(): def obd_connection():
global thread_speed, thread_rpm
if connection.is_connected(): if connection.is_connected():
print(obd_status[1]) print(obd_status[1])
app_events.socketio.emit('obd_status', obd_status[1]) app_events.socketio.emit('obd_status', obd_status[1])
print("OBD connection established.") print("OBD connection established.")
else: else:
print("OBD connection failed.") print("OBD connection failed.")
print(obd_status[0]) print(obd_status[0])
@@ -46,15 +50,17 @@ def obd_connection():
app_events.socketio.emit('obm_error', "-") app_events.socketio.emit('obm_error', "-")
app_events.socketio.emit('obd_rpm', "-") app_events.socketio.emit('obd_rpm', "-")
# debug speed for testing if thread_speed is None or not thread_speed.is_alive():
thread_speed = Thread(target=obd_speed) thread_speed = Thread(target=obd_speed)
thread_speed.daemon = True print(f'thread_speed alive? {thread_speed.is_alive()}')
thread_speed.start() thread_speed.daemon = True
thread_speed.start()
# debug rpm for testing if thread_rpm is None or not thread_rpm.is_alive():
thread_rpm = Thread(target=obd_rpm) thread_rpm = Thread(target=obd_rpm)
thread_rpm.daemon = True print(f'thread_rpm alive? {thread_rpm.is_alive()}')
thread_rpm.start() thread_rpm.daemon = True
thread_rpm.start()
def obd_speed(): def obd_speed():
obd_speed_lock.acquire() obd_speed_lock.acquire()
@@ -65,7 +71,7 @@ def obd_speed():
while loop == True: while loop == True:
global speed global speed
speed = speed + 1 speed = speed + 1
time.sleep(10) time.sleep(2)
if response.is_null(): if response.is_null():
print("No data received. #"+ str(get_speedtime())) print("No data received. #"+ str(get_speedtime()))
print(app_gps.get_gps()) print(app_gps.get_gps())