コード例 #1
0
ファイル: devices.py プロジェクト: Acidburn0zzz/slackbuilds
	def __init__ (self, keymap, id=None, output=None, **params):
		"""
			If not specified, the id will be populated by the device's
			detected 'name' parameter (if any).
			The keymap argument should be an instance of mapping.Mapper.
			The keyword arguments are used to determine which device node/s
			to use for this device, and are matched against the information
			gleaned from the nodes themselves. Hence valid kwargs are:
			bus, name, vendor, product, and version.
		"""
		global _allInputNodes
		
		# This is a record of all currently 'down' keystrings, against the
		# Key instance that started it all off.
		self._pressed = {}
		# This is a record of the last-recorded positions of all ABS inputs.
		# The entries are of the same form as self._pressed; string:Key.
		self._absolute = {}
		# This is a dict of cycles of keypresses which need to be sent
		# out, against an iterator over the relevant sequence in the cycle.
		self._queue = {}
		# This is the set of all cycles which are due to end.
		self._ending = set()
		# This is the set of all cycles which have yet to start
		# This is needed because, for example, EV_REL events start and end
		# at the same time...
		self._starting = set()
		
		
		# Do stuff with device nodes
		nodes = ioctl.matchInputNodes (**params)
		self._nodes = nodes
		# Add all our nodes to the module's collection
		for node in nodes:
			_allInputNodes[node] = self
		# Make room for any partial data we get from our nodes
		self._partialReadData = dict(zip(nodes, [''] * len(nodes)))
		
		if nodes:
			if id is None:
				# Fetch the id (name) of the first node.
				id = ioctl.getDeviceName(nodes[0])
			
			ioctl.grabDevices(*nodes)
			
		
		
		self.keymap = keymap
		self.id = id
		self._outputNode = output
		
		# Shortcuts
		self._remap = lambda chord: self.keymap.remap(chord, device=self.id)
		self._inMap = lambda chord: self.keymap.deviceContains(chord, device=self.id)
コード例 #2
0
ファイル: devices.py プロジェクト: ShaneMcC/pystromo
	def __init__ (self, keymap, id=None, output=None, **params):
		"""
			If not specified, the id will be populated by the device's
			detected 'name' parameter (if any).
			The keymap argument should be an instance of mapping.Mapper.
			The keyword arguments are used to determine which device node/s
			to use for this device, and are matched against the information
			gleaned from the nodes themselves. Hence valid kwargs are:
			bus, name, vendor, product, and version.
		"""
		global _allInputNodes
		
		# Allow access to config params in other places.
		self._configParams = params;
		
		# This is a record of all currently 'down' keystrings, against the
		# Key instance that started it all off.
		self._pressed = {}
		# This is a record of the last-recorded positions of all ABS inputs.
		# The entries are of the same form as self._pressed; string:Key.
		self._absolute = {}
		# This is a set of all the 'on' feedback event key-strings:
		# "LED_*"s, etc.
		self._modes = set()
		# This is a dict of cycles of keypresses which need to be sent
		# out, against an iterator over the relevant sequence in the cycle.
		self._queue = {}
		# This is the set of all cycles which are due to end.
		self._ending = set()
		# This is the set of all cycles which have yet to start
		# This is needed because, for example, EV_REL events start and end
		# at the same time...
		self._starting = set()
		
		if self._configParams.has_key('leds'):
			self.saitekLED = self._configParams['leds'].replace(' ', '').split(',');
			# print 'Buttons that are actually LEDs: %s' % self.saitekLED;
		
		# Do stuff with device nodes
		# nodes = ioctl.matchInputNodes (**params)
		nodes = ioctl.matchInputNodes (vendor=params['vendor'], product=params['product'])
		self._nodes = nodes
		for node in nodes:
			# Gimme gimme gimme!
			node.grab()
			# Add our nodes to the module's collection
			_allInputNodes[node] = self
			
			# Zero all the LEDs on this node
			## We will receive events for every LED affected. Problem?
			if const.EV_LED in node.events:
				for led in node.events[const.EV_LED]:
					node.write(str(events.Event(type=const.EV_LED, code=led, value=0)))
			
		# Make room for any partial data we get from our nodes
		self._partialReadData = dict(zip(nodes, [''] * len(nodes)))
		
		if nodes and id is None:
			# Use the name of the first node.
			id = nodes[0].name
		
		# Work out which events should go where
		self._targetDevices = targets = {}
		for evType in const.TYPES:
			if evType in output.node.events:
				targets[evType] = output
			else:
				targets[evType] = self
			
		
		self.keymap = keymap
		self.id = id
		self._outputNode = output
		
		# Shortcuts
		self._remap = lambda chord, **kwargs: self.keymap.remap(chord, device=self.id, **kwargs)
		self._inMap = lambda chord: self.keymap.deviceContains(chord, device=self.id)
		
		if self._configParams.has_key('savefile'):
			self.savefile_name = self._configParams['savefile'];
			self.savefile = ConfigParser.ConfigParser()
			self.savefile.read(os.path.expanduser(self.savefile_name))
			if self.savefile.has_section('lastled:'+self.id):
				try:
					stringCode = self.savefile.get('lastled:'+self.id, 'stringCode')
					eventValue = self.savefile.get('lastled:'+self.id, 'eventValue')
					key = mapping.Key(stringCode, eventValue, eventValue)
					self._changeMode(key)
					#print 'Last LED mode was: %s' % stringCode
				except KeyError:
					print 'Last LED mode unknown, hoping for EV_LED event.. (HINT: Change the mode on the keypad..)'
			else:
				print 'Last LED mode unknown, hoping for EV_LED event.. (HINT: Change the mode on the keypad..)'
