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

Commit f875921

Browse files
authored
Merge pull request SHA2017-badge#64 from rnplus/master
Updated launcher, added nickname setup and non-functional sponsors app
2 parents 00df83d + 317166b commit f875921

File tree

5 files changed

+208
-57
lines changed

5 files changed

+208
-57
lines changed

esp32/modules/installer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@
1414
ugfx.string(140,75, "WiFi","PermanentMarker22",ugfx.WHITE)
1515
ugfx.flush()
1616

17+
timeout = 500
1718
while not wifi.sta_if.isconnected():
1819
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("")
1927
pass
2028

2129
ugfx.clear(ugfx.WHITE)

esp32/modules/setup.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# SETUP APPLICATION
2+
# SHOWN ON FIRST BOOT
3+
4+
import ugfx, badge, appglue, dialogs, utime
5+
6+
# Globals
7+
8+
nickname = ""
9+
10+
def load_settings():
11+
global nickname
12+
nickname = badge.nvs_get_str("owner", "name", "")
13+
14+
def store_settings():
15+
global nickname
16+
nickname_new = badge.nvs_set_str("owner", "name", nickname)
17+
if (nickname_new):
18+
nickname = nickname_new
19+
20+
def check_developer():
21+
global nickname
22+
if (nickname==""):
23+
badge.nvs_set_str('badge', 'setup.state', '2') # Skip the sponsors
24+
return True
25+
return False
26+
27+
def ask_nickname():
28+
global nickname
29+
nickname_new = dialogs.prompt_text("Nickname", nickname)
30+
if (nickname_new):
31+
nickname = nickname_new
32+
33+
def action_home(pressed):
34+
if (pressed):
35+
appglue.start_app("")
36+
37+
def set_setup_state():
38+
s_old = int(badge.nvs_get_str('badge', 'setup.state', '0'))
39+
s_new = 2
40+
if (s_old==0):
41+
s_new = 1
42+
badge.nvs_set_str('badge', 'setup.state', str(s_new))
43+
44+
def draw_setup_completed():
45+
ugfx.clear(ugfx.WHITE)
46+
ugfx.string(0, 0, "Setup", "PermanentMarker22", ugfx.BLACK)
47+
ugfx.string(0, 25, "Settings stored to flash!", "Roboto_Regular12", ugfx.BLACK)
48+
ugfx.set_lut(ugfx.LUT_FASTER)
49+
ugfx.flush()
50+
51+
def return_to_home():
52+
badge.eink_busy_wait()
53+
appglue.start_app("")
54+
55+
def program_main():
56+
ugfx.init() # We need graphics
57+
load_settings() # Load current settings
58+
ask_nickname() # Ask the nickname
59+
if not check_developer():
60+
store_settings() # Store the settings
61+
set_setup_state() # Do the firstboot magic
62+
draw_setup_completed() # Show the user that we are done
63+
utime.sleep(2) # Sleep 2 seconds
64+
return_to_home() # Return to the splash app
65+
66+
# Start main application
67+
program_main()
68+

esp32/modules/splash.py

Lines changed: 108 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ugfx, time, badge, machine, uos, appglue, deepsleep
1+
import ugfx, time, badge, machine, uos, appglue, deepsleep, network
22

33
# SHA2017 badge home screen
44
# Renze Nicolai 2017
@@ -9,20 +9,20 @@ def setup_services():
99
try:
1010
apps = uos.listdir('lib')
1111
except OSError:
12-
print("No lib folder!")
12+
print("[SPLASH] Can't setup services: no lib folder!")
1313
return False
1414
for app in apps:
1515
try:
1616
files = uos.listdir('lib/'+app)
1717
except OSError:
18-
print("Listing app files for '"+app+"' failed!")
18+
print("[SPLASH] Listing app files for app '"+app+"' failed!")
1919
return False
2020
status = True
2121
found = False
2222
for f in files:
2323
if (f=="service.py"):
2424
found = True
25-
print("Running service "+app+"...")
25+
print("[SPLASH] Running service "+app+"...")
2626
try:
2727
srv = __import__('lib/'+app+'/service')
2828
services.append(srv) #Add to global list
@@ -32,7 +32,7 @@ def setup_services():
3232
status = False
3333
break
3434
if not found:
35-
print("App '"+app+"' has no service")
35+
print("[SPLASH] App '"+app+"' has no service")
3636
return status
3737

