Skip to content

Commit

Permalink
moving files
Browse files Browse the repository at this point in the history
  • Loading branch information
krismaz committed Nov 25, 2016
1 parent 7e8599c commit 281dfca
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 2 deletions.
28 changes: 28 additions & 0 deletions Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

class Controller(QThread):
program_changed = pyqtSignal([object])
sensors_changed = pyqtSignal(object)
temp_changed = pyqtSignal(float)
pump_changed = pyqtSignal(bool)


def __init__(self, settings, coms, script, parent=None):
QThread.__init__(self, parent)
self.settings = settings
Expand All @@ -18,18 +20,21 @@ def __init__(self, settings, coms, script, parent=None):
self.pump = False
self.program = [step for step in map(Steps.parse, script) if step]
self.current_step = None
self.to_pause = False

def name_sensors(self, raw):
return dict((self.settings['names'].get(k) or k, v) for k, v in raw.items())

def evaluate(self, op, index):
self.program_changed.emit(self.program)
self.to_pause = False
if op.tag == 'TARGET':
print('TARGET command deprecated, use settings file.')
if op.tag == 'HEAT':
self.coms.set_temperature(op.temp)
while True:
temps = self.coms.get_temperatures()
self.sensors_changed.emit(self.name_sensors(temps))
print(index, '-', self.name_sensors(temps))
try:
if temps[self.coms.sensor] >= op.temp:
Expand All @@ -40,18 +45,29 @@ def evaluate(self, op, index):
print('\n'.join(*temps.keys()))
exit(1)
self.temp_changed.emit(temps[self.coms.sensor])
if self.to_pause:
self.coms.set_temperature(-100000000.0)
alert(text='PAUSE', title='', button='OK')
self.to_pause = False
self.coms.set_temperature(op.temp)
sleep(5)
if op.tag == 'COOK':
start = time()
self.coms.set_temperature(op.temp)
while True:
temps = self.coms.get_temperatures()
self.sensors_changed.emit(self.name_sensors(temps))
print(index, '-', self.name_sensors(temps))
remaining = start + op.time - time()
if remaining < 0:
break
print('Time remaining:', datetime.timedelta(seconds=remaining))
self.temp_changed.emit(temps[self.coms.sensor])
if self.to_pause:
self.coms.set_temperature(-100000000.0)
alert(text='PAUSE', title='', button='OK')
self.to_pause = False
self.coms.set_temperature(op.temp)
sleep(5)
if op.tag == 'PAUSE':
self.coms.set_temperature(-100000000.0)
Expand All @@ -71,6 +87,18 @@ def pump_toggle(self, newState):
self.pump = True
self.pump_changed.emit(self.pump)

def shift_temp(self, diff):
try:
self.current_step.temp += diff
if not self.to_pause:
self.coms.set_temperature(self.current_step.temp)
self.program_changed.emit(self.program)
except Exception as e:
print(e)

def request_pause(self):
self.to_pause = True

def brew_loop(self):
for i, step in enumerate(self.program):
self.current_step = step
Expand Down
12 changes: 12 additions & 0 deletions SerialCom.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def update_list(arg1):
text = '\n'.join(('> ' if step == control.current_step else ' ') + str(step) for step in arg1)
ui.label.setText(text)

def update_sensors(arg1):
text = '\n'.join('{}: {}'.format(k,v) for k,v in arg1.items())
ui.label_2.setText(text)


if __name__ == "__main__":
global ui
Expand Down Expand Up @@ -49,8 +53,16 @@ def update_list(arg1):
control.pump_changed.connect(update_pump)
control.temp_changed.connect(update_temp)
control.program_changed.connect(update_list)
control.sensors_changed.connect(update_sensors)

ui.checkBox.stateChanged.connect(lambda x: control.pump_toggle(bool(x)))

ui.upButton.clicked.connect(lambda x: control.shift_temp(0.5))
ui.downButton.clicked.connect(lambda x: control.shift_temp(-0.5))
ui.pauseButton.clicked.connect(lambda x: control.request_pause())



control.start()

MainWindow.show()
Expand Down
18 changes: 17 additions & 1 deletion gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,21 @@ def setupUi(self, MainWindow):
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(0, 0, 291, 261))
self.label.setObjectName("label")
self.upButton = QtWidgets.QPushButton(self.centralwidget)
self.upButton.setGeometry(QtCore.QRect(700, 450, 80, 22))
self.upButton.setObjectName("upButton")
self.downButton = QtWidgets.QPushButton(self.centralwidget)
self.downButton.setGeometry(QtCore.QRect(700, 470, 80, 22))
self.downButton.setObjectName("downButton")
self.pauseButton = QtWidgets.QPushButton(self.centralwidget)
self.pauseButton.setGeometry(QtCore.QRect(619, 501, 161, 51))
self.pauseButton.setObjectName("pauseButton")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(10, 340, 201, 121))
self.label_2.setObjectName("label_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 19))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
Expand All @@ -47,4 +59,8 @@ def retranslateUi(self, MainWindow):
self.progressBar.setFormat(_translate("MainWindow", "%p"))
self.checkBox.setText(_translate("MainWindow", "Pumps"))
self.label.setText(_translate("MainWindow", "TextLabel"))
self.upButton.setText(_translate("MainWindow", "^"))
self.downButton.setText(_translate("MainWindow", "v"))
self.pauseButton.setText(_translate("MainWindow", "Pause"))
self.label_2.setText(_translate("MainWindow", " "))

54 changes: 53 additions & 1 deletion gui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,66 @@
<string>TextLabel</string>
</property>
</widget>
<widget class="QPushButton" name="upButton">
<property name="geometry">
<rect>
<x>700</x>
<y>450</y>
<width>80</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>^</string>
</property>
</widget>
<widget class="QPushButton" name="downButton">
<property name="geometry">
<rect>
<x>700</x>
<y>470</y>
<width>80</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>v</string>
</property>
</widget>
<widget class="QPushButton" name="pauseButton">
<property name="geometry">
<rect>
<x>619</x>
<y>501</y>
<width>161</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>Pause</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>10</x>
<y>340</y>
<width>201</width>
<height>121</height>
</rect>
</property>
<property name="text">
<string> </string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
<height>19</height>
</rect>
</property>
</widget>
Expand Down

0 comments on commit 281dfca

Please sign in to comment.