def run(self): sixaxis.initialize(self.csock, self.isock) self.xbmc.connect() try: # start the zeroconf thread if possible try: self.zeroconf_thread = ZeroconfThread() self.zeroconf_thread.add_service('_xbmc-events._udp', self.zeroconf_service_handler) self.zeroconf_thread.start() except Exception, e: print str(e) # main thread loop while not self.stop(): status = process_remote(self.isock, self.xbmc) if status == 2: # 2 = socket read timeout if self.timed_out(): raise Exception("PS3 Blu-Ray Remote powering off, "\ "timed out") elif status == 3: # 3 = ps and skip + self.next_xbmc() elif status == 4: # 4 = ps and skip - self.previous_xbmc() elif not status: # 0 = keys are normally processed self.reset_timeout()
def run(self): sixaxis.initialize(self.csock, self.isock) self.xbmc.connect() bflags = 0 released = set() pressed = set() pending = set() held = set() psflags = 0 psdown = 0 toggle_mouse = 0 self.reset_timeout() try: while not self.stop(): if self.timed_out(): for key in (held | pressed): (mapname, action, amount, axis) = keymap_sixaxis[key] self.xbmc.send_button_state(map=mapname, button=action, amount=0, down=0, axis=axis) raise Exception("PS3 Sixaxis powering off, timed out") if self.idle_time() > 50: self.xbmc.connect() try: data = sixaxis.read_input(self.isock) except Exception, e: print str(e) break if not data: continue (bflags, psflags, pressure) = sixaxis.process_input(data, self.xbmc, toggle_mouse) if psflags: self.reset_timeout() if psdown: if (time.time() - psdown) > 5: for key in (held | pressed): (mapname, action, amount, axis) = keymap_sixaxis[key] self.xbmc.send_button_state(map=mapname, button=action, amount=0, down=0, axis=axis) raise Exception("PS3 Sixaxis powering off, user request") else: psdown = time.time() else: if psdown: toggle_mouse = 1 - toggle_mouse psdown = 0 keys = set(getkeys(bflags)) released = (pressed | held) - keys held = (pressed | held) - released pressed = (keys - held) & pending pending = (keys - held) for key in released: (mapname, action, amount, axis) = keymap_sixaxis[key] self.xbmc.send_button_state(map=mapname, button=action, amount=0, down=0, axis=axis) for key in held: (mapname, action, amount, axis) = keymap_sixaxis[key] if amount > 0: amount = pressure[amount-1] * 256 self.xbmc.send_button_state(map=mapname, button=action, amount=amount, down=1, axis=axis) for key in pressed: (mapname, action, amount, axis) = keymap_sixaxis[key] if amount > 0: amount = pressure[amount-1] * 256 self.xbmc.send_button_state(map=mapname, button=action, amount=amount, down=1, axis=axis) if keys: self.reset_timeout() except Exception, e: printerr()
def run(self): sixaxis.initialize(self.csock, self.isock) self.xbmc.connect() bflags = 0 released = set() pressed = set() pending = set() held = set() psflags = 0 psdown = 0 toggle_mouse = 0 self.reset_timeout() try: while not self.stop(): if self.timed_out(): for key in (held | pressed): (mapname, action, amount, axis) = keymap_sixaxis[key] self.xbmc.send_button_state(map=mapname, button=action, amount=0, down=0, axis=axis) raise Exception("PS3 Sixaxis powering off, timed out") if self.idle_time() > 50: self.xbmc.connect() try: data = sixaxis.read_input(self.isock) except Exception, e: print str(e) break if not data: continue (bflags, psflags, pressure, analog) = sixaxis.process_input(data, self.xbmc, toggle_mouse) if analog: self.reset_timeout() if psflags: self.reset_timeout() if psdown: if (time.time() - psdown) > 5: for key in (held | pressed): (mapname, action, amount, axis) = keymap_sixaxis[key] self.xbmc.send_button_state(map=mapname, button=action, amount=0, down=0, axis=axis) raise Exception("PS3 Sixaxis powering off, user request") else: psdown = time.time() else: if psdown: toggle_mouse = 1 - toggle_mouse psdown = 0 keys = set(getkeys(bflags)) released = (pressed | held) - keys held = (pressed | held) - released pressed = (keys - held) & pending pending = (keys - held) for key in released: (mapname, action, amount, axis) = keymap_sixaxis[key] self.xbmc.send_button_state(map=mapname, button=action, amount=0, down=0, axis=axis) for key in held: (mapname, action, amount, axis) = keymap_sixaxis[key] if amount > 0: amount = pressure[amount-1] * 256 self.xbmc.send_button_state(map=mapname, button=action, amount=amount, down=1, axis=axis) for key in pressed: (mapname, action, amount, axis) = keymap_sixaxis[key] if amount > 0: amount = pressure[amount-1] * 256 self.xbmc.send_button_state(map=mapname, button=action, amount=amount, down=1, axis=axis) if keys: self.reset_timeout() except Exception, e: printerr()