Ver Fonte

prepare menu to set alarm time

Fabian Peter Hammerle há 2 anos atrás
pai
commit
2a525b500d
1 ficheiros alterados com 35 adições e 2 exclusões
  1. 35 2
      vibrating_alarm_m5stickc.py

+ 35 - 2
vibrating_alarm_m5stickc.py

@@ -5,7 +5,11 @@ tested on uiflow for stickc v1.8.1
 # pylint: disable=import-error
 import m5ui
 import machine
-from m5stack import lcd, axp
+import micropython
+from m5stack import axp, btnA, lcd
+
+FONT = lcd.FONT_DejaVu40
+DEFAULT_FONT_COLOR = lcd.WHITE
 
 print("battery:", axp.getBatVoltage(), "V")
 
@@ -13,7 +17,14 @@ m5ui.setScreenColor(0x000000)  # clear screen
 screen_width, screen_height = lcd.winsize()
 # https://github.com/m5stack/UIFlow-Code/wiki/M5UI#textbox
 clock_text_box = m5ui.M5TextBox(
-    screen_width - 1, 0, "HH:MM", lcd.FONT_DejaVu40, 0xFFFFFF, rotate=90
+    screen_width - 1, 0, "HH:MM", FONT, DEFAULT_FONT_COLOR, rotate=90
+)
+alarm_hour_text_box = m5ui.M5TextBox(
+    screen_width // 2, 0, "00", FONT, DEFAULT_FONT_COLOR, rotate=90
+)
+m5ui.M5TextBox(screen_width // 2, 53, ":", FONT, DEFAULT_FONT_COLOR, rotate=90)
+alarm_minute_text_box = m5ui.M5TextBox(
+    screen_width // 2, 66, "00", FONT, DEFAULT_FONT_COLOR, rotate=90
 )
 
 # > [contradictory to] official micropython documentation,
@@ -30,5 +41,27 @@ clock_update_timer.init(
     ),
 )
 
+menu_position = 0  # pylint: disable=invalid-name
+
+
+def update_menu(event_arg: None):
+    # pylint: disable=unused-argument; callback
+    alarm_hour_text_box.setColor(
+        lcd.GREEN if menu_position == 1 else DEFAULT_FONT_COLOR
+    )
+    alarm_minute_text_box.setColor(
+        lcd.GREEN if menu_position == 2 else DEFAULT_FONT_COLOR
+    )
+
+
+def button_a_pressed():
+    global menu_position  # pylint: disable=global-statement,invalid-name
+    menu_position = (menu_position + 1) % 3
+    # https://docs.micropython.org/en/latest/library/micropython.html#micropython.schedule
+    micropython.schedule(update_menu, menu_position)
+
+
+btnA.wasPressed(button_a_pressed)
+
 # TODO https://docs.micropython.org/en/latest/library/machine.WDT.html#machine-wdt
 # TODO https://docs.micropython.org/en/latest/esp8266/tutorial/powerctrl.html#deep-sleep-mode