Browse Source

get ntp time and adjust brightness accordingly

Thomas Buck 1 year ago
parent
commit
33ea9f0cb3
14 changed files with 467 additions and 72 deletions
  1. 255
    33
      camp_pico.py
  2. 2
    0
      copy.sh
  3. 3
    2
      image.py
  4. 6
    4
      life.py
  5. 3
    2
      manager.py
  6. 81
    0
      mapper.py
  7. 18
    4
      net.py
  8. 24
    4
      pico.py
  9. 6
    2
      qr.py
  10. 4
    5
      scroll.py
  11. 3
    2
      snake.py
  12. 5
    3
      solid.py
  13. 3
    2
      tetris.py
  14. 54
    9
      util.py

+ 255
- 33
camp_pico.py View File

10
 camp_pink = (251, 72, 196)
10
 camp_pink = (251, 72, 196)
11
 camp_green = (63, 255, 33)
11
 camp_green = (63, 255, 33)
12
 
12
 
13
-# QR code image for "Hello World"
14
-# size:21x21
13
+# QR code image for "http://ubabot.frubar.net"
14
+# size:25x25
15
 qr_data = [
15
 qr_data = [
16
     [
16
     [
17
         (255, 255, 255),
17
         (255, 255, 255),
22
         (255, 255, 255),
22
         (255, 255, 255),
23
         (255, 255, 255),
23
         (255, 255, 255),
24
         (0, 0, 0),
24
         (0, 0, 0),
25
-        (0, 0, 0),
25
+        (255, 255, 255),
26
         (255, 255, 255),
26
         (255, 255, 255),
27
         (0, 0, 0),
27
         (0, 0, 0),
28
+        (255, 255, 255),
28
         (0, 0, 0),
29
         (0, 0, 0),
29
         (255, 255, 255),
30
         (255, 255, 255),
31
+        (255, 255, 255),
32
+        (255, 255, 255),
33
+        (255, 255, 255),
30
         (0, 0, 0),
34
         (0, 0, 0),
31
         (255, 255, 255),
35
         (255, 255, 255),
32
         (255, 255, 255),
36
         (255, 255, 255),
45
         (0, 0, 0),
49
         (0, 0, 0),
46
         (255, 255, 255),
50
         (255, 255, 255),
47
         (0, 0, 0),
51
         (0, 0, 0),
48
-        (255, 255, 255),
49
         (0, 0, 0),
52
         (0, 0, 0),
50
-        (255, 255, 255),
53
+        (0, 0, 0),
54
+        (0, 0, 0),
55
+        (0, 0, 0),
56
+        (0, 0, 0),
57
+        (0, 0, 0),
51
         (255, 255, 255),
58
         (255, 255, 255),
52
         (0, 0, 0),
59
         (0, 0, 0),
60
+        (255, 255, 255),
53
         (0, 0, 0),
61
         (0, 0, 0),
54
         (255, 255, 255),
62
         (255, 255, 255),
55
         (0, 0, 0),
63
         (0, 0, 0),
70
         (0, 0, 0),
78
         (0, 0, 0),
71
         (0, 0, 0),
79
         (0, 0, 0),
72
         (255, 255, 255),
80
         (255, 255, 255),
81
+        (255, 255, 255),
82
+        (255, 255, 255),
83
+        (255, 255, 255),
73
         (0, 0, 0),
84
         (0, 0, 0),
74
         (0, 0, 0),
85
         (0, 0, 0),
75
         (255, 255, 255),
86
         (255, 255, 255),
76
         (0, 0, 0),
87
         (0, 0, 0),
88
+        (0, 0, 0),
77
         (255, 255, 255),
89
         (255, 255, 255),
78
         (0, 0, 0),
90
         (0, 0, 0),
79
         (255, 255, 255),
91
         (255, 255, 255),
91
         (0, 0, 0),
103
         (0, 0, 0),
92
         (255, 255, 255),
104
         (255, 255, 255),
93
         (0, 0, 0),
105
         (0, 0, 0),
94
-        (0, 0, 0),
95
         (255, 255, 255),
106
         (255, 255, 255),
96
         (0, 0, 0),
107
         (0, 0, 0),
97
-        (0, 0, 0),
108
+        (255, 255, 255),
109
+        (255, 255, 255),
110
+        (255, 255, 255),
111
+        (255, 255, 255),
112
+        (255, 255, 255),
113
+        (255, 255, 255),
98
         (0, 0, 0),
114
         (0, 0, 0),
99
         (0, 0, 0),
115
         (0, 0, 0),
100
         (255, 255, 255),
116
         (255, 255, 255),
115
         (255, 255, 255),
131
         (255, 255, 255),
116
         (0, 0, 0),
132
         (0, 0, 0),
117
         (255, 255, 255),
133
         (255, 255, 255),
118
-        (255, 255, 255),
134
+        (0, 0, 0),
119
         (255, 255, 255),
135
         (255, 255, 255),
120
         (0, 0, 0),
136
         (0, 0, 0),
137
+        (0, 0, 0),
138
+        (255, 255, 255),
139
+        (255, 255, 255),
140
+        (255, 255, 255),
121
         (255, 255, 255),
141
         (255, 255, 255),
122
         (0, 0, 0),
142
         (0, 0, 0),
123
         (255, 255, 255),
143
         (255, 255, 255),
137
         (0, 0, 0),
157
         (0, 0, 0),
138
         (255, 255, 255),
158
         (255, 255, 255),
139
         (0, 0, 0),
159
         (0, 0, 0),
140
-        (0, 0, 0),
141
-        (0, 0, 0),
160
+        (255, 255, 255),
161
+        (255, 255, 255),
162
+        (255, 255, 255),
142
         (255, 255, 255),
163
         (255, 255, 255),
143
         (0, 0, 0),
164
         (0, 0, 0),
144
         (255, 255, 255),
165
         (255, 255, 255),
166
+        (255, 255, 255),
167
+        (0, 0, 0),
168
+        (0, 0, 0),
145
         (0, 0, 0),
169
         (0, 0, 0),
146
         (255, 255, 255),
170
         (255, 255, 255),
147
         (0, 0, 0),
171
         (0, 0, 0),
167
         (255, 255, 255),
191
         (255, 255, 255),
168
         (0, 0, 0),
192
         (0, 0, 0),
169
         (255, 255, 255),
193
         (255, 255, 255),
194
+        (0, 0, 0),
195
+        (255, 255, 255),
196
+        (0, 0, 0),
197
+        (255, 255, 255),
170
         (255, 255, 255),
198
         (255, 255, 255),
171
         (255, 255, 255),
199
         (255, 255, 255),
172
         (255, 255, 255),
200
         (255, 255, 255),
183
         (0, 0, 0),
211
         (0, 0, 0),
184
         (0, 0, 0),
212
         (0, 0, 0),
185
         (0, 0, 0),
213
         (0, 0, 0),
214
+        (255, 255, 255),
215
+        (0, 0, 0),
216
+        (255, 255, 255),
186
         (0, 0, 0),
217
         (0, 0, 0),
187
         (255, 255, 255),
218
         (255, 255, 255),
188
         (0, 0, 0),
219
         (0, 0, 0),
189
         (255, 255, 255),
220
         (255, 255, 255),
221
+        (0, 0, 0),
190
         (255, 255, 255),
222
         (255, 255, 255),
191
         (0, 0, 0),
223
         (0, 0, 0),
192
         (0, 0, 0),
224
         (0, 0, 0),
200
     [
232
     [
201
         (255, 255, 255),
233
         (255, 255, 255),
202
         (0, 0, 0),
234
         (0, 0, 0),
235
+        (0, 0, 0),
236
+        (0, 0, 0),
237
+        (255, 255, 255),
238
+        (0, 0, 0),
203
         (255, 255, 255),
239
         (255, 255, 255),
240
+        (255, 255, 255),
241
+        (255, 255, 255),
242
+        (255, 255, 255),
243
+        (0, 0, 0),
204
         (0, 0, 0),
244
         (0, 0, 0),
205
         (255, 255, 255),
245
         (255, 255, 255),
206
         (0, 0, 0),
246
         (0, 0, 0),
247
+        (0, 0, 0),
248
+        (0, 0, 0),
249
+        (255, 255, 255),
250
+        (255, 255, 255),
251
+        (255, 255, 255),
252
+        (255, 255, 255),
253
+        (255, 255, 255),
207
         (255, 255, 255),
254
         (255, 255, 255),
208
         (0, 0, 0),
255
         (0, 0, 0),
209
         (0, 0, 0),
256
         (0, 0, 0),
210
         (255, 255, 255),
257
         (255, 255, 255),
258
+    ],
259
+    [
211
         (255, 255, 255),
260
         (255, 255, 255),
212
         (255, 255, 255),
261
         (255, 255, 255),
213
         (0, 0, 0),
262
         (0, 0, 0),
214
         (0, 0, 0),
263
         (0, 0, 0),
215
         (0, 0, 0),
264
         (0, 0, 0),
265
+        (255, 255, 255),
266
+        (0, 0, 0),
267
+        (255, 255, 255),
268
+        (255, 255, 255),
269
+        (255, 255, 255),
270
+        (0, 0, 0),
271
+        (255, 255, 255),
272
+        (255, 255, 255),
273
+        (255, 255, 255),
216
         (0, 0, 0),
274
         (0, 0, 0),
217
         (255, 255, 255),
275
         (255, 255, 255),
276
+        (255, 255, 255),
277
+        (0, 0, 0),
218
         (0, 0, 0),
278
         (0, 0, 0),
219
         (0, 0, 0),
279
         (0, 0, 0),
220
         (255, 255, 255),
280
         (255, 255, 255),
281
+        (255, 255, 255),
282
+        (0, 0, 0),
283
+        (255, 255, 255),
221
         (0, 0, 0),
284
         (0, 0, 0),
222
     ],
285
     ],
223
     [
286
     [
224
         (0, 0, 0),
287
         (0, 0, 0),
288
+        (0, 0, 0),
289
+        (0, 0, 0),
225
         (255, 255, 255),
290
         (255, 255, 255),
226
         (0, 0, 0),
291
         (0, 0, 0),
227
         (255, 255, 255),
292
         (255, 255, 255),
228
         (255, 255, 255),
293
         (255, 255, 255),
229
         (0, 0, 0),
294
         (0, 0, 0),
295
+        (255, 255, 255),
230
         (0, 0, 0),
296
         (0, 0, 0),
231
         (255, 255, 255),
297
         (255, 255, 255),
232
         (255, 255, 255),
298
         (255, 255, 255),
233
         (0, 0, 0),
299
         (0, 0, 0),
234
-        (0, 0, 0),
235
-        (0, 0, 0),
236
-        (0, 0, 0),
300
+        (255, 255, 255),
237
         (0, 0, 0),
301
         (0, 0, 0),
238
         (255, 255, 255),
302
         (255, 255, 255),
239
         (255, 255, 255),
303
         (255, 255, 255),
242
         (0, 0, 0),
306
         (0, 0, 0),
243
         (255, 255, 255),
307
         (255, 255, 255),
244
         (255, 255, 255),
308
         (255, 255, 255),
309
+        (255, 255, 255),
310
+        (0, 0, 0),
311
+        (0, 0, 0),
245
     ],
312
     ],
246
     [
313
     [
314
+        (255, 255, 255),
315
+        (255, 255, 255),
316
+        (0, 0, 0),
317
+        (0, 0, 0),
318
+        (0, 0, 0),
319
+        (255, 255, 255),
320
+        (0, 0, 0),
321
+        (0, 0, 0),
322
+        (0, 0, 0),
247
         (0, 0, 0),
323
         (0, 0, 0),
248
         (255, 255, 255),
324
         (255, 255, 255),
325
+        (255, 255, 255),
326
+        (0, 0, 0),
327
+        (0, 0, 0),
328
+        (0, 0, 0),
329
+        (0, 0, 0),
330
+        (0, 0, 0),
249
         (0, 0, 0),
331
         (0, 0, 0),
250
         (0, 0, 0),
332
         (0, 0, 0),
251
         (0, 0, 0),
333
         (0, 0, 0),
252
         (0, 0, 0),
334
         (0, 0, 0),
335
+        (0, 0, 0),
336
+        (255, 255, 255),
253
         (255, 255, 255),
337
         (255, 255, 255),
338
+        (0, 0, 0),
339
+    ],
340
+    [
254
         (255, 255, 255),
341
         (255, 255, 255),
342
+        (0, 0, 0),
255
         (255, 255, 255),
343
         (255, 255, 255),
256
         (0, 0, 0),
344
         (0, 0, 0),
345
+        (0, 0, 0),
346
+        (0, 0, 0),
257
         (255, 255, 255),
347
         (255, 255, 255),
258
         (0, 0, 0),
348
         (0, 0, 0),
349
+        (0, 0, 0),
350
+        (0, 0, 0),
351
+        (0, 0, 0),
259
         (255, 255, 255),
352
         (255, 255, 255),
353
+        (0, 0, 0),
354
+        (0, 0, 0),
260
         (255, 255, 255),
355
         (255, 255, 255),
261
         (0, 0, 0),
356
         (0, 0, 0),
357
+        (0, 0, 0),
262
         (255, 255, 255),
358
         (255, 255, 255),
263
         (255, 255, 255),
359
         (255, 255, 255),
264
         (255, 255, 255),
360
         (255, 255, 255),
361
+        (0, 0, 0),
362
+        (255, 255, 255),
265
         (255, 255, 255),
363
         (255, 255, 255),
266
         (255, 255, 255),
364
         (255, 255, 255),
267
         (255, 255, 255),
365
         (255, 255, 255),
268
     ],
366
     ],
269
     [
367
     [
368
+        (255, 255, 255),
369
+        (255, 255, 255),
270
         (0, 0, 0),
370
         (0, 0, 0),
371
+        (0, 0, 0),
372
+        (255, 255, 255),
271
         (255, 255, 255),
373
         (255, 255, 255),
374
+        (0, 0, 0),
272
         (255, 255, 255),
375
         (255, 255, 255),
273
         (0, 0, 0),
376
         (0, 0, 0),
274
         (255, 255, 255),
377
         (255, 255, 255),
378
+        (0, 0, 0),
379
+        (0, 0, 0),
275
         (255, 255, 255),
380
         (255, 255, 255),
276
         (0, 0, 0),
381
         (0, 0, 0),
277
         (255, 255, 255),
382
         (255, 255, 255),
280
         (0, 0, 0),
385
         (0, 0, 0),
281
         (0, 0, 0),
386
         (0, 0, 0),
282
         (0, 0, 0),
387
         (0, 0, 0),
388
+        (255, 255, 255),
389
+        (0, 0, 0),
390
+        (0, 0, 0),
391
+        (255, 255, 255),
392
+        (0, 0, 0),
393
+    ],
394
+    [
395
+        (0, 0, 0),
396
+        (0, 0, 0),
397
+        (255, 255, 255),
398
+        (255, 255, 255),
399
+        (255, 255, 255),
400
+        (0, 0, 0),
401
+        (255, 255, 255),
402
+        (255, 255, 255),
283
         (0, 0, 0),
403
         (0, 0, 0),
284
         (0, 0, 0),
404
         (0, 0, 0),
285
         (0, 0, 0),
405
         (0, 0, 0),
286
         (255, 255, 255),
406
         (255, 255, 255),
407
+        (255, 255, 255),
408
+        (255, 255, 255),
409
+        (255, 255, 255),
410
+        (255, 255, 255),
411
+        (255, 255, 255),
412
+        (255, 255, 255),
287
         (0, 0, 0),
413
         (0, 0, 0),
414
+        (255, 255, 255),
288
         (0, 0, 0),
415
         (0, 0, 0),
289
         (255, 255, 255),
416
         (255, 255, 255),
417
+        (255, 255, 255),
418
+        (0, 0, 0),
290
         (0, 0, 0),
419
         (0, 0, 0),
291
     ],
420
     ],
292
     [
421
     [
293
         (0, 0, 0),
422
         (0, 0, 0),
423
+        (0, 0, 0),
424
+        (0, 0, 0),
425
+        (0, 0, 0),
294
         (255, 255, 255),
426
         (255, 255, 255),
295
         (0, 0, 0),
427
         (0, 0, 0),
428
+        (0, 0, 0),
429
+        (0, 0, 0),
296
         (255, 255, 255),
430
         (255, 255, 255),
297
         (255, 255, 255),
431
         (255, 255, 255),
298
         (0, 0, 0),
432
         (0, 0, 0),
299
         (255, 255, 255),
433
         (255, 255, 255),
300
         (0, 0, 0),
434
         (0, 0, 0),
435
+        (0, 0, 0),
436
+        (0, 0, 0),
437
+        (0, 0, 0),
438
+        (0, 0, 0),
439
+        (255, 255, 255),
440
+        (255, 255, 255),
441
+        (255, 255, 255),
442
+        (0, 0, 0),
301
         (255, 255, 255),
443
         (255, 255, 255),
302
         (255, 255, 255),
444
         (255, 255, 255),
303
         (255, 255, 255),
445
         (255, 255, 255),
304
         (0, 0, 0),
446
         (0, 0, 0),
447
+    ],
448
+    [
305
         (255, 255, 255),
449
         (255, 255, 255),
306
         (255, 255, 255),
450
         (255, 255, 255),
307
         (0, 0, 0),
451
         (0, 0, 0),
452
+        (0, 0, 0),
453
+        (0, 0, 0),
454
+        (0, 0, 0),
455
+        (255, 255, 255),
456
+        (0, 0, 0),
457
+        (0, 0, 0),
308
         (255, 255, 255),
458
         (255, 255, 255),
309
         (255, 255, 255),
459
         (255, 255, 255),
310
         (0, 0, 0),
460
         (0, 0, 0),
461
+        (255, 255, 255),
462
+        (0, 0, 0),
311
         (0, 0, 0),
463
         (0, 0, 0),
464
+        (255, 255, 255),
465
+        (255, 255, 255),
466
+        (255, 255, 255),
467
+        (255, 255, 255),
468
+        (255, 255, 255),
469
+        (255, 255, 255),
470
+        (255, 255, 255),
471
+        (255, 255, 255),
312
         (0, 0, 0),
472
         (0, 0, 0),
313
         (0, 0, 0),
473
         (0, 0, 0),
314
     ],
474
     ],
322
         (0, 0, 0),
482
         (0, 0, 0),
323
         (0, 0, 0),
483
         (0, 0, 0),
324
         (255, 255, 255),
484
         (255, 255, 255),
325
-        (0, 0, 0),
326
         (255, 255, 255),
485
         (255, 255, 255),
327
         (255, 255, 255),
486
         (255, 255, 255),
328
         (0, 0, 0),
487
         (0, 0, 0),
488
+        (0, 0, 0),
489
+        (0, 0, 0),
329
         (255, 255, 255),
490
         (255, 255, 255),
330
         (0, 0, 0),
491
         (0, 0, 0),
492
+        (255, 255, 255),
331
         (0, 0, 0),
493
         (0, 0, 0),
332
         (0, 0, 0),
494
         (0, 0, 0),
333
         (0, 0, 0),
495
         (0, 0, 0),
334
         (255, 255, 255),
496
         (255, 255, 255),
497
+        (0, 0, 0),
335
         (255, 255, 255),
498
         (255, 255, 255),
336
         (0, 0, 0),
499
         (0, 0, 0),
500
+        (0, 0, 0),
337
     ],
501
     ],
338
     [
502
     [
339
         (255, 255, 255),
503
         (255, 255, 255),
344
         (255, 255, 255),
508
         (255, 255, 255),
345
         (255, 255, 255),
509
         (255, 255, 255),
346
         (0, 0, 0),
510
         (0, 0, 0),
347
-        (0, 0, 0),
348
-        (255, 255, 255),
349
-        (255, 255, 255),
350
         (255, 255, 255),
511
         (255, 255, 255),
351
         (0, 0, 0),
512
         (0, 0, 0),
513
+        (255, 255, 255),
352
         (0, 0, 0),
514
         (0, 0, 0),
353
         (0, 0, 0),
515
         (0, 0, 0),
354
         (255, 255, 255),
516
         (255, 255, 255),
355
         (255, 255, 255),
517
         (255, 255, 255),
356
         (0, 0, 0),
518
         (0, 0, 0),
357
         (255, 255, 255),
519
         (255, 255, 255),
520
+        (0, 0, 0),
521
+        (255, 255, 255),
522
+        (0, 0, 0),
358
         (255, 255, 255),
523
         (255, 255, 255),
359
         (255, 255, 255),
524
         (255, 255, 255),
525
+        (0, 0, 0),
526
+        (0, 0, 0),
527
+        (0, 0, 0),
360
     ],
528
     ],
361
     [
529
     [
362
         (255, 255, 255),
530
         (255, 255, 255),
369
         (0, 0, 0),
537
         (0, 0, 0),
370
         (0, 0, 0),
538
         (0, 0, 0),
371
         (0, 0, 0),
539
         (0, 0, 0),
372
-        (0, 0, 0),
373
         (255, 255, 255),
540
         (255, 255, 255),
541
+        (0, 0, 0),
374
         (255, 255, 255),
542
         (255, 255, 255),
375
         (0, 0, 0),
543
         (0, 0, 0),
376
         (0, 0, 0),
544
         (0, 0, 0),
377
         (255, 255, 255),
545
         (255, 255, 255),
546
+        (255, 255, 255),
378
         (0, 0, 0),
547
         (0, 0, 0),
379
         (0, 0, 0),
548
         (0, 0, 0),
380
         (0, 0, 0),
549
         (0, 0, 0),
381
-        (0, 0, 0),
382
         (255, 255, 255),
550
         (255, 255, 255),
551
+        (255, 255, 255),
552
+        (255, 255, 255),
553
+        (255, 255, 255),
554
+        (0, 0, 0),
383
     ],
555
     ],
384
     [
556
     [
385
         (255, 255, 255),
557
         (255, 255, 255),
394
         (255, 255, 255),
566
         (255, 255, 255),
395
         (255, 255, 255),
567
         (255, 255, 255),
396
         (255, 255, 255),
568
         (255, 255, 255),
397
-        (0, 0, 0),
569
+        (255, 255, 255),
398
         (0, 0, 0),
570
         (0, 0, 0),
399
         (0, 0, 0),
571
         (0, 0, 0),
400
         (0, 0, 0),
572
         (0, 0, 0),
401
         (255, 255, 255),
573
         (255, 255, 255),
574
+        (255, 255, 255),
575
+        (255, 255, 255),
576
+        (255, 255, 255),
577
+        (255, 255, 255),
402
         (0, 0, 0),
578
         (0, 0, 0),
403
-        (0, 0, 0),
579
+        (255, 255, 255),
404
         (0, 0, 0),
580
         (0, 0, 0),
405
         (0, 0, 0),
581
         (0, 0, 0),
406
     ],
582
     ],
416
         (0, 0, 0),
592
         (0, 0, 0),
417
         (255, 255, 255),
593
         (255, 255, 255),
418
         (255, 255, 255),
594
         (255, 255, 255),
419
-        (255, 255, 255),
420
-        (0, 0, 0),
421
         (0, 0, 0),
595
         (0, 0, 0),
422
         (255, 255, 255),
596
         (255, 255, 255),
423
         (255, 255, 255),
597
         (255, 255, 255),
424
         (255, 255, 255),
598
         (255, 255, 255),
425
         (0, 0, 0),
599
         (0, 0, 0),
600
+        (0, 0, 0),
426
         (255, 255, 255),
601
         (255, 255, 255),
427
         (255, 255, 255),
602
         (255, 255, 255),
428
         (0, 0, 0),
603
         (0, 0, 0),
604
+        (0, 0, 0),
605
+        (255, 255, 255),
606
+        (255, 255, 255),
607
+        (255, 255, 255),
608
+        (255, 255, 255),
429
     ],
609
     ],
