Class: Phidgets::Encoder
- Defined in:
- lib/phidgets/encoder.rb,
ext/phidgets/phidgets_encoder.c
Constant Summary collapse
- IO_MODE_PUSH_PULL =
INT2NUM(ENCODER_IO_MODE_PUSH_PULL)
- IO_MODE_LINE_DRIVER_2K2 =
INT2NUM(ENCODER_IO_MODE_LINE_DRIVER_2K2)
- IO_MODE_LINE_DRIVER_10K =
INT2NUM(ENCODER_IO_MODE_LINE_DRIVER_10K)
- IO_MODE_OPEN_COLLECTOR_2K2 =
INT2NUM(ENCODER_IO_MODE_OPEN_COLLECTOR_2K2)
- IO_MODE_OPEN_COLLECTOR_10K =
INT2NUM(ENCODER_IO_MODE_OPEN_COLLECTOR_10K)
Instance Method Summary collapse
-
#getDataInterval ⇒ Object
(also: #data_interval)
The DataInterval is the time that must elapse before the channel will fire another PositionChange event.
-
#getEnabled ⇒ Boolean
(also: #enabled?)
The enabled state of the encoder.
-
#getIndexPosition ⇒ Object
(also: #index_position)
The most recent position of the index channel calculated by the Phidgets library.
-
#getIOMode ⇒ Object
(also: #io_mode)
The encoder interface mode.
-
#getMaxDataInterval ⇒ Object
(also: #max_data_interval)
The maximum value that DataInterval can be set to.
-
#getMaxPositionChangeTrigger ⇒ Object
(also: #max_position_change_trigger)
The maximum value that PositionChangeTrigger can be set to.
-
#getMinDataInterval ⇒ Object
(also: #min_data_interval)
The minimum value that DataInterval can be set to.
-
#getMinPositionChangeTrigger ⇒ Object
(also: #min_position_change_trigger)
The minimum value that PositionChangeTrigger can be set to.
-
#getPosition ⇒ Object
(also: #position)
The most recent position value calculated by the Phidgets library.
-
#getPositionChangeTrigger ⇒ Object
(also: #position_change_trigger)
The channel will not issue a PositionChange event until the position value has changed by the amount specified by the PositionChangeTrigger.
-
#new ⇒ Object
constructor
Creates a Phidget Encoder object.
-
#setDataInterval(interval) ⇒ Object
(also: #data_interval=)
The DataInterval is the time that must elapse before the channel will fire another PositionChange event.
-
#setEnabled(state) ⇒ Object
(also: #enabled=)
The enabled state of the encoder.
-
#setIOMode(mode) ⇒ Object
(also: #io_mode=)
The encoder interface mode.
-
#setOnPositionChangeHandler(cb_proc = nil, &cb_block) ⇒ Object
(also: #on_position_change)
call-seq: setOnPositionChangeHandler(proc=nil, &block).
-
#setPosition(position) ⇒ Object
(also: #position=)
The most recent position value calculated by the Phidgets library.
-
#setPositionChangeTrigger(trigger) ⇒ Object
(also: #position_change_trigger=)
The channel will not issue a PositionChange event until the position value has changed by the amount specified by the PositionChangeTrigger.
Methods inherited from Common
#close, #getAttached, #getChannel, #getChannelClass, #getChannelClassName, #getChannelName, #getChannelSubclass, #getDeviceChannelCount, #getDeviceClass, #getDeviceClassName, #getDeviceID, #getDeviceLabel, #getDeviceName, #getDeviceSKU, #getDeviceSerialNumber, #getDeviceVersion, #getHubPort, #getHubPortCount, #getIsChannel, #getIsHubPortDevice, #getIsLocal, #getIsRemote, #getServerHostname, #getServerName, #getServerPeerName, #getServerUniqueName, #open, #openWaitForAttachment, #setChannel, #setDeviceLabel, #setDeviceSerialNumber, #setHubPort, #setIsHubPortDevice, #setIsLocal, #setIsRemote, #setOnAttachHandler, #setOnDetachHandler, #setOnErrorHandler, #setOnPropertyChangeHandler, #setServerName, #writeDeviceLabel
Constructor Details
#new ⇒ Object
Creates a Phidget Encoder object.
7 8 9 10 11 |
# File 'ext/phidgets/phidgets_encoder.c', line 7
VALUE ph_encoder_init(VALUE self) {
ph_data_t *ph = get_ph_data(self);
ph_raise(PhidgetEncoder_create((PhidgetEncoderHandle *)(&(ph->handle))));
return self;
}
|
Instance Method Details
#getDataInterval ⇒ Object Also known as: data_interval
The DataInterval is the time that must elapse before the channel will fire another PositionChange event. The data interval is bounded by MinDataInterval and MaxDataInterval. The timing between PositionChange events can also affected by the PositionChangeTrigger.
22 23 24 |
# File 'ext/phidgets/phidgets_encoder.c', line 22
VALUE ph_encoder_get_data_interval(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetEncoder_getDataInterval);
}
|
#getEnabled ⇒ Boolean Also known as: enabled?
The enabled state of the encoder.
13 14 15 |
# File 'ext/phidgets/phidgets_encoder.c', line 13
VALUE ph_encoder_get_enabled(VALUE self) {
return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetEncoder_getEnabled);
}
|
#getIndexPosition ⇒ Object Also known as: index_position
The most recent position of the index channel calculated by the Phidgets library. The index channel will usually pulse once per rotation. Setting the encoder position will move the index position the same amount so their relative position stays the same. Index position is tracked locally as the last position at which the index was triggered. Setting position will only affect the local copy of the index position value. This means that index positions seen by multiple network applications may not agree.
39 40 41 |
# File 'ext/phidgets/phidgets_encoder.c', line 39
VALUE ph_encoder_get_index_position(VALUE self) {
return ph_get_int64(get_ph_handle(self), (phidget_get_int64_func)PhidgetEncoder_getIndexPosition);
}
|
#getIOMode ⇒ Object Also known as: io_mode
The encoder interface mode. Match the mode to the type of encoder you have attached. It is recommended to only change this when the encoder disabled in order to avoid unexpected results.
43 44 45 |
# File 'ext/phidgets/phidgets_encoder.c', line 43
VALUE ph_encoder_get_io_mode(VALUE self) {
return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetEncoder_getIOMode);
}
|
#getMaxDataInterval ⇒ Object Also known as: max_data_interval
The maximum value that DataInterval can be set to.
35 36 37 |
# File 'ext/phidgets/phidgets_encoder.c', line 35
VALUE ph_encoder_get_max_data_interval(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetEncoder_getMaxDataInterval);
}
|
#getMaxPositionChangeTrigger ⇒ Object Also known as: max_position_change_trigger
The maximum value that PositionChangeTrigger can be set to.
74 75 76 |
# File 'ext/phidgets/phidgets_encoder.c', line 74
VALUE ph_encoder_get_max_position_change_trigger(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetEncoder_getMaxPositionChangeTrigger);
}
|
#getMinDataInterval ⇒ Object Also known as: min_data_interval
The minimum value that DataInterval can be set to.
31 32 33 |
# File 'ext/phidgets/phidgets_encoder.c', line 31
VALUE ph_encoder_get_min_data_interval(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetEncoder_getMinDataInterval);
}
|
#getMinPositionChangeTrigger ⇒ Object Also known as: min_position_change_trigger
The minimum value that PositionChangeTrigger can be set to.
70 71 72 |
# File 'ext/phidgets/phidgets_encoder.c', line 70
VALUE ph_encoder_get_min_position_change_trigger(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetEncoder_getMinPositionChangeTrigger);
}
|
#getPosition ⇒ Object Also known as: position
The most recent position value calculated by the Phidgets library. Position counts quadrature edges within a quadrature cycle. This means there are four counts per full quadrature cycle. Position is tracked locally as the total position change from the time the channel is opened. Setting position will only affect the local copy of the position value. This means that positions seen by multiple network applications may not agree.
52 53 54 |
# File 'ext/phidgets/phidgets_encoder.c', line 52
VALUE ph_encoder_get_position(VALUE self) {
return ph_get_int64(get_ph_handle(self), (phidget_get_int64_func)PhidgetEncoder_getPosition);
}
|
#getPositionChangeTrigger ⇒ Object Also known as: position_change_trigger
The channel will not issue a PositionChange event until the position value has changed by the amount specified by the PositionChangeTrigger. Setting the PositionChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
61 62 63 |
# File 'ext/phidgets/phidgets_encoder.c', line 61
VALUE ph_encoder_get_position_change_trigger(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetEncoder_getPositionChangeTrigger);
}
|
#setDataInterval(interval) ⇒ Object Also known as: data_interval=
The DataInterval is the time that must elapse before the channel will fire another PositionChange event. The data interval is bounded by MinDataInterval and MaxDataInterval. The timing between PositionChange events can also affected by the PositionChangeTrigger.
26 27 28 29 |
# File 'ext/phidgets/phidgets_encoder.c', line 26
VALUE ph_encoder_set_data_interval(VALUE self, VALUE interval) {
ph_raise(PhidgetEncoder_setDataInterval((PhidgetEncoderHandle)get_ph_handle(self), NUM2UINT(interval)));
return Qnil;
}
|
#setEnabled(state) ⇒ Object Also known as: enabled=
The enabled state of the encoder.
17 18 19 20 |
# File 'ext/phidgets/phidgets_encoder.c', line 17
VALUE ph_encoder_set_enabled(VALUE self, VALUE state) {
ph_raise(PhidgetEncoder_setEnabled((PhidgetEncoderHandle)get_ph_handle(self), TYPE(state) == T_TRUE ? PTRUE : PFALSE));
return Qnil;
}
|
#setIOMode(mode) ⇒ Object Also known as: io_mode=
The encoder interface mode. Match the mode to the type of encoder you have attached. It is recommended to only change this when the encoder disabled in order to avoid unexpected results.
47 48 49 50 |
# File 'ext/phidgets/phidgets_encoder.c', line 47
VALUE ph_encoder_set_io_mode(VALUE self, VALUE mode) {
ph_raise(PhidgetEncoder_setIOMode((PhidgetEncoderHandle)get_ph_handle(self), NUM2INT(mode)));
return Qnil;
}
|
#setOnPositionChangeHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_position_change
call-seq:
setOnPositionChangeHandler(proc=nil, &block)
Sets an encoder position change handler. This is called when an encoder position changes.
11 12 13 14 15 |
# File 'lib/phidgets/encoder.rb', line 11 def setOnPositionChangeHandler(cb_proc = nil, &cb_block) @on_position_change_thread.kill if defined? @on_position_change_thread and @on_position_change_thread.alive? callback = cb_proc || cb_block @on_position_change_thread = Thread.new {ext_setOnPositionChangeHandler(callback)} end |
#setPosition(position) ⇒ Object Also known as: position=
The most recent position value calculated by the Phidgets library. Position counts quadrature edges within a quadrature cycle. This means there are four counts per full quadrature cycle. Position is tracked locally as the total position change from the time the channel is opened. Setting position will only affect the local copy of the position value. This means that positions seen by multiple network applications may not agree.
56 57 58 59 |
# File 'ext/phidgets/phidgets_encoder.c', line 56
VALUE ph_encoder_set_position(VALUE self, VALUE position) {
ph_raise(PhidgetEncoder_setPosition((PhidgetEncoderHandle)get_ph_handle(self), NUM2LL(position)));
return Qnil;
}
|
#setPositionChangeTrigger(trigger) ⇒ Object Also known as: position_change_trigger=
The channel will not issue a PositionChange event until the position value has changed by the amount specified by the PositionChangeTrigger. Setting the PositionChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
65 66 67 68 |
# File 'ext/phidgets/phidgets_encoder.c', line 65
VALUE ph_encoder_set_position_change_trigger(VALUE self, VALUE trigger) {
ph_raise(PhidgetEncoder_setPositionChangeTrigger((PhidgetEncoderHandle)get_ph_handle(self), NUM2UINT(trigger)));
return Qnil;
}
|