Skip to content

Commit

Permalink
Merge pull request #4 from aschuma/current
Browse files Browse the repository at this point in the history
Current
  • Loading branch information
aschuma authored Feb 6, 2021
2 parents ec0144a + 3863092 commit b90dba6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
31 changes: 19 additions & 12 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

CLOCK_FONT = CP437_FONT
MSG_FONT = proportional(LCD_FONT)

LONG_MSG_LEN = 11

class HoursMinutes:
def __init__(self):
Expand All @@ -41,6 +41,8 @@ def now():
def day_of_week():
return ["MO", "DI", "MI", "DO", "FR", "SA", "SO"][datetime.today().weekday()]

def cp437_encode(str):
return [c.encode('cp437') for c in str]

def minute_change(device):
"""When we reach a minute change, animate it."""
Expand All @@ -53,7 +55,7 @@ def helper(current_y):
text(draw, (17, current_y), ts.minutes, fill="white", font=CLOCK_FONT)
text(draw, (device.width - 2 * 8, 1), day_of_week(), fill="white", font=proportional(CLOCK_FONT))

time.sleep(0.1)
time.sleep(0.08)

for current_y in range(1, 9):
helper(current_y)
Expand All @@ -72,7 +74,7 @@ def animation(device, from_y, to_y):
text(draw, (15, current_y), ":", fill="white", font=proportional(TINY_FONT))
text(draw, (17, current_y), ts.minutes, fill="white", font=CLOCK_FONT)
text(draw, (device.width - 2 * 8, current_y + 1), day_of_week(), fill="white", font=proportional(CLOCK_FONT))
time.sleep(0.1)
time.sleep(0.065)
current_y += 1 if to_y > from_y else -1


Expand All @@ -99,8 +101,8 @@ def vertical_scroll(device, words):
for i in range(virtual.height - 12):
virtual.set_position((0, i))
if i > 0 and i % 12 == 0:
time.sleep(1.8)
time.sleep(0.05)
time.sleep(1.5)
time.sleep(0.022)


def main():
Expand All @@ -126,17 +128,22 @@ def main():
if sec == 59:
# When we change minutes, animate the minute change
minute_change(device)
elif sec == 20:
elif sec == 10:
today = date.today()
messages = [today.strftime("%2d.%2m.%4Y")] + msg_provider.messages()
messages = [today.strftime("%2d.%2m.%4Y")] + [m for m in msg_provider.messages() if len(m) <= LONG_MSG_LEN]
vertical_scroll(device, messages)
elif sec == 40:
today = date.today()
messages = [today.strftime("%2d.%2m.%4Y")] + msg_provider.messages()
animation(device, 1, 8)
for full_msg in messages:
show_message(device, full_msg, fill="white", font=proportional(MSG_FONT))
animation(device, 8, 1)
long_messages = [ m for m in msg_provider.messages() if len(m) > LONG_MSG_LEN ]
if len(long_messages) > 0:
messages = long_messages
animation(device, 1, 8)
for full_msg in messages:
show_message(device, cp437_encode(full_msg), fill="white", font=proportional(CLOCK_FONT), scroll_delay=0.024)
animation(device, 8, 1)
else:
messages = [today.strftime("%2d.%2m.%4Y")] + [m for m in msg_provider.messages() if len(m) <= LONG_MSG_LEN]
vertical_scroll(device, messages)
else:
ts = now()
with canvas(device) as draw:
Expand Down
2 changes: 1 addition & 1 deletion messageprovider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ def messages(self):

@staticmethod
def _format(json_obj):
return "" + str(json_obj["name"]) + " " + str(json_obj["value"]) + "" + str(json_obj["unit"])
return ("" + str(json_obj["name"]) + " " + str(json_obj["value"]) + "" + str(json_obj["unit"])).strip()

0 comments on commit b90dba6

Please sign in to comment.