Class: Evdev
- Inherits:
-
Object
show all
- Includes:
- CallbacksAttachable
- Defined in:
- lib/evdev.rb,
lib/evdev/version.rb,
lib/evdev/abs_axis.rb,
lib/evdev/converter.rb
Defined Under Namespace
Modules: AwaitEvent, Converter
Classes: AbsAxis
Constant Summary
collapse
- VERSION =
"1.0.0"
Instance Attribute Summary collapse
-
#file ⇒ Object
(also: #event_channel)
readonly
Returns the value of attribute file.
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(file_path) ⇒ Evdev
Returns a new instance of Evdev.
23
24
25
26
27
28
29
30
|
# File 'lib/evdev.rb', line 23
def initialize(file_path)
@file = File.open(file_path)
device_ptr = FFI::MemoryPointer.new :pointer
Libevdev.new_from_fd(@file.fileno, device_ptr)
@device = device_ptr.read_pointer
ObjectSpace.define_finalizer(self, self.class.finalize(@device))
end
|
Instance Attribute Details
#file ⇒ Object
Also known as:
event_channel
Returns the value of attribute file.
32
33
34
|
# File 'lib/evdev.rb', line 32
def file
@file
end
|
Class Method Details
.all(file_paths = '/dev/input/event*') ⇒ Object
18
19
20
|
# File 'lib/evdev.rb', line 18
def all(file_paths = '/dev/input/event*')
Dir[file_paths].map{ |file_path| new(file_path) }
end
|
.finalize(device) ⇒ Object
14
15
16
|
# File 'lib/evdev.rb', line 14
def finalize(device)
proc { Libevdev.free(device) }
end
|
Instance Method Details
#bustype ⇒ Object
55
56
57
|
# File 'lib/evdev.rb', line 55
def bustype
Libevdev.get_id_bustype(@device)
end
|
#driver_version ⇒ Object
63
64
65
|
# File 'lib/evdev.rb', line 63
def driver_version
Libevdev.get_driver_version(@device)
end
|
#event_value(event) ⇒ Object
#events_pending? ⇒ Boolean
97
98
99
|
# File 'lib/evdev.rb', line 97
def events_pending?
1 == Libevdev.has_event_pending(@device)
end
|
#grab ⇒ Object
75
76
77
|
# File 'lib/evdev.rb', line 75
def grab
0 == Libevdev.grab(@device, Libevdev::GRAB)
end
|
#handle_event(mode = :blocking) ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'lib/evdev.rb', line 88
def handle_event(mode = :blocking)
event = LinuxInput::InputEvent.new
Libevdev.next_event(@device, Libevdev.const_get(:"READ_FLAG_#{mode.upcase}"), event.pointer)
event_name = Converter.int_to_name(event[:type], event[:code])
trigger(event_name, event[:value], event_name)
rescue Errno::EAGAIN => e
raise e.extend AwaitEvent
end
|
#has_property?(property) ⇒ Boolean
67
68
69
|
# File 'lib/evdev.rb', line 67
def has_property?(property)
1 == Libevdev.has_property(@device, Converter.property_to_int(property))
end
|
#name ⇒ Object
35
36
37
|
# File 'lib/evdev.rb', line 35
def name
Libevdev.get_name(@device)
end
|
#phys ⇒ Object
39
40
41
|
# File 'lib/evdev.rb', line 39
def phys
Libevdev.get_phys(@device)
end
|
#product_id ⇒ Object
51
52
53
|
# File 'lib/evdev.rb', line 51
def product_id
Libevdev.get_id_product(@device)
end
|
#supports_event?(event) ⇒ Boolean
83
84
85
86
|
# File 'lib/evdev.rb', line 83
def supports_event?(event)
type = Converter.code_to_type(event)
handles_event_type?(type) and handles_event_code?(type, event)
end
|
#ungrab ⇒ Object
79
80
81
|
# File 'lib/evdev.rb', line 79
def ungrab
0 == Libevdev.grab(@device, Libevdev::UNGRAB)
end
|
#uniq ⇒ Object
43
44
45
|
# File 'lib/evdev.rb', line 43
def uniq
Libevdev.get_uniq(@device)
end
|
#vendor_id ⇒ Object
47
48
49
|
# File 'lib/evdev.rb', line 47
def vendor_id
Libevdev.get_id_vendor(@device)
end
|
#version ⇒ Object
59
60
61
|
# File 'lib/evdev.rb', line 59
def version
Libevdev.get_id_version(@device)
end
|