diff options
author | Suchinton Chakravarty <suchinton.2001@gmail.com> | 2024-10-30 16:13:15 +0530 |
---|---|---|
committer | Suchinton Chakravarty <suchinton.2001@gmail.com> | 2024-10-30 19:39:08 +0530 |
commit | baee04c181eb9043606797da2f223a1fafed1ae1 (patch) | |
tree | ffabbfd86e8212a878f9ae77baa0696419da88e3 /Widgets/TirePressure.py | |
parent | 18fdc7e1bcf160f8e9bbad406f1556c3d1911734 (diff) |
Bug fixes for Control PanelHEADtrout_19.90.0trout/19.90.019.90.0master
- 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/TirePressure.py')
-rw-r--r-- | Widgets/TirePressure.py | 69 |
1 files changed, 51 insertions, 18 deletions
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() |