Browse Source

various on-camp adjustments

Thomas Buck 1 year ago
parent
commit
62258f23f3
6 changed files with 87 additions and 9 deletions
  1. 2
    0
      copy.sh
  2. 3
    0
      games.py
  3. 1
    1
      net.py
  4. 55
    1
      pico_ota.py
  5. 1
    1
      snake.py
  6. 25
    6
      util.py

+ 2
- 0
copy.sh View File

15
 cp qr.py /pyboard
15
 cp qr.py /pyboard
16
 cp camp_pico.py /pyboard
16
 cp camp_pico.py /pyboard
17
 cp scroll.py /pyboard
17
 cp scroll.py /pyboard
18
+cp telegram.py /pyboard
18
 cp qr_tmp.py /pyboard
19
 cp qr_tmp.py /pyboard
19
 cp img_tmp.py /pyboard
20
 cp img_tmp.py /pyboard
20
 cp $1 /pyboard/main.py
21
 cp $1 /pyboard/main.py
35
 cp qr.py /pyboard
36
 cp qr.py /pyboard
36
 cp camp_pico.py /pyboard
37
 cp camp_pico.py /pyboard
37
 cp scroll.py /pyboard
38
 cp scroll.py /pyboard
39
+cp telegram.py /pyboard
38
 cp qr_tmp.py /pyboard
40
 cp qr_tmp.py /pyboard
39
 cp img_tmp.py /pyboard
41
 cp img_tmp.py /pyboard
40
 EOF
42
 EOF

+ 3
- 0
games.py View File

21
 from gamepad import InputWrapper
21
 from gamepad import InputWrapper
22
 from manager import Manager
22
 from manager import Manager
23
 from tetris import Tetris
23
 from tetris import Tetris
24
+from breakout import Breakout
24
 import util
25
 import util
25
 
26
 
26
 url_uba = "http://ubabot.frubar.net"
27
 url_uba = "http://ubabot.frubar.net"
41
 
42
 
42
 # Main "Menu"
43
 # Main "Menu"
43
 m = Manager(t, i)
44
 m = Manager(t, i)
45
+m.add(Breakout(t, i))
46
+m.add(Solid(t, 1.0))
44
 m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), None, 2.0))
47
 m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), None, 2.0))
45
 m.add(Solid(t, 1.0))
48
 m.add(Solid(t, 1.0))
46
 m.add(Tetris(t, i,))
49
 m.add(Tetris(t, i,))

+ 1
- 1
net.py View File

18
         self.successScreen = None
18
         self.successScreen = None
19
         self.failScreen = None
19
         self.failScreen = None
20
         self.response = None
20
         self.response = None
21
-        self.get = util.getRequests()
21
+        self.get, post = util.getRequests()
22
 
22
 
23
         self.restart()
23
         self.restart()
24
 
24
 

+ 55
- 1
pico_ota.py View File

49
         self.gui = g
49
         self.gui = g
50
         self.text = t
50
         self.text = t
51
 
51
 
52
+
53
+        if (self.gui == None) or (self.text == None):
54
+            return
55
+
56
+        for i in range(0, 5):
57
+            self.gui.loop_start()
58
+
59
+            self.text.fg = (255, 255, 0)
60
+            self.text.setText("WiFi", "bitmap6")
61
+            self.text.draw(0, 6 * 0, False)
62
+
63
+            self.text.fg = (255, 0, 255)
64
+            self.text.setText("???", "bitmap6")
65
+            self.text.draw(0, 6 * 1, False)
66
+
67
+            self.text.fg = (255, 0, 0)
68
+            self.text.setText(str(i + 1) + " / 5", "bitmap6")
69
+            self.text.draw(0, 6 * 2, False)
70
+
71
+            self.text.fg = (0, 255, 0)
72
+            self.text.setText("", "bitmap6")
73
+            self.text.draw(0, 6 * 3, False)
74
+
75
+            self.text.setText("Conn...", "bitmap6")
76
+            self.text.draw(0, 6 * 4, False)
77
+
78
+            self.gui.loop_end()
79
+
80
+            util.connectToWiFi()
81
+
82
+            self.gui.loop_start()
83
+
84
+            self.text.fg = (255, 255, 0)
85
+            self.text.setText("WiFi", "bitmap6")
86
+            self.text.draw(0, 6 * 0, False)
87
+
88
+            self.text.fg = (255, 0, 255)
89
+            self.text.setText("$NAME", "bitmap6")
90
+            self.text.draw(0, 6 * 1, False)
91
+
92
+            self.text.fg = (255, 0, 0)
93
+            self.text.setText(str(i + 1) + " / 5", "bitmap6")
94
+            self.text.draw(0, 6 * 2, False)
95
+
96
+            self.text.fg = (0, 255, 0)
97
+            self.text.setText("Status:", "bitmap6")
98
+            self.text.draw(0, 6 * 3, False)
99
+
100
+            self.text.setText("$val", "bitmap6")
101
+            self.text.draw(0, 6 * 4, False)
102
+
103
+            self.gui.loop_end()
104
+
52
     def path(self, p):
105
     def path(self, p):
53
         self.update_path = p
106
         self.update_path = p
54
 
107
 
62
     def fetch(self, url):
115
     def fetch(self, url):
63
         # lazily initialize WiFi
116
         # lazily initialize WiFi
64
         if self.get == None:
117
         if self.get == None:
65
-            self.get = util.getRequests()
118
+            self.get, post = util.getRequests()
66
             if self.get == None:
119
             if self.get == None:
67
                 return None
120
                 return None
68
 
121
 
84
             return r
137
             return r
85
         except Exception as e:
138
         except Exception as e:
86
             print()
139
             print()
140
+            print(url)
87
             if hasattr(sys, "print_exception"):
141
             if hasattr(sys, "print_exception"):
88
                 sys.print_exception(e)
142
                 sys.print_exception(e)
89
             else:
143
             else:

+ 1
- 1
snake.py View File

78
 
78
 
79
     def placeDot(self):
79
     def placeDot(self):
80
         d = (random.randrange(0, self.gui.width), random.randrange(0, self.gui.height))
80
         d = (random.randrange(0, self.gui.width), random.randrange(0, self.gui.height))
81
-        while self.data[d[0]][d[1]] != 0: # TODO don't place dots below score text
81
+        while (self.data[d[0]][d[1]] != 0) or (d[0] < 15) or (d[1] < 8):
82
             d = (random.randrange(0, self.gui.width), random.randrange(0, self.gui.height))
82
             d = (random.randrange(0, self.gui.width), random.randrange(0, self.gui.height))
83
         self.data[d[0]][d[1]] = 2
83
         self.data[d[0]][d[1]] = 2
84
 
84
 

+ 25
- 6
util.py View File

136
     # Look for known networks
136
     # Look for known networks
137
     visible = wlan.scan()
137
     visible = wlan.scan()
138
     ssid = None
138
     ssid = None
139
+    user = None
139
     password = None
140
     password = None
141
+
142
+    print(visible)
143
+    if len(visible) == 0:
144
+        print("No networks visible at all")
145
+        wifiConnected = False
146
+        return False
147
+
140
     for name, a, b, c, d, e in visible:
148
     for name, a, b, c, d, e in visible:
141
-        for t_ssid, t_password in Config.networks:
149
+        for net in Config.networks:
150
+            if len(net) == 2:
151
+                t_ssid, t_password = net
152
+            elif len(net) == 3:
153
+                t_ssid, t_user, t_password = net
154
+
142
             if name.decode("utf-8") == t_ssid:
155
             if name.decode("utf-8") == t_ssid:
143
                 ssid = t_ssid
156
                 ssid = t_ssid
157
+                if len(net) == 3:
158
+                    user = t_user
144
                 password = t_password
159
                 password = t_password
145
                 break
160
                 break
146
     if (ssid == None) or (password == None):
161
     if (ssid == None) or (password == None):
149
         return False
164
         return False
150
 
165
 
151
     # Start connection
166
     # Start connection
152
-    wlan.connect(ssid, password)
167
+    if user != None:
168
+        wlan.seteap(user, password)
169
+        wlan.connect(ssid)
170
+    else:
171
+        wlan.connect(ssid, password)
153
 
172
 
154
     # Wait for connect success or failure
173
     # Wait for connect success or failure
155
     max_wait = 40
174
     max_wait = 40
186
     try:
205
     try:
187
         # try to get normal python lib
206
         # try to get normal python lib
188
         import requests
207
         import requests
189
-        return requests.get
208
+        return requests.get, requests.post
190
     except Exception as e:
209
     except Exception as e:
191
         print()
210
         print()
192
         if hasattr(sys, "print_exception"):
211
         if hasattr(sys, "print_exception"):
201
         # in this case we also need to connect to WiFi first
220
         # in this case we also need to connect to WiFi first
202
         if not wifiConnected:
221
         if not wifiConnected:
203
             if not connectToWiFi():
222
             if not connectToWiFi():
204
-                return None
223
+                return None, None
205
 
224
 
206
-        return requests.get
225
+        return requests.get, requests.post
207
 
226
 
208
-    return None
227
+    return None, None
209
 
228
 
210
 def getTextDrawer():
229
 def getTextDrawer():
211
     try:
230
     try:

Loading…
Cancel
Save