430
     [
610
     [
431
         (255, 255, 255),
611
         (255, 255, 255),
436
         (0, 0, 0),
616
         (0, 0, 0),
437
         (255, 255, 255),
617
         (255, 255, 255),
438
         (0, 0, 0),
618
         (0, 0, 0),
439
-        (255, 255, 255),
440
         (0, 0, 0),
619
         (0, 0, 0),
441
         (255, 255, 255),
620
         (255, 255, 255),
442
-        (0, 0, 0),
443
         (255, 255, 255),
621
         (255, 255, 255),
444
-        (0, 0, 0),
445
         (255, 255, 255),
622
         (255, 255, 255),
446
         (0, 0, 0),
623
         (0, 0, 0),
624
+        (0, 0, 0),
447
         (255, 255, 255),
625
         (255, 255, 255),
448
         (0, 0, 0),
626
         (0, 0, 0),
449
         (255, 255, 255),
627
         (255, 255, 255),
628
+        (255, 255, 255),
629
+        (255, 255, 255),
630
+        (255, 255, 255),
631
+        (0, 0, 0),
632
+        (0, 0, 0),
450
         (0, 0, 0),
633
         (0, 0, 0),
451
         (255, 255, 255),
634
         (255, 255, 255),
635
+        (0, 0, 0),
452
     ],
636
     ],
