本文整理汇总了Python中evdev.InputDevice.fileno方法的典型用法代码示例。如果您正苦于以下问题:Python InputDevice.fileno方法的具体用法?Python InputDevice.fileno怎么用?Python InputDevice.fileno使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类evdev.InputDevice
的用法示例。
在下文中一共展示了InputDevice.fileno方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EvdevScanner
# 需要导入模块: from evdev import InputDevice [as 别名]
# 或者: from evdev.InputDevice import fileno [as 别名]
class EvdevScanner(BasePort):
""" Event scanner button port.
Event device scanner port reads keyup events from the specified event
device special file representing keyboard into a buffer. Once a RETURN
key is read the buffer is flushed as a read code.
Most barcode readers act as a HID keyboard. In order to make them work
with this port they must be configured to send RETURN after code.
Configuration
-------------
Port accepts the following positional arguments:
#. /path/to/event_device - path to event device special file
Full configuration line of evdev button is:
``scanner=evdev:/path/to/event_device``
"""
# NOTE This is really incomplete but it works with ticket generator just
# fine. Only missing symbols from Code39 (Standard) are %
CODE39 = {
2: '1', 3: '2', 4: '3', 5: ['4', '$'], 6: ['5', '%'],
7: '6', 8: '7', 9: ['8', '*'], 10: '9', 11: '0', 12: '-',
13: '+', 16: 'Q', 17: 'W', 18: 'E', 19: 'R', 20: 'T', 21: 'Y',
22: 'U', 23: 'I', 24: 'O', 25: 'P', 30: 'A', 31: 'S', 32: 'D',
33: 'F', 34: 'G', 35: 'H', 36: 'J', 37: 'K', 38: 'L', 44: 'Z',
45: 'X', 46: 'C', 47: 'V', 48: 'B', 49: 'N', 50: 'M', 52: '.',
53: '/', 57: ' ', }
def __init__(self, *args):
""" Initialize port configuration.
"""
self.path = '/dev/input/event0'
self.device = None
if len(args) >= 1:
self.path = args[0]
self._buffer = ''
self._shift = False
self._caps = False
logger.debug('Evdev scanner using: {}'.format(self.path))
def test(self):
""" Test if event device exists, is readable and has capability of
reading a keypress.
"""
if not os.access(self.path, os.R_OK | os.W_OK):
raise EvdevScannerTestError('Cannot access {}'.format(self.path))
# Check for EV_KEY capability
inputdev = InputDevice(self.path)
if 1 not in inputdev.capabilities():
raise EvdevScannerTestError('Device has no EV_KEY capability')
inputdev.close()
def open(self):
""" Open event device.
"""
logger.debug('Opening evdev {}'.format(self.path))
self.device = InputDevice(self.path)
if self.device:
logger.info('Evdev scanner found: {}'.format(self.device))
def close(self):
""" Close event device.
"""
logger.debug('Closing evdev {}'.format(self.path))
if self.is_open():
self.device.close()
def is_open(self):
""" Check whether the event device is open.
"""
if self.device:
return True
return False
def read(self, callback=None):
""" Read event device.
If button event is triggered a function assigned to callback
argument is run.
"""
# In order to avoid bare polling a select() is called on device
# descriptor with a reasonable timeout so the thread can be
# interrupted. In case of event read we will read and process it.
r, w, x = select.select([self.device.fileno()], [], [], 1)
if r:
event = self.device.read_one()
#.........这里部分代码省略.........
示例2: EvdevButton
# 需要导入模块: from evdev import InputDevice [as 别名]
# 或者: from evdev.InputDevice import fileno [as 别名]
class EvdevButton(BasePort):
""" Event device button port.
Event device button port reads keyup events from the specified event
device special file representing keyboard. A given keycode acts as
a button.
Configuration
-------------
Port accepts the following positional arguments:
#. /path/to/event_device - path to event device special file
#. scancode - scancode of trigger key
Full configuration line of evdev button is:
``button=evdev:/path/to/event_device,keycode``
"""
def __init__(self, *args):
""" Initialize port configuration.
"""
self.path = '/dev/input/event0'
self.scancode = 57
self.device = None
if len(args) >= 1:
self.path = args[0]
if len(args) >= 2:
self.scancode = int(args[1])
logger.info('Evdev button using: {} keycode={}'.format(
self.path, self.scancode))
def test(self):
""" Test if event device exists, is readable and has capability of
reading a keypress.
"""
# FIXME
pass
def open(self):
""" Open event device.
"""
logger.info('Opening evdev {}'.format(self.path))
self.device = InputDevice(self.path)
if self.device:
logger.info('Evdev button found: {}'.format(self.device))
def close(self):
""" Close event device.
"""
logger.info('Closing evdev {}'.format(self.path))
if self.is_open():
self.device.close()
self.device = None
def is_open(self):
""" Check whether the event device is open.
"""
if self.device:
return True
return False
def read(self, callback=None):
""" Read event device.
If button event is triggered a function assigned to callback
argument is run.
"""
# In order to avoid bare polling a select() is called on device
# descriptor with a reasonable timeout so the thread can be
# interrupted. In case of event read we will read and process it.
r, w, x = select.select([self.device.fileno()], [], [], 1)
if r:
e = self.device.read_one()
if e.type == ecodes.EV_KEY \
and e.value == 0 and e.code == self.scancode:
logger.debug('Trigger: {}'.format(e))
# Execute callback function
if callback and hasattr(callback, '__call__'):
callback()
def flush(self):
""" Flush event device.
"""
logger.debug('Flushing port')
while True:
r, w, x = select.select([self.device.fd], [], [], 0)
if r:
self.device.read_one()
else:
break
示例3: bytearray
# 需要导入模块: from evdev import InputDevice [as 别名]
# 或者: from evdev.InputDevice import fileno [as 别名]
strip.begin() # Initialize SPI pins for output
ledBuf = strip.getPixels() # Pointer to 'raw' LED strip data
clearBuf = bytearray([0xFF, 0, 0, 0] * num_leds)
imgNum = 0 # Index of currently-active image
duration = 2.0 # Image paint time, in seconds
filename = None # List of image files (nothing loaded yet)
lightpaint = None # LightPaint object for currently-active image (none yet)
# If a mouse is plugged in, set up epoll for sensing position
if os.path.exists(mousefile):
dev = InputDevice(eventfile)
# Register mouse descriptor with epoll
epoll = select.epoll()
epoll.register(dev.fileno(), select.EPOLLIN)
print 'Using mouse for positional input'
# FUNCTIONS ----------------------------------------------------------------
# Signal handler when SIGUSR1 is received (USB flash drive mounted,
# triggered by usbmount and 99_lightpaint_mount script).
def sigusr1_handler(signum, frame):
scandir()
# Ditto for SIGUSR2 (USB drive removed -- clears image file list)
def sigusr2_handler(signum, frame):
global filename
filename = None
imgNum = 0