def readFromPacket(packet): if (len(packet) < MegaDrive.PACKET_SIZE): return None state = ControllerStateBuilder() # data starts at bit 2 for i in range(0, 8): if MegaDrive.BUTTONS_0[i] is None: continue state.setButton(MegaDrive.BUTTONS_0[i], readBit(packet[0], i) != 0x01) for i in range(0, 8): if MegaDrive.BUTTONS_1[i] is None: continue state.setButton(MegaDrive.BUTTONS_1[i], readBit(packet[1], i) != 0x01) if (len(packet) >= MegaDrive.PACKET_SIZE_6_BUTTON): for i in range(0, 8): if MegaDrive.BUTTONS_2[i] is None: continue state.setButton(MegaDrive.BUTTONS_2[i], readBit(packet[2], i) != 0x01) return state.build()
def readPacketButtons(packet, buttons): if len(packet) < len(buttons): return None state = ControllerStateBuilder() for i in range(0, len(buttons)): if buttons[i] is None: continue state.setButton(buttons[i], packet[i] != 0x00) return state.build()
def readFromPacket(sender, packet): state = ControllerStateBuilder() for key in packet: p = packet[key] # check for special cases if key == 'shift' or key == 'ctrl' or key == 'windows': if p['type'] == 'button': state.setButton('left ' + p['name'], p['val']) state.setButton('right ' + p['name'], p['val']) if p['type'] == 'button': state.setButton(p['name'], p['val']) return state.build()
def readFromPacket(sender, packet): state = ControllerStateBuilder() for key in packet: p = packet[key] if p['type'] == 'button': state.setButton(p['name'], p['val']) elif p['type'] == 'analog': state.setAnalog(p['name'], p['val']) return state.build()
def readFromPacket(packet): if (len(packet) < Nintendo64.PACKET_SIZE): return None state = ControllerStateBuilder() for i in range(0, len(Nintendo64.BUTTONS)): if Nintendo64.BUTTONS[i] is None: continue state.setButton(Nintendo64.BUTTONS[i], packet[i] != 0x00) state.setAnalog( 'stick_x', Nintendo64.readStick( readByte(packet, len(Nintendo64.BUTTONS), True))) state.setAnalog( 'stick_y', Nintendo64.readStick( readByte(packet, len(Nintendo64.BUTTONS) + 8, True))) return state.build()
def readFromPacket(packet): if (len(packet) < GameCube.PACKET_SIZE): return None state = ControllerStateBuilder() for i in range(0, len(GameCube.BUTTONS)): if GameCube.BUTTONS[i] is None: continue state.setButton(GameCube.BUTTONS[i], packet[i] != 0x00) state.setAnalog( 'lstick_x', GameCube.readStick(readByte(packet, len(GameCube.BUTTONS)))) state.setAnalog( 'lstick_y', GameCube.readStick(readByte(packet, len(GameCube.BUTTONS) + 8))) state.setAnalog( 'cstick_x', GameCube.readStick(readByte(packet, len(GameCube.BUTTONS) + 16))) state.setAnalog( 'cstick_y', GameCube.readStick(readByte(packet, len(GameCube.BUTTONS) + 24))) state.setAnalog( 'trig_l', GameCube.readTrigger(readByte(packet, len(GameCube.BUTTONS) + 32))) state.setAnalog( 'trig_r', GameCube.readTrigger(readByte(packet, len(GameCube.BUTTONS) + 40))) return state.build()
def readFromPacket(sender, packet): state = ControllerStateBuilder() for key in packet: p = packet[key] # map buttons to nintendospy names if p['type'] == 'button': state.setButton(GENERIC_CONTROLLER_BTN[p['name']], p['val']) elif p['type'] == 'stick': # check for dpad if p['name'] == 'ABS_HAT0X': if p['val'] == 0: state.setButton('left', False) state.setButton('right', False) elif p['val'] == 1: state.setButton('right', True) state.setButton('left', False) elif p['val'] == -1: state.setButton('left', True) state.setButton('right', False) elif p['name'] == 'ABS_HAT0Y': if p['val'] == 0: state.setButton('up', False) state.setButton('down', False) elif p['val'] == 1: state.setButton('down', True) state.setButton('up', False) elif p['val'] == -1: state.setButton('up', True) state.setButton('down', False) elif p['name'] == 'ABS_X': state.setAnalog( 'x', GenericControllerParser.readStick(p['val'])) elif p['name'] == 'ABS_Y': state.setAnalog( 'y', GenericControllerParser.readStick(p['val'])) elif p['name'] == 'ABS_Z': state.setAnalog( 'rx', GenericControllerParser.readStick(p['val'])) elif p['name'] == 'ABS_RZ': state.setAnalog( 'ry', GenericControllerParser.readStick(p['val'])) return state.build()