453
     [
637
     [
454
         (255, 255, 255),
638
         (255, 255, 255),
461
         (0, 0, 0),
645
         (0, 0, 0),
462
         (0, 0, 0),
646
         (0, 0, 0),
463
         (0, 0, 0),
647
         (0, 0, 0),
648
+        (0, 0, 0),
464
         (255, 255, 255),
649
         (255, 255, 255),
465
         (255, 255, 255),
650
         (255, 255, 255),
466
         (0, 0, 0),
651
         (0, 0, 0),
652
+        (255, 255, 255),
467
         (0, 0, 0),
653
         (0, 0, 0),
468
         (0, 0, 0),
654
         (0, 0, 0),
469
         (0, 0, 0),
655
         (0, 0, 0),
470
         (255, 255, 255),
656
         (255, 255, 255),
471
-        (0, 0, 0),
472
-        (0, 0, 0),
657
+        (255, 255, 255),
658
+        (255, 255, 255),
659
+        (255, 255, 255),
660
+        (255, 255, 255),
473
         (255, 255, 255),
661
         (255, 255, 255),
474
         (0, 0, 0),
662
         (0, 0, 0),
475
     ],
663
     ],
483
         (255, 255, 255),
671
         (255, 255, 255),
484
         (0, 0, 0),
672
         (0, 0, 0),
