phidgets 0.1.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.txt +3 -0
- data/README.rdoc +32 -43
- data/Rakefile +4 -2
- data/bin/phidget +18 -72
- data/ext/phidgets/extconf.rb +5 -8
- data/ext/phidgets/phidgets.c +708 -173
- data/ext/phidgets/phidgets.h +54 -35
- data/ext/phidgets/phidgets_accelerometer.c +193 -109
- data/ext/phidgets/phidgets_bldc_motor.c +529 -0
- data/ext/phidgets/phidgets_capacitive_touch.c +302 -0
- data/ext/phidgets/phidgets_common.c +570 -315
- data/ext/phidgets/phidgets_current_input.c +229 -0
- data/ext/phidgets/phidgets_dc_motor.c +562 -0
- data/ext/phidgets/phidgets_dictionary.c +154 -213
- data/ext/phidgets/phidgets_digital_input.c +127 -0
- data/ext/phidgets/phidgets_digital_output.c +288 -0
- data/ext/phidgets/phidgets_distance_sensor.c +295 -0
- data/ext/phidgets/phidgets_encoder.c +211 -192
- data/ext/phidgets/phidgets_frequency_counter.c +310 -177
- data/ext/phidgets/phidgets_gps.c +226 -164
- data/ext/phidgets/phidgets_gyroscope.c +195 -0
- data/ext/phidgets/phidgets_hub.c +39 -0
- data/ext/phidgets/phidgets_humidity_sensor.c +200 -0
- data/ext/phidgets/phidgets_ir.c +211 -171
- data/ext/phidgets/phidgets_lcd.c +512 -0
- data/ext/phidgets/phidgets_light_sensor.c +200 -0
- data/ext/phidgets/phidgets_log.c +263 -0
- data/ext/phidgets/phidgets_magnetometer.c +279 -0
- data/ext/phidgets/phidgets_manager.c +86 -297
- data/ext/phidgets/phidgets_motor_position_controller.c +787 -0
- data/ext/phidgets/phidgets_phsensor.c +200 -152
- data/ext/phidgets/phidgets_power_guard.c +144 -0
- data/ext/phidgets/phidgets_pressure_sensor.c +200 -0
- data/ext/phidgets/phidgets_rc_servo.c +672 -0
- data/ext/phidgets/phidgets_resistance_input.c +227 -0
- data/ext/phidgets/phidgets_rfid.c +107 -221
- data/ext/phidgets/phidgets_sound_sensor.c +284 -0
- data/ext/phidgets/phidgets_spatial.c +124 -318
- data/ext/phidgets/phidgets_stepper.c +457 -430
- data/ext/phidgets/phidgets_temp_sensor.c +223 -228
- data/ext/phidgets/phidgets_voltage_input.c +428 -0
- data/ext/phidgets/phidgets_voltage_output.c +167 -0
- data/ext/phidgets/phidgets_voltage_ratio_input.c +435 -0
- data/lib/phidgets.rb +21 -14
- data/lib/phidgets/accelerometer.rb +11 -15
- data/lib/phidgets/bldc_motor.rb +45 -0
- data/lib/phidgets/capacitive_touch.rb +33 -0
- data/lib/phidgets/common.rb +40 -69
- data/lib/phidgets/current_input.rb +21 -0
- data/lib/phidgets/dc_motor.rb +45 -0
- data/lib/phidgets/dictionary.rb +30 -39
- data/lib/phidgets/digital_input.rb +21 -0
- data/lib/phidgets/digital_output.rb +56 -0
- data/lib/phidgets/distance_sensor.rb +33 -0
- data/lib/phidgets/encoder.rb +1 -29
- data/lib/phidgets/frequency_counter.rb +23 -14
- data/lib/phidgets/gps.rb +34 -26
- data/lib/phidgets/gyroscope.rb +21 -0
- data/lib/phidgets/humidity_sensor.rb +21 -0
- data/lib/phidgets/ir.rb +34 -39
- data/lib/phidgets/light_sensor.rb +21 -0
- data/lib/phidgets/magnetometer.rb +21 -0
- data/lib/phidgets/manager.rb +18 -66
- data/lib/phidgets/motor_position_controller.rb +45 -0
- data/lib/phidgets/ph_sensor.rb +2 -6
- data/lib/phidgets/pressure_sensor.rb +21 -0
- data/lib/phidgets/rc_servo.rb +58 -0
- data/lib/phidgets/resistance_input.rb +21 -0
- data/lib/phidgets/rfid.rb +22 -38
- data/lib/phidgets/sound_sensor.rb +21 -0
- data/lib/phidgets/spatial.rb +11 -15
- data/lib/phidgets/stepper.rb +48 -50
- data/lib/phidgets/temperature_sensor.rb +11 -15
- data/lib/phidgets/version.rb +5 -0
- data/lib/phidgets/voltage_input.rb +34 -0
- data/lib/phidgets/voltage_output.rb +23 -0
- data/lib/phidgets/voltage_ratio_input.rb +34 -0
- data/phidgets.gemspec +3 -22
- data/test/test_accelerometer.rb +42 -23
- data/test/test_bldc_motor.rb +134 -0
- data/test/test_capacitive_touch.rb +82 -0
- data/test/test_common.rb +125 -108
- data/test/test_current_input.rb +62 -0
- data/test/test_dc_motor.rb +146 -0
- data/test/test_dictionary.rb +22 -54
- data/test/test_digital_input.rb +30 -0
- data/test/test_digital_output.rb +70 -0
- data/test/test_distance_sensor.rb +76 -0
- data/test/test_encoder.rb +45 -38
- data/test/test_frequency_counter.rb +71 -36
- data/test/test_gps.rb +29 -38
- data/test/test_gyroscope.rb +54 -0
- data/test/test_helper.rb +0 -1
- data/test/test_hub.rb +14 -0
- data/test/test_humidity_sensor.rb +58 -0
- data/test/test_ir.rb +34 -34
- data/test/test_lcd.rb +146 -0
- data/test/test_light_sensor.rb +58 -0
- data/test/test_magnetometer.rb +78 -0
- data/test/test_manager.rb +10 -79
- data/test/test_motor_control.rb +146 -108
- data/test/test_phidgets.rb +2 -14
- data/test/test_phsensor.rb +46 -34
- data/test/test_power_guard.rb +42 -0
- data/test/test_pressure_sensor.rb +58 -0
- data/test/test_rc_servo.rb +174 -0
- data/test/test_resistance_input.rb +66 -0
- data/test/test_rfid.rb +15 -54
- data/test/test_sound_sensor.rb +78 -0
- data/test/test_spatial.rb +19 -85
- data/test/test_stepper.rb +89 -98
- data/test/test_temp_sensor.rb +42 -47
- data/test/test_voltage_input.rb +102 -0
- data/test/test_voltage_output.rb +46 -0
- data/test/test_voltage_ratio_input.rb +102 -0
- metadata +72 -89
- data/ext/phidgets/phidgets_advanced_servo.c +0 -567
- data/ext/phidgets/phidgets_analog.c +0 -139
- data/ext/phidgets/phidgets_bridge.c +0 -263
- data/ext/phidgets/phidgets_interface_kit.c +0 -340
- data/ext/phidgets/phidgets_led.c +0 -178
- data/ext/phidgets/phidgets_motor_control.c +0 -642
- data/ext/phidgets/phidgets_servo.c +0 -276
- data/ext/phidgets/phidgets_text_lcd.c +0 -381
- data/ext/phidgets/phidgets_text_led.c +0 -107
- data/ext/phidgets/phidgets_weight_sensor.c +0 -113
- data/lib/phidgets/advanced_servo.rb +0 -49
- data/lib/phidgets/analog.rb +0 -8
- data/lib/phidgets/bridge.rb +0 -25
- data/lib/phidgets/interfacekit.rb +0 -49
- data/lib/phidgets/led.rb +0 -8
- data/lib/phidgets/motor_control.rb +0 -110
- data/lib/phidgets/servo.rb +0 -23
- data/lib/phidgets/text_lcd.rb +0 -8
- data/lib/phidgets/text_led.rb +0 -8
- data/lib/phidgets/weight_sensor.rb +0 -25
- data/test/test_advanced_servo.rb +0 -152
- data/test/test_analog.rb +0 -45
- data/test/test_bridge.rb +0 -77
- data/test/test_interfacekit.rb +0 -97
- data/test/test_led.rb +0 -55
- data/test/test_servo.rb +0 -67
- data/test/test_text_lcd.rb +0 -115
- data/test/test_text_led.rb +0 -35
- data/test/test_weight_sensor.rb +0 -32
@@ -1,22 +1,108 @@
|
|
1
1
|
|
2
2
|
#include "phidgets.h"
|
3
3
|
|
4
|
+
#define PH_CHANGE_CALLBACK 0
|
4
5
|
|
5
|
-
VALUE ph_phsensor_init(VALUE self);
|
6
|
-
VALUE ph_phsensor_get_ph(VALUE self);
|
7
|
-
VALUE ph_phsensor_get_ph_min(VALUE self);
|
8
|
-
VALUE ph_phsensor_get_ph_max(VALUE self);
|
9
|
-
VALUE ph_phsensor_get_ph_change_trigger(VALUE self);
|
10
|
-
VALUE ph_phsensor_set_ph_change_trigger(VALUE self, VALUE trigger);
|
11
|
-
VALUE ph_phsensor_get_potential(VALUE self);
|
12
|
-
VALUE ph_phsensor_get_potential_min(VALUE self);
|
13
|
-
VALUE ph_phsensor_get_potential_max(VALUE self);
|
14
|
-
VALUE ph_phsensor_set_temperature(VALUE self, VALUE temperature);
|
15
6
|
|
16
|
-
|
17
|
-
VALUE
|
18
|
-
|
19
|
-
|
7
|
+
|
8
|
+
VALUE ph_phsensor_init(VALUE self) {
|
9
|
+
ph_data_t *ph = get_ph_data(self);
|
10
|
+
ph_raise(PhidgetPHSensor_create((PhidgetPHSensorHandle *)(&(ph->handle))));
|
11
|
+
return self;
|
12
|
+
}
|
13
|
+
|
14
|
+
VALUE ph_phsensor_get_correction_temperature(VALUE self) {
|
15
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPHSensor_getCorrectionTemperature);
|
16
|
+
}
|
17
|
+
|
18
|
+
VALUE ph_phsensor_set_correction_temperature(VALUE self, VALUE temperature) {
|
19
|
+
ph_raise(PhidgetPHSensor_setCorrectionTemperature((PhidgetPHSensorHandle)get_ph_handle(self), NUM2DBL(temperature)));
|
20
|
+
return Qnil;
|
21
|
+
}
|
22
|
+
|
23
|
+
VALUE ph_phsensor_get_min_correction_temperature(VALUE self) {
|
24
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPHSensor_getMinCorrectionTemperature);
|
25
|
+
}
|
26
|
+
|
27
|
+
VALUE ph_phsensor_get_max_correction_temperature(VALUE self) {
|
28
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPHSensor_getMaxCorrectionTemperature);
|
29
|
+
}
|
30
|
+
|
31
|
+
VALUE ph_phsensor_get_data_interval(VALUE self) {
|
32
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetPHSensor_getDataInterval);
|
33
|
+
}
|
34
|
+
|
35
|
+
VALUE ph_phsensor_set_data_interval(VALUE self, VALUE interval) {
|
36
|
+
ph_raise(PhidgetPHSensor_setDataInterval((PhidgetPHSensorHandle)get_ph_handle(self), NUM2UINT(interval)));
|
37
|
+
return Qnil;
|
38
|
+
}
|
39
|
+
|
40
|
+
VALUE ph_phsensor_get_min_data_interval(VALUE self) {
|
41
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetPHSensor_getMinDataInterval);
|
42
|
+
}
|
43
|
+
|
44
|
+
VALUE ph_phsensor_get_max_data_interval(VALUE self) {
|
45
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetPHSensor_getMaxDataInterval);
|
46
|
+
}
|
47
|
+
|
48
|
+
VALUE ph_phsensor_get_ph(VALUE self) {
|
49
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPHSensor_getPH);
|
50
|
+
}
|
51
|
+
|
52
|
+
VALUE ph_phsensor_get_min_ph(VALUE self) {
|
53
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPHSensor_getMinPH);
|
54
|
+
}
|
55
|
+
|
56
|
+
VALUE ph_phsensor_get_max_ph(VALUE self) {
|
57
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPHSensor_getMaxPH);
|
58
|
+
}
|
59
|
+
|
60
|
+
VALUE ph_phsensor_get_ph_change_trigger(VALUE self) {
|
61
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPHSensor_getPHChangeTrigger);
|
62
|
+
}
|
63
|
+
|
64
|
+
VALUE ph_phsensor_set_ph_change_trigger(VALUE self, VALUE trigger) {
|
65
|
+
ph_raise(PhidgetPHSensor_setPHChangeTrigger((PhidgetPHSensorHandle)get_ph_handle(self), NUM2DBL(trigger)));
|
66
|
+
return Qnil;
|
67
|
+
}
|
68
|
+
|
69
|
+
VALUE ph_phsensor_get_min_ph_change_trigger(VALUE self) {
|
70
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPHSensor_getMinPHChangeTrigger);
|
71
|
+
}
|
72
|
+
|
73
|
+
VALUE ph_phsensor_get_max_ph_change_trigger(VALUE self) {
|
74
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPHSensor_getMaxPHChangeTrigger);
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
void CCONV ph_phsensor_on_ph_change(PhidgetPHSensorHandle phid, void *userPtr, double ph) {
|
79
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
80
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
81
|
+
callback_data->arg1 = DBL2NUM(ph);
|
82
|
+
callback_data->arg2 = Qnil;
|
83
|
+
callback_data->arg3 = Qnil;
|
84
|
+
callback_data->arg4 = Qnil;
|
85
|
+
sem_post(&callback_data->callback_called);
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
VALUE ph_phsensor_set_on_ph_change_handler(VALUE self, VALUE handler) {
|
90
|
+
ph_data_t *ph = get_ph_data(self);
|
91
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[PH_CHANGE_CALLBACK];
|
92
|
+
if( TYPE(handler) == T_NIL ) {
|
93
|
+
callback_data->callback = T_NIL;
|
94
|
+
callback_data->exit = true;
|
95
|
+
ph_raise(PhidgetPHSensor_setOnPHChangeHandler((PhidgetPHSensorHandle)ph->handle, NULL, (void *)NULL));
|
96
|
+
sem_post(&callback_data->callback_called);
|
97
|
+
} else {
|
98
|
+
callback_data->exit = false;
|
99
|
+
callback_data->phidget = self;
|
100
|
+
callback_data->callback = handler;
|
101
|
+
ph_raise(PhidgetPHSensor_setOnPHChangeHandler((PhidgetPHSensorHandle)ph->handle, ph_phsensor_on_ph_change, (void *)callback_data));
|
102
|
+
ph_callback_thread(callback_data);
|
103
|
+
}
|
104
|
+
return Qnil;
|
105
|
+
}
|
20
106
|
|
21
107
|
|
22
108
|
void Init_ph_sensor() {
|
@@ -31,178 +117,140 @@ void Init_ph_sensor() {
|
|
31
117
|
*/
|
32
118
|
rb_define_method(ph_phsensor, "initialize", ph_phsensor_init, 0);
|
33
119
|
|
34
|
-
/* Document-method:
|
35
|
-
* call-seq:
|
120
|
+
/* Document-method: getCorrectionTemperature
|
121
|
+
* call-seq: getCorrectionTemperature -> temperature
|
36
122
|
*
|
37
|
-
*
|
123
|
+
* Set this property to the measured temperature of the solution to correct the slope of the pH conversion for temperature.
|
38
124
|
*/
|
39
|
-
rb_define_method(ph_phsensor, "
|
125
|
+
rb_define_method(ph_phsensor, "getCorrectionTemperature", ph_phsensor_get_correction_temperature, 0);
|
126
|
+
rb_define_alias(ph_phsensor, "correction_temperature", "getCorrectionTemperature");
|
40
127
|
|
41
|
-
/* Document-method:
|
42
|
-
* call-seq:
|
128
|
+
/* Document-method: setCorrectionTemperature
|
129
|
+
* call-seq: setCorrectionTemperature(temperature)
|
43
130
|
*
|
44
|
-
*
|
131
|
+
* Set this property to the measured temperature of the solution to correct the slope of the pH conversion for temperature.
|
45
132
|
*/
|
46
|
-
rb_define_method(ph_phsensor, "
|
133
|
+
rb_define_method(ph_phsensor, "setCorrectionTemperature", ph_phsensor_set_correction_temperature, 1);
|
134
|
+
rb_define_alias(ph_phsensor, "correction_temperature=", "setCorrectionTemperature");
|
47
135
|
|
48
|
-
/* Document-method:
|
49
|
-
* call-seq:
|
136
|
+
/* Document-method: getMinCorrectionTemperature
|
137
|
+
* call-seq: getMinCorrectionTemperature -> temperature
|
50
138
|
*
|
51
|
-
*
|
139
|
+
* The minimum value that CorrectionTemperature can be set to.
|
52
140
|
*/
|
53
|
-
rb_define_method(ph_phsensor, "
|
141
|
+
rb_define_method(ph_phsensor, "getMinCorrectionTemperature", ph_phsensor_get_min_correction_temperature, 0);
|
142
|
+
rb_define_alias(ph_phsensor, "min_correction_temperature", "getMinCorrectionTemperature");
|
54
143
|
|
55
|
-
/* Document-method:
|
56
|
-
* call-seq:
|
144
|
+
/* Document-method: getMaxCorrectionTemperature
|
145
|
+
* call-seq: getMaxCorrectionTemperature -> temperature
|
57
146
|
*
|
58
|
-
*
|
147
|
+
* The maximum value that CorrectionTemperature can be set to.
|
59
148
|
*/
|
60
|
-
rb_define_method(ph_phsensor, "
|
149
|
+
rb_define_method(ph_phsensor, "getMaxCorrectionTemperature", ph_phsensor_get_max_correction_temperature, 0);
|
150
|
+
rb_define_alias(ph_phsensor, "max_correction_temperature", "getMaxCorrectionTemperature");
|
61
151
|
|
62
|
-
/* Document-method:
|
63
|
-
* call-seq:
|
152
|
+
/* Document-method: getDataInterval
|
153
|
+
* call-seq: getDataInterval -> data_interval
|
64
154
|
*
|
65
|
-
*
|
155
|
+
* The DataInterval is the time that must elapse before the channel will fire another PHChange event.
|
156
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
157
|
+
* The timing between PHChange events can also affected by the PHChangeTrigger.
|
66
158
|
*/
|
67
|
-
rb_define_method(ph_phsensor, "
|
159
|
+
rb_define_method(ph_phsensor, "getDataInterval", ph_phsensor_get_data_interval, 0);
|
160
|
+
rb_define_alias(ph_phsensor, "data_interval", "getDataInterval");
|
68
161
|
|
69
|
-
/* Document-method:
|
70
|
-
* call-seq:
|
162
|
+
/* Document-method: setDataInterval
|
163
|
+
* call-seq: setDataInterval(data_interval)
|
71
164
|
*
|
72
|
-
*
|
165
|
+
* The DataInterval is the time that must elapse before the channel will fire another PHChange event.
|
166
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
167
|
+
* The timing between PHChange events can also affected by the PHChangeTrigger.
|
73
168
|
*/
|
74
|
-
rb_define_method(ph_phsensor, "
|
169
|
+
rb_define_method(ph_phsensor, "setDataInterval", ph_phsensor_set_data_interval, 1);
|
170
|
+
rb_define_alias(ph_phsensor, "data_interval=", "setDataInterval");
|
75
171
|
|
76
|
-
/* Document-method:
|
77
|
-
* call-seq:
|
172
|
+
/* Document-method: getMinDataInterval
|
173
|
+
* call-seq: getMinDataInterval -> data_interval
|
78
174
|
*
|
79
|
-
*
|
175
|
+
* The minimum value that DataInterval can be set to.
|
80
176
|
*/
|
81
|
-
rb_define_method(ph_phsensor, "
|
177
|
+
rb_define_method(ph_phsensor, "getMinDataInterval", ph_phsensor_get_min_data_interval, 0);
|
178
|
+
rb_define_alias(ph_phsensor, "min_data_interval", "getMinDataInterval");
|
82
179
|
|
83
|
-
/* Document-method:
|
84
|
-
* call-seq:
|
180
|
+
/* Document-method: getMaxDataInterval
|
181
|
+
* call-seq: getMaxDataInterval -> data_interval
|
85
182
|
*
|
86
|
-
*
|
183
|
+
* The maximum value that DataInterval can be set to.
|
87
184
|
*/
|
88
|
-
rb_define_method(ph_phsensor, "
|
185
|
+
rb_define_method(ph_phsensor, "getMaxDataInterval", ph_phsensor_get_max_data_interval, 0);
|
186
|
+
rb_define_alias(ph_phsensor, "max_data_interval", "getMaxDataInterval");
|
89
187
|
|
90
|
-
/* Document-method:
|
91
|
-
* call-seq:
|
188
|
+
/* Document-method: getPH
|
189
|
+
* call-seq: getPH -> ph
|
92
190
|
*
|
93
|
-
*
|
191
|
+
* The most recent pH value that the channel has reported.
|
192
|
+
* This value will always be between MinPH and MaxPH.
|
94
193
|
*/
|
95
|
-
rb_define_method(ph_phsensor, "
|
96
|
-
|
97
|
-
#ifdef PH_CALLBACK
|
98
|
-
rb_define_private_method(ph_phsensor, "ext_setOnPHChangeHandler", ph_phsensor_set_on_ph_change_handler, 1);
|
99
|
-
#endif
|
100
|
-
|
194
|
+
rb_define_method(ph_phsensor, "getPH", ph_phsensor_get_ph, 0);
|
101
195
|
rb_define_alias(ph_phsensor, "ph", "getPH");
|
102
|
-
rb_define_alias(ph_phsensor, "ph_min", "getPHMin");
|
103
|
-
rb_define_alias(ph_phsensor, "ph_max", "getPHMax");
|
104
|
-
rb_define_alias(ph_phsensor, "ph_change_trigger", "getPHChangeTrigger");
|
105
|
-
rb_define_alias(ph_phsensor, "ph_change_trigger=", "setPHChangeTrigger");
|
106
|
-
rb_define_alias(ph_phsensor, "potential", "getPotential");
|
107
|
-
rb_define_alias(ph_phsensor, "potential_min", "getPotentialMin");
|
108
|
-
rb_define_alias(ph_phsensor, "potential_max", "getPotentialMax");
|
109
|
-
rb_define_alias(ph_phsensor, "temperature=", "setTemperature");
|
110
|
-
}
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
VALUE ph_phsensor_init(VALUE self) {
|
115
|
-
ph_data_t *ph = get_ph_data(self);
|
116
|
-
ph_raise(CPhidgetPHSensor_create((CPhidgetPHSensorHandle *)(&(ph->handle))));
|
117
|
-
return self;
|
118
|
-
}
|
119
|
-
|
120
|
-
VALUE ph_phsensor_get_ph(VALUE self) {
|
121
|
-
CPhidgetPHSensorHandle handle = (CPhidgetPHSensorHandle)get_ph_handle(self);
|
122
|
-
double ph;
|
123
|
-
ph_raise(CPhidgetPHSensor_getPH(handle, &ph));
|
124
|
-
return rb_float_new(ph);
|
125
|
-
}
|
126
196
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
VALUE ph_phsensor_get_ph_max(VALUE self) {
|
135
|
-
CPhidgetPHSensorHandle handle = (CPhidgetPHSensorHandle)get_ph_handle(self);
|
136
|
-
double ph;
|
137
|
-
ph_raise(CPhidgetPHSensor_getPHMax(handle, &ph));
|
138
|
-
return rb_float_new(ph);
|
139
|
-
}
|
140
|
-
|
141
|
-
VALUE ph_phsensor_get_ph_change_trigger(VALUE self) {
|
142
|
-
CPhidgetPHSensorHandle handle = (CPhidgetPHSensorHandle)get_ph_handle(self);
|
143
|
-
double trigger;
|
144
|
-
ph_raise(CPhidgetPHSensor_getPHChangeTrigger(handle, &trigger));
|
145
|
-
return rb_float_new(trigger);
|
146
|
-
}
|
147
|
-
|
148
|
-
VALUE ph_phsensor_set_ph_change_trigger(VALUE self, VALUE trigger) {
|
149
|
-
CPhidgetPHSensorHandle handle = (CPhidgetPHSensorHandle)get_ph_handle(self);
|
150
|
-
ph_raise(CPhidgetPHSensor_setPHChangeTrigger(handle, NUM2DBL(trigger)));
|
151
|
-
return Qnil;
|
152
|
-
}
|
153
|
-
|
154
|
-
VALUE ph_phsensor_get_potential(VALUE self) {
|
155
|
-
CPhidgetPHSensorHandle handle = (CPhidgetPHSensorHandle)get_ph_handle(self);
|
156
|
-
double potential;
|
157
|
-
ph_raise(CPhidgetPHSensor_getPotential(handle, &potential));
|
158
|
-
return rb_float_new(potential);
|
159
|
-
}
|
197
|
+
/* Document-method: getMinPH
|
198
|
+
* call-seq: getMinPH -> ph
|
199
|
+
*
|
200
|
+
* The minimum value the PHChange event will report.
|
201
|
+
*/
|
202
|
+
rb_define_method(ph_phsensor, "getMinPH", ph_phsensor_get_min_ph, 0);
|
203
|
+
rb_define_alias(ph_phsensor, "min_ph", "getMinPH");
|
160
204
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
205
|
+
/* Document-method: getMaxPH
|
206
|
+
* call-seq: getMaxPH -> ph
|
207
|
+
*
|
208
|
+
* The maximum value the PHChange event will report.
|
209
|
+
*/
|
210
|
+
rb_define_method(ph_phsensor, "getMaxPH", ph_phsensor_get_max_ph, 0);
|
211
|
+
rb_define_alias(ph_phsensor, "max_ph", "getMaxPH");
|
167
212
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
213
|
+
/* Document-method: getPHChangeTrigger
|
214
|
+
* call-seq: getPHChangeTrigger -> trigger
|
215
|
+
*
|
216
|
+
* The channel will not issue a PHChange event until the pH value has changed by the amount specified by the PHChangeTrigger.
|
217
|
+
* Setting the PHChangeTrigger to 0 will result in the channel firing events every DataInterval.
|
218
|
+
* This is useful for applications that implement their own data filtering.
|
219
|
+
*/
|
220
|
+
rb_define_method(ph_phsensor, "getPHChangeTrigger", ph_phsensor_get_ph_change_trigger, 0);
|
221
|
+
rb_define_alias(ph_phsensor, "ph_change_trigger", "getPHChangeTrigger");
|
174
222
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
223
|
+
/* Document-method: setPHChangeTrigger
|
224
|
+
* call-seq: setPHChangeTrigger(trigger)
|
225
|
+
*
|
226
|
+
* The channel will not issue a PHChange event until the pH value has changed by the amount specified by the PHChangeTrigger.
|
227
|
+
* Setting the PHChangeTrigger to 0 will result in the channel firing events every DataInterval.
|
228
|
+
* This is useful for applications that implement their own data filtering.
|
229
|
+
*/
|
230
|
+
rb_define_method(ph_phsensor, "setPHChangeTrigger", ph_phsensor_set_ph_change_trigger, 1);
|
231
|
+
rb_define_alias(ph_phsensor, "ph_change_trigger=", "setPHChangeTrigger");
|
180
232
|
|
233
|
+
/* Document-method: getMinPHChangeTrigger
|
234
|
+
* call-seq: getMinPHChangeTrigger -> trigger
|
235
|
+
*
|
236
|
+
* The channel will not issue a PHChange event until the pH value has changed by the amount specified by the PHChangeTrigger.
|
237
|
+
* Setting the PHChangeTrigger to 0 will result in the channel firing events every DataInterval.
|
238
|
+
* This is useful for applications that implement their own data filtering.
|
239
|
+
*/
|
240
|
+
rb_define_method(ph_phsensor, "getMinPHChangeTrigger", ph_phsensor_get_min_ph_change_trigger, 0);
|
241
|
+
rb_define_alias(ph_phsensor, "min_ph_change_trigger", "getMinPHChangeTrigger");
|
181
242
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
callback_data->exit = false;
|
192
|
-
callback_data->phidget = self;
|
193
|
-
callback_data->callback = handler;
|
194
|
-
ph_raise(CPhidgetPHSensor_set_OnPHChange_Handler((CPhidgetPHSensorHandle)ph->handle, ph_phsensor_on_ph_change, (void *)callback_data));
|
195
|
-
ph_callback_thread(callback_data);
|
196
|
-
}
|
197
|
-
return Qnil;
|
198
|
-
}
|
243
|
+
/* Document-method: getMaxPHChangeTrigger
|
244
|
+
* call-seq: getMaxPHChangeTrigger -> trigger
|
245
|
+
*
|
246
|
+
* The channel will not issue a PHChange event until the pH value has changed by the amount specified by the PHChangeTrigger.
|
247
|
+
* Setting the PHChangeTrigger to 0 will result in the channel firing events every DataInterval.
|
248
|
+
* This is useful for applications that implement their own data filtering.
|
249
|
+
*/
|
250
|
+
rb_define_method(ph_phsensor, "getMaxPHChangeTrigger", ph_phsensor_get_max_ph_change_trigger, 0);
|
251
|
+
rb_define_alias(ph_phsensor, "max_ph_change_trigger", "getMaxPHChangeTrigger");
|
199
252
|
|
200
253
|
|
201
|
-
|
202
|
-
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
203
|
-
callback_data->called = true;
|
204
|
-
return EPHIDGET_OK;
|
254
|
+
rb_define_private_method(ph_phsensor, "ext_setOnPHChangeHandler", ph_phsensor_set_on_ph_change_handler, 1);
|
205
255
|
}
|
206
256
|
|
207
|
-
#endif
|
208
|
-
|
@@ -0,0 +1,144 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
VALUE ph_power_guard_init(VALUE self) {
|
7
|
+
ph_data_t *ph = get_ph_data(self);
|
8
|
+
ph_raise(PhidgetPowerGuard_create((PhidgetPowerGuardHandle *)(&(ph->handle))));
|
9
|
+
return self;
|
10
|
+
}
|
11
|
+
|
12
|
+
VALUE ph_power_guard_get_fan_mode(VALUE self) {
|
13
|
+
return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetPowerGuard_getFanMode);
|
14
|
+
}
|
15
|
+
|
16
|
+
VALUE ph_power_guard_set_fan_mode(VALUE self, VALUE mode) {
|
17
|
+
ph_raise(PhidgetPowerGuard_setFanMode((PhidgetPowerGuardHandle)get_ph_handle(self), NUM2INT(mode)));
|
18
|
+
return Qnil;
|
19
|
+
}
|
20
|
+
|
21
|
+
VALUE ph_power_guard_get_over_voltage(VALUE self) {
|
22
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPowerGuard_getOverVoltage);
|
23
|
+
}
|
24
|
+
|
25
|
+
VALUE ph_power_guard_set_over_voltage(VALUE self, VALUE over_voltage) {
|
26
|
+
ph_raise(PhidgetPowerGuard_setOverVoltage((PhidgetPowerGuardHandle)get_ph_handle(self), NUM2DBL(over_voltage)));
|
27
|
+
return Qnil;
|
28
|
+
}
|
29
|
+
|
30
|
+
VALUE ph_power_guard_get_min_over_voltage(VALUE self) {
|
31
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPowerGuard_getMinOverVoltage);
|
32
|
+
}
|
33
|
+
|
34
|
+
VALUE ph_power_guard_get_max_over_voltage(VALUE self) {
|
35
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetPowerGuard_getMaxOverVoltage);
|
36
|
+
}
|
37
|
+
|
38
|
+
VALUE ph_power_guard_get_power_enabled(VALUE self) {
|
39
|
+
return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetPowerGuard_getPowerEnabled);
|
40
|
+
}
|
41
|
+
|
42
|
+
VALUE ph_power_guard_set_power_enabled(VALUE self, VALUE enabled) {
|
43
|
+
ph_raise(PhidgetPowerGuard_setPowerEnabled((PhidgetPowerGuardHandle)get_ph_handle(self), TYPE(enabled) == T_TRUE ? PTRUE : PFALSE));
|
44
|
+
return Qnil;
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
void Init_power_guard() {
|
49
|
+
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
50
|
+
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
51
|
+
VALUE ph_power_guard = rb_define_class_under(ph_module, "PowerGuard", ph_common);
|
52
|
+
|
53
|
+
/* Document-method: new
|
54
|
+
* call-seq: new
|
55
|
+
*
|
56
|
+
* Creates a Phidget PowerGuard object.
|
57
|
+
*/
|
58
|
+
rb_define_method(ph_power_guard, "initialize", ph_power_guard_init, 0);
|
59
|
+
|
60
|
+
/* Document-method: getFanMode
|
61
|
+
* call-seq: getFanMode -> fan_mode
|
62
|
+
*
|
63
|
+
* The FanMode dictates the operating condition of the fan.
|
64
|
+
* Choose between on, off, or automatic (based on temperature).
|
65
|
+
* If the FanMode is set to automatic, the fan will turn on when the temperature reaches 70°C and it will remain on until the temperature falls below 55°C.
|
66
|
+
* If the FanMode is off, the device will still turn on the fan if the temperature reaches 85°C and it will remain on until it falls below 70°C.
|
67
|
+
*/
|
68
|
+
rb_define_method(ph_power_guard, "getFanMode", ph_power_guard_get_fan_mode, 0);
|
69
|
+
rb_define_alias(ph_power_guard, "fan_mode", "getFanMode");
|
70
|
+
|
71
|
+
/* Document-method: setFanMode
|
72
|
+
* call-seq: setFanMode(fan_mode)
|
73
|
+
*
|
74
|
+
* The FanMode dictates the operating condition of the fan.
|
75
|
+
* Choose between on, off, or automatic (based on temperature).
|
76
|
+
* If the FanMode is set to automatic, the fan will turn on when the temperature reaches 70°C and it will remain on until the temperature falls below 55°C.
|
77
|
+
* If the FanMode is off, the device will still turn on the fan if the temperature reaches 85°C and it will remain on until it falls below 70°C.
|
78
|
+
*/
|
79
|
+
rb_define_method(ph_power_guard, "setFanMode", ph_power_guard_set_fan_mode, 1);
|
80
|
+
rb_define_alias(ph_power_guard, "fan_mode=", "setFanMode");
|
81
|
+
|
82
|
+
/* Document-method: getOverVoltage
|
83
|
+
* call-seq: getOverVoltage -> over_voltage
|
84
|
+
*
|
85
|
+
* The device constantly monitors the output voltage, and if it exceeds the OverVoltage value, it will disconnect the input from the output.
|
86
|
+
* This functionality is critical for protecting power supplies from regenerated voltage coming from motors. Many power supplies assume that
|
87
|
+
* a higher than output expected voltage is related to an internal failure to the power supply, and will permanently disable themselves to protect
|
88
|
+
* the system. A typical safe value is to set OverVoltage to 1-2 volts higher than the output voltage of the supply. For instance, a 12V supply
|
89
|
+
* would be protected by setting OverVoltage to 13V.
|
90
|
+
* The device will connect the input to the output again when the voltage drops to (OverVoltage - 1V).
|
91
|
+
*/
|
92
|
+
rb_define_method(ph_power_guard, "getOverVoltage", ph_power_guard_get_over_voltage, 0);
|
93
|
+
rb_define_alias(ph_power_guard, "over_voltage", "getOverVoltage");
|
94
|
+
|
95
|
+
/* Document-method: setOverVoltage
|
96
|
+
* call-seq: setOverVoltage(over_voltage)
|
97
|
+
*
|
98
|
+
* The device constantly monitors the output voltage, and if it exceeds the OverVoltage value, it will disconnect the input from the output.
|
99
|
+
* This functionality is critical for protecting power supplies from regenerated voltage coming from motors. Many power supplies assume that
|
100
|
+
* a higher than output expected voltage is related to an internal failure to the power supply, and will permanently disable themselves to protect
|
101
|
+
* the system. A typical safe value is to set OverVoltage to 1-2 volts higher than the output voltage of the supply. For instance, a 12V supply
|
102
|
+
* would be protected by setting OverVoltage to 13V.
|
103
|
+
* The device will connect the input to the output again when the voltage drops to (OverVoltage - 1V).
|
104
|
+
*/
|
105
|
+
rb_define_method(ph_power_guard, "setOverVoltage", ph_power_guard_set_over_voltage, 1);
|
106
|
+
rb_define_alias(ph_power_guard, "over_voltage=", "setOverVoltage");
|
107
|
+
|
108
|
+
/* Document-method: getMinOverVoltage
|
109
|
+
* call-seq: getMinOverVoltage -> over_voltage
|
110
|
+
*
|
111
|
+
* The minimum value that OverVoltage can be set to.
|
112
|
+
*/
|
113
|
+
rb_define_method(ph_power_guard, "getMinOverVoltage", ph_power_guard_get_min_over_voltage, 0);
|
114
|
+
rb_define_alias(ph_power_guard, "min_over_voltage", "getMinOverVoltage");
|
115
|
+
|
116
|
+
/* Document-method: getMaxOverVoltage
|
117
|
+
* call-seq: getMaxOverVoltage -> over_voltage
|
118
|
+
*
|
119
|
+
* The maximum value that OverVoltage can be set to.
|
120
|
+
*/
|
121
|
+
rb_define_method(ph_power_guard, "getMaxOverVoltage", ph_power_guard_get_max_over_voltage, 0);
|
122
|
+
rb_define_alias(ph_power_guard, "max_over_voltage", "getMaxOverVoltage");
|
123
|
+
|
124
|
+
/* Document-method: getPowerEnabled
|
125
|
+
* call-seq: getPowerEnabled -> true or false
|
126
|
+
*
|
127
|
+
* When PowerEnabled is true, the device will connect the input to the output and begin monitoring.
|
128
|
+
* The output voltage is constantly monitored and will be automatically disconnected from the input when the output exceeds the OverVoltage value.
|
129
|
+
* PowerEnabled allows the device to operate as a Solid State Relay, powering on or off all devices connected to the output.
|
130
|
+
*/
|
131
|
+
rb_define_method(ph_power_guard, "getPowerEnabled", ph_power_guard_get_power_enabled, 0);
|
132
|
+
rb_define_alias(ph_power_guard, "power_enabled", "getPowerEnabled");
|
133
|
+
|
134
|
+
/* Document-method: setPowerEnabled
|
135
|
+
* call-seq: setPowerEnabled(power_enabled)
|
136
|
+
*
|
137
|
+
* When PowerEnabled is true, the device will connect the input to the output and begin monitoring.
|
138
|
+
* The output voltage is constantly monitored and will be automatically disconnected from the input when the output exceeds the OverVoltage value.
|
139
|
+
* PowerEnabled allows the device to operate as a Solid State Relay, powering on or off all devices connected to the output.
|
140
|
+
*/
|
141
|
+
rb_define_method(ph_power_guard, "setPowerEnabled", ph_power_guard_set_power_enabled, 1);
|
142
|
+
rb_define_alias(ph_power_guard, "power_enabled=", "setPowerEnabled");
|
143
|
+
}
|
144
|
+
|