Class: Phidgets::Stepper

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/phidgets-ffi/stepper.rb

Overview

This class represents a PhidgetStepper.

Defined Under Namespace

Classes: StepperDigitalInputs, StepperSteppers

Constant Summary collapse

Klass =
Phidgets::FFI::CPhidgetStepper

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#attached?, #attached_to_server?, attributes, #close, #detached?, #detached_to_server?, device_class, #device_class, device_id, #id, #initialize, #label, #label=, #name, #on_attach, #on_detach, #on_error, #on_server_connect, #on_server_disconnect, #on_sleep, #on_wake, #serial_number, #server_address, server_address, #server_id, server_id, server_status, #type, #version, #wait_for_attachment

Instance Attribute Details

#attributesObject (readonly)

The attributes of a PhidgetStepper



20
21
22
# File 'lib/phidgets-ffi/stepper.rb', line 20

def attributes
  @attributes
end

#inputsStepperDigitalInputs (readonly)

Collection of digital inputs



11
12
13
# File 'lib/phidgets-ffi/stepper.rb', line 11

def inputs
  @inputs
end

#steppersStepperSteppers (readonly)

Collection of stepper motors

Returns:



15
16
17
# File 'lib/phidgets-ffi/stepper.rb', line 15

def steppers
  @steppers
end

Instance Method Details

#on_current_change(obj = nil, &block) ⇒ Boolean

Sets a current change handler callback function. This is called when current consumption of a stepper changes. Not all PhidgetSteppers support current sense.

As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.

Examples:

st.on_current_change do |device, stepper, current, obj|
  puts "Stepper #{stepper.index}'s current has changed to #{current}"
end

Parameters:

  • obj (String) (defaults to: nil)

    Object to pass to the callback function. This is optional.

  • Block (Proc)

    When the callback is executed, the device and object are yielded to this block.

Returns:

  • (Boolean)

    returns true or raises an error



91
92
93
94
95
96
97
# File 'lib/phidgets-ffi/stepper.rb', line 91

def on_current_change(obj=nil, &block)
  @on_current_change_obj = obj
  @on_current_change = Proc.new { |device, obj_ptr, index, current|
    yield self, @steppers[index], current, object_for(obj_ptr)
  }
  Klass.set_OnCurrentChange_Handler(@handle, @on_current_change, pointer_for(obj))
end

#on_input_change(obj = nil, &block) ⇒ Boolean

Sets an input change handler callback function. This is called when a digital input on the PhidgetStepper board has changed.

As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.

Examples:

st.on_input_change do |device, input, state, obj|
  print "Digital Input  #{input.index}, changed to #{state}\n"
end

Parameters:

  • obj (String) (defaults to: nil)

    Object to pass to the callback function. This is optional.

  • Block (Proc)

    When the callback is executed, the device and object are yielded to this block.

Returns:

  • (Boolean)

    returns true or raises an error



37
38
39
40
41
42
43
# File 'lib/phidgets-ffi/stepper.rb', line 37

def on_input_change(obj=nil, &block)
  @on_input_change_obj = obj
  @on_input_change = Proc.new { |device, obj_ptr, index, state|
    yield self, @inputs[index], (state == 0 ? false : true), object_for(obj_ptr)
  }
  Klass.set_OnInputChange_Handler(@handle, @on_input_change, pointer_for(obj))
end

#on_position_change(obj = nil, &block) ⇒ Boolean

Sets a position change handler callback function. This is called when the stepper position changes.

As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.

Examples:

st.on_position_change do |device, stepper, position, obj|
  puts "Stepper #{stepper.index}'s position has changed to #{position}"
end

Parameters:

  • obj (String) (defaults to: nil)

    Object to pass to the callback function. This is optional.

  • Block (Proc)

    When the callback is executed, the device and object are yielded to this block.

Returns:

  • (Boolean)

    returns true or raises an error



73
74
75
76
77
78
79
# File 'lib/phidgets-ffi/stepper.rb', line 73

def on_position_change(obj=nil, &block)
  @on_position_change_obj = obj
  @on_position_change = Proc.new { |device, obj_ptr, index, position|
    yield self, @steppers[index], position, object_for(obj_ptr)
  }
  Klass.set_OnPositionChange_Handler(@handle, @on_position_change, pointer_for(obj))
end

#on_velocity_change(obj = nil, &block) ⇒ Boolean

Sets a velocity change handler callback function. This is called when a stepper velocity changes.

As this runs in it’s own thread, be sure that all errors are properly handled or the thread will halt and not fire any more.

Examples:

st.on_velocity_change do |device, stepper, velocity, obj|
  puts "Stepper #{stepper.index}'s velocity has changed to #{velocity}"
end

Parameters:

  • obj (String) (defaults to: nil)

    Object to pass to the callback function. This is optional.

  • Block (Proc)

    When the callback is executed, the device and object are yielded to this block.

Returns:

  • (Boolean)

    returns true or raises an error



55
56
57
58
59
60
61
# File 'lib/phidgets-ffi/stepper.rb', line 55

def on_velocity_change(obj=nil, &block)
  @on_velocity_change_obj = obj
  @on_velocity_change = Proc.new { |device, obj_ptr, index, velocity|
    yield self, @steppers[index], velocity, object_for(obj_ptr)
  }
  Klass.set_OnVelocityChange_Handler(@handle, @on_velocity_change, pointer_for(obj))
end