Class: Phidgets::Magnetometer

Inherits:
Common
  • Object
show all
Defined in:
lib/phidgets/magnetometer.rb,
ext/phidgets/phidgets_magnetometer.c

Instance Method Summary collapse

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

#newObject

Creates a Phidget Magnetometer object.



7
8
9
10
11
# File 'ext/phidgets/phidgets_magnetometer.c', line 7

VALUE ph_magnetometer_init(VALUE self) {
  ph_data_t *ph = get_ph_data(self);
  ph_raise(PhidgetMagnetometer_create((PhidgetMagnetometerHandle *)(&(ph->handle))));
  return self;
}

Instance Method Details

#getAxisCountObject Also known as: axis_count

The number of axes the channel can measure field strength on. See your device’s User Guide for more information about the number of axes and their orientation.



13
14
15
# File 'ext/phidgets/phidgets_magnetometer.c', line 13

VALUE ph_magnetometer_get_axis_count(VALUE self) {
  return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetMagnetometer_getAxisCount);
}

#getDataIntervalObject Also known as: data_interval

The DataInterval is the time that must elapse before the channel will fire another IlluminanceChange event. The data interval is bounded by MinDataInterval and MaxDataInterval. The timing between IlluminanceChange events can also affected by the IlluminanceChangeTrigger.



23
24
25
# File 'ext/phidgets/phidgets_magnetometer.c', line 23

VALUE ph_magnetometer_get_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetMagnetometer_getDataInterval);
}

#getMagneticFieldObject Also known as: magnetic_field

The most recent field strength value that the channel has reported. This value will always be between MinMagneticField and MaxMagneticField.



40
41
42
43
44
# File 'ext/phidgets/phidgets_magnetometer.c', line 40

VALUE ph_magnetometer_get_magnetic_field(VALUE self) {
  double mag_field[3];
  ph_raise(PhidgetMagnetometer_getMagneticField((PhidgetMagnetometerHandle)get_ph_handle(self), &mag_field));
  return rb_ary_new3(3, DBL2NUM(mag_field[0]), DBL2NUM(mag_field[1]), DBL2NUM(mag_field[2]));
}

#getMagneticFieldChangeTriggerObject Also known as: magnetic_field_change_trigger

The channel will not issue a MagneticFieldChange event until the field strength value has changed by the amount specified by the MagneticFieldChangeTrigger. Setting the MagneticFieldChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.



58
59
60
# File 'ext/phidgets/phidgets_magnetometer.c', line 58

VALUE ph_magnetometer_get_magnetic_field_change_trigger(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMagnetometer_getMagneticFieldChangeTrigger);
}

#getMaxDataIntervalObject Also known as: max_data_interval

The maximum value that DataInterval can be set to.



36
37
38
# File 'ext/phidgets/phidgets_magnetometer.c', line 36

VALUE ph_magnetometer_get_max_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetMagnetometer_getMaxDataInterval);
}

#getMaxMagneticFieldObject Also known as: max_magnetic_field

The maximum value that the MagneticFieldChange event will report.



52
53
54
55
56
# File 'ext/phidgets/phidgets_magnetometer.c', line 52

VALUE ph_magnetometer_get_max_magnetic_field(VALUE self) {
  double mag_field[3];
  ph_raise(PhidgetMagnetometer_getMaxMagneticField((PhidgetMagnetometerHandle)get_ph_handle(self), &mag_field));
  return rb_ary_new3(3, DBL2NUM(mag_field[0]), DBL2NUM(mag_field[1]), DBL2NUM(mag_field[2]));
}

#getMaxMagneticFieldChangeTriggerObject Also known as: max_magnetic_field_change_trigger

The maximum value that MagneticFieldChangeTrigger can be set to.



71
72
73
# File 'ext/phidgets/phidgets_magnetometer.c', line 71

VALUE ph_magnetometer_get_max_magnetic_field_change_trigger(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMagnetometer_getMaxMagneticFieldChangeTrigger);
}

#getMinDataIntervalObject Also known as: min_data_interval

The minimum value that DataInterval can be set to.



32
33
34
# File 'ext/phidgets/phidgets_magnetometer.c', line 32

VALUE ph_magnetometer_get_min_data_interval(VALUE self) {
  return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetMagnetometer_getMinDataInterval);
}

#getMinMagneticFieldObject Also known as: min_magnetic_field

The minimum value that the MagneticFieldChange event will report.



46
47
48
49
50
# File 'ext/phidgets/phidgets_magnetometer.c', line 46

VALUE ph_magnetometer_get_min_magnetic_field(VALUE self) {
  double mag_field[3];
  ph_raise(PhidgetMagnetometer_getMinMagneticField((PhidgetMagnetometerHandle)get_ph_handle(self), &mag_field));
  return rb_ary_new3(3, DBL2NUM(mag_field[0]), DBL2NUM(mag_field[1]), DBL2NUM(mag_field[2]));
}

#getMinMagneticFieldChangeTriggerObject Also known as: min_magnetic_field_change_trigger

The minimum value that MagneticFieldChangeTrigger can be set to.



67
68
69
# File 'ext/phidgets/phidgets_magnetometer.c', line 67

VALUE ph_magnetometer_get_min_magnetic_field_change_trigger(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMagnetometer_getMinMagneticFieldChangeTrigger);
}