485
         (255, 255, 255),
673
         (255, 255, 255),
486
-        (255, 255, 255),
487
         (0, 0, 0),
674
         (0, 0, 0),
488
-        (255, 255, 255),
489
-        (255, 255, 255),
490
         (0, 0, 0),
675
         (0, 0, 0),
491
         (0, 0, 0),
676
         (0, 0, 0),
677
+        (0, 0, 0),
678
+        (0, 0, 0),
679
+        (0, 0, 0),
680
+        (255, 255, 255),
681
+        (0, 0, 0),
492
         (255, 255, 255),
682
         (255, 255, 255),
493
         (0, 0, 0),
683
         (0, 0, 0),
494
         (0, 0, 0),
684
         (0, 0, 0),
495
         (0, 0, 0),
685
         (0, 0, 0),
686
+        (0, 0, 0),
687
+        (255, 255, 255),
496
         (255, 255, 255),
688
         (255, 255, 255),
497
         (255, 255, 255),
689
         (255, 255, 255),
498
     ],
690
     ],
504
     from net import CheckHTTP
696
     from net import CheckHTTP
505
     from qr import QRScreen
697
     from qr import QRScreen
506
     from scroll import ScrollText
698
     from scroll import ScrollText
699
+    from splash import SplashScreen
507
     from manager import Manager
