Browse Source

actually run pico_ota on pico

Thomas Buck 1 year ago
parent
commit
fc7cd6ac92
2 changed files with 66 additions and 10 deletions
  1. 2
    0
      copy.sh
  2. 64
    10
      pico_ota.py

+ 2
- 0
copy.sh View File

4
 cat << EOF | rshell
4
 cat << EOF | rshell
5
 cp config.py /pyboard
5
 cp config.py /pyboard
6
 cp pico.py /pyboard
6
 cp pico.py /pyboard
7
+cp pico_ota.py /pyboard
7
 cp util.py /pyboard
8
 cp util.py /pyboard
8
 cp manager.py /pyboard
9
 cp manager.py /pyboard
9
 cp mapper.py /pyboard
10
 cp mapper.py /pyboard
23
 rm /pyboard/main.py
24
 rm /pyboard/main.py
24
 cp config.py /pyboard
25
 cp config.py /pyboard
25
 cp pico.py /pyboard
26
 cp pico.py /pyboard
27
+cp pico_ota.py /pyboard
26
 cp util.py /pyboard
28
 cp util.py /pyboard
27
 cp manager.py /pyboard
29
 cp manager.py /pyboard
28
 cp mapper.py /pyboard
30
 cp mapper.py /pyboard

+ 64
- 10
pico_ota.py View File

61
         try:
61
         try:
62
             #print("GET " + url)
62
             #print("GET " + url)
63
             r = self.get(url)
63
             r = self.get(url)
64
-            r.close()
64
+
65
+            # explitic close on Response object not needed,
66
+            # handled internally by r.content / r.text / r.json()
67
+            # to avoid this automatic behaviour, first access r.content
68
+            # to trigger caching it in response object, then close
69
+            # socket.
70
+            tmp = r.content
71
+            if hasattr(r, "raw"):
72
+                if r.raw != None:
73
+                    r.raw.close()
74
+                    r.raw = None
75
+
65
             return r
76
             return r
66
         except Exception as e:
77
         except Exception as e:
67
             print()
78
             print()
75
     def get_stored_commit(self):
86
     def get_stored_commit(self):
76
         current = "unknown"
87
         current = "unknown"
77
         try:
88
         try:
78
-            f = open(os.path.join(self.update_path, self.version_file), "r")
89
+            f = open(self.update_path + "/" + self.version_file, "r")
79
             current = f.readline().strip()
90
             current = f.readline().strip()
80
             f.close()
91
             f.close()
81
         except Exception as e:
92
         except Exception as e:
152
                 print("Writing " + f["path"] + " to " + self.update_path)
163
                 print("Writing " + f["path"] + " to " + self.update_path)
153
 
164
 
154
             # overwrite existing file
165
             # overwrite existing file
155
-            fo = open(os.path.join(self.update_path, f["path"]), "w")
166
+            fo = open(self.update_path + "/" + f["path"], "w")
156
             fo.write(r)
167
             fo.write(r)
157
             fo.close()
168
             fo.close()
158
 
169
 
160
                 if verbose:
171
                 if verbose:
161
                     print("Writing " + f["path"] + " to main.py")
172
                     print("Writing " + f["path"] + " to main.py")
162
 
173
 
163
-                fo = open(os.path.join(self.update_path, "main.py"), "w")
174
+                fo = open(self.update_path + "/" + "main.py", "w")
164
                 fo.write(r)
175
                 fo.write(r)
165
                 fo.close()
176
                 fo.close()
166
 
177
 
167
         # Write new commit id to local file
178
         # Write new commit id to local file
168
-        f = open(os.path.join(self.update_path, self.version_file), "w")
169
-        f.write(commit + os.linesep)
179
+        f = open(self.update_path + "/" + self.version_file, "w")
180
+        f.write(commit + "\n")
170
         f.close()
181
         f.close()
171
 
182
 
172
 def non_pico_ota_test(ota):
