v.0.9.0 DigitalClock
This commit is contained in:
26
app/utils/digital_clock.py
Normal file
26
app/utils/digital_clock.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
from app.display.neopixel_64x64 import NeoPixel_64x64
|
||||||
|
from app.utils import get_datetime_string
|
||||||
|
from app.utils import colors
|
||||||
|
|
||||||
|
|
||||||
|
class DigitalClock:
|
||||||
|
CLOCK_WIDTH = 38
|
||||||
|
|
||||||
|
def __init__(self, display: NeoPixel_64x64, xpos: int, ypos: int):
|
||||||
|
self.display = display
|
||||||
|
self.xpos = xpos
|
||||||
|
self.ypos = ypos
|
||||||
|
|
||||||
|
async def tick(self):
|
||||||
|
time_str: str = get_datetime_string("time")
|
||||||
|
self.display.clear_box(
|
||||||
|
self.ypos,
|
||||||
|
self.xpos,
|
||||||
|
self.ypos + self.display.font_height,
|
||||||
|
self.xpos + self.CLOCK_WIDTH,
|
||||||
|
color=colors.MAGENTA,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.display.write_text(
|
||||||
|
time_str[:8], self.xpos, self.ypos, color=colors.NEON_YELLOW
|
||||||
|
)
|
||||||
13
main.py
13
main.py
@@ -9,6 +9,7 @@ from app.utils import (
|
|||||||
) # Time-related functions
|
) # Time-related functions
|
||||||
from app.utils import SimpleCounter, colors
|
from app.utils import SimpleCounter, colors
|
||||||
import time
|
import time
|
||||||
|
from app.utils.digital_clock import DigitalClock
|
||||||
import uasyncio as asyncio # type: ignore
|
import uasyncio as asyncio # type: ignore
|
||||||
from app.web import Wlan
|
from app.web import Wlan
|
||||||
|
|
||||||
@@ -26,21 +27,17 @@ async def weather_check_task(weather_checker: Weather_Checker):
|
|||||||
|
|
||||||
|
|
||||||
async def print_time_task() -> None:
|
async def print_time_task() -> None:
|
||||||
|
bottom_ypos = display.MATRIX_HEIGHT - display.font_height
|
||||||
simpleCnt: SimpleCounter = SimpleCounter()
|
simpleCnt: SimpleCounter = SimpleCounter()
|
||||||
|
digitalClock: DigitalClock = DigitalClock(display, 0, bottom_ypos)
|
||||||
while True:
|
while True:
|
||||||
dt1: str = get_datetime_string()
|
dt1: str = get_datetime_string()
|
||||||
dt2: str = get_german_datetime()
|
dt2: str = get_german_datetime()
|
||||||
simpleCnt += 1
|
simpleCnt += 1
|
||||||
print(f"print_time_task running... {simpleCnt.value % 16} {dt1} {dt2}")
|
print(f"print_time_task running... {simpleCnt.value % 16} {dt1} {dt2}")
|
||||||
bottom_ypos = display.MATRIX_HEIGHT - display.font_height
|
|
||||||
|
|
||||||
time_str: str = get_datetime_string("time")
|
await digitalClock.tick()
|
||||||
display.clear_box(bottom_ypos, 0, bottom_ypos + display.font_height, 38)
|
await asyncio.sleep(2)
|
||||||
|
|
||||||
# display.clear_row(bottom_ypos)
|
|
||||||
display.write_text(time_str[:8], 0, bottom_ypos, color=colors.NEON_YELLOW)
|
|
||||||
|
|
||||||
await asyncio.sleep(5)
|
|
||||||
|
|
||||||
|
|
||||||
async def sync_ntp_time_task() -> None:
|
async def sync_ntp_time_task() -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user