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
Branches master
No related tags found
No related merge requests found
......@@ -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"
......
__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"
......@@ -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)
......
......@@ -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
......
......@@ -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"
......
......@@ -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"
......
......@@ -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))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment