51 |
56 |
52 def trigger_event(what): |
57 def trigger_event(what): |
53 trigger_sound(what) |
58 trigger_sound(what) |
54 Popen(["/bin/sh", os.path.abspath(EVENTPREFIX + what)]) |
59 Popen(["/bin/sh", os.path.abspath(EVENTPREFIX + what)]) |
55 |
60 |
|
61 class SlotServer(threading.Thread): |
|
62 def __init__(self, blackbox): |
|
63 threading.Thread.__init__(self) |
|
64 self.server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000)) |
|
65 self.server.register_instance(blackbox) |
|
66 #self.server.register_function(lambda astr: '_' + astr, '_string') |
|
67 |
|
68 def run(self): |
|
69 self.server.serve_forever() |
|
70 |
|
71 class SlotClient(): |
|
72 def __init__(self, url): |
|
73 self.box = xmlrpclib.Server(url) |
|
74 |
56 class SlotCli(): |
75 class SlotCli(): |
57 def __init__(self, test = None, dev=""): |
76 def __init__(self, test = None, dev=""): |
58 self.box = Blackbox() |
77 self.box = Blackbox() |
59 if not test: |
78 if (not test): |
60 self.box.connect(dev) |
79 self.box.connect(dev) |
|
80 self.rpcserver = SlotServer(self.box) |
|
81 self.rpcserver.start() |
61 self.slot_dummy = { |
82 self.slot_dummy = { |
62 "name": "Unnamed", |
83 "name": "Unnamed", |
63 "laps": 0, |
84 "laps": 0, |
64 "laps_last": 0, |
85 "laps_last": 0, |
65 "last": 0.00, |
86 "last": 0.00, |
572 help="Communication port", metavar="[/dev/ttyUSB0]") |
593 help="Communication port", metavar="[/dev/ttyUSB0]") |
573 |
594 |
574 (options, args) = parser.parse_args() |
595 (options, args) = parser.parse_args() |
575 #if not options.dev: |
596 #if not options.dev: |
576 # options.dev = "/dev/ttyUSB0" |
597 # options.dev = "/dev/ttyUSB0" |
577 cli = SlotCli(options.test, options.dev) |
598 |
|
599 if options.live or options.learn or options.playback: |
|
600 cli = SlotCli(options.test, options.dev) |
|
601 else: |
|
602 cli = SlotClient('http://localhost:8000') |
578 # should a CLI function be started? |
603 # should a CLI function be started? |
579 |
604 |
580 if options.live: |
605 if options.live: |
581 # start the live monitor |
606 # start the live monitor |
582 cli.monitor() |
607 cli.monitor() |