Class: Fusuma::Plugin::Sendkey::Device
- Inherits:
-
Object
- Object
- Fusuma::Plugin::Sendkey::Device
- Defined in:
- lib/fusuma/plugin/sendkey/device.rb
Overview
handle Evdev device
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
Instance Method Summary collapse
-
#initialize(path:) ⇒ Device
constructor
A new instance of Device.
- #path ⇒ Object
- #reload_capability ⇒ Object
- #write_event(event) ⇒ Object
Constructor Details
#initialize(path:) ⇒ Device
Returns a new instance of Device.
11 12 13 14 |
# File 'lib/fusuma/plugin/sendkey/device.rb', line 11 def initialize(path:) @evdev = Revdev::EventDevice.new(path) @capabilities = Set.new end |
Instance Attribute Details
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
16 17 18 |
# File 'lib/fusuma/plugin/sendkey/device.rb', line 16 def capabilities @capabilities end |
Instance Method Details
#path ⇒ Object
18 19 20 21 22 |
# File 'lib/fusuma/plugin/sendkey/device.rb', line 18 def path raise "Device path is not found" if @evdev.nil? @path ||= @evdev.file.path end |
#reload_capability ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fusuma/plugin/sendkey/device.rb', line 28 def reload_capability @capabilities.clear buf = fetch_capabilities buf.unpack("C*").each_with_index do |byte, i| 8.times do |bit| # 0..7 if byte[bit] != 0 @capabilities << (i * 8 + bit) end end end @capabilities end |
#write_event(event) ⇒ Object
24 25 26 |
# File 'lib/fusuma/plugin/sendkey/device.rb', line 24 def write_event(event) @evdev.write_input_event(event) end |