phidgets 0.1.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.txt +3 -0
- data/README.rdoc +32 -43
- data/Rakefile +4 -2
- data/bin/phidget +18 -72
- data/ext/phidgets/extconf.rb +5 -8
- data/ext/phidgets/phidgets.c +708 -173
- data/ext/phidgets/phidgets.h +54 -35
- data/ext/phidgets/phidgets_accelerometer.c +193 -109
- data/ext/phidgets/phidgets_bldc_motor.c +529 -0
- data/ext/phidgets/phidgets_capacitive_touch.c +302 -0
- data/ext/phidgets/phidgets_common.c +570 -315
- data/ext/phidgets/phidgets_current_input.c +229 -0
- data/ext/phidgets/phidgets_dc_motor.c +562 -0
- data/ext/phidgets/phidgets_dictionary.c +154 -213
- data/ext/phidgets/phidgets_digital_input.c +127 -0
- data/ext/phidgets/phidgets_digital_output.c +288 -0
- data/ext/phidgets/phidgets_distance_sensor.c +295 -0
- data/ext/phidgets/phidgets_encoder.c +211 -192
- data/ext/phidgets/phidgets_frequency_counter.c +310 -177
- data/ext/phidgets/phidgets_gps.c +226 -164
- data/ext/phidgets/phidgets_gyroscope.c +195 -0
- data/ext/phidgets/phidgets_hub.c +39 -0
- data/ext/phidgets/phidgets_humidity_sensor.c +200 -0
- data/ext/phidgets/phidgets_ir.c +211 -171
- data/ext/phidgets/phidgets_lcd.c +512 -0
- data/ext/phidgets/phidgets_light_sensor.c +200 -0
- data/ext/phidgets/phidgets_log.c +263 -0
- data/ext/phidgets/phidgets_magnetometer.c +279 -0
- data/ext/phidgets/phidgets_manager.c +86 -297
- data/ext/phidgets/phidgets_motor_position_controller.c +787 -0
- data/ext/phidgets/phidgets_phsensor.c +200 -152
- data/ext/phidgets/phidgets_power_guard.c +144 -0
- data/ext/phidgets/phidgets_pressure_sensor.c +200 -0
- data/ext/phidgets/phidgets_rc_servo.c +672 -0
- data/ext/phidgets/phidgets_resistance_input.c +227 -0
- data/ext/phidgets/phidgets_rfid.c +107 -221
- data/ext/phidgets/phidgets_sound_sensor.c +284 -0
- data/ext/phidgets/phidgets_spatial.c +124 -318
- data/ext/phidgets/phidgets_stepper.c +457 -430
- data/ext/phidgets/phidgets_temp_sensor.c +223 -228
- data/ext/phidgets/phidgets_voltage_input.c +428 -0
- data/ext/phidgets/phidgets_voltage_output.c +167 -0
- data/ext/phidgets/phidgets_voltage_ratio_input.c +435 -0
- data/lib/phidgets.rb +21 -14
- data/lib/phidgets/accelerometer.rb +11 -15
- data/lib/phidgets/bldc_motor.rb +45 -0
- data/lib/phidgets/capacitive_touch.rb +33 -0
- data/lib/phidgets/common.rb +40 -69
- data/lib/phidgets/current_input.rb +21 -0
- data/lib/phidgets/dc_motor.rb +45 -0
- data/lib/phidgets/dictionary.rb +30 -39
- data/lib/phidgets/digital_input.rb +21 -0
- data/lib/phidgets/digital_output.rb +56 -0
- data/lib/phidgets/distance_sensor.rb +33 -0
- data/lib/phidgets/encoder.rb +1 -29
- data/lib/phidgets/frequency_counter.rb +23 -14
- data/lib/phidgets/gps.rb +34 -26
- data/lib/phidgets/gyroscope.rb +21 -0
- data/lib/phidgets/humidity_sensor.rb +21 -0
- data/lib/phidgets/ir.rb +34 -39
- data/lib/phidgets/light_sensor.rb +21 -0
- data/lib/phidgets/magnetometer.rb +21 -0
- data/lib/phidgets/manager.rb +18 -66
- data/lib/phidgets/motor_position_controller.rb +45 -0
- data/lib/phidgets/ph_sensor.rb +2 -6
- data/lib/phidgets/pressure_sensor.rb +21 -0
- data/lib/phidgets/rc_servo.rb +58 -0
- data/lib/phidgets/resistance_input.rb +21 -0
- data/lib/phidgets/rfid.rb +22 -38
- data/lib/phidgets/sound_sensor.rb +21 -0
- data/lib/phidgets/spatial.rb +11 -15
- data/lib/phidgets/stepper.rb +48 -50
- data/lib/phidgets/temperature_sensor.rb +11 -15
- data/lib/phidgets/version.rb +5 -0
- data/lib/phidgets/voltage_input.rb +34 -0
- data/lib/phidgets/voltage_output.rb +23 -0
- data/lib/phidgets/voltage_ratio_input.rb +34 -0
- data/phidgets.gemspec +3 -22
- data/test/test_accelerometer.rb +42 -23
- data/test/test_bldc_motor.rb +134 -0
- data/test/test_capacitive_touch.rb +82 -0
- data/test/test_common.rb +125 -108
- data/test/test_current_input.rb +62 -0
- data/test/test_dc_motor.rb +146 -0
- data/test/test_dictionary.rb +22 -54
- data/test/test_digital_input.rb +30 -0
- data/test/test_digital_output.rb +70 -0
- data/test/test_distance_sensor.rb +76 -0
- data/test/test_encoder.rb +45 -38
- data/test/test_frequency_counter.rb +71 -36
- data/test/test_gps.rb +29 -38
- data/test/test_gyroscope.rb +54 -0
- data/test/test_helper.rb +0 -1
- data/test/test_hub.rb +14 -0
- data/test/test_humidity_sensor.rb +58 -0
- data/test/test_ir.rb +34 -34
- data/test/test_lcd.rb +146 -0
- data/test/test_light_sensor.rb +58 -0
- data/test/test_magnetometer.rb +78 -0
- data/test/test_manager.rb +10 -79
- data/test/test_motor_control.rb +146 -108
- data/test/test_phidgets.rb +2 -14
- data/test/test_phsensor.rb +46 -34
- data/test/test_power_guard.rb +42 -0
- data/test/test_pressure_sensor.rb +58 -0
- data/test/test_rc_servo.rb +174 -0
- data/test/test_resistance_input.rb +66 -0
- data/test/test_rfid.rb +15 -54
- data/test/test_sound_sensor.rb +78 -0
- data/test/test_spatial.rb +19 -85
- data/test/test_stepper.rb +89 -98
- data/test/test_temp_sensor.rb +42 -47
- data/test/test_voltage_input.rb +102 -0
- data/test/test_voltage_output.rb +46 -0
- data/test/test_voltage_ratio_input.rb +102 -0
- metadata +72 -89
- data/ext/phidgets/phidgets_advanced_servo.c +0 -567
- data/ext/phidgets/phidgets_analog.c +0 -139
- data/ext/phidgets/phidgets_bridge.c +0 -263
- data/ext/phidgets/phidgets_interface_kit.c +0 -340
- data/ext/phidgets/phidgets_led.c +0 -178
- data/ext/phidgets/phidgets_motor_control.c +0 -642
- data/ext/phidgets/phidgets_servo.c +0 -276
- data/ext/phidgets/phidgets_text_lcd.c +0 -381
- data/ext/phidgets/phidgets_text_led.c +0 -107
- data/ext/phidgets/phidgets_weight_sensor.c +0 -113
- data/lib/phidgets/advanced_servo.rb +0 -49
- data/lib/phidgets/analog.rb +0 -8
- data/lib/phidgets/bridge.rb +0 -25
- data/lib/phidgets/interfacekit.rb +0 -49
- data/lib/phidgets/led.rb +0 -8
- data/lib/phidgets/motor_control.rb +0 -110
- data/lib/phidgets/servo.rb +0 -23
- data/lib/phidgets/text_lcd.rb +0 -8
- data/lib/phidgets/text_led.rb +0 -8
- data/lib/phidgets/weight_sensor.rb +0 -25
- data/test/test_advanced_servo.rb +0 -152
- data/test/test_analog.rb +0 -45
- data/test/test_bridge.rb +0 -77
- data/test/test_interfacekit.rb +0 -97
- data/test/test_led.rb +0 -55
- data/test/test_servo.rb +0 -67
- data/test/test_text_lcd.rb +0 -115
- data/test/test_text_led.rb +0 -35
- data/test/test_weight_sensor.rb +0 -32
data/ext/phidgets/phidgets_gps.c
CHANGED
@@ -1,235 +1,297 @@
|
|
1
1
|
|
2
2
|
#include "phidgets.h"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
-
void Init_gps() {
|
25
|
-
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
26
|
-
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
27
|
-
VALUE ph_gps = rb_define_class_under(ph_module, "GPS", ph_common);
|
28
|
-
|
29
|
-
/* Document-method: new
|
30
|
-
* call-seq: new
|
31
|
-
*
|
32
|
-
* Creates a Phidget GPS object.
|
33
|
-
*/
|
34
|
-
rb_define_method(ph_gps, "initialize", ph_gps_init, 0);
|
35
|
-
|
36
|
-
/* Document-method: getLatitude
|
37
|
-
* call-seq: getLatitude -> latitude
|
38
|
-
*
|
39
|
-
* Gets the current latitude.
|
40
|
-
*/
|
41
|
-
rb_define_method(ph_gps, "getLatitude", ph_gps_get_latitude, 0);
|
42
|
-
|
43
|
-
/* Document-method: getLongitude
|
44
|
-
* call-seq: getLongitude -> longitude
|
45
|
-
*
|
46
|
-
* Gets the current longitude.
|
47
|
-
*/
|
48
|
-
rb_define_method(ph_gps, "getLongitude", ph_gps_get_longitude, 0);
|
49
|
-
|
50
|
-
/* Document-method: getAltitude
|
51
|
-
* call-seq: getAltitude -> altitude
|
52
|
-
*
|
53
|
-
* Gets the current altitude, in meters.
|
54
|
-
*/
|
55
|
-
rb_define_method(ph_gps, "getAltitude", ph_gps_get_altitude, 0);
|
56
|
-
|
57
|
-
/* Document-method: getHeading
|
58
|
-
* call-seq: getHeading -> heading
|
59
|
-
*
|
60
|
-
* Gets the current heading, in degrees.
|
61
|
-
*/
|
62
|
-
rb_define_method(ph_gps, "getHeading", ph_gps_get_heading, 0);
|
63
|
-
|
64
|
-
/* Document-method: getVelocity
|
65
|
-
* call-seq: getVelocity -> velocity
|
66
|
-
*
|
67
|
-
* Gets the current velocity, in km/h.
|
68
|
-
*/
|
69
|
-
rb_define_method(ph_gps, "getVelocity", ph_gps_get_velocity, 0);
|
70
|
-
|
71
|
-
/* Document-method: getTime
|
72
|
-
* call-seq: getTime -> time
|
73
|
-
*
|
74
|
-
* Gets the current GPS time, in UTC, as an array [hour, minute, second, millisecond].
|
75
|
-
*/
|
76
|
-
rb_define_method(ph_gps, "getTime", ph_gps_get_time, 0);
|
77
|
-
|
78
|
-
/* Document-method: getDate
|
79
|
-
* call-seq: getDate -> date
|
80
|
-
*
|
81
|
-
* Gets the current GPS date, in UTC, as an array [year, month, day].
|
82
|
-
*/
|
83
|
-
rb_define_method(ph_gps, "getDate", ph_gps_get_date, 0);
|
84
|
-
|
85
|
-
/* Document-method: getPositionFixStatus
|
86
|
-
* call-seq: getPositionFixStatus -> status
|
87
|
-
*
|
88
|
-
* Gets the position fix status.
|
89
|
-
*/
|
90
|
-
rb_define_method(ph_gps, "getPositionFixStatus", ph_gps_get_position_fix_status, 0);
|
91
|
-
|
92
|
-
/* Document-method: getNMEAData
|
93
|
-
* call-seq: getNMEAData -> data
|
94
|
-
*
|
95
|
-
* ** NOT IMPLEMENTED **
|
96
|
-
*/
|
97
|
-
rb_define_method(ph_gps, "getNMEAData", ph_gps_get_nmea_data, 0);
|
98
|
-
#ifdef PH_CALLBACK
|
99
|
-
rb_define_private_method(ph_gps, "ext_setOnPositionChangeHandler", ph_gps_set_on_position_change_handler, 1);
|
100
|
-
rb_define_private_method(ph_gps, "ext_setOnPositionFixStatusChangeHandler", ph_gps_set_on_position_fix_status_change_handler, 1);
|
101
|
-
#endif
|
102
|
-
|
103
|
-
rb_define_alias(ph_gps, "latitude", "getLatitude");
|
104
|
-
rb_define_alias(ph_gps, "longitude", "getLongitude");
|
105
|
-
rb_define_alias(ph_gps, "altitude", "getAltitude");
|
106
|
-
rb_define_alias(ph_gps, "heading", "getHeading");
|
107
|
-
rb_define_alias(ph_gps, "velocity", "getVelocity");
|
108
|
-
rb_define_alias(ph_gps, "time", "getTime");
|
109
|
-
rb_define_alias(ph_gps, "date", "getDate");
|
110
|
-
rb_define_alias(ph_gps, "position_fix_status", "getPositionFixStatus");
|
111
|
-
rb_define_alias(ph_gps, "nmea_data", "getNMEAData");
|
112
|
-
}
|
4
|
+
#define GPS_HEADING_CHANGE_CALLBACK 0
|
5
|
+
#define GPS_POSITION_CHANGE_CALLBACK 1
|
6
|
+
#define GPS_FIX_STATE_CHANGE_CALLBACK 2
|
113
7
|
|
114
8
|
|
115
9
|
|
116
10
|
VALUE ph_gps_init(VALUE self) {
|
117
11
|
ph_data_t *ph = get_ph_data(self);
|
118
|
-
ph_raise(
|
12
|
+
ph_raise(PhidgetGPS_create((PhidgetGPSHandle *)(&(ph->handle))));
|
119
13
|
return self;
|
120
14
|
}
|
121
15
|
|
122
16
|
VALUE ph_gps_get_latitude(VALUE self) {
|
123
|
-
|
124
|
-
double latitude;
|
125
|
-
ph_raise(CPhidgetGPS_getLatitude(handle, &latitude));
|
126
|
-
return rb_float_new(latitude);
|
17
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetGPS_getLatitude);
|
127
18
|
}
|
128
19
|
|
129
20
|
VALUE ph_gps_get_longitude(VALUE self) {
|
130
|
-
|
131
|
-
double longitude;
|
132
|
-
ph_raise(CPhidgetGPS_getLongitude(handle, &longitude));
|
133
|
-
return rb_float_new(longitude);
|
21
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetGPS_getLongitude);
|
134
22
|
}
|
135
23
|
|
136
24
|
VALUE ph_gps_get_altitude(VALUE self) {
|
137
|
-
|
138
|
-
double altitude;
|
139
|
-
ph_raise(CPhidgetGPS_getAltitude(handle, &altitude));
|
140
|
-
return rb_float_new(altitude);
|
25
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetGPS_getAltitude);
|
141
26
|
}
|
142
27
|
|
143
28
|
VALUE ph_gps_get_heading(VALUE self) {
|
144
|
-
|
145
|
-
double heading;
|
146
|
-
ph_raise(CPhidgetGPS_getHeading(handle, &heading));
|
147
|
-
return rb_float_new(heading);
|
29
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetGPS_getHeading);
|
148
30
|
}
|
149
31
|
|
150
32
|
VALUE ph_gps_get_velocity(VALUE self) {
|
151
|
-
|
152
|
-
double velocity;
|
153
|
-
ph_raise(CPhidgetGPS_getVelocity(handle, &velocity));
|
154
|
-
return rb_float_new(velocity);
|
33
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetGPS_getVelocity);
|
155
34
|
}
|
156
35
|
|
157
36
|
VALUE ph_gps_get_time(VALUE self) {
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
37
|
+
PhidgetGPSHandle handle = (PhidgetGPSHandle)get_ph_handle(self);
|
38
|
+
PhidgetGPS_Time time;
|
39
|
+
VALUE rb_time = rb_hash_new();
|
40
|
+
ph_raise(PhidgetGPS_getTime(handle, &time));
|
41
|
+
rb_hash_aset(rb_time, rb_str_new2("tm_hour"), INT2NUM(time.tm_hour));
|
42
|
+
rb_hash_aset(rb_time, rb_str_new2("tm_min"), INT2NUM(time.tm_min));
|
43
|
+
rb_hash_aset(rb_time, rb_str_new2("tm_sec"), INT2NUM(time.tm_sec));
|
44
|
+
rb_hash_aset(rb_time, rb_str_new2("tm_ms"), INT2NUM(time.tm_ms));
|
45
|
+
return rb_time;
|
162
46
|
}
|
163
47
|
|
164
48
|
VALUE ph_gps_get_date(VALUE self) {
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
49
|
+
PhidgetGPSHandle handle = (PhidgetGPSHandle)get_ph_handle(self);
|
50
|
+
PhidgetGPS_Date date;
|
51
|
+
VALUE rb_date = rb_hash_new();
|
52
|
+
ph_raise(PhidgetGPS_getDate(handle, &date));
|
53
|
+
rb_hash_aset(rb_date, rb_str_new2("tm_year"), INT2NUM(date.tm_year));
|
54
|
+
rb_hash_aset(rb_date, rb_str_new2("tm_mon"), INT2NUM(date.tm_mon));
|
55
|
+
rb_hash_aset(rb_date, rb_str_new2("tm_mday"), INT2NUM(date.tm_mday));
|
56
|
+
return rb_date;
|
169
57
|
}
|
170
58
|
|
171
|
-
VALUE
|
172
|
-
|
173
|
-
int state;
|
174
|
-
ph_raise(CPhidgetGPS_getPositionFixStatus(handle, &state));
|
175
|
-
return INT2FIX(state);
|
59
|
+
VALUE ph_gps_get_position_fix_state(VALUE self) {
|
60
|
+
return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetGPS_getPositionFixState);
|
176
61
|
}
|
177
62
|
|
178
63
|
VALUE ph_gps_get_nmea_data(VALUE self) {
|
179
|
-
|
180
|
-
|
64
|
+
PhidgetGPSHandle handle = (PhidgetGPSHandle)get_ph_handle(self);
|
65
|
+
PhidgetGPS_NMEAData nmea_data;
|
66
|
+
VALUE rb_gga_data = rb_hash_new();
|
67
|
+
VALUE rb_gsa_data = rb_hash_new();
|
68
|
+
VALUE rb_rmc_data = rb_hash_new();
|
69
|
+
VALUE rb_vtg_data = rb_hash_new();
|
70
|
+
VALUE rb_nmea_data = rb_hash_new();
|
71
|
+
VALUE sat_used = rb_ary_new();
|
72
|
+
int i;
|
73
|
+
|
74
|
+
ph_raise(PhidgetGPS_getNMEAData(handle, &nmea_data));
|
75
|
+
|
76
|
+
// GGA
|
77
|
+
rb_hash_aset(rb_gga_data, rb_str_new2("latitude"), DBL2NUM(nmea_data.GGA.latitude));
|
78
|
+
rb_hash_aset(rb_gga_data, rb_str_new2("longitude"), DBL2NUM(nmea_data.GGA.longitude));
|
79
|
+
rb_hash_aset(rb_gga_data, rb_str_new2("fixQuality"), INT2NUM(nmea_data.GGA.fixQuality));
|
80
|
+
rb_hash_aset(rb_gga_data, rb_str_new2("numSatellites"), INT2NUM(nmea_data.GGA.numSatellites));
|
81
|
+
rb_hash_aset(rb_gga_data, rb_str_new2("horizontalDilution"), DBL2NUM(nmea_data.GGA.horizontalDilution));
|
82
|
+
rb_hash_aset(rb_gga_data, rb_str_new2("altitude"), DBL2NUM(nmea_data.GGA.altitude));
|
83
|
+
rb_hash_aset(rb_gga_data, rb_str_new2("heightOfGeoid"), DBL2NUM(nmea_data.GGA.heightOfGeoid));
|
84
|
+
|
85
|
+
// GSA
|
86
|
+
rb_hash_aset(rb_gsa_data, rb_str_new2("mode"), INT2NUM(nmea_data.GSA.mode));
|
87
|
+
rb_hash_aset(rb_gsa_data, rb_str_new2("fixType"), INT2NUM(nmea_data.GSA.fixType));
|
88
|
+
for(i=0; i<12; i++) {rb_ary_push(sat_used, INT2NUM(nmea_data.GSA.satUsed[i]));}
|
89
|
+
rb_hash_aset(rb_gsa_data, rb_str_new2("satUsed"), sat_used);
|
90
|
+
rb_hash_aset(rb_gsa_data, rb_str_new2("posnDilution"), DBL2NUM(nmea_data.GSA.posnDilution));
|
91
|
+
rb_hash_aset(rb_gsa_data, rb_str_new2("horizDilution"), DBL2NUM(nmea_data.GSA.horizDilution));
|
92
|
+
rb_hash_aset(rb_gsa_data, rb_str_new2("vertDilution"), DBL2NUM(nmea_data.GSA.vertDilution));
|
93
|
+
|
94
|
+
// RMC
|
95
|
+
rb_hash_aset(rb_rmc_data, rb_str_new2("status"), INT2NUM(nmea_data.RMC.status));
|
96
|
+
rb_hash_aset(rb_rmc_data, rb_str_new2("latitude"), DBL2NUM(nmea_data.RMC.latitude));
|
97
|
+
rb_hash_aset(rb_rmc_data, rb_str_new2("longitude"), DBL2NUM(nmea_data.RMC.longitude));
|
98
|
+
rb_hash_aset(rb_rmc_data, rb_str_new2("speedKnots"), DBL2NUM(nmea_data.RMC.speedKnots));
|
99
|
+
rb_hash_aset(rb_rmc_data, rb_str_new2("heading"), DBL2NUM(nmea_data.RMC.heading));
|
100
|
+
rb_hash_aset(rb_rmc_data, rb_str_new2("magneticVariation"), DBL2NUM(nmea_data.RMC.magneticVariation));
|
101
|
+
rb_hash_aset(rb_rmc_data, rb_str_new2("mode"), INT2NUM(nmea_data.RMC.mode));
|
102
|
+
|
103
|
+
// VTG
|
104
|
+
rb_hash_aset(rb_vtg_data, rb_str_new2("trueHeading"), DBL2NUM(nmea_data.VTG.trueHeading));
|
105
|
+
rb_hash_aset(rb_vtg_data, rb_str_new2("magneticHeading"), DBL2NUM(nmea_data.VTG.magneticHeading));
|
106
|
+
rb_hash_aset(rb_vtg_data, rb_str_new2("speedKnots"), DBL2NUM(nmea_data.VTG.speedKnots));
|
107
|
+
rb_hash_aset(rb_vtg_data, rb_str_new2("speed"), DBL2NUM(nmea_data.VTG.speed));
|
108
|
+
rb_hash_aset(rb_vtg_data, rb_str_new2("mode"), INT2NUM(nmea_data.VTG.mode));
|
109
|
+
|
110
|
+
rb_hash_aset(rb_nmea_data, rb_str_new2("GGA"), rb_gga_data);
|
111
|
+
rb_hash_aset(rb_nmea_data, rb_str_new2("GSA"), rb_gsa_data);
|
112
|
+
rb_hash_aset(rb_nmea_data, rb_str_new2("RMC"), rb_rmc_data);
|
113
|
+
rb_hash_aset(rb_nmea_data, rb_str_new2("VTG"), rb_vtg_data);
|
114
|
+
return rb_nmea_data;
|
181
115
|
}
|
182
116
|
|
183
117
|
|
184
|
-
|
185
|
-
|
118
|
+
void CCONV ph_gps_on_heading_change(PhidgetGPSHandle phid, void *userPtr, double heading, double velocity) {
|
119
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
120
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
121
|
+
callback_data->arg1 = DBL2NUM(heading);
|
122
|
+
callback_data->arg2 = DBL2NUM(velocity);
|
123
|
+
callback_data->arg3 = Qnil;
|
124
|
+
callback_data->arg4 = Qnil;
|
125
|
+
sem_post(&callback_data->callback_called);
|
126
|
+
}
|
127
|
+
|
128
|
+
|
129
|
+
VALUE ph_gps_set_on_heading_change_handler(VALUE self, VALUE handler) {
|
186
130
|
ph_data_t *ph = get_ph_data(self);
|
187
|
-
ph_callback_data_t *callback_data = &ph->
|
131
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[GPS_HEADING_CHANGE_CALLBACK];
|
188
132
|
if( TYPE(handler) == T_NIL ) {
|
133
|
+
callback_data->callback = T_NIL;
|
189
134
|
callback_data->exit = true;
|
190
|
-
ph_raise(
|
135
|
+
ph_raise(PhidgetGPS_setOnHeadingChangeHandler((PhidgetGPSHandle)ph->handle, NULL, (void *)NULL));
|
136
|
+
sem_post(&callback_data->callback_called);
|
191
137
|
} else {
|
192
|
-
callback_data->called = false;
|
193
138
|
callback_data->exit = false;
|
194
139
|
callback_data->phidget = self;
|
195
140
|
callback_data->callback = handler;
|
196
|
-
ph_raise(
|
141
|
+
ph_raise(PhidgetGPS_setOnHeadingChangeHandler((PhidgetGPSHandle)ph->handle, ph_gps_on_heading_change, (void *)callback_data));
|
197
142
|
ph_callback_thread(callback_data);
|
198
143
|
}
|
199
144
|
return Qnil;
|
200
145
|
}
|
201
146
|
|
202
147
|
|
203
|
-
|
148
|
+
void CCONV ph_gps_on_position_change(PhidgetGPSHandle phid, void *userPtr, double latitude, double longitude, double altitude) {
|
149
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
150
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
151
|
+
callback_data->arg1 = DBL2NUM(latitude);
|
152
|
+
callback_data->arg2 = DBL2NUM(longitude);
|
153
|
+
callback_data->arg3 = DBL2NUM(altitude);
|
154
|
+
callback_data->arg4 = Qnil;
|
155
|
+
sem_post(&callback_data->callback_called);
|
156
|
+
}
|
157
|
+
|
158
|
+
|
159
|
+
VALUE ph_gps_set_on_position_change_handler(VALUE self, VALUE handler) {
|
204
160
|
ph_data_t *ph = get_ph_data(self);
|
205
|
-
ph_callback_data_t *callback_data = &ph->
|
161
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[GPS_POSITION_CHANGE_CALLBACK];
|
206
162
|
if( TYPE(handler) == T_NIL ) {
|
163
|
+
callback_data->callback = T_NIL;
|
207
164
|
callback_data->exit = true;
|
208
|
-
ph_raise(
|
165
|
+
ph_raise(PhidgetGPS_setOnPositionChangeHandler((PhidgetGPSHandle)ph->handle, NULL, (void *)NULL));
|
166
|
+
sem_post(&callback_data->callback_called);
|
209
167
|
} else {
|
210
|
-
callback_data->called = false;
|
211
168
|
callback_data->exit = false;
|
212
169
|
callback_data->phidget = self;
|
213
170
|
callback_data->callback = handler;
|
214
|
-
ph_raise(
|
171
|
+
ph_raise(PhidgetGPS_setOnPositionChangeHandler((PhidgetGPSHandle)ph->handle, ph_gps_on_position_change, (void *)callback_data));
|
215
172
|
ph_callback_thread(callback_data);
|
216
173
|
}
|
217
174
|
return Qnil;
|
218
175
|
}
|
219
176
|
|
220
177
|
|
221
|
-
|
178
|
+
void CCONV ph_gps_on_position_fix_state_change(PhidgetGPSHandle phid, void *userPtr, int state) {
|
222
179
|
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
223
|
-
callback_data->
|
224
|
-
|
180
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
181
|
+
callback_data->arg1 = state == PTRUE ? Qtrue : Qfalse;
|
182
|
+
callback_data->arg2 = Qnil;
|
183
|
+
callback_data->arg3 = Qnil;
|
184
|
+
callback_data->arg4 = Qnil;
|
185
|
+
sem_post(&callback_data->callback_called);
|
225
186
|
}
|
226
187
|
|
227
188
|
|
228
|
-
|
229
|
-
|
230
|
-
callback_data
|
231
|
-
|
189
|
+
VALUE ph_gps_set_on_position_fix_state_change_handler(VALUE self, VALUE handler) {
|
190
|
+
ph_data_t *ph = get_ph_data(self);
|
191
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[GPS_FIX_STATE_CHANGE_CALLBACK];
|
192
|
+
if( TYPE(handler) == T_NIL ) {
|
193
|
+
callback_data->callback = T_NIL;
|
194
|
+
callback_data->exit = true;
|
195
|
+
ph_raise(PhidgetGPS_setOnPositionFixStateChangeHandler((PhidgetGPSHandle)ph->handle, NULL, (void *)NULL));
|
196
|
+
sem_post(&callback_data->callback_called);
|
197
|
+
} else {
|
198
|
+
callback_data->exit = false;
|
199
|
+
callback_data->phidget = self;
|
200
|
+
callback_data->callback = handler;
|
201
|
+
ph_raise(PhidgetGPS_setOnPositionFixStateChangeHandler((PhidgetGPSHandle)ph->handle, ph_gps_on_position_fix_state_change, (void *)callback_data));
|
202
|
+
ph_callback_thread(callback_data);
|
203
|
+
}
|
204
|
+
return Qnil;
|
232
205
|
}
|
233
206
|
|
234
|
-
|
207
|
+
|
208
|
+
void Init_gps() {
|
209
|
+
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
210
|
+
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
211
|
+
VALUE ph_gps = rb_define_class_under(ph_module, "GPS", ph_common);
|
212
|
+
|
213
|
+
/* Document-method: new
|
214
|
+
* call-seq: new
|
215
|
+
*
|
216
|
+
* Creates a Phidget GPS object.
|
217
|
+
*/
|
218
|
+
rb_define_method(ph_gps, "initialize", ph_gps_init, 0);
|
219
|
+
|
220
|
+
/* Document-method: getLatitude
|
221
|
+
* call-seq: getLatitude -> latitude
|
222
|
+
*
|
223
|
+
* The latitude of the GPS in degrees.
|
224
|
+
*/
|
225
|
+
rb_define_method(ph_gps, "getLatitude", ph_gps_get_latitude, 0);
|
226
|
+
rb_define_alias(ph_gps, "latitude", "getLatitude");
|
227
|
+
|
228
|
+
/* Document-method: getLongitude
|
229
|
+
* call-seq: getLongitude -> longitude
|
230
|
+
*
|
231
|
+
* The longitude of the GPS.
|
232
|
+
*/
|
233
|
+
rb_define_method(ph_gps, "getLongitude", ph_gps_get_longitude, 0);
|
234
|
+
rb_define_alias(ph_gps, "longitude", "getLongitude");
|
235
|
+
|
236
|
+
/* Document-method: getAltitude
|
237
|
+
* call-seq: getAltitude -> altitude
|
238
|
+
*
|
239
|
+
* The altitude above mean sea level in meters.
|
240
|
+
*/
|
241
|
+
rb_define_method(ph_gps, "getAltitude", ph_gps_get_altitude, 0);
|
242
|
+
rb_define_alias(ph_gps, "altitude", "getAltitude");
|
243
|
+
|
244
|
+
/* Document-method: getHeading
|
245
|
+
* call-seq: getHeading -> heading
|
246
|
+
*
|
247
|
+
* The current true course over ground of the GPS.
|
248
|
+
*/
|
249
|
+
rb_define_method(ph_gps, "getHeading", ph_gps_get_heading, 0);
|
250
|
+
rb_define_alias(ph_gps, "heading", "getHeading");
|
251
|
+
|
252
|
+
/* Document-method: getVelocity
|
253
|
+
* call-seq: getVelocity -> velocity
|
254
|
+
*
|
255
|
+
* The current speed over ground of the GPS.
|
256
|
+
*/
|
257
|
+
rb_define_method(ph_gps, "getVelocity", ph_gps_get_velocity, 0);
|
258
|
+
rb_define_alias(ph_gps, "velocity", "getVelocity");
|
259
|
+
|
260
|
+
/* Document-method: getTime
|
261
|
+
* call-seq: getTime -> time
|
262
|
+
*
|
263
|
+
* The current UTC time of the GPS.
|
264
|
+
*/
|
265
|
+
rb_define_method(ph_gps, "getTime", ph_gps_get_time, 0);
|
266
|
+
rb_define_alias(ph_gps, "time", "getTime");
|
267
|
+
|
268
|
+
/* Document-method: getDate
|
269
|
+
* call-seq: getDate -> date
|
270
|
+
*
|
271
|
+
* The UTC date of the last received position.
|
272
|
+
*/
|
273
|
+
rb_define_method(ph_gps, "getDate", ph_gps_get_date, 0);
|
274
|
+
rb_define_alias(ph_gps, "date", "getDate");
|
275
|
+
|
276
|
+
/* Document-method: getPositionFixState
|
277
|
+
* call-seq: getPositionFixState -> fix_state
|
278
|
+
*
|
279
|
+
* The status of the position fix
|
280
|
+
* True if a fix is available and latitude, longitude, and altitude can be read. False if the fix is not available.
|
281
|
+
*/
|
282
|
+
rb_define_method(ph_gps, "getPositionFixState", ph_gps_get_position_fix_state, 0);
|
283
|
+
rb_define_alias(ph_gps, "position_fix?", "getPositionFixState");
|
284
|
+
|
285
|
+
/* Document-method: getNMEAData
|
286
|
+
* call-seq: getNMEAData -> nmea_data
|
287
|
+
*
|
288
|
+
* The NMEA data structure.
|
289
|
+
*/
|
290
|
+
rb_define_method(ph_gps, "getNMEAData", ph_gps_get_nmea_data, 0);
|
291
|
+
rb_define_alias(ph_gps, "nmea_data", "getNMEAData");
|
292
|
+
|
293
|
+
rb_define_private_method(ph_gps, "ext_setOnHeadingChangeHandler", ph_gps_set_on_heading_change_handler, 1);
|
294
|
+
rb_define_private_method(ph_gps, "ext_setOnPositionChangeHandler", ph_gps_set_on_position_change_handler, 1);
|
295
|
+
rb_define_private_method(ph_gps, "ext_setOnPositionFixStateChangeHandler", ph_gps_set_on_position_fix_state_change_handler, 1);
|
296
|
+
}
|
235
297
|
|