Thomas Buck преди 1 година
родител
ревизия
8088909682
променени са 4 файла, в които са добавени 94 реда и са изтрити 3 реда
  1. 10
    0
      README.md
  2. 7
    2
      camp_small.py
  3. 73
    0
      qr.py
  4. 4
    1
      util.py

+ 10
- 0
README.md Целия файл

@@ -10,6 +10,16 @@ Just run
10 10
 
11 11
 and go from there.
12 12
 
13
+## Dependencies
14
+
15
+You always need
16
+
17
+    pip install pil
18
+    pip install bdfparser
19
+    pip install "qrcode[pil]"
20
+
21
+The rest depends on the output device chosen.
22
+
13 23
 ## Licensing
14 24
 
15 25
 This project is licensed as beer-ware:

+ 7
- 2
camp_small.py Целия файл

@@ -14,8 +14,11 @@ if __name__ == "__main__":
14 14
     from life import GameOfLife
15 15
     from net import CheckHTTP
16 16
     from image import ImageScreen
17
+    from qr import QRScreen
17 18
     from manager import Manager
18 19
 
20
+    url = "http://ubabot.frubar.net"
21
+
19 22
     import util
20 23
     t = util.getTarget()
21 24
 
@@ -25,7 +28,9 @@ if __name__ == "__main__":
25 28
     t.loop_end()
26 29
 
27 30
     success = Manager(t)
28
-    success.add(ImageScreen(t, "drinka.gif", 0.2, 3, 20.0))
31
+    success.add(ImageScreen(t, "drinka.gif", 0.2, 2, 20.0))
32
+    success.add(Solid(t, 1.0))
33
+    success.add(QRScreen(t, url, 30.0))
29 34
     success.add(Solid(t, 1.0))
30 35
 
31 36
     fail = Manager(t)
@@ -35,7 +40,7 @@ if __name__ == "__main__":
35 40
     fail.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), None, 2.0))
36 41
     fail.add(Solid(t, 2.0))
37 42
 
38
-    d = CheckHTTP("http://ubabot.frubar.net")
43
+    d = CheckHTTP(url)
39 44
     d.success(success)
40 45
     d.fail(fail)
41 46
 

+ 73
- 0
qr.py Целия файл

@@ -0,0 +1,73 @@
1
+#!/usr/bin/env python3
2
+
3
+# ----------------------------------------------------------------------------
4
+# "THE BEER-WARE LICENSE" (Revision 42):
5
+# <xythobuz@xythobuz.de> wrote this file.  As long as you retain this notice
6
+# you can do whatever you want with this stuff. If we meet some day, and you
7
+# think this stuff is worth it, you can buy me a beer in return.   Thomas Buck
8
+# ----------------------------------------------------------------------------
9
+
10
+import time
11
+import qrcode
12
+import util
13
+
14
+class QRScreen:
15
+    def __init__(self, g, d, t = 10.0, c1 = (0, 0, 0), c2 = (255, 255, 255)):
16
+        self.gui = g
17
+        self.time = t
18
+        self.c1 = c1
19
+        self.c2 = c2
20
+
21
+        qr = qrcode.QRCode(
22
+            box_size = 1,
23
+            border = 0,
24
+        )
25
+        qr.add_data(d)
26
+        qr.make(fit = True)
27
+
28
+        if util.isPi():
29
+            # work-around for weird bug in old qrcode lib?
30
+            self.image = qr.make_image(fill_color = "black", back_color = "white")
31
+            self.c1 = (0, 0, 0)
32
+            self.c2 = (255, 255, 255)
33
+        else:
34
+            self.image = qr.make_image(fill_color = self.c1, back_color = self.c2)
35
+
36
+        self.xOff = int((self.gui.width - self.image.width) / 2)
37
+        self.yOff = int((self.gui.height - self.image.height) / 2)
38
+
39
+        self.restart()
40
+
41
+    def restart(self):
42
+        self.start = time.time()
43
+
44
+    def finished(self):
45
+        return (time.time() - self.start) >= self.time
46
+
47
+    def draw(self):
48
+        # fill border, if needed
49
+        if self.c2 != (0, 0, 0):
50
+            for x in range(0, self.gui.width):
51
+                for y in range(0, self.yOff):
52
+                    self.gui.set_pixel(x, y, self.c2)
53
+                for y in range(0, self.gui.height - self.image.height - self.yOff):
54
+                    self.gui.set_pixel(x, y + self.yOff + self.image.height, self.c2)
55
+            for y in range(0, self.image.height):
56
+                for x in range(0, self.xOff):
57
+                    self.gui.set_pixel(x, y + self.yOff, self.c2)
58
+                for x in range(0, self.gui.width - self.image.width - self.xOff):
59
+                    self.gui.set_pixel(x + self.xOff + self.image.width, y + self.yOff, self.c2)
60
+
61
+        for x in range(0, self.image.width):
62
+            for y in range(0, self.image.height):
63
+                v = self.image.getpixel((x, y))
64
+                if isinstance(v, int):
65
+                    v = (v, v, v)
66
+                self.gui.set_pixel(x + self.xOff, y + self.yOff, v)
67
+
68
+if __name__ == "__main__":
69
+    import util
70
+    t = util.getTarget()
71
+
72
+    d = QRScreen(t, "Hello World")
73
+    t.debug_loop(d.draw)

+ 4
- 1
util.py Целия файл

@@ -9,9 +9,12 @@
9 9
 
10 10
 import platform
11 11
 
12
+def isPi():
13
+    return platform.machine() == "armv7l"
14
+
12 15
 def getTarget():
13 16
     t = None
14
-    if platform.machine() == "armv7l":
17
+    if isPi():
15 18
         from pi import PiMatrix
16 19
         t = PiMatrix()
17 20
     else:

Loading…
Отказ
Запис