def poll(self): command = '' # buttons are first priority for i in range(self.Joystick.get_numbuttons()): if (self.Joystick.get_button(i)): button = "button %d" % (i + 1) command = config.JOY_CMDS.get(button, '') # hats are second priority if command == '': hatstring = '' for i in range(self.Joystick.get_numhats()): value = self.Joystick.get_hat(i) if (value[1] == 1): hatstring = "h%d up" % (i + 1) if (value[1] == -1): hatstring = "h%d down" % (i + 1) if (value[0] == -1): hatstring = "h%d left" % (i + 1) if (value[0] == 1): hatstring = "h%d right" % (i + 1) if hatstring != '': command = config.JOY_CMDS.get(hatstring, '') # axis are last priority if command == '': joystring = '' for i in range(self.Joystick.get_numaxes()): value = self.Joystick.get_axis(i) if (value > self.MAX[i]): self.MAX[i] = value if (value < self.MIN[i]): self.MIN[i] = value if (value > (self.MAX[i] * 0.8)): joystring = "a%d pos" % (i + 1) if (value < (self.MIN[i] * 0.8)): joystring = "a%d neg" % (i + 1) if joystring != '': command = config.JOY_CMDS.get(joystring, '') # if we have something to do if command != '': command = rc.key_event_mapper(command) if command: rc.post_event(command) sleep(0.2)
def poll(self): command = '' # buttons are first priority for i in range(self.Joystick.get_numbuttons()): if(self.Joystick.get_button(i)): button = "button %d" % (i + 1) command = config.JOY_CMDS.get(button, '') # hats are second priority if command == '': hatstring = '' for i in range(self.Joystick.get_numhats()): value = self.Joystick.get_hat(i) if(value[1] == 1): hatstring = "h%d up" % (i + 1) if(value[1] == -1): hatstring = "h%d down" % (i + 1) if(value[0] == -1): hatstring = "h%d left" % (i + 1) if(value[0] == 1): hatstring = "h%d right" % (i + 1) if hatstring != '': command = config.JOY_CMDS.get(hatstring, '') # axis are last priority if command == '': joystring = '' for i in range(self.Joystick.get_numaxes()): value = self.Joystick.get_axis(i) if (value > self.MAX[i]): self.MAX[i] = value if (value < self.MIN[i]): self.MIN[i] = value if (value > (self.MAX[i] * 0.8)): joystring = "a%d pos" % (i + 1) if (value < (self.MIN[i] * 0.8)): joystring = "a%d neg" % (i + 1) if joystring != '': command = config.JOY_CMDS.get(joystring, '') # if we have something to do if command != '': command = rc.key_event_mapper(command) if command: rc.post_event(command) sleep(0.2)
def poll(self): if not self.enabled: return command = '' _debug_('self.joyfd = %s' % self.joyfd, level=3) (r, w, e) = select.select([self.joyfd], [], [], 0) _debug_('r,w,e = %s,%s,%s' % (r, w, e), level=3) self.sensitivity = config.JOY_SENS if r: c = os.read(self.joyfd, 8) else: return data = struct.unpack('IhBB', c) if data[2] == 1 & data[1] == 1: button = 'button ' + str((data[3] + 1)) command = config.JOY_CMDS.get(button, '') if data[2] == 2: if ((data[3] == 1) & (data[1] < -self.sensitivity)): button = 'up' command = config.JOY_CMDS['up'] if ((data[3] == 1) & (data[1] > self.sensitivity)): button = 'down' command = config.JOY_CMDS['down'] if ((data[3] == 0) & (data[1] < -self.sensitivity)): button = 'left' command = config.JOY_CMDS['left'] if ((data[3] == 0) & (data[1] > self.sensitivity)): button = 'right' command = config.JOY_CMDS['right'] if command != '': _debug_('Translation: "%s" -> "%s"' % (button, command)) command = rc.key_event_mapper(command) if command: if not config.JOY_LOCKFILE: rc.post_event(command) elif not os.path.exists(config.JOY_LOCKFILE): rc.post_event(command)
def poll(self): if not self.enabled: return command = '' (r, w, e) = select.select([self.joyfd], [], [], 0) logger.log( 8, 'r=%r, w=%r, e=%r', r, w, e) self.sensitivity = config.JOY_SENS if not r: return c = os.read(self.joyfd, 8) data = struct.unpack('IhBB', c) logger.log( 9, 'data=%r', data) if data[2] == 1 & data[1] == 1: button = 'button '+str((data[3] + 1)) command = config.JOY_CMDS.get(button, '') if data[2] == 2: if ((data[3] == 1) & (data[1] < -self.sensitivity)): button = 'up' command = config.JOY_CMDS['up'] if ((data[3] == 1) & (data[1] > self.sensitivity)): button = 'down' command = config.JOY_CMDS['down'] if ((data[3] == 0) & (data[1] < -self.sensitivity)): button = 'left' command = config.JOY_CMDS['left'] if ((data[3] == 0) & (data[1] > self.sensitivity)): button = 'right' command = config.JOY_CMDS['right'] if command != '': logger.debug('Translation: "%s" -> "%s"', button, command) command = rc.key_event_mapper(command) if command: if not config.JOY_LOCKFILE: rc.post_event(command) elif not os.path.exists(config.JOY_LOCKFILE): rc.post_event(command)
def post(self, key): #print self.KEYMAP[key] command = rc.key_event_mapper(self.KEYMAP[key]) rc.post_event(command)