-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
30 lines (25 loc) · 872 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from gi.repository import GObject
from tornado import websocket, web, ioloop
import simplejson as json
import scrollphat
class MainHandler(web.RequestHandler):
def get(self):
self.render("main.html")
class WebSocketHandler(websocket.WebSocketHandler):
def initialize(self):
self._foo= "hello"
print self._foo
def open(self):
print "I am open"
def on_message(self, message):
cmd = json.loads(message)
#{u'raw': 1, u'turned_on': True, u'led': 1}
if cmd['turned_on']:
scrollphat.set_pixel(cmd['led'],cmd['raw'],1)
else:
scrollphat.set_pixel(cmd['led'],cmd['raw'],0)
scrollphat.update()
if __name__ == "__main__":
handlers = [("/main", MainHandler), ("/ws", WebSocketHandler)];
web.Application(handlers).listen(80)
ioloop.IOLoop.current().start()