Skip to content

Commit

Permalink
* updated to firmware 1.7 (jailbroken)
Browse files Browse the repository at this point in the history
* improved battery app: auto brightness and extra mode
* updated apps
* updated main.py and menu.py
  • Loading branch information
Lyra1337 committed Aug 27, 2019
1 parent 43a7b55 commit b6d6dd8
Show file tree
Hide file tree
Showing 11 changed files with 432 additions and 121 deletions.
14 changes: 7 additions & 7 deletions apps/adventure_timer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def init():
if CONFIG_NAME not in os.listdir("."):
at_config = {"time_start": "unset"}
f = open(CONFIG_NAME, 'w')
f = open(CONFIG_NAME, "w")
f.write(ujson.dumps(at_config))
f.close()

Expand All @@ -21,7 +21,7 @@ def init():


def is_timestamp_set():
f = open(CONFIG_NAME, 'r')
f = open(CONFIG_NAME, "r")
c = ujson.loads(f.read())
f.close()
if c["time_start"] == "unset":
Expand All @@ -39,29 +39,29 @@ def triangle(disp, x, y, left):


def timestamp_reset():
f = open(CONFIG_NAME, 'r')
f = open(CONFIG_NAME, "r")
c = ujson.loads(f.read())
c["time_start"] = "unset"
f.close()
f = open(CONFIG_NAME, 'w')
f = open(CONFIG_NAME, "w")
f.write(ujson.dumps(c))
f.close()


def timestamp_read():
global time_start
f = open(CONFIG_NAME, 'r')
f = open(CONFIG_NAME, "r")
c = ujson.loads(f.read())
time_start = c["time_start"]
f.close()


def timestamp_write():
f = open(CONFIG_NAME, 'r')
f = open(CONFIG_NAME, "r")
c = ujson.loads(f.read())
c["time_start"] = utime.time()
f.close()
f = open(CONFIG_NAME, 'w')
f = open(CONFIG_NAME, "w")
f.write(ujson.dumps(c))
f.close()

Expand Down
32 changes: 22 additions & 10 deletions apps/battery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
import buttons
import power
import light_sensor

def update_leds(batteryLevel):
lastIndex = round(batteryLevel * 11)
Expand Down Expand Up @@ -40,6 +41,9 @@ def display_logo():
disp = display.open()
mode = 0 # 0 = Voltage & Percentage | 1 =
waitAfterUpdate = False
light_sensor.start()
mode = math.floor(4 * min(8, max(1, light_sensor.get_reading() / 10)))
light_sensor.stop()

display_logo()

Expand All @@ -51,29 +55,33 @@ def display_logo():
)

if pressed & buttons.BOTTOM_LEFT != 0:
brightness = max(0, brightness - 3)
waitAfterUpdate = True
brightness = max(0, brightness - round(1 + brightness * 0.1))
utime.sleep_ms(20)

if pressed & buttons.BOTTOM_RIGHT != 0:
brightness = min(255, brightness + 3)
waitAfterUpdate = True
brightness = min(255, brightness + round(1 + brightness * 0.1))
utime.sleep_ms(20)

if pressed & buttons.TOP_RIGHT != 0:
mode = mode + 1
if mode > 2:
mode = 0
waitAfterUpdate = True

voltage = os.read_battery()
batteryPercent = (voltage - minVoltage) / (maxVoltage - minVoltage)
batteryPercent = (voltage - minVoltage) ** 1.35 / (maxVoltage - minVoltage) ** 1.35

batteryLevel = max(0, min(1, batteryPercent))
mode = mode % ((4 - 1) + 4 * 8)
actualMode = mode % 4

if mode == 0:
if actualMode < 3:
disp.backlight(math.floor(mode / 4 + 1))

if actualMode == 0:
disp.print("Battery:")
disp.print("%f%%" % (batteryLevel * 100), posy = 20)
disp.print("%fV" % voltage, posy = 40, posx = 14)

if mode == 1:
if actualMode == 1:
chargeCurrent = power.read_chargein_current()
chargeVoltage = power.read_chargein_voltage()
disp.print("Charging:", posy = 0)
Expand All @@ -84,11 +92,15 @@ def display_logo():
disp.print("Voltage:", posy = 40)
disp.print("%fV" % chargeVoltage, posy = 60)

if mode == 2:
if actualMode == 2:
batteryCurrent = power.read_battery_current()
disp.print("Drawing:", posy = 0)
disp.print("%fA" % batteryCurrent, posy = 20)

if actualMode == 3:
leds.dim_top(math.floor(1 + mode / 4))
disp.backlight(0)

update_leds(batteryLevel)
update_rockets(batteryLevel)

Expand Down
132 changes: 79 additions & 53 deletions apps/card10_nickname/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import ujson
import os

FILENAME = 'nickname.txt'
FILENAME_ADV = 'nickname.json'
ANIM_TYPES = ['none', 'led', 'fade', 'gay', 'rainbow', 'rnd_led']
FILENAME = "nickname.txt"
FILENAME_ADV = "nickname.json"
ANIM_TYPES = ["none", "led", "fade", "gay", "rainbow", "rnd_led"]


def wheel(pos):
Expand Down Expand Up @@ -40,7 +40,7 @@ def random_rgb():
"""
rgb = []
for i in range(0, 3):
rand = int.from_bytes(os.urandom(1), 'little')
rand = int.from_bytes(os.urandom(1), "little")
if rand > 255:
rand = 255
rgb.append(rand)
Expand Down Expand Up @@ -112,15 +112,15 @@ def get_time():
Generates a nice timestamp in format hh:mm:ss from the devices localtime
:return: timestamp
"""
timestamp = ''
timestamp = ""
if utime.localtime()[3] < 10:
timestamp = timestamp + '0'
timestamp = timestamp + str(utime.localtime()[3]) + ':'
timestamp = timestamp + "0"
timestamp = timestamp + str(utime.localtime()[3]) + ":"
if utime.localtime()[4] < 10:
timestamp = timestamp + '0'
timestamp = timestamp + str(utime.localtime()[4]) + ':'
timestamp = timestamp + "0"
timestamp = timestamp + str(utime.localtime()[4]) + ":"
if utime.localtime()[5] < 10:
timestamp = timestamp + '0'
timestamp = timestamp + "0"
timestamp = timestamp + str(utime.localtime()[5])
return timestamp

Expand Down Expand Up @@ -154,7 +154,7 @@ def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg, mode, bat):
"""
anim = mode
posy = 30
if sub != '':
if sub != "":
posy = 18
r = 255
g = 0
Expand All @@ -164,7 +164,7 @@ def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg, mode, bat):
last_btn_poll = utime.time() - 2
while True:
sleep = 0.5
if sub == '#time':
if sub == "#time":
r_sub = get_time()
dark = 0
if light_sensor.get_reading() < 30:
Expand All @@ -175,9 +175,7 @@ def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg, mode, bat):
r_bg_sub_color = bg_sub[dark]
r_bg = main_bg[dark]
# Button handling
pressed = buttons.read(
buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT
)
pressed = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT)
if utime.time() - last_btn_poll >= 1:
last_btn_poll = utime.time()
if pressed & buttons.BOTTOM_RIGHT != 0:
Expand All @@ -191,7 +189,7 @@ def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg, mode, bat):
anim = len(ANIM_TYPES) - 1
blink_led(0)
# Animations
if ANIM_TYPES[anim] == 'fade':
if ANIM_TYPES[anim] == "fade":
sleep = 0.1
leds.clear()
toggle_rockets(False)
Expand All @@ -207,7 +205,7 @@ def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg, mode, bat):
r_bg = [r, g, b]
r_bg_color = r_bg
r_bg_sub_color = r_bg
if ANIM_TYPES[anim] == 'led':
if ANIM_TYPES[anim] == "led":
if dark == 1:
for i in range(0, 11):
leds.prep(i, r_bg)
Expand All @@ -217,7 +215,7 @@ def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg, mode, bat):
else:
leds.clear()
toggle_rockets(False)
if ANIM_TYPES[anim] == 'rnd_led':
if ANIM_TYPES[anim] == "rnd_led":
if dark == 1:
for i in range(0, 11):
leds.prep(i, random_rgb())
Expand All @@ -227,10 +225,10 @@ def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg, mode, bat):
else:
leds.clear()
toggle_rockets(False)
if ANIM_TYPES[anim] == 'gay':
if ANIM_TYPES[anim] == "gay":
toggle_rockets(False)
leds.gay(0.4)
if ANIM_TYPES[anim] == 'rainbow':
if ANIM_TYPES[anim] == "rainbow":
for i in range(0, 11):
lr, lg, lb = wheel(rainbow_led_pos + i * 3)
leds.prep(i, [lr, lg, lb])
Expand All @@ -240,16 +238,28 @@ def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg, mode, bat):
leds.update()
leds.dim_top(3)
toggle_rockets(True)
if ANIM_TYPES[anim] == 'none':
if ANIM_TYPES[anim] == "none":
leds.clear()
toggle_rockets(False)
with display.open() as disp:
disp.rect(0, 0, 160, 80, col=r_bg, filled=True)
if bat[0]:
render_battery(disp, bat)
disp.print(title, fg=r_fg_color, bg=r_bg_color, posx=80 - round(len(title) / 2 * 14), posy=posy)
if r_sub != '':
disp.print(r_sub, fg=r_fg_sub_color, bg=r_bg_sub_color, posx=80 - round(len(r_sub) / 2 * 14), posy=42)
disp.print(
title,
fg=r_fg_color,
bg=r_bg_color,
posx=80 - round(len(title) / 2 * 14),
posy=posy,
)
if r_sub != "":
disp.print(
r_sub,
fg=r_fg_sub_color,
bg=r_bg_sub_color,
posx=80 - round(len(r_sub) / 2 * 14),
posy=42,
)
disp.update()
disp.close()
utime.sleep(sleep)
Expand All @@ -274,49 +284,65 @@ def get_key(json, key, default):
disp.clear().update()
disp.close()
if FILENAME_ADV in os.listdir("."):
f = open(FILENAME_ADV, 'r')
f = open(FILENAME_ADV, "r")
try:
c = ujson.loads(f.read())
f.close()
# parse config
nick = get_key(c, 'nickname', 'no nick')
sub = get_key(c, 'subtitle', '')
mode = get_key(c, 'mode', 0)
nick = get_key(c, "nickname", "no nick")
sub = get_key(c, "subtitle", "")
mode = get_key(c, "mode", 0)
# battery
battery_show = get_key(c, 'battery', True)
battery_c_good = get_key(c, 'battery_color_good', [0, 230, 00])
battery_c_ok = get_key(c, 'battery_color_ok', [255, 215, 0])
battery_c_bad = get_key(c, 'battery_color_bad', [255, 0, 0])
battery_show = get_key(c, "battery", True)
battery_c_good = get_key(c, "battery_color_good", [0, 230, 00])
battery_c_ok = get_key(c, "battery_color_ok", [255, 215, 0])
battery_c_bad = get_key(c, "battery_color_bad", [255, 0, 0])
# daytime values
background = get_key(c, 'background', [0, 0, 0])
fg_color = get_key(c, 'fg_color', [255, 255, 255])
bg_color = get_key(c, 'bg_color', background)
fg_sub_color = get_key(c, 'fg_sub_color', [255, 255, 255])
bg_sub_color = get_key(c, 'bg_sub_color', background)
background = get_key(c, "background", [0, 0, 0])
fg_color = get_key(c, "fg_color", [255, 255, 255])
bg_color = get_key(c, "bg_color", background)
fg_sub_color = get_key(c, "fg_sub_color", [255, 255, 255])
bg_sub_color = get_key(c, "bg_sub_color", background)
# nighttime values
background_night = get_key(c, 'background_night', [0, 0, 0])
fg_color_night = get_key(c, 'fg_color_night', [255, 255, 255])
bg_color_night = get_key(c, 'bg_color_night', background_night)
fg_sub_color_night = get_key(c, 'fg_sub_color_night', [255, 255, 255])
bg_sub_color_night = get_key(c, 'bg_sub_color_night', background_night)
background_night = get_key(c, "background_night", [0, 0, 0])
fg_color_night = get_key(c, "fg_color_night", [255, 255, 255])
bg_color_night = get_key(c, "bg_color_night", background_night)
fg_sub_color_night = get_key(c, "fg_sub_color_night", [255, 255, 255])
bg_sub_color_night = get_key(c, "bg_sub_color_night", background_night)
# render nickname
render_nickname(nick, sub, (fg_color, fg_color_night), (bg_color, bg_color_night),
(fg_sub_color, fg_sub_color_night), (bg_sub_color, bg_sub_color_night),
(background, background_night), mode,
(battery_show, battery_c_good, battery_c_ok, battery_c_bad))
render_nickname(
nick,
sub,
(fg_color, fg_color_night),
(bg_color, bg_color_night),
(fg_sub_color, fg_sub_color_night),
(bg_sub_color, bg_sub_color_night),
(background, background_night),
mode,
(battery_show, battery_c_good, battery_c_ok, battery_c_bad),
)
except ValueError:
render_error('invalid', 'json')
render_error("invalid", "json")
else:
if FILENAME not in os.listdir("."):
render_error('file not', 'found')
render_error("file not", "found")
else:
f = open(FILENAME, 'r')
f = open(FILENAME, "r")
nick = f.read()
f.close()
if len(nick) > 11:
render_error('name too', 'long')
render_error("name too", "long")
if len(nick) < 1:
render_error('nick file', 'empty')
render_error("nick file", "empty")
else:
render_nickname(nick, '', ([255, 255, 255], [255, 255, 255]), ([0, 0, 0], [0, 0, 0]),
([255, 255, 255], [255, 255, 255]), ([0, 0, 0], [0, 0, 0]), ([0, 0, 0], [0, 0, 0]))
render_nickname(
nick,
"",
([255, 255, 255], [255, 255, 255]),
([0, 0, 0], [0, 0, 0]),
([255, 255, 255], [255, 255, 255]),
([0, 0, 0], [0, 0, 0]),
([0, 0, 0], [0, 0, 0]),
0,
(0, [255, 0, 255], [255, 0, 255], [255, 0, 255]),
)
Loading

0 comments on commit b6d6dd8

Please sign in to comment.