aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <jaseg@jaseg.net>2014-03-07 01:11:07 +0100
committerjaseg <jaseg@jaseg.net>2014-03-07 01:46:24 +0100
commit2cff1d4dde5120d437cbe22a6269cfba93486c62 (patch)
tree9ba2de8c7f90fb913b710caca94b89935ab6189f
parent2e4792f3b6592972a3ec653e96574108400e437a (diff)
parent8166cb4bb22b479e2e09a608499c09a6e09c3b44 (diff)
downloadmatelight-2cff1d4dde5120d437cbe22a6269cfba93486c62.tar.gz
matelight-2cff1d4dde5120d437cbe22a6269cfba93486c62.tar.bz2
matelight-2cff1d4dde5120d437cbe22a6269cfba93486c62.zip
Merge branch 'master' of https://github.com/jaseg/matelight
-rw-r--r--README.rst6
-rwxr-xr-xhost/server.py52
2 files changed, 50 insertions, 8 deletions
diff --git a/README.rst b/README.rst
index b6412a7..376db26 100644
--- a/README.rst
+++ b/README.rst
@@ -31,13 +31,19 @@ Related Projects
----------------
* `A Python script that plays gifs over CRAP`_
* `An HTML5 CRAP emulator`_
+* `A CRAP client for node.js`_
* `Webcam streaming on Mate Light`_
* `A game programming framework for Mate Light`_
* `Snake for Mate Light`_
* `Game of Life for Mate Light`_
+* `Mate Light Android App`_
+* `Blinkenlights for Mate Light`_
+* `Postillon Newsticker for Matelight`_
.. _`A Python script that plays gifs over CRAP`: https://github.com/uwekamper/matelight-gifplayer
.. _`An HTML5 CRAP emulator`: https://github.com/sodoku/matelightemu
+.. _`A CRAP client for node.js`: https://github.com/sodoku/node-matelight
+.. _`Postillon Newsticker for Matelight`: https://gist.github.com/XenGi/9168633
.. _`Webcam streaming on Mate Light`: https://github.com/c-base/matetv
.. _`A game programming framework for Mate Light`: https://github.com/c-base/pymlgame
.. _`Snake for Mate Light`: https://github.com/c-base/pymlsnake
diff --git a/host/server.py b/host/server.py
index ef4ce32..3b9590c 100755
--- a/host/server.py
+++ b/host/server.py
@@ -81,7 +81,29 @@ def log(*args):
print(strftime('\x1B[93m[%m-%d %H:%M:%S]\x1B[0m'), ' '.join(str(arg) for arg in args), '\x1B[0m')
printlock.release()
+
+class MateLightUDPServer(UDPServer):
+ """
+ The server class for the SocketServer interface.
+ """
+ def __init__(self, *args, **kwargs):
+ """
+ Setup the deque for the frame
+ """
+ super(MateLightUDPServer, self).__init__(*args, **kwargs)
+ self.frame_deque = collections.deque(maxlen=30)
+
+ def get_next_frame(self):
+ try:
+ return self.frame_deque.popleft()
+ except IndexError:
+ return None
+
+
class MateLightUDPHandler(BaseRequestHandler):
+ """
+ Handles one UDP connection to the matelight
+ """
def handle(self):
try:
# Housekeeping - FIXME: This is *so* the wrong place for this.
@@ -111,8 +133,9 @@ class MateLightUDPHandler(BaseRequestHandler):
if current_entry.entrytype == 'udp' and current_entry.remote == addr:
current_entry = conn
frame = a.reshape((DISPLAY_HEIGHT, DISPLAY_WIDTH, 3))
- sendframe(frame)
- printframe(np.pad(frame, ((0,0),(0,0),(0,1)), 'constant', constant_values=(0,0)))
+ self.server.frame_deque.append(frame)
+ #sendframe(frame)
+ #printframe(np.pad(frame, ((0,0),(0,0),(0,1)), 'constant', constant_values=(0,0)))
except Exception as e:
log('Error receiving UDP frame:', e)
@@ -129,19 +152,32 @@ class MateLightTCPTextHandler(BaseRequestHandler):
textqueue.append(QueueEntry('text', addr, timestamp, data))
self.request.sendall(b'KTHXBYE!\n')
-TCPServer.allow_reuse_address = True
-server = TCPServer(('', 1337), MateLightTCPTextHandler)
-t = threading.Thread(target=server.serve_forever)
-t.daemon = True
-t.start()
+#TCPServer.allow_reuse_address = True
+#server = TCPServer(('', 1337), MateLightTCPTextHandler)
+#t = threading.Thread(target=server.serve_forever)
+#t.daemon = True
+#t.start()
UDPServer.allow_reuse_address = True
-userver = UDPServer(('', 1337), MateLightUDPHandler)
+userver = MateLightUDPServer(('', 1337), MateLightUDPHandler)
t = threading.Thread(target=userver.serve_forever)
t.daemon = True
t.start()
if __name__ == '__main__':
+ while True:
+ millis = int(round(time.time() * 1000))
+
+ next_frame = userver.get_next_frame()
+ if next_frame:
+ sendframe(next_frame)
+
+ while int(round(time.time() * 1000)) - millis < 50:
+ // do nothing
+ pass
+
+
+def bla():
print('\033[2J'+'\n'*9)
while True:
if current_entry.entrytype == 'text':