comparison service/tinyScreen/tiny_screen.py @ 1198:971462233d15

fix screen timing corruption, hopefully. add py client Ignore-this: 53f42a30bbc5d9047658fef6ff79637c darcs-hash:91af2c8b3b8fce208c5a0eb460de095754a80424
author drewp <drewp@bigasterisk.com>
date Sat, 19 Jan 2019 12:12:06 -0800
parents 08a6eb5edf3d
children a471688fb7b7
comparison
equal deleted inserted replaced
1197:d8acab2b01f5 1198:971462233d15
16 16
17 class Screen(object): 17 class Screen(object):
18 def __init__(self, spiDevice=1, rotation=0): 18 def __init__(self, spiDevice=1, rotation=0):
19 self._initOutput(spiDevice, rotation) 19 self._initOutput(spiDevice, rotation)
20 self.news = "" 20 self.news = ""
21 self.goalState = None
21 self.animateTo(ROOM['boot']) 22 self.animateTo(ROOM['boot'])
22 23
23 def _stateImage(self, state): 24 def _stateImage(self, state):
24 return Image.open('anim/%s.png' % state.rsplit('/')[-1]) 25 return Image.open('anim/%s.png' % state.rsplit('/')[-1])
25 26
26 def _initOutput(self, spiDevice, rotation): 27 def _initOutput(self, spiDevice, rotation):
27 self._dev = ssd1331(spi(device=spiDevice, port=0), rotation=rotation) 28 self._dev = ssd1331(spi(device=spiDevice, port=0,
29 # lots of timeouts on the 12288-byte transfer without this
30 transfer_size=64,
31 bus_speed_hz=16000000,
32 gpio_RST=None),
33 rotation=rotation)
28 34
29 def setContrast(self, contrast): 35 def setContrast(self, contrast):
30 """0..255""" 36 """0..255"""
31 self._dev.contrast(contrast) 37 self._dev.contrast(contrast)
32 38
36 42
37 def show(self): 43 def show(self):
38 self._dev.show() 44 self._dev.show()
39 45
40 def display(self, img): 46 def display(self, img):
41 self._dev.display(img) 47 self._dev.display(img.convert(self._dev.mode))
42 48
43 def animateTo(self, state): 49 def animateTo(self, state):
44 """ 50 """
45 boot 51 boot
46 sleep 52 sleep
47 locked 53 locked
48 lockedUnknownKey 54 lockedUnknownKey
49 unlockNews 55 unlockNews
50 """ 56 """
57 if self.goalState == state:
58 return
51 self.goalState = state 59 self.goalState = state
52 self.display(self._stateImage(state)) 60 self.display(self._stateImage(state))
53 if state == ROOM['unlockNews']: 61 if state == ROOM['unlockNews']:
54 self.renderNews() 62 self.renderNews()
55 63
56 def setNews(self, text): 64 def setNews(self, text):
65 if self.news == text:
66 return
57 self.news = text 67 self.news = text
58 if self.goalState == ROOM['unlockNews']: 68 if self.goalState == ROOM['unlockNews']:
59 # wrong during animation 69 # wrong during animation
60 self.renderNews() 70 self.renderNews()
61 71
69 textwrap.fill(self.news, width=12).splitlines()): 79 textwrap.fill(self.news, width=12).splitlines()):
70 draw.text((24, 0 + 10 * i), line, font=font) 80 draw.text((24, 0 + 10 * i), line, font=font)
71 self.display(bg) 81 self.display(bg)
72 82
73 class ScreenSim(Screen): 83 class ScreenSim(Screen):
74 def _initOutput(self, spiDevice, rotation): 84 def _initOutput(self):
75 self.windowScale = 2 85 self.windowScale = 2
76 import pygame 86 import pygame
77 self.pygame = pygame 87 self.pygame = pygame
78 pygame.init() 88 pygame.init()
79 self.surf = pygame.display.set_mode( 89 self.surf = pygame.display.set_mode(