瀏覽代碼

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

Thomas Buck 10 月之前
父節點
當前提交
e8939748ad
共有 1 個檔案被更改,包括 42 行新增23 行删除
  1. 42
    23
      pico_ota.py

+ 42
- 23
pico_ota.py 查看文件

@@ -15,6 +15,7 @@
15 15
 import util
16 16
 import sys
17 17
 import os
18
+import gc
18 19
 
19 20
 # to check if we're actually running on MicroPython
20 21
 on_pico = False
@@ -156,6 +157,10 @@ class PicoOTA:
156 157
             if f["path"] in self.blacklist:
157 158
                 continue
158 159
 
160
+            gc.collect()
161
+            if hasattr(gc, "mem_free"):
162
+                print("Collected Garbage:", gc.mem_free())
163
+
159 164
             # get a file from a commit
160 165
             r = self.fetch(self.host + "/" + self.repo + "/raw/commit/" + commit + "/" + f["path"]).text
161 166
 
@@ -203,48 +208,59 @@ def non_pico_ota_test(ota):
203 208
         print("No update required")
204 209
 
205 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 214
     i = util.getInput()
211 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 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 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 232
     print("Checking for updates")
228 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 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 252
         print("Updating to:", commit)
244 253
         ota.update_to_commit(commit, True)
245 254
 
246 255
         print("Resetting")
247 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 265
     fallback = False
250 266
 
@@ -293,5 +309,8 @@ if True: #__name__ == "__main__":
293 309
     if not on_pico:
294 310
         non_pico_ota_test(ota)
295 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 316
         pico_ota_run(ota)

Loading…
取消
儲存