700
     from manager import Manager
508
 
701
 
702
+    #url = "http://ubabot.frubar.net"
703
+    url = "http://xythobuz.de"
704
+
509
     import util
705
     import util
510
     t = util.getTarget()
706
     t = util.getTarget()
511
 
707
 
708
+    # Loading fonts and graphics takes a while.
709
+    # So show a splash screen while the user waits.
710
+    splash = SplashScreen(t)
711
+    t.loop_start()
712
+    splash.draw()
713
+    t.loop_end()
714
+
715
+    # UbaBot is online
716
+    success = Manager(t)
717
+    success.add(ScrollText(t, "Visit UbaBot Cocktail machine at FruBar village for drinks!", "bitmap8", 1, 10, camp_pink))
718
+    success.add(Solid(t, 1.0))
719
+    success.add(QRScreen(t, qr_data, 30.0, "Drinks", "bitmap6", (255, 255, 255), (0, 0, 0)))
720
+    success.add(Solid(t, 1.0))
721
+
722
+    # UbaBot is offline
723
+    fail = Manager(t)
724
+    fail.add(ScrollText(t, "The UbaBot Cocktail machine is closed. Please come back later!", "bitmap8", 1, 10, camp_pink))
725
+    fail.add(Solid(t, 1.0))
726
+    fail.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), None, 2.0))
727
+    fail.add(Solid(t, 1.0))
728
+
729
+    # UbaBot status checker
730
+    d = CheckHTTP(url)
731
+    d.success(success)
732
+    d.fail(fail)
733
+
512
     # Main "Menu"
734
     # Main "Menu"
513
     m = Manager(t)
735
     m = Manager(t)
514
     m.add(ScrollText(t, "#CCCAMP23", "bitmap8", 1, 10, camp_green))
736
     m.add(ScrollText(t, "#CCCAMP23", "bitmap8", 1, 10, camp_green))
515
     m.add(Solid(t, 1.0))
737
     m.add(Solid(t, 1.0))
516
-    #m.add(QRScreen(t, qr_data, 30.0, "Drinks:", "bitmap8", (255, 255, 255), (0, 0, 0)))
517
-    #m.add(Solid(t, 1.0))
738
+    m.add(d) # HTTP Check, either "success" or "fail"
739
+    m.add(Solid(t, 1.0))
518
 
740
 
519
     m.restart()
741
     m.restart()
520
     t.loop(m.draw)
742
     t.loop(m.draw)

+ 2
- 0
copy.sh View File

6
 cp pico.py /pyboard
6
 cp pico.py /pyboard
7
 cp util.py /pyboard
7
 cp util.py /pyboard
8
 cp manager.py /pyboard
8
 cp manager.py /pyboard
9
+cp mapper.py /pyboard
9
 cp net.py /pyboard
10
 cp net.py /pyboard
10
 cp solid.py /pyboard
11
 cp solid.py /pyboard
11
 cp splash.py /pyboard
12
 cp splash.py /pyboard
22
 cp pico.py /pyboard
23
 cp pico.py /pyboard
23
 cp util.py /pyboard
24
 cp util.py /pyboard
24
 cp manager.py /pyboard
25
 cp manager.py /pyboard
26
+cp mapper.py /pyboard
25
 cp net.py /pyboard
27
 cp net.py /pyboard
26
 cp solid.py /pyboard
28
 cp solid.py /pyboard
27
 cp splash.py /pyboard
29
 cp splash.py /pyboard

+ 3
- 2
image.py View File

68
 
68
 
69
     def draw(self):
69
     def draw(self):
70
         if self.image.is_animated:
70
         if self.image.is_animated:
71
-            if (time.time() - self.frame) >= self.time:
72
-                self.frame = time.time()
71
+            now = time.time()
72
+            if (now - self.frame) >= self.time:
73
+                self.frame = now
73
                 self.count = (self.count + 1) % self.image.n_frames
74
                 self.count = (self.count + 1) % self.image.n_frames
74
                 if self.count == 0:
75
                 if self.count == 0:
75
                     self.done += 1
76
                     self.done += 1

+ 6
- 4
life.py View File

122
         self.lastDiff = diff
122
         self.lastDiff = diff
123
 
123
 
124
     def draw(self):
124
     def draw(self):
125
-        if (time.time() - self.last) > self.interval:
126
-            self.last = time.time()
125
+        now = time.time()
126
+        if (now - self.last) > self.interval:
127
+            self.last = now
127
             self.step()
128
             self.step()
128
 
129
 
129
         if (self.randomizeColors != None) and (self.randomizeColors != True):
130
         if (self.randomizeColors != None) and (self.randomizeColors != True):
130
-            if (time.time() - self.lastColor) > self.randomizeColors:
131
-                self.lastColor = time.time()
131
+            now = time.time()
132
+            if (now - self.lastColor) > self.randomizeColors:
133
+                self.lastColor = now
132
                 self.randomize()
134
                 self.randomize()
133
 
135
 
134
         for x in range(0, self.gui.width):
136
         for x in range(0, self.gui.width):

+ 3
- 2
manager.py View File

41
                 self.screens[self.index][0].restart()
41
                 self.screens[self.index][0].restart()
42
         else:
42
         else:
43
             # use given timeout
43
             # use given timeout
44
-            if (time.time() - self.lastTime) > self.screens[self.index][1]:
45
-                self.lastTime = time.time()
44
+            now = time.time()
45
+            if ((now - self.lastTime) > self.screens[self.index][1]) or (now < self.lastTime):
46
+                self.lastTime = now
46
                 self.index = (self.index + 1) % len(self.screens)
47
                 self.index = (self.index + 1) % len(self.screens)
47
                 self.done = (self.index == 0)
48
                 self.done = (self.index == 0)
48
                 self.screens[self.index][0].restart()
49
                 self.screens[self.index][0].restart()

+ 81
- 0
mapper.py View File

