add app_dash.py and some files
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,18 +1,15 @@
|
||||
from flask import Flask, render_template, make_response, json
|
||||
import app_obd, app_car, app_account, time
|
||||
import app_obd, app_car, app_account, time, app_events
|
||||
from app_events import socketio
|
||||
|
||||
app = Flask(__name__)
|
||||
socketio.init_app(app)
|
||||
|
||||
account = app_account.Account()
|
||||
obd = app_obd.OBD()
|
||||
car = app_car.Car()
|
||||
app_obd.obd_connection()
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
print("hello "+account.name)
|
||||
return render_template('index.html', account = account)
|
||||
print("hello")
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route('/dtc')
|
||||
def dtc():
|
||||
@@ -25,3 +22,14 @@ def data():
|
||||
response = make_response(json.dumps(data))
|
||||
response.content_type = 'application/json'
|
||||
return response
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Run the Flask application with a custom port."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--port", type=int, default=5000, help="Port number (default is 5000)"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
app.run(debug=True, port=args.port)
|
||||
+12
-21
@@ -1,27 +1,18 @@
|
||||
import app_car as Car
|
||||
import threading, app_events
|
||||
from threading import Thread
|
||||
|
||||
account_car = Car()
|
||||
account_car.model = "YARIS"
|
||||
socketio = app_events.SocketIO()
|
||||
account_name = "quoije"
|
||||
account_pp_image = "static\img\image.png"
|
||||
account_info = ["name","pp_image", "car_model"]
|
||||
account_car = Car
|
||||
account_car.model = "YARIS"
|
||||
account_lock = threading.Lock()
|
||||
|
||||
class Account:
|
||||
def __init__(self):
|
||||
self.name = "quoije"
|
||||
self.pp_image = None
|
||||
self.car = account_car.model
|
||||
|
||||
def account_info():
|
||||
obd_speed_lock.acquire()
|
||||
cmd = obd.commands.GET_DTC # select an OBD command (sensor)
|
||||
response = connection.query(cmd) # send the command and parse the response
|
||||
try:
|
||||
if response.is_null():
|
||||
error_txt = "No data received."
|
||||
print(error_txt)
|
||||
socketio.emit('obd_dtc', error_txt)
|
||||
else:
|
||||
print(response.value)
|
||||
socketio.emit('obd_dtc', response.value)
|
||||
finally:
|
||||
obd_rpm_lock.release()
|
||||
self.name = account_name
|
||||
self.pp_image = account_pp_image
|
||||
self.car = account_car
|
||||
def info():
|
||||
return [name, pp_image, car.model]
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
import os
|
||||
import shutil
|
||||
from tqdm import tqdm
|
||||
|
||||
def mount_device(device, mount_point):
|
||||
os.system(f"sudo mount {device} {mount_point}")
|
||||
|
||||
def unmount_device(mount_point):
|
||||
os.system(f"sudo umount {mount_point}")
|
||||
|
||||
def copy_files(source_folder, destination_folder):
|
||||
if not os.path.exists(destination_folder):
|
||||
os.makedirs(destination_folder)
|
||||
|
||||
for root, dirs, files in os.walk(source_folder):
|
||||
for file in tqdm(files, desc="Copying files", unit="file"):
|
||||
source_path = os.path.join(root, file)
|
||||
destination_path = os.path.join(destination_folder, file)
|
||||
|
||||
# Check if the file already exists in the destination folder
|
||||
if not os.path.exists(destination_path):
|
||||
shutil.copy2(source_path, destination_folder)
|
||||
|
||||
if __name__ == "__main__":
|
||||
source_device = "/dev/sda"
|
||||
mount_point = "/mnt/dash"
|
||||
destination_folder = "~/yaris-obd/dash/videos"
|
||||
|
||||
try:
|
||||
# Mount the device
|
||||
mount_device(source_device, mount_point)
|
||||
|
||||
# Copy files from source to destination
|
||||
copy_files(os.path.join(mount_point, "DCIM"), os.path.expanduser(destination_folder))
|
||||
|
||||
finally:
|
||||
# Unmount the device (even if an exception occurs)
|
||||
unmount_device(mount_point)
|
||||
+1
-2
@@ -1,6 +1,6 @@
|
||||
from flask_socketio import SocketIO
|
||||
from threading import Thread
|
||||
import app_obd, time, threading
|
||||
import app_obd, app_account, time, threading
|
||||
|
||||
socketio = SocketIO()
|
||||
uptime_lock = threading.Lock()
|
||||
@@ -9,7 +9,6 @@ uptime_lock = threading.Lock()
|
||||
def connect_event():
|
||||
print('Client connected')
|
||||
print('Getting OBD status...')
|
||||
app_obd.obd_connection()
|
||||
uptime()
|
||||
|
||||
def uptime():
|
||||
|
||||
+41
-15
@@ -5,7 +5,7 @@ from threading import Thread
|
||||
|
||||
status = None
|
||||
speed = 0
|
||||
rpm = None
|
||||
rpm = 0
|
||||
|
||||
class OBD:
|
||||
def __init__(self):
|
||||
@@ -15,7 +15,9 @@ class OBD:
|
||||
|
||||
obd_status = ["Disconnected", "Connected", "Connection...", "wtf"]
|
||||
obd_speed_lock = threading.Lock()
|
||||
obd_speed_rpm = threading.Lock()
|
||||
obd_rpm_lock = threading.Lock()
|
||||
obd_dtc_lock = threading.Lock()
|
||||
obd_state_lock = threading.Lock()
|
||||
|
||||
try:
|
||||
print(obd_status[2])
|
||||
@@ -31,21 +33,28 @@ def get_speedtime():
|
||||
time_now = str(date.strftime("%H:%M:%S"))
|
||||
return [str(time_now), speed]
|
||||
|
||||
@socketio.on('obd')
|
||||
def obd_connection():
|
||||
if connection.is_connected():
|
||||
print(obd_status[1])
|
||||
socketio.emit('obd_status', obd_status[1])
|
||||
print("OBD connection established.")
|
||||
obd_events(1)
|
||||
|
||||
else:
|
||||
print("OBD connection failed.")
|
||||
print(obd_status[0])
|
||||
obd_events(2)
|
||||
|
||||
socketio.emit('obd_status', obd_status[0])
|
||||
socketio.emit('obd_speed', "-")
|
||||
socketio.emit('obm_error', "-")
|
||||
socketio.emit('obd_rpm', "-")
|
||||
@socketio.on('obd')
|
||||
def obd_events(status):
|
||||
if status == 1:
|
||||
thread_speed = Thread(target=obd_state(1))
|
||||
thread_speed.daemon = True
|
||||
thread_speed.start()
|
||||
|
||||
elif status == 2:
|
||||
thread_speed = Thread(target=obd_state(2))
|
||||
thread_speed.daemon = True
|
||||
thread_speed.start()
|
||||
|
||||
# debug speed for testing
|
||||
thread_speed = Thread(target=obd_speed)
|
||||
@@ -57,6 +66,22 @@ def obd_connection():
|
||||
thread_rpm.daemon = True
|
||||
thread_rpm.start()
|
||||
|
||||
else:
|
||||
thread_speed = Thread(target=obd_state(0))
|
||||
thread_speed.daemon = True
|
||||
thread_speed.start()
|
||||
|
||||
|
||||
def obd_state(status):
|
||||
obd_state_lock.acquire()
|
||||
loop = True
|
||||
try:
|
||||
while loop == True:
|
||||
socketio.emit('obd_status', obd_status[status])
|
||||
time.sleep(2)
|
||||
finally:
|
||||
obd_state_lock.release()
|
||||
|
||||
def obd_speed():
|
||||
obd_speed_lock.acquire()
|
||||
cmd = obd.commands.SPEED # select an OBD command (sensor)
|
||||
@@ -64,6 +89,7 @@ def obd_speed():
|
||||
loop = True
|
||||
try:
|
||||
while loop == True:
|
||||
socketio.emit('obd_status', obd_status[3])
|
||||
global speed
|
||||
speed = speed + 1
|
||||
time.sleep(1)
|
||||
@@ -78,26 +104,26 @@ def obd_speed():
|
||||
obd_speed_lock.release()
|
||||
|
||||
def obd_rpm():
|
||||
obd_speed_lock.acquire()
|
||||
obd_rpm_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
|
||||
rpm = rpm + 1
|
||||
time.sleep(1)
|
||||
if response.is_null():
|
||||
print("No data received. #"+ str(get_speedtime()))
|
||||
socketio.emit('obd_speed', get_speedtime())
|
||||
print("No data received. #"+"RPM :"+str(rpm))
|
||||
socketio.emit('obd_rpm', rpm)
|
||||
else:
|
||||
print("RPM:", response.value)
|
||||
socketio.emit('obd_speed', response.value.to("kph"))
|
||||
socketio.emit('obd_rpm', response.value.to("kph"))
|
||||
finally:
|
||||
obd_rpm_lock.release()
|
||||
|
||||
def obd_dtc():
|
||||
obd_speed_lock.acquire()
|
||||
obd_dtc_lock.acquire()
|
||||
cmd = obd.commands.GET_DTC # select an OBD command (sensor)
|
||||
response = connection.query(cmd) # send the command and parse the response
|
||||
try:
|
||||
@@ -109,7 +135,7 @@ def obd_dtc():
|
||||
print(response.value)
|
||||
socketio.emit('obd_dtc', response.value)
|
||||
finally:
|
||||
obd_rpm_lock.release()
|
||||
obd_dtc_lock.release()
|
||||
|
||||
def kill_obd(obd_type):
|
||||
if obd_type == "speed":
|
||||
|
||||
@@ -32,6 +32,10 @@ chart = new Chart(ctx, {
|
||||
}
|
||||
});
|
||||
|
||||
// account
|
||||
|
||||
|
||||
|
||||
// websockets
|
||||
|
||||
socket.on('connect', function(data) {
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
<nav class="navbar align-items-start sidebar sidebar-dark accordion bg-gradient-primary p-0 navbar-dark" style="color: var(--bs-accordion-btn-focus-border-color);background: rgb(0,0,0);filter: blur(0px);backdrop-filter: blur(0px) hue-rotate(0deg);">
|
||||
<div class="container-fluid d-flex flex-column p-0"><a class="navbar-brand d-flex justify-content-center align-items-center sidebar-brand m-0" href="#">
|
||||
<div class="sidebar-brand-icon rotate-n-15"><i class="fas fa-car"></i></div>
|
||||
<div class="sidebar-brand-text mx-3"><span>yaris </span></div>
|
||||
<div id="index-car-model" class="sidebar-brand-text mx-3"><span>CAR MODEL</span></div>
|
||||
</a>
|
||||
<hr class="sidebar-divider my-0">
|
||||
<ul class="navbar-nav text-light" id="accordionSidebar">
|
||||
|
||||
Reference in New Issue
Block a user