コード例 #3
0
ファイル: devices.py プロジェクト: Nicolas01/Pystromo
	def __init__ (self, keymap, id=None, output=None, **params):
		"""
			If not specified, the id will be populated by the device's
			detected 'name' parameter (if any).
			The keymap argument should be an instance of mapping.Mapper.
			The keyword arguments are used to determine which device node/s
			to use for this device, and are matched against the information
			gleaned from the nodes themselves. Hence valid kwargs are:
			bus, name, vendor, product, and version.
		"""
		global _allInputNodes
		
		# This is a record of all currently 'down' keystrings, against the
		# Key instance that started it all off.
		self._pressed = {}
		# This is a record of the last-recorded positions of all ABS inputs.
		# The entries are of the same form as self._pressed; string:Key.
		self._absolute = {}
		# This is a set of all the 'on' feedback event key-strings:
		# "LED_*"s, etc.
		self._modes = set()
		# This is a dict of cycles of keypresses which need to be sent
		# out, against an iterator over the relevant sequence in the cycle.
		self._queue = {}
		# This is the set of all cycles which are due to end.
		self._ending = set()
		# This is the set of all cycles which have yet to start
		# This is needed because, for example, EV_REL events start and end
		# at the same time...
		self._starting = set()
		
		
		# Do stuff with device nodes
		nodes = ioctl.matchInputNodes (**params)
		self._nodes = nodes
		for node in nodes:
			# Gimme gimme gimme!
			node.grab()
			# Add our nodes to the module's collection
			_allInputNodes[node] = self
			
			# Zero all the LEDs on this node
			## We will receive events for every LED affected. Problem?
			if const.EV_LED in node.events:
				for led in node.events[const.EV_LED]:
					node.write(str(events.Event(type=const.EV_LED, code=led, value=0)))
			
		# Make room for any partial data we get from our nodes
		self._partialReadData = dict(zip(nodes, [''] * len(nodes)))
		
		if nodes and id is None:
			# Use the name of the first node.
			id = nodes[0].name
		
		# Work out which events should go where
		self._targetDevices = targets = {}
		for evType in const.TYPES:
			if evType in output.node.events:
				targets[evType] = output
			else:
				targets[evType] = self
			
		
		self.keymap = keymap
		self.id = id
		self._outputNode = output
		
		# Shortcuts
		self._remap = lambda chord, **kwargs: self.keymap.remap(chord, device=self.id, **kwargs)
		self._inMap = lambda chord: self.keymap.deviceContains(chord, device=self.id)