183
 def non_pico_ota_test(ota):
192
         print("No update required")
203
         print("No update required")
193
 
204
 
194
 def pico_ota_run(ota):
205
 def pico_ota_run(ota):
206
+    import gc
207
+    #gc.collect()
208
+    #print(gc.mem_free())
209
+
210
+    i = util.getInput()
211
+    t = util.getTarget(i)
212
+
213
+    #gc.collect()
214
+    #print(gc.mem_free())
215
+
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
+    t.loop_start()
221
+    splash.draw()
222
+    t.loop_end()
223
+
224
+    #gc.collect()
225
+    #print(gc.mem_free())
226
+
227
+    print("Checking for updates")
195
     newer, commit = ota.check(True)
228
     newer, commit = ota.check(True)
196
 
229
 
230
+    #gc.collect()
231
+    #print(gc.mem_free())
232
+
197
     if newer:
233
     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)
242
+
243
+        print("Updating to:", commit)
198
         ota.update_to_commit(commit, True)
244
         ota.update_to_commit(commit, True)
245
+
246
+        print("Resetting")
199
         machine.soft_reset()
247
         machine.soft_reset()
200
 
248
 
201
     fallback = False
249
     fallback = False
202
 
250
 
203
     try:
251
     try:
252
+        gc.collect()
253
+        print("Collected Garbage:", gc.mem_free())
254
+
255
+        print("Starting Application")
204
         import camp_pico
256
         import camp_pico
205
     except Exception as e:
257
     except Exception as e:
206
-        fallback = True
207
         print()
258
         print()
208
         if hasattr(sys, "print_exception"):
259
         if hasattr(sys, "print_exception"):
209
             sys.print_exception(e)
260
             sys.print_exception(e)
211
             print(e)
262
             print(e)
212
         print()
263
         print()
213
 
264
 
265
+        print("Falling back to previous")
266
+        fallback = True
267
+
214
     # TODO this would immediately cause another update on reboot
268
     # TODO this would immediately cause another update on reboot
215
     # TODO set a flag to prevent updates after fallbacks?
269
     # TODO set a flag to prevent updates after fallbacks?
216
     # TODO or better, blacklist failed commit_id!
270
     # TODO or better, blacklist failed commit_id!
219
     #    ota.update_to_commit(previous, True)
273
     #    ota.update_to_commit(previous, True)
220
     #    machine.soft_reset()
274
     #    machine.soft_reset()
221
 
275
 
222
-if __name__ == "__main__":
276
+if True: #__name__ == "__main__":
223
     ota = PicoOTA("https://git.xythobuz.de", "thomas/rgb-matrix-visualizer")
277
     ota = PicoOTA("https://git.xythobuz.de", "thomas/rgb-matrix-visualizer")
224
 
278
 
225
     # stuff not needed on Pico
279
     # stuff not needed on Pico
228
     ota.ignore("copy.sh")
282
     ota.ignore("copy.sh")
229
     ota.ignore("config.py")
283
     ota.ignore("config.py")
230
     ota.ignore("fonts")
284
     ota.ignore("fonts")
285
+    ota.ignore("hardware")
231
     ota.ignore("images")
286
     ota.ignore("images")
232
     ota.ignore("bdf.py")
287
     ota.ignore("bdf.py")
233
     ota.ignore("camp_small.py")
288
     ota.ignore("camp_small.py")
235
     ota.ignore("pi.py")
290
     ota.ignore("pi.py")
236
     ota.ignore("test.py")
291
     ota.ignore("test.py")
237
 
292
 
238
-    ota.exe("camp_pico.py")
239
-
240
     if not on_pico:
293
     if not on_pico:
241
         non_pico_ota_test(ota)
294
         non_pico_ota_test(ota)
242
     else:
295
     else:
296
+        ota.exe("pico_ota.py")
243
         pico_ota_run(ota)
297
         pico_ota_run(ota)

Loading…
Cancel
Save