Skip to content
Snippets Groups Projects
Commit 47cdea30 authored by Adrien Lescourt's avatar Adrien Lescourt
Browse files

Remove percent. Blind and valves values are bytes

parent ef91eb17
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ from actuasim.command_handler import CommandHandler ...@@ -21,7 +21,7 @@ from actuasim.command_handler import CommandHandler
__author__ = "Adrien Lescourt" __author__ = "Adrien Lescourt"
__copyright__ = "HES-SO 2015, Project EMG4B" __copyright__ = "HES-SO 2015, Project EMG4B"
__credits__ = ["Adrien Lescourt"] __credits__ = ["Adrien Lescourt"]
__version__ = "1.0.1" __version__ = "1.0.2"
__email__ = "adrien.lescourt@gmail.com" __email__ = "adrien.lescourt@gmail.com"
__status__ = "Prototype" __status__ = "Prototype"
......
__author__ = "Adrien Lescourt" __author__ = "Adrien Lescourt"
__copyright__ = "HES-SO 2015, Project EMG4B" __copyright__ = "HES-SO 2015, Project EMG4B"
__credits__ = ["Adrien Lescourt"] __credits__ = ["Adrien Lescourt"]
__version__ = "1.0.1" __version__ = "1.0.2"
__email__ = "adrien.lescourt@gmail.com" __email__ = "adrien.lescourt@gmail.com"
__status__ = "Prototype" __status__ = "Prototype"
...@@ -11,12 +11,15 @@ from actuasim.ui_blind import Ui_Blind ...@@ -11,12 +11,15 @@ from actuasim.ui_blind import Ui_Blind
__author__ = "Adrien Lescourt" __author__ = "Adrien Lescourt"
__copyright__ = "HES-SO 2015, Project EMG4B" __copyright__ = "HES-SO 2015, Project EMG4B"
__credits__ = ["Adrien Lescourt"] __credits__ = ["Adrien Lescourt"]
__version__ = "1.0.1" __version__ = "1.0.2"
__email__ = "adrien.lescourt@gmail.com" __email__ = "adrien.lescourt@gmail.com"
__status__ = "Prototype" __status__ = "Prototype"
class BlindWidget(QWidget): class BlindWidget(QWidget):
MAX_PROGRESS_BAR = 255
def __init__(self, individual_address, group_address, blind_position=0, animation_speed_ms=1500): def __init__(self, individual_address, group_address, blind_position=0, animation_speed_ms=1500):
super(BlindWidget, self).__init__() super(BlindWidget, self).__init__()
...@@ -32,6 +35,7 @@ class BlindWidget(QWidget): ...@@ -32,6 +35,7 @@ class BlindWidget(QWidget):
self.is_moving = False self.is_moving = False
self.animation_speed = animation_speed_ms self.animation_speed = animation_speed_ms
self.animate_progress = QPropertyAnimation(self.ui.progressBar, QByteArray(bytes('value', 'utf-8'))) 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.ui.progressBar.setValue(0)
self.position = blind_position self.position = blind_position
self.setFixedWidth(220) self.setFixedWidth(220)
...@@ -56,8 +60,8 @@ class BlindWidget(QWidget): ...@@ -56,8 +60,8 @@ class BlindWidget(QWidget):
def position(self, value): def position(self, value):
if value < 0: if value < 0:
value = 0 value = 0
if value > 100: if value > BlindWidget.MAX_PROGRESS_BAR:
value = 100 value = BlindWidget.MAX_PROGRESS_BAR
self.animate_progressbar(value) self.animate_progressbar(value)
def update_position_value(self): def update_position_value(self):
...@@ -83,7 +87,7 @@ class BlindWidget(QWidget): ...@@ -83,7 +87,7 @@ class BlindWidget(QWidget):
def move_up(self): def move_up(self):
self.logger.info('Blind ' + self.address_str + ' UP') self.logger.info('Blind ' + self.address_str + ' UP')
self.animation_finished() self.animation_finished()
self.animate_progressbar(100) self.animate_progressbar(BlindWidget.MAX_PROGRESS_BAR)
def move_to(self, value): def move_to(self, value):
self.logger.info('Blind ' + self.address_str + ' MOVE TO %s' % value) self.logger.info('Blind ' + self.address_str + ' MOVE TO %s' % value)
...@@ -93,7 +97,7 @@ class BlindWidget(QWidget): ...@@ -93,7 +97,7 @@ class BlindWidget(QWidget):
def animate_progressbar(self, end_value): def animate_progressbar(self, end_value):
if end_value == self.ui.progressBar.value(): if end_value == self.ui.progressBar.value():
return 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.setDuration(self.animation_speed*blind_move_speed_ratio)
self.animate_progress.setStartValue(self.ui.progressBar.value()) self.animate_progress.setStartValue(self.ui.progressBar.value())
self.animate_progress.setEndValue(end_value) self.animate_progress.setEndValue(end_value)
......
...@@ -5,7 +5,7 @@ from knxnet import * ...@@ -5,7 +5,7 @@ from knxnet import *
__author__ = "Adrien Lescourt" __author__ = "Adrien Lescourt"
__copyright__ = "HES-SO 2015, Project EMG4B" __copyright__ = "HES-SO 2015, Project EMG4B"
__credits__ = ["Adrien Lescourt"] __credits__ = ["Adrien Lescourt"]
__version__ = "1.0.1" __version__ = "1.0.2"
__email__ = "adrien.lescourt@gmail.com" __email__ = "adrien.lescourt@gmail.com"
__status__ = "Prototype" __status__ = "Prototype"
...@@ -45,7 +45,7 @@ class CommandHandler: ...@@ -45,7 +45,7 @@ class CommandHandler:
return tunnel_req_response return tunnel_req_response
# write # write
elif tunnelling_request.apci == 2: elif tunnelling_request.apci == 2:
valve.position = int(tunnelling_request.data / 0xFF * 100) valve.position = tunnelling_request.data
else: else:
self.actuasim.logger.error('Destination address group not found in the simulator: ' + self.actuasim.logger.error('Destination address group not found in the simulator: ' +
str(tunnelling_request.dest_addr_group)) str(tunnelling_request.dest_addr_group))
...@@ -55,8 +55,7 @@ class CommandHandler: ...@@ -55,8 +55,7 @@ class CommandHandler:
if blind is not None: if blind is not None:
if tunnelling_request.dest_addr_group.main_group == 3: if tunnelling_request.dest_addr_group.main_group == 3:
value = tunnelling_request.data value = tunnelling_request.data
blind_value = int(value * (100 / 255)) # [0-255] to [0-100] blind.move_to(value)
blind.move_to(blind_value)
elif tunnelling_request.data == 0: elif tunnelling_request.data == 0:
blind.move_up() blind.move_up()
elif tunnelling_request.data == 1: elif tunnelling_request.data == 1:
...@@ -68,7 +67,7 @@ class CommandHandler: ...@@ -68,7 +67,7 @@ class CommandHandler:
def _ask_blind_short(self, tunnelling_request): def _ask_blind_short(self, tunnelling_request):
blind = self._get_blind_from_group_address(tunnelling_request.dest_addr_group) blind = self._get_blind_from_group_address(tunnelling_request.dest_addr_group)
if blind is not None: if blind is not None:
data = int(blind.position / 100 * 0xFF) data = blind.position
data_size = 2 data_size = 2
apci = 1 apci = 1
data_service = 0x29 data_service = 0x29
......
...@@ -7,7 +7,7 @@ from PyQt5.QtCore import QObject, pyqtSignal ...@@ -7,7 +7,7 @@ from PyQt5.QtCore import QObject, pyqtSignal
__author__ = "Adrien Lescourt" __author__ = "Adrien Lescourt"
__copyright__ = "HES-SO 2015, Project EMG4B" __copyright__ = "HES-SO 2015, Project EMG4B"
__credits__ = ["Adrien Lescourt"] __credits__ = ["Adrien Lescourt"]
__version__ = "1.0.1" __version__ = "1.0.2"
__email__ = "adrien.lescourt@gmail.com" __email__ = "adrien.lescourt@gmail.com"
__status__ = "Prototype" __status__ = "Prototype"
......
...@@ -9,7 +9,7 @@ from knxnet.utils import * ...@@ -9,7 +9,7 @@ from knxnet.utils import *
__author__ = "Adrien Lescourt" __author__ = "Adrien Lescourt"
__copyright__ = "HES-SO 2015, Project EMG4B" __copyright__ = "HES-SO 2015, Project EMG4B"
__credits__ = ["Adrien Lescourt"] __credits__ = ["Adrien Lescourt"]
__version__ = "1.0.1" __version__ = "1.0.2"
__email__ = "adrien.lescourt@gmail.com" __email__ = "adrien.lescourt@gmail.com"
__status__ = "Prototype" __status__ = "Prototype"
......
...@@ -14,12 +14,15 @@ from actuasim.ui_valve import Ui_Valve ...@@ -14,12 +14,15 @@ from actuasim.ui_valve import Ui_Valve
__author__ = "Adrien Lescourt" __author__ = "Adrien Lescourt"
__copyright__ = "HES-SO 2015, Project EMG4B" __copyright__ = "HES-SO 2015, Project EMG4B"
__credits__ = ["Adrien Lescourt"] __credits__ = ["Adrien Lescourt"]
__version__ = "1.0.1" __version__ = "1.0.2"
__email__ = "adrien.lescourt@gmail.com" __email__ = "adrien.lescourt@gmail.com"
__status__ = "Prototype" __status__ = "Prototype"
class ValveWidget(QWidget): class ValveWidget(QWidget):
MAX_PROGRESS_BAR = 255
def __init__(self, individual_address, group_address, valve_position=45, animation_speed_ms=1500): def __init__(self, individual_address, group_address, valve_position=45, animation_speed_ms=1500):
super(ValveWidget, self).__init__() super(ValveWidget, self).__init__()
self.ui = Ui_Valve() self.ui = Ui_Valve()
...@@ -58,8 +61,8 @@ class ValveWidget(QWidget): ...@@ -58,8 +61,8 @@ class ValveWidget(QWidget):
self._position = value self._position = value
if self._position < 0: if self._position < 0:
self._position = 0 self._position = 0
if self._position > 100: if self._position > ValveWidget.MAX_PROGRESS_BAR:
self._position = 100 self._position = ValveWidget.MAX_PROGRESS_BAR
self.logger.info('Valve ' + self.address_str + ' = ' + str(self._position)) self.logger.info('Valve ' + self.address_str + ' = ' + str(self._position))
self.ui.labelPositionValue.setText(str(self._position)) self.ui.labelPositionValue.setText(str(self._position))
self.repaint() self.repaint()
...@@ -74,6 +77,8 @@ class ValveWidget(QWidget): ...@@ -74,6 +77,8 @@ class ValveWidget(QWidget):
painter = QPainter(self) painter = QPainter(self)
painter.setRenderHint(int(QPainter.SmoothPixmapTransform) | int(QPainter.Antialiasing)) painter.setRenderHint(int(QPainter.SmoothPixmapTransform) | int(QPainter.Antialiasing))
painter.drawImage(self.temperature_bar_rect, self.temperature_bar_image) 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)) to_180_degree = 180 / ValveWidget.MAX_PROGRESS_BAR
y = self.line_origin.y() + self.line_length * cos(radians((100-self.position)*1.8+90)) 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)) painter.drawLine(self.line_origin, QPoint(x, y))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment