Skip to content
This repository was archived by the owner on Oct 28, 2023. It is now read-only.

Commit 60a3e8e

Browse files
committed
New installer version :D
1 parent 23906af commit 60a3e8e

File tree

3 files changed

+129
-125
lines changed

3 files changed

+129
-125
lines changed

esp32/modules/installer.py

Lines changed: 119 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,54 @@
1-
import ugfx, badge, sys, gc
2-
import uos as os
3-
import uerrno as errno
4-
import ujson as json
5-
import network, wifi
6-
import machine, esp, time
7-
import urequests as requests
8-
import appglue
9-
10-
wifi.init()
11-
12-
ugfx.clear(ugfx.BLACK)
13-
ugfx.string(20,25,"Connecting to:","Roboto_BlackItalic24",ugfx.WHITE)
14-
ugfx.string(140,75, "WiFi","PermanentMarker22",ugfx.WHITE)
15-
ugfx.flush()
16-
17-
timeout = 250
18-
while not wifi.sta_if.isconnected():
19-
time.sleep(0.1)
20-
timeout = timeout - 1
21-
if (timeout<1):
22-
ugfx.clear(ugfx.BLACK)
23-
ugfx.string(5,5,"Failure.","Roboto_BlackItalic24",ugfx.WHITE)
24-
ugfx.flush()
25-
time.sleep(2)
26-
appglue.start_app("")
27-
pass
28-
29-
ugfx.clear(ugfx.WHITE)
1+
import ugfx, badge, network, gc, time, urequests, appglue
2+
3+
# SHA2017 Badge installer
4+
# V2 Thomas Roos
5+
# V1 Niek Blankers
6+
7+
def draw_msg(msg):
8+
global line_number
9+
try:
10+
line_number
11+
except:
12+
line_number = 0
13+
ugfx.clear(ugfx.WHITE)
14+
ugfx.string(0, 0, 'Still Loading Anyway...', "PermanentMarker22", ugfx.BLACK)
15+
ugfx.set_lut(ugfx.LUT_FASTER)
16+
draw_msg(msg)
17+
else:
18+
ugfx.string(0, 30 + (line_number * 15), msg, "Roboto_Regular12", ugfx.BLACK)
19+
ugfx.flush()
20+
line_number += 1
21+
22+
def connectWiFi():
23+
nw = network.WLAN(network.STA_IF)
24+
if not nw.isconnected():
25+
nw.active(True)
26+
ssid = badge.nvs_get_str('badge', 'wifi.ssid', 'SHA2017-insecure')
27+
password = badge.nvs_get_str('badge', 'wifi.password')
28+
nw.connect(ssid, password) if password else nw.connect(ssid)
29+
30+
draw_msg("Connecting to '"+ssid+"'...")
31+
32+
timeout = badge.nvs_get_u8('splash', 'wifi.timeout', 40)
33+
while not nw.isconnected():
34+
time.sleep(0.1)
35+
timeout = timeout - 1
36+
if (timeout<1):
37+
draw_msg("Timeout while connecting!")
38+
nw.active(True)
39+
return False
40+
return True
3041

3142
def show_description(active):
3243
if active:
44+
global text
3345
text.text(packages[options.selected_index()]["description"])
3446
ugfx.flush()
3547

36-
def empty_options():
37-
global options
38-
options.destroy()
39-
options = ugfx.List(0,0,int(ugfx.width()/2),ugfx.height())
40-
41-
ugfx.input_init()
42-
43-
window = ugfx.Container(0, 0, ugfx.width(), ugfx.height())
44-
45-
options = ugfx.List(0,0,int(ugfx.width()/2),ugfx.height())
46-
47-
text = ugfx.Textbox(int(ugfx.width()/2),0, int(ugfx.width()/2), ugfx.height())
48-
text.text("Downloading category list...")
49-
50-
ugfx.flush(ugfx.LUT_FULL)
51-
badge.eink_busy_wait()
52-
ugfx.set_lut(ugfx.LUT_FASTER)
53-
54-
packages = {} # global variable
55-
56-
gc.collect()
57-
58-
f = requests.get("https://badge.sha2017.org/eggs/categories/json")
59-
try:
60-
categories = f.json()
61-
finally:
62-
f.close()
63-
64-
gc.collect()
65-
66-
def show_category(active):
67-
if active:
68-
ugfx.string_box(148,0,148,26, "Hatchery", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter)
69-
text.text("Install or update eggs from the hatchery here.\nSelect a category to start, or press B to return to the launcher.\n\nbadge.sha2017.org")
70-
ugfx.flush()
71-
72-
def list_categories():
73-
global options
74-
global text
75-
76-
empty_options()
77-
text.destroy()
78-
text = ugfx.Textbox(int(ugfx.width()/2),26,int(ugfx.width()/2),ugfx.height()-26)
79-
80-
ugfx.input_attach(ugfx.JOY_UP, show_category)
81-
ugfx.input_attach(ugfx.JOY_DOWN, show_category)
82-
ugfx.input_attach(ugfx.BTN_A, select_category)
83-
ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.start_app("launcher") if pushed else 0)
84-
ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else 0)
85-
86-
for category in categories:
87-
options.add_item("%s (%d) >" % (category["name"], category["eggs"]))
88-
89-
show_category(True)
90-
9148
def select_category(active):
9249
if active:
9350
global categories
51+
global options
9452
index = options.selected_index()
9553
category = categories[index]["slug"]
9654
list_apps(category)
@@ -106,46 +64,48 @@ def list_apps(slug):
10664
ugfx.input_attach(ugfx.BTN_B, 0)
10765
ugfx.input_attach(ugfx.BTN_START, 0)
10866

