aboutsummaryrefslogtreecommitdiff
path: root/turtetris_slave/__init__.py
diff options
context:
space:
mode:
authorKarel Kočí <karel.koci@nic.cz>2017-07-18 20:11:12 +0200
committerKarel Kočí <karel.koci@nic.cz>2017-07-19 10:15:02 +0200
commitdd8bcc2da80d15280b9aa94cec648fbdac576cc3 (patch)
treebac1f0e7b71b18414753e4ddfb507d70b79a0923 /turtetris_slave/__init__.py
parent0a9a2fd752b03e1796ed6ce110ee939f0eb773e6 (diff)
downloadturris-tetris-dd8bcc2da80d15280b9aa94cec648fbdac576cc3.tar.gz
turris-tetris-dd8bcc2da80d15280b9aa94cec648fbdac576cc3.tar.bz2
turris-tetris-dd8bcc2da80d15280b9aa94cec648fbdac576cc3.zip
Add matrix
Diffstat (limited to 'turtetris_slave/__init__.py')
-rw-r--r--turtetris_slave/__init__.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/turtetris_slave/__init__.py b/turtetris_slave/__init__.py
new file mode 100644
index 0000000..5779dee
--- /dev/null
+++ b/turtetris_slave/__init__.py
@@ -0,0 +1,31 @@
+import json
+import zmq
+from subprocess import check_output
+from . import leds
+
+
+def socket_init(line):
+ "Initialize socket for given line"
+ context = zmq.Context()
+ socket = context.socket(zmq.SUB)
+ socket.subscribe('line' + str(line))
+ # socket.setsockopt_string(zmq.SUBSCRIBE, 'line' + str(line))
+ socket.connect('tcp://192.168.2.1:4444') # TODO change to 192.168.1.1
+ return socket
+
+
+def main():
+ "Main function"
+ line = int(check_output("uci get turtetris.line", shell=True))
+ print("Starting turtetris client and connecting as line " + str(line))
+ sck = socket_init(line)
+ leds.prepare()
+ while True:
+ msg = sck.recv_string()
+ print(msg)
+ json0 = msg.find(' ') # First empty char is end of envelope
+ leds.output(json.loads(msg[json0:]))
+
+
+if __name__ == '__main__':
+ main()