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

Commit e1f8c26

Browse files
authored
Merge pull request SHA2017-badge#124 from SHA2017-badge/rstd-newSetup
New setup and default name
2 parents a4023bd + 8273ea1 commit e1f8c26

File tree

2 files changed

+22
-53
lines changed

2 files changed

+22
-53
lines changed

esp32/modules/setup.py

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,28 @@
11
# SETUP APPLICATION
2-
# SHOWN ON FIRST BOOT
2+
# v2 by Thomas Roos
3+
# v1 by Renze Nicolai
34

4-
import ugfx, badge, appglue, dialogs, utime
5+
import ugfx, badge, appglue, dialogs
56

6-
def load_settings():
7-
return badge.nvs_get_str("owner", "name", "")
7+
def asked_nickname(value):
8+
if value:
9+
badge.nvs_set_str("owner", "name", value)
810

9-
def store_settings(nickname):
10-
badge.nvs_set_str("owner", "name", nickname)
11+
# Do the firstboot magic
12+
newState = 1 if badge.nvs_get_u8('badge', 'setup.state', 0) == 0 else 3
13+
badge.nvs_set_u8('badge', 'setup.state', newState)
1114

12-
def is_developer(nickname):
13-
if (nickname==""):
15+
# Show the user that we are done
16+
ugfx.clear(ugfx.WHITE)
17+
ugfx.string(0, 0, "Hi, " + value, "PermanentMarker22", ugfx.BLACK)
18+
ugfx.string(0, 25, "Your nick is stored to flash!", "Roboto_Regular12", ugfx.BLACK)
19+
ugfx.flush(ugfx.LUT_FASTER)
20+
else:
1421
badge.nvs_set_u8('badge', 'setup.state', 2) # Skip the sponsors
15-
return True
16-
return False
1722

18-
def action_home(pressed):
19-
if (pressed):
20-
appglue.start_app("")
21-
22-
def set_setup_state():
23-
s_old = badge.nvs_get_u8('badge', 'setup.state', 0)
24-
s_new = 2
25-
if (s_old==0):
26-
s_new = 1
27-
badge.nvs_set_u8('badge', 'setup.state', s_new)
28-
29-
def draw_setup_completed():
30-
ugfx.clear(ugfx.WHITE)
31-
ugfx.string(0, 0, "Setup", "PermanentMarker22", ugfx.BLACK)
32-
ugfx.string(0, 25, "Settings stored to flash!", "Roboto_Regular12", ugfx.BLACK)
33-
ugfx.set_lut(ugfx.LUT_FASTER)
34-
ugfx.flush()
35-
36-
def return_to_home():
3723
badge.eink_busy_wait()
3824
appglue.start_app("")
3925

40-
def program_main():
41-
ugfx.init()
42-
nickname = load_settings()
43-
44-
def asked_nickname(value):
45-
nickname = value if value else nickname
46-
if not is_developer(nickname):
47-
store_settings(nickname)
48-
# Do the firstboot magic
49-
set_setup_state()
50-
# Show the user that we are done
51-
draw_setup_completed()
52-
utime.sleep(2)
53-
return_to_home()
54-
55-
dialogs.prompt_text("Nickname", nickname, cb=asked_nickname)
56-
57-
# Start main application
58-
program_main()
59-
26+
ugfx.init()
27+
nickname = badge.nvs_get_str("owner", "name", "")
28+
dialogs.prompt_text("Nickname", nickname, cb=asked_nickname)

esp32/modules/splash.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,21 @@ def inputInit():
197197
ugfx.input_attach(ugfx.JOY_RIGHT, press_nothing)
198198

199199
def checkFirstBoot():
200-
setupcompleted = int(badge.nvs_get_str('badge', 'setup.state', '0'))
200+
setupcompleted = badge.nvs_get_u8('badge', 'setup.state', 0)
201201
if setupcompleted == 0: # First boot (open setup)
202202
print("[SPLASH] Setup not completed. Running setup!")
203203
appglue.start_app("setup")
204204
elif setupcompleted == 1: # Second boot (after setup)
205205
print("[SPLASH] Showing sponsors once...")
206-
badge.nvs_set_str('badge', 'setup.state', '2') # Only force show sponsors once
206+
badge.nvs_set_u8('badge', 'setup.state', 2) # Only force show sponsors once
207207
appglue.start_app("sponsors")
208208
elif setupcompleted == 2:
209-
badge.nvs_set_str('badge', 'setup.state', '3')
209+
badge.nvs_set_u8('badge', 'setup.state', 3)
210210
check_ota_available()
211211
else: # Setup completed
212212
print("[SPLASH] Normal boot.")
213213

214-
nick = badge.nvs_get_str("owner", "name", 'John Doe')
214+
nick = badge.nvs_get_str("owner", "name", 'Jan de Boer')
215215
vMin = badge.nvs_get_u16('splash', 'bat.volt.min', 3600) # mV
216216
vMax = badge.nvs_get_u16('splash', 'bat.volt.max', 4200) # mV
217217
if badge.battery_charge_status() == False and badge.usb_volt_sense() > 4500 and badge.battery_volt_sense() > 2500:

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