Exemple #1
0
	def __init__(self, vendor, product, version, name, keys, axes, rels, keyboard=False, rumble=False):
		self._lib = None
		self._k = keys
		self.name = name
		if not axes or len(axes) == 0:
			self._a, self._amin, self._amax, self._afuzz, self._aflat = [[]] * 5
		else:
			self._a, self._amin, self._amax, self._afuzz, self._aflat = zip(*axes)

		self._r = rels
		
		self._lib = find_library("libuinput")
		self._ff_events = None
		if rumble:
			self._ff_events = (POINTER(FeedbackEvent) * MAX_FEEDBACK_EFFECTS)()
			for i in xrange(MAX_FEEDBACK_EFFECTS):
				self._ff_events[i].contents = FeedbackEvent()
		
		try:
			if self._lib.uinput_module_version() != UNPUT_MODULE_VERSION:
				raise Exception()
		except:
			import sys
			print >>sys.stderr, "Invalid native module version. Please, recompile 'libuinput.so'"
			print >>sys.stderr, "If you are running sc-controller from source, you can do this by removing 'build' directory"
			print >>sys.stderr, "and runinng 'python setup.py build' or 'run.sh' script"
			raise Exception("Invalid native module version")
		
		c_k		= (ctypes.c_uint16 * len(self._k))(*self._k)
		c_a		= (ctypes.c_uint16 * len(self._a))(*self._a)
		c_amin	 = (ctypes.c_int32  * len(self._amin ))(*self._amin )
		c_amax	 = (ctypes.c_int32  * len(self._amax ))(*self._amax )
		c_afuzz	= (ctypes.c_int32  * len(self._afuzz))(*self._afuzz)
		c_aflat	= (ctypes.c_int32  * len(self._aflat))(*self._aflat)
		c_r		= (ctypes.c_uint16 * len(self._r))(*self._r)
		c_vendor   = ctypes.c_uint16(vendor)
		c_product  = ctypes.c_uint16(product)
		c_version  = ctypes.c_uint16(version)
		c_keyboard = ctypes.c_int(keyboard)
		c_rumble = ctypes.c_int(MAX_FEEDBACK_EFFECTS if rumble else 0)
		c_name = ctypes.c_char_p(name)
		
		self._fd = self._lib.uinput_init(ctypes.c_int(len(self._k)),
										 c_k,
										 ctypes.c_int(len(self._a)),
										 c_a,
										 c_amin,
										 c_amax,
										 c_afuzz,
										 c_aflat,
										 ctypes.c_int(len(self._r)),
										 c_r,
										 c_keyboard,
										 c_vendor,
										 c_product,
										 c_version,
										 c_rumble,
										 c_name)
		if self._fd < 0:
			raise CannotCreateUInputException("Failed to create uinput device. Error code: %s" % (self._fd,))
    def __init__(self, daemon):
        self._lib = find_library('libcemuhook')
        self._lib.cemuhook_data_recieved.argtypes = [
            c_int, c_int, c_char_p, c_size_t
        ]
        self._lib.cemuhook_data_recieved.restype = None
        self._lib.cemuhook_feed.argtypes = [
            c_int, c_int, CemuhookServer.C_DATA_T
        ]
        self._lib.cemuhook_feed.restype = None
        self._lib.cemuhook_socket_enable.argtypes = []
        self._lib.cemuhook_socket_enable.restype = c_bool

        if not self._lib.cemuhook_socket_enable():
            raise OSError("cemuhook_socket_enable failed")

        self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

        poller = daemon.get_poller()
        daemon.poller.register(self.socket.fileno(), poller.POLLIN,
                               self.on_data_recieved)

        self.socket.bind(('127.0.0.1', 26760))
        log.info("Created CemuHookUDP Motion Provider")
	def __init__(self, daemon, config):
		self.config = config
		self.daemon = daemon
		self.reconnecting = set()
		self._lib = find_library('libsc_by_bt')
		read_input = self._lib.read_input
		read_input.restype = ctypes.c_int
		read_input.argtypes = [ SCByBtCPtr ]
		daemon.get_device_monitor().add_callback("bluetooth",
				VENDOR_ID, PRODUCT_ID, self.new_device_callback, None)
	def __init__(self, daemon, config):
		self._controllers = {}
		self.daemon = daemon
		self.config = config
		self._lib = find_library('libremotepad')
		self._lib.remotepad_input.argtypes = [ POINTER(RemotePad), POINTER(RemoteJoypadMessage) ]
		self._lib.remotepad_input.restype = None
		self._size = ctypes.sizeof(RemoteJoypadMessage)
		self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
		self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
		server_address = ('0.0.0.0', self.PORT)
		self.sock.bind(server_address)
		poller = self.daemon.get_poller()
		poller.register(self.sock.fileno(), poller.POLLIN, self.on_data_ready)
		log.info("Listening on %s:%s", *server_address)
Exemple #5
0
class HIDDecoder(ctypes.Structure):
	_fields_ = [
		('axes', AxisData * AXIS_COUNT),
		('buttons', ButtonData),
		('packet_size', ctypes.c_size_t),
		
		('old_state', HIDControllerInput),
		('state', HIDControllerInput),
	]


HIDDecoderPtr = ctypes.POINTER(HIDDecoder)


_lib = find_library('libhiddrv')
_lib.decode.restype = bool
_lib.decode.argtypes = [ HIDDecoderPtr, ctypes.c_char_p ]


class HIDController(USBDevice, Controller):
	flags = ( ControllerFlags.HAS_RSTICK
			| ControllerFlags.SEPARATE_STICK
			| ControllerFlags.HAS_DPAD
			| ControllerFlags.NO_GRIPS )
	
	def __init__(self, device, daemon, handle, config_file, config, test_mode=False):
		USBDevice.__init__(self, device, handle)
		self._ready = False
		self.daemon = daemon
		self.config_file = config_file
Exemple #6
0
class HIDDecoder(ctypes.Structure):
	_fields_ = [
		('axes', AxisData * AXIS_COUNT),
		('buttons', ButtonData),
		('packet_size', ctypes.c_size_t),
		
		('old_state', HIDControllerInput),
		('state', HIDControllerInput),
	]


HIDDecoderPtr = ctypes.POINTER(HIDDecoder)


_lib = find_library('libhiddrv')
_lib.decode.restype = bool
_lib.decode.argtypes = [ HIDDecoderPtr, ctypes.c_char_p ]


class HIDController(USBDevice, Controller):
	flags = ControllerFlags.HAS_RSTICK | ControllerFlags.SEPARATE_STICK
	
	def __init__(self, device, daemon, handle, config_file, config, test_mode=False):
		USBDevice.__init__(self, device, handle)
		self._ready = False
		self.daemon = daemon
		self.config_file = config_file
		
		id = None
		max_size = 64