aa
This commit is contained in:
17
init.py
17
init.py
@@ -51,6 +51,12 @@ class AlarmClock:
|
|||||||
def loop(self):
|
def loop(self):
|
||||||
currentButtonState = not self.buttonGpio.read()
|
currentButtonState = not self.buttonGpio.read()
|
||||||
currentTime = time()
|
currentTime = time()
|
||||||
|
|
||||||
|
if (self.configMode == "normal"):
|
||||||
|
currentMinute = int((currentTime / 60) % 60)
|
||||||
|
currentHour = int((currentTime / 3600) % 24)
|
||||||
|
|
||||||
|
self.setLcdText(f"Time {currentHour:02d}:{currentMinute:02d} \nAlarm {self.alarmHour:02d}:{self.alarmMinute:02d}")
|
||||||
|
|
||||||
# Only process button state change if debounce delay has passed
|
# Only process button state change if debounce delay has passed
|
||||||
if currentButtonState != self.lastKnownButtonState:
|
if currentButtonState != self.lastKnownButtonState:
|
||||||
@@ -66,16 +72,6 @@ class AlarmClock:
|
|||||||
self.onLongPress()
|
self.onLongPress()
|
||||||
self.buttonPressStartTime = 0.0 # Reset to prevent repeated triggers
|
self.buttonPressStartTime = 0.0 # Reset to prevent repeated triggers
|
||||||
|
|
||||||
def setLcdTime(self, hours: int, minutes: int):
|
|
||||||
self.lcd.clear()
|
|
||||||
# write the time on spanning both rows of the LCD
|
|
||||||
timeString = f"{hours:02}:{minutes:02}"
|
|
||||||
self.setLcdText(timeString)
|
|
||||||
|
|
||||||
def generateDualLineTimeString(self, hours: int, minutes: int) -> str:
|
|
||||||
# generate custom characters to display time in dual line format
|
|
||||||
|
|
||||||
|
|
||||||
def onButtonPress(self, button: str, state: bool):
|
def onButtonPress(self, button: str, state: bool):
|
||||||
print(f"Button '{button}' pressed state: {state}")
|
print(f"Button '{button}' pressed state: {state}")
|
||||||
currentTime = time()
|
currentTime = time()
|
||||||
@@ -97,7 +93,6 @@ class AlarmClock:
|
|||||||
if self.configMode == "normal":
|
if self.configMode == "normal":
|
||||||
# Normal mode: toggle relay
|
# Normal mode: toggle relay
|
||||||
self.setRelayState(not self.relayGpio.read())
|
self.setRelayState(not self.relayGpio.read())
|
||||||
self.setLcdText(f"Relay: {'ON' if self.relayGpio.read() else 'OFF'}")
|
|
||||||
elif self.configMode == "set_hour":
|
elif self.configMode == "set_hour":
|
||||||
# Increment hour
|
# Increment hour
|
||||||
self.alarmHour = (self.alarmHour + 1) % 24
|
self.alarmHour = (self.alarmHour + 1) % 24
|
||||||
|
|||||||
Reference in New Issue
Block a user