Selaa lähdekoodia

some old uncommited changes

Thomas B 3 kuukautta sitten
vanhempi
commit
941bec592a
4 muutettua tiedostoa jossa 91 lisäystä ja 20 poistoa
  1. 11
    0
      README.md
  2. 73
    16
      apod.py
  3. 3
    0
      games.py
  4. 4
    4
      mapper.py

+ 11
- 0
README.md Näytä tiedosto

18
 
18
 
19
 For evdev to find all devices you may need to add your user to the `input` group or run the scripts as root.
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
 The rest depends on the output device chosen.
32
 The rest depends on the output device chosen.
22
 For debugging on your host PC you can use the TestGUI interface with pygame:
33
 For debugging on your host PC you can use the TestGUI interface with pygame:
23
 
34
 

+ 73
- 16
apod.py Näytä tiedosto

17
 from image import ImageScreen
17
 from image import ImageScreen
18
 
18
 
19
 class APOD:
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
         self.gui = g
21
         self.gui = g
22
         self.input = i
22
         self.input = i
23
         self.timeout = to
23
         self.timeout = to
24
         self.refresh = r
24
         self.refresh = r
25
+        self.input_timeout = ito
25
 
26
 
26
         self.get = None
27
         self.get = None
27
         self.path = "https://apod.nasa.gov/apod"
28
         self.path = "https://apod.nasa.gov/apod"
31
         self.last = None
32
         self.last = None
32
         self.restart()
33
         self.restart()
33
 
34
 
34
-    def restart(self):
35
+    def reloadImage(self):
35
         if (self.last == None) or ((time.time() - self.last) >= self.refresh):
36
         if (self.last == None) or ((time.time() - self.last) >= self.refresh):
36
             try:
37
             try:
37
                 print("APOD refresh")
38
                 print("APOD refresh")
38
-                self.img_url = self.get_image_path()
39
+                self.img_url, self.img_desc = self.get_image_metadata()
39
                 self.img_path = self.download_image(self.img_url)
40
                 self.img_path = self.download_image(self.img_url)
40
                 self.image = ImageScreen(self.gui, self.img_path, 0.2, 1, 5.0, None, None, False)
41
                 self.image = ImageScreen(self.gui, self.img_path, 0.2, 1, 5.0, None, None, False)
41
                 self.last = time.time()
42
                 self.last = time.time()
47
                     print(e)
48
                     print(e)
48
                 print()
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
         self.show = time.time()
56
         self.show = time.time()
51
 
57
 
52
     def finished(self):
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
     def fetch(self, url):
74
     def fetch(self, url):
56
         # lazily initialize WiFi
75
         # lazily initialize WiFi
85
             print()
104
             print()
86
             return None
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
         r = self.fetch(self.path + "/" + path).text
116
         r = self.fetch(self.path + "/" + path).text
91
         for line in r.splitlines():
117
         for line in r.splitlines():
92
             start = line.find('IMG SRC="')
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
     def download_image(self, path):
128
     def download_image(self, path):
102
         print("Loading " + path)
129
         print("Loading " + path)
103
         r = self.fetch(path).content
130
         r = self.fetch(path).content
131
+
104
         scriptDir = os.path.dirname(os.path.realpath(__file__))
132
         scriptDir = os.path.dirname(os.path.realpath(__file__))
105
         imageDir = os.path.join(scriptDir, "images")
133
         imageDir = os.path.join(scriptDir, "images")
106
         imagePath = os.path.join(imageDir, "apod_" + os.path.basename(path))
134
         imagePath = os.path.join(imageDir, "apod_" + os.path.basename(path))
135
+
107
         if os.path.isfile(imagePath):
136
         if os.path.isfile(imagePath):
108
             print("Image already loaded. Skip.")
137
             print("Image already loaded. Skip.")
109
             return imagePath
138
             return imagePath
139
+
110
         print("Storing at " + imagePath)
140
         print("Storing at " + imagePath)
111
         with open(imagePath, 'wb') as f:
141
         with open(imagePath, 'wb') as f:
112
             f.write(r)
142
             f.write(r)
143
+
113
         return imagePath
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
     def draw(self):
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
 if __name__ == "__main__":
170
 if __name__ == "__main__":
120
     i = util.getInput()
171
     i = util.getInput()
121
     t = util.getTarget(i)
172
     t = util.getTarget(i)
122
 
173
 
123
     s = APOD(t, i)
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 Näytä tiedosto

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

+ 4
- 4
mapper.py Näytä tiedosto

150
             # 6am utc == 8am cest germany
150
             # 6am utc == 8am cest germany
151
             morning = (now[0], now[1], now[2], 6, 0, 0, 0, 0)
151
             morning = (now[0], now[1], now[2], 6, 0, 0, 0, 0)
152
         else:
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
             # 8am cest germany
159
             # 8am cest germany
160
             morning = (now[0], now[1], now[2], 8, 0, 0, 0, 0)
160
             morning = (now[0], now[1], now[2], 8, 0, 0, 0, 0)

Loading…
Peruuta
Tallenna