Class: Phidgets::DistanceSensor
- Defined in:
- lib/phidgets/distance_sensor.rb,
ext/phidgets/phidgets_distance_sensor.c
Instance Method Summary collapse
-
#getDataInterval ⇒ Object
(also: #data_interval)
The DataInterval is the time that must elapse before the channel will fire another event.
-
#getDistance ⇒ Object
(also: #distance)
The most recent distance value that the channel has reported.
-
#getDistanceChangeTrigger ⇒ Object
(also: #distance_change_trigger)
The channel will not issue an event until the distance value has changed by the amount specified by the DistanceChangeTrigger.
-
#getMaxDataInterval ⇒ Object
(also: #max_data_interval)
The maximum value that DataInterval can be set to.
-
#getMaxDistance ⇒ Object
(also: #max_distance)
The maximum distance that a event will report.
-
#getMaxDistanceChangeTrigger ⇒ Object
(also: #max_distance_change_trigger)
The maximum value that DistanceChangeTrigger can be set to.
-
#getMinDataInterval ⇒ Object
(also: #min_data_interval)
The minimum value that DataInterval can be set to.
-
#getMinDistance ⇒ Object
(also: #min_distance)
The minimum distance that a event will report.
-
#getMinDistanceChangeTrigger ⇒ Object
(also: #min_distance_change_trigger)
The minimum value that DistanceChangeTrigger can be set to.
-
#getSonarQuietMode ⇒ Boolean
(also: #sonar_quiet_mode)
When set to true, the device will operate more quietly.
-
#getSonarReflections ⇒ Object
(also: #sonar_reflections)
The most recent reflection values that the channel has reported.
-
#new ⇒ Object
constructor
Creates a Phidget DistanceSensor object.
-
#setDataInterval(interval) ⇒ Object
(also: #data_interval=)
The DataInterval is the time that must elapse before the channel will fire another event.
-
#setDistanceChangeTrigger(change_trigger) ⇒ Object
(also: #distance_change_trigger=)
The channel will not issue an event until the distance value has changed by the amount specified by the DistanceChangeTrigger.
-
#setOnDistanceChangeHandler(cb_proc = nil, &cb_block) ⇒ Object
(also: #on_distance_change)
call-seq: setOnDistanceChangeHandler(proc=nil, &block).
-
#setOnSonarReflectionsUpdateHandler(cb_proc = nil, &cb_block) ⇒ Object
(also: #on_sonar_reflections_update)
call-seq: setOnSonarReflectionsUpdateHandler(proc=nil, &block).
-
#setSonarQuietMode(quiet_mode) ⇒ Object
(also: #sonar_quiet_mode=)
When set to true, the device will operate more quietly.
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 DistanceSensor object.
8 9 10 11 12 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 8
VALUE ph_distance_init(VALUE self) {
ph_data_t *ph = get_ph_data(self);
ph_raise(PhidgetDistanceSensor_create((PhidgetDistanceSensorHandle *)(&(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 event. The data interval is bounded by MinDataInterval and MaxDataInterval. The timing between events can also affected by the change trigger.
14 15 16 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 14
VALUE ph_distance_get_data_interval(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDistanceSensor_getDataInterval);
}
|
#getDistance ⇒ Object Also known as: distance
The most recent distance value that the channel has reported. This value will always be between MinDistance and MaxDistance.
31 32 33 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 31
VALUE ph_distance_get_distance(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDistanceSensor_getDistance);
}
|
#getDistanceChangeTrigger ⇒ Object Also known as: distance_change_trigger
The channel will not issue an event until the distance value has changed by the amount specified by the DistanceChangeTrigger. Setting the DistanceChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
43 44 45 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 43
VALUE ph_distance_get_distance_change_trigger(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDistanceSensor_getDistanceChangeTrigger);
}
|
#getMaxDataInterval ⇒ Object Also known as: max_data_interval
The maximum value that DataInterval can be set to.
27 28 29 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 27
VALUE ph_distance_get_max_data_interval(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDistanceSensor_getMaxDataInterval);
}
|
#getMaxDistance ⇒ Object Also known as: max_distance
The maximum distance that a event will report.
39 40 41 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 39
VALUE ph_distance_get_max_distance(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDistanceSensor_getMaxDistance);
}
|
#getMaxDistanceChangeTrigger ⇒ Object Also known as: max_distance_change_trigger
The maximum value that DistanceChangeTrigger can be set to.
56 57 58 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 56
VALUE ph_distance_get_max_distance_change_trigger(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDistanceSensor_getMaxDistanceChangeTrigger);
}
|
#getMinDataInterval ⇒ Object Also known as: min_data_interval
The minimum value that DataInterval can be set to.
23 24 25 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 23
VALUE ph_distance_get_min_data_interval(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDistanceSensor_getMinDataInterval);
}
|
#getMinDistance ⇒ Object Also known as: min_distance
The minimum distance that a event will report.
35 36 37 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 35
VALUE ph_distance_get_min_distance(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDistanceSensor_getMinDistance);
}
|
#getMinDistanceChangeTrigger ⇒ Object Also known as: min_distance_change_trigger
The minimum value that DistanceChangeTrigger can be set to.
52 53 54 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 52
VALUE ph_distance_get_min_distance_change_trigger(VALUE self) {
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDistanceSensor_getMinDistanceChangeTrigger);
}
|
#getSonarQuietMode ⇒ Boolean Also known as: sonar_quiet_mode
When set to true, the device will operate more quietly. The measurable range is reduced when operating in quiet mode.
60 61 62 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 60
VALUE ph_distance_get_sonar_quiet_mode(VALUE self) {
return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetDistanceSensor_getSonarQuietMode);
}
|
#getSonarReflections ⇒ Object Also known as: sonar_reflections
The most recent reflection values that the channel has reported. The distance values will always be between MinDistance and MaxDistance. The closest reflection will be placed at index 0 of the distances array, and the furthest reflection at index 7 The amplitude values are relative amplitudes of the reflections that are normalized to an arbitrary scale.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 69
VALUE ph_distance_get_sonar_reflections(VALUE self) {
PhidgetDistanceSensorHandle handle = (PhidgetDistanceSensorHandle)get_ph_handle(self);
uint32_t distances[8];
uint32_t amplitudes[8];
uint32_t count, i;
VALUE rb_reflections = rb_hash_new();
VALUE rb_distances = rb_ary_new();
VALUE rb_amplitudes = rb_ary_new();
ph_raise(PhidgetDistanceSensor_getSonarReflections(handle, &distances, &litudes, &count));
for(i=0; i<count; i++) {
rb_ary_push(rb_distances, UINT2NUM(distances[i]));
rb_ary_push(rb_amplitudes, UINT2NUM(amplitudes[i]));
}
rb_hash_aset(rb_reflections, rb_str_new2("distances"), rb_distances);
rb_hash_aset(rb_reflections, rb_str_new2("amplitudes"), rb_amplitudes);
return rb_reflections;
}
|
#setDataInterval(interval) ⇒ Object Also known as: data_interval=
The DataInterval is the time that must elapse before the channel will fire another event. The data interval is bounded by MinDataInterval and MaxDataInterval. The timing between events can also affected by the change trigger.
18 19 20 21 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 18
VALUE ph_distance_set_data_interval(VALUE self, VALUE interval) {
ph_raise(PhidgetDistanceSensor_setDataInterval((PhidgetDistanceSensorHandle)get_ph_handle(self), NUM2UINT(interval)));
return Qnil;
}
|
#setDistanceChangeTrigger(change_trigger) ⇒ Object Also known as: distance_change_trigger=
The channel will not issue an event until the distance value has changed by the amount specified by the DistanceChangeTrigger. Setting the DistanceChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
47 48 49 50 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 47
VALUE ph_distance_set_distance_change_trigger(VALUE self, VALUE trigger) {
ph_raise(PhidgetDistanceSensor_setDistanceChangeTrigger((PhidgetDistanceSensorHandle)get_ph_handle(self), NUM2UINT(trigger)));
return Qnil;
}
|
#setOnDistanceChangeHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_distance_change
call-seq:
setOnDistanceChangeHandler(proc=nil, &block)
Assigns a handler that will be called when the DistanceChange event occurs.
11 12 13 14 15 |
# File 'lib/phidgets/distance_sensor.rb', line 11 def setOnDistanceChangeHandler(cb_proc = nil, &cb_block) @on_distance_change_thread.kill if defined? @on_distance_change_thread and @on_distance_change_thread.alive? callback = cb_proc || cb_block @on_distance_change_thread = Thread.new {ext_setOnDistanceChangeHandler(callback)} end |
#setOnSonarReflectionsUpdateHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_sonar_reflections_update
call-seq:
setOnSonarReflectionsUpdateHandler(proc=nil, &block)
Assigns a handler that will be called when the SonarReflectionsUpdate event occurs.
22 23 24 25 26 |
# File 'lib/phidgets/distance_sensor.rb', line 22 def setOnSonarReflectionsUpdateHandler(cb_proc = nil, &cb_block) @on_reflections_update_thread.kill if defined? @on_reflections_update_thread and @on_reflections_update_thread.alive? callback = cb_proc || cb_block @on_reflections_update_thread = Thread.new {ext_setOnSonarReflectionsUpdateHandler(callback)} end |
#setSonarQuietMode(quiet_mode) ⇒ Object Also known as: sonar_quiet_mode=
When set to true, the device will operate more quietly. The measurable range is reduced when operating in quiet mode.
64 65 66 67 |
# File 'ext/phidgets/phidgets_distance_sensor.c', line 64
VALUE ph_distance_set_sonar_quiet_mode(VALUE self, VALUE mode) {
ph_raise(PhidgetDistanceSensor_setSonarQuietMode((PhidgetDistanceSensorHandle)get_ph_handle(self), TYPE(mode) == T_TRUE ? PTRUE : PFALSE));
return Qnil;
}
|