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.
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
@@ -1,24 +1,167 @@
1
1
 
2
2
  #include "phidgets.h"
3
3
 
4
+ #define FREQ_COUNTER_COUNT_CHANGE_CALLBACK 0
5
+ #define FREQ_COUNTER_FREQUENCY_CHANGE_CALLBACK 1
4
6
 
5
- VALUE ph_freq_init(VALUE self);
6
- VALUE ph_freq_get_frequency_input_count(VALUE self);
7
- VALUE ph_freq_reset(VALUE self, VALUE index);
8
- VALUE ph_freq_get_frequency(VALUE self, VALUE index);
9
- VALUE ph_freq_get_total_time(VALUE self, VALUE index);
10
- VALUE ph_freq_get_total_count(VALUE self, VALUE index);
11
- VALUE ph_freq_get_timeout(VALUE self, VALUE index);
12
- VALUE ph_freq_set_timeout(VALUE self, VALUE index, VALUE timeout);
13
- VALUE ph_freq_get_enabled(VALUE self, VALUE index);
14
- VALUE ph_freq_set_enabled(VALUE self, VALUE index, VALUE state);
15
- VALUE ph_freq_get_filter(VALUE self, VALUE index);
16
- VALUE ph_freq_set_filter(VALUE self, VALUE index, VALUE filter);
17
-
18
- #ifdef PH_CALLBACK
19
- VALUE ph_freq_set_on_count_handler(VALUE self, VALUE handler);
20
- int ph_freq_on_count(CPhidgetFrequencyCounterHandle phid, void *userPtr, int index, int time, int counts);
21
- #endif
7
+
8
+
9
+ VALUE ph_freq_init(VALUE self) {
10
+ ph_data_t *ph = get_ph_data(self);
11
+ ph_raise(PhidgetFrequencyCounter_create((PhidgetFrequencyCounterHandle *)(&(ph->handle))));
12
+ return self;
13
+ }
14
+
15
+ VALUE ph_freq_get_count(VALUE self) {
16
+ return ph_get_uint64(get_ph_handle(self), (phidget_get_uint64_func)PhidgetFrequencyCounter_getCount);
17
+ }
18
+
19
+ VALUE ph_freq_get_enabled(VALUE self) {
20
+ return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetFrequencyCounter_getEnabled);
21
+ }
22
+
23
+ VALUE ph_freq_set_enabled(VALUE self, VALUE state) {
24
+ ph_raise(PhidgetFrequencyCounter_setEnabled((PhidgetFrequencyCounterHandle)get_ph_handle(self), TYPE(state) == T_TRUE ? PTRUE : PFALSE));
25
+ return Qnil;
26
+ }
27
+
28
+ VALUE ph_freq_get_data_interval(VALUE self) {
29
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetFrequencyCounter_getDataInterval);
30
+ }
31
+
32
+ VALUE ph_freq_set_data_interval(VALUE self, VALUE interval) {
33
+ ph_raise(PhidgetFrequencyCounter_setDataInterval((PhidgetFrequencyCounterHandle)get_ph_handle(self), NUM2UINT(interval)));
34
+ return Qnil;
35
+ }
36
+
37
+ VALUE ph_freq_get_min_data_interval(VALUE self) {
38
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetFrequencyCounter_getMinDataInterval);
39
+ }
40
+
41
+ VALUE ph_freq_get_max_data_interval(VALUE self) {
42
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetFrequencyCounter_getMaxDataInterval);
43
+ }
44
+
45
+ VALUE ph_freq_get_filter_type(VALUE self) {
46
+ return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetFrequencyCounter_getFilterType);
47
+ }
48
+
49
+ VALUE ph_freq_set_filter_type(VALUE self, VALUE filter) {
50
+ ph_raise(PhidgetFrequencyCounter_setFilterType((PhidgetFrequencyCounterHandle)get_ph_handle(self), NUM2INT(filter)));
51
+ return Qnil;
52
+ }
53
+
54
+ VALUE ph_freq_get_frequency(VALUE self) {
55
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetFrequencyCounter_getFrequency);
56
+ }
57
+
58
+ VALUE ph_freq_get_max_frequency(VALUE self) {
59
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetFrequencyCounter_getMaxFrequency);
60
+ }
61
+
62
+ VALUE ph_freq_get_frequency_cutoff(VALUE self) {
63
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetFrequencyCounter_getFrequencyCutoff);
64
+ }
65
+
66
+ VALUE ph_freq_set_frequency_cutoff(VALUE self, VALUE cutoff) {
67
+ ph_raise(PhidgetFrequencyCounter_setFrequencyCutoff((PhidgetFrequencyCounterHandle)get_ph_handle(self), NUM2DBL(cutoff)));
68
+ return Qnil;
69
+ }
70
+
71
+ VALUE ph_freq_get_min_frequency_cutoff(VALUE self) {
72
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetFrequencyCounter_getMinFrequencyCutoff);
73
+ }
74
+
75
+ VALUE ph_freq_get_max_frequency_cutoff(VALUE self) {
76
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetFrequencyCounter_getMaxFrequencyCutoff);
77
+ }
78
+
79
+ VALUE ph_freq_get_input_mode(VALUE self) {
80
+ return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetFrequencyCounter_getInputMode);
81
+ }
82
+
83
+ VALUE ph_freq_set_input_mode(VALUE self, VALUE mode) {
84
+ ph_raise(PhidgetFrequencyCounter_setInputMode((PhidgetFrequencyCounterHandle)get_ph_handle(self), NUM2INT(mode)));
85
+ return Qnil;
86
+ }
87
+
88
+ VALUE ph_freq_get_power_supply(VALUE self) {
89
+ return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetFrequencyCounter_getPowerSupply);
90
+ }
91
+
92
+ VALUE ph_freq_set_power_supply(VALUE self, VALUE power_supply) {
93
+ ph_raise(PhidgetFrequencyCounter_setPowerSupply((PhidgetFrequencyCounterHandle)get_ph_handle(self), NUM2INT(power_supply)));
94
+ return Qnil;
95
+ }
96
+
97
+ VALUE ph_freq_reset(VALUE self) {
98
+ ph_raise(PhidgetFrequencyCounter_reset((PhidgetFrequencyCounterHandle)get_ph_handle(self)));
99
+ return Qnil;
100
+ }
101
+
102
+ VALUE ph_freq_get_time_elapsed(VALUE self) {
103
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetFrequencyCounter_getTimeElapsed);
104
+ }
105
+
106
+
107
+ void CCONV ph_freq_on_count_change(PhidgetFrequencyCounterHandle phid, void *userPtr, uint64_t counts, double timeChange) {
108
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
109
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
110
+ callback_data->arg1 = ULL2NUM(counts);
111
+ callback_data->arg2 = DBL2NUM(timeChange);
112
+ callback_data->arg3 = Qnil;
113
+ callback_data->arg4 = Qnil;
114
+ sem_post(&callback_data->callback_called);
115
+ }
116
+
117
+
118
+ VALUE ph_freq_set_on_count_change_handler(VALUE self, VALUE handler) {
119
+ ph_data_t *ph = get_ph_data(self);
120
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[FREQ_COUNTER_COUNT_CHANGE_CALLBACK];
121
+ if( TYPE(handler) == T_NIL ) {
122
+ callback_data->callback = T_NIL;
123
+ callback_data->exit = true;
124
+ ph_raise(PhidgetFrequencyCounter_setOnCountChangeHandler((PhidgetFrequencyCounterHandle)ph->handle, NULL, (void *)NULL));
125
+ sem_post(&callback_data->callback_called);
126
+ } else {
127
+ callback_data->exit = false;
128
+ callback_data->phidget = self;
129
+ callback_data->callback = handler;
130
+ ph_raise(PhidgetFrequencyCounter_setOnCountChangeHandler((PhidgetFrequencyCounterHandle)ph->handle, ph_freq_on_count_change, (void *)callback_data));
131
+ ph_callback_thread(callback_data);
132
+ }
133
+ return Qnil;
134
+ }
135
+
136
+
137
+ void CCONV ph_freq_on_frequency_change(PhidgetFrequencyCounterHandle phid, void *userPtr, double frequency) {
138
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
139
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
140
+ callback_data->arg1 = DBL2NUM(frequency);
141
+ callback_data->arg2 = Qnil;
142
+ callback_data->arg3 = Qnil;
143
+ callback_data->arg4 = Qnil;
144
+ sem_post(&callback_data->callback_called);
145
+ }
146
+
147
+
148
+ VALUE ph_freq_set_on_frequency_change_handler(VALUE self, VALUE handler) {
149
+ ph_data_t *ph = get_ph_data(self);
150
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[FREQ_COUNTER_FREQUENCY_CHANGE_CALLBACK];
151
+ if( TYPE(handler) == T_NIL ) {
152
+ callback_data->callback = T_NIL;
153
+ callback_data->exit = true;
154
+ ph_raise(PhidgetFrequencyCounter_setOnFrequencyChangeHandler((PhidgetFrequencyCounterHandle)ph->handle, NULL, (void *)NULL));
155
+ sem_post(&callback_data->callback_called);
156
+ } else {
157
+ callback_data->exit = false;
158
+ callback_data->phidget = self;
159
+ callback_data->callback = handler;
160
+ ph_raise(PhidgetFrequencyCounter_setOnFrequencyChangeHandler((PhidgetFrequencyCounterHandle)ph->handle, ph_freq_on_frequency_change, (void *)callback_data));
161
+ ph_callback_thread(callback_data);
162
+ }
163
+ return Qnil;
164
+ }
22
165
 
