forked from MaximeCheramy/remotefreebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfreeboxcontroller.py
executable file
·47 lines (36 loc) · 1.45 KB
/
freeboxcontroller.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#/usr/bin/python3
from threading import Thread
from .detectserver import detect
from .rudp.client import client_handler
from .event_loop import event_loop
from .rudp.rudp import rudp
from .rudp_hid_client import rudp_hid_client
from .fbx_descriptor import fbx_foils_hid_device_descriptor, fbx_get_command
from frozax.log import success, info
class FreeboxController(object):
def __init__(self):
# find freebox
freebox = detect()
success("%s found at %s:%s" % (freebox.name, freebox.address, freebox.port))
fb_addr = (freebox.address, freebox.port)
# rudp event loop
evtloop = event_loop()
r = rudp(evtloop)
loop_thread = Thread(target=r.evtloop.loop)
loop_thread.daemon = True
loop_thread.start()
def handle_packet(cl, cmd, data):
info("handle packet main.py (%s %s %s)" % (cl, cmd, data))
def link_info(cl, info_):
info("link_info %s %s" % (cl, info_))
def connected(cl):
info("connected %s" % cl)
def server_lost(cl):
info("server_lost %s" % cl)
my_handler = client_handler(handle_packet, link_info, connected,
server_lost)
self.client = rudp_hid_client(r, my_handler, fb_addr)
self.client.setup_device(fbx_foils_hid_device_descriptor)
def press(self, key):
info("pressing %s" % key)
self.client.send_command(*fbx_get_command(key))