소스 검색

some old uncommited changes

Thomas B 3 달 전
부모
커밋
941bec592a
4개의 변경된 파일91개의 추가작업 그리고 20개의 파일을 삭제
  1. 11
    0
      README.md
  2. 73
    16
      apod.py
  3. 3
    0
      games.py
  4. 4
    4
      mapper.py

+ 11
- 0
README.md 파일 보기

@@ -18,6 +18,17 @@ You always need:
18 18
 
19 19
 For evdev to find all devices you may need to add your user to the `input` group or run the scripts as root.
20 20
 
21
+To install wetterdienst on a Raspberry Pi 4 you first need to [get a Rust toolchain](https://rustup.rs/) (install it for root, because the visualizer has to run as root as well):
22
+
23
+    sudo su
24
+    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
25
+    # select arm-unknown-linux-gnueabihf manually
26
+    apt-get install gfortran libopenblas-base libopenblas-dev libatlas-base-dev python3-lxml python3-scipy python3-numpy python3-venv
27
+    python -m venv venv
28
+    source venv/bin/activate
29
+
30
+    pip install wetterdienst>=0.59.1 polars
31
+
21 32
 The rest depends on the output device chosen.
22 33
 For debugging on your host PC you can use the TestGUI interface with pygame:
23 34
 

+ 73
- 16
apod.py 파일 보기

@@ -17,11 +17,12 @@ import util
17 17
 from image import ImageScreen
18 18
 
19 19
 class APOD:
20
-    def __init__(self, g, i, to = 10.0, r = 6 * 60 * 60):
20
+    def __init__(self, g, i, to = 10.0, r = 6 * 60 * 60, ito = 30.0):
21 21
         self.gui = g
22 22
         self.input = i
23 23
         self.timeout = to
24 24
         self.refresh = r
25
+        self.input_timeout = ito
25 26
 
26 27
         self.get = None
27 28
         self.path = "https://apod.nasa.gov/apod"
@@ -31,11 +32,11 @@ class APOD:
31 32
         self.last = None
32 33
         self.restart()
33 34
 
34
-    def restart(self):
35
+    def reloadImage(self):
35 36
         if (self.last == None) or ((time.time() - self.last) >= self.refresh):
36 37
             try:
37 38
                 print("APOD refresh")
38
-                self.img_url = self.get_image_path()
39
+                self.img_url, self.img_desc = self.get_image_metadata()
39 40
                 self.img_path = self.download_image(self.img_url)
40 41
                 self.image = ImageScreen(self.gui, self.img_path, 0.2, 1, 5.0, None, None, False)
41 42
                 self.last = time.time()
@@ -47,10 +48,28 @@ class APOD:
47 48
                     print(e)
48 49
                 print()
49 50
 
51
+    def restart(self):
52
+        self.reloadImage()
53
+        self.old_keys = self.input.empty() # TODO support missing input
54
+        self.lastInput = None
55
+        self.drawingText = False
50 56
         self.show = time.time()
51 57
 
52 58
     def finished(self):
53
-        return (self.image == None) or ((time.time() - self.show) >= self.timeout)
59
+        if self.lastInput == None:
60
+            # skip when no image could be loaded
61
+            if self.image == None:
62
+                return True
63
+
64
+            # 10s show image timeout when no buttons have been pressed
65
+            if (time.time() - self.show) >= self.timeout:
66
+                return True
67
+        else:
68
+            # 30s button input timeout after last button press
69
+            if (time.time() - self.lastInput) >= self.input_timeout:
70
+                return True
71
+
72
+        return False
54 73
 
55 74
     def fetch(self, url):
56 75
         # lazily initialize WiFi
@@ -85,40 +104,78 @@ class APOD:
85 104
             print()
86 105
             return None
87 106
 
88
-    def get_image_path(self, path = ""):
89
-        print("Checking for new APOD")
107
+    def get_image_metadata(self, path = ""):
108
+        if len(path) == 0:
109
+            print("Checking for new APOD")
110
+        else:
111
+            print("Checking out APOD '{}'".format(path))
112
+
113
+        imgPath = None
114
+        imgDesc = None
115
+
90 116
         r = self.fetch(self.path + "/" + path).text
91 117
         for line in r.splitlines():
92 118
             start = line.find('IMG SRC="')
93
-            if start < 0:
94
-                continue
95
-            start += 9
96
-            end = line.find('"', start)
97
-            img = line[start : end]
98
-            return self.path + "/" + img
99
-        return None
119
+            if start >= 0:
120
+                start += 9
121
+                end = line.find('"', start)
122
+                img = line[start : end]
123
+                imgPath = self.path + "/" + img
124
+                break # TODO also check for description
125
+
126
+        return imgPath, imgDesc
100 127
 
101 128
     def download_image(self, path):
102 129
         print("Loading " + path)
103 130
         r = self.fetch(path).content
131
+
104 132
         scriptDir = os.path.dirname(os.path.realpath(__file__))
105 133
         imageDir = os.path.join(scriptDir, "images")
106 134
         imagePath = os.path.join(imageDir, "apod_" + os.path.basename(path))
135
+
107 136
         if os.path.isfile(imagePath):
108 137
             print("Image already loaded. Skip.")
109 138
             return imagePath
139
+
110 140
         print("Storing at " + imagePath)
111 141
         with open(imagePath, 'wb') as f:
112 142
             f.write(r)
143
+
113 144
         return imagePath
114 145
 
146
+    def buttons(self):
147
+        keys = self.input.get()
148
+
149
+        if keys["up"] and (not self.old_keys["up"]) and (not self.old_keys["select"]):
150
+            pass # TODO next picture
151
+        elif keys["down"] and (not self.old_keys["down"]) and (not self.old_keys["select"]):
152
+            pass # TODO previous picture
153
+        elif keys["a"] and (not self.old_keys["a"]):
154
+            self.drawingText = True
155
+        elif (keys["select"] and keys["start"] and (not self.old_keys["start"])) or (keys["start"] and keys["select"] and (not self.old_keys["select"])):
156
+            self.restart()
157
+
158
+        self.old_keys = keys.copy()
159
+
115 160
     def draw(self):
116
-        if self.image != None:
117
-            self.image.draw()
161
+        if self.input != None:
162
+            self.buttons()
163
+
164
+        if self.drawingText:
165
+            pass # TODO
166
+        else:
167
+            if self.image != None:
168
+                self.image.draw()
118 169
 
119 170
 if __name__ == "__main__":
120 171
     i = util.getInput()
121 172
     t = util.getTarget(i)
122 173
 
123 174
     s = APOD(t, i)
124
-    util.loop(t, s.draw)
175
+
176
+    def helper():
177
+        s.draw()
178
+        if s.finished():
179
+            s.restart()
180
+
181
+    util.loop(t, helper)

+ 3
- 0
games.py 파일 보기

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

+ 4
- 4
mapper.py 파일 보기

@@ -150,11 +150,11 @@ class MapperReduceBrightness(MapperNull):
150 150
             # 6am utc == 8am cest germany
151 151
             morning = (now[0], now[1], now[2], 6, 0, 0, 0, 0)
152 152
         else:
153
-            # 8pm cest germany
154
-            evening = (now[0], now[1], now[2], 20, 0, 0, 0, 0)
153
+            # 6pm cest germany
154
+            evening = (now[0], now[1], now[2], 18, 0, 0, 0, 0)
155 155
 
156
-            # 2am cest germany
157
-            night = (now[0], now[1], now[2], 2, 0, 0, 0, 0)
156
+            # 1am cest germany
157
+            night = (now[0], now[1], now[2], 1, 0, 0, 0, 0)
158 158
 
159 159
             # 8am cest germany
160 160
             morning = (now[0], now[1], now[2], 8, 0, 0, 0, 0)

Loading…
취소
저장