diff options
author | suchinton2001 <suchinton.2001@gmail.com> | 2023-10-20 15:50:09 +0530 |
---|---|---|
committer | suchinton2001 <suchinton.2001@gmail.com> | 2023-10-23 00:19:17 +0530 |
commit | 9af16ad7272f4e1d068004fc4443db5d14f89b3c (patch) | |
tree | 79871060d0157332ca971fcbe1c86f02f61419fa /extras | |
parent | 20fe2d131df0041e121eccaf4fc58d4ac88dfbbc (diff) |
agl-demo-control-panel: Fix Svg icons scaling on Dashboard
V1:
- Use QtSvg to set icons for dashboard icons
- Update Readme and install_package script for docker image
V2: Clean up code and improve formatting
V3:
- Increase font size for UI files
- Fix HVAC bug, Control panel no longer
crashes when Temp goes out of range
- Refactor blocking subscription updates when CP in use
Bug-AGL: SPEC-4939
Signed-off-by: suchinton2001 <suchinton.2001@gmail.com>
Change-Id: I4f256d29fac614dd3e3c4193c2a08b230359906e
Diffstat (limited to 'extras')
-rw-r--r-- | extras/FeedCAN.py | 11 | ||||
-rw-r--r-- | extras/FeedKuksa.py | 23 | ||||
-rw-r--r-- | extras/Kuksa_Instance.py | 7 | ||||
-rw-r--r-- | extras/UI_Handeler.py | 58 |
4 files changed, 52 insertions, 47 deletions
diff --git a/extras/FeedCAN.py b/extras/FeedCAN.py index 9cd01d5..1282e61 100644 --- a/extras/FeedCAN.py +++ b/extras/FeedCAN.py @@ -17,6 +17,7 @@ import can import logging + def send_can_signal(frame): """ Sends a CAN signal to the CAN bus using the given frame. @@ -26,7 +27,7 @@ def send_can_signal(frame): None """ msg = separate_can_frame(frame) - + try: bus = can.interface.Bus(channel='can0', bustype='socketcan') except Exception as e: @@ -38,7 +39,7 @@ def send_can_signal(frame): print("CAN signal sent successfully:") print("CAN ID:", hex(msg.arbitration_id)) print("Data:", msg.data) - if frame!="021#FFFFFFFF00000000": + if frame != "021#FFFFFFFF00000000": # Turn off signal send_can_signal("021#FFFFFFFF00000000") @@ -47,13 +48,14 @@ def send_can_signal(frame): finally: bus.shutdown() + def separate_can_frame(frame): """ Separates a CAN frame into its arbitration ID and data parts. - + Args: frame (str): A string representing the CAN frame in the format "ARBID#DATA". - + Returns: can.Message: A can.Message object with the arbitration ID and data extracted from the input frame. """ @@ -68,5 +70,6 @@ def main(): frame = "021#FFFFFFFF10000000" send_can_signal(frame) + if __name__ == "__main__": main() diff --git a/extras/FeedKuksa.py b/extras/FeedKuksa.py index cda2a30..75846d5 100644 --- a/extras/FeedKuksa.py +++ b/extras/FeedKuksa.py @@ -16,13 +16,12 @@ import logging from PyQt5.QtCore import QThread -from PyQt5.QtCore import pyqtSignal +from PyQt5.QtCore import pyqtSignal, QObject from . import Kuksa_Instance as kuksa_instance +from . import UI_Handeler import threading class FeedKuksa(QThread): - sending_values = pyqtSignal() - finished_sending_values = pyqtSignal() """ A class to handle sending values to Kuksa. @@ -35,6 +34,9 @@ class FeedKuksa(QThread): client : kuksa_instance.KuksaClientSingleton.instance().client A client object to interact with the Kuksa server. """ + + sending_values = pyqtSignal() + finished_sending_values = pyqtSignal() def __init__(self, parent=None): """ @@ -45,9 +47,12 @@ class FeedKuksa(QThread): parent : QObject The parent object of the FeedKuksa object. """ - QThread.__init__(self,parent) + QThread.__init__(self, parent) self.stop_flag = False + self.sending_values.connect(UI_Handeler.UI_Handeler.block_updates) + self.finished_sending_values.connect(UI_Handeler.UI_Handeler.unblock_updates) + def run(self): """ Starts the thread and sets the instance of the Kuksa client. @@ -60,7 +65,7 @@ class FeedKuksa(QThread): Stops the thread. """ self.stop_flag = True - + logging.info("Stopping thread") def set_instance(self): @@ -88,7 +93,7 @@ class FeedKuksa(QThread): Exception If there is an error sending values to Kuksa. """ - + if self.client is None: logging.error("Kuksa client is None, try reconnecting") return @@ -102,11 +107,11 @@ class FeedKuksa(QThread): if attribute is not None: self.sending_values.emit() self.client.setValue(path, value, attribute) + self.finished_sending_values.emit() else: self.sending_values.emit() self.client.setValue(path, value) - - self.finished_sending_values.emit() + self.finished_sending_values.emit() except Exception as e: logging.error(f"Error sending values to kuksa {e}") - threading.Thread(target=self.set_instance).start()
\ No newline at end of file + threading.Thread(target=self.set_instance).start() diff --git a/extras/Kuksa_Instance.py b/extras/Kuksa_Instance.py index 1ff8056..cda539e 100644 --- a/extras/Kuksa_Instance.py +++ b/extras/Kuksa_Instance.py @@ -19,6 +19,7 @@ import kuksa_client as kuksa import threading import time + class KuksaClientSingleton: """ A singleton class that provides a single instance of KuksaClientThread. @@ -88,7 +89,7 @@ class KuksaClientSingleton: """ if self.client: self.client.stop() - + self.client = kuksa.KuksaClientThread(config) self.client.authorize(token) self.client.start() @@ -104,7 +105,7 @@ class KuksaClientSingleton: return self.client else: return None - + def get_config(self): """ Returns the configuration. @@ -128,4 +129,4 @@ class KuksaClientSingleton: Stops the client instance. """ if self.client: - self.client.stop()
\ No newline at end of file + self.client.stop() diff --git a/extras/UI_Handeler.py b/extras/UI_Handeler.py index 261df94..3e653e4 100644 --- a/extras/UI_Handeler.py +++ b/extras/UI_Handeler.py @@ -20,32 +20,26 @@ from PyQt5.QtCore import QPropertyAnimation from PyQt5.QtWidgets import QWidget from PyQt5.QtCore import QEasingCurve from PyQt5.QtWidgets import QGraphicsOpacityEffect -from PyQt5.QtWidgets import QDesktopWidget import logging import json -from . import FeedKuksa as feed_kuksa from . import Kuksa_Instance as kuksa_instance # Global variables subscribed = False -should_execute_callback = True block_subscription_updates = False + class UI_Handeler(MainWindow): - """ - This class handles the UI of the AGL Demo Control Panel application. - """ - def __init__(self): - self.feed_kuksa = feed_kuksa.FeedKuksa() - self.feed_kuksa.sending_values.connect(self.block_updates) - self.feed_kuksa.finished_sending_values.connect(self.unblock_updates) - - def block_updates(self): + + def display_sending_message(self): + print("message sent") + + def block_updates(): global block_subscription_updates block_subscription_updates = True - def unblock_updates(self): + def unblock_updates(): global block_subscription_updates block_subscription_updates = False @@ -59,7 +53,8 @@ class UI_Handeler(MainWindow): height = self.BottomMenuSubContainer.height() heightExtended = 75 if bool_arg else 0 - self.animation = QPropertyAnimation(self.BottomMenuSubContainer, b"minimumHeight") + self.animation = QPropertyAnimation( + self.BottomMenuSubContainer, b"minimumHeight") self.animation.setDuration(400) self.animation.setStartValue(height) self.animation.setEndValue(heightExtended) @@ -73,7 +68,8 @@ class UI_Handeler(MainWindow): Args: - index: The index of the page to switch to. """ - self.fader_widget = FaderWidget(self.stackedWidget.currentWidget(), self.stackedWidget.widget(index)) + self.fader_widget = FaderWidget( + self.stackedWidget.currentWidget(), self.stackedWidget.widget(index)) self.stackedWidget.setCurrentIndex(index) def toggleMaximized(self): @@ -96,30 +92,28 @@ class UI_Handeler(MainWindow): self.move(self.pos() + event.globalPos() - self.clickPosition) self.clickPosition = event.globalPos() event.accept() - + def mousePressEvent(self, event): self.clickPosition = event.globalPos() event.accept() - + def mouseReleaseEvent(self, event): self.clickPosition = None event.accept() - - def set_instance(self): - """ - This method sets the instance of the Kuksa client. - Returns: - - True if the client is connected to Kuksa, False otherwise. - """ + def set_instance(self): self.kuksa = kuksa_instance.KuksaClientSingleton.instance() self.client = self.kuksa.get_client() if self.client is not None and self.client.checkConnection(): return True else: - print("No connection to Kuksa") + logging.error("Kuksa client is not connected, try reconnecting") return False + def stop_client(self): + if self.client is not None and self.client.checkConnection(): + self.client.stop() + def subscribe_VSS_Signals(self): """ This method subscribes to the VSS signals from Kuksa. @@ -144,13 +138,15 @@ class UI_Handeler(MainWindow): "Vehicle.Cabin.HVAC.Station.Row1.Right.FanSpeed"] for signal in signals: - self.client.subscribe(signal, lambda data: UI_Handeler.VSS_callback(self,data), 'value') + self.client.subscribe( + signal, lambda data: UI_Handeler.VSS_callback(self, data), 'value') subscribed = True else: subscribed = False - print("No connection to Kuksa") + logging.error( + "Kuksa client is not connected, try reconnecting") - def VSS_callback(self,data): + def VSS_callback(self, data): """ This method is the callback function for the VSS signals from Kuksa. @@ -160,7 +156,7 @@ class UI_Handeler(MainWindow): global block_subscription_updates if block_subscription_updates: return - + IC_Page = self.stackedWidget.widget(1) HVAC_Page = self.stackedWidget.widget(2) @@ -219,7 +215,7 @@ class UI_Handeler(MainWindow): class FaderWidget(QWidget): def __init__(self, old_widget, new_widget): super().__init__(new_widget) - + self.old_widget = old_widget self.new_widget = new_widget @@ -241,4 +237,4 @@ class FaderWidget(QWidget): def close(self): self.old_widget.close() self.new_widget.show() - super().close()
\ No newline at end of file + super().close() |