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
Branches
No related tags found
1 merge request!396Add G-Watch to preload
...@@ -22,14 +22,15 @@ DIGITS = [ ...@@ -22,14 +22,15 @@ DIGITS = [
(True, False, True, True, True, True, True), (True, False, True, True, True, True, True),
(True, True, True, False, False, False, False), (True, True, True, False, False, False, False),
(True, True, True, True, True, True, True), (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 led_count = 11
b7 = 255 # brightness of 7-segment display 0...255 b7 = 255 # brightness of 7-segment display 0...255
def ceil_div(a, b): def ceil_div(a, b):
return (a + (b - 1)) // b return (a + (b - 1)) // b
...@@ -114,8 +115,6 @@ def draw_grid_7seg( x, y, w, segs, c): ...@@ -114,8 +115,6 @@ def draw_grid_7seg( x, y, w, segs, c):
draw_grid_Hseg(x, y + 3, w, 4, c) draw_grid_Hseg(x, y + 3, w, 4, c)
def render_num(num, x): def render_num(num, x):
draw_grid_7seg(x, 1, 7, DIGITS[num // 10], (b7, b7, b7)) 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)) draw_grid_7seg(x + 5, 1, 7, DIGITS[num % 10], (b7, b7, b7))
...@@ -136,8 +135,6 @@ def render7segment(): ...@@ -136,8 +135,6 @@ def render7segment():
render_colon() render_colon()
with display.open() as disp: with display.open() as disp:
disp.clear().update() disp.clear().update()
...@@ -158,25 +155,24 @@ with display.open() as disp: ...@@ -158,25 +155,24 @@ with display.open() as disp:
leds_on = 0 leds_on = 0
p_leds_on = 0 p_leds_on = 0
while True: while True:
millis = utime.monotonic_ms() millis = utime.monotonic_ms()
lt = utime.localtime() lt = utime.localtime()
dow = lt[6] dow = lt[6]
# ---------------------------------------- read brightness sensor # ---------------------------------------- read brightness sensor
bri = light_sensor.get_reading() 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 bri = 100
if (bri<0): if bri < 0:
bri = 0 bri = 0
ledbri = ((bri / 2) + 50) / 100 # calculate led bar brightness (ledbri = 0...1) ledbri = ((bri / 2) + 50) / 100 # calculate led bar brightness (ledbri = 0...1)
# ---------------------------------------- read buttons # ---------------------------------------- read buttons
pressed = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT) pressed = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT)
p_leds_on = leds_on p_leds_on = leds_on
...@@ -184,7 +180,7 @@ with display.open() as disp: ...@@ -184,7 +180,7 @@ with display.open() as disp:
if pressed & buttons.BOTTOM_LEFT != 0: if pressed & buttons.BOTTOM_LEFT != 0:
leds_on = 0 leds_on = 0
disp.clear() 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.update()
disp.backlight(brightness=50) disp.backlight(brightness=50)
utime.sleep_ms(500) utime.sleep_ms(500)
...@@ -196,15 +192,12 @@ with display.open() as disp: ...@@ -196,15 +192,12 @@ with display.open() as disp:
if pressed & buttons.BOTTOM_RIGHT != 0: if pressed & buttons.BOTTOM_RIGHT != 0:
leds_on = 1 leds_on = 1
disp.clear() 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.update()
disp.backlight(brightness=50) disp.backlight(brightness=50)
utime.sleep_ms(500) utime.sleep_ms(500)
disp.backlight(brightness=0) disp.backlight(brightness=0)
# ---------------------------------------- read orientation sensor # ---------------------------------------- read orientation sensor
samples = sensors[sensor]["sensor"].read() samples = sensors[sensor]["sensor"].read()
if len(samples) > 0: # get orientation sensor samples if len(samples) > 0: # get orientation sensor samples
...@@ -219,7 +212,7 @@ with display.open() as disp: ...@@ -219,7 +212,7 @@ with display.open() as disp:
if abs(sample.z) > 50: # if arm is hanging: if abs(sample.z) > 50: # if arm is hanging:
yd = 0 # do not regard wrist rotation yd = 0 # do not regard wrist rotation
ydl=ydl*.9 ydl = ydl * 0.9
ydl = (yd + ydl * 9) / 10 # low pass filter wrist rotation ydl = (yd + ydl * 9) / 10 # low pass filter wrist rotation
if ydl > 100: # check rottion against threshold and limit value if ydl > 100: # check rottion against threshold and limit value
...@@ -231,18 +224,18 @@ with display.open() as disp: ...@@ -231,18 +224,18 @@ with display.open() as disp:
# .................................... display rotation bargraph on leds // full bar == hitting threshold # .................................... display rotation bargraph on leds // full bar == hitting threshold
if (leds_on==1): if leds_on == 1:
hour = lt[3] hour = lt[3]
hue = 360 - (hour / 24 * 360) hue = 360 - (hour / 24 * 360)
for led in range(led_count): 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 leds.prep_hsv(10 - led, [hue, 100, ledbri]) # led=0
else: else:
leds.prep_hsv(10 - led, [0, 0, 0]) leds.prep_hsv(10 - led, [0, 0, 0])
# ---------------------------------------- display clock # ---------------------------------------- display clock
disp.clear() disp.clear()
if clock_off >= millis: if clock_off >= millis:
...@@ -257,7 +250,6 @@ with display.open() as disp: ...@@ -257,7 +250,6 @@ with display.open() as disp:
sec = lt[5] sec = lt[5]
dow = lt[6] dow = lt[6]
fade_time = clock_off - millis - 1000 # calculate fade out fade_time = clock_off - millis - 1000 # calculate fade out
if fade_time < 0: if fade_time < 0:
...@@ -270,8 +262,12 @@ with display.open() as disp: ...@@ -270,8 +262,12 @@ with display.open() as disp:
render7segment() # render time in 7-segment digiclock style 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 # .................................... power
pwr = math.sqrt(power.read_battery_voltage()) pwr = math.sqrt(power.read_battery_voltage())
...@@ -298,17 +294,11 @@ with display.open() as disp: ...@@ -298,17 +294,11 @@ with display.open() as disp:
if pwrpercent > 25: if pwrpercent > 25:
c = [0, 255, 0] # green=ok 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 # ---------------------------------------- do not display clock
leds.update() leds.update()
disp.update() disp.update()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment