diff --git a/apps/clock/clock.py b/apps/clock/clock.py new file mode 100644 index 0000000..0d18530 --- /dev/null +++ b/apps/clock/clock.py @@ -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) diff --git a/apps/clock/font/0.bmp b/apps/clock/font/0.bmp new file mode 100644 index 0000000..c54a8cf Binary files /dev/null and b/apps/clock/font/0.bmp differ diff --git a/apps/clock/font/1.bmp b/apps/clock/font/1.bmp new file mode 100644 index 0000000..162f150 Binary files /dev/null and b/apps/clock/font/1.bmp differ diff --git a/apps/clock/font/2.bmp b/apps/clock/font/2.bmp new file mode 100644 index 0000000..55eeed1 Binary files /dev/null and b/apps/clock/font/2.bmp differ diff --git a/apps/clock/font/3.bmp b/apps/clock/font/3.bmp new file mode 100644 index 0000000..118c2d1 Binary files /dev/null and b/apps/clock/font/3.bmp differ diff --git a/apps/clock/font/4.bmp b/apps/clock/font/4.bmp new file mode 100644 index 0000000..7b119bb Binary files /dev/null and b/apps/clock/font/4.bmp differ diff --git a/apps/clock/font/5.bmp b/apps/clock/font/5.bmp new file mode 100644 index 0000000..79e804b Binary files /dev/null and b/apps/clock/font/5.bmp differ diff --git a/apps/clock/font/6.bmp b/apps/clock/font/6.bmp new file mode 100644 index 0000000..d9312a1 Binary files /dev/null and b/apps/clock/font/6.bmp differ diff --git a/apps/clock/font/7.bmp b/apps/clock/font/7.bmp new file mode 100644 index 0000000..b443c59 Binary files /dev/null and b/apps/clock/font/7.bmp differ diff --git a/apps/clock/font/8.bmp b/apps/clock/font/8.bmp new file mode 100644 index 0000000..b059d65 Binary files /dev/null and b/apps/clock/font/8.bmp differ diff --git a/apps/clock/font/9.bmp b/apps/clock/font/9.bmp new file mode 100644 index 0000000..bf10162 Binary files /dev/null and b/apps/clock/font/9.bmp differ diff --git a/apps/clock/font/colon.bmp b/apps/clock/font/colon.bmp new file mode 100644 index 0000000..dd6e6a2 Binary files /dev/null and b/apps/clock/font/colon.bmp differ diff --git a/code.py b/code.py index 4041548..727d262 100644 --- a/code.py +++ b/code.py @@ -6,6 +6,7 @@ import time import supervisor from nametags.nametags import NametagsApp +from apps.clock.clock import ClockApp print("AramCon Badge 2020 Firmware") @@ -20,6 +21,7 @@ def i2c_device_available(i2c, addr): addon = addons.read_addon_descriptor(e) nametags = NametagsApp(not addon) +clock = ClockApp() while True: nametags.update() @@ -27,6 +29,9 @@ def i2c_device_available(i2c, addr): 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']))