7
 # think this stuff is worth it, you can buy me a beer in return.   Thomas Buck
7
 # think this stuff is worth it, you can buy me a beer in return.   Thomas Buck
8
 # ----------------------------------------------------------------------------
8
 # ----------------------------------------------------------------------------
9
 
9
 
10
+import util
11
+import time
12
+import sys
13
+
14
+useNTP = False
15
+try:
16
+    import ntptime
17
+    useNTP = True
18
+except:
19
+    pass
20
+
10
 # Does nothing. Take this as parent for new mappers.
21
 # Does nothing. Take this as parent for new mappers.
11
 class MapperNull:
22
 class MapperNull:
12
     def __init__(self, g):
23
     def __init__(self, g):
17
         self.panelW = self.gui.panelW
28
         self.panelW = self.gui.panelW
18
         self.panelH = self.gui.panelH
29
         self.panelH = self.gui.panelH
19
 
30
 
31
+        if hasattr(self.gui, "matrix"):
32
+            self.matrix = self.gui.matrix
33
+
20
     def loop_start(self):
34
     def loop_start(self):
21
         return self.gui.loop_start()
35
         return self.gui.loop_start()
22
 
36
 
69
             y -= self.panelH
83
             y -= self.panelH
70
 
84
 
71
         self.gui.set_pixel(x, y, color)
85
         self.gui.set_pixel(x, y, color)
86
+
87
+# Fetches current time via NTP.
88
+# System time will be in UTC afterwards, not with local time-zone
89
+# offset like when using rshell (eg. when using with a Pico).
90
+#
91
+# Brightness of display will be adjusted according to current time.
92
+# To avoid being too bright at night.
93
+#
94
+# When used with the Interstate75 Pico implementation,
95
+# this needs to be the "first" element of the mapper chain.
96
+# Otherwise special handling for PicoText will not work.
97
+class MapperReduceBrightness(MapperNull):
98
+    def __init__(self, g):
99
+        super().__init__(g)
100
+        self.last = None
101
+        self.connected = False
102
+        self.refresh = 60 * 60 * 6
103
+        self.factor = 1.0
104
+
105
+    def fetch(self):
106
+        self.factor = 1.0
107
+
108
+        if not useNTP:
109
+            return
110
+
111
+        if not self.connected:
112
+            self.connected = util.connectToWiFi()
113
+
114
+        if self.connected:
115
+            now = time.time()
116
+            if (self.last == None) or ((now - self.last) >= self.refresh) or (now < self.last):
117
+                self.last = now
118
+
119
+                try:
120
+                    print("Before sync: " + str(time.localtime()))
121
+                    ntptime.settime()
122
+                    print("After sync: "  + str(time.localtime()))
123
+                except Exception as e:
124
+                    print()
125
+                    sys.print_exception(e)
126
+                    print()
127
+                    return
128
+
129
+        # (year, month, day, hour, minute, second, ?, ?)
130
+        now = time.localtime()
131
+
132
+        # 8pm utc == 22pm dst germany
133
+        night = (now[0], now[1], now[2], 20, 0, 0, 0, 0)
134
+
135
+        # 5am utc == 7am dst germany
136
+        morning = (now[0], now[1], now[2], 5, 0, 0, 0, 0)
137
+
138
+        if (now > morning) and (now < night):
139
+            self.factor = 1.0
140
+        else:
141
+            self.factor = 0.25
142
+
143
+    def adjust(self, color):
144
+        return (int(color[0] * self.factor), int(color[1] * self.factor), int(color[2] * self.factor))
145
+
146
+    def loop_end(self):
147
+        super().loop_end()
148
+        self.fetch()
149
+
150
+    def set_pixel(self, x, y, color):
151
+        color = self.adjust(color)
152
+        self.gui.set_pixel(x, y, color)

+ 18
- 4
net.py View File

9
 
9
 
10
 import time
10
 import time
11
 import util
11
 import util
12
+import sys
12
 
13
 
13
 class CheckHTTP:
14
 class CheckHTTP:
14
     def __init__(self, u, r = 600.0):
15
     def __init__(self, u, r = 600.0):
16
         self.refresh = r
17
         self.refresh = r
17
         self.successScreen = None
18
         self.successScreen = None
18
         self.failScreen = None
19
         self.failScreen = None
20
+        self.response = None
19
         self.get = util.getRequests()
21
         self.get = util.getRequests()
20
 
22
 
21
         self.restart()
23
         self.restart()
28
 
30
 
29
     def restart(self):
31
     def restart(self):
30
         self.start = time.time()
32
         self.start = time.time()
31
-        self.response = None
33
+
34
+        # when set to None here, manager will cause re-request every time
35
+        # we don't do it, caching the response for the full refresh time.
36
+        # this assumes the URL never changes, of course.
37
+        #self.response = None
38
+
32
         self.request()
39
         self.request()
33
 
40
 
34
         if self.successScreen != None:
41
         if self.successScreen != None:
40
         if self.get == None:
47
         if self.get == None:
41
             return
48
             return
42
 
49
 
43
-        if (self.response == None) or ((time.time() - self.start) >= self.refresh):
44
-            self.start = time.time()
50
+        now = time.time()
51
+        if (self.response == None) or ((now - self.start) >= self.refresh):
52
+            self.start = now
45
             try:
53
             try:
54
+                print("Refreshing " + self.url)
46
                 r = self.get(self.url)
55
                 r = self.get(self.url)
56
+                r.close()
57
+                print("Response: " + str(r.status_code))
47
                 self.response = (r.status_code < 400)
58
                 self.response = (r.status_code < 400)
48
-            except:
59
+            except Exception as e:
60
+                print()
61
+                sys.print_exception(e)
62
+                print()
49
                 self.response = False
63
                 self.response = False
50
 
64
 
51
     def finished(self):
65
     def finished(self):

+ 24
- 4
pico.py View File

11
 # ----------------------------------------------------------------------------
11
 # ----------------------------------------------------------------------------
12
 
12
 
13
 import interstate75
13
 import interstate75
14
+from mapper import MapperReduceBrightness
15
+import time
16
+from machine import Pin
14
 
17
 
15
 class PicoMatrix:
18
 class PicoMatrix:
16
     def __init__(self, w = 32, h = 32):
19
     def __init__(self, w = 32, h = 32):
26
         if (w != 32) or (h != 32):
29
         if (w != 32) or (h != 32):
27
             raise RuntimeError("TODO not yet supported")
30
             raise RuntimeError("TODO not yet supported")
28
 
31
 
29
-        self.matrix = interstate75.Interstate75(display = interstate75.DISPLAY_INTERSTATE75_32X32)
32
+        mode = interstate75.DISPLAY_INTERSTATE75_32X32
33
+        self.matrix = interstate75.Interstate75(display = mode)
30
 
34
 
31
         self.black = self.matrix.display.create_pen(0, 0, 0)
35
         self.black = self.matrix.display.create_pen(0, 0, 0)
32
         self.white = self.matrix.display.create_pen(255, 255, 255)
36
         self.white = self.matrix.display.create_pen(255, 255, 255)
33
 
37
 
38
+        self.ledTime = time.time()
39
+        self.led = Pin("LED", Pin.OUT)
40
+
34
         self.loop_start() # initialize with blank image for ScrollText constructor
41
         self.loop_start() # initialize with blank image for ScrollText constructor
35
 
42
 
36
     def loop_start(self):
43
     def loop_start(self):
47
         while True:
54
         while True:
48
             if self.loop_start():
55
             if self.loop_start():
49
                 break
56
                 break
57
+
50
             if func != None:
58
             if func != None:
51
                 func()
59
                 func()
60
+
52
             self.loop_end()
61
             self.loop_end()
62
+
63
+            now = time.time()
64
+            if ((now - self.ledTime) >= 0.5) or (now < self.ledTime):
65
+                self.ledTime = now
66
+                self.led.toggle()
67
+
53
         self.matrix.stop()
68
         self.matrix.stop()
54
 
69
 
55
     def set_pixel(self, x, y, color):
70
     def set_pixel(self, x, y, color):
72
         if not earlyAbort:
87
         if not earlyAbort:
73
             return self.gui.matrix.display.measure_text(s, scale=1)
88
             return self.gui.matrix.display.measure_text(s, scale=1)
74
 
89
 
75
-        pen = self.gui.matrix.display.create_pen(self.fg[0], self.fg[1], self.fg[2])
90
+        color = self.fg
91
+        if isinstance(self.gui, MapperReduceBrightness):
92
+            color = self.gui.adjust(color)
93
+
94
+        pen = self.gui.matrix.display.create_pen(color[0], color[1], color[2])
76
         self.gui.matrix.display.set_pen(pen)
95
         self.gui.matrix.display.set_pen(pen)
77
 
96
 
78
         self.gui.matrix.display.set_font(f)
97
         self.gui.matrix.display.set_font(f)
107
     def helper():
126
     def helper():
108
         global s, start, i
127
         global s, start, i
109
 
128
 
110
-        if (time.time() - start) > 2.0:
111
-            start = time.time()
129
+        now = time.time()
130
+        if ((now - start) > 2.0) or (now < start):
131
+            start = now
112
             i = (i + 1) % 2
132
             i = (i + 1) % 2
113
 
133
 
114
         if i == 0:
134
         if i == 0:

+ 6
- 2
qr.py View File

91
                     self.gui.set_pixel(x + self.xOff + self.image.width, y + self.yOff, self.c2)
91
                     self.gui.set_pixel(x + self.xOff + self.image.width, y + self.yOff, self.c2)
92
 
92
 
93
         if self.heading != None:
93
         if self.heading != None:
94
-            self.text.text(self.heading, self.font, 0, True, -10)
94
+            off = -10
95
+            if self.font == "bitmap6":
96
+                off -= 3
97
+
98
+            self.text.text(self.heading, self.font, 0, True, off)
95
 
99
 
96
         for x in range(0, self.image.width):
100
         for x in range(0, self.image.width):
97
             for y in range(0, self.image.height):
101
             for y in range(0, self.image.height):
106
 
110
 
107
     t = util.getTarget()
111
     t = util.getTarget()
108
 
112
 
109
-    d = QRScreen(t, "Hello World", 10.0, "Drinks:", "tom-thumb", (255, 255, 255), (0, 0, 0))
113
+    d = QRScreen(t, "http://ubabot.frubar.net", 10.0, "Drinks:", "tom-thumb", (255, 255, 255), (0, 0, 0))
110
 
114
 
111
     # dump generated QR image to console, for embedding in Pico script
115
     # dump generated QR image to console, for embedding in Pico script
112
     print("Dumping QR image to qr_tmp.txt")
116
     print("Dumping QR image to qr_tmp.txt")

+ 4
- 5
scroll.py View File

33
         self.text = t
33
         self.text = t
34
         self.font = f
34
         self.font = f
35
         self.width = self.drawer.text(self.text, self.font, 0, False)
35
         self.width = self.drawer.text(self.text, self.font, 0, False)
36
-        print(self.text, self.font, self.width)
37
 
36
 
38
     def restart(self):
37
     def restart(self):
39
         self.offset = -self.gui.width
38
         self.offset = -self.gui.width
44
         return (self.count >= self.iterations)
43
         return (self.count >= self.iterations)
45
 
44
 
46
     def draw(self):
45
     def draw(self):
47
-        if (time.time() - self.last) > self.speed:
48
-            off = (time.time() - self.last) / self.speed
49
-            print(self.offset, "->", self.offset + int(off))
46
+        now = time.time()
47
+        if (now - self.last) > self.speed:
48
+            off = (now - self.last) / self.speed
50
             self.offset += int(off)
49
             self.offset += int(off)
51
-            self.last = time.time()
50
+            self.last = now
52
             if self.offset >= self.width:
51
             if self.offset >= self.width:
53
                 self.offset = -self.gui.width
52
                 self.offset = -self.gui.width
54
                 self.count += 1
53
                 self.count += 1

+ 3
- 2
snake.py View File

136
             # TODO "AI"
136
             # TODO "AI"
137
             pass
137
             pass
138
 
138
 
139
-        if (time.time() - self.last) >= self.timestep:
140
-            self.last = time.time()
139
+        now = time.time()
140
+        if (now - self.last) >= self.timestep:
141
+            self.last = now
141
 
142
 
142
             # only allow valid inputs
143
             # only allow valid inputs
143
             tmp = self.direction + self.directionTmp
144
             tmp = self.direction + self.directionTmp

+ 5
- 3
solid.py View File

23
         self.start = time.time()
23
         self.start = time.time()
24
 
24
 
25
     def finished(self):
25
     def finished(self):
26
-        return (time.time() - self.start) >= self.time
26
+        now = time.time()
27
+        return ((now - self.start) >= self.time) or (now < self.start)
27
 
28
 
28
     def draw(self):
29
     def draw(self):
29
         for x in range(0, self.gui.width):
30
         for x in range(0, self.gui.width):
55
     def helper():
56
     def helper():
56
         global s, colors, ci, n, c
57
         global s, colors, ci, n, c
57
 
58
 
58
-        if (time.time() - s) >= 0.1:
59
-            s = time.time()
59
+        now = time.time()
60
+        if ((now - s) >= 0.1) or (now < s):
61
+            s = now
60
             n += 1
62
             n += 1
61
             if n >= 15:
63
             if n >= 15:
62
                 ci = (ci + 1) % len(colors)
64
                 ci = (ci + 1) % len(colors)

+ 3
- 2
tetris.py View File

243
             # TODO "AI"
