aboutsummaryrefslogtreecommitdiffstats
path: root/Widgets
diff options
context:
space:
mode:
authorSuchinton Chakravarty <suchinton.2001@gmail.com>2024-10-30 16:13:15 +0530
committerSuchinton Chakravarty <suchinton.2001@gmail.com>2024-10-30 19:39:08 +0530
commitbaee04c181eb9043606797da2f223a1fafed1ae1 (patch)
treeffabbfd86e8212a878f9ae77baa0696419da88e3 /Widgets
parent18fdc7e1bcf160f8e9bbad406f1556c3d1911734 (diff)
- Fixed Stutter while setting values using slider (when databroker is connected), Caused due to the values being sent at every step on main thread. - Improved error handeling if playback file is empty/ not found - Fixed Tire pressure values not being sent when connected to databroker - Selected tire pressure value and unit is updated on LCD display as selected Bug-AGL: SPEC-5161 Change-Id: I66ed5f2e36bd0b0a84743e2c2a8af0de955cf4ba Signed-off-by: Suchinton Chakravarty <suchinton.2001@gmail.com>
Diffstat (limited to 'Widgets')
-rw-r--r--Widgets/ICPage.py48
-rw-r--r--Widgets/TirePressure.py69
2 files changed, 82 insertions, 35 deletions
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()