diff --git a/coffeebuddy/__init__.py b/coffeebuddy/__init__.py index 0004477..5b49a49 100644 --- a/coffeebuddy/__init__.py +++ b/coffeebuddy/__init__.py @@ -13,7 +13,7 @@ from flask_sqlalchemy import SQLAlchemy from sqlalchemy.exc import OperationalError -__version__ = "1.3.1" +__version__ = "1.4.0" db = SQLAlchemy() login_manager = flask_login.LoginManager() diff --git a/coffeebuddy/attachments.py b/coffeebuddy/attachments.py index c752f30..e0a1666 100644 --- a/coffeebuddy/attachments.py +++ b/coffeebuddy/attachments.py @@ -7,7 +7,7 @@ def init(): if flask.current_app.testing: return - if flask.current_app.config["ILLUMINATION"] is True: + if flask.current_app.config["ILLUMINATION"]: import coffeebuddy.illumination coffeebuddy.illumination.init() diff --git a/coffeebuddy/illumination.py b/coffeebuddy/illumination.py index 361e499..986bcb1 100644 --- a/coffeebuddy/illumination.py +++ b/coffeebuddy/illumination.py @@ -11,7 +11,12 @@ pi = pigpio.pi() -def setup(): +def setup(pin_red, pin_green, pin_blue): + global PIN_RED, PIN_GREEN, PIN_BLUE + PIN_RED = pin_red + PIN_GREEN = pin_green + PIN_BLUE = pin_blue + pi.set_PWM_frequency(PIN_RED, 10_000) pi.set_PWM_frequency(PIN_GREEN, 10_000) pi.set_PWM_frequency(PIN_BLUE, 10_000) @@ -41,22 +46,37 @@ def color_named(name): "lightsteelblue": (0.1, 0.05, 0.1), "lime": (1, 1, 0), } - color(*names[name]) + color(*names.get(name, (0, 0, 0))) def init(): logging.getLogger(__name__).info("Init") - setup() + config = flask.current_app.config.get("ILLUMINATION") + setup(*config["pins"]) - flask.current_app.events.register("motion_detected", lambda: color_named("rose")) - flask.current_app.events.register("motion_lost", lambda: color_named("lightrose")) - flask.current_app.events.register("route_coffee", lambda: color_named("green")) - flask.current_app.events.register("route_welcome", lambda: color_named("rose")) flask.current_app.events.register( - "facerecognition_face_detected", lambda: color_named("violet") + "motion_detected", + lambda: color_named(config.get("color_motion_detected")), + ) + flask.current_app.events.register( + "motion_lost", + lambda: color_named(config.get("color_motion_lost")), + ) + flask.current_app.events.register( + "route_coffee", + lambda: color_named(config.get("color_route_coffee")), + ) + flask.current_app.events.register( + "route_welcome", + lambda: color_named(config.get("color_route_welcome")), + ) + flask.current_app.events.register( + "facerecognition_face_detected", + lambda: color_named(config.get("color_facerecognition_face_detected")), ) flask.current_app.events.register( - "facerecognition_face_lost", lambda: color_named("rose") + "facerecognition_face_lost", + lambda: color_named(config.get("color_facerecognition_face_lost")), ) @@ -69,6 +89,6 @@ def init(): parser.add_argument("color", help="Color in RGB (0-1) or (0-255). E.g. 255 255 0") args = parser.parse_args() - setup() + setup(16, 20, 21) color(*[float(i) for i in args.color.split(" ")]) IPython.embed() diff --git a/config.py b/config.py index b74eb37..575273a 100644 --- a/config.py +++ b/config.py @@ -22,7 +22,9 @@ # Enable Facerecognition FACERECOGNITION = False -# Illumination +# Illumination. +# If set: `{"pins": (1, 2, 3), "color_motion_detected": "rose", "color_X": ...}`. +# See ./coffeebuddy/illumination.py for details ILLUMINATION = False # PIR motion detection (None if not used, BCM pin number otherwise)