3838
def loop_services(loopCnt):
@@ -43,7 +43,7 @@ def loop_services(loopCnt):
4343
if (srv.loop(loopCnt)):
4444
noSleep = True
4545
except BaseException as msg:
46-
print("Service loop exception: ", msg)
46+
print("[SPLASH] Service loop exception: ", msg)
4747
return noSleep
4848

4949
# RTC
@@ -64,6 +64,10 @@ def clockstring():
6464
minstr = "0"+minstr
6565
return daystr+"-"+monthstr+"-"+str(year)+" "+hourstr+":"+minstr
6666

67+
def disableWifi():
68+
nw = network.WLAN(network.STA_IF)
69+
nw.active(False)
70+
6771
def getTimeNTP():
6872
import ntp
6973
import wifi
@@ -75,35 +79,43 @@ def getTimeNTP():
7579
wifi.init()
7680
ssid = badge.nvs_get_str('badge', 'wifi.ssid', 'SHA2017-insecure')
7781
draw_msg("Configuring clock...", "Connecting to '"+ssid+"'...")
78-
timeout = 20
82+
timeout = 30
7983
while not wifi.sta_if.isconnected():
8084
time.sleep(0.1)
8185
timeout = timeout - 1
8286
if (timeout<1):
8387
draw_msg("Error", "Timeout while connecting!")
88+
disableWifi()
8489
time.sleep(1)
8590
return False
8691
else:
87-
print("Time to failure: "+str(timeout))
8892
pass
8993
draw_msg("Configuring clock...", "NTP...")
9094
ntp.set_NTP_time()
9195
draw_msg("Configuring clock...", "Done!")
96+
disableWifi()
9297
return True
93-
else:
94-
print("RTC already set.")
98+
#else:
99+
# print("[SPLASH] RTC already set.")
95100
return True
96101

97102
# BATTERY
98103

99-
def battery_percent(vempty, vfull, vbatt):
104+
def battery_percent_internal(vempty, vfull, vbatt):
100105
percent = round(((vbatt-vempty)*100)/(vfull-vempty))
101106
if (percent<0):
102107
percent = 0
103108
if (percent>100):
104109
percent = 100
105110
return percent
106111

112+
def battery_percent():
113+
vbatt = 0
114+
for i in range(0,10):
115+
vbatt = vbatt + badge.battery_volt_sense()
116+
percent = battery_percent_internal(3800, 4300, round(vbatt/10))
117+
return percent
118+
107119
# GRAPHICS
108120

109121
def draw_msg(title, desc):
@@ -129,38 +141,78 @@ def draw_logo(x,y,h):
129141
ugfx.line(x + 10 + len, y + 27, x + 10 + len, y + 45, ugfx.BLACK)
130142
ugfx.string(x + 10, y + 50,"Anyway","Roboto_BlackItalic24",ugfx.BLACK)
131143

132-
def draw_home(percent, cstate, status):
144+
def draw_helper_clear(full):
145+
if full:
146+
ugfx.clear(ugfx.BLACK)
147+
ugfx.flush()
133148
ugfx.clear(ugfx.WHITE)
134-
if (cstate):
135-
ugfx.string(0, 0, str(percent)+"% & Charging... | "+status,"Roboto_Regular12",ugfx.BLACK)
149+
if full:
150+
ugfx.flush()
151+
152+
def draw_helper_battery(percent,cstate):
153+
ugfx.area(2,2,40,18,ugfx.WHITE)
154+
ugfx.box(42,7,2,8,ugfx.WHITE)
155+
if (percent>0):
156+
if (cstate):
157+
ugfx.string(5,5,"chrg","Roboto_Regular12",ugfx.BLACK)
158+
else:
159+
if (percent>10):
160+
w = round((percent*38)/100)
161+
ugfx.area(3,3,w,16,ugfx.BLACK)
162+
else:
163+
ugfx.string(5,5,"empty","Roboto_Regular12",ugfx.BLACK)
136164
else:
137-
ugfx.string(0, 0, str(percent)+"% | "+status,"Roboto_Regular12",ugfx.BLACK)
165+
ugfx.string(2,5,"no batt","Roboto_Regular12",ugfx.BLACK)
166+
167+
def draw_helper_header(text):
168+
ugfx.area(0,0,ugfx.width(),23,ugfx.BLACK)
169+
ugfx.string(45, 1, text,"DejaVuSans20",ugfx.WHITE)
138170

