Skip to content

Commit

Permalink
split picobrew c firmware from picobrew s/pro and require config.yml …
Browse files Browse the repository at this point in the history
…for any picobrew firmware updates (#130)
  • Loading branch information
tmack8001 authored Nov 14, 2020
1 parent f962fa1 commit 923061b
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 27 deletions.
4 changes: 2 additions & 2 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def create_app(debug=False):
restore_active_sessions()
initialize_data()
if 'aliases' in server_cfg:
machine_types = [MachineType.ZSERIES, MachineType.ZYMATIC, MachineType.PICOBREW, MachineType.PICOFERM, MachineType.PICOSTILL, MachineType.ISPINDEL]
machine_types = [MachineType.ZSERIES, MachineType.ZYMATIC, MachineType.PICOBREW, MachineType.PICOBREW_C, MachineType.PICOFERM, MachineType.PICOSTILL, MachineType.ISPINDEL]
for mtype in machine_types:
aliases = server_cfg['aliases']
if mtype in aliases and aliases[mtype] is not None:
Expand All @@ -80,7 +80,7 @@ def create_app(debug=False):
active_iSpindel_sessions[uid] = iSpindelSession()
active_iSpindel_sessions[uid].alias = aliases[mtype][uid]
else:
active_brew_sessions[uid] = PicoBrewSession()
active_brew_sessions[uid] = PicoBrewSession(mtype)
active_brew_sessions[uid].alias = aliases[mtype][uid]
active_brew_sessions[uid].is_pico = True if mtype == MachineType.PICOBREW else False

Expand Down
1 change: 1 addition & 0 deletions app/firmware/pico_c/pico_c_0_1_34.bin

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions app/main/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


class MachineType(str, Enum):
PICOBREW_C = 'PicoBrewC'
PICOBREW = 'PicoBrew'
PICOFERM = 'PicoFerm'
PICOSTILL = 'PicoStill'
Expand All @@ -25,8 +26,11 @@ def zseries_firmware_path():
return current_app.config['FIRMWARE_PATH'].joinpath('zseries')


def pico_firmware_path():
return current_app.config['FIRMWARE_PATH'].joinpath('pico')
def pico_firmware_path(machineType):
if machineType is MachineType.PICOBREW:
return current_app.config['FIRMWARE_PATH'].joinpath('pico')
else:
return current_app.config['FIRMWARE_PATH'].joinpath('pico_c')


def picostill_firmware_path():
Expand Down
8 changes: 6 additions & 2 deletions app/main/firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
from distutils.version import LooseVersion, StrictVersion

def firmware_filename(device: MachineType, version: str):
firmware_prefix = device.lower()
if (device == MachineType.PICOBREW):
return "pico_{}.bin".format(version.replace(".", "_"))
return "{}_{}.bin".format(device.lower(), version.replace(".", "_"))
firmware_prefix = "pico"
if (device == MachineType.PICOBREW_C):
firmware_prefix = "pico_c"
return "{}_{}.bin".format(firmware_prefix, version.replace(".", "_"))


def firmware_upgrade_required(device: MachineType, version: str):
Expand All @@ -14,6 +17,7 @@ def firmware_upgrade_required(device: MachineType, version: str):
def minimum_firmware(device: MachineType):
default_firmware = {
MachineType.ZSERIES: '0.0.116',
MachineType.PICOBREW_C: '0.1.34',
MachineType.PICOBREW: '0.1.34',
MachineType.PICOSTILL: '0.0.30',
MachineType.PICOFERM: '0.2.6'
Expand Down
14 changes: 8 additions & 6 deletions app/main/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import shutil
from .config import brew_archive_sessions_path, ferm_archive_sessions_path, iSpindel_archive_sessions_path
from .config import MachineType, brew_archive_sessions_path, ferm_archive_sessions_path, iSpindel_archive_sessions_path


ZYMATIC_LOCATION = {
Expand Down Expand Up @@ -41,11 +41,12 @@
}


class PicoBrewSession():
def __init__(self):
class PicoBrewSession:
def __init__(self, machineType=None):
self.file = None
self.filepath = None
self.alias = ''
self.machine_type = machineType
self.created_at = None
self.name = 'Waiting To Brew'
self.type = 0
Expand Down Expand Up @@ -74,7 +75,7 @@ def cleanup(self):
self.data = []


class PicoFermSession():
class PicoFermSession:
def __init__(self):
self.file = None
self.filepath = None
Expand All @@ -94,7 +95,7 @@ def cleanup(self):
self.voltage = '-'
self.start_time = None
self.data = []


class iSpindelSession():
def __init__(self):
Expand All @@ -109,7 +110,8 @@ def __init__(self):
def cleanup(self):
if self.file and self.filepath:
self.file.close()
shutil.move(str(self.filepath), str(iSpindel_archive_sessions_path()))
shutil.move(str(self.filepath), str(
iSpindel_archive_sessions_path()))
self.file = None
self.filepath = None
self.uninit = True
Expand Down
18 changes: 12 additions & 6 deletions app/main/routes_pico_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def process_change_state_request(args):
@main.route('/API/pico/checkFirmware')
@use_args(check_firmware_args, location='querystring')
def process_check_firmware(args):
if firmware_upgrade_required(MachineType.PICOBREW, args['version']):
# only give update available if machine type is known (C firmware != S/Pro Firmware)
if args['uid'] in active_brew_sessions and firmware_upgrade_required(active_brew_sessions[args['uid']].machine_type, args['version']):
return '#T#'
return '#F#'

Expand All @@ -61,11 +62,16 @@ def process_check_firmware(args):
@main.route('/API/pico/getFirmware')
@use_args(get_firmware_args, location='querystring')
def process_get_firmware(args):
filename = firmware_filename(MachineType.PICOBREW, minimum_firmware(MachineType.PICOBREW))
f = open(pico_firmware_path().joinpath(filename))
fw = f.read()
f.close()
return '{}'.format(fw)
if args['uid'] in active_brew_sessions:
machine_type = active_brew_sessions[args['uid']].machine_type
filename = firmware_filename(machine_type, minimum_firmware(machine_type))
f = open(pico_firmware_path(machine_type).joinpath(filename))
fw = f.read()
f.close()
return '{}'.format(fw)
else:
# TODO: Error Processing?
return '#F#'


# Actions Needed: /API/pico/getActionsNeeded?uid={UID}
Expand Down
1 change: 0 additions & 1 deletion app/main/routes_picostill_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from . import main
from .config import picostill_firmware_path
from .firmware import MachineType, firmware_filename, firmware_upgrade_required, minimum_firmware
from .model import PicoBrewSession
from .routes_frontend import get_zseries_recipes, load_brew_sessions
from .session_parser import active_brew_sessions

Expand Down
6 changes: 3 additions & 3 deletions app/main/routes_zseries_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

from .. import socketio
from . import main
from .config import brew_active_sessions_path, zseries_firmware_path
from .firmware import MachineType, firmware_filename, firmware_upgrade_required, minimum_firmware
from .config import MachineType, brew_active_sessions_path, zseries_firmware_path
from .firmware import firmware_filename, firmware_upgrade_required, minimum_firmware
from .model import PicoBrewSession
from .routes_frontend import get_zseries_recipes, load_brew_sessions
from .session_parser import active_brew_sessions
Expand Down Expand Up @@ -390,7 +390,7 @@ def create_session(token, body):
current_app.logger.debug('recipe for session: {}'.format(recipe.serialize()))

if uid not in active_brew_sessions:
active_brew_sessions[uid] = PicoBrewSession()
active_brew_sessions[uid] = PicoBrewSession(MachineType.ZSERIES)

session_guid = uuid.uuid4().hex[:32]
session_id = increment_session_id(uid)
Expand Down
4 changes: 2 additions & 2 deletions app/main/routes_zymatic_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .. import socketio
from . import main
from .config import brew_active_sessions_path
from .model import PicoBrewSession
from .model import MachineType, PicoBrewSession
from .routes_frontend import get_zymatic_recipes
from .session_parser import active_brew_sessions

Expand Down Expand Up @@ -151,7 +151,7 @@ def process_log_session(args):
if args['code'] == 0:
uid = args['machine']
if uid not in active_brew_sessions:
active_brew_sessions[uid] = PicoBrewSession()
active_brew_sessions[uid] = PicoBrewSession(MachineType.Zymatic)
active_brew_sessions[uid].session = uuid.uuid4().hex[:32]
active_brew_sessions[uid].name = get_recipe_name_by_id(args['recipe'])
active_brew_sessions[uid].filepath = brew_active_sessions_path().joinpath('{0}#{1}#{2}#{3}.json'.format(datetime.now().strftime('%Y%m%d_%H%M%S'), uid, active_brew_sessions[uid].session, active_brew_sessions[uid].name.replace(' ', '_')))
Expand Down
9 changes: 6 additions & 3 deletions app/main/session_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,14 @@ def restore_active_sessions():
session.created_at = brew_session['date']
session.name = brew_session['name']
session.type = brew_session['type']
session.session = brew_session['session'] # session guid
session.id = -1 # session id (integer)
session.session = brew_session['session'] # session guid
session.id = -1 # session id (integer)

if 'machine_type' in brew_session:
session.machine_type = brew_session['machine_type'] # keep track of machine type of uid (if known)

if 'recovery' in brew_session:
session.recovery = brew_session['recovery'] # find last step name
session.recovery = brew_session['recovery'] # find last step name

# session.remaining_time = None
session.is_pico = brew_session['is_pico']
Expand Down
3 changes: 3 additions & 0 deletions config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ aliases:
#ProductID : Nickname
ZSeries:
#ProductID : Nickname
PicoBrewC:
#ProductID : Nickname
PicoBrew:
#ProductID : Nickname
PicoFerm:
Expand Down Expand Up @@ -53,6 +55,7 @@ aliases:
# been sent to the pico brewing community for early beta testing and are bundled with this server.
firmware:
# ZSeries: 0.0.116
# PicoBrewC: 0.1.34
# PicoBrew: 0.1.34
# PicoStill: 0.0.30
# PicoFerm: 0.2.6
Expand Down

0 comments on commit 923061b

Please sign in to comment.