Skip to content

Commit a364abd

Browse files
add config to control led behavior during preparation
1 parent 914519f commit a364abd

File tree

6 files changed

+56
-27
lines changed

6 files changed

+56
-27
lines changed

docs/setup.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,20 @@ They can be used at own risk of CocktailBerry not working 100% properly.
6565
??? info "List Hardware Config Values"
6666
Hardware config values are used to configure and enable the connected hardware.
6767

68-
| Value Name | Description |
69-
| :--------------------- | :--------------------------------------------------------------------------------------- |
70-
| `PUMP_CONFIG` | List with config for each pump: pin, volume flow, tube volume to pump up |
71-
| `LED_PINS` | List of pins connected to LEDs for preparation |
72-
| `LED_BRIGHTNESS` | Brightness for the WS281x LED (1-255) |
73-
| `LED_COUNT` | Number of LEDs on the WS281x |
74-
| `LED_NUMBER_RINGS` | Number of IDENTICAL daisy chained WS281x LED rings |
75-
| `LED_DEFAULT_ON` | Always turn on to a white LED by default |
76-
| `LED_IS_WS` | Is the led a controllable WS281x LED, [see also](troubleshooting.md#get-the-led-working) |
77-
| `RFID_READER` | Enables connected RFID reader, [more info](troubleshooting.md#set-up-rfid-reader) |
78-
| `MAKER_PINS_INVERTED` | [Inverts](faq.md#what-is-the-inverted-option) pin signal (on=low, off=high) |
79-
| `MAKER_PUMP_REVERSION` | Enables reversion (direction) of pump |
80-
| `MAKER_REVERSION_PIN` | [Pin](#configuring-the-pins-or-used-board) which triggers reversion |
68+
| Value Name | Description |
69+
| :---------------------- | :--------------------------------------------------------------------------------------- |
70+
| `PUMP_CONFIG` | List with config for each pump: pin, volume flow, tube volume to pump up |
71+
| `LED_PINS` | List of pins connected to LEDs for preparation |
72+
| `LED_BRIGHTNESS` | Brightness for the WS281x LED (1-255) |
73+
| `LED_COUNT` | Number of LEDs on the WS281x |
74+
| `LED_NUMBER_RINGS` | Number of IDENTICAL daisy chained WS281x LED rings |
75+
| `LED_DEFAULT_ON` | Always turn on to a white LED by default |
76+
| `LED_PREPARATION_STATE` | Set LED state/effect during preparation (e.g. color effects, on, off) |
77+
| `LED_IS_WS` | Is the led a controllable WS281x LED, [see also](troubleshooting.md#get-the-led-working) |
78+
| `RFID_READER` | Enables connected RFID reader, [more info](troubleshooting.md#set-up-rfid-reader) |
79+
| `MAKER_PINS_INVERTED` | [Inverts](faq.md#what-is-the-inverted-option) pin signal (on=low, off=high) |
80+
| `MAKER_PUMP_REVERSION` | Enables reversion (direction) of pump |
81+
| `MAKER_REVERSION_PIN` | [Pin](#configuring-the-pins-or-used-board) which triggers reversion |
8182

8283
??? info "List Software Config Values"
8384
Software config values are used to configure additional connected software and its behavior.

src/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
SupportedLanguagesType = Literal["en", "de"]
77
SupportedThemesType = Literal["default", "bavaria", "alien", "berry", "tropical", "purple", "custom"]
88
SupportedRfidType = Literal["No", "MFRC522", "PiicoDev"]
9+
SupportedLedStatesType = Literal["Off", "On", "Effect"]
910
NEEDED_PYTHON_VERSION = (3, 9)
1011
FUTURE_PYTHON_VERSION = (3, 11)

src/config/config_manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
MAX_SUPPORTED_BOTTLES,
1515
PROJECT_NAME,
1616
SupportedLanguagesType,
17+
SupportedLedStatesType,
1718
SupportedRfidType,
1819
SupportedThemesType,
1920
__version__,
@@ -120,6 +121,8 @@ class ConfigManager:
120121
LED_NUMBER_RINGS: int = 1
121122
# Turns the led always on to a white when not doing anything else
122123
LED_DEFAULT_ON: bool = False
124+
# LED does things during Preparation (e.g. on or color effects)
125+
LED_PREPARATION_STATE: SupportedLedStatesType = "Effect"
123126
# If the led is as ws-x series (and controllable)
124127
LED_IS_WS: bool = True
125128
# if a RFID reader exists
@@ -195,6 +198,7 @@ def __init__(self) -> None:
195198
"LED_COUNT": IntType([build_number_limiter(1, 500)]),
196199
"LED_NUMBER_RINGS": IntType([build_number_limiter(1, 10)]),
197200
"LED_DEFAULT_ON": BoolType(check_name="Default On"),
201+
"LED_PREPARATION_STATE": ChooseOptions.leds,
198202
"LED_IS_WS": BoolType(check_name="WS281x"),
199203
"RFID_READER": ChooseOptions.rfid,
200204
"MICROSERVICE_ACTIVE": BoolType(check_name="Microservice Active"),

src/config/config_types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
from dataclasses import dataclass, field
1111
from typing import Any, Callable, Generic, Protocol, TypeVar, get_args
1212

13-
from src import SupportedLanguagesType, SupportedRfidType, SupportedThemesType
13+
from src import SupportedLanguagesType, SupportedLedStatesType, SupportedRfidType, SupportedThemesType
1414
from src.config.errors import ConfigError
1515

1616
SUPPORTED_LANGUAGES = list(get_args(SupportedLanguagesType))
1717
SUPPORTED_THEMES = list(get_args(SupportedThemesType))
1818
SUPPORTED_RFID = list(get_args(SupportedRfidType))
19+
SUPPORTED_LED_STATES = list(get_args(SupportedLedStatesType))
1920

2021

2122
class ConfigInterface(Protocol):
@@ -66,6 +67,7 @@ class ChooseOptions:
6667
language = ChooseType(allowed=SUPPORTED_LANGUAGES)
6768
rfid = ChooseType(allowed=SUPPORTED_RFID)
6869
theme = ChooseType(allowed=SUPPORTED_THEMES)
70+
leds = ChooseType(allowed=SUPPORTED_LED_STATES)
6971

7072

7173
@dataclass

src/language.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@ ui:
670670
LED_DEFAULT_ON:
671671
en: 'LED is on by default, use white LED color. Still use colors during preparation.'
672672
de: 'LED ist standardmäßig an, verwendet weiße LED Farbe. Verwendet immer noch Farben-Zyklus während der Zubereitung.'
673+
LED_PREPARATION_STATE:
674+
en: 'LED state during preparation, on/off/effects.'
675+
de: 'LED Zustand während der Zubereitung, an/aus/Effekte.'
673676
LED_IS_WS:
674677
en: 'Is the LED a controllable (WS281x) LED'
675678
de: 'Ist der LED ein ansteuerbarer (WS281x) LED'

src/machine/leds.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,22 @@ def turn_off(self) -> None:
101101

102102
def preparation_start(self) -> None:
103103
"""Turn the LED on during preparation."""
104-
self.turn_on()
104+
if cfg.LED_PREPARATION_STATE in ("On", "Effect"):
105+
self.turn_on()
106+
else:
107+
self.turn_off()
105108

106109
def preparation_end(self, duration: int = 5) -> None:
107110
"""Blink for some time after preparation."""
108-
self.turn_off()
109-
blinker = Thread(target=self._blink_for, kwargs={"duration": duration})
110-
blinker.daemon = True
111-
blinker.start()
111+
if cfg.LED_PREPARATION_STATE == "Effect":
112+
self.turn_off()
113+
blinker = Thread(target=self._blink_for, kwargs={"duration": duration})
114+
blinker.daemon = True
115+
blinker.start()
116+
elif cfg.LED_DEFAULT_ON:
117+
self.turn_on()
118+
else:
119+
self.turn_off()
112120

113121
def _blink_for(self, duration: int = 5, interval: float = 0.2) -> None:
114122
current_time = 0.0
@@ -223,14 +231,24 @@ def _end_thread(self, duration: int = 5) -> None:
223231

224232
def preparation_start(self) -> None:
225233
"""Effect during preparation."""
226-
self.is_preparing = True
227-
cycler = Thread(target=self._preparation_thread)
228-
cycler.daemon = True
229-
cycler.start()
234+
if cfg.LED_PREPARATION_STATE == "Effect":
235+
self.is_preparing = True
236+
cycler = Thread(target=self._preparation_thread)
237+
cycler.daemon = True
238+
cycler.start()
239+
elif cfg.LED_PREPARATION_STATE == "On":
240+
self.turn_on()
241+
else:
242+
self.turn_off()
230243

231244
def preparation_end(self, duration: int = 5) -> None:
232245
"""Plays an effect after the preparation for x seconds."""
233-
self.is_preparing = False
234-
rainbow = Thread(target=self._end_thread, kwargs={"duration": duration})
235-
rainbow.daemon = True
236-
rainbow.start()
246+
if cfg.LED_PREPARATION_STATE == "Effect":
247+
self.is_preparing = False
248+
rainbow = Thread(target=self._end_thread, kwargs={"duration": duration})
249+
rainbow.daemon = True
250+
rainbow.start()
251+
elif cfg.LED_DEFAULT_ON:
252+
self.turn_on()
253+
else:
254+
self.turn_off()

0 commit comments

Comments
 (0)