#getTimestampObject Also known as: timestamp

The most recent timestamp value that the channel has reported. This is an extremely accurate time measurement streamed from the device. If your application requires a time measurement, you should use this value over a local software timestamp.



85
86
87
# File 'ext/phidgets/phidgets_magnetometer.c', line 85

VALUE ph_magnetometer_get_timestamp(VALUE self) {
  return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetMagnetometer_getTimestamp);
}

#resetCorrectionParametersObject Also known as: reset_correction_parameters

Resets the CompassCorrectionParameters to their default values. Due to physical location, hard and soft iron offsets, and even bias errors, your device should be calibrated. We have created a calibration program that will provide you with the CompassCorrectionParameters for your specific situation. See your device’s User Guide for more information.



75
76
77
78
# File 'ext/phidgets/phidgets_magnetometer.c', line 75

VALUE ph_magnetometer_reset_correction_parameters(VALUE self) {
  ph_raise(PhidgetMagnetometer_resetCorrectionParameters((PhidgetMagnetometerHandle)get_ph_handle(self)));
  return Qnil;
}

#saveCorrectionParametersObject Also known as: save_correction_parameters

Saves the CalibrationParameters. Due to physical location, hard and soft iron offsets, and even bias errors, your device should be calibrated. We have created a calibration program that will provide you with the CompassCorrectionParameters for your specific situation. See your device’s User Guide for more information.



80
81
82
83
# File 'ext/phidgets/phidgets_magnetometer.c', line 80

VALUE ph_magnetometer_save_correction_parameters(VALUE self) {
  ph_raise(PhidgetMagnetometer_saveCorrectionParameters((PhidgetMagnetometerHandle)get_ph_handle(self)));
  return Qnil;
}

#setCorrectionParameters(mag_field, offset0, offset1, offset2, gain0, gain1, gain2, T0, T1, T2, T3, T4, T5) ⇒ Object Also known as: set_correction_parameters

Calibrate your device for the environment it will be used in. Due to physical location, hard and soft iron offsets, and even bias errors, your device should be calibrated. We have created a calibration program that will provide you with the CompassCorrectionParameters for your specific situation. See your device’s User Guide for more information.



17
18
19
20
21
# File 'ext/phidgets/phidgets_magnetometer.c', line 17

VALUE ph_magnetometer_set_correction_parameters(VALUE self, VALUE mag_field, VALUE offset0, VALUE offset1, VALUE offset2, VALUE gain0, VALUE gain1, VALUE gain2, VALUE T0, VALUE T1, VALUE T2, VALUE T3, VALUE T4, VALUE T5) {
  ph_raise(PhidgetMagnetometer_setCorrectionParameters((PhidgetMagnetometerHandle)get_ph_handle(self), NUM2DBL(mag_field), NUM2DBL(offset0), NUM2DBL(offset1), NUM2DBL(offset2),
      NUM2DBL(gain0), NUM2DBL(gain1), NUM2DBL(gain2), NUM2DBL(T0), NUM2DBL(T1), NUM2DBL(T2), NUM2DBL(T3), NUM2DBL(T4), NUM2DBL(T5)));
  return Qnil;
}

#setDataInterval(interval) ⇒ Object Also known as: data_interval=

The DataInterval is the time that must elapse before the channel will fire another IlluminanceChange event. The data interval is bounded by MinDataInterval and MaxDataInterval. The timing between IlluminanceChange events can also affected by the IlluminanceChangeTrigger.



27
28
29
30
# File 'ext/phidgets/phidgets_magnetometer.c', line 27

VALUE ph_magnetometer_set_data_interval(VALUE self, VALUE interval) {
  ph_raise(PhidgetMagnetometer_setDataInterval((PhidgetMagnetometerHandle)get_ph_handle(self), NUM2UINT(interval)));
  return Qnil;
}

#setMagneticFieldChangeTrigger(change_trigger) ⇒ Object Also known as: magnetic_field_change_trigger=

The channel will not issue a MagneticFieldChange event until the field strength value has changed by the amount specified by the MagneticFieldChangeTrigger. Setting the MagneticFieldChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.



62
63
64
65
# File 'ext/phidgets/phidgets_magnetometer.c', line 62

VALUE ph_magnetometer_set_magnetic_field_change_trigger(VALUE self, VALUE change_trigger) {
  ph_raise(PhidgetMagnetometer_setMagneticFieldChangeTrigger((PhidgetMagnetometerHandle)get_ph_handle(self), NUM2DBL(change_trigger)));
  return Qnil;
}

#setOnMagneticFieldChangeHandler(cb_proc = nil, &cb_block) ⇒ Object Also known as: on_magnetic_field_change

call-seq:

setOnMagneticFieldChangeHandler(proc=nil, &block)

Assigns a handler that will be called when the MagneticFieldChange event occurs.



11
12
13
14
15
# File 'lib/phidgets/magnetometer.rb', line 11

def setOnMagneticFieldChangeHandler(cb_proc = nil, &cb_block)
  @on_magnetic_field_change_thread.kill if defined? @on_magnetic_field_change_thread and @on_magnetic_field_change_thread.alive?
  callback = cb_proc || cb_block
  @on_magnetic_field_change_thread = Thread.new {ext_setOnMagneticFieldChangeHandler(callback)}
end