class LibComponent::Input

Instanciate an input pin to your component

Attributes

input[RW]
interface[R]
last_iface_init[RW]
name[R]

Public Class Methods

new(pin_name_,iface_name_) click to toggle source

instaciate an input pin with its name and the interface this pin will support

# File lib/openplacos/libcomponent.rb, line 68
def initialize(pin_name_,iface_name_)
  @name      = pin_name_
  @interface = iface_name_      
  @input     = nil
  @last_iface_init = ""
end

Public Instance Methods

on_read(&block) click to toggle source

Event style for read definition Can also be overloaded by developper

# File lib/openplacos/libcomponent.rb, line 105
def on_read(&block)
  self.singleton_class.instance_eval {
    define_method(:read , &block)
  }
end
on_write(&block) click to toggle source

Event style for write definition Can also be overloaded by developper

# File lib/openplacos/libcomponent.rb, line 113
def on_write(&block)
  self.singleton_class.instance_eval {
    define_method(:write , &block)
  }
end
read_lib(*args) click to toggle source

read method called by dbus this method will

  • turning off previous interface

  • turn pin into input mode

  • initialize current interface

  • and then made a read access

All these steps are optionnal and are in charge of component developper.

# File lib/openplacos/libcomponent.rb, line 82
def read_lib(*args)
  set_off # set_off last iface
  set_input_lib
  init_iface
  return read(*args)
end
write_lib(*args) click to toggle source

write method called by dbus this method will

  • turning off previous interface

  • turn pin into input mode

  • initialize current interface

  • and then made a read access

All these steps are optionnal and are in charge of component developper.

# File lib/openplacos/libcomponent.rb, line 96
def write_lib(*args)
  set_off # set_off last iface
  set_output_lib
  init_iface
  return write(*args)
end

Private Instance Methods

init_iface() click to toggle source

Initialize this interface Please implement init method at your end

# File lib/openplacos/libcomponent.rb, line 157
def init_iface
  if(@last_iface_init != @interface)
    if(self.respond_to?(:init))
      self.init
    end
  end
  @component.set_last_iface_init(@name, @interface) # set last_iface_name
end
set_input_lib() click to toggle source

If pin has to be set to input mode Please implement set_input method at your end

# File lib/openplacos/libcomponent.rb, line 134
def set_input_lib
  if (@input != 1) # 1 means input / 0 output
    if(self.respond_to?(:set_input))
      self.set_input()
    end
    @input = 1
  end 
  @last_iface_init = @interface
end
set_off() click to toggle source

Iface changed since last call, turn off previous one Please implement exit method at your end

# File lib/openplacos/libcomponent.rb, line 123
def set_off()
  if (@last_iface_init != @interface)
    prev_iface = @component.get_input_iface(@name, @last_iface_init)
    if(prev_iface.respond_to?(:exit))
       prev_iface.exit()
    end     
  end
end
set_output_lib() click to toggle source

If pin has to be set to output mode Please implement set_output method at your end

# File lib/openplacos/libcomponent.rb, line 146
def set_output_lib
  if (@input != 0) # 1 means input / 0 output
    if(self.respond_to?(:set_output))
      self.set_output()
    end
    @input = 0
  end     
end