Skip to content

Commit

Permalink
Add config options for illumination
Browse files Browse the repository at this point in the history
  • Loading branch information
hackenbergstefan committed Aug 18, 2024
1 parent 248fec8 commit eabdec3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion coffeebuddy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion coffeebuddy/attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
40 changes: 30 additions & 10 deletions coffeebuddy/illumination.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")),
)


Expand All @@ -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()
4 changes: 3 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit eabdec3

Please sign in to comment.