243
             # TODO "AI"
244
             self.button = None
244
             self.button = None
245
 
245
 
246
-        if (self.button != None) or ((time.time() - self.last) >= self.timestep):
247
-            self.last = time.time()
246
+        now = time.time()
247
+        if (self.button != None) or ((now - self.last) >= self.timestep) or (now < self.last):
248
+            self.last = now
248
             cont = self.step()
249
             cont = self.step()
249
             if cont == False:
250
             if cont == False:
250
                 self.done = True
251
                 self.done = True

+ 54
- 9
util.py View File

7
 # think this stuff is worth it, you can buy me a beer in return.   Thomas Buck
7
 # think this stuff is worth it, you can buy me a beer in return.   Thomas Buck
8
 # ----------------------------------------------------------------------------
8
 # ----------------------------------------------------------------------------
9
 
9
 
10
+import sys
11
+
10
 targetPlatform = None
12
 targetPlatform = None
13
+wifiConnected = False
11
 
14
 
12
 def isPi():
15
 def isPi():
13
     global targetPlatform
16
     global targetPlatform
43
             # only print once
46
             # only print once
44
             print("Raspberry Pi Adafruit RGB LED Matrix detected")
47
             print("Raspberry Pi Adafruit RGB LED Matrix detected")
45
         targetPlatform = "pi"
48
         targetPlatform = "pi"
46
-    except:
49
+    except Exception as e:
50
+        print()
51
+        sys.print_exception(e)
52
+        print()
53
+
47
         try:
54
         try:
48
             # Next we try the Pico Interstate75 interface
55
             # Next we try the Pico Interstate75 interface
49
             from pico import PicoMatrix
56
             from pico import PicoMatrix
50
-            target = PicoMatrix()
57
+            pico = PicoMatrix()
58
+
59
+            # TODO hard-coded adjustments
60
+            from mapper import MapperReduceBrightness
61
+            target = MapperReduceBrightness(pico)
51
 
62
 
52
             if targetPlatform == None:
63
             if targetPlatform == None:
53
                 # only print once
64
                 # only print once
54
                 print("Raspberry Pi Pico Interstate75 RGB LED Matrix detected")
65
                 print("Raspberry Pi Pico Interstate75 RGB LED Matrix detected")
55
             targetPlatform = "pico"
66
             targetPlatform = "pico"
56
-        except:
67
+        except Exception as e:
68
+            print()
69
+            sys.print_exception(e)
70
+            print()
71
+
57
             # If this fails fall back to the SDL/pygame GUI
72
             # If this fails fall back to the SDL/pygame GUI
58
             from test import TestGUI
73
             from test import TestGUI
59
             target = TestGUI()
74
             target = TestGUI()
67
 
82
 
68
 # https://github.com/raspberrypi/pico-examples/blob/master/pico_w/wifi/python_test_tcp/micropython_test_tcp_client.py
83
 # https://github.com/raspberrypi/pico-examples/blob/master/pico_w/wifi/python_test_tcp/micropython_test_tcp_client.py
69
 def connectToWiFi():
84
 def connectToWiFi():
85
+    global wifiConnected
86
+
87
+    if wifiConnected:
88
+        return True
89
+
90
+    # only use WiFi on Pico
91
+    try:
92
+        from pico import PicoMatrix
93
+    except Exception as e:
94
+        print()
95
+        sys.print_exception(e)
96
+        print()
97
+        wifiConnected = True
98
+        return True
99
+
70
     import network
100
     import network
71
     import time
101
     import time
72
     from config import Config
102
     from config import Config
74
     # Check if wifi details have been set
104
     # Check if wifi details have been set
75
     if len(Config.networks) == 0:
105
     if len(Config.networks) == 0:
76
         print('Please set wifi ssid and password in config.py')
106
         print('Please set wifi ssid and password in config.py')
107
+        wifiConnected = False
77
         return False
108
         return False
78
 
109
 
79
     # Start WiFi hardware
110
     # Start WiFi hardware
92
                 break
123
                 break
93
     if (ssid == None) or (password == None):
124
     if (ssid == None) or (password == None):
94
         print("No known network found")
125
         print("No known network found")
126
+        wifiConnected = False
95
         return False
127
         return False
96
 
128
 
97
     # Start connection
129
     # Start connection
98
     wlan.connect(ssid, password)
130
     wlan.connect(ssid, password)
99
 
131
 
100
     # Wait for connect success or failure
132
     # Wait for connect success or failure
101
-    max_wait = 20
102
-    error_count = 20
133
+    max_wait = 40
134
+    error_count = max_wait
103
     while max_wait > 0:
135
     while max_wait > 0:
104
         if wlan.status() >= 3:
136
         if wlan.status() >= 3:
105
             break
137
             break
116
     # Handle connection error
148
     # Handle connection error
117
     if wlan.status() != 3:
149
     if wlan.status() != 3:
118
         print('wifi connection failed %d' % wlan.status())
150
         print('wifi connection failed %d' % wlan.status())
151
+        wifiConnected = False
119
         return False
152
         return False
120
     else:
153
     else:
121
         print('connected')
154
         print('connected')
122
         status = wlan.ifconfig()
155
         status = wlan.ifconfig()
123
         print('ip = ' + status[0])
156
         print('ip = ' + status[0])
124
 
157
 
158
+    wifiConnected = True
125
     return True
159
     return True
126
 
160
 
127
 def getRequests():
161
 def getRequests():
162
+    global wifiConnected
163
+
128
     try:
164
     try:
129
         # try to get normal python lib
165
         # try to get normal python lib
130
         import requests
166
         import requests
131
         return requests.get
167
         return requests.get
132
-    except:
168
+    except Exception as e:
169
+        print()
170
+        sys.print_exception(e)
171
+        print()
172
+
133
         # if it fails try the Pi Pico MicroPython implementation
173
         # if it fails try the Pi Pico MicroPython implementation
134
         import urequests as requests
174
         import urequests as requests
135
 
175
 
136
         # in this case we also need to connect to WiFi first
176
         # in this case we also need to connect to WiFi first
137
-        if not connectToWiFi():
138
-            return None
177
+        if not wifiConnected:
178
+            if not connectToWiFi():
179
+                return None
139
 
180
 
140
         return requests.get
181
         return requests.get
141
 
182
 
146
         # Try BDF parser library
187
         # Try BDF parser library
147
         from bdf import DrawText
188
         from bdf import DrawText
148
         return DrawText
189
         return DrawText
149
-    except:
190
+    except Exception as e:
191
+        print()
192
+        sys.print_exception(e)
193
+        print()
194
+
150
         # fall back to the Pico Interstate75 implementation
195
         # fall back to the Pico Interstate75 implementation
151
         from pico import PicoText
196
         from pico import PicoText
152
         return PicoText
197
         return PicoText

Loading…
Cancel
Save