Skip to content

Instantly share code, notes, and snippets.

@lovelaced
Last active August 31, 2019 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lovelaced/ad77d113cd9d593eb7d06ee072b91da1 to your computer and use it in GitHub Desktop.
Save lovelaced/ad77d113cd9d593eb7d06ee072b91da1 to your computer and use it in GitHub Desktop.
apps/freeside/
import display
import utime
import leds
import buttons
import os
import math
w, h = 160, 80
BATTERY_COLOR_GOOD = [212, 170, 0]
BATTERY_COLOR_OK = [0, 0, 0]
BATTERY_COLOR_BAD = [255, 0, 0]
direction = 0
brightness = 1
leds.dim_top(brightness)
_rand = 123456789
def rand():
global _rand
_rand = (1103515245 * _rand + 12345) & 0xFFFFFF
return _rand
gs = 160
colors = [((i >> 2) * gs, (i >> 1 & 1) * gs, (i & 1) * gs) for i in range(1, 8)]
def get_bat_color(v):
if v > 3.8:
return BATTERY_COLOR_GOOD
if v > 3.6:
return BATTERY_COLOR_OK
return BATTERY_COLOR_BAD
def render_battery(d, v):
c = get_bat_color(v)
if not c:
return
# 7
# 3
d.rect(140, 2, 155, 9, filled=True, col=c)
d.rect(155, 4, 157, 7, filled=True, col=c)
if v < 4.0:
d.rect(151, 72, 154, 77, filled=True, col=[0, 0, 0])
if v < 3.8:
d.rect(146, 72, 151, 77, filled=True, col=[0, 0, 0])
if v < 3.6:
d.rect(141, 72, 146, 77, filled=True, col=[0, 0, 0])
def set_time():
h = 0
m = 0
s = 0
utime.sleep(1)
with display.open() as d:
# Set hour
d.print("Hour?")
while True:
d.print("%02d" % h, posy=15)
pressed = buttons.read(
buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT | buttons.TOP_RIGHT
)
if pressed & buttons.BOTTOM_LEFT != 0:
if h > 0:
h -= 1
if pressed & buttons.BOTTOM_RIGHT != 0:
if h <= 24:
h += 1
if pressed & buttons.TOP_RIGHT != 0:
break
d.update()
utime.sleep(0.1)
utime.sleep(0.5)
d.print("Minute?")
while True:
d.print("%02d" % m, posy=15)
pressed = buttons.read(
buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT | buttons.TOP_RIGHT
)
if pressed & buttons.BOTTOM_LEFT != 0:
if m > 0:
m -= 1
if pressed & buttons.BOTTOM_RIGHT != 0:
if m <= 60:
m += 1
if pressed & buttons.TOP_RIGHT != 0:
break
d.update()
utime.sleep(0.1)
utime.set_time(utime.mktime((2000, 1, 1, h, m, s, 0, 0)))
render_background()
def render_background():
f = open('/image.raw','rb')
with display.open() as d:
for y in range(h):
for x in range(w):
r = ord(f.read(1))
g = ord(f.read(1))
b = ord(f.read(1))
f.read(1)
d.pixel(x,y,col=(r,g,b))
d.update()
d.close()
f.close()
# ----- main program loop -----
render_background()
# Start the clock
while True:
pressed = buttons.read(
buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT | buttons.TOP_RIGHT
)
if pressed & buttons.BOTTOM_LEFT != 0:
if brightness > 0:
brightness -= 1
print(brightness)
leds.dim_top(brightness)
if pressed & buttons.BOTTOM_RIGHT != 0:
if brightness < 8:
brightness += 1
print(brightness)
leds.dim_top(brightness)
if pressed & buttons.TOP_RIGHT != 0:
set_time()
t = utime.localtime()
with display.open() as d:
d.print("%02d:%02d:%02d" %(t[3],t[4],t[5]), fg=(212,170,0))
render_battery(d, os.read_battery())
d.update()
d.close()
# Do the cool blit
if direction == 0:
for i in range(11):
leds.set(i, colors[rand() % len(colors)])
utime.sleep(0.05)
leds.set(i-1, (0,0,0))
utime.sleep(0.01)
leds.set(10, (0,0,0))
direction = 1
utime.sleep(0.1)
continue
if direction == 1:
for i in range(10,-1,-1):
leds.set(i, colors[rand() % len(colors)])
utime.sleep(0.05)
leds.set(i+1, (0,0,0))
utime.sleep(0.01)
leds.set(0, (0,0,0))
direction = 0
utime.sleep(0.1)
continue

All you need to do is create an image in GIMP which is 160x80 (the Freeside logo is exactly these dimensions when scaled down).

Export this image in RAW format with type BMP.

Add whatever you want to the image and the clock will appear in the top right and the "invisible" battery marker will be in the top right - it will turn black when semi-low and red when low.

Watch time can be set by pressing top right button (may need a long press if it doesn't work right away).

{"name":"assembly","description":"freeside assembly represent","category":"graphics","author":"s3krit","revision":1}
@lovelaced
Copy link
Author

image.raw is the filename of the raw image and it goes in the root directory of the card10 (NOT the apps/ directory).

@lovelaced
Copy link
Author

If your image colors are inverted, swap line 96 and line 98.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment