Quellcode durchsuchen

pico interstate75 support

Thomas Buck vor 11 Monaten
Ursprung
Commit
d2c9fab4c5
7 geänderte Dateien mit 166 neuen und 32 gelöschten Zeilen
  1. 15
    0
      copy.sh
  2. 6
    0
      draw.py
  3. 34
    8
      mapper.py
  4. 1
    1
      pi.py
  5. 58
    0
      pico.py
  6. 15
    7
      solid.py
  7. 37
    16
      util.py

+ 15
- 0
copy.sh Datei anzeigen

@@ -0,0 +1,15 @@
1
+#!/bin/bash
2
+
3
+if [ $# -ne 0 ] ; then
4
+cat << EOF | rshell
5
+cp pico.py /pyboard
6
+cp util.py /pyboard
7
+cp $1 /pyboard/main.py
8
+EOF
9
+else
10
+cat << EOF | rshell
11
+cp pico.py /pyboard
12
+cp util.py /pyboard
13
+cp life.py /pyboard
14
+EOF
15
+fi

+ 6
- 0
draw.py Datei anzeigen

@@ -54,6 +54,12 @@ class DrawText:
54 54
                 offset = 12
55 55
                 spacing = 2
56 56
 
57
+            # center vertically, in case of
58
+            # multiple stacked panels
59
+            # TODO hard-coded offsets assume 32x32 panels
60
+            if self.gui.height > 32:
61
+                offset += 16
62
+
57 63
             font = Font(os.path.join(fontDir, filename))
58 64
             data = (font, offset, {}, spacing)
59 65
             self.fonts[filename[:-4]] = data

+ 34
- 8
mapper.py Datei anzeigen

@@ -7,7 +7,7 @@
7 7
 # think this stuff is worth it, you can buy me a beer in return.   Thomas Buck
8 8
 # ----------------------------------------------------------------------------
9 9
 
10
-# Does nothing. Take this as an example for new Mappers.
10
+# Does nothing. Take this as parent for new mappers.
11 11
 class MapperNull:
12 12
     def __init__(self, g):
13 13
         self.gui = g
@@ -29,17 +29,43 @@ class MapperNull:
29 29
     def set_pixel(self, x, y, color):
30 30
         self.gui.set_pixel(x, y, color)
31 31
 
32
-# For some reason the red and green LEDs on newer Pimoroni panels
33
-# are far brighter than on older panels.
32
+# For some reason the red and green LEDs on older Pimoroni panels
33
+# are far brighter than on newer panels.
34 34
 # Adjust this by multiplying rg channels with 0.75, depending
35 35
 # on hard-corded coordinate ranges.
36 36
 class MapperColorAdjust(MapperNull):
37 37
     def set_pixel(self, x, y, color):
38
-        # right-most panel, with maximum x coordinates,
39
-        # is "new" type with brighter LEDs.
40
-        # rest of panels to the left are less bright.
41
-        # so adjust brightness of right panel rg channels down.
42
-        if x < self.gui.panelW:
38
+        # third panel from the left, with 64 <= x < 96,
39
+        # is "old" type with brighter LEDs.
40
+        # rest of panels to the left and right are less bright.
41
+        # so adjust brightness of inner panel rg channels down.
42
+        if (x >= (self.gui.panelW * 2)) and (x < (self.gui.panelW * 3)):
43 43
             color = (int(color[0] * 0.75), int(color[1] * 0.75), color[2])
44 44
 
45 45
         self.gui.set_pixel(x, y, color)
46
+
47
+# This converts a long 128x32 strip to a 64x64 panel.
48
+# The Pi is always connected to d, the last subpanel.
49
+#
50
+#     (0,  0)            (128, 0)
51
+#             a  b  c  d
52
+#     (0, 32)            (128, 32)
53
+#
54
+# on the hardware is converted to this for the effects:
55
+#
56
+#     (0,  0)      (64, 0)
57
+#             a  b
58
+#             c  d
59
+#     (0, 64)      (64, 64)
60
+class MapperStripToRect(MapperNull):
61
+    def __init__(self, g):
62
+        super().__init__(g)
63
+        self.width = int(self.gui.width / 2)
64
+        self.height = self.gui.height * 2
65
+
66
+    def set_pixel(self, x, y, color):
67
+        if y >= self.gui.height:
68
+            x += self.width
69
+            y -= self.panelH
70
+
71
+        self.gui.set_pixel(x, y, color)

+ 1
- 1
pi.py Datei anzeigen

@@ -32,7 +32,7 @@ from rgbmatrix import RGBMatrix, RGBMatrixOptions
32 32
 from PIL import Image
33 33
 
34 34
 class PiMatrix:
35
-    def __init__(self, w = 64, h = 32, panelW = 32, panelH = 32):
35
+    def __init__(self, w = 32 * 4, h = 32, panelW = 32, panelH = 32):
36 36
         self.width = w # x-axis
37 37
         self.height = h # y-axis
38 38
 

+ 58
- 0
pico.py Datei anzeigen

@@ -0,0 +1,58 @@
1
+#!/usr/bin/env python3
2
+
3
+#
4
+# ----------------------------------------------------------------------------
5
+# "THE BEER-WARE LICENSE" (Revision 42):
6
+# <xythobuz@xythobuz.de> wrote this file.  As long as you retain this notice
7
+# you can do whatever you want with this stuff. If we meet some day, and you
8
+# think this stuff is worth it, you can buy me a beer in return.   Thomas Buck
9
+# ----------------------------------------------------------------------------
10
+
11
+import interstate75
12
+
13
+
14
+class PicoMatrix:
15
+    def __init__(self, w = 32, h = 32):
16
+        self.width = w # x-axis
17
+        self.height = h # y-axis
18
+
19
+        self.panelW = w # x-axis
20
+        self.panelH = h # y-axis
21
+
22
+        # compatibility to TestGUI
23
+        self.multiplier = 1.0
24
+
25
+        if (w != 32) or (h != 32):
26
+            raise RuntimeError("TODO not yet supported")
27
+
28
+        self.matrix = interstate75.Interstate75(display = interstate75.DISPLAY_INTERSTATE75_32X32)
29
+
30
+        self.loop_start() # initialize with blank image for ScrollText constructor
31
+
32
+    def loop_start(self):
33
+        self.matrix.display.clear()
34
+        return False # no input, never quit on our own
35
+
36
+    def loop_end(self):
37
+        self.matrix.update()
38
+
39
+    def loop(self, func = None):
40
+        while True:
41
+            if self.loop_start():
42
+                break
43
+            if func != None:
44
+                func()
45
+            self.loop_end()
46
+        self.matrix.stop()
47
+
48
+    def set_pixel(self, x, y, color):
49
+        if (x < 0) or (y < 0) or (x >= self.width) or (y >= self.height):
50
+            return
51
+
52
+        pen = self.matrix.display.create_pen(color[0], color[1], color[2])
53
+        self.matrix.display.set_pen(pen)
54
+        self.matrix.display.pixel(int(x), int(y))
55
+
56
+if __name__ == "__main__":
57
+    t = PicoMatrix(32, 32)
58
+    t.loop(lambda: t.set_pixel(15, 15, (255, 255, 255)))

+ 15
- 7
solid.py Datei anzeigen

@@ -34,6 +34,8 @@ if __name__ == "__main__":
34 34
     import util
35 35
     t = util.getTarget()
36 36
 
37
+    d = Solid(t, 1.0, (0, 0, 0))
38
+
37 39
     colors = [
38 40
         (251, 72, 196), # camp23 pink
39 41
         (63, 255, 33), # camp23 green
@@ -45,18 +47,24 @@ if __name__ == "__main__":
45 47
         (255, 0, 255),
46 48
         (255, 255, 255),
47 49
     ]
48
-    ci = 0
49
-
50
-    d = Solid(t, 1.0, colors[ci])
51 50
 
52 51
     s = time.time()
52
+    ci = 0
53
+    n = 0
54
+    c = (0, 0, 0)
53 55
     def helper():
54
-        global s, colors, ci
56
+        global s, colors, ci, n, c
55 57
 
56
-        if (time.time() - s) >= 1.0:
58
+        if (time.time() - s) >= 0.1:
57 59
             s = time.time()
58
-            ci = (ci + 1) % len(colors)
59
-            c = colors[ci]
60
+            n += 1
61
+            if n >= 15:
62
+                ci = (ci + 1) % len(colors)
63
+                n = 0
64
+                c = (0, 0, 0)
65
+            elif n <= 10:
66
+                c = colors[ci]
67
+                c = (int(c[0] * (0.1 * n)), int(c[1] * (0.1 * n)), int(c[2] * (0.1 * n)))
60 68
             d.setColor(c)
61 69
 
62 70
         d.draw()

+ 37
- 16
util.py Datei anzeigen

@@ -7,39 +7,60 @@
7 7
 # think this stuff is worth it, you can buy me a beer in return.   Thomas Buck
8 8
 # ----------------------------------------------------------------------------
9 9
 
10
-targetIsPi = None
10
+targetPlatform = None
11 11
 
12 12
 def isPi():
13
-    global targetIsPi
13
+    global targetPlatform
14 14
 
15
-    if targetIsPi == None:
15
+    if targetPlatform == None:
16 16
         getTarget()
17
-    return targetIsPi
17
+
18
+    return targetPlatform == "pi"
19
+
20
+def isPico():
21
+    global targetPlatform
22
+
23
+    if targetPlatform == None:
24
+        getTarget()
25
+
26
+    return targetPlatform == "pico"
18 27
 
19 28
 def getTarget():
20
-    global targetIsPi
29
+    global targetPlatform
21 30
 
22 31
     target = None
23 32
     try:
33
+        # First we try the Raspberry Pi interface
24 34
         from pi import PiMatrix
25 35
         pi = PiMatrix()
26 36
 
27 37
         # TODO hard-coded adjustments
28
-        from mapper import MapperColorAdjust
29
-        target = MapperColorAdjust(pi)
38
+        from mapper import MapperColorAdjust, MapperStripToRect
39
+        col = MapperColorAdjust(pi)
40
+        target = MapperStripToRect(col)
30 41
 
31
-        if targetIsPi == None:
42
+        if targetPlatform == None:
32 43
             # only print once
33 44
             print("Raspberry Pi Adafruit RGB LED Matrix detected")
45
+        targetPlatform = "pi"
46
+    except:
47
+        try:
48
+            # Next we try the Pico Interstate75 interface
49
+            from pico import PicoMatrix
50
+            target = PicoMatrix()
34 51
 
35
-        targetIsPi = True
36
-    except ModuleNotFoundError:
37
-        from test import TestGUI
38
-        target = TestGUI()
52
+            if targetPlatform == None:
53
+                # only print once
54
+                print("Raspberry Pi Pico Interstate75 RGB LED Matrix detected")
55
+            targetPlatform = "pico"
56
+        except:
57
+            # If this fails fall back to the SDL/pygame GUI
58
+            from test import TestGUI
59
+            target = TestGUI()
39 60
 
40
-        if targetIsPi == None:
41
-            # only print once
42
-            print("Falling back to GUI debug interface")
61
+            if targetPlatform == None:
62
+                # only print once
63
+                print("Falling back to GUI debug interface")
64
+            targetPlatform = "tk"
43 65
 
44
-        targetIsPi = False
45 66
     return target

Laden…
Abbrechen
Speichern