summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Buesch <m@bues.ch>2014-12-10 17:17:37 +0100
committerMichael Buesch <m@bues.ch>2014-12-10 17:17:37 +0100
commit275a8a3e90f3fac538dfb201eea0138594d91b30 (patch)
tree83dcdf7c20ed5d4956b5ae14c3ea89a406697ab1
parentd0859040ac3fd8fba0c6546002df387206f58897 (diff)
downloadmoistcontrol-275a8a3e90f3fac538dfb201eea0138594d91b30.zip
moistcontrol-275a8a3e90f3fac538dfb201eea0138594d91b30.tar.xz
Add RTC check
Signed-off-by: Michael Buesch <m@bues.ch>
-rw-r--r--TODO2
-rw-r--r--host/pymoistcontrol/globalwidgets.py25
2 files changed, 24 insertions, 3 deletions
diff --git a/TODO b/TODO
index f14fa52..f27af4f 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,3 @@
- Add software button to force start measurement.
-- After connect check whether RTC is out of sync with PC clock.
- Offer optional sync in that case.
- Show notification-LED state on host software.
- Show on/off-switch state on host software.
diff --git a/host/pymoistcontrol/globalwidgets.py b/host/pymoistcontrol/globalwidgets.py
index dd775d5..329911d 100644
--- a/host/pymoistcontrol/globalwidgets.py
+++ b/host/pymoistcontrol/globalwidgets.py
@@ -40,6 +40,8 @@ class GlobalConfigWidget(QWidget):
self.setLayout(QGridLayout(self))
y = 0
+ self.__shouldCheckRtc = True
+
self.enableCheckBox = QCheckBox("Enable the regulator globally",
self)
self.layout().addWidget(self.enableCheckBox, y, 0, 1, 2)
@@ -159,6 +161,7 @@ class GlobalConfigWidget(QWidget):
self.enableCheckBox.setCheckState(Qt.Unchecked)
self.lowestSensorSpin.setValue(msg.sensor_lowest_value)
self.highestSensorSpin.setValue(msg.sensor_highest_value)
+ self.__shouldCheckRtc = True
self.ignoreChanges -= 1
def handlePotStateMessage(self, msg):
@@ -197,10 +200,30 @@ class GlobalConfigWidget(QWidget):
def handlePotEnableChange(self, potNumber, enabled):
self.statWidgets[potNumber].enableMessageHandling(enabled)
+ def __syncRtc(self):
+ # Sync RTC with PC clock.
+ self.rtcEditCheckBox.setCheckState(Qt.Unchecked)
+ self.rtcEdit.setDateTime(QDateTime.currentDateTime())
+ self.rtcEdited.emit()
+
def handleRtcMessage(self, msg):
self.ignoreChanges += 1
date = QDate(2000 + msg.year, msg.month + 1, msg.day + 1)
time = QTime(msg.hour, msg.minute, msg.second)
+ dateTime = QDateTime(date, time)
if self.rtcEdit.isReadOnly():
- self.rtcEdit.setDateTime(QDateTime(date, time))
+ self.rtcEdit.setDateTime(dateTime)
+ if self.__shouldCheckRtc:
+ error = QDateTime.currentDateTime().secsTo(dateTime)
+ if abs(error) > 30:
+ res = QMessageBox.question(self,
+ "Fix RTC time drift?",
+ "The RTC is off by %d seconds.\n"
+ "Do you want to synchronize the RTC "
+ "with the PC's clock?" % error,
+ QMessageBox.Yes | QMessageBox.No,
+ QMessageBox.Yes)
+ if res == QMessageBox.Yes:
+ self.__syncRtc()
+ self.__shouldCheckRtc = False
self.ignoreChanges -= 1
bues.ch cgit interface