Skip to content

Commit

Permalink
fix(choose_child): provided way to provide specific child per button,…
Browse files Browse the repository at this point in the history
… or allow for toggling child using next/previous child.
  • Loading branch information
MikeSchapp committed Oct 2, 2022
1 parent 17ade4f commit 4a45270
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
9 changes: 9 additions & 0 deletions firmware/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@ def get_base_path(path):
def join_path(*args):
path_list = list(args)
return "/".join(path_list)

class partial:
def __init__(self, func, *args, **kwargs):
self.func = func
self.args = args
self.kwargs = kwargs

def __call__(self, *args, **kwds):
return self.func(*self.args, *args, **kwds, **self.kwargs)
22 changes: 12 additions & 10 deletions firmware/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import time
import uos as os
import _thread
from lib.utils import retrieve_auth_variables, join_path, auth_variables_valid
from lib.utils import retrieve_auth_variables, join_path, auth_variables_valid, partial
from picoconnection import PicoConnection
from lib.webpage import config_route, default_route
from lib.scout import connect_to_baby_buddy
Expand All @@ -29,26 +29,27 @@
BABY_SCOUT = connect_to_baby_buddy(base_url=WLAN_VARIABLES["BASE_URL"])
# Set default to first child in BabyBuddy, add functionality to allow for toggling between multiple children.
BABY_SCOUT.next_child()
child = BABY_SCOUT.children[0]

# Create button matrix, matching gpio pin to the specific action you want to capture
button_gpio_pins = [9, 8, 7, 6, 5, 4, 3, 2]
button_actions = [
BABY_SCOUT.left_breast,
BABY_SCOUT.breast_feed,
BABY_SCOUT.right_breast,
BABY_SCOUT.bottle_feed,
BABY_SCOUT.wet_diaper,
BABY_SCOUT.solid_diaper,
BABY_SCOUT.wet_solid_diaper,
BABY_SCOUT.sleep,
partial(BABY_SCOUT.left_breast, BABY_SCOUT.children[BABY_SCOUT.child_index]),
partial(BABY_SCOUT.breast_feed, BABY_SCOUT.children[BABY_SCOUT.child_index]),
partial(BABY_SCOUT.right_breast, BABY_SCOUT.children[BABY_SCOUT.child_index]),
partial(BABY_SCOUT.bottle_feed, BABY_SCOUT.children[BABY_SCOUT.child_index]),
partial(BABY_SCOUT.wet_diaper, BABY_SCOUT.children[BABY_SCOUT.child_index]),
partial(BABY_SCOUT.solid_diaper, BABY_SCOUT.children[BABY_SCOUT.child_index]),
partial(BABY_SCOUT.wet_solid_diaper, BABY_SCOUT.children[BABY_SCOUT.child_index]),
partial(BABY_SCOUT.sleep, BABY_SCOUT.children[BABY_SCOUT.child_index])
]

# Initialize buttons
buttons = []
for button in button_gpio_pins:
buttons.append(create_button(button))

button_actions[4]()

# Loop through and check if any button has been pressed.
def button_pressed():
while True:
Expand Down Expand Up @@ -86,3 +87,4 @@ def ensure_connection():
app.route("/config")(config_route)()
app.serve()


0 comments on commit 4a45270

Please sign in to comment.