-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/krismaz/BrewLinker
- Loading branch information
Showing
12 changed files
with
659 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
################# | ||
## Eclipse | ||
################# | ||
|
||
*.pydevproject | ||
.project | ||
.metadata | ||
bin/ | ||
tmp/ | ||
*.tmp | ||
*.bak | ||
*.swp | ||
*~.nib | ||
local.properties | ||
.classpath | ||
.settings/ | ||
.loadpath | ||
|
||
# External tool builders | ||
.externalToolBuilders/ | ||
|
||
# Locally stored "Eclipse launch configurations" | ||
*.launch | ||
|
||
# CDT-specific | ||
.cproject | ||
|
||
# PDT-specific | ||
.buildpath | ||
|
||
|
||
################# | ||
## Visual Studio | ||
################# | ||
|
||
## Ignore Visual Studio temporary files, build results, and | ||
## files generated by popular Visual Studio add-ons. | ||
|
||
# User-specific files | ||
*.suo | ||
*.user | ||
*.sln.docstates | ||
|
||
# Build results | ||
|
||
[Dd]ebug/ | ||
[Rr]elease/ | ||
x64/ | ||
build/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
|
||
# MSTest test Results | ||
[Tt]est[Rr]esult*/ | ||
[Bb]uild[Ll]og.* | ||
|
||
*_i.c | ||
*_p.c | ||
*.ilk | ||
*.meta | ||
*.obj | ||
*.pch | ||
*.pdb | ||
*.pgc | ||
*.pgd | ||
*.rsp | ||
*.sbr | ||
*.tlb | ||
*.tli | ||
*.tlh | ||
*.tmp | ||
*.tmp_proj | ||
*.log | ||
*.vspscc | ||
*.vssscc | ||
.builds | ||
*.pidb | ||
*.log | ||
*.scc | ||
|
||
# Visual C++ cache files | ||
ipch/ | ||
*.aps | ||
*.ncb | ||
*.opensdf | ||
*.sdf | ||
*.cachefile | ||
|
||
# Visual Studio profiler | ||
*.psess | ||
*.vsp | ||
*.vspx | ||
|
||
# Guidance Automation Toolkit | ||
*.gpState | ||
|
||
# ReSharper is a .NET coding add-in | ||
_ReSharper*/ | ||
*.[Rr]e[Ss]harper | ||
|
||
# TeamCity is a build add-in | ||
_TeamCity* | ||
|
||
# DotCover is a Code Coverage Tool | ||
*.dotCover | ||
|
||
# NCrunch | ||
*.ncrunch* | ||
.*crunch*.local.xml | ||
|
||
# Installshield output folder | ||
[Ee]xpress/ | ||
|
||
# DocProject is a documentation generator add-in | ||
DocProject/buildhelp/ | ||
DocProject/Help/*.HxT | ||
DocProject/Help/*.HxC | ||
DocProject/Help/*.hhc | ||
DocProject/Help/*.hhk | ||
DocProject/Help/*.hhp | ||
DocProject/Help/Html2 | ||
DocProject/Help/html | ||
|
||
# Click-Once directory | ||
publish/ | ||
|
||
# Publish Web Output | ||
*.Publish.xml | ||
*.pubxml | ||
*.publishproj | ||
|
||
# NuGet Packages Directory | ||
## TODO: If you have NuGet Package Restore enabled, uncomment the next line | ||
#packages/ | ||
|
||
# Windows Azure Build Output | ||
csx | ||
*.build.csdef | ||
|
||
# Windows Store app package directory | ||
AppPackages/ | ||
|
||
# Others | ||
sql/ | ||
*.Cache | ||
ClientBin/ | ||
[Ss]tyle[Cc]op.* | ||
~$* | ||
*~ | ||
*.dbmdl | ||
*.[Pp]ublish.xml | ||
*.pfx | ||
*.publishsettings | ||
|
||
# RIA/Silverlight projects | ||
Generated_Code/ | ||
|
||
# Backup & report files from converting an old project file to a newer | ||
# Visual Studio version. Backup files are not needed, because we have git ;-) | ||
_UpgradeReport_Files/ | ||
Backup*/ | ||
UpgradeLog*.XML | ||
UpgradeLog*.htm | ||
|
||
# SQL Server files | ||
App_Data/*.mdf | ||
App_Data/*.ldf | ||
|
||
############# | ||
## Windows detritus | ||
############# | ||
|
||
# Windows image file caches | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Mac crap | ||
.DS_Store | ||
|
||
|
||
############# | ||
## Python | ||
############# | ||
|
||
*.py[cod] | ||
|
||
# Packages | ||
*.egg | ||
*.egg-info | ||
dist/ | ||
build/ | ||
eggs/ | ||
parts/ | ||
var/ | ||
sdist/ | ||
develop-eggs/ | ||
.installed.cfg | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
||
# Unit test / coverage reports | ||
.coverage | ||
.tox | ||
|
||
#Translations | ||
*.mo | ||
|
||
#Mr Developer | ||
.mr.developer.cfg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import serial | ||
import io | ||
from time import sleep | ||
from struct import pack | ||
|
||
|
||
class ArduinoCommunicator: | ||
def __init__(self, port, sensor): | ||
self.setup_serial(port) | ||
self.set_sensor(sensor) | ||
|
||
def setup_serial(self, port): | ||
print('Connecting to', port) | ||
try: | ||
ser = serial.Serial( | ||
port=port, | ||
baudrate=9600, | ||
timeout=3 | ||
) | ||
except serial.serialutil.SerialException: | ||
print('Error communicating with device "{}"! \n'.format(port) + | ||
'Have you provided the correct COM port?') | ||
exit(1) | ||
print('a') | ||
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser, 1), | ||
encoding='ascii', | ||
newline=None) | ||
sio._CHUNK_SIZE = 1 | ||
print('Connection Established, waiting for ready...') | ||
sleep(10) | ||
print('Connection done!') | ||
self.ser, self.sio = ser, sio | ||
|
||
def set_sensor(self, sensor): | ||
self.sensor = sensor | ||
self.ser.write(bytes([3])) | ||
self.ser.write(bytes(map(lambda x: int(x, 16), sensor.split(" ")))) | ||
self.ser.flush() | ||
print('Sensor set:', self.sio.readline()) | ||
|
||
def set_temperature(self, temp): | ||
bts = pack('f', temp) | ||
self.ser.write(bytes([2])) | ||
self.ser.write(bts) | ||
self.ser.flush() | ||
print('Temperature set:', self.sio.readline()) | ||
|
||
def get_temperatures(self): | ||
self.ser.write(bytes([1])) | ||
self.ser.flush() | ||
res = dict() | ||
for i in range(int(self.sio.readline())): | ||
addr = self.sio.readline().strip() # Right side evaluates first | ||
res[addr] = float(self.sio.readline()) | ||
return res | ||
|
||
def pump_on(self): | ||
self.ser.write(bytes([4])) | ||
self.ser.flush() | ||
|
||
def pump_off(self): | ||
self.ser.write(bytes([5])) | ||
self.ser.flush() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from time import sleep, time | ||
import datetime | ||
from pymsgbox import * | ||
import Steps | ||
from PyQt5.QtCore import QThread, pyqtSignal | ||
|
||
|
||
class Controller(QThread): | ||
program_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 | ||
self.coms = coms | ||
self.coms.pump_off() | ||
self.pump = False | ||
self.program = [step for step in map(Steps.parse, script) if step] | ||
self.current_step = None | ||
|
||
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) | ||
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() | ||
print(index, '-', self.name_sensors(temps)) | ||
try: | ||
if temps[self.coms.sensor] >= op.temp: | ||
break | ||
except KeyError: | ||
print('Unknown target sensor {}!'.format(self.coms.sensor)) | ||
print('Connected sensors are:') | ||
print('\n'.join(*temps.keys())) | ||
exit(1) | ||
self.temp_changed.emit(temps[self.coms.sensor]) | ||
sleep(5) | ||
if op.tag == 'COOK': | ||
start = time() | ||
self.coms.set_temperature(op.temp) | ||
while True: | ||
temps = self.coms.get_temperatures() | ||
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]) | ||
sleep(5) | ||
if op.tag == 'PAUSE': | ||
self.coms.set_temperature(-100000000.0) | ||
alert(text=op.msg, title='', button='OK') | ||
if op.tag == 'DONE': | ||
self.coms.set_temperature(-100000000.0) | ||
self.coms.set_sensor('0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0') | ||
|
||
def pump_toggle(self, newState): | ||
if self.pump == newState: | ||
return | ||
if self.pump: | ||
self.coms.pump_off() | ||
self.pump = False | ||
else: | ||
self.coms.pump_on() | ||
self.pump = True | ||
self.pump_changed.emit(self.pump) | ||
|
||
def brew_loop(self): | ||
for i, step in enumerate(self.program): | ||
self.current_step = step | ||
self.evaluate(step, i) | ||
|
||
def run(self): | ||
self.brew_loop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from time import sleep, time | ||
|
||
|
||
class DebugCommunicator: | ||
def __init__(self, port, sensor): | ||
self.setup_serial(port) | ||
self.set_sensor(sensor) | ||
self.start = time() | ||
|
||
def setup_serial(self, port): | ||
print('Connecting to', port) | ||
sleep(3) | ||
print('Connection done!') | ||
|
||
def set_sensor(self, sensor): | ||
self.sensor = sensor | ||
print('Sensor set:', sensor) | ||
|
||
def set_temperature(self, temp): | ||
print('Temperature set:', temp) | ||
|
||
def get_temperatures(self): | ||
return {self.sensor: time() - self.start + 70.} | ||
|
||
def pump_on(self): | ||
print('Pump on') | ||
|
||
def pump_off(self): | ||
print('Pump off') |
Oops, something went wrong.