Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New app: qlock #2879

Merged
merged 4 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/qlock/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: qlock
name: Qlock
summary: Advanced clock
desc: Custom clock with time, binary, beats, and date; all with a custom font.
author: craigerskine
172 changes: 172 additions & 0 deletions apps/qlock/qlock.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
"""
Applet: Qlock
Summary: Advanced clock
Description: Custom clock with time, binary, beats, and date; all with a custom font.
Author: craigerskine
"""

load("encoding/base64.star", "base64")
load("render.star", "render")
load("schema.star", "schema")
load("time.star", "time")

# contants
COLOR_LIGHT = "#FFF"
COLOR_MEDIUM = "#AAA"
COLOR_DARK = "#444"
COLOR_ACTIVE = "#60A5FA"
IMG_AT = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAABnRSTlMARwBwAEyv7uYjAAAAHklEQVR4AWMAAvcCHwiCchhAAMoGYTQlCFUIPlwSACKBDShuPBCFAAAAAElFTkSuQmCC"
FONT_LG = {
0: "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAKCAIAAADzWwNnAAAABnRSTlMARwBwAEyv7uYjAAAAGklEQVR4AWMAAvcCHwhCcBBCcBla8hEI3T0ApgwoeZVEgsQAAAAASUVORK5CYII=",
1: "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAKCAIAAADzWwNnAAAABnRSTlMARwBwAEyv7uYjAAAAF0lEQVR4AWMAAvcCHyBiAAMoH11owPgAx6oVQCDcnwcAAAAASUVORK5CYII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AqeJ4pAAAAEElEQVR42mNAgP8o7P9wCgA17QT8awBcmwAAAABJRU5ErkJggg==",
}

def zero_pad(number, width):
return "0" * (width - len(str(number))) + str(number)

def to_binary(value, bits):
lines = []
for i in range(bits):
color = COLOR_ACTIVE if value & (1 << (bits - 1 - i)) else COLOR_DARK
lines.append(render.Box(width = 3, height = 1, color = color))
return render.Column(children = lines)

def render_digits(value, width, font = FONT_SM, color = COLOR_MEDIUM, spacing = 1):
padded_value = zero_pad(value, width)
digits = [render_digit(padded_value[i], font, color) for i in range(width)]
spaced_digits = []
for i, digit in enumerate(digits):
spaced_digits.append(digit)
if i < len(digits) - 1:
spaced_digits.append(render.Box(width = spacing, height = 1))
return spaced_digits

def render_digit(digit, font, color):
return render.Stack(children = [
render.Box(width = 5 if font == FONT_LG else (2 if digit == "1" else 3), height = 10 if font == FONT_LG else 5, color = color),
render.Image(src = base64.decode(font[int(digit)])),
])

def main():
now = time.now().in_location("UTC")
bmt = time.now().in_location("Europe/Zurich")

hours = now.hour % 12 or 12
minutes = now.minute
seconds = now.second
month = now.month
day = now.day

# beats
seconds_since_midnight = (bmt.hour * 3600) + (bmt.minute * 60) + bmt.second
beats = int((seconds_since_midnight / 86.4))
beats = beats % 1000

time_digits = (
render_digits(hours, 2, FONT_LG, COLOR_LIGHT, spacing = 2) +
[render.Box(width = 10, height = 1)] +
render_digits(minutes, 2, FONT_LG, COLOR_LIGHT, spacing = 2) +
[render.Box(width = 10, height = 1)] +
render_digits(seconds, 2, FONT_LG, COLOR_LIGHT, spacing = 2)
)

beats_render = render_digits(beats, 3)

date_digits = (
render_digits(month, 2) +
[render.Padding(pad = (1, 2, 1, 0), child = render.Box(width = 2, height = 1, color = COLOR_DARK))] +
render_digits(day, 2)
)

return render.Root(
delay = 864,
max_age = 120,
child = render.Column(
expanded = True,
main_align = "space_around",
cross_align = "center",
children = [
render.Row(children = time_digits),
render.Row(
children = [
to_binary(hours // 10, 4),
render.Box(width = 4, height = 1),
to_binary(hours % 10, 4),
render.Box(width = 12, height = 1),
to_binary(minutes // 10, 4),
render.Box(width = 4, height = 1),
to_binary(minutes % 10, 4),
render.Box(width = 12, height = 1),
to_binary(seconds // 10, 4),
render.Box(width = 4, height = 1),
to_binary(seconds % 10, 4),
],
),
render.Padding(
pad = (4, 0, 4, 0),
child = render.Row(
expanded = True,
main_align = "space_between",
cross_align = "center",
children = [
render.Row(children = date_digits),
render.Row(
children = [
render.Stack(
children = [
render.Box(width = 5, height = 5, color = "#666"),
render.Image(src = base64.decode(IMG_AT)),
],
),
render.Box(width = 2, height = 1),
render.Row(children = beats_render),
],
),
],
),
),
],
),
)

def get_schema():
return schema.Schema(
version = "1",
# fields = [
# schema.Toggle(
# id = 'show_date',
# name = 'Display Date',
# desc = '',
# icon = 'calendar',
# default = True,
# ),
# schema.Toggle(
# id = 'show_beats',
# name = 'Display Beats',
# desc = '',
# icon = 'clock',
# default = True,
# ),
# ],
)
Binary file added apps/qlock/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading