Explorar el Código

Add PicoInput to get buttons on Interstate75 W.

Thomas Buck hace 10 meses
padre
commit
4d2eb03483
Se han modificado 7 ficheros con 68 adiciones y 24 borrados
  1. 3
    2
      camp_pico.py
  2. 1
    2
      camp_small.py
  3. 12
    11
      manager.py
  4. 29
    1
      pico.py
  5. 2
    4
      snake.py
  6. 1
    3
      tetris.py
  7. 20
    1
      util.py

+ 3
- 2
camp_pico.py Ver fichero

27
 url = "http://www.xythobuz.de"
27
 url = "http://www.xythobuz.de"
28
 
28
 
29
 import util
29
 import util
30
-t = util.getTarget()
30
+i = util.getInput()
31
+t = util.getTarget(i)
31
 
32
 
32
 # Loading fonts and graphics takes a while.
33
 # Loading fonts and graphics takes a while.
33
 # So show a splash screen while the user waits.
34
 # So show a splash screen while the user waits.
60
 d.fail(fail)
61
 d.fail(fail)
61
 
62
 
62
 # Main "Menu"
63
 # Main "Menu"
63
-m = Manager(t)
64
+m = Manager(t, i)
64
 m.add(QRScreen(t, img_data, 15.0))
65
 m.add(QRScreen(t, img_data, 15.0))
65
 m.add(Solid(t, 1.0))
66
 m.add(Solid(t, 1.0))
66
 m.add(d) # HTTP Check, either "success" or "fail"
67
 m.add(d) # HTTP Check, either "success" or "fail"

+ 1
- 2
camp_small.py Ver fichero

28
 scroll_speed = 15
28
 scroll_speed = 15
29
 
29
 
30
 # Need to import InputWrapper before initializing RGB Matrix on Pi
30
 # Need to import InputWrapper before initializing RGB Matrix on Pi
31
-i = InputWrapper()
32
-
31
+i = util.getInput()
33
 t = util.getTarget(i)
32
 t = util.getTarget(i)
34
 
33
 
35
 # Loading fonts and graphics takes a while.
34
 # Loading fonts and graphics takes a while.

+ 12
- 11
manager.py Ver fichero

109
     from life import GameOfLife
109
     from life import GameOfLife
110
 
110
 
111
     import util
111
     import util
112
-    t = util.getTarget()
112
+    i = util.getInput()
113
+    t = util.getTarget(i)
113
 
114
 
114
     splash = SplashScreen(t)
115
     splash = SplashScreen(t)
115
     t.loop_start()
116
     t.loop_start()
116
     splash.draw()
117
     splash.draw()
117
     t.loop_end()
118
     t.loop_end()
118
 
119
 
119
-    m = Manager(t)
120
-
121
-    m.add(ScrollText(t, "This appears once", "ib8x8u"))
122
-    m.add(Solid(t, 1.0))
123
-
124
-    m.add(ScrollText(t, "And this twice...", "ib8x8u", 2))
125
-    m.add(Solid(t, 1.0))
126
-
127
-    m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), 20.0, True))
128
-    m.add(Solid(t, 1.0))
120
+    m = Manager(t, i)
129
 
121
 
130
     sub = Manager(t)
122
     sub = Manager(t)
131
     sub.add(ScrollText(t, "Hello", "ib8x8u"))
123
     sub.add(ScrollText(t, "Hello", "ib8x8u"))
135
     m.add(sub)
127
     m.add(sub)
136
     m.add(Solid(t, 1.0))
128
     m.add(Solid(t, 1.0))
137
 
129
 
130
+    m.add(ScrollText(t, "This appears once", "ib8x8u"))
131
+    m.add(Solid(t, 1.0))
132
+
133
+    m.add(ScrollText(t, "And this twice...", "ib8x8u", 2))
134
+    m.add(Solid(t, 1.0))
135
+
136
+    m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), 5.0, True))
137
+    m.add(Solid(t, 1.0))
138
+
138
     m.restart()
139
     m.restart()
139
     util.loop(t, m.draw)
140
     util.loop(t, m.draw)

+ 29
- 1
pico.py Ver fichero

47
     return r, g, b
47
     return r, g, b
48
 
48
 
49
 class PicoMatrix:
49
 class PicoMatrix:
50
-    def __init__(self, w = 32, h = 32):
50
+    def __init__(self, input = None, w = 32, h = 32):
51
         self.width = w # x-axis
51
         self.width = w # x-axis
52
         self.height = h # y-axis
52
         self.height = h # y-axis
53
 
53
 
60
         if (w != 32) or (h != 32):
60
         if (w != 32) or (h != 32):
61
             raise RuntimeError("TODO not yet supported")
61
             raise RuntimeError("TODO not yet supported")
62
 
62
 
63
+        self.input = input
64
+        if self.input != None:
65
+            self.input.gui = self
66
+
63
         mode = interstate75.DISPLAY_INTERSTATE75_32X32
67
         mode = interstate75.DISPLAY_INTERSTATE75_32X32
64
         self.matrix = interstate75.Interstate75(display = mode, panel_type = hub75.PANEL_FM6126A)
68
         self.matrix = interstate75.Interstate75(display = mode, panel_type = hub75.PANEL_FM6126A)
65
 
69
 
284
         else:
288
         else:
285
             self.drawText(refresh)
289
             self.drawText(refresh)
286
 
290
 
291
+class PicoInput:
292
+    def __init__(self):
293
+        self.gui = None
294
+        self.keys = {
295
+            "left": False,
296
+            "right": False,
297
+            "up": False,
298
+            "down": False,
299
+            "a": False,
300
+            "b": False,
301
+            "x": False,
302
+            "y": False,
303
+            "l": False,
304
+            "r": False,
305
+            "start": False,
306
+            "select": False,
307
+        }
308
+
309
+    def get(self):
310
+        if self.gui != None:
311
+            self.keys["l"] = self.gui.matrix.switch_pressed(interstate75.SWITCH_A)
312
+            self.keys["r"] = self.gui.matrix.switch_pressed(interstate75.SWITCH_B)
313
+        return self.keys
314
+
287
 if __name__ == "__main__":
315
 if __name__ == "__main__":
288
     import time
316
     import time
289
     import util
317
     import util

+ 2
- 4
snake.py Ver fichero

178
                 self.gui.set_pixel(x, y, self.colors[self.data[x][y]])
178
                 self.gui.set_pixel(x, y, self.colors[self.data[x][y]])
179
 
179
 
180
 if __name__ == "__main__":
180
 if __name__ == "__main__":
181
-    # Need to import InputWrapper before initializing RGB Matrix on Pi
182
-    from gamepad import InputWrapper
183
-    i = InputWrapper()
184
-
185
     import util
181
     import util
182
+    # Need to import InputWrapper before initializing RGB Matrix on Pi
183
+    i = util.getInput()
186
     t = util.getTarget(i)
184
     t = util.getTarget(i)
187
 
185
 
188
     d = Snake(t, i)
186
     d = Snake(t, i)

+ 1
- 3
tetris.py Ver fichero

422
 
422
 
423
 if __name__ == "__main__":
423
 if __name__ == "__main__":
424
     # Need to import InputWrapper before initializing RGB Matrix on Pi
424
     # Need to import InputWrapper before initializing RGB Matrix on Pi
425
-    from gamepad import InputWrapper
426
-    i = InputWrapper()
427
-
425
+    i = util.getInput()
428
     t = util.getTarget(i)
426
     t = util.getTarget(i)
429
 
427
 
430
     # show splash screen while initializing
428
     # show splash screen while initializing

+ 20
- 1
util.py Ver fichero

65
         try:
65
         try:
66
             # Next we try the Pico Interstate75 interface
66
             # Next we try the Pico Interstate75 interface
67
             from pico import PicoMatrix
67
             from pico import PicoMatrix
68
-            pico = PicoMatrix()
68
+            pico = PicoMatrix(i)
69
 
69
 
70
             # TODO hard-coded adjustments
70
             # TODO hard-coded adjustments
71
             from mapper import MapperReduceBrightness
71
             from mapper import MapperReduceBrightness
225
 
225
 
226
     return None
226
     return None
227
 
227
 
228
+def getInput():
229
+    try:
230
+        # try evdev library
231
+        from gamepad import InputWrapper
232
+        return InputWrapper()
233
+    except Exception as e:
234
+        print()
235
+        if hasattr(sys, "print_exception"):
236
+            sys.print_exception(e)
237
+        else:
238
+            print(e)
239
+        print()
240
+
241
+        # fall back to the Pico Interstate75 implementation
242
+        from pico import PicoInput
243
+        return PicoInput()
244
+
245
+    return None
246
+
228
 def loop(gui, func = None):
247
 def loop(gui, func = None):
229
     while True:
248
     while True:
230
         if gui.loop_start():
249
         if gui.loop_start():

Loading…
Cancelar
Guardar