Skip to content
Snippets Groups Projects
Commit 2f671ced authored by schneider's avatar schneider
Browse files

chore(g-watch): use card10 code style

parent 30a885c8
No related branches found
No related tags found
No related merge requests found
......@@ -22,14 +22,15 @@ DIGITS = [
(True, False, True, True, True, True, True),
(True, True, True, False, False, False, False),
(True, True, True, True, True, True, True),
(True, True, True, True, False, True, True)
(True, True, True, True, False, True, True),
]
DOW = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']
DOW = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"]
led_count = 11
b7 = 255 # brightness of 7-segment display 0...255
def ceil_div(a, b):
return (a + (b - 1)) // b
......@@ -114,8 +115,6 @@ def draw_grid_7seg( x, y, w, segs, c):
draw_grid_Hseg(x, y + 3, w, 4, c)
def render_num(num, x):
draw_grid_7seg(x, 1, 7, DIGITS[num // 10], (b7, b7, b7))
draw_grid_7seg(x + 5, 1, 7, DIGITS[num % 10], (b7, b7, b7))
......@@ -136,8 +135,6 @@ def render7segment():
render_colon()
with display.open() as disp:
disp.clear().update()
......@@ -158,25 +155,24 @@ with display.open() as disp:
leds_on = 0
p_leds_on = 0
while True:
millis = utime.monotonic_ms()
lt = utime.localtime()
dow = lt[6]
# ---------------------------------------- read brightness sensor
bri = light_sensor.get_reading()
bri=int(fade_time*100/1000 * bri/200) # calculate display brightness in percent (bri)
bri = int(
fade_time * 100 / 1000 * bri / 200
) # calculate display brightness in percent (bri)
if (bri>100):
if bri > 100:
bri = 100
if (bri<0):
if bri < 0:
bri = 0
ledbri = ((bri / 2) + 50) / 100 # calculate led bar brightness (ledbri = 0...1)
# ---------------------------------------- read buttons
pressed = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT)
p_leds_on = leds_on
......@@ -184,7 +180,7 @@ with display.open() as disp:
if pressed & buttons.BOTTOM_LEFT != 0:
leds_on = 0
disp.clear()
disp.print('LEDS OFF', posx=40, posy=30, font=2)
disp.print("LEDS OFF", posx=40, posy=30, font=2)
disp.update()
disp.backlight(brightness=50)
utime.sleep_ms(500)
......@@ -196,15 +192,12 @@ with display.open() as disp:
if pressed & buttons.BOTTOM_RIGHT != 0:
leds_on = 1
disp.clear()
disp.print('LEDS ON', posx=40, posy=30, font=2)
disp.print("LEDS ON", posx=40, posy=30, font=2)
disp.update()
disp.backlight(brightness=50)
utime.sleep_ms(500)
disp.backlight(brightness=0)
# ---------------------------------------- read orientation sensor
samples = sensors[sensor]["sensor"].read()
if len(samples) > 0: # get orientation sensor samples
......@@ -219,7 +212,7 @@ with display.open() as disp:
if abs(sample.z) > 50: # if arm is hanging:
yd = 0 # do not regard wrist rotation
ydl=ydl*.9
ydl = ydl * 0.9
ydl = (yd + ydl * 9) / 10 # low pass filter wrist rotation
if ydl > 100: # check rottion against threshold and limit value
......@@ -231,18 +224,18 @@ with display.open() as disp:
# .................................... display rotation bargraph on leds // full bar == hitting threshold
if (leds_on==1):
if leds_on == 1:
hour = lt[3]
hue = 360 - (hour / 24 * 360)
for led in range(led_count):
if(led<int(ydl/100*12)-1) or millis<clock_off-1500-((10-led)*15)+300:
if (led < int(ydl / 100 * 12) - 1) or millis < clock_off - 1500 - (
(10 - led) * 15
) + 300:
leds.prep_hsv(10 - led, [hue, 100, ledbri]) # led=0
else:
leds.prep_hsv(10 - led, [0, 0, 0])
# ---------------------------------------- display clock
disp.clear()
if clock_off >= millis:
......@@ -257,7 +250,6 @@ with display.open() as disp:
sec = lt[5]
dow = lt[6]
fade_time = clock_off - millis - 1000 # calculate fade out
if fade_time < 0:
......@@ -270,8 +262,12 @@ with display.open() as disp:
render7segment() # render time in 7-segment digiclock style
disp.print('{:02d}-{:02d}-{} {}'.format(day, month, year, DOW[dow]), posx=10, posy=67, font=2) # display date
disp.print(
"{:02d}-{:02d}-{} {}".format(day, month, year, DOW[dow]),
posx=10,
posy=67,
font=2,
) # display date
# .................................... power
pwr = math.sqrt(power.read_battery_voltage())
......@@ -298,17 +294,11 @@ with display.open() as disp:
if pwrpercent > 25:
c = [0, 255, 0] # green=ok
disp.rect(8, 60, int(pwrpercent*1.43+8), 63, col=c) # draw charge bar in battery bar
disp.rect(
8, 60, int(pwrpercent * 1.43 + 8), 63, col=c
) # draw charge bar in battery bar
# ---------------------------------------- do not display clock
leds.update()
disp.update()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment