Skip to content

Commit 1cd5ed7

Browse files
authored
Merge pull request SHA2017-badge#172 from SHA2017-badge/sleep-in-launcher
Add power management to launcher
2 parents 8189248 + 0ea431c commit 1cd5ed7

File tree

1 file changed

+61
-34
lines changed

1 file changed

+61
-34
lines changed

esp32/modules/launcher.py

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ugfx, badge, sys, uos as os, appglue, version, easydraw
1+
import ugfx, badge, sys, uos as os, appglue, version, easydraw, virtualtimers, tasks.powermanagement as pm
22

33
def populate_it():
44
global options
@@ -18,11 +18,10 @@ def populate_it():
1818

1919
options.add_item('setup')
2020

21-
def run_it(pushed):
22-
if (pushed):
23-
selected = options.selected_text()
24-
options.destroy()
25-
appglue.start_app(selected)
21+
def run_it():
22+
selected = options.selected_text()
23+
options.destroy()
24+
appglue.start_app(selected)
2625

2726
def expandhome(s):
2827
if "~/" in s:
@@ -42,27 +41,26 @@ def get_install_path():
4241
install_path = expandhome(install_path)
4342
return install_path
4443

45-
def uninstall_it(pushed):
46-
if (pushed):
47-
selected = options.selected_text()
48-
if selected == 'installer':
49-
return
50-
if selected == 'ota_update':
51-
return
52-
options.destroy()
53-
54-
def perform_uninstall(ok):
55-
if ok:
56-
easydraw.msg(selected,"Uninstalling...",True)
57-
install_path = get_install_path()
58-
for rm_file in os.listdir("%s/%s" % (install_path, selected)):
59-
os.remove("%s/%s/%s" % (install_path, selected, rm_file))
60-
os.rmdir("%s/%s" % (install_path, selected))
61-
badge.eink_busy_wait()
62-
appglue.start_app('launcher')
63-
64-
import dialogs
65-
uninstall = dialogs.prompt_boolean('Are you sure you want to remove %s?' % selected, cb=perform_uninstall)
44+
def uninstall_it():
45+
selected = options.selected_text()
46+
if selected == 'installer':
47+
return
48+
if selected == 'ota_update':
49+
return
50+
options.destroy()
51+
52+
def perform_uninstall(ok):
53+
if ok:
54+
easydraw.msg(selected,"Uninstalling...",True)
55+
install_path = get_install_path()
56+
for rm_file in os.listdir("%s/%s" % (install_path, selected)):
57+
os.remove("%s/%s/%s" % (install_path, selected, rm_file))
58+
os.rmdir("%s/%s" % (install_path, selected))
59+
badge.eink_busy_wait()
60+
appglue.start_app('launcher')
61+
62+
import dialogs
63+
uninstall = dialogs.prompt_boolean('Are you sure you want to remove %s?' % selected, cb=perform_uninstall)
6664

6765

6866
ugfx.input_init()
@@ -100,13 +98,42 @@ def perform_uninstall(ok):
10098

10199
populate_it()
102100

103-
ugfx.input_attach(ugfx.BTN_A, run_it)
104-
ugfx.input_attach(ugfx.BTN_SELECT, uninstall_it)
105-
106-
ugfx.input_attach(ugfx.JOY_UP, lambda pushed: ugfx.flush() if pushed else 0)
107-
ugfx.input_attach(ugfx.JOY_DOWN, lambda pushed: ugfx.flush() if pushed else 0)
101+
def input_a(pressed):
102+
pm.feed()
103+
if pressed:
104+
run_it()
105+
106+
def input_b(pressed):
107+
pm.feed()
108+
if pressed:
109+
appglue.home()
108110

109-
ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.home() if pushed else 0)
110-
#ugfx.input_attach(ugfx.BTN_START, lambda pushed: appglue.home() if pushed else 0)
111+
def input_select(pressed):
112+
pm.feed()
113+
if pressed:
114+
uninstall_it()
115+
116+
def input_other(pressed):
117+
pm.feed()
118+
if pressed:
119+
ugfx.flush()
120+
121+
ugfx.input_attach(ugfx.BTN_A, input_a)
122+
ugfx.input_attach(ugfx.BTN_B, input_b)
123+
ugfx.input_attach(ugfx.BTN_SELECT, input_select)
124+
ugfx.input_attach(ugfx.JOY_UP, input_other)
125+
ugfx.input_attach(ugfx.JOY_DOWN, input_other)
126+
ugfx.input_attach(ugfx.JOY_LEFT, input_other)
127+
ugfx.input_attach(ugfx.JOY_RIGHT, input_other)
128+
ugfx.input_attach(ugfx.BTN_START, input_other)
111129

112130
ugfx.flush(ugfx.LUT_FULL)
131+
132+
def pm_cb(dummy):
133+
appglue.home()
134+
135+
# Power management
136+
virtualtimers.activate(1000) # Start scheduler with 1 second ticks
137+
pm.set_timeout(5*60*1000) # Set timeout to 5 minutes
138+
pm.callback(pm_cb) # Go to splash instead of sleep
139+
pm.feed() # Feed the power management task, starts the countdown...

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