Skip to content

Commit

Permalink
feat(clock): add clock app
Browse files Browse the repository at this point in the history
  • Loading branch information
urish committed May 16, 2020
1 parent cc94f79 commit 4507294
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 0 deletions.
43 changes: 43 additions & 0 deletions apps/clock/clock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import board
import busio
import time
import rtc
import adafruit_il0373
import displayio
from arambadge import badge
from adafruit_display_shapes.rect import Rect

ASSET_ROOT = '/'.join(__file__.split('/')[:-1])
ASSET_LIST = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'colon']

class ClockApp:
def __init__(self):
# Load all assets
self.assets = {}
for asset in ASSET_LIST:
self.assets[asset] = displayio.OnDiskBitmap(open(ASSET_ROOT + '/font/%s.bmp' % asset, 'rb'))
self.assets[':'] = self.assets['colon']

def draw_time(self, dt, x, y):
timestr = '%02d:%02d' % (dt.tm_hour, dt.tm_min)
group = displayio.Group(max_size=len(timestr), x=x, y=y)
xpos = 0
for ch in timestr:
sprite = displayio.TileGrid(self.assets[ch], x=xpos, pixel_shader=displayio.ColorConverter())
group.append(sprite)
xpos += self.assets[ch].width + 8
return group

def run(self):
display = badge.display

while True:
rtc_instance = rtc.RTC()
group = displayio.Group()
group.append(Rect(0, 0, display.width, display.height, fill=0xffffff))
group.append(self.draw_time(rtc_instance.datetime, 48, 40))
display.show(group)
while display.time_to_refresh > 0:
pass
display.refresh()
time.sleep(60-time.time()%60)
Binary file added apps/clock/font/0.bmp
Binary file not shown.
Binary file added apps/clock/font/1.bmp
Binary file not shown.
Binary file added apps/clock/font/2.bmp
Binary file not shown.
Binary file added apps/clock/font/3.bmp
Binary file not shown.
Binary file added apps/clock/font/4.bmp
Binary file not shown.
Binary file added apps/clock/font/5.bmp
Binary file not shown.
Binary file added apps/clock/font/6.bmp
Binary file not shown.
Binary file added apps/clock/font/7.bmp
Binary file not shown.
Binary file added apps/clock/font/8.bmp
Binary file not shown.
Binary file added apps/clock/font/9.bmp
Binary file not shown.
Binary file added apps/clock/font/colon.bmp
Binary file not shown.
5 changes: 5 additions & 0 deletions code.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
import supervisor
from nametags.nametags import NametagsApp
from apps.clock.clock import ClockApp

print("AramCon Badge 2020 Firmware")

Expand All @@ -20,13 +21,17 @@ def i2c_device_available(i2c, addr):
addon = addons.read_addon_descriptor(e)

nametags = NametagsApp(not addon)
clock = ClockApp()

while True:
nametags.update()
for i in range(4):
badge.pixels[i] = (255 * badge.left, 255 * badge.up, 255 * badge.right)
badge.vibration = badge.action

if badge.down:
clock.run()

addon = addons.read_addon_descriptor(e)
if addon:
print("Add-on connected: {}".format(addon['name']))
Expand Down

0 comments on commit 4507294

Please sign in to comment.