summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Buesch <m@bues.ch>2014-12-10 18:20:26 +0100
committerMichael Buesch <m@bues.ch>2014-12-10 18:20:26 +0100
commitf2246437360217aee4f4c2ed7e1242a916a1bb59 (patch)
tree6191de8b5cf2b249e986cb6600851854aec4c495
parent394d5d20d2d6c16988d9fc6b140283699691ea9c (diff)
downloadmoistcontrol-f2246437360217aee4f4c2ed7e1242a916a1bb59.zip
moistcontrol-f2246437360217aee4f4c2ed7e1242a916a1bb59.tar.xz
gui: Show global state
Signed-off-by: Michael Buesch <m@bues.ch>
-rw-r--r--TODO2
-rwxr-xr-xhost/moistcontrol-gui10
-rw-r--r--host/pymoistcontrol/globalwidgets.py14
-rw-r--r--host/pymoistcontrol/messages.py32
4 files changed, 54 insertions, 4 deletions
diff --git a/TODO b/TODO
index f27af4f..b56fd20 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1 @@
- Add software button to force start measurement.
-- Show notification-LED state on host software.
-- Show on/off-switch state on host software.
diff --git a/host/moistcontrol-gui b/host/moistcontrol-gui
index 837502b..be94b59 100755
--- a/host/moistcontrol-gui
+++ b/host/moistcontrol-gui
@@ -43,6 +43,7 @@ class MainWidget(QWidget):
serialDisconnected = Signal()
fetchCycle = [
+ "global_state",
"log",
"rtc",
"pot_state",
@@ -206,7 +207,9 @@ class MainWidget(QWidget):
def __fetchCycleNext(self):
action = self.fetchCycle[self.fetchCycleNumber]
try:
- if action == "log":
+ if action == "global_state":
+ msg = MsgContrStateFetch()
+ elif action == "log":
msg = MsgLogFetch()
elif action == "rtc":
msg = MsgRtcFetch()
@@ -296,7 +299,10 @@ class MainWidget(QWidget):
advanceFetchCycle = True
action = self.fetchCycle[self.fetchCycleNumber]
- if action == "log":
+ if action == "global_state":
+ if self.__checkRxMsg(msg, Message.MSG_CONTR_STATE):
+ self.globConfWidget.handleGlobalStateMessage(msg)
+ elif action == "log":
if self.__checkRxMsg(msg, Message.MSG_LOG,
ignoreErrorCode = True):
if error == Message.COMM_ERR_OK:
diff --git a/host/pymoistcontrol/globalwidgets.py b/host/pymoistcontrol/globalwidgets.py
index 329911d..a8de90e 100644
--- a/host/pymoistcontrol/globalwidgets.py
+++ b/host/pymoistcontrol/globalwidgets.py
@@ -77,6 +77,10 @@ class GlobalConfigWidget(QWidget):
self.layout().addWidget(potStatWidget, y, 1)
y += 1
+ self.stateLabel = QLabel(self)
+ self.layout().addWidget(self.stateLabel, y, 0, 1, 2)
+ y += 1
+
self.advancedCheckBox = QCheckBox("Advanced", self)
self.layout().addWidget(self.advancedCheckBox, y, 0, 1, 2)
y += 1
@@ -164,6 +168,16 @@ class GlobalConfigWidget(QWidget):
self.__shouldCheckRtc = True
self.ignoreChanges -= 1
+ def handleGlobalStateMessage(self, msg):
+ text = []
+ if msg.flags & msg.CONTRSTAT_ONOFFSWITCH:
+ text.append("Hardware switch is on")
+ else:
+ text.append("Hardware switch is OFF")
+ if msg.flags & msg.CONTRSTAT_NOTIFLED:
+ text.append("Notification LED is ON")
+ self.stateLabel.setText("; ".join(text))
+
def handlePotStateMessage(self, msg):
self.ignoreChanges += 1
self.statWidgets[msg.pot_number].handlePotStateMessage(msg)
diff --git a/host/pymoistcontrol/messages.py b/host/pymoistcontrol/messages.py
index d80c20e..d23e4a3 100644
--- a/host/pymoistcontrol/messages.py
+++ b/host/pymoistcontrol/messages.py
@@ -30,6 +30,8 @@ class Message(SerialMessage):
MSG_CONTR_POT_REM_STATE_FETCH = 11
MSG_MAN_MODE = 12
MSG_MAN_MODE_FETCH = 13
+ MSG_CONTR_STATE = 14
+ MSG_CONTR_STATE_FETCH = 15
@classmethod
def fromRawMessage(cls, rawMsg):
@@ -102,6 +104,10 @@ class Message(SerialMessage):
flags = rawMsg.payload[4])
elif msgId == cls.MSG_MAN_MODE_FETCH:
msg = MsgManModeFetch()
+ elif msgId == cls.MSG_CONTR_STATE:
+ msg = MsgContrState(flags = rawMsg.payload[1])
+ elif msgId == cls.MSG_CONTR_STATE_FETCH:
+ msg = MsgContrStateFetch()
else:
raise Error("Unknown message ID: %d" % msgId)
msg.copyHeaderFrom(rawMsg)
@@ -480,3 +486,29 @@ class MsgManModeFetch(Message):
def getPayload(self):
return bytes([ self.getType(), ])
+
+class MsgContrState(Message):
+ CONTRSTAT_ONOFFSWITCH = 1 << 0
+ CONTRSTAT_NOTIFLED = 1 << 1
+
+ def __init__(self,
+ flags = 0):
+ self.flags = flags
+ Message.__init__(self)
+
+ def getType(self):
+ return self.MSG_CONTR_STATE
+
+ def getPayload(self):
+ return bytes([ self.getType(),
+ self.flags, ])
+
+class MsgContrStateFetch(Message):
+ def __init__(self):
+ Message.__init__(self, fc = Message.COMM_FC_REQ_ACK)
+
+ def getType(self):
+ return self.MSG_CONTR_STATE_FETCH
+
+ def getPayload(self):
+ return bytes([ self.getType(), ])
bues.ch cgit interface