annotate service/tinyScreen/tiny_screen.py @ 393:5fc79536885a

fix screen timing corruption, hopefully. add py client Ignore-this: 53f42a30bbc5d9047658fef6ff79637c
author drewp@bigasterisk.com
date Sat, 19 Jan 2019 12:12:06 -0800
parents c146fa2bc7d4
children a471688fb7b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
388
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
1 from docopt import docopt
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
2 from patchablegraph import PatchableGraph, CycloneGraphHandler, CycloneGraphEventsHandler
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
3 from rdflib import Namespace, URIRef, Literal, Graph
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
4 from rdflib.parser import StringInputSource
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
5 from twisted.internet import reactor
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
6 import cyclone.web
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
7 import sys, logging, time, textwrap
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
8
384
5cdc6e85265f start tiny_screen
drewp@bigasterisk.com
parents:
diff changeset
9 from luma.core.interface.serial import spi
5cdc6e85265f start tiny_screen
drewp@bigasterisk.com
parents:
diff changeset
10 from luma.oled.device import ssd1331
388
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
11 from PIL import Image, ImageFont, ImageDraw
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
12 ROOM = Namespace('http://projects.bigasterisk.com/room/')
384
5cdc6e85265f start tiny_screen
drewp@bigasterisk.com
parents:
diff changeset
13
388
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
14 logging.basicConfig()
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
15 log = logging.getLogger()
384
5cdc6e85265f start tiny_screen
drewp@bigasterisk.com
parents:
diff changeset
16
5cdc6e85265f start tiny_screen
drewp@bigasterisk.com
parents:
diff changeset
17 class Screen(object):
5cdc6e85265f start tiny_screen
drewp@bigasterisk.com
parents:
diff changeset
18 def __init__(self, spiDevice=1, rotation=0):
388
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
19 self._initOutput(spiDevice, rotation)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
20 self.news = ""
393
5fc79536885a fix screen timing corruption, hopefully. add py client
drewp@bigasterisk.com
parents: 388
diff changeset
21 self.goalState = None
388
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
22 self.animateTo(ROOM['boot'])
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
23
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
24 def _stateImage(self, state):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
25 return Image.open('anim/%s.png' % state.rsplit('/')[-1])
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
26
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
27 def _initOutput(self, spiDevice, rotation):
393
5fc79536885a fix screen timing corruption, hopefully. add py client
drewp@bigasterisk.com
parents: 388
diff changeset
28 self._dev = ssd1331(spi(device=spiDevice, port=0,
5fc79536885a fix screen timing corruption, hopefully. add py client
drewp@bigasterisk.com
parents: 388
diff changeset
29 # lots of timeouts on the 12288-byte transfer without this
5fc79536885a fix screen timing corruption, hopefully. add py client
drewp@bigasterisk.com
parents: 388
diff changeset
30 transfer_size=64,
5fc79536885a fix screen timing corruption, hopefully. add py client
drewp@bigasterisk.com
parents: 388
diff changeset
31 bus_speed_hz=16000000,
5fc79536885a fix screen timing corruption, hopefully. add py client
drewp@bigasterisk.com
parents: 388
diff changeset
32 gpio_RST=None),
5fc79536885a fix screen timing corruption, hopefully. add py client
drewp@bigasterisk.com
parents: 388
diff changeset
33 rotation=rotation)
388
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
34
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
35 def setContrast(self, contrast):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
36 """0..255"""
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
37 self._dev.contrast(contrast)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
38
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
39 def hide(self):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
40 """Switches the display mode OFF, putting the device in low-power sleep mode."""
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
41 self._dev.hide()
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
42
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
43 def show(self):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
44 self._dev.show()
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
45
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
46 def display(self, img):
393
5fc79536885a fix screen timing corruption, hopefully. add py client
drewp@bigasterisk.com
parents: 388
diff changeset
47 self._dev.display(img.convert(self._dev.mode))
388
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
48
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
49 def animateTo(self, state):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
50 """
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
51 boot
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
52 sleep
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
53 locked
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
54 lockedUnknownKey
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
55 unlockNews
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
56 """
393
5fc79536885a fix screen timing corruption, hopefully. add py client
drewp@bigasterisk.com
parents: 388
diff changeset
57 if self.goalState == state:
5fc79536885a fix screen timing corruption, hopefully. add py client
drewp@bigasterisk.com
parents: 388
diff changeset
58 return
388
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
59 self.goalState = state
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
60 self.display(self._stateImage(state))
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
61 if state == ROOM['unlockNews']:
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
62 self.renderNews()
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
63
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
64 def setNews(self, text):
393
5fc79536885a fix screen timing corruption, hopefully. add py client
drewp@bigasterisk.com
parents: 388
diff changeset
65 if self.news == text:
5fc79536885a fix screen timing corruption, hopefully. add py client
drewp@bigasterisk.com
parents: 388
diff changeset
66 return
388
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
67 self.news = text
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
68 if self.goalState == ROOM['unlockNews']:
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
69 # wrong during animation
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
70 self.renderNews()
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
71
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
72 def renderNews(self):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
73 bg = self._stateImage(ROOM['unlockNews'])
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
74 draw = ImageDraw.Draw(bg)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
75
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
76 font = ImageFont.truetype("font/Oswald-SemiBold.ttf", 12)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
77 #w, h = font.getsize('txt')
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
78 for i, line in enumerate(
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
79 textwrap.fill(self.news, width=12).splitlines()):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
80 draw.text((24, 0 + 10 * i), line, font=font)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
81 self.display(bg)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
82
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
83 class ScreenSim(Screen):
393
5fc79536885a fix screen timing corruption, hopefully. add py client
drewp@bigasterisk.com
parents: 388
diff changeset
84 def _initOutput(self):
388
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
85 self.windowScale = 2
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
86 import pygame
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
87 self.pygame = pygame
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
88 pygame.init()
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
89 self.surf = pygame.display.set_mode(
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
90 (96 * self.windowScale, 64 * self.windowScale))
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
91 time.sleep(.05) # something was causing the 1st update not to show
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
92
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
93 def display(self, img):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
94 pgi = self.pygame.image.fromstring(
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
95 img.tobytes(), img.size, img.mode)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
96 self.pygame.transform.scale(pgi, self.surf.get_size(), self.surf)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
97 self.pygame.display.flip()
384
5cdc6e85265f start tiny_screen
drewp@bigasterisk.com
parents:
diff changeset
98
388
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
99 def rdfGraphBody(body, headers):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
100 g = Graph()
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
101 g.parse(StringInputSource(body), format='nt')
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
102 return g
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
103
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
104 class OutputPage(cyclone.web.RequestHandler):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
105 def put(self):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
106 arg = self.request.arguments
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
107 if arg.get('s') and arg.get('p'):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
108 subj = URIRef(arg['s'][-1])
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
109 pred = URIRef(arg['p'][-1])
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
110 turtleLiteral = self.request.body
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
111 try:
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
112 obj = Literal(float(turtleLiteral))
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
113 except ValueError:
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
114 obj = Literal(turtleLiteral)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
115 stmts = [(subj, pred, obj)]
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
116 else:
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
117 nt = self.request.body.replace("\\n", "\n") # wrong, but i can't quote right in curl
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
118 g = rdfGraphBody(nt, self.request.headers)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
119 assert len(g)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
120 stmts = list(g.triples((None, None, None)))
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
121 self._onStatement(stmts)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
122
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
123 def _onStatement(self, stmts):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
124 """
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
125 (disp :brightness 1.0 . )
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
126 (disp :state :locked . )
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
127 (disp :state :sleep . )
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
128 (disp :state :readKeyUnlock . disp :news "some news text" . )
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
129 """
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
130 disp = ROOM['frontDoorOled']
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
131 for stmt in stmts:
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
132 if stmt[:2] == (disp, ROOM['news']):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
133 self.settings.screen.setNews(stmt[2].toPython())
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
134 elif stmt[:2] == (disp, ROOM['state']):
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
135 self.settings.screen.animateTo(stmt[2])
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
136 else:
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
137 log.warn("ignoring %s", stmt)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
138
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
139 if __name__ == '__main__':
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
140 arg = docopt("""
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
141 Usage: tiny_screen.py [options]
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
142
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
143 -v Verbose
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
144 -x Draw to X11 window, not output hardware
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
145 """)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
146 log.setLevel(logging.WARN)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
147 if arg['-v']:
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
148 from twisted.python import log as twlog
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
149 twlog.startLogging(sys.stdout)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
150 log.setLevel(logging.DEBUG)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
151
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
152 masterGraph = PatchableGraph()
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
153
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
154 if arg['-x']:
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
155 screen = ScreenSim()
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
156 else:
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
157 screen = Screen(spiDevice=1)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
158
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
159 port = 10013
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
160 reactor.listenTCP(port, cyclone.web.Application([
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
161 (r"/()", cyclone.web.StaticFileHandler,
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
162 {"path": ".", "default_filename": "index.html"}),
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
163 (r"/graph", CycloneGraphHandler, {'masterGraph': masterGraph}),
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
164 (r"/graph/events", CycloneGraphEventsHandler,
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
165 {'masterGraph': masterGraph}),
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
166 (r'/output', OutputPage),
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
167 ], screen=screen, masterGraph=masterGraph, debug=arg['-v']),
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
168 interface='::')
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
169 log.warn('serving on %s', port)
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
170
c146fa2bc7d4 tinyscreen can flip images and render news
drewp@bigasterisk.com
parents: 384
diff changeset
171 reactor.run()