phidgets 0.0.5 → 0.1.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.
- data/History.txt +10 -2
- data/README.rdoc +41 -18
- data/Rakefile +31 -20
- data/bin/phidget +29 -44
- data/ext/phidgets/extconf.rb +14 -0
- data/ext/phidgets/phidgets.c +272 -0
- data/ext/phidgets/phidgets.h +82 -0
- data/ext/phidgets/phidgets_accelerometer.c +165 -0
- data/ext/phidgets/phidgets_advanced_servo.c +567 -0
- data/ext/phidgets/phidgets_analog.c +139 -0
- data/ext/phidgets/phidgets_bridge.c +263 -0
- data/ext/phidgets/phidgets_common.c +454 -0
- data/ext/phidgets/phidgets_dictionary.c +279 -0
- data/ext/phidgets/phidgets_encoder.c +249 -0
- data/ext/phidgets/phidgets_frequency_counter.c +241 -0
- data/ext/phidgets/phidgets_gps.c +235 -0
- data/ext/phidgets/phidgets_interface_kit.c +340 -0
- data/ext/phidgets/phidgets_ir.c +251 -0
- data/ext/phidgets/phidgets_led.c +178 -0
- data/ext/phidgets/phidgets_manager.c +366 -0
- data/ext/phidgets/phidgets_motor_control.c +642 -0
- data/ext/phidgets/phidgets_phsensor.c +208 -0
- data/ext/phidgets/phidgets_rfid.c +281 -0
- data/ext/phidgets/phidgets_servo.c +276 -0
- data/ext/phidgets/phidgets_spatial.c +369 -0
- data/ext/phidgets/phidgets_stepper.c +560 -0
- data/ext/phidgets/phidgets_temp_sensor.c +295 -0
- data/ext/phidgets/phidgets_text_lcd.c +381 -0
- data/ext/phidgets/phidgets_text_led.c +107 -0
- data/ext/phidgets/phidgets_weight_sensor.c +113 -0
- data/lib/phidgets/accelerometer.rb +25 -0
- data/lib/phidgets/advanced_servo.rb +49 -0
- data/lib/phidgets/analog.rb +8 -0
- data/lib/phidgets/bridge.rb +25 -0
- data/lib/phidgets/common.rb +75 -190
- data/lib/phidgets/dictionary.rb +53 -0
- data/lib/phidgets/encoder.rb +49 -0
- data/lib/phidgets/frequency_counter.rb +25 -0
- data/lib/phidgets/gps.rb +37 -0
- data/lib/phidgets/interfacekit.rb +38 -128
- data/lib/phidgets/ir.rb +50 -0
- data/lib/phidgets/led.rb +8 -0
- data/lib/phidgets/manager.rb +67 -119
- data/lib/phidgets/motor_control.rb +110 -0
- data/lib/phidgets/ph_sensor.rb +25 -0
- data/lib/phidgets/rfid.rb +38 -111
- data/lib/phidgets/servo.rb +12 -95
- data/lib/phidgets/spatial.rb +25 -0
- data/lib/phidgets/stepper.rb +61 -0
- data/lib/phidgets/temperature_sensor.rb +25 -0
- data/lib/phidgets/text_lcd.rb +8 -0
- data/lib/phidgets/text_led.rb +8 -0
- data/lib/phidgets/weight_sensor.rb +25 -0
- data/lib/phidgets.rb +22 -3
- data/phidgets.gemspec +42 -0
- data/test/test_accelerometer.rb +47 -0
- data/test/test_advanced_servo.rb +152 -0
- data/test/test_analog.rb +45 -0
- data/test/test_bridge.rb +77 -0
- data/test/test_common.rb +167 -0
- data/test/test_dictionary.rb +82 -0
- data/test/test_encoder.rb +67 -0
- data/test/test_frequency_counter.rb +67 -0
- data/test/test_gps.rb +67 -0
- data/test/test_helper.rb +1 -0
- data/test/test_interfacekit.rb +86 -182
- data/test/test_ir.rb +57 -0
- data/test/test_led.rb +55 -0
- data/test/test_manager.rb +94 -0
- data/test/test_motor_control.rb +172 -0
- data/test/test_phidgets.rb +14 -6
- data/test/test_phsensor.rb +62 -0
- data/test/test_rfid.rb +77 -0
- data/test/test_servo.rb +67 -0
- data/test/test_spatial.rb +112 -0
- data/test/test_stepper.rb +163 -0
- data/test/test_temp_sensor.rb +87 -0
- data/test/test_text_lcd.rb +115 -0
- data/test/test_text_led.rb +35 -0
- data/test/test_weight_sensor.rb +32 -0
- metadata +165 -75
- data/Manifest.txt +0 -21
- data/PostInstall.txt +0 -3
- data/README.txt +0 -87
- data/lib/phidgets/phidgets.rb +0 -225
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
@@ -0,0 +1,241 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
|
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
|
22
|
+
|
23
|
+
|
24
|
+
VALUE Init_phidgets_freq(VALUE ph_module, VALUE ph_common) {
|
25
|
+
VALUE ph_freq = rb_define_class_under(ph_module, "FrequencyCounter", ph_common);
|
26
|
+
|
27
|
+
rb_define_const(ph_freq, "FILTERTYPE_ZERO_CROSSING", INT2FIX(PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_ZERO_CROSSING));
|
28
|
+
rb_define_const(ph_freq, "FILTERTYPE_LOGIC_LEVEL", INT2FIX(PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_LOGIC_LEVEL));
|
29
|
+
rb_define_const(ph_freq, "FILTERTYPE_UNKNOWN", INT2FIX(PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_UNKNOWN));
|
30
|
+
|
31
|
+
/* Document-method: new
|
32
|
+
* call-seq: new
|
33
|
+
*
|
34
|
+
* Creates a Phidget FrequencyCounter object.
|
35
|
+
*/
|
36
|
+
rb_define_method(ph_freq, "initialize", ph_freq_init, 0);
|
37
|
+
|
38
|
+
/* Document-method: getFrequencyInputCount
|
39
|
+
* call-seq: getFrequencyInputCount -> count
|
40
|
+
*
|
41
|
+
* Gets the number of inputs supported by this phidget frequency counter.
|
42
|
+
*/
|
43
|
+
rb_define_method(ph_freq, "getFrequencyInputCount", ph_freq_get_frequency_input_count, 0);
|
44
|
+
|
45
|
+
/* Document-method: reset
|
46
|
+
* call-seq: reset(index)
|
47
|
+
*
|
48
|
+
* Resets total count and total time for an input.
|
49
|
+
*/
|
50
|
+
rb_define_method(ph_freq, "reset", ph_freq_reset, 1);
|
51
|
+
|
52
|
+
/* Document-method: getFrequency
|
53
|
+
* call-seq: getFrequency(index) -> frequency
|
54
|
+
*
|
55
|
+
* Gets the measured frequency of an input, in Hz.
|
56
|
+
*/
|
57
|
+
rb_define_method(ph_freq, "getFrequency", ph_freq_get_frequency, 1);
|
58
|
+
|
59
|
+
/* Document-method: getTotalTime
|
60
|
+
* call-seq: getTotalTime(index) -> time
|
61
|
+
*
|
62
|
+
* Gets the total time that has passed since the last reset on this input, in microseconds.
|
63
|
+
*/
|
64
|
+
rb_define_method(ph_freq, "getTotalTime", ph_freq_get_total_time, 1);
|
65
|
+
|
66
|
+
/* Document-method: getTotalCount
|
67
|
+
* call-seq: getTotalCount(index) -> count
|
68
|
+
*
|
69
|
+
* Gets the total number of ticks that have happened since the last reset on this input.
|
70
|
+
*/
|
71
|
+
rb_define_method(ph_freq, "getTotalCount", ph_freq_get_total_count, 1);
|
72
|
+
|
73
|
+
/* Document-method: getTimeout
|
74
|
+
* call-seq: getTimeout(index) -> timeout
|
75
|
+
*
|
76
|
+
* Gets the timeout value for an input, in microseconds. This controls the lowest measurable frequency.
|
77
|
+
*/
|
78
|
+
rb_define_method(ph_freq, "getTimeout", ph_freq_get_timeout, 1);
|
79
|
+
|
80
|
+
/* Document-method: setTimeout
|
81
|
+
* call-seq: setTimeout(index, timeout)
|
82
|
+
*
|
83
|
+
* Sets the timeout value for an input, in microseconds.
|
84
|
+
*/
|
85
|
+
rb_define_method(ph_freq, "setTimeout", ph_freq_set_timeout, 2);
|
86
|
+
|
87
|
+
/* Document-method: getEnabled
|
88
|
+
* call-seq: getEnabled(index) -> true or false
|
89
|
+
*
|
90
|
+
* Gets the enabled state for an input.
|
91
|
+
*/
|
92
|
+
rb_define_method(ph_freq, "getEnabled", ph_freq_get_enabled, 1);
|
93
|
+
|
94
|
+
/* Document-method: setEnabled
|
95
|
+
* call-seq: setEnabled(index, state)
|
96
|
+
*
|
97
|
+
* Sets the enabled state for an input.
|
98
|
+
*/
|
99
|
+
rb_define_method(ph_freq, "setEnabled", ph_freq_set_enabled, 2);
|
100
|
+
|
101
|
+
/* Document-method: getFilter
|
102
|
+
* call-seq: getFilter(index) -> filter_type
|
103
|
+
*
|
104
|
+
* Gets the filter type for an input.
|
105
|
+
*/
|
106
|
+
rb_define_method(ph_freq, "getFilter", ph_freq_get_filter, 1);
|
107
|
+
|
108
|
+
/* Document-method: setFilter
|
109
|
+
* call-seq: setFilter(index, filter_type)
|
110
|
+
*
|
111
|
+
* Sets the filter type for an input.
|
112
|
+
*/
|
113
|
+
rb_define_method(ph_freq, "setFilter", ph_freq_set_filter, 2);
|
114
|
+
|
115
|
+
#ifdef PH_CALLBACK
|
116
|
+
rb_define_private_method(ph_freq, "ext_setOnCountHandler", ph_freq_set_on_count_handler, 1);
|
117
|
+
#endif
|
118
|
+
|
119
|
+
rb_define_alias(ph_freq, "frequency_input_count", "getFrequencyInputCount");
|
120
|
+
rb_define_alias(ph_freq, "frequency", "getFrequency");
|
121
|
+
rb_define_alias(ph_freq, "total_time", "getTotalTime");
|
122
|
+
rb_define_alias(ph_freq, "total_count", "getTotalCount");
|
123
|
+
rb_define_alias(ph_freq, "timeout", "getTimeout");
|
124
|
+
rb_define_alias(ph_freq, "set_timeout", "setTimeout");
|
125
|
+
rb_define_alias(ph_freq, "enabled?", "getEnabled");
|
126
|
+
rb_define_alias(ph_freq, "set_enabled", "setEnabled");
|
127
|
+
rb_define_alias(ph_freq, "filter", "getFilter");
|
128
|
+
rb_define_alias(ph_freq, "set_filter", "setFilter");
|
129
|
+
|
130
|
+
return ph_freq;
|
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
|
+
}
|
174
|
+
|
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
|
+
}
|
181
|
+
|
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
|
+
}
|
187
|
+
|
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
|
+
}
|
194
|
+
|
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
|
+
}
|
200
|
+
|
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
|
+
}
|
207
|
+
|
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
|
+
}
|
213
|
+
|
214
|
+
|
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
|
+
}
|
232
|
+
|
233
|
+
|
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;
|
238
|
+
}
|
239
|
+
|
240
|
+
#endif
|
241
|
+
|
@@ -0,0 +1,235 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
|
5
|
+
VALUE ph_gps_init(VALUE self);
|
6
|
+
VALUE ph_gps_get_latitude(VALUE self);
|
7
|
+
VALUE ph_gps_get_longitude(VALUE self);
|
8
|
+
VALUE ph_gps_get_altitude(VALUE self);
|
9
|
+
VALUE ph_gps_get_heading(VALUE self);
|
10
|
+
VALUE ph_gps_get_velocity(VALUE self);
|
11
|
+
VALUE ph_gps_get_time(VALUE self);
|
12
|
+
VALUE ph_gps_get_date(VALUE self);
|
13
|
+
VALUE ph_gps_get_position_fix_status(VALUE self);
|
14
|
+
VALUE ph_gps_get_nmea_data(VALUE self);
|
15
|
+
|
16
|
+
#ifdef PH_CALLBACK
|
17
|
+
VALUE ph_gps_set_on_position_change_handler(VALUE self, VALUE handler);
|
18
|
+
VALUE ph_gps_set_on_position_fix_status_change_handler(VALUE self, VALUE handler);
|
19
|
+
int ph_gps_on_position_change(CPhidgetGPSHandle phid, void *userPtr, double latitude, double longitude, double altitude);
|
20
|
+
int ph_gps_on_position_fix_status_change(CPhidgetGPSHandle phid, void *userPtr, int status);
|
21
|
+
#endif
|
22
|
+
|
23
|
+
|
24
|
+
VALUE Init_phidgets_gps(VALUE ph_module, VALUE ph_common) {
|
25
|
+
VALUE ph_gps = rb_define_class_under(ph_module, "GPS", ph_common);
|
26
|
+
|
27
|
+
/* Document-method: new
|
28
|
+
* call-seq: new
|
29
|
+
*
|
30
|
+
* Creates a Phidget GPS object.
|
31
|
+
*/
|
32
|
+
rb_define_method(ph_gps, "initialize", ph_gps_init, 0);
|
33
|
+
|
34
|
+
/* Document-method: getLatitude
|
35
|
+
* call-seq: getLatitude -> latitude
|
36
|
+
*
|
37
|
+
* Gets the current latitude.
|
38
|
+
*/
|
39
|
+
rb_define_method(ph_gps, "getLatitude", ph_gps_get_latitude, 0);
|
40
|
+
|
41
|
+
/* Document-method: getLongitude
|
42
|
+
* call-seq: getLongitude -> longitude
|
43
|
+
*
|
44
|
+
* Gets the current longitude.
|
45
|
+
*/
|
46
|
+
rb_define_method(ph_gps, "getLongitude", ph_gps_get_longitude, 0);
|
47
|
+
|
48
|
+
/* Document-method: getAltitude
|
49
|
+
* call-seq: getAltitude -> altitude
|
50
|
+
*
|
51
|
+
* Gets the current altitude, in meters.
|
52
|
+
*/
|
53
|
+
rb_define_method(ph_gps, "getAltitude", ph_gps_get_altitude, 0);
|
54
|
+
|
55
|
+
/* Document-method: getHeading
|
56
|
+
* call-seq: getHeading -> heading
|
57
|
+
*
|
58
|
+
* Gets the current heading, in degrees.
|
59
|
+
*/
|
60
|
+
rb_define_method(ph_gps, "getHeading", ph_gps_get_heading, 0);
|
61
|
+
|
62
|
+
/* Document-method: getVelocity
|
63
|
+
* call-seq: getVelocity -> velocity
|
64
|
+
*
|
65
|
+
* Gets the current velocity, in km/h.
|
66
|
+
*/
|
67
|
+
rb_define_method(ph_gps, "getVelocity", ph_gps_get_velocity, 0);
|
68
|
+
|
69
|
+
/* Document-method: getTime
|
70
|
+
* call-seq: getTime -> time
|
71
|
+
*
|
72
|
+
* Gets the current GPS time, in UTC, as an array [hour, minute, second, millisecond].
|
73
|
+
*/
|
74
|
+
rb_define_method(ph_gps, "getTime", ph_gps_get_time, 0);
|
75
|
+
|
76
|
+
/* Document-method: getDate
|
77
|
+
* call-seq: getDate -> date
|
78
|
+
*
|
79
|
+
* Gets the current GPS date, in UTC, as an array [year, month, day].
|
80
|
+
*/
|
81
|
+
rb_define_method(ph_gps, "getDate", ph_gps_get_date, 0);
|
82
|
+
|
83
|
+
/* Document-method: getPositionFixStatus
|
84
|
+
* call-seq: getPositionFixStatus -> status
|
85
|
+
*
|
86
|
+
* Gets the position fix status.
|
87
|
+
*/
|
88
|
+
rb_define_method(ph_gps, "getPositionFixStatus", ph_gps_get_position_fix_status, 0);
|
89
|
+
|
90
|
+
/* Document-method: getNMEAData
|
91
|
+
* call-seq: getNMEAData -> data
|
92
|
+
*
|
93
|
+
* ** NOT IMPLEMENTED **
|
94
|
+
*/
|
95
|
+
rb_define_method(ph_gps, "getNMEAData", ph_gps_get_nmea_data, 0);
|
96
|
+
#ifdef PH_CALLBACK
|
97
|
+
rb_define_private_method(ph_gps, "ext_setOnPositionChangeHandler", ph_gps_set_on_position_change_handler, 1);
|
98
|
+
rb_define_private_method(ph_gps, "ext_setOnPositionFixStatusChangeHandler", ph_gps_set_on_position_fix_status_change_handler, 1);
|
99
|
+
#endif
|
100
|
+
|
101
|
+
rb_define_alias(ph_gps, "latitude", "getLatitude");
|
102
|
+
rb_define_alias(ph_gps, "longitude", "getLongitude");
|
103
|
+
rb_define_alias(ph_gps, "altitude", "getAltitude");
|
104
|
+
rb_define_alias(ph_gps, "heading", "getHeading");
|
105
|
+
rb_define_alias(ph_gps, "velocity", "getVelocity");
|
106
|
+
rb_define_alias(ph_gps, "time", "getTime");
|
107
|
+
rb_define_alias(ph_gps, "date", "getDate");
|
108
|
+
rb_define_alias(ph_gps, "position_fix_status", "getPositionFixStatus");
|
109
|
+
rb_define_alias(ph_gps, "nmea_data", "getNMEAData");
|
110
|
+
|
111
|
+
return ph_gps;
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
VALUE ph_gps_init(VALUE self) {
|
117
|
+
ph_data_t *ph = get_ph_data(self);
|
118
|
+
ph_raise(CPhidgetGPS_create((CPhidgetGPSHandle *)(&(ph->handle))));
|
119
|
+
return self;
|
120
|
+
}
|
121
|
+
|
122
|
+
VALUE ph_gps_get_latitude(VALUE self) {
|
123
|
+
CPhidgetGPSHandle handle = (CPhidgetGPSHandle)get_ph_handle(self);
|
124
|
+
double latitude;
|
125
|
+
ph_raise(CPhidgetGPS_getLatitude(handle, &latitude));
|
126
|
+
return rb_float_new(latitude);
|
127
|
+
}
|
128
|
+
|
129
|
+
VALUE ph_gps_get_longitude(VALUE self) {
|
130
|
+
CPhidgetGPSHandle handle = (CPhidgetGPSHandle)get_ph_handle(self);
|
131
|
+
double longitude;
|
132
|
+
ph_raise(CPhidgetGPS_getLongitude(handle, &longitude));
|
133
|
+
return rb_float_new(longitude);
|
134
|
+
}
|
135
|
+
|
136
|
+
VALUE ph_gps_get_altitude(VALUE self) {
|
137
|
+
CPhidgetGPSHandle handle = (CPhidgetGPSHandle)get_ph_handle(self);
|
138
|
+
double altitude;
|
139
|
+
ph_raise(CPhidgetGPS_getAltitude(handle, &altitude));
|
140
|
+
return rb_float_new(altitude);
|
141
|
+
}
|
142
|
+
|
143
|
+
VALUE ph_gps_get_heading(VALUE self) {
|
144
|
+
CPhidgetGPSHandle handle = (CPhidgetGPSHandle)get_ph_handle(self);
|
145
|
+
double heading;
|
146
|
+
ph_raise(CPhidgetGPS_getHeading(handle, &heading));
|
147
|
+
return rb_float_new(heading);
|
148
|
+
}
|
149
|
+
|
150
|
+
VALUE ph_gps_get_velocity(VALUE self) {
|
151
|
+
CPhidgetGPSHandle handle = (CPhidgetGPSHandle)get_ph_handle(self);
|
152
|
+
double velocity;
|
153
|
+
ph_raise(CPhidgetGPS_getVelocity(handle, &velocity));
|
154
|
+
return rb_float_new(velocity);
|
155
|
+
}
|
156
|
+
|
157
|
+
VALUE ph_gps_get_time(VALUE self) {
|
158
|
+
CPhidgetGPSHandle handle = (CPhidgetGPSHandle)get_ph_handle(self);
|
159
|
+
GPSTime time;
|
160
|
+
ph_raise(CPhidgetGPS_getTime(handle, &time));
|
161
|
+
return rb_ary_new3(4, INT2FIX(time.tm_hour), INT2FIX(time.tm_min), INT2FIX(time.tm_sec), INT2FIX(time.tm_ms));
|
162
|
+
}
|
163
|
+
|
164
|
+
VALUE ph_gps_get_date(VALUE self) {
|
165
|
+
CPhidgetGPSHandle handle = (CPhidgetGPSHandle)get_ph_handle(self);
|
166
|
+
GPSDate date;
|
167
|
+
ph_raise(CPhidgetGPS_getDate(handle, &date));
|
168
|
+
return rb_ary_new3(3, INT2FIX(date.tm_year), INT2FIX(date.tm_mon), INT2FIX(date.tm_mday));
|
169
|
+
}
|
170
|
+
|
171
|
+
VALUE ph_gps_get_position_fix_status(VALUE self) {
|
172
|
+
CPhidgetGPSHandle handle = (CPhidgetGPSHandle)get_ph_handle(self);
|
173
|
+
int state;
|
174
|
+
ph_raise(CPhidgetGPS_getPositionFixStatus(handle, &state));
|
175
|
+
return INT2FIX(state);
|
176
|
+
}
|
177
|
+
|
178
|
+
VALUE ph_gps_get_nmea_data(VALUE self) {
|
179
|
+
ph_raise(EPHIDGET_NOTIMPLEMENTED);
|
180
|
+
return Qnil;
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
#ifdef PH_CALLBACK
|
185
|
+
VALUE ph_gps_set_on_position_change_handler(VALUE self, VALUE handler) {
|
186
|
+
ph_data_t *ph = get_ph_data(self);
|
187
|
+
ph_callback_data_t *callback_data = &ph->dev_callback_1;
|
188
|
+
if( TYPE(handler) == T_NIL ) {
|
189
|
+
callback_data->exit = true;
|
190
|
+
ph_raise(CPhidgetGPS_set_OnPositionChange_Handler((CPhidgetGPSHandle)ph->handle, NULL, (void *)NULL));
|
191
|
+
} else {
|
192
|
+
callback_data->called = false;
|
193
|
+
callback_data->exit = false;
|
194
|
+
callback_data->phidget = self;
|
195
|
+
callback_data->callback = handler;
|
196
|
+
ph_raise(CPhidgetGPS_set_OnPositionChange_Handler((CPhidgetGPSHandle)ph->handle, ph_gps_on_position_change, (void *)callback_data));
|
197
|
+
ph_callback_thread(callback_data);
|
198
|
+
}
|
199
|
+
return Qnil;
|
200
|
+
}
|
201
|
+
|
202
|
+
|
203
|
+
VALUE ph_gps_set_on_position_fix_status_change_handler(VALUE self, VALUE handler) {
|
204
|
+
ph_data_t *ph = get_ph_data(self);
|
205
|
+
ph_callback_data_t *callback_data = &ph->dev_callback_2;
|
206
|
+
if( TYPE(handler) == T_NIL ) {
|
207
|
+
callback_data->exit = true;
|
208
|
+
ph_raise(CPhidgetGPS_set_OnPositionFixStatusChange_Handler((CPhidgetGPSHandle)ph->handle, NULL, (void *)NULL));
|
209
|
+
} else {
|
210
|
+
callback_data->called = false;
|
211
|
+
callback_data->exit = false;
|
212
|
+
callback_data->phidget = self;
|
213
|
+
callback_data->callback = handler;
|
214
|
+
ph_raise(CPhidgetGPS_set_OnPositionFixStatusChange_Handler((CPhidgetGPSHandle)ph->handle, ph_gps_on_position_fix_status_change, (void *)callback_data));
|
215
|
+
ph_callback_thread(callback_data);
|
216
|
+
}
|
217
|
+
return Qnil;
|
218
|
+
}
|
219
|
+
|
220
|
+
|
221
|
+
int ph_gps_on_position_change(CPhidgetGPSHandle phid, void *userPtr, double latitude, double longitude, double altitude) {
|
222
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
223
|
+
callback_data->called = true;
|
224
|
+
return EPHIDGET_OK;
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
int ph_gps_on_position_fix_status_change(CPhidgetGPSHandle phid, void *userPtr, int status) {
|
229
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
230
|
+
callback_data->called = true;
|
231
|
+
return EPHIDGET_OK;
|
232
|
+
}
|
233
|
+
|
234
|
+
#endif
|
235
|
+
|