Class: Vigilem::Evdev::Multiplexer

Inherits:
Object
  • Object
show all
Includes:
Core::Multiplexer
Defined in:
lib/vigilem/evdev/multiplexer.rb

Constant Summary collapse

Input =
System::Input
InputEvent =
Input::InputEvent

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(in_ios_or_arrays, out = nil) ⇒ Multiplexer

Returns a new instance of Multiplexer.

Parameters:

  • in_ios_or_arrays (Array || IO)
  • out (Array || IO) (defaults to: nil)


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_typeObject (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

Parameters:

  • (Array)

Returns:



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

Parameters:

  • num, (Integer)

    how much to read from each stream

Returns:



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