Class: Phidgets::Encoder::EncoderEncoders

Inherits:
Object
  • Object
show all
Defined in:
lib/phidgets-ffi/encoder.rb

Overview

This class represents a encoder for a PhidgetEncoder. All the properties of an encoder are stored and modified in this class.

Constant Summary collapse

Klass =
Phidgets::FFI::CPhidgetEncoder

Instance Method Summary collapse

Instance Method Details

#enabledBoolean

Returns the enabled state of a encoder, or raises an error.

Returns:

  • (Boolean)

    returns the enabled state of a encoder, or raises an error.



133
134
135
136
137
# File 'lib/phidgets-ffi/encoder.rb', line 133

def enabled
  ptr = ::FFI::MemoryPointer.new(:int)
  Klass.getEnabled(@handle, @index, ptr)
  (ptr.get_int(0) == 0) ? false : true
end

#enabled=(new_state) ⇒ Boolean

Sets the enabled state of an encoder, or raises an error.

Parameters:

  • new_state (Boolean)

    new state

Returns:

  • (Boolean)

    returns enabled state of an encoder, or raises an error.



142
143
144
145
146
# File 'lib/phidgets-ffi/encoder.rb', line 142

def enabled=(new_state)
  tmp = new_state ? 1 : 0
  Klass.setEnabled(@handle, @index, tmp)
  new_state
end

#indexInteger

Returns the index of the encoder, or raises an error.

Returns:

  • (Integer)

    returns the index of the encoder, or raises an error.



121
122
123
# File 'lib/phidgets-ffi/encoder.rb', line 121

def index 
	@index
end

#index_positionInteger

Returns the index position for an encoder that supports index, or raises an error.

Returns:

  • (Integer)

    returns the index position for an encoder that supports index, or raises an error.



126
127
128
129
130
# File 'lib/phidgets-ffi/encoder.rb', line 126

def index_position
  ptr = ::FFI::MemoryPointer.new(:int)
  Klass.getIndexPosition(@handle, @index, ptr)
  ptr.get_int(0)
end

#inspectObject

Displays data for the encoder.



115
116
117
118
# File 'lib/phidgets-ffi/encoder.rb', line 115

def inspect
     "#<#{self.class} @index=#{index}, @position=#{position}>"

end

#positionInteger

Returns the position of an encoder, or raises an error.

Returns:

  • (Integer)

    returns the position of an encoder, or raises an error.



149
150
151
152
153
# File 'lib/phidgets-ffi/encoder.rb', line 149

def position
  ptr = ::FFI::MemoryPointer.new(:int)
  Klass.getPosition(@handle, @index, ptr)
  ptr.get_int(0)
end

#position=(new_position) ⇒ Integer

Sets the position of an encoder, or raises an error.

Parameters:

  • new_position (Integer)

    new position

Returns:

  • (Integer)

    returns the position of an encoder, or raises an error.



158
159
160
161
# File 'lib/phidgets-ffi/encoder.rb', line 158

def position=(new_position)
  Klass.setPosition(@handle, @index, new_position.to_i)
  new_position
end