aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--QMLWidgets/Tire_Pressure/TirePressure.qml2
-rw-r--r--Scripts/record_playback.py10
-rw-r--r--Widgets/ICPage.py48
-rw-r--r--Widgets/TirePressure.py69
-rw-r--r--extras/KuksaClient.py1
-rw-r--r--ui/TirePressure.ui14
6 files changed, 103 insertions, 41 deletions
diff --git a/QMLWidgets/Tire_Pressure/TirePressure.qml b/QMLWidgets/Tire_Pressure/TirePressure.qml
index 0102fba..4c02417 100644
--- a/QMLWidgets/Tire_Pressure/TirePressure.qml
+++ b/QMLWidgets/Tire_Pressure/TirePressure.qml
@@ -16,6 +16,7 @@ Item {
property color darkbg: "#131313"
property int selectedTireIndex: -1
+ signal valueChanged(int newValue)
// Move these functions here so they're accessible to all buttons
function resetAllButtons() {
@@ -33,6 +34,7 @@ Item {
function selectButton(index) {
selectedTireIndex = index;
+ valueChanged(index);
switch(index) {
case 0:
diff --git a/Scripts/record_playback.py b/Scripts/record_playback.py
index 4d067f1..0eb8e70 100644
--- a/Scripts/record_playback.py
+++ b/Scripts/record_playback.py
@@ -10,6 +10,7 @@ import argparse
from PyQt6.QtCore import QThread, pyqtSignal
import cantools
import sys
+import logging
current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.dirname(current_dir))
@@ -28,7 +29,7 @@ class CAN_playback(QThread):
try:
playbackFile = config.get_playback_file()
except Exception as e:
- print(e)
+ logging.error("Error loading playback file:", e)
# playbackFile = os.path.join(current_dir, "can_messages.txt")
def __init__(self, interface='vcan0'):
@@ -104,7 +105,11 @@ class CAN_playback(QThread):
def replay_messages(self, messages):
"""Replay CAN messages."""
# self._running = True
- start_time = messages[0].timestamp
+ try:
+ start_time = messages[0].timestamp
+ except IndexError:
+ logging.error("No messages to replay from file:", self.output_file)
+ self.reset()
for msg in messages:
if not self._running: # Check if playback should stop
@@ -161,7 +166,6 @@ class CAN_playback(QThread):
if decoded_data['PT_LeftTurnOn'] == 1:
self.indicatorUpdate.emit('LeftBlinkerOn')
- print("Left Blinker On")
if decoded_data['PT_LeftTurnOn'] == 0:
self.indicatorUpdate.emit('LeftBlinkerOff')
diff --git a/Widgets/ICPage.py b/Widgets/ICPage.py
index 3b03b35..8d426ee 100644
--- a/Widgets/ICPage.py
+++ b/Widgets/ICPage.py
@@ -32,6 +32,7 @@ from extras.VehicleSimulator import VehicleSimulator
from Scripts.record_playback import CAN_playback
import res_rc
from Widgets.animatedToggle import AnimatedToggle
+from Widgets import TirePressure
def Gauge(gaugeType):
"""QWidget
@@ -182,6 +183,8 @@ class ICWidget(Base, Form):
logging.error(f"Error creating playback object {e}")
self.TirePressureDock = self.findChild(QDockWidget, "TirePressureDock")
+ self.dockWidgetContents = self.TirePressureDock.widget()
+ self.TirePressure = self.dockWidgetContents.findChild(QWidget, "TirePressure")
self.TirePressureBtn = self.findChild(
QtWidgets.QPushButton, "TirePressureBtn")
self.TirePressureBtn.clicked.connect(self.toggle_TirePressureDock)
@@ -209,10 +212,15 @@ class ICWidget(Base, Form):
def toggle_TirePressureDock(self):
if self.TirePressureBtn.isChecked():
self.Hide_TirePressure(True)
+ self.TirePressure.kuksa_client.start()
+ print("TirePressureDock is visible")
+
self.TirePressureBtn.setChecked(True)
else:
self.Hide_TirePressure(False)
+ self.TirePressure.kuksa_client.stop()
self.TirePressureBtn.setChecked(False)
+ print("TirePressureDock is hidden")
def Hide_TirePressure(self, bool_arg):
self.TirePressureDock.setVisible(bool_arg)
@@ -270,7 +278,6 @@ class ICWidget(Base, Form):
# Update slider to reflect the gauge's value
self.Speed_slider.blockSignals(True)
self.Speed_slider.setValue(speed)
- print(speed)
self.Speed_slider.blockSignals(False)
elif source == 'slider':
@@ -286,11 +293,11 @@ class ICWidget(Base, Form):
self.Speed_Gauge.rootObject().setProperty('animationDuration', 500)
# Send updated speed to kuksa if simulator is not running
- if not self.simulator_running:
- try:
- self.kuksa_client.set(self.IC.speed, str(speed), 'value')
- except Exception as e:
- logging.error(f"Error sending values to kuksa {e}")
+ # if not self.simulator_running:
+ try:
+ threading.Thread(target=self.kuksa_client.set, args=(self.IC.speed, str(speed), 'value')).start()
+ except Exception as e:
+ logging.error(f"Error sending values to kuksa {e}")
def update_RPM(self, source, value):
"""
@@ -322,11 +329,11 @@ class ICWidget(Base, Form):
self.RPM_Gauge.rootObject().setProperty('animationDuration', 1000)
# Send updated RPM to kuksa if simulator is not running
- if not self.simulator_running:
- try:
- self.kuksa_client.set(self.IC.engineRPM, str(rpm), 'value')
- except Exception as e:
- logging.error(f"Error sending values to kuksa {e}")
+ # if not self.simulator_running:
+ try:
+ threading.Thread(target=self.kuksa_client.set, args=(self.IC.engineRPM, str(rpm), 'value')).start()
+ except Exception as e:
+ logging.error(f"Error sending values to kuksa {e}")
def update_coolantTemp(self, source, value):
"""
@@ -347,8 +354,7 @@ class ICWidget(Base, Form):
self.Coolant_Gauge.blockSignals(False)
self.Coolant_Gauge.rootObject().setProperty('animationDuration', 1000)
try:
- self.kuksa_client.set(
- self.IC.coolantTemp, str(coolantTemp), 'value')
+ threading.Thread(target=self.kuksa_client.set, args=(self.IC.coolantTemp, str(coolantTemp), 'value')).start()
except Exception as e:
logging.error(f"Error sending values to kuksa {e}")
@@ -371,7 +377,7 @@ class ICWidget(Base, Form):
self.Fuel_Gauge.blockSignals(False)
self.Fuel_Gauge.rootObject().setProperty('animationDuration', 1000)
try:
- self.kuksa_client.set(self.IC.fuelLevel, str(fuelLevel))
+ threading.Thread(target=self.kuksa_client.set, args=(self.IC.fuelLevel, str(fuelLevel), 'value')).start()
except Exception as e:
logging.error(f"Error sending values to kuksa {e}")
@@ -482,7 +488,7 @@ class ICWidget(Base, Form):
if self.Script_toggle.isChecked():
# self.Playback.start()
- print("Playback started")
+ logging.info("Starting playback")
try:
if self.Playback is None:
@@ -491,6 +497,12 @@ class ICWidget(Base, Form):
logging.error(f"Error creating playback object {e}")
self.Script_toggle.showError()
return
+ # Check if playback file exists and is not empty
+ if not os.path.exists(self.Playback.output_file) or os.stat(self.Playback.output_file).st_size == 0:
+ logging.error("Playback file, %s, does not exist or is empty", self.Playback.output_file)
+ self.Script_toggle.showError() # Show error on toggle button
+ self.Script_toggle.setChecked(False) # Uncheck the toggle
+ return
if not self.Playback.isRunning():
self.Playback.start_playback()
@@ -511,7 +523,7 @@ class ICWidget(Base, Form):
#self.Playback.finished.connect(self.Playback.deleteLater)
self.Playback = None
- print("Playback stopped")
+ logging.info("Playback stopped")
self.Speed_slider.show()
self.RPM_slider.show()
@@ -524,6 +536,8 @@ class ICWidget(Base, Form):
button.setEnabled(False)
self.set_Vehicle_RPM(1000)
self.set_Vehicle_Speed(0)
+ self.coolantTemp_slider.setValue(90)
+ self.fuelLevel_slider.setValue(50)
self.simulator_running = True
self.simulator.start()
else:
@@ -584,7 +598,7 @@ class ICWidget(Base, Form):
except Exception as e:
logging.error(f"Error sending values to kuksa {e}")
else:
- print("Unknown button checked!")
+ logging.error("No gear selected")
class AccelerationFns():
diff --git a/Widgets/TirePressure.py b/Widgets/TirePressure.py
index 0f3efce..7f2a614 100644
--- a/Widgets/TirePressure.py
+++ b/Widgets/TirePressure.py
@@ -6,11 +6,13 @@
import os
import sys
from PyQt6 import uic
-from PyQt6.QtWidgets import QApplication, QPushButton, QWidget, QLabel
+from PyQt6.QtWidgets import QApplication, QPushButton, QWidget, QLabel, QLCDNumber
+from PyQt6.QtCore import QTimer
from PyQt6.QtQuickWidgets import QQuickWidget
from PyQt6.QtWidgets import QSizePolicy
from PyQt6.QtCore import QUrl
import logging
+import json
current_dir = os.path.dirname(os.path.abspath(__file__))
@@ -18,7 +20,6 @@ current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.dirname(current_dir))
-
Form, Base = uic.loadUiType(os.path.join(current_dir, "../ui/TirePressure.ui"))
# ========================================
@@ -78,21 +79,49 @@ class TirePressure(Base, Form):
self.TPIncreaseBtn = self.findChild(QPushButton, "TPIncreaseBtn")
self.TPDecreaseBtn = self.findChild(QPushButton, "TPDecreaseBtn")
self.TPUnit = self.findChild(QLabel, "TPUnit")
+ self.TPLCD = self.findChild(QLCDNumber, "TPLCD")
+ self.TireSelector.rootObject().valueChanged.connect(self.update_TP_LCD_value)
self.TPIncreaseBtn.clicked.connect(self.increase_pressure)
self.TPDecreaseBtn.clicked.connect(self.decrease_pressure)
- def get_Current(self, tire):
+ # after 2 seconds reconnect the signals
+ QTimer.singleShot(500, self.reconnectSignals)
+
+ def reconnectSignals(self):
+ self.TireSelector.rootObject().valueChanged.connect(self.update_TP_LCD_value)
+
+ def update_TP_LCD_value(self):
"""
- Initializes the TirePressure widget.
+ Updates the value on the LCD display when a new tire is selected.
"""
-
+ selected_tire = self.TireSelector.rootObject().property("selectedTireIndex")
+ print(selected_tire)
+ tire = str(self.TirePressurePath.Tires[selected_tire])
try:
- self.TPUnit = self.kuksa_client.get("Vehicle.Cabin.Infotainment.HMI.TirePressureUnit")
- return self.kuksa_client.get(self.TirePressurePath.Tires[tire])
+ value = int(json.loads(self.kuksa_client.get(tire))["value"]["value"])
+ self.set_LCD_Value(value)
+
+ unit = str(json.loads(self.kuksa_client.get("Vehicle.Cabin.Infotainment.HMI.TirePressureUnit"))["value"]["value"])
+ self.TPUnit.setText(unit)
except Exception as e:
- logging.error(f"Error getting tire pressure values: {e}")
+ logging.error(e)
+ def set_LCD_Value(self, value):
+ """
+ Sets the value of the LCD display.
+ """
+ self.TPLCD.display(value)
+
+ def get_selected_tire_pressure(self):
+ """
+ Gets the pressure of the selected tire.
+ """
+
+ selected_tire = self.TireSelector.rootObject().property("selectedTireIndex")
+ tire = str(self.TirePressurePath.Tires[selected_tire])
+ value = int(json.loads(self.kuksa_client.get(tire))["value"]["value"])
+ return value
def increase_pressure(self):
"""
@@ -101,27 +130,31 @@ class TirePressure(Base, Form):
selected_tire = self.TireSelector.rootObject().property("selectedTireIndex")
- current_pressure = self.get_Current(selected_tire)
- if current_pressure is None:
+ if selected_tire == -1:
return
- else:
- self.kuksa_client.setValues({self.TirePressurePath.Tires[selected_tire]: current_pressure + 1})
+
+ tire = str(self.TirePressurePath.Tires[selected_tire])
+ current = self.get_selected_tire_pressure()
+ self.kuksa_client.set(tire, current + 1)
+ self.set_LCD_Value(current + 1)
def decrease_pressure(self):
"""
Decreases the pressure of the selected tire.
"""
-
+
selected_tire = self.TireSelector.rootObject().property("selectedTireIndex")
- current_pressure = self.get_Current(selected_tire)
- if current_pressure is None:
+ if selected_tire == -1:
return
- else:
- self.kuksa_client.setValues({self.TirePressurePath.Tires[selected_tire]: current_pressure - 1})
-
+ tire = str(self.TirePressurePath.Tires[selected_tire])
+ current = self.get_selected_tire_pressure()
+ self.kuksa_client.set(tire, current - 1)
+ self.set_LCD_Value(current - 1)
+
+
if __name__ == '__main__':
app = QApplication(sys.argv)
w = TirePressure()
diff --git a/extras/KuksaClient.py b/extras/KuksaClient.py
index dbffd93..af47b8a 100644
--- a/extras/KuksaClient.py
+++ b/extras/KuksaClient.py
@@ -151,6 +151,7 @@ class KuksaClient(QThread):
if self.client is None:
logging.error("Kuksa client is None, try reconnecting")
+ self.set_instance()
return
if not self.client.checkConnection():
diff --git a/ui/TirePressure.ui b/ui/TirePressure.ui
index 7387ff3..dfbaecb 100644
--- a/ui/TirePressure.ui
+++ b/ui/TirePressure.ui
@@ -241,7 +241,7 @@ QListWidget::item:hover {
</widget>
</item>
<item>
- <widget class="QLCDNumber" name="LCD">
+ <widget class="QLCDNumber" name="TPLCD">
<property name="autoFillBackground">
<bool>false</bool>
</property>
@@ -252,7 +252,7 @@ QListWidget::item:hover {
<bool>false</bool>
</property>
<property name="digitCount">
- <number>2</number>
+ <number>3</number>
</property>
<property name="segmentStyle">
<enum>QLCDNumber::Flat</enum>
@@ -261,6 +261,14 @@ QListWidget::item:hover {
</item>
<item>
<widget class="QLabel" name="TPUnit">
+ <property name="font">
+ <font>
+ <pointsize>18</pointsize>
+ <weight>75</weight>
+ <italic>true</italic>
+ <bold>true</bold>
+ </font>
+ </property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:18pt;&quot;&gt;lbp&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
@@ -268,7 +276,7 @@ QListWidget::item:hover {
<bool>true</bool>
</property>
<property name="alignment">
- <set>Qt::AlignBottom|Qt::AlignLeading|Qt::AlignLeft</set>
+ <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>