Mercurial > code > home > repos > homeauto
comparison service/tinyScreen/tiny_screen.py @ 723:b87b6e9cedb2
whitespace
Ignore-this: c727f388f197a6fae88595fe6d455c7d
author | drewp@bigasterisk.com |
---|---|
date | Wed, 05 Feb 2020 00:29:13 -0800 |
parents | a93fbf0d0daa |
children |
comparison
equal
deleted
inserted
replaced
722:a93fbf0d0daa | 723:b87b6e9cedb2 |
---|---|
21 self.goalState = None | 21 self.goalState = None |
22 self.animateTo(ROOM['boot']) | 22 self.animateTo(ROOM['boot']) |
23 | 23 |
24 def _stateImage(self, state): | 24 def _stateImage(self, state): |
25 return Image.open('anim/%s.png' % state.rsplit('/')[-1]) | 25 return Image.open('anim/%s.png' % state.rsplit('/')[-1]) |
26 | 26 |
27 def _initOutput(self, spiDevice, rotation): | 27 def _initOutput(self, spiDevice, rotation): |
28 # CS on pin 26 (GPIO7; spi0 ce1), DC on pin 18 (GPIO24), RST held at VCC. | 28 # CS on pin 26 (GPIO7; spi0 ce1), DC on pin 18 (GPIO24), RST held at VCC. |
29 self._dev = ssd1331(spi(device=spiDevice, port=0, | 29 self._dev = ssd1331(spi(device=spiDevice, port=0, |
30 # lots of timeouts on the 12288-byte transfer without this | 30 # lots of timeouts on the 12288-byte transfer without this |
31 #transfer_size=64, | 31 #transfer_size=64, |
32 #bus_speed_hz=16000000, | 32 #bus_speed_hz=16000000, |
33 gpio_RST=None, | 33 gpio_RST=None, |
34 gpio_DC=24, | 34 gpio_DC=24, |
35 ), | 35 ), |
36 rotation=rotation) | 36 rotation=rotation) |
37 | 37 |
38 def setContrast(self, contrast): | 38 def setContrast(self, contrast): |
39 """0..255""" | 39 """0..255""" |
40 self._dev.contrast(contrast) | 40 self._dev.contrast(contrast) |
41 | 41 |
42 def hide(self): | 42 def hide(self): |
69 return | 69 return |
70 self.news = text | 70 self.news = text |
71 if self.goalState == ROOM['unlockNews']: | 71 if self.goalState == ROOM['unlockNews']: |
72 # wrong during animation | 72 # wrong during animation |
73 self.renderNews() | 73 self.renderNews() |
74 | 74 |
75 def renderNews(self): | 75 def renderNews(self): |
76 bg = self._stateImage(ROOM['unlockNews']) | 76 bg = self._stateImage(ROOM['unlockNews']) |
77 draw = ImageDraw.Draw(bg) | 77 draw = ImageDraw.Draw(bg) |
78 | 78 |
79 font = ImageFont.truetype("font/Oswald-SemiBold.ttf", 12) | 79 font = ImageFont.truetype("font/Oswald-SemiBold.ttf", 12) |
80 #w, h = font.getsize('txt') | 80 #w, h = font.getsize('txt') |
81 for i, line in enumerate( | 81 for i, line in enumerate( |
82 textwrap.fill(self.news, width=12).splitlines()): | 82 textwrap.fill(self.news, width=12).splitlines()): |
83 draw.text((24, 0 + 10 * i), line, font=font) | 83 draw.text((24, 0 + 10 * i), line, font=font) |
84 self.display(bg) | 84 self.display(bg) |
85 | 85 |
86 class ScreenSim(Screen): | 86 class ScreenSim(Screen): |
87 def _initOutput(self): | 87 def _initOutput(self): |
88 self.windowScale = 2 | 88 self.windowScale = 2 |
89 import pygame | 89 import pygame |
90 self.pygame = pygame | 90 self.pygame = pygame |
91 pygame.init() | 91 pygame.init() |
92 self.surf = pygame.display.set_mode( | 92 self.surf = pygame.display.set_mode( |
93 (96 * self.windowScale, 64 * self.windowScale)) | 93 (96 * self.windowScale, 64 * self.windowScale)) |
94 time.sleep(.05) # something was causing the 1st update not to show | 94 time.sleep(.05) # something was causing the 1st update not to show |
95 | 95 |
96 def display(self, img): | 96 def display(self, img): |
97 pgi = self.pygame.image.fromstring( | 97 pgi = self.pygame.image.fromstring( |
98 img.tobytes(), img.size, img.mode) | 98 img.tobytes(), img.size, img.mode) |
99 self.pygame.transform.scale(pgi, self.surf.get_size(), self.surf) | 99 self.pygame.transform.scale(pgi, self.surf.get_size(), self.surf) |
100 self.pygame.display.flip() | 100 self.pygame.display.flip() |
120 nt = self.request.body.replace("\\n", "\n") # wrong, but i can't quote right in curl | 120 nt = self.request.body.replace("\\n", "\n") # wrong, but i can't quote right in curl |
121 g = rdfGraphBody(nt, self.request.headers) | 121 g = rdfGraphBody(nt, self.request.headers) |
122 assert len(g) | 122 assert len(g) |
123 stmts = list(g.triples((None, None, None))) | 123 stmts = list(g.triples((None, None, None))) |
124 self._onStatement(stmts) | 124 self._onStatement(stmts) |
125 | 125 |
126 def _onStatement(self, stmts): | 126 def _onStatement(self, stmts): |
127 """ | 127 """ |
128 (disp :brightness 1.0 . ) | 128 (disp :brightness 1.0 . ) |
129 (disp :state :locked . ) | 129 (disp :state :locked . ) |
130 (disp :state :sleep . ) | 130 (disp :state :sleep . ) |
136 self.settings.screen.setNews(stmt[2].toPython()) | 136 self.settings.screen.setNews(stmt[2].toPython()) |
137 elif stmt[:2] == (disp, ROOM['state']): | 137 elif stmt[:2] == (disp, ROOM['state']): |
138 self.settings.screen.animateTo(stmt[2]) | 138 self.settings.screen.animateTo(stmt[2]) |
139 else: | 139 else: |
140 log.warn("ignoring %s", stmt) | 140 log.warn("ignoring %s", stmt) |
141 | 141 |
142 if __name__ == '__main__': | 142 if __name__ == '__main__': |
143 arg = docopt(""" | 143 arg = docopt(""" |
144 Usage: tiny_screen.py [options] | 144 Usage: tiny_screen.py [options] |
145 | 145 |
146 -v Verbose | 146 -v Verbose |
168 {'masterGraph': masterGraph}), | 168 {'masterGraph': masterGraph}), |
169 (r'/output', OutputPage), | 169 (r'/output', OutputPage), |
170 ], screen=screen, masterGraph=masterGraph, debug=arg['-v']), | 170 ], screen=screen, masterGraph=masterGraph, debug=arg['-v']), |
171 interface='::') | 171 interface='::') |
172 log.warn('serving on %s', port) | 172 log.warn('serving on %s', port) |
173 | 173 |
174 reactor.run() | 174 reactor.run() |