David 10 anni fa
commit
7c814135d4

BIN
client/__pycache__/clock.cpython-35.pyc


BIN
client/__pycache__/keyboard.cpython-35.pyc


BIN
client/__pycache__/sock.cpython-35.pyc


+ 15 - 0
client/clock.py

@@ -0,0 +1,15 @@
+import threading
+import time
+class Clock(threading.Thread):
+    def __init__(self,sock):
+        super(Clock, self).__init__()
+        self.running = False
+        self.sock=sock
+
+    def run(self):
+        self.running=True
+        self.handleTime()
+    def handleTime(self):
+        while True:
+            self.sock.send( dict(type='time', time=time.strftime("%H:%M")))
+            time.sleep(15)

BIN
client/clock.pyc


File diff suppressed because it is too large
+ 86680 - 0
client/json


+ 29 - 0
client/keyboard.py

@@ -0,0 +1,29 @@
+import threading
+import json
+from select import select
+from evdev import ecodes, InputDevice, list_devices
+
+
+class Keyboard(threading.Thread):
+    def __init__(self,sock):
+        super(Keyboard, self).__init__()
+        self.devices = [InputDevice(d) for d in list_devices("/dev/input/")]
+        self.sock = sock
+        self.running = False
+
+    def run(self):
+        self.running=True
+        self.handleInput()
+    def handleInput(self):
+        dev = InputDevice("/dev/input/by-id/usb-Microsoft_Comfort_Curve_Keyboard_3000-event-kbd")
+        VALID_KEYS = [ "KEY_PAGEUP", "KEY_PAGEDOWN", "KEY_F5" ]
+        while True:
+            r, w, e = select([dev], [], [])
+            for ev in dev.read():
+                codename = '?'
+                if ev.type == ecodes.EV_SYN:
+                   continue 
+                if ev.type in ecodes.bytype:
+                    codename = ecodes.bytype[ev.type][ev.code]
+                if codename in VALID_KEYS and ev.value==0:
+                    print(codename)

BIN
client/keyboard.pyc


+ 25 - 0
client/main.py

@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+from keyboard import Keyboard
+from sock import Sock
+from clock import Clock
+import time
+
+HANDLE_KBD = 1
+
+s = Sock()
+s.start()
+time.sleep(0.5)
+if HANDLE_KBD == 1:
+    k = Keyboard(s)
+    k.start()
+
+c = Clock(s)
+c.start()
+
+if HANDLE_KBD == 1:
+    k.join()
+    print("k")
+c.join()
+print("c")
+s.join()
+print("s")

+ 18 - 0
client/sock.py

@@ -0,0 +1,18 @@
+import socket
+import threading
+import json
+import time
+class Sock(threading.Thread):
+    def __init__(self):
+        super(Sock, self).__init__()
+        self.running = False
+    def run(self):
+        self.INFOBEAMER_ADDR = ('127.0.0.1', 4444)
+        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
+        self.running = True
+
+    def send(self,obj):
+        data = str.encode("eba/data:%s\n" % json.dumps(obj))
+        self.sock.sendto(data, self.INFOBEAMER_ADDR)
+

BIN
client/sock.pyc


File diff suppressed because it is too large
+ 168797 - 0
client/socket


File diff suppressed because it is too large
+ 86680 - 0
client/threading


BIN
node/1.png


BIN
node/2.png


BIN
node/3.png


BIN
node/4.png


BIN
node/5.png


+ 40 - 0
node/node.lua

@@ -0,0 +1,40 @@
+gl.setup(800,600)
+
+local json = require "json"
+local font = resource.load_font("silkscreen.ttf")
+local cur_image = resource.load_image("../test/1.png")
+
+node.alias("eba")
+
+function decode_command(line)
+    local cmd = json.decode(line)
+	print(line)
+	if cmd.type == "diapo" then
+		cur_image:dispose()
+		cur_image = resource.load_image(cmd.image)
+	elseif cmd.type == "pregunta" then
+		cur_preg = cmd.preg	
+	elseif cmd.type == "time" then
+		time = cmd.time
+		print(time)
+	elseif cmd.type == "video" then
+		-- ?
+	elseif cmd.type == "switch" then
+		state = cmd.new_state
+	end
+end
+
+--node.event("input", decode_command) -- listen to TCP
+node.event("data", decode_command)  -- listen to UDP
+state = "diapo"
+cur_preg = ""
+time = "0:0"
+function node.render()
+	if state == "diapo" then
+		cur_image:draw(0,0,WIDTH,HEIGHT)
+		font:write(730,580,time,20,1,1,1,1)
+	elseif state == "pregunta" then
+		preguntas:draw(0,0,WIDTH,HEIGHT)
+		font:write(120,320,cur_preg,20,1,1,1,1)
+	end
+end

BIN
node/silkscreen.ttf