139-
ugfx.string(0, 14, clockstring(), "Roboto_Regular12",ugfx.BLACK)
171+
def draw_helper_footer(text_l, text_r):
172+
ugfx.string(0, ugfx.height()-13, text_l, "Roboto_Regular12",ugfx.BLACK)
173+
l = ugfx.get_string_width(text_r,"Roboto_Regular12")
174+
ugfx.string(ugfx.width()-l, ugfx.height()-13, text_r, "Roboto_Regular12",ugfx.BLACK)
140175

176+
def draw_helper_nick(default):
177+
nick = badge.nvs_get_str("owner", "name", default)
178+
ugfx.string(0, 40, nick, "PermanentMarker36", ugfx.BLACK)
141179
htext = badge.nvs_get_str("owner", "htext", "")
142180
if (htext!=""):
143181
draw_logo(160, 25, htext)
144182

145-
nick = badge.nvs_get_str("owner", "name", "Anonymous")
146-
ugfx.string(0, 40, nick, "PermanentMarker36", ugfx.BLACK)
147-
148-
ugfx.set_lut(ugfx.LUT_FULL)
183+
def draw_helper_flush(full):
184+
if (full):
185+
ugfx.set_lut(ugfx.LUT_FULL)
149186
ugfx.flush()
150187
ugfx.set_lut(ugfx.LUT_FASTER)
151188

189+
def draw_home(percent, cstate, status, full_clear, going_to_sleep):
190+
draw_helper_clear(full_clear)
191+
if (cstate):
192+
draw_helper_header(status)
193+
else:
194+
draw_helper_header(status)
195+
draw_helper_battery(percent, cstate)
196+
if (going_to_sleep):
197+
info = "[ ANY: Wake up ]"
198+
else:
199+
info = "[ START: LAUNCHER ]"
200+
draw_helper_footer(clockstring(),info)
201+
draw_helper_nick(":(")
202+
draw_helper_flush(True)
203+
152204
def draw_batterylow(percent):
153-
ugfx.clear(ugfx.WHITE)
154-
ugfx.string(0, 0, str(percent)+"% - Battery empty. Please charge me!","Roboto_Regular12",ugfx.BLACK)
155-
nick = badge.nvs_get_str("owner", "name", ":( Zzzz...")
156-
ugfx.string(0, 40, nick, "PermanentMarker36", ugfx.BLACK)
157-
ugfx.set_lut(ugfx.LUT_FASTER)
158-
ugfx.flush()
205+
draw_helper_clear(True)
206+
draw_helper_header("")
207+
draw_helper_battery(percent, False)
208+
draw_helper_footer("BATTERY LOW, CONNECT CHARGER!", "")
209+
draw_helper_nick(":( Zzzz...")
210+
draw_helper_flush(False)
159211

160212
# START LAUNCHER
161213

162214
def start_launcher(pushed):
163-
print("START LAUNCHER: ", pushed)
215+
#print("START LAUNCHER: ", pushed)
164216
if(pushed):
165217
global splashTimer
166218
splashTimer.deinit()
@@ -169,31 +221,34 @@ def start_launcher(pushed):
169221
# SLEEP
170222

171223
def badge_sleep():
172-
print("Going to sleep now...")
224+
print("[SPLASH] Going to sleep now...")
173225
badge.eink_busy_wait() #Always wait for e-ink
174226
deepsleep.start_sleeping(30000) #Sleep for 30 seconds
175227

228+
def badge_sleep_forever():
229+
print("[SPLASH] Going to sleep WITHOUT TIME WAKEUP now...")
230+
badge.eink_busy_wait() #Always wait for e-ink
231+
deepsleep.start_sleeping(0) #Sleep until button interrupt occurs
232+
176233
# TIMER
177234