23
166
 
24
167
  void Init_frequency_counter() {
@@ -26,9 +169,10 @@ void Init_frequency_counter() {
26
169
  VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
27
170
  VALUE ph_freq = rb_define_class_under(ph_module, "FrequencyCounter", ph_common);
28
171
 
29
- rb_define_const(ph_freq, "FILTERTYPE_ZERO_CROSSING", INT2FIX(PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_ZERO_CROSSING));
30
- rb_define_const(ph_freq, "FILTERTYPE_LOGIC_LEVEL", INT2FIX(PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_LOGIC_LEVEL));
31
- rb_define_const(ph_freq, "FILTERTYPE_UNKNOWN", INT2FIX(PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_UNKNOWN));
172
+
173
+ rb_define_const(ph_freq, "FILTER_TYPE_ZERO_CROSSING", INT2NUM(FILTER_TYPE_ZERO_CROSSING));
174
+ rb_define_const(ph_freq, "FILTER_TYPE_LOGIC_LEVEL", INT2NUM(FILTER_TYPE_LOGIC_LEVEL));
175
+
32
176
 
33
177
  /* Document-method: new
34
178
  * call-seq: new
@@ -37,205 +181,194 @@ void Init_frequency_counter() {
37
181
  */
38
182
  rb_define_method(ph_freq, "initialize", ph_freq_init, 0);
39
183
 
40
- /* Document-method: getFrequencyInputCount
41
- * call-seq: getFrequencyInputCount -> count
184
+ /* Document-method: getCount
185
+ * call-seq: getCount -> count
42
186
  *
43
- * Gets the number of inputs supported by this phidget frequency counter.
187
+ * The most recent count value the channel has reported.
188
+ * The count represents the total number of pulses since the the channel was opened, or last reset.
44
189
  */
45
- rb_define_method(ph_freq, "getFrequencyInputCount", ph_freq_get_frequency_input_count, 0);
190
+ rb_define_method(ph_freq, "getCount", ph_freq_get_count, 0);
191
+ rb_define_alias(ph_freq, "count", "getCount");
46
192
 
47
- /* Document-method: reset
48
- * call-seq: reset(index)
193
+ /* Document-method: getEnabled
194
+ * call-seq: getEnabled -> true or false
49
195
  *
50
- * Resets total count and total time for an input.
196
+ * Enables or disables the channel.
197
+ * When a channel is disabled, it will not longer register counts, therefore the TimeElapsed and Count will not be updated until the channel is re-enabled.
51
198
  */
52
- rb_define_method(ph_freq, "reset", ph_freq_reset, 1);
199
+ rb_define_method(ph_freq, "getEnabled", ph_freq_get_enabled, 0);
200
+ rb_define_alias(ph_freq, "enabled?", "getEnabled");
53
201
 
54
- /* Document-method: getFrequency
55
- * call-seq: getFrequency(index) -> frequency
202
+ /* Document-method: setEnabled
203
+ * call-seq: setEnabled(state)
56
204
  *
57
- * Gets the measured frequency of an input, in Hz.
205
+ * Enables or disables the channel.
206
+ * When a channel is disabled, it will not longer register counts, therefore the TimeElapsed and Count will not be updated until the channel is re-enabled.
58
207
  */
59
- rb_define_method(ph_freq, "getFrequency", ph_freq_get_frequency, 1);
208
+ rb_define_method(ph_freq, "setEnabled", ph_freq_set_enabled, 1);
209
+ rb_define_alias(ph_freq, "enabled=", "setEnabled");
60
210
 
61
- /* Document-method: getTotalTime
62
- * call-seq: getTotalTime(index) -> time
211
+ /* Document-method: getDataInterval
212
+ * call-seq: getDataInterval -> interval
63
213
  *
64
- * Gets the total time that has passed since the last reset on this input, in microseconds.
214
+ * The DataInterval is the time that must elapse before the channel will fire another CountChange/FrequencyChange event.
215
+ * The data interval is bounded by MinDataInterval and MaxDataInterval.
65
216
  */
66
- rb_define_method(ph_freq, "getTotalTime", ph_freq_get_total_time, 1);
217
+ rb_define_method(ph_freq, "getDataInterval", ph_freq_get_data_interval, 0);
218
+ rb_define_alias(ph_freq, "data_interval", "getDataInterval");
67
219
 
68
- /* Document-method: getTotalCount
69
- * call-seq: getTotalCount(index) -> count
220
+ /* Document-method: setDataInterval
221
+ * call-seq: setDataInterval(interval)
70
222
  *
71
- * Gets the total number of ticks that have happened since the last reset on this input.
223
+ * The DataInterval is the time that must elapse before the channel will fire another CountChange/FrequencyChange event.
224
+ * The data interval is bounded by MinDataInterval and MaxDataInterval.
72
225
  */
73
- rb_define_method(ph_freq, "getTotalCount", ph_freq_get_total_count, 1);
226
+ rb_define_method(ph_freq, "setDataInterval", ph_freq_set_data_interval, 1);
227
+ rb_define_alias(ph_freq, "data_interval=", "setDataInterval");
74
228
 
75
- /* Document-method: getTimeout
76
- * call-seq: getTimeout(index) -> timeout
229
+ /* Document-method: getMinDataInterval
230
+ * call-seq: getMinDataInterval -> interval
77
231
  *
78
- * Gets the timeout value for an input, in microseconds. This controls the lowest measurable frequency.
232
+ * The minimum value that DataInterval can be set to.
79
233
  */
80
- rb_define_method(ph_freq, "getTimeout", ph_freq_get_timeout, 1);
234
+ rb_define_method(ph_freq, "getMinDataInterval", ph_freq_get_min_data_interval, 0);
235
+ rb_define_alias(ph_freq, "min_data_interval", "getMinDataInterval");
81
236
 
82
- /* Document-method: setTimeout
83
- * call-seq: setTimeout(index, timeout)
237
+ /* Document-method: getMaxDataInterval
238
+ * call-seq: getMaxDataInterval -> interval
84
239
  *
85
- * Sets the timeout value for an input, in microseconds.
240
+ * The maximum value that DataInterval can be set to.
86
241
  */
87
- rb_define_method(ph_freq, "setTimeout", ph_freq_set_timeout, 2);
242
+ rb_define_method(ph_freq, "getMaxDataInterval", ph_freq_get_max_data_interval, 0);
243
+ rb_define_alias(ph_freq, "max_data_interval", "getMaxDataInterval");
88
244
 
89
- /* Document-method: getEnabled
90
- * call-seq: getEnabled(index) -> true or false
245
+ /* Document-method: getFilterType
246
+ * call-seq: getFilterType -> filter_type
91
247
  *
92
- * Gets the enabled state for an input.
248
+ * Determines the signal type that the channel responds to.
249
+ * The filter type is chosen based on the type of input signal. See the PhidgetFrequencyCounter_FilterType entry under Enumerations for more information.
93
250
  */
94
- rb_define_method(ph_freq, "getEnabled", ph_freq_get_enabled, 1);
251
+ rb_define_method(ph_freq, "getFilterType", ph_freq_get_filter_type, 0);
252
+ rb_define_alias(ph_freq, "filter_type", "getFilterType");
95
253
 
96
- /* Document-method: setEnabled
97
- * call-seq: setEnabled(index, state)
254
+ /* Document-method: setFilterType
255
+ * call-seq: setFilterType(filter_type)
98
256
  *
99
- * Sets the enabled state for an input.
257
+ * Determines the signal type that the channel responds to.
258
+ * The filter type is chosen based on the type of input signal. See the PhidgetFrequencyCounter_FilterType entry under Enumerations for more information.
100
259
  */
101
- rb_define_method(ph_freq, "setEnabled", ph_freq_set_enabled, 2);
260
+ rb_define_method(ph_freq, "setFilterType", ph_freq_set_filter_type, 1);
261
+ rb_define_alias(ph_freq, "filter_type=", "setFilterType");
102
262
 
103
- /* Document-method: getFilter
104
- * call-seq: getFilter(index) -> filter_type
263
+ /* Document-method: getFrequency
264
+ * call-seq: getFrequency -> frequency
105
265
  *
106
- * Gets the filter type for an input.
266
+ * The most recent frequency value that the channel has reported.
267
+ * This value will always be between 0 Hz and MaxFrequency.
107
268
  */
108
- rb_define_method(ph_freq, "getFilter", ph_freq_get_filter, 1);
269
+ rb_define_method(ph_freq, "getFrequency", ph_freq_get_frequency, 0);
270
+ rb_define_alias(ph_freq, "frequency", "getFrequency");
109
271
 
110
- /* Document-method: setFilter
111
- * call-seq: setFilter(index, filter_type)
272
+ /* Document-method: getMaxFrequency
273
+ * call-seq: getMaxFrequency -> frequency
112
274
  *
113
- * Sets the filter type for an input.
275
+ * The maximum value the FrequencyChange event will report.
114
276
  */
115
- rb_define_method(ph_freq, "setFilter", ph_freq_set_filter, 2);
116
-
117
- #ifdef PH_CALLBACK
118
- rb_define_private_method(ph_freq, "ext_setOnCountHandler", ph_freq_set_on_count_handler, 1);
119
- #endif
277
+ rb_define_method(ph_freq, "getMaxFrequency", ph_freq_get_max_frequency, 0);
278
+ rb_define_alias(ph_freq, "max_frequency", "getMaxFrequency");
120
279
 
121
- rb_define_alias(ph_freq, "frequency_input_count", "getFrequencyInputCount");
122
- rb_define_alias(ph_freq, "frequency", "getFrequency");
123
- rb_define_alias(ph_freq, "total_time", "getTotalTime");
124
- rb_define_alias(ph_freq, "total_count", "getTotalCount");
125
- rb_define_alias(ph_freq, "timeout", "getTimeout");
126
- rb_define_alias(ph_freq, "set_timeout", "setTimeout");
127
- rb_define_alias(ph_freq, "enabled?", "getEnabled");
128
- rb_define_alias(ph_freq, "set_enabled", "setEnabled");
129
- rb_define_alias(ph_freq, "filter", "getFilter");
130
- rb_define_alias(ph_freq, "set_filter", "setFilter");
131
- }
132
-
133
-
134
-
135
- VALUE ph_freq_init(VALUE self) {
136
- ph_data_t *ph = get_ph_data(self);
137
- ph_raise(CPhidgetFrequencyCounter_create((CPhidgetFrequencyCounterHandle *)(&(ph->handle))));
138
- return self;
139
- }
140
-
141
- VALUE ph_freq_get_frequency_input_count(VALUE self) {
142
- CPhidgetFrequencyCounterHandle handle = (CPhidgetFrequencyCounterHandle)get_ph_handle(self);
143
- int count;
144
- ph_raise(CPhidgetFrequencyCounter_getFrequencyInputCount(handle, &count));
145
- return INT2FIX(count);
146
- }
147
-
148
- VALUE ph_freq_reset(VALUE self, VALUE index) {
149
- CPhidgetFrequencyCounterHandle handle = (CPhidgetFrequencyCounterHandle)get_ph_handle(self);
150
- ph_raise(CPhidgetFrequencyCounter_reset(handle, FIX2INT(index)));
151
- return Qnil;
152
- }
153
-
154
- VALUE ph_freq_get_frequency(VALUE self, VALUE index) {
155
- CPhidgetFrequencyCounterHandle handle = (CPhidgetFrequencyCounterHandle)get_ph_handle(self);
156
- double freq;
157
- ph_raise(CPhidgetFrequencyCounter_getFrequency(handle, FIX2INT(index), &freq));
158
- return rb_float_new(freq);
159
- }
160
-
161
- VALUE ph_freq_get_total_time(VALUE self, VALUE index) {
162
- CPhidgetFrequencyCounterHandle handle = (CPhidgetFrequencyCounterHandle)get_ph_handle(self);
163
- __int64 time;
164
- ph_raise(CPhidgetFrequencyCounter_getTotalTime(handle, FIX2INT(index), &time));
165
- return INT2NUM(time);
166
- }
167
-
168
- VALUE ph_freq_get_total_count(VALUE self, VALUE index) {
169
- CPhidgetFrequencyCounterHandle handle = (CPhidgetFrequencyCounterHandle)get_ph_handle(self);
170
- __int64 count;
171
- ph_raise(CPhidgetFrequencyCounter_getTotalCount(handle, FIX2INT(index), &count));
172
- return INT2NUM(count);
173
- }
280
+ /* Document-method: getFrequencyCutoff
281
+ * call-seq: getFrequencyCutoff -> cutoff
282
+ *
283
+ * The frequency at which zero hertz is assumed.
284
+ * This means any frequency at or below the FrequencyCutoff value will be reported as 0 Hz.
285
+ * This property is stored locally, so other users who have this Phidget open over a network connection won't see the effects of your selected cutoff.
286
+ */
287
+ rb_define_method(ph_freq, "getFrequencyCutoff", ph_freq_get_frequency_cutoff, 0);
288
+ rb_define_alias(ph_freq, "frequency_cutoff", "getFrequencyCutoff");
174
289
 
175
- VALUE ph_freq_get_timeout(VALUE self, VALUE index) {
176
- CPhidgetFrequencyCounterHandle handle = (CPhidgetFrequencyCounterHandle)get_ph_handle(self);
177
- int timeout;
178
- ph_raise(CPhidgetFrequencyCounter_getTimeout(handle, FIX2INT(index), &timeout));
179
- return INT2FIX(timeout);
180
- }
290
+ /* Document-method: setFrequencyCutoff
291
+ * call-seq: setFrequencyCutoff(cutoff)
292
+ *
293
+ * The frequency at which zero hertz is assumed.
294
+ * This means any frequency at or below the FrequencyCutoff value will be reported as 0 Hz.
295
+ * This property is stored locally, so other users who have this Phidget open over a network connection won't see the effects of your selected cutoff.
296
+ */
297
+ rb_define_method(ph_freq, "setFrequencyCutoff", ph_freq_set_frequency_cutoff, 1);
298
+ rb_define_alias(ph_freq, "frequency_cutoff=", "setFrequencyCutoff");
181
299
 
182
- VALUE ph_freq_set_timeout(VALUE self, VALUE index, VALUE timeout) {
183
- CPhidgetFrequencyCounterHandle handle = (CPhidgetFrequencyCounterHandle)get_ph_handle(self);
184
- ph_raise(CPhidgetFrequencyCounter_setTimeout(handle, FIX2INT(index), FIX2INT(timeout)));
185
- return Qnil;
186
- }
300
+ /* Document-method: getMinFrequencyCutoff
301
+ * call-seq: getMinFrequencyCutoff -> cutoff
302
+ *
303
+ * The minimum value that FrequencyCutoff can be set to.
304
+ */
305
+ rb_define_method(ph_freq, "getMinFrequencyCutoff", ph_freq_get_min_frequency_cutoff, 0);
306
+ rb_define_alias(ph_freq, "min_frequency_cutoff", "getMinFrequencyCutoff");
187
307
 
188
- VALUE ph_freq_get_enabled(VALUE self, VALUE index) {
189
- CPhidgetFrequencyCounterHandle handle = (CPhidgetFrequencyCounterHandle)get_ph_handle(self);
190
- int state;
191
- ph_raise(CPhidgetFrequencyCounter_getEnabled(handle, FIX2INT(index), &state));
192
- return state == PTRUE ? Qtrue : Qfalse;
193
- }
308
+ /* Document-method: getMaxFrequencyCutoff
309
+ * call-seq: getMaxFrequencyCutoff -> cutoff
310
+ *
311
+ * The maximum value that FrequencyCutoff can be set to.
312
+ */
313
+ rb_define_method(ph_freq, "getMaxFrequencyCutoff", ph_freq_get_max_frequency_cutoff, 0);
314
+ rb_define_alias(ph_freq, "max_frequency_cutoff", "getMaxFrequencyCutoff");
194
315
 
195
- VALUE ph_freq_set_enabled(VALUE self, VALUE index, VALUE state) {
196
- CPhidgetFrequencyCounterHandle handle = (CPhidgetFrequencyCounterHandle)get_ph_handle(self);
197
- ph_raise(CPhidgetFrequencyCounter_setEnabled(handle, FIX2INT(index), TYPE(state) == T_TRUE ? PTRUE : PFALSE));
198
- return Qnil;
199
- }
316
+ /* Document-method: getInputMode
317
+ * call-seq: getInputMode -> mode
318
+ *
319
+ * The input polarity mode for your channel.
320
+ * See your device's User Guide for more information about what value to chooose for the InputMode.
321
+ */
322
+ rb_define_method(ph_freq, "getInputMode", ph_freq_get_input_mode, 0);
323
+ rb_define_alias(ph_freq, "input_mode", "getInputMode");
200
324
 
201
- VALUE ph_freq_get_filter(VALUE self, VALUE index) {
202
- CPhidgetFrequencyCounterHandle handle = (CPhidgetFrequencyCounterHandle)get_ph_handle(self);
203
- CPhidgetFrequencyCounter_FilterType filter;
204
- ph_raise(CPhidgetFrequencyCounter_getFilter(handle, FIX2INT(index), &filter));
205
- return INT2FIX(filter);
206
- }
325
+ /* Document-method: setInputMode
326
+ * call-seq: setInputMode(mode)
327
+ *
328
+ * The input polarity mode for your channel.
329
+ * See your device's User Guide for more information about what value to chooose for the InputMode.
330
+ */
331
+ rb_define_method(ph_freq, "setInputMode", ph_freq_set_input_mode, 1);
332
+ rb_define_alias(ph_freq, "input_mode=", "setInputMode");
207
333
 
208
- VALUE ph_freq_set_filter(VALUE self, VALUE index, VALUE filter) {
209
- CPhidgetFrequencyCounterHandle handle = (CPhidgetFrequencyCounterHandle)get_ph_handle(self);
210
- ph_raise(CPhidgetFrequencyCounter_setFilter(handle, FIX2INT(index), FIX2INT(filter)));
211
- return Qnil;
212
- }
334
+ /* Document-method: getPowerSupply
335
+ * call-seq: getPowerSupply -> power_supply
336
+ *
337
+ * Choose the power supply voltage.
338
+ * Set this to the voltage specified in the attached sensor's data sheet to power it.
339
+ * Set to POWER_SUPPLY_OFF to turn off the supply to save power.
340
+ */
341
+ rb_define_method(ph_freq, "getPowerSupply", ph_freq_get_power_supply, 0);
342
+ rb_define_alias(ph_freq, "power_supply", "getPowerSupply");
213
343
 
344
+ /* Document-method: setPowerSupply
345
+ * call-seq: setPowerSupply(power_supply)
346
+ *
347
+ * Choose the power supply voltage.
348
+ * Set this to the voltage specified in the attached sensor's data sheet to power it.
349
+ * Set to POWER_SUPPLY_OFF to turn off the supply to save power.
350
+ */
351
+ rb_define_method(ph_freq, "setPowerSupply", ph_freq_set_power_supply, 1);
352
+ rb_define_alias(ph_freq, "power_supply=", "setPowerSupply");
214
353
 
215
- #ifdef PH_CALLBACK
216
- VALUE ph_freq_set_on_count_handler(VALUE self, VALUE handler) {
217
- ph_data_t *ph = get_ph_data(self);
218
- ph_callback_data_t *callback_data = &ph->dev_callback_1;
219
- if( TYPE(handler) == T_NIL ) {
220
- callback_data->exit = true;
221
- ph_raise(CPhidgetFrequencyCounter_set_OnCount_Handler((CPhidgetFrequencyCounterHandle)ph->handle, NULL, (void *)NULL));
222
- } else {
223
- callback_data->called = false;
224
- callback_data->exit = false;
225
- callback_data->phidget = self;
226
- callback_data->callback = handler;
227
- ph_raise(CPhidgetFrequencyCounter_set_OnCount_Handler((CPhidgetFrequencyCounterHandle)ph->handle, ph_freq_on_count, (void *)callback_data));
228
- ph_callback_thread(callback_data);
229
- }
230
- return Qnil;
231
- }
354
+ /* Document-method: reset
355
+ * call-seq: reset
356
+ *
357
+ * Resets the Count and TimeElapsed.
358
+ * For best results, reset should be called when the channel is disabled.
359
+ */
360
+ rb_define_method(ph_freq, "reset", ph_freq_reset, 0);
232
361
 
362
+ /* Document-method: getTimeElapsed
363
+ * call-seq: getTimeElapsed -> time
364
+ *
365
+ * The amount of time the frequency counter has been enabled for.
366
+ * This property complements Count, the total number of pulses detected since the channel was opened, or last reset.
367
+ */
368
+ rb_define_method(ph_freq, "getTimeElapsed", ph_freq_get_time_elapsed, 0);
369
+ rb_define_alias(ph_freq, "time_elapsed", "getTimeElapsed");
233
370
 
234
- int ph_freq_on_count(CPhidgetFrequencyCounterHandle phid, void *userPtr, int index, int time, int counts) {
235
- ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
236
- callback_data->called = true;
237
- return EPHIDGET_OK;
371
+ rb_define_private_method(ph_freq, "ext_setOnCountChangeHandler", ph_freq_set_on_count_change_handler, 1);
372
+ rb_define_private_method(ph_freq, "ext_setOnFrequencyChangeHandler", ph_freq_set_on_frequency_change_handler, 1);
238
373
  }
239
374
 
240
- #endif
241
-