diff --git a/actuasim.py b/actuasim.py index 8ce185711eceb165c185f682b1e8709efc3cb0fd..d3bd3b56c0c80246692c7d5569274ecf33f2e63a 100755 --- a/actuasim.py +++ b/actuasim.py @@ -21,7 +21,7 @@ from actuasim.command_handler import CommandHandler __author__ = "Adrien Lescourt" __copyright__ = "HES-SO 2015, Project EMG4B" __credits__ = ["Adrien Lescourt"] -__version__ = "1.0.1" +__version__ = "1.0.2" __email__ = "adrien.lescourt@gmail.com" __status__ = "Prototype" diff --git a/actuasim/__init__.py b/actuasim/__init__.py index f3fc50b59d0af9df46af072957e8c192105e2c91..2ab12b719def4a2d3c687d82bb7915d450885cca 100644 --- a/actuasim/__init__.py +++ b/actuasim/__init__.py @@ -1,6 +1,6 @@ __author__ = "Adrien Lescourt" __copyright__ = "HES-SO 2015, Project EMG4B" __credits__ = ["Adrien Lescourt"] -__version__ = "1.0.1" +__version__ = "1.0.2" __email__ = "adrien.lescourt@gmail.com" __status__ = "Prototype" diff --git a/actuasim/blind.py b/actuasim/blind.py index b22fd57dde6578eac8232eba20fff242243ccfd4..ac9f7d95f2196542226f4633447e0dbf217266ad 100644 --- a/actuasim/blind.py +++ b/actuasim/blind.py @@ -11,12 +11,15 @@ from actuasim.ui_blind import Ui_Blind __author__ = "Adrien Lescourt" __copyright__ = "HES-SO 2015, Project EMG4B" __credits__ = ["Adrien Lescourt"] -__version__ = "1.0.1" +__version__ = "1.0.2" __email__ = "adrien.lescourt@gmail.com" __status__ = "Prototype" class BlindWidget(QWidget): + + MAX_PROGRESS_BAR = 255 + def __init__(self, individual_address, group_address, blind_position=0, animation_speed_ms=1500): super(BlindWidget, self).__init__() @@ -32,6 +35,7 @@ class BlindWidget(QWidget): self.is_moving = False self.animation_speed = animation_speed_ms self.animate_progress = QPropertyAnimation(self.ui.progressBar, QByteArray(bytes('value', 'utf-8'))) + self.ui.progressBar.setMaximum(BlindWidget.MAX_PROGRESS_BAR) self.ui.progressBar.setValue(0) self.position = blind_position self.setFixedWidth(220) @@ -56,8 +60,8 @@ class BlindWidget(QWidget): def position(self, value): if value < 0: value = 0 - if value > 100: - value = 100 + if value > BlindWidget.MAX_PROGRESS_BAR: + value = BlindWidget.MAX_PROGRESS_BAR self.animate_progressbar(value) def update_position_value(self): @@ -83,7 +87,7 @@ class BlindWidget(QWidget): def move_up(self): self.logger.info('Blind ' + self.address_str + ' UP') self.animation_finished() - self.animate_progressbar(100) + self.animate_progressbar(BlindWidget.MAX_PROGRESS_BAR) def move_to(self, value): self.logger.info('Blind ' + self.address_str + ' MOVE TO %s' % value) @@ -93,7 +97,7 @@ class BlindWidget(QWidget): def animate_progressbar(self, end_value): if end_value == self.ui.progressBar.value(): return - blind_move_speed_ratio = abs(self.ui.progressBar.value()-end_value)/100 + blind_move_speed_ratio = abs(self.ui.progressBar.value()-end_value)/BlindWidget.MAX_PROGRESS_BAR self.animate_progress.setDuration(self.animation_speed*blind_move_speed_ratio) self.animate_progress.setStartValue(self.ui.progressBar.value()) self.animate_progress.setEndValue(end_value) diff --git a/actuasim/command_handler.py b/actuasim/command_handler.py index fec90a5a6a324fe90548d2587e4e0c4084a5f8b6..c4816ce258e9c2109d7c1e0083370b0ae1acb1b4 100644 --- a/actuasim/command_handler.py +++ b/actuasim/command_handler.py @@ -5,7 +5,7 @@ from knxnet import * __author__ = "Adrien Lescourt" __copyright__ = "HES-SO 2015, Project EMG4B" __credits__ = ["Adrien Lescourt"] -__version__ = "1.0.1" +__version__ = "1.0.2" __email__ = "adrien.lescourt@gmail.com" __status__ = "Prototype" @@ -45,7 +45,7 @@ class CommandHandler: return tunnel_req_response # write elif tunnelling_request.apci == 2: - valve.position = int(tunnelling_request.data / 0xFF * 100) + valve.position = tunnelling_request.data else: self.actuasim.logger.error('Destination address group not found in the simulator: ' + str(tunnelling_request.dest_addr_group)) @@ -55,8 +55,7 @@ class CommandHandler: if blind is not None: if tunnelling_request.dest_addr_group.main_group == 3: value = tunnelling_request.data - blind_value = int(value * (100 / 255)) # [0-255] to [0-100] - blind.move_to(blind_value) + blind.move_to(value) elif tunnelling_request.data == 0: blind.move_up() elif tunnelling_request.data == 1: @@ -68,7 +67,7 @@ class CommandHandler: def _ask_blind_short(self, tunnelling_request): blind = self._get_blind_from_group_address(tunnelling_request.dest_addr_group) if blind is not None: - data = int(blind.position / 100 * 0xFF) + data = blind.position data_size = 2 apci = 1 data_service = 0x29 diff --git a/actuasim/knxserver.py b/actuasim/knxserver.py index 251d0cedecff866def72cedc6aa5a1a029c60b9a..4d634b93da0377957478e3c3156805a83120d25b 100644 --- a/actuasim/knxserver.py +++ b/actuasim/knxserver.py @@ -7,7 +7,7 @@ from PyQt5.QtCore import QObject, pyqtSignal __author__ = "Adrien Lescourt" __copyright__ = "HES-SO 2015, Project EMG4B" __credits__ = ["Adrien Lescourt"] -__version__ = "1.0.1" +__version__ = "1.0.2" __email__ = "adrien.lescourt@gmail.com" __status__ = "Prototype" diff --git a/actuasim/room.py b/actuasim/room.py index 720df09f19b6900c537ae47fdeb72a05b21ef0a3..23ccf45f47ae99681180c52bd8459462f05b16c7 100644 --- a/actuasim/room.py +++ b/actuasim/room.py @@ -9,7 +9,7 @@ from knxnet.utils import * __author__ = "Adrien Lescourt" __copyright__ = "HES-SO 2015, Project EMG4B" __credits__ = ["Adrien Lescourt"] -__version__ = "1.0.1" +__version__ = "1.0.2" __email__ = "adrien.lescourt@gmail.com" __status__ = "Prototype" diff --git a/actuasim/valve.py b/actuasim/valve.py index 4ad17571d66c42fa70aa341f4fae336055393d68..7634b2aa52b5ce1baef82d398819701bd3cddf86 100644 --- a/actuasim/valve.py +++ b/actuasim/valve.py @@ -14,12 +14,15 @@ from actuasim.ui_valve import Ui_Valve __author__ = "Adrien Lescourt" __copyright__ = "HES-SO 2015, Project EMG4B" __credits__ = ["Adrien Lescourt"] -__version__ = "1.0.1" +__version__ = "1.0.2" __email__ = "adrien.lescourt@gmail.com" __status__ = "Prototype" class ValveWidget(QWidget): + + MAX_PROGRESS_BAR = 255 + def __init__(self, individual_address, group_address, valve_position=45, animation_speed_ms=1500): super(ValveWidget, self).__init__() self.ui = Ui_Valve() @@ -58,8 +61,8 @@ class ValveWidget(QWidget): self._position = value if self._position < 0: self._position = 0 - if self._position > 100: - self._position = 100 + if self._position > ValveWidget.MAX_PROGRESS_BAR: + self._position = ValveWidget.MAX_PROGRESS_BAR self.logger.info('Valve ' + self.address_str + ' = ' + str(self._position)) self.ui.labelPositionValue.setText(str(self._position)) self.repaint() @@ -74,6 +77,8 @@ class ValveWidget(QWidget): painter = QPainter(self) painter.setRenderHint(int(QPainter.SmoothPixmapTransform) | int(QPainter.Antialiasing)) painter.drawImage(self.temperature_bar_rect, self.temperature_bar_image) - x = self.line_origin.x() + self.line_length * sin(radians((100-self.position)*1.8+90)) - y = self.line_origin.y() + self.line_length * cos(radians((100-self.position)*1.8+90)) + to_180_degree = 180 / ValveWidget.MAX_PROGRESS_BAR + angle = (ValveWidget.MAX_PROGRESS_BAR - self.position) * to_180_degree + 90 + x = self.line_origin.x() + self.line_length * sin(radians(angle)) + y = self.line_origin.y() + self.line_length * cos(radians(angle)) painter.drawLine(self.line_origin, QPoint(x, y))