Browse Source

pico_ota more garbage collecting and nicer text on display. seems to work.

Thomas Buck 1 year ago
parent
commit
e8939748ad
1 changed files with 42 additions and 23 deletions
  1. 42
    23
      pico_ota.py

+ 42
- 23
pico_ota.py View File

15
 import util
15
 import util
16
 import sys
16
 import sys
17
 import os
17
 import os
18
+import gc
18
 
19
 
19
 # to check if we're actually running on MicroPython
20
 # to check if we're actually running on MicroPython
20
 on_pico = False
21
 on_pico = False
156
             if f["path"] in self.blacklist:
157
             if f["path"] in self.blacklist:
157
                 continue
158
                 continue
158
 
159
 
160
+            gc.collect()
161
+            if hasattr(gc, "mem_free"):
162
+                print("Collected Garbage:", gc.mem_free())
163
+
159
             # get a file from a commit
164
             # get a file from a commit
160
             r = self.fetch(self.host + "/" + self.repo + "/raw/commit/" + commit + "/" + f["path"]).text
165
             r = self.fetch(self.host + "/" + self.repo + "/raw/commit/" + commit + "/" + f["path"]).text
161
 
166
 
203
         print("No update required")
208
         print("No update required")
204
 
209
 
205
 def pico_ota_run(ota):
210
 def pico_ota_run(ota):
206
-    import gc
207
-    #gc.collect()
208
-    #print(gc.mem_free())
211
+    gc.collect()
212
+    print("Collected Garbage:", gc.mem_free())
209
 
213
 
210
     i = util.getInput()
214
     i = util.getInput()
211
     t = util.getTarget(i)
215
     t = util.getTarget(i)
212
 
216
 
213
-    #gc.collect()
214
-    #print(gc.mem_free())
217
+    gc.collect()
218
+    print("Collected Garbage:", gc.mem_free())
215
 
219
 
216
-    # Loading fonts and graphics takes a while.
217
-    # So show a splash screen while the user waits.
218
-    from splash import SplashScreen
219
-    splash = SplashScreen(t)
220
+    from pico import PicoText
221
+    s = PicoText(t)
220
     t.loop_start()
222
     t.loop_start()
221
-    splash.draw()
223
+    s.setText("OTA", "bitmap6")
224
+    s.draw(0, 6 * 0, False)
225
+    s.setText("Check", "bitmap6")
226
+    s.draw(0, 6 * 2, False)
222
     t.loop_end()
227
     t.loop_end()
223
 
228
 
224
-    #gc.collect()
225
-    #print(gc.mem_free())
229
+    gc.collect()
230
+    print("Collected Garbage:", gc.mem_free())
226
 
231
 
227
     print("Checking for updates")
232
     print("Checking for updates")
228
     newer, commit = ota.check(True)
233
     newer, commit = ota.check(True)
229
 
234
 
230
-    #gc.collect()
231
-    #print(gc.mem_free())
235
+    gc.collect()
236
+    print("Collected Garbage:", gc.mem_free())
232
 
237
 
233
     if newer:
238
     if newer:
234
-        from pico import PicoText
235
-        s = PicoText(t)
236
-
237
-        s.setText("Update", "bitmap6")
238
-        s.draw(0, 0, False)
239
-
240
-        s.setText(commit, "bitmap6")
241
-        s.draw(0, 8, False)
239
+        t.loop_start()
240
+        s.setText("OTA", "bitmap6")
241
+        s.draw(0, 6 * 0, False)
242
+        s.setText(commit[0 : 6], "bitmap6")
243
+        s.draw(0, 6 * 1, False)
244
+        s.setText(commit[6 : 12], "bitmap6")
245
+        s.draw(0, 6 * 2, False)
246
+        s.setText(commit[12 : 18], "bitmap6")
247
+        s.draw(0, 6 * 3, False)
248
+        s.setText(commit[18 : 24], "bitmap6")
249
+        s.draw(0, 6 * 4, False)
250
+        t.loop_end()
242
 
251
 
243
         print("Updating to:", commit)
252
         print("Updating to:", commit)
244
         ota.update_to_commit(commit, True)
253
         ota.update_to_commit(commit, True)
245
 
254
 
246
         print("Resetting")
255
         print("Resetting")
247
         machine.soft_reset()
256
         machine.soft_reset()
257
+    else:
258
+        t.loop_start()
259
+        s.setText("OTA", "bitmap6")
260
+        s.draw(0, 6 * 0, False)
261
+        s.setText("Done", "bitmap6")
262
+        s.draw(0, 6 * 3, False)
263
+        t.loop_end()
248
 
264
 
249
     fallback = False
265
     fallback = False
250
 
266
 
293
     if not on_pico:
309
     if not on_pico:
294
         non_pico_ota_test(ota)
310
         non_pico_ota_test(ota)
295
     else:
311
     else:
296
-        ota.exe("pico_ota.py")
312
+        # TODO overwriting pico_ota causes problems?!
313
+        #ota.exe("pico_ota.py")
314
+        ota.ignore("pico_ota.py")
315
+
297
         pico_ota_run(ota)
316
         pico_ota_run(ota)

Loading…
Cancel
Save