def create_gamepad(self, enabled, poller): """ Parses gamepad configuration and creates apropriate unput device """ if not enabled or "SCC_NOGAMEPAD" in os.environ: # Completly undocumented and for debuging purposes only. # If set, no gamepad is emulated self.gamepad = Dummy() return cfg = Config() keys = ALL_BUTTONS[0:cfg["output"]["buttons"]] vendor = int(cfg["output"]["vendor"], 16) product = int(cfg["output"]["product"], 16) version = int(cfg["output"]["version"], 16) name = cfg["output"]["name"] rumble = cfg["output"]["rumble"] and poller != None axes = [] i = 0 for min, max in cfg["output"]["axes"]: fuzz, flat = 0, 0 if abs(max - min) > 32768: fuzz, flat = 16, 128 try: axes.append(( ALL_AXES[i], min, max, fuzz, flat )) except IndexError: # Out of axes break i += 1 ui = UInput(vendor=vendor, product=product, version=version, name=name, keys=keys, axes=axes, rels=[], rumble=rumble) if poller and rumble: poller.register(ui.getDescriptor(), poller.POLLIN, self._rumble_ready) return ui