109-
empty_options()
110-
text.destroy()
111-
text = ugfx.Textbox(int(ugfx.width()/2),0, int(ugfx.width()/2), ugfx.height())
67+
while options.count() > 0:
68+
options.remove_item(0)
11269
text.text("Downloading list of eggs...")
113-
ugfx.flush(ugfx.LUT_FULL)
114-
badge.eink_busy_wait()
70+
ugfx.flush()
11571

116-
gc.collect()
117-
f = requests.get("https://badge.sha2017.org/eggs/category/%s/json" % slug)
11872
try:
73+
f = urequests.get("https://badge.sha2017.org/eggs/category/%s/json" % slug)
11974
packages = f.json()
12075
finally:
12176
f.close()
12277

123-
gc.collect()
124-
12578
for package in packages:
12679
options.add_item("%s rev. %s" % (package["name"], package["revision"]))
12780

12881
ugfx.input_attach(ugfx.JOY_UP, show_description)
12982
ugfx.input_attach(ugfx.JOY_DOWN, show_description)
13083
ugfx.input_attach(ugfx.BTN_A, install_app)
131-
ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.start_app("installer") if pushed else 0)
132-
ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app("installer") if pushed else 0)
84+
ugfx.input_attach(ugfx.BTN_B, lambda pushed: list_categories() if pushed else 0)
85+
ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app('') if pushed else 0)
13386

13487
show_description(True)
135-
badge.eink_busy_wait()
13688
ugfx.set_lut(ugfx.LUT_FASTER)
89+
gc.collect()
90+
91+
def start_categories(pushed):
92+
if pushed:
93+
list_categories()
94+
95+
def start_app(pushed):
96+
if pushed:
97+
global selected_app
98+
appglue.start_app(selected_app)
13799

138100
def install_app(active):
139101
if active:
140102
global options
141103
global text
142104
global packages
105+
global selected_app
143106

144107
index = options.selected_index()
145108

146-
options.destroy()
147-
text.destroy()
148-
149109
ugfx.input_attach(ugfx.JOY_UP, 0)
150110
ugfx.input_attach(ugfx.JOY_DOWN, 0)
151111
ugfx.input_attach(ugfx.BTN_A, 0)
@@ -158,19 +118,71 @@ def install_app(active):
158118
ugfx.flush()
159119

160120
import woezel
161-
woezel.install(packages[index]["slug"])
121+
selected_app = packages[index]["slug"]
122+
woezel.install(selected_app)
162123

163124
ugfx.clear(ugfx.WHITE)
164125
ugfx.string(40,25,"Installed:","Roboto_BlackItalic24",ugfx.BLACK)
165126
ugfx.string(100,55, packages[index]["name"],"PermanentMarker22",ugfx.BLACK)
166-
text = ugfx.Textbox(0,100, ugfx.width(), ugfx.height()-100)
167-
text.text("Press A to start %s, or B to return to the installer" % packages[index]["name"])
168-
169-
ugfx.input_attach(ugfx.BTN_A, lambda pushed: appglue.start_app(packages[index]["slug"]) if pushed else 0)
170-
ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.start_app("installer"))
171-
ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app(""))
127+
ugfx.string(0, 115, "[ A: START | B: BACK ]", "Roboto_Regular12", ugfx.BLACK)
128+
129+
ugfx.input_attach(ugfx.BTN_A, start_app)
130+
ugfx.input_attach(ugfx.BTN_B, start_categories)
131+
ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else 0)
172132

173133
ugfx.flush()
134+
gc.collect()
135+
136+
def list_categories():
137+
global options
138+
global text
139+
global categories
140+
141+
try:
142+
categories
143+
except:
144+
ugfx.input_init()
145+
draw_msg('Getting categories')
146+
try:
147+
f = urequests.get("https://badge.sha2017.org/eggs/categories/json")
148+
categories = f.json()
149+
except:
150+
draw_msg('Failed!')
151+
draw_msg('Returning to launcher :(')
152+
appglue.start_app('launcher')
153+
154+
f.close()
155+
draw_msg('Done!')
156+
157+
ugfx.input_attach(ugfx.JOY_UP, lambda pushed: ugfx.flush() if pushed else 0)
158+
ugfx.input_attach(ugfx.JOY_DOWN, lambda pushed: ugfx.flush() if pushed else 0)
159+
ugfx.input_attach(ugfx.BTN_A, select_category)
160+
ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.start_app("launcher") if pushed else 0)
161+
ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else 0)
174162

