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
2
2
3
3
def populate_it ():
4
4
global options
@@ -18,11 +18,10 @@ def populate_it():
18
18
19
19
options .add_item ('setup' )
20
20
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 )
26
25
27
26
def expandhome (s ):
28
27
if "~/" in s :
@@ -42,27 +41,26 @@ def get_install_path():
42
41
install_path = expandhome (install_path )
43
42
return install_path
44
43
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 )
66
64
67
65
68
66
ugfx .input_init ()
@@ -100,13 +98,42 @@ def perform_uninstall(ok):
100
98
101
99
populate_it ()
102
100
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 ()
108
110
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 )
111
129
112
130
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