phidgets 0.1.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +3 -0
  3. data/README.rdoc +32 -43
  4. data/Rakefile +4 -2
  5. data/bin/phidget +18 -72
  6. data/ext/phidgets/extconf.rb +5 -8
  7. data/ext/phidgets/phidgets.c +708 -173
  8. data/ext/phidgets/phidgets.h +54 -35
  9. data/ext/phidgets/phidgets_accelerometer.c +193 -109
  10. data/ext/phidgets/phidgets_bldc_motor.c +529 -0
  11. data/ext/phidgets/phidgets_capacitive_touch.c +302 -0
  12. data/ext/phidgets/phidgets_common.c +570 -315
  13. data/ext/phidgets/phidgets_current_input.c +229 -0
  14. data/ext/phidgets/phidgets_dc_motor.c +562 -0
  15. data/ext/phidgets/phidgets_dictionary.c +154 -213
  16. data/ext/phidgets/phidgets_digital_input.c +127 -0
  17. data/ext/phidgets/phidgets_digital_output.c +288 -0
  18. data/ext/phidgets/phidgets_distance_sensor.c +295 -0
  19. data/ext/phidgets/phidgets_encoder.c +211 -192
  20. data/ext/phidgets/phidgets_frequency_counter.c +310 -177
  21. data/ext/phidgets/phidgets_gps.c +226 -164
  22. data/ext/phidgets/phidgets_gyroscope.c +195 -0
  23. data/ext/phidgets/phidgets_hub.c +39 -0
  24. data/ext/phidgets/phidgets_humidity_sensor.c +200 -0
  25. data/ext/phidgets/phidgets_ir.c +211 -171
  26. data/ext/phidgets/phidgets_lcd.c +512 -0
  27. data/ext/phidgets/phidgets_light_sensor.c +200 -0
  28. data/ext/phidgets/phidgets_log.c +263 -0
  29. data/ext/phidgets/phidgets_magnetometer.c +279 -0
  30. data/ext/phidgets/phidgets_manager.c +86 -297
  31. data/ext/phidgets/phidgets_motor_position_controller.c +787 -0
  32. data/ext/phidgets/phidgets_phsensor.c +200 -152
  33. data/ext/phidgets/phidgets_power_guard.c +144 -0
  34. data/ext/phidgets/phidgets_pressure_sensor.c +200 -0
  35. data/ext/phidgets/phidgets_rc_servo.c +672 -0
  36. data/ext/phidgets/phidgets_resistance_input.c +227 -0
  37. data/ext/phidgets/phidgets_rfid.c +107 -221
  38. data/ext/phidgets/phidgets_sound_sensor.c +284 -0
  39. data/ext/phidgets/phidgets_spatial.c +124 -318
  40. data/ext/phidgets/phidgets_stepper.c +457 -430
  41. data/ext/phidgets/phidgets_temp_sensor.c +223 -228
  42. data/ext/phidgets/phidgets_voltage_input.c +428 -0
  43. data/ext/phidgets/phidgets_voltage_output.c +167 -0
  44. data/ext/phidgets/phidgets_voltage_ratio_input.c +435 -0
  45. data/lib/phidgets.rb +21 -14
  46. data/lib/phidgets/accelerometer.rb +11 -15
  47. data/lib/phidgets/bldc_motor.rb +45 -0
  48. data/lib/phidgets/capacitive_touch.rb +33 -0
  49. data/lib/phidgets/common.rb +40 -69
  50. data/lib/phidgets/current_input.rb +21 -0
  51. data/lib/phidgets/dc_motor.rb +45 -0
  52. data/lib/phidgets/dictionary.rb +30 -39
  53. data/lib/phidgets/digital_input.rb +21 -0
  54. data/lib/phidgets/digital_output.rb +56 -0
  55. data/lib/phidgets/distance_sensor.rb +33 -0
  56. data/lib/phidgets/encoder.rb +1 -29
  57. data/lib/phidgets/frequency_counter.rb +23 -14
  58. data/lib/phidgets/gps.rb +34 -26
  59. data/lib/phidgets/gyroscope.rb +21 -0
  60. data/lib/phidgets/humidity_sensor.rb +21 -0
  61. data/lib/phidgets/ir.rb +34 -39
  62. data/lib/phidgets/light_sensor.rb +21 -0
  63. data/lib/phidgets/magnetometer.rb +21 -0
  64. data/lib/phidgets/manager.rb +18 -66
  65. data/lib/phidgets/motor_position_controller.rb +45 -0
  66. data/lib/phidgets/ph_sensor.rb +2 -6
  67. data/lib/phidgets/pressure_sensor.rb +21 -0
  68. data/lib/phidgets/rc_servo.rb +58 -0
  69. data/lib/phidgets/resistance_input.rb +21 -0
  70. data/lib/phidgets/rfid.rb +22 -38
  71. data/lib/phidgets/sound_sensor.rb +21 -0
  72. data/lib/phidgets/spatial.rb +11 -15
  73. data/lib/phidgets/stepper.rb +48 -50
  74. data/lib/phidgets/temperature_sensor.rb +11 -15
  75. data/lib/phidgets/version.rb +5 -0
  76. data/lib/phidgets/voltage_input.rb +34 -0
  77. data/lib/phidgets/voltage_output.rb +23 -0
  78. data/lib/phidgets/voltage_ratio_input.rb +34 -0
  79. data/phidgets.gemspec +3 -22
  80. data/test/test_accelerometer.rb +42 -23
  81. data/test/test_bldc_motor.rb +134 -0
  82. data/test/test_capacitive_touch.rb +82 -0
  83. data/test/test_common.rb +125 -108
  84. data/test/test_current_input.rb +62 -0
  85. data/test/test_dc_motor.rb +146 -0
  86. data/test/test_dictionary.rb +22 -54
  87. data/test/test_digital_input.rb +30 -0
  88. data/test/test_digital_output.rb +70 -0
  89. data/test/test_distance_sensor.rb +76 -0
  90. data/test/test_encoder.rb +45 -38
  91. data/test/test_frequency_counter.rb +71 -36
  92. data/test/test_gps.rb +29 -38
  93. data/test/test_gyroscope.rb +54 -0
  94. data/test/test_helper.rb +0 -1
  95. data/test/test_hub.rb +14 -0
  96. data/test/test_humidity_sensor.rb +58 -0
  97. data/test/test_ir.rb +34 -34
  98. data/test/test_lcd.rb +146 -0
  99. data/test/test_light_sensor.rb +58 -0
  100. data/test/test_magnetometer.rb +78 -0
  101. data/test/test_manager.rb +10 -79
  102. data/test/test_motor_control.rb +146 -108
  103. data/test/test_phidgets.rb +2 -14
  104. data/test/test_phsensor.rb +46 -34
  105. data/test/test_power_guard.rb +42 -0
  106. data/test/test_pressure_sensor.rb +58 -0
  107. data/test/test_rc_servo.rb +174 -0
  108. data/test/test_resistance_input.rb +66 -0
  109. data/test/test_rfid.rb +15 -54
  110. data/test/test_sound_sensor.rb +78 -0
  111. data/test/test_spatial.rb +19 -85
  112. data/test/test_stepper.rb +89 -98
  113. data/test/test_temp_sensor.rb +42 -47
  114. data/test/test_voltage_input.rb +102 -0
  115. data/test/test_voltage_output.rb +46 -0
  116. data/test/test_voltage_ratio_input.rb +102 -0
  117. metadata +72 -89
  118. data/ext/phidgets/phidgets_advanced_servo.c +0 -567
  119. data/ext/phidgets/phidgets_analog.c +0 -139
  120. data/ext/phidgets/phidgets_bridge.c +0 -263
  121. data/ext/phidgets/phidgets_interface_kit.c +0 -340
  122. data/ext/phidgets/phidgets_led.c +0 -178
  123. data/ext/phidgets/phidgets_motor_control.c +0 -642
  124. data/ext/phidgets/phidgets_servo.c +0 -276
  125. data/ext/phidgets/phidgets_text_lcd.c +0 -381
  126. data/ext/phidgets/phidgets_text_led.c +0 -107
  127. data/ext/phidgets/phidgets_weight_sensor.c +0 -113
  128. data/lib/phidgets/advanced_servo.rb +0 -49
  129. data/lib/phidgets/analog.rb +0 -8
  130. data/lib/phidgets/bridge.rb +0 -25
  131. data/lib/phidgets/interfacekit.rb +0 -49
  132. data/lib/phidgets/led.rb +0 -8
  133. data/lib/phidgets/motor_control.rb +0 -110
  134. data/lib/phidgets/servo.rb +0 -23
  135. data/lib/phidgets/text_lcd.rb +0 -8
  136. data/lib/phidgets/text_led.rb +0 -8
  137. data/lib/phidgets/weight_sensor.rb +0 -25
  138. data/test/test_advanced_servo.rb +0 -152
  139. data/test/test_analog.rb +0 -45
  140. data/test/test_bridge.rb +0 -77
  141. data/test/test_interfacekit.rb +0 -97
  142. data/test/test_led.rb +0 -55
  143. data/test/test_servo.rb +0 -67
  144. data/test/test_text_lcd.rb +0 -115
  145. data/test/test_text_led.rb +0 -35
  146. data/test/test_weight_sensor.rb +0 -32
@@ -0,0 +1,428 @@
1
+
2
+ #include "phidgets.h"
3
+
4
+ #define VOLTAGE_INPUT_SENSOR_CHANGE_CALLBACK 0
5
+ #define VOLTAGE_INPUT_VOLTAGE_CHANGE_CALLBACK 1
6
+
7
+
8
+ VALUE ph_voltage_input_init(VALUE self) {
9
+ ph_data_t *ph = get_ph_data(self);
10
+ ph_raise(PhidgetVoltageInput_create((PhidgetVoltageInputHandle *)(&(ph->handle))));
11
+ return self;
12
+ }
13
+
14
+ VALUE ph_voltage_input_get_data_interval(VALUE self) {
15
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetVoltageInput_getDataInterval);
16
+ }
17
+
18
+ VALUE ph_voltage_input_set_data_interval(VALUE self, VALUE interval) {
19
+ ph_raise(PhidgetVoltageInput_setDataInterval((PhidgetVoltageInputHandle)get_ph_handle(self), NUM2UINT(interval)));
20
+ return Qnil;
21
+ }
22
+
23
+ VALUE ph_voltage_input_get_min_data_interval(VALUE self) {
24
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetVoltageInput_getMinDataInterval);
25
+ }
26
+
27
+ VALUE ph_voltage_input_get_max_data_interval(VALUE self) {
28
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetVoltageInput_getMaxDataInterval);
29
+ }
30
+
31
+ VALUE ph_voltage_input_get_power_supply(VALUE self) {
32
+ return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetVoltageInput_getPowerSupply);
33
+ }
34
+
35
+ VALUE ph_voltage_input_set_power_supply(VALUE self, VALUE power_supply) {
36
+ ph_raise(PhidgetVoltageInput_setPowerSupply((PhidgetVoltageInputHandle)get_ph_handle(self), NUM2INT(power_supply)));
37
+ return Qnil;
38
+ }
39
+
40
+ VALUE ph_voltage_input_get_sensor_type(VALUE self) {
41
+ return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetVoltageInput_getSensorType);
42
+ }
43
+
44
+ VALUE ph_voltage_input_set_sensor_type(VALUE self, VALUE sensor_type) {
45
+ ph_raise(PhidgetVoltageInput_setSensorType((PhidgetVoltageInputHandle)get_ph_handle(self), NUM2INT(sensor_type)));
46
+ return Qnil;
47
+ }
48
+
49
+ VALUE ph_voltage_input_get_sensor_unit(VALUE self) {
50
+ VALUE unit_info = rb_hash_new();
51
+ Phidget_UnitInfo sensorUnit;
52
+ ph_raise(PhidgetVoltageInput_getSensorUnit((PhidgetVoltageInputHandle)get_ph_handle(self), &sensorUnit));
53
+ rb_hash_aset(unit_info, rb_str_new2("unit"), INT2NUM(sensorUnit.unit));
54
+ rb_hash_aset(unit_info, rb_str_new2("name"), rb_str_new2(sensorUnit.name));
55
+ rb_hash_aset(unit_info, rb_str_new2("symbol"), rb_str_new2(sensorUnit.symbol));
56
+ return unit_info;
57
+ }
58
+
59
+ VALUE ph_voltage_input_get_sensor_value(VALUE self) {
60
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetVoltageInput_getSensorValue);
61
+ }
62
+
63
+ VALUE ph_voltage_input_get_sensor_value_change_trigger(VALUE self) {
64
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetVoltageInput_getSensorValueChangeTrigger);
65
+ }
66
+
67
+ VALUE ph_voltage_input_set_sensor_value_change_trigger(VALUE self, VALUE trigger) {
68
+ ph_raise(PhidgetVoltageInput_setSensorValueChangeTrigger((PhidgetVoltageInputHandle)get_ph_handle(self), NUM2DBL(trigger)));
69
+ return Qnil;
70
+ }
71
+
72
+ VALUE ph_voltage_input_get_voltage(VALUE self) {
73
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetVoltageInput_getVoltage);
74
+ }
75
+
76
+ VALUE ph_voltage_input_get_min_voltage(VALUE self) {
77
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetVoltageInput_getMinVoltage);
78
+ }
79
+
80
+ VALUE ph_voltage_input_get_max_voltage(VALUE self) {
81
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetVoltageInput_getMaxVoltage);
82
+ }
83
+
84
+ VALUE ph_voltage_input_get_voltage_change_trigger(VALUE self) {
85
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetVoltageInput_getVoltageChangeTrigger);
86
+ }
87
+
88
+ VALUE ph_voltage_input_set_voltage_change_trigger(VALUE self, VALUE trigger) {
89
+ ph_raise(PhidgetVoltageInput_setVoltageChangeTrigger((PhidgetVoltageInputHandle)get_ph_handle(self), NUM2DBL(trigger)));
90
+ return Qnil;
91
+ }
92
+
93
+ VALUE ph_voltage_input_get_min_voltage_change_trigger(VALUE self) {
94
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetVoltageInput_getMinVoltageChangeTrigger);
95
+ }
96
+
97
+ VALUE ph_voltage_input_get_max_voltage_change_trigger(VALUE self) {
98
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetVoltageInput_getMaxVoltageChangeTrigger);
99
+ }
100
+
101
+ VALUE ph_voltage_input_get_voltage_range(VALUE self) {
102
+ return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetVoltageInput_getVoltageRange);
103
+ }
104
+
105
+ VALUE ph_voltage_input_set_voltage_range(VALUE self, VALUE voltage_range) {
106
+ ph_raise(PhidgetVoltageInput_setVoltageRange((PhidgetVoltageInputHandle)get_ph_handle(self), NUM2INT(voltage_range)));
107
+ return Qnil;
108
+ }
109
+
110
+
111
+ void CCONV ph_voltage_input_on_sensor_change(PhidgetVoltageInputHandle phid, void *userPtr, double sensor_value, Phidget_UnitInfo *sensor_unit) {
112
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
113
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
114
+ callback_data->arg1 = DBL2NUM(sensor_value);
115
+ callback_data->arg2 = INT2NUM(sensor_unit->unit);
116
+ callback_data->arg3 = rb_str_new2(sensor_unit->name);
117
+ callback_data->arg4 = rb_str_new2(sensor_unit->symbol);
118
+ sem_post(&callback_data->callback_called);
119
+ }
120
+
121
+ VALUE ph_voltage_input_set_on_sensor_change_handler(VALUE self, VALUE handler) {
122
+ ph_data_t *ph = get_ph_data(self);
123
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[VOLTAGE_INPUT_SENSOR_CHANGE_CALLBACK];
124
+ if( TYPE(handler) == T_NIL ) {
125
+ callback_data->callback = T_NIL;
126
+ callback_data->exit = true;
127
+ ph_raise(PhidgetVoltageInput_setOnSensorChangeHandler((PhidgetVoltageInputHandle)ph->handle, NULL, (void *)NULL));
128
+ sem_post(&callback_data->callback_called);
129
+ } else {
130
+ callback_data->exit = false;
131
+ callback_data->phidget = self;
132
+ callback_data->callback = handler;
133
+ ph_raise(PhidgetVoltageInput_setOnSensorChangeHandler((PhidgetVoltageInputHandle)ph->handle, ph_voltage_input_on_sensor_change, (void *)callback_data));
134
+ ph_callback_thread(callback_data);
135
+ }
136
+ return Qnil;
137
+ }
138
+
139
+
140
+ void CCONV ph_voltage_input_on_voltage_change(PhidgetVoltageInputHandle phid, void *userPtr, double voltage) {
141
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
142
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
143
+ callback_data->arg1 = DBL2NUM(voltage);
144
+ callback_data->arg2 = Qnil;
145
+ callback_data->arg3 = Qnil;
146
+ callback_data->arg4 = Qnil;
147
+ sem_post(&callback_data->callback_called);
148
+ }
149
+
150
+ VALUE ph_voltage_input_set_on_voltage_change_handler(VALUE self, VALUE handler) {
151
+ ph_data_t *ph = get_ph_data(self);
152
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[VOLTAGE_INPUT_VOLTAGE_CHANGE_CALLBACK];
153
+ if( TYPE(handler) == T_NIL ) {
154
+ callback_data->callback = T_NIL;
155
+ callback_data->exit = true;
156
+ ph_raise(PhidgetVoltageInput_setOnVoltageChangeHandler((PhidgetVoltageInputHandle)ph->handle, NULL, (void *)NULL));
157
+ sem_post(&callback_data->callback_called);
158
+ } else {
159
+ callback_data->exit = false;
160
+ callback_data->phidget = self;
161
+ callback_data->callback = handler;
162
+ ph_raise(PhidgetVoltageInput_setOnVoltageChangeHandler((PhidgetVoltageInputHandle)ph->handle, ph_voltage_input_on_voltage_change, (void *)callback_data));
163
+ ph_callback_thread(callback_data);
164
+ }
165
+ return Qnil;
166
+ }
167
+
168
+
169
+ void Init_voltage_input() {
170
+ VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
171
+ VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
172
+ VALUE ph_voltage_input = rb_define_class_under(ph_module, "VoltageInput", ph_common);
173
+
174
+
175
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_VOLTAGE", INT2NUM(SENSOR_TYPE_VOLTAGE));
176
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_1114", INT2NUM(SENSOR_TYPE_1114));
177
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_1117", INT2NUM(SENSOR_TYPE_1117));
178
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_1123", INT2NUM(SENSOR_TYPE_1123));
179
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_1127", INT2NUM(SENSOR_TYPE_1127));
180
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_1130_PH", INT2NUM(SENSOR_TYPE_1130_PH));
181
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_1130_ORP", INT2NUM(SENSOR_TYPE_1130_ORP));
182
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_1132", INT2NUM(SENSOR_TYPE_1132));
183
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_1133", INT2NUM(SENSOR_TYPE_1133));
184
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_1135", INT2NUM(SENSOR_TYPE_1135));
185
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_1142", INT2NUM(SENSOR_TYPE_1142));
186
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_1143", INT2NUM(SENSOR_TYPE_1143));
187
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3500", INT2NUM(SENSOR_TYPE_3500));
188
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3501", INT2NUM(SENSOR_TYPE_3501));
189
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3502", INT2NUM(SENSOR_TYPE_3502));
190
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3503", INT2NUM(SENSOR_TYPE_3503));
191
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3507", INT2NUM(SENSOR_TYPE_3507));
192
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3508", INT2NUM(SENSOR_TYPE_3508));
193
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3509", INT2NUM(SENSOR_TYPE_3509));
194
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3510", INT2NUM(SENSOR_TYPE_3510));
195
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3511", INT2NUM(SENSOR_TYPE_3511));
196
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3512", INT2NUM(SENSOR_TYPE_3512));
197
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3513", INT2NUM(SENSOR_TYPE_3513));
198
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3514", INT2NUM(SENSOR_TYPE_3514));
199
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3515", INT2NUM(SENSOR_TYPE_3515));
200
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3516", INT2NUM(SENSOR_TYPE_3516));
201
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3517", INT2NUM(SENSOR_TYPE_3517));
202
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3518", INT2NUM(SENSOR_TYPE_3518));
203
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3519", INT2NUM(SENSOR_TYPE_3519));
204
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3584", INT2NUM(SENSOR_TYPE_3584));
205
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3585", INT2NUM(SENSOR_TYPE_3585));
206
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3586", INT2NUM(SENSOR_TYPE_3586));
207
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3587", INT2NUM(SENSOR_TYPE_3587));
208
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3588", INT2NUM(SENSOR_TYPE_3588));
209
+ rb_define_const(ph_voltage_input, "SENSOR_TYPE_3589", INT2NUM(SENSOR_TYPE_3589));
210
+
211
+ rb_define_const(ph_voltage_input, "VOLTAGE_RANGE_10mV", INT2NUM(VOLTAGE_RANGE_10mV));
212
+ rb_define_const(ph_voltage_input, "VOLTAGE_RANGE_40mV", INT2NUM(VOLTAGE_RANGE_40mV));
213
+ rb_define_const(ph_voltage_input, "VOLTAGE_RANGE_200mV", INT2NUM(VOLTAGE_RANGE_200mV));
214
+ rb_define_const(ph_voltage_input, "VOLTAGE_RANGE_312_5mV", INT2NUM(VOLTAGE_RANGE_312_5mV));
215
+ rb_define_const(ph_voltage_input, "VOLTAGE_RANGE_400mV", INT2NUM(VOLTAGE_RANGE_400mV));
216
+ rb_define_const(ph_voltage_input, "VOLTAGE_RANGE_1000mV", INT2NUM(VOLTAGE_RANGE_1000mV));
217
+ rb_define_const(ph_voltage_input, "VOLTAGE_RANGE_2V", INT2NUM(VOLTAGE_RANGE_2V));
218
+ rb_define_const(ph_voltage_input, "VOLTAGE_RANGE_5V", INT2NUM(VOLTAGE_RANGE_5V));
219
+ rb_define_const(ph_voltage_input, "VOLTAGE_RANGE_15V", INT2NUM(VOLTAGE_RANGE_15V));
220
+ rb_define_const(ph_voltage_input, "VOLTAGE_RANGE_40V", INT2NUM(VOLTAGE_RANGE_40V));
221
+ rb_define_const(ph_voltage_input, "VOLTAGE_RANGE_AUTO", INT2NUM(VOLTAGE_RANGE_AUTO));
222
+
223
+
224
+ /* Document-method: new
225
+ * call-seq: new
226
+ *
227
+ * Creates a Phidget VoltageInput object.
228
+ */
229
+ rb_define_method(ph_voltage_input, "initialize", ph_voltage_input_init, 0);
230
+
231
+ /* Document-method: getDataInterval
232
+ * call-seq: getDataInterval -> interval
233
+ *
234
+ * The DataInterval is the time that must elapse before the channel will fire another event.
235
+ * The data interval is bounded by MinDataInterval and MaxDataInterval.
236
+ * The timing between events can also affected by the change trigger values.
237
+ */
238
+ rb_define_method(ph_voltage_input, "getDataInterval", ph_voltage_input_get_data_interval, 0);
239
+ rb_define_alias(ph_voltage_input, "data_interval", "getDataInterval");
240
+
241
+ /* Document-method: setDataInterval
242
+ * call-seq: setDataInterval(interval)
243
+ *
244
+ * The DataInterval is the time that must elapse before the channel will fire another event.
245
+ * The data interval is bounded by MinDataInterval and MaxDataInterval.
246
+ * The timing between events can also affected by the change trigger values.
247
+ */
248
+ rb_define_method(ph_voltage_input, "setDataInterval", ph_voltage_input_set_data_interval, 1);
249
+ rb_define_alias(ph_voltage_input, "data_interval=", "setDataInterval");
250
+
251
+ /* Document-method: getMinDataInterval
252
+ * call-seq: getMinDataInterval -> interval
253
+ *
254
+ * The minimum value that DataInterval can be set to.
255
+ */
256
+ rb_define_method(ph_voltage_input, "getMinDataInterval", ph_voltage_input_get_min_data_interval, 0);
257
+ rb_define_alias(ph_voltage_input, "min_data_interval", "getMinDataInterval");
258
+
259
+ /* Document-method: getMaxDataInterval
260
+ * call-seq: getMaxDataInterval -> interval
261
+ *
262
+ * The maximum value that DataInterval can be set to.
263
+ */
264
+ rb_define_method(ph_voltage_input, "getMaxDataInterval", ph_voltage_input_get_max_data_interval, 0);
265
+ rb_define_alias(ph_voltage_input, "max_data_interval", "getMaxDataInterval");
266
+
267
+ /* Document-method: getPowerSupply
268
+ * call-seq: getPowerSupply -> power_supply
269
+ *
270
+ * Choose the power supply voltage.
271
+ * Set this to the voltage specified in the attached sensor's data sheet to power it.
272
+ * Set to POWER_SUPPLY_OFF to turn off the supply to save power.
273
+ */
274
+ rb_define_method(ph_voltage_input, "getPowerSupply", ph_voltage_input_get_power_supply, 0);
275
+ rb_define_alias(ph_voltage_input, "power_supply", "getPowerSupply");
276
+
277
+ /* Document-method: setPowerSupply
278
+ * call-seq: setPowerSupply(power_supply)
279
+ *
280
+ * Choose the power supply voltage.
281
+ * Set this to the voltage specified in the attached sensor's data sheet to power it.
282
+ * Set to POWER_SUPPLY_OFF to turn off the supply to save power.
283
+ */
284
+ rb_define_method(ph_voltage_input, "setPowerSupply", ph_voltage_input_set_power_supply, 1);
285
+ rb_define_alias(ph_voltage_input, "power_supply=", "setPowerSupply");
286
+
287
+ /* Document-method: getSensorType
288
+ * call-seq: getSensorType -> sensor_type
289
+ *
290
+ * By matching the SensorType to your analog sensor, the correct formula will automatically be applied to data when you get the SensorValue or subscribe to the SensorChange event.
291
+ * The SensorChange event has its own change trigger associated with it: SensorValueChangeTrigger.
292
+ * Any data from getting the SensorValue or subscribing to the SensorChange event will have a SensorUnit associated with it.
293
+ * Note: Unlike other properties such as DeviceSerialNumber or Channel, SensorType is set after the device is opened, not before.
294
+ */
295
+ rb_define_method(ph_voltage_input, "getSensorType", ph_voltage_input_get_sensor_type, 0);
296
+ rb_define_alias(ph_voltage_input, "sensor_type", "getSensorType");
297
+
298
+ /* Document-method: setSensorType
299
+ * call-seq: setSensorType(sensor_type)
300
+ *
301
+ * By matching the SensorType to your analog sensor, the correct formula will automatically be applied to data when you get the SensorValue or subscribe to the SensorChange event.
302
+ * The SensorChange event has its own change trigger associated with it: SensorValueChangeTrigger.
303
+ * Any data from getting the SensorValue or subscribing to the SensorChange event will have a SensorUnit associated with it.
304
+ * Note: Unlike other properties such as DeviceSerialNumber or Channel, SensorType is set after the device is opened, not before.
305
+ */
306
+ rb_define_method(ph_voltage_input, "setSensorType", ph_voltage_input_set_sensor_type, 1);
307
+ rb_define_alias(ph_voltage_input, "sensor_type=", "setSensorType");
308
+
309
+ /* Document-method: getSensorUnit
310
+ * call-seq: getSensorUnit -> sensor_unit
311
+ *
312
+ * The unit of measurement that applies to the sensor values of the SensorType that has been selected.
313
+ * Helps keep track of the type of information being calculated from the voltage input.
314
+ */
315
+ rb_define_method(ph_voltage_input, "getSensorUnit", ph_voltage_input_get_sensor_unit, 0);
316
+ rb_define_alias(ph_voltage_input, "sensor_unit", "getSensorUnit");
317
+
318
+ /* Document-method: getSensorValue
319
+ * call-seq: getSensorValue -> sensor_value
320
+ *
321
+ * The most recent sensor value that the channel has reported.
322
+ * Use SensorUnit to get the measurement units that are associated with the SensorValue.
323
+ */
324
+ rb_define_method(ph_voltage_input, "getSensorValue", ph_voltage_input_get_sensor_value, 0);
325
+ rb_define_alias(ph_voltage_input, "sensor_value", "getSensorValue");
326
+
327
+ /* Document-method: getSensorValueChangeTrigger
328
+ * call-seq: getSensorValueChangeTrigger -> trigger
329
+ *
330
+ * The channel will not issue a SensorChange event until the sensor value has changed by the amount specified by the SensorValueChangeTrigger.
331
+ * Setting the SensorChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
332
+ */
333
+ rb_define_method(ph_voltage_input, "getSensorValueChangeTrigger", ph_voltage_input_get_sensor_value_change_trigger, 0);
334
+ rb_define_alias(ph_voltage_input, "sensor_value_change_trigger", "getSensorValueChangeTrigger");
335
+
336
+ /* Document-method: setSensorValueChangeTrigger
337
+ * call-seq: setSensorValueChangeTrigger(trigger)
338
+ *
339
+ * The channel will not issue a SensorChange event until the sensor value has changed by the amount specified by the SensorValueChangeTrigger.
340
+ * Setting the SensorChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
341
+ */
342
+ rb_define_method(ph_voltage_input, "setSensorValueChangeTrigger", ph_voltage_input_set_sensor_value_change_trigger, 1);
343
+ rb_define_alias(ph_voltage_input, "sensor_value_change_trigger=", "setSensorValueChangeTrigger");
344
+
345
+ /* Document-method: getVoltage
346
+ * call-seq: getVoltage -> voltage
347
+ *
348
+ * The most recent voltage value that the channel has reported.
349
+ * This value will always be between MinVoltage and MaxVoltage.
350
+ */
351
+ rb_define_method(ph_voltage_input, "getVoltage", ph_voltage_input_get_voltage, 0);
352
+ rb_define_alias(ph_voltage_input, "voltage", "getVoltage");
353
+
354
+ /* Document-method: getMinVoltage
355
+ * call-seq: getMinVoltage -> voltage
356
+ *
357
+ * The minimum value the VoltageChange event will report.
358
+ */
359
+ rb_define_method(ph_voltage_input, "getMinVoltage", ph_voltage_input_get_min_voltage, 0);
360
+ rb_define_alias(ph_voltage_input, "min_voltage", "getMinVoltage");
361
+
362
+ /* Document-method: getMaxVoltage
363
+ * call-seq: getMaxVoltage -> voltage
364
+ *
365
+ * The maximum value the VoltageChange event will report.
366
+ */
367
+ rb_define_method(ph_voltage_input, "getMaxVoltage", ph_voltage_input_get_max_voltage, 0);
368
+ rb_define_alias(ph_voltage_input, "max_voltage", "getMaxVoltage");
369
+
370
+ /* Document-method: getVoltageChangeTrigger
371
+ * call-seq: getVoltageChangeTrigger -> trigger
372
+ *
373
+ * The channel will not issue a VoltageChange event until the voltage value has changed by the amount specified by the VoltageChangeTrigger.
374
+ * Setting the VoltageChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
375
+ */
376
+ rb_define_method(ph_voltage_input, "getVoltageChangeTrigger", ph_voltage_input_get_voltage_change_trigger, 0);
377
+ rb_define_alias(ph_voltage_input, "voltage_change_trigger", "getVoltageChangeTrigger");
378
+
379
+ /* Document-method: setVoltageChangeTrigger
380
+ * call-seq: setVoltageChangeTrigger(trigger)
381
+ *
382
+ * The channel will not issue a VoltageChange event until the voltage value has changed by the amount specified by the VoltageChangeTrigger.
383
+ * Setting the VoltageChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
384
+ */
385
+ rb_define_method(ph_voltage_input, "setVoltageChangeTrigger", ph_voltage_input_set_voltage_change_trigger, 1);
386
+ rb_define_alias(ph_voltage_input, "voltage_change_trigger=", "setVoltageChangeTrigger");
387
+
388
+ /* Document-method: getMinVoltageChangeTrigger
389
+ * call-seq: getMinVoltageChangeTrigger -> trigger
390
+ *
391
+ * The minimum value that VoltageChangeTrigger can be set to.
392
+ */
393
+ rb_define_method(ph_voltage_input, "getMinVoltageChangeTrigger", ph_voltage_input_get_min_voltage_change_trigger, 0);
394
+ rb_define_alias(ph_voltage_input, "min_voltage_change_trigger", "getMinVoltageChangeTrigger");
395
+
396
+ /* Document-method: getMaxVoltageChangeTrigger
397
+ * call-seq: getMaxVoltageChangeTrigger -> trigger
398
+ *
399
+ * The maximum value that VoltageChangeTrigger can be set to.
400
+ */
401
+ rb_define_method(ph_voltage_input, "getMaxVoltageChangeTrigger", ph_voltage_input_get_max_voltage_change_trigger, 0);
402
+ rb_define_alias(ph_voltage_input, "max_voltage_change_trigger", "getMaxVoltageChangeTrigger");
403
+
404
+ /* Document-method: getVoltageRange
405
+ * call-seq: getVoltageRange -> trigger
406
+ *
407
+ * The voltage range you choose should allow you to measure the full range of your input signal.
408
+ * A larger VoltageRange equates to less resolution.
409
+ * If a Saturation event occurs, increase the voltage range.
410
+ */
411
+ rb_define_method(ph_voltage_input, "getVoltageRange", ph_voltage_input_get_voltage_range, 0);
412
+ rb_define_alias(ph_voltage_input, "voltage_range", "getVoltageRange");
413
+
414
+ /* Document-method: setVoltageRange
415
+ * call-seq: setVoltageRange(voltage_range)
416
+ *
417
+ * The voltage range you choose should allow you to measure the full range of your input signal.
418
+ * A larger VoltageRange equates to less resolution.
419
+ * If a Saturation event occurs, increase the voltage range.
420
+ */
421
+ rb_define_method(ph_voltage_input, "setVoltageRange", ph_voltage_input_set_voltage_range, 1);
422
+ rb_define_alias(ph_voltage_input, "voltage_range=", "setVoltageRange");
423
+
424
+
425
+ rb_define_private_method(ph_voltage_input, "ext_setOnSensorChangeHandler", ph_voltage_input_set_on_sensor_change_handler, 1);
426
+ rb_define_private_method(ph_voltage_input, "ext_setOnVoltageChangeHandler", ph_voltage_input_set_on_voltage_change_handler, 1);
427
+ }
428
+
@@ -0,0 +1,167 @@
1
+
2
+ #include "phidgets.h"
3
+
4
+ #define VOLTAGE_OUTPUT_VOLTAGE_ASYNC_CALLBACK 0
5
+
6
+
7
+ VALUE ph_voltage_output_init(VALUE self) {
8
+ ph_data_t *ph = get_ph_data(self);
9
+ ph_raise(PhidgetVoltageOutput_create((PhidgetVoltageOutputHandle *)(&(ph->handle))));
10
+ return self;
11
+ }
12
+
13
+ VALUE ph_voltage_output_get_enabled(VALUE self) {
14
+ return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetVoltageOutput_getEnabled);
15
+ }
16
+
17
+ VALUE ph_voltage_output_set_enabled(VALUE self, VALUE enabled) {
18
+ ph_raise(PhidgetVoltageOutput_setEnabled((PhidgetVoltageOutputHandle)get_ph_handle(self), TYPE(enabled) == T_TRUE ? PTRUE : PFALSE));
19
+ return Qnil;
20
+ }
21
+
22
+ VALUE ph_voltage_output_get_voltage(VALUE self) {
23
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetVoltageOutput_getVoltage);
24
+ }
25
+
26
+ VALUE ph_voltage_output_set_voltage(VALUE self, VALUE voltage) {
27
+ ph_raise(PhidgetVoltageOutput_setVoltage((PhidgetVoltageOutputHandle)get_ph_handle(self), NUM2DBL(voltage)));
28
+ return Qnil;
29
+ }
30
+
31
+ VALUE ph_voltage_output_get_min_voltage(VALUE self) {
32
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetVoltageOutput_getMinVoltage);
33
+ }
34
+
35
+ VALUE ph_voltage_output_get_max_voltage(VALUE self) {
36
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetVoltageOutput_getMaxVoltage);
37
+ }
38
+
39
+ VALUE ph_voltage_output_get_voltage_output_range(VALUE self) {
40
+ return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetVoltageOutput_getVoltageOutputRange);
41
+ }
42
+
43
+ VALUE ph_voltage_output_set_voltage_output_range(VALUE self, VALUE output_range) {
44
+ ph_raise(PhidgetVoltageOutput_setVoltageOutputRange((PhidgetVoltageOutputHandle)get_ph_handle(self), NUM2INT(output_range)));
45
+ return Qnil;
46
+ }
47
+
48
+
49
+
50
+ void CCONV ph_voltage_output_voltage_async(PhidgetHandle phid, void *userPtr, PhidgetReturnCode res) {
51
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
52
+ callback_data->exit = true;
53
+ callback_data->arg1 = INT2NUM(res);
54
+ callback_data->arg2 = Qnil;
55
+ callback_data->arg3 = Qnil;
56
+ callback_data->arg4 = Qnil;
57
+ sem_post(&callback_data->callback_called);
58
+ }
59
+
60
+ VALUE ph_voltage_output_set_voltage_async(VALUE self, VALUE voltage, VALUE handler) {
61
+ ph_data_t *ph = get_ph_data(self);
62
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[VOLTAGE_OUTPUT_VOLTAGE_ASYNC_CALLBACK];
63
+ if( TYPE(handler) == T_NIL ) {
64
+ PhidgetVoltageOutput_setVoltage_async((PhidgetVoltageOutputHandle)ph->handle, NUM2DBL(voltage), NULL, (void *)NULL);
65
+ } else {
66
+ callback_data->exit = false;
67
+ callback_data->phidget = self;
68
+ callback_data->callback = handler;
69
+ PhidgetVoltageOutput_setVoltage_async((PhidgetVoltageOutputHandle)ph->handle, NUM2DBL(voltage), ph_voltage_output_voltage_async, (void *)callback_data);
70
+ ph_callback_thread(callback_data);
71
+ }
72
+ return Qnil;
73
+ }
74
+
75
+
76
+ void Init_voltage_output() {
77
+ VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
78
+ VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
79
+ VALUE ph_voltage_output = rb_define_class_under(ph_module, "VoltageOutput", ph_common);
80
+
81
+
82
+ rb_define_const(ph_voltage_output, "VOLTAGE_OUTPUT_RANGE_10V", INT2NUM(VOLTAGE_OUTPUT_RANGE_10V));
83
+ rb_define_const(ph_voltage_output, "VOLTAGE_OUTPUT_RANGE_5V", INT2NUM(VOLTAGE_OUTPUT_RANGE_5V));
84
+
85
+
86
+ /* Document-method: new
87
+ * call-seq: new
88
+ *
89
+ * Creates a Phidget VoltageOutput object.
90
+ */
91
+ rb_define_method(ph_voltage_output, "initialize", ph_voltage_output_init, 0);
92
+
93
+ /* Document-method: getEnabled
94
+ * call-seq: getEnabled -> enabled
95
+ *
96
+ * Enable the output voltage by setting Enabled to true.
97
+ * Disable the output by seting Enabled to false to save power.
98
+ */
99
+ rb_define_method(ph_voltage_output, "getEnabled", ph_voltage_output_get_enabled, 0);
100
+ rb_define_alias(ph_voltage_output, "enabled?", "getEnabled");
101
+
102
+ /* Document-method: setEnabled
103
+ * call-seq: setEnabled(enabled)
104
+ *
105
+ * Enable the output voltage by setting Enabled to true.
106
+ * Disable the output by seting Enabled to false to save power.
107
+ */
108
+ rb_define_method(ph_voltage_output, "setEnabled", ph_voltage_output_set_enabled, 1);
109
+ rb_define_alias(ph_voltage_output, "enabled=", "setEnabled");
110
+
111
+ /* Document-method: getVoltage
112
+ * call-seq: getVoltage -> voltage
113
+ *
114
+ * The voltage value that the channel will output.
115
+ * The Voltage value is bounded by MinVoltage and MaxVoltage.
116
+ * The voltage value will not be output until Enabled is set to true.
117
+ */
118
+ rb_define_method(ph_voltage_output, "getVoltage", ph_voltage_output_get_voltage, 0);
119
+ rb_define_alias(ph_voltage_output, "voltage", "getVoltage");
120
+
121
+ /* Document-method: setVoltage
122
+ * call-seq: setVoltage(voltage)
123
+ *
124
+ * The voltage value that the channel will output.
125
+ * The Voltage value is bounded by MinVoltage and MaxVoltage.
126
+ * The voltage value will not be output until Enabled is set to true.
127
+ */
128
+ rb_define_method(ph_voltage_output, "setVoltage", ph_voltage_output_set_voltage, 1);
129
+ rb_define_alias(ph_voltage_output, "voltage=", "setVoltage");
130
+
131
+ /* Document-method: getMinVoltage
132
+ * call-seq: getMinVoltage -> min_voltage
133
+ *
134
+ * The minimum value that Voltage can be set to.
135
+ */
136
+ rb_define_method(ph_voltage_output, "getMinVoltage", ph_voltage_output_get_min_voltage, 0);
137
+ rb_define_alias(ph_voltage_output, "min_voltage", "getMinVoltage");
138
+
139
+ /* Document-method: getMaxVoltage
140
+ * call-seq: getMaxVoltage -> max_voltage
141
+ *
142
+ * The maximum value that Voltage can be set to.
143
+ */
144
+ rb_define_method(ph_voltage_output, "getMaxVoltage", ph_voltage_output_get_max_voltage, 0);
145
+ rb_define_alias(ph_voltage_output, "max_voltage", "getMaxVoltage");
146
+
147
+ /* Document-method: getVoltageOutputRange
148
+ * call-seq: getVoltageOutputRange -> output_range
149
+ *
150
+ * Choose a VoltageOutputRange that best suits your application.
151
+ * Changing the VoltageOutputRange will also affect the MinVoltage and MaxVoltage values.
152
+ */
153
+ rb_define_method(ph_voltage_output, "getVoltageOutputRange", ph_voltage_output_get_voltage_output_range, 0);
154
+ rb_define_alias(ph_voltage_output, "voltage_output_range", "getVoltageOutputRange");
155
+
156
+ /* Document-method: setVoltageOutputRange
157
+ * call-seq: setVoltageOutputRange(output_range)
158
+ *
159
+ * Choose a VoltageOutputRange that best suits your application.
160
+ * Changing the VoltageOutputRange will also affect the MinVoltage and MaxVoltage values.
161
+ */
162
+ rb_define_method(ph_voltage_output, "setVoltageOutputRange", ph_voltage_output_set_voltage_output_range, 1);
163
+ rb_define_alias(ph_voltage_output, "voltage_output_range=", "setVoltageOutputRange");
164
+
165
+ rb_define_private_method(ph_voltage_output, "ext_setVoltage_async", ph_voltage_output_set_voltage_async, 2);
166
+ }
167
+