Class: Vigilem::Evdev::Multiplexer
- Inherits:
-
Object
- Object
- Vigilem::Evdev::Multiplexer
- Includes:
- Core::Multiplexer
- Defined in:
- lib/vigilem/evdev/multiplexer.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#event_type ⇒ Object
readonly
[#from_string, #time, #size].
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(in_ios_or_arrays, out = nil) ⇒ Multiplexer
constructor
A new instance of Multiplexer.
-
#sweep(num) ⇒ Array<InputEvent>
calls the inputs and returns the converted array.
Constructor Details
#initialize(in_ios_or_arrays, out = nil) ⇒ Multiplexer
Returns a new instance of Multiplexer.
26 27 28 29 |
# File 'lib/vigilem/evdev/multiplexer.rb', line 26 def initialize(in_ios_or_arrays, out=nil) @event_type = InputEvent initialize_multiplexer(in_ios_or_arrays, out) end |
Instance Attribute Details
#event_type ⇒ Object (readonly)
- #from_string, #time, #size
21 22 23 |
# File 'lib/vigilem/evdev/multiplexer.rb', line 21 def event_type @event_type end |
Class Method Details
.acquire(inputs = []) ⇒ Evdev::Multiplexer
59 60 61 62 63 64 65 66 |
# File 'lib/vigilem/evdev/multiplexer.rb', line 59 def acquire(inputs=[]) if not @multiplexer @multiplexer ||= new(inputs) else @multiplexer.add_inputs(*inputs) @multiplexer end end |
Instance Method Details
#sweep(num) ⇒ Array<InputEvent>
calls the inputs and returns the converted array
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/vigilem/evdev/multiplexer.rb', line 34 def sweep(num) [*ready?].map do |input| begin event_ary = [*if input.respond_to? :read_nonblock events = event_type.from_string(input.read_nonblock(num * event_type.size)) events else input.slice!(num) end] event_ary.each do |event| # @fixme kludge, &block? if input.respond_to? :leds? and input.leds? and input.respond_to? :led_bits event.leds = input.led_bits end event.[:source] = input end rescue EOFError, Errno::EAGAIN => e end end.flatten.compact.sort {|a,b| a.time.to_f <=> b.time.to_f } end |