Class: Revdev::EventDevice
- Inherits:
-
Object
- Object
- Revdev::EventDevice
- Defined in:
- lib/revdev.rb,
lib/revdev/event_device.rb
Constant Summary collapse
- ONE_CHAR_CODE =
'1'[0]
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Instance Method Summary collapse
- #all_leds_status ⇒ Object
- #all_sounds_status ⇒ Object
- #all_switch_status ⇒ Object
- #device_id ⇒ Object
- #device_name ⇒ Object
- #device_prop ⇒ Object
- #driver_version ⇒ Object
- #global_key_state ⇒ Object
-
#grab ⇒ Object
grab all input events of the event device.
-
#initialize(arg) ⇒ EventDevice
constructor
A new instance of EventDevice.
- #physical_location ⇒ Object
- #read_input_event ⇒ Object
- #read_ioctl_as_string_with(command) ⇒ Object
- #read_ioctl_with(command) ⇒ Object
-
#ungrab ⇒ Object
release the grabbed event device.
- #uniq_id ⇒ Object
- #write_input_event(ie) ⇒ Object
Constructor Details
#initialize(arg) ⇒ EventDevice
Returns a new instance of EventDevice.
9 10 11 12 13 14 15 |
# File 'lib/revdev/event_device.rb', line 9 def initialize arg if arg.kind_of? File @file = arg else @file = File.new arg, 'r+' end end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/revdev/event_device.rb', line 5 def file @file end |
Instance Method Details
#all_leds_status ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/revdev/event_device.rb', line 59 def all_leds_status r = read_ioctl_with EVIOCGLED r = r.unpack("b#{LED_MAX}")[0] m = {} LED_MAX.times do |i| break if REVERSE_MAPS[:LED][i].nil? m[REVERSE_MAPS[:LED][i]] = (r[i] == ONE_CHAR_CODE) end m end |
#all_sounds_status ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/revdev/event_device.rb', line 70 def all_sounds_status r = read_ioctl_with EVIOCGSND r = r.unpack("b#{LED_MAX}")[0] m = {} SND_MAX.times do |i| break if REVERSE_MAPS[:SND][i].nil? m[REVERSE_MAPS[:SND][i]] = (r[i] == ONE_CHAR_CODE) end m end |
#all_switch_status ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/revdev/event_device.rb', line 81 def all_switch_status r = read_ioctl_with EVIOCGSW r = r.unpack("b#{LED_MAX}")[0] m = {} SW_MAX.times do |i| break if REVERSE_MAPS[:SW][i].nil? m[REVERSE_MAPS[:SW][i]] = (r[i] == ONE_CHAR_CODE) end m end |
#device_id ⇒ Object
28 29 30 |
# File 'lib/revdev/event_device.rb', line 28 def device_id InputId.new read_ioctl_with EVIOCGID end |
#device_name ⇒ Object
37 38 39 |
# File 'lib/revdev/event_device.rb', line 37 def device_name read_ioctl_as_string_with EVIOCGNAME end |
#device_prop ⇒ Object
50 51 52 |
# File 'lib/revdev/event_device.rb', line 50 def device_prop read_ioctl_as_string_with EVIOCGPROP end |
#driver_version ⇒ Object
23 24 25 26 |
# File 'lib/revdev/event_device.rb', line 23 def driver_version r = read_ioctl_with EVIOCGVERSION r.unpack('C3') end |
#global_key_state ⇒ Object
55 56 57 |
# File 'lib/revdev/event_device.rb', line 55 def global_key_state read_ioctl_as_string_with EVIOCGKEY end |
#grab ⇒ Object
grab all input events of the event device
93 94 95 |
# File 'lib/revdev/event_device.rb', line 93 def grab @file.ioctl EVIOCGRAB, 1 end |
#physical_location ⇒ Object
41 42 43 |
# File 'lib/revdev/event_device.rb', line 41 def physical_location read_ioctl_as_string_with EVIOCGPHYS end |
#read_input_event ⇒ Object
102 103 104 105 106 |
# File 'lib/revdev/event_device.rb', line 102 def read_input_event ie = InputEvent.new @file.sysread InputEvent::SIZEOF puts "read #{ie.hr_type}\t#{ie.hr_code}\t#{ie.value}" if $DEBUG ie end |
#read_ioctl_as_string_with(command) ⇒ Object
32 33 34 35 |
# File 'lib/revdev/event_device.rb', line 32 def read_ioctl_as_string_with command r = read_ioctl_with command r.unpack('Z*').first end |
#read_ioctl_with(command) ⇒ Object
17 18 19 20 21 |
# File 'lib/revdev/event_device.rb', line 17 def read_ioctl_with command r = "" @file.ioctl command, r return r end |
#ungrab ⇒ Object
release the grabbed event device
98 99 100 |
# File 'lib/revdev/event_device.rb', line 98 def ungrab @file.ioctl EVIOCGRAB, 0 end |
#uniq_id ⇒ Object
45 46 47 |
# File 'lib/revdev/event_device.rb', line 45 def uniq_id read_ioctl_as_string_with EVIOCGUNIQ end |
#write_input_event(ie) ⇒ Object
108 109 110 111 |
# File 'lib/revdev/event_device.rb', line 108 def write_input_event ie puts "write #{ie.hr_type}\t#{ie.hr_code}\t#{ie.value}" if $DEBUG @file.syswrite ie.to_byte_string end |