163+
ugfx.clear(ugfx.WHITE)
164+
ugfx.flush()
175165

176-
list_categories()
166+
while options.count() > 0:
167+
options.remove_item(0)
168+
for category in categories:
169+
options.add_item("%s (%d) >" % (category["name"], category["eggs"]))
170+
171+
ugfx.string_box(148,0,148,26, "Hatchery", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter)
172+
text.text("Install or update eggs from the hatchery here\n\n\n\n")
173+
ugfx.line(148, 78, 296, 78, ugfx.BLACK)
174+
ugfx.string_box(148,78,148,18, " A: Open catergory", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft)
175+
ugfx.string_box(148,92,148,18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft)
176+
ugfx.line(148, 110, 296, 110, ugfx.BLACK)
177+
ugfx.string_box(148,110,148,18, " badge.sha2017.org", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft)
178+
ugfx.flush(ugfx.LUT_FULL)
179+
gc.collect()
180+
181+
182+
if not connectWiFi():
183+
draw_msg('Returning to launcher :(')
184+
appglue.start_app('launcher')
185+
else:
186+
options = ugfx.List(0,0,int(ugfx.width()/2),ugfx.height())
187+
text = ugfx.Textbox(int(ugfx.width()/2),0, int(ugfx.width()/2), ugfx.height())
188+
list_categories()

esp32/modules/launcher.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import ugfx, badge, sys, gc
2-
import uos as os
3-
import uerrno as errno
4-
import ujson as json
5-
import time
6-
import esp
7-
import appglue
8-
import version
1+
import ugfx, badge, sys, uos as os, appglue, version
92

103
ugfx.init()
114
ugfx.input_init()
5+
ugfx.set_lut(ugfx.LUT_FASTER)
126
ugfx.clear(ugfx.BLACK)
137
ugfx.flush()
148
ugfx.clear(ugfx.WHITE)
@@ -31,8 +25,8 @@
3125
# Instructions
3226
ugfx.line(148, 78, 296, 78, ugfx.BLACK)
3327
ugfx.string_box(148,78,148,18, " A: Run", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft)
34-
ugfx.string_box(148,78,148,18, " B: Uninstall", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyRight)
35-
ugfx.string_box(148,92,148,18, " START: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft)
28+
ugfx.string_box(148,78,148,18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyRight)
29+
ugfx.string_box(148,92,148,18, " SELECT: Uninstall", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft)
3630
ugfx.line(148, 110, 296, 110, ugfx.BLACK)
3731
ugfx.string_box(148,110,148,18, " " + version.name, "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft)
3832

@@ -113,13 +107,12 @@ def perform_uninstall(ok):
113107
populate_it()
114108

115109
ugfx.input_attach(ugfx.BTN_A, run_it)
116-
ugfx.input_attach(ugfx.BTN_B, uninstall_it)
110+
ugfx.input_attach(ugfx.BTN_SELECT, uninstall_it)
117111

118112
ugfx.input_attach(ugfx.JOY_UP, lambda pushed: ugfx.flush() if pushed else 0)
119113
ugfx.input_attach(ugfx.JOY_DOWN, lambda pushed: ugfx.flush() if pushed else 0)
120114

115+
ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.start_app("") if pushed else 0)
121116
ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else 0)
122117

123-
ugfx.set_lut(ugfx.LUT_FULL)
124-
ugfx.flush()
125-
ugfx.set_lut(ugfx.LUT_FASTER)
118+
ugfx.flush(ugfx.LUT_FULL)

esp32/modules/splash.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def draw_home(do_BPP):
6161
if do_BPP:
6262
info = '[ ANY: Wake up ]'
6363
elif OTA_available:
64-
info = '[ B: UPDATE ] [ START: LAUNCHER ]'
65-
ugfx.string(0, 108, 'OTA ready!', 'Roboto_Regular18', ugfx.BLACK)
64+
info = '[ SELECT: UPDATE | START: LAUNCHER ]'
65+
ugfx.string(0, 115, 'OTA ready!', 'Roboto_Regular12', ugfx.BLACK)
6666
else:
6767
info = '[ START: LAUNCHER ]'
6868

@@ -79,7 +79,7 @@ def draw_home(do_BPP):
7979
# appglue.start_bpp() ## SHOULD BE THIS!!
8080
deepsleep.start_sleeping()
8181
else:
82-
ugfx.input_attach(ugfx.BTN_B, start_ota)
82+
ugfx.input_attach(ugfx.BTN_SELECT, start_ota)
8383

8484
def start_ota(pushed):
8585
if pushed:
@@ -232,7 +232,6 @@ def checkFirstBoot():
232232
else:
233233
OTA_available = badge.nvs_get_u8('badge','OTA.ready',0)
234234

235-
disableWiFi()
236235
ugfx.clear(ugfx.WHITE)
237236
ugfx.flush(ugfx.LUT_FASTER)
238237

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy