Class: Evdev

Inherits:
Object
  • 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: Converter Classes: AbsAxis

Constant Summary collapse

VERSION =
"0.1.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Evdev



21
22
23
24
25
26
27
28
# File 'lib/evdev.rb', line 21

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

#fileObject (readonly) Also known as: event_channel

Returns the value of attribute file.



30
31
32
# File 'lib/evdev.rb', line 30

def file
  @file
end

Class Method Details

.all(file_paths = '/dev/input/event*') ⇒ Object



16
17
18
# File 'lib/evdev.rb', line 16

def all(file_paths = '/dev/input/event*')
  Dir[file_paths].map{ |file_path| new(file_path) }
end

.finalize(device) ⇒ Object



12
13
14
# File 'lib/evdev.rb', line 12

def finalize(device)
  proc { Libevdev.free(device) }
end

Instance Method Details

#abs_axis(code) ⇒ Object



69
70
71
# File 'lib/evdev.rb', line 69

def abs_axis(code)
  AbsAxis.new(@device, Converter.code_to_int(code))
end

#bustypeObject



53
54
55
# File 'lib/evdev.rb', line 53

def bustype
  Libevdev.get_id_bustype(@device)
end

#driver_versionObject



61
62
63
# File 'lib/evdev.rb', line 61

def driver_version
  Libevdev.get_driver_version(@device)
end

#event_value(event) ⇒ Object



96
97
98
99
100
# File 'lib/evdev.rb', line 96

def event_value(event)
  return unless supports_event?(event)
  type = Converter.code_to_type(event)
  Libevdev.get_event_value(@device, Converter.type_to_int(type), Converter.code_to_int(event))
end

#events_pending?Boolean



92
93
94
# File 'lib/evdev.rb', line 92

def events_pending?
  1 == Libevdev.has_event_pending(@device)
end

#grabObject



73
74
75
# File 'lib/evdev.rb', line 73

def grab
  0 == Libevdev.grab(@device, Libevdev::GRAB)
end

#handle_event(mode = :blocking) ⇒ Object



86
87
88
89
90
# File 'lib/evdev.rb', line 86

def handle_event(mode = :blocking)
  event = LinuxInput::InputEvent.new
  Libevdev.next_event(@device, Libevdev.const_get(:"READ_FLAG_#{mode.upcase}"), event.pointer)
  trigger(Converter.int_to_name(event[:type], event[:code]), event[:value])
end

#has_property?(property) ⇒ Boolean



65
66
67
# File 'lib/evdev.rb', line 65

def has_property?(property)
  1 == Libevdev.has_property(@device, Converter.property_to_int(property))
end

#nameObject



33
34
35
# File 'lib/evdev.rb', line 33

def name
  Libevdev.get_name(@device)
end

#physObject



37
38
39
# File 'lib/evdev.rb', line 37

def phys
  Libevdev.get_phys(@device)
end

#product_idObject



49
50
51
# File 'lib/evdev.rb', line 49

def product_id
  Libevdev.get_id_product(@device)
end

#supports_event?(event) ⇒ Boolean



81
82
83
84
# File 'lib/evdev.rb', line 81

def supports_event?(event)
  type = Converter.code_to_type(event)
  handles_event_type?(type) and handles_event_code?(type, event)
end

#ungrabObject



77
78
79
# File 'lib/evdev.rb', line 77

def ungrab
  0 == Libevdev.grab(@device, Libevdev::UNGRAB)
end

#uniqObject



41
42
43
# File 'lib/evdev.rb', line 41

def uniq
  Libevdev.get_uniq(@device)
end

#vendor_idObject



45
46
47
# File 'lib/evdev.rb', line 45

def vendor_id
  Libevdev.get_id_vendor(@device)
end

#versionObject



57
58
59
# File 'lib/evdev.rb', line 57

def version
  Libevdev.get_id_version(@device)
end