Class: Fusuma::Plugin::Inputs::PointingStickInput
- Inherits:
-
Input
- Object
- Input
- Fusuma::Plugin::Inputs::PointingStickInput
- Defined in:
- lib/fusuma/plugin/inputs/pointing_stick_input.rb
Overview
Read pointing stick events
Instance Method Summary collapse
- #config_param_types ⇒ Object
-
#initialize ⇒ PointingStickInput
constructor
A new instance of PointingStickInput.
- #io ⇒ Object
- #process_device_events(writer) ⇒ Object
-
#read_from_io ⇒ Object
Override Input#read_from_io.
Constructor Details
#initialize ⇒ PointingStickInput
Returns a new instance of PointingStickInput.
20 21 22 23 |
# File 'lib/fusuma/plugin/inputs/pointing_stick_input.rb', line 20 def initialize super @device_name_pattern = config_params(:device_name_pattern) end |
Instance Method Details
#config_param_types ⇒ Object
14 15 16 17 18 |
# File 'lib/fusuma/plugin/inputs/pointing_stick_input.rb', line 14 def config_param_types { device_name_pattern: String } end |
#io ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fusuma/plugin/inputs/pointing_stick_input.rb', line 25 def io @io ||= begin reader, writer = IO.pipe Thread.new do process_device_events(writer) writer.close end reader end end |
#process_device_events(writer) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fusuma/plugin/inputs/pointing_stick_input.rb', line 37 def process_device_events(writer) hidraw_device = find_hidraw_device(@device_name_pattern, wait: 3) hidraw_parser = select_hidraw_parser(hidraw_device.bustype) mouse_state = nil hidraw_parser.new(hidraw_device).parse do |new_state| next if mouse_state == new_state mouse_state = new_state writer.puts(mouse_state) end rescue Errno::EIO => e MultiLogger.error "#{self.class.name}: #{e}" retry end |
#read_from_io ⇒ Object
Override Input#read_from_io
55 56 57 58 59 60 61 62 |
# File 'lib/fusuma/plugin/inputs/pointing_stick_input.rb', line 55 def read_from_io status = io.readline(chomp: true) Events::Records::GestureRecord.new(gesture: "touch", status: status, finger: 1, delta: nil) rescue EOFError => e MultiLogger.error "#{self.class.name}: #{e}" MultiLogger.error "Shutdown fusuma process..." Process.kill("TERM", Process.pid) end |