ソースを参照

various on-camp adjustments

Thomas Buck 1年前
コミット
62258f23f3
6個のファイルの変更87行の追加9行の削除
  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 ファイルの表示

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

+ 3
- 0
games.py ファイルの表示

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

+ 1
- 1
net.py ファイルの表示

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

+ 55
- 1
pico_ota.py ファイルの表示

@@ -49,6 +49,59 @@ class PicoOTA:
49 49
         self.gui = g
50 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 105
     def path(self, p):
53 106
         self.update_path = p
54 107
 
@@ -62,7 +115,7 @@ class PicoOTA:
62 115
     def fetch(self, url):
63 116
         # lazily initialize WiFi
64 117
         if self.get == None:
65
-            self.get = util.getRequests()
118
+            self.get, post = util.getRequests()
66 119
             if self.get == None:
67 120
                 return None
68 121
 
@@ -84,6 +137,7 @@ class PicoOTA:
84 137
             return r
85 138
         except Exception as e:
86 139
             print()
140
+            print(url)
87 141
             if hasattr(sys, "print_exception"):
88 142
                 sys.print_exception(e)
89 143
             else:

+ 1
- 1
snake.py ファイルの表示

@@ -78,7 +78,7 @@ class Snake:
78 78
 
79 79
     def placeDot(self):
80 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 82
             d = (random.randrange(0, self.gui.width), random.randrange(0, self.gui.height))
83 83
         self.data[d[0]][d[1]] = 2
84 84
 

+ 25
- 6
util.py ファイルの表示

@@ -136,11 +136,26 @@ def connectToWiFi():
136 136
     # Look for known networks
137 137
     visible = wlan.scan()
138 138
     ssid = None
139
+    user = None
139 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 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 155
             if name.decode("utf-8") == t_ssid:
143 156
                 ssid = t_ssid
157
+                if len(net) == 3:
158
+                    user = t_user
144 159
                 password = t_password
145 160
                 break
146 161
     if (ssid == None) or (password == None):
@@ -149,7 +164,11 @@ def connectToWiFi():
149 164
         return False
150 165
 
151 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 173
     # Wait for connect success or failure
155 174
     max_wait = 40
@@ -186,7 +205,7 @@ def getRequests():
186 205
     try:
187 206
         # try to get normal python lib
188 207
         import requests
189
-        return requests.get
208
+        return requests.get, requests.post
190 209
     except Exception as e:
191 210
         print()
192 211
         if hasattr(sys, "print_exception"):
@@ -201,11 +220,11 @@ def getRequests():
201 220
         # in this case we also need to connect to WiFi first
202 221
         if not wifiConnected:
203 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 229
 def getTextDrawer():
211 230
     try:

読み込み中…
キャンセル
保存