178235
def splashTimer_callback(tmr):
179236
global loopCnt
180237
if loopCnt>9:
181238
loopCnt = 0
182239
cstate = badge.battery_charge_status()
240+
percent = battery_percent()
183241
vbatt = badge.battery_volt_sense()
184-
percent = battery_percent(3800, 4300, vbatt)
185-
if (cstate) or (percent>95) or (percent<1):
186-
if (percent==0):
187-
draw_home(percent, cstate, "Huh?! You removed the battery?")
188-
else:
189-
draw_home(percent, cstate, "Press start to open the launcher!")
242+
if (cstate) or (percent>95) or (vbatt<100):
243+
draw_home(percent, cstate, "", False, False)
190244
else:
191245
if (percent<10):
192246
draw_batterylow(percent)
193247
ugfx.flush()
248+
badge_sleep_forever()
194249
else:
195-
draw_home(percent, cstate, "Zzz...")
196-
badge_sleep()
250+
draw_home(percent, cstate, "Zzz...", True, True)
251+
badge_sleep()
197252
else:
198253
if (loop_services(loopCnt)):
199254
loopCnt = 0
@@ -211,44 +266,40 @@ def restart_sleep_counter():
211266
stop_sleep_counter()
212267
start_sleep_counter()
213268

214-
# WELCOME
269+
# WELCOME (SETUP, SPONSORS OR CLOCK)
215270

216271
def welcome():
217-
setupcompleted = badge.nvs_get_str('badge', 'setup.state', 'first')
218-
if (setupcompleted=='first'):
219-
#First boot!
220-
draw_msg("Welcome to SHA2017!", "Hello and welcome to your new badge!")
221-
time.sleep(1)
222-
draw_msg("Welcome to SHA2017!", "Please configure your nickname in the settings.")
223-
time.sleep(1)
224-
badge.nvs_set_str('badge', 'setup.state', 'done')
272+
setupcompleted = int(badge.nvs_get_str('badge', 'setup.state', '0'))
273+
if (setupcompleted==0): # First boot (open setup)
274+
print("[SPLASH] Setup not completed. Running setup!")
275+
appglue.start_app("setup")
276+
elif (setupcompleted==1): # Second boot (after setup)
277+
print("[SPLASH] Showing sponsors once...")
278+
badge.nvs_set_str('badge', 'setup.state', '2') # Only force show sponsors once
279+
appglue.start_app("sponsors")
280+
else: # Setup completed
281+
print("[SPLASH] Normal boot.")
282+
getTimeNTP() # Set clock if needed
225283

226284
# MAIN
227285

228286
def splash_main():
229287
cstate = badge.battery_charge_status()
288+
percent = battery_percent()
230289
vbatt = badge.battery_volt_sense()
231-
percent = battery_percent(3800, 4300, vbatt)
290+
print("[SPLASH] Vbatt = "+str(vbatt))
232291
ugfx.init()
233-
if (cstate) or (percent>9):
292+
if (cstate) or (percent>9) or (vbatt<100):
234293
ugfx.input_init()
235294
welcome()
236-
getTimeNTP()
237-
draw_home(percent, cstate, "Press start to open launcher!")
295+
draw_home(percent, cstate, "", True, False)
238296
ugfx.input_attach(ugfx.BTN_START, start_launcher)
239297
global splashTimer
240298
setup_services()
241299
start_sleep_counter()
242-
elif(percent==0):
243-
ugfx.clear(ugfx.WHITE)
244-
ugfx.string(0, 0, "Recovery mode", "PermanentMarker22", ugfx.BLACK)
245-
ugfx.string(0, 25, "No battery. Dropping to shell...", "Roboto_Regular12", ugfx.BLACK)
246-
ugfx.set_lut(ugfx.LUT_FASTER)
247-
ugfx.flush()
248-
249300
else:
250301
draw_batterylow(percent)
251-
badge_sleep()
302+
badge_sleep_forever()
252303

253304
#Global variables
254305
splashTimer = machine.Timer(0)

esp32/modules/sponsor1.png

521 Bytes
Loading

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