phidgets_native 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/Gemfile +3 -0
- data/Gemfile.lock +12 -0
- data/README.rdoc +176 -0
- data/Rakefile +31 -0
- data/examples/gps.rb +25 -0
- data/examples/interface_kit.rb +61 -0
- data/examples/lib/common.rb +51 -0
- data/examples/lib/console_table.rb +38 -0
- data/examples/list_all.rb +16 -0
- data/examples/spatial.rb +53 -0
- data/ext/phidgets_native/accelerometer_ruby.c +36 -0
- data/ext/phidgets_native/advancedservo_ruby.c +33 -0
- data/ext/phidgets_native/analog_ruby.c +34 -0
- data/ext/phidgets_native/bridge_ruby.c +32 -0
- data/ext/phidgets_native/device.c +68 -0
- data/ext/phidgets_native/device_ruby.c +404 -0
- data/ext/phidgets_native/encoder_ruby.c +34 -0
- data/ext/phidgets_native/extconf.rb +18 -0
- data/ext/phidgets_native/frequencycounter_ruby.c +32 -0
- data/ext/phidgets_native/gps.c +102 -0
- data/ext/phidgets_native/gps_ruby.c +212 -0
- data/ext/phidgets_native/interfacekit.c +203 -0
- data/ext/phidgets_native/interfacekit_ruby.c +507 -0
- data/ext/phidgets_native/ir_ruby.c +33 -0
- data/ext/phidgets_native/led_ruby.c +33 -0
- data/ext/phidgets_native/motorcontrol_ruby.c +32 -0
- data/ext/phidgets_native/phidgets_native.c +197 -0
- data/ext/phidgets_native/phidgets_native.h +320 -0
- data/ext/phidgets_native/phidgets_native_ruby.c +468 -0
- data/ext/phidgets_native/phsensor_ruby.c +32 -0
- data/ext/phidgets_native/rfid_ruby.c +31 -0
- data/ext/phidgets_native/servo_ruby.c +31 -0
- data/ext/phidgets_native/spatial.c +168 -0
- data/ext/phidgets_native/spatial_ruby.c +533 -0
- data/ext/phidgets_native/stepper_ruby.c +32 -0
- data/ext/phidgets_native/temperaturesensor_ruby.c +31 -0
- data/ext/phidgets_native/textlcd_ruby.c +31 -0
- data/ext/phidgets_native/textled_ruby.c +31 -0
- data/ext/phidgets_native/weightsensor_ruby.c +32 -0
- data/phidgets_native.gemspec +21 -0
- metadata +96 -0
@@ -0,0 +1,212 @@
|
|
1
|
+
#include "phidgets_native.h"
|
2
|
+
|
3
|
+
/*
|
4
|
+
* Document-class: PhidgetsNative::GPS < PhidgetsNative::Device
|
5
|
+
*
|
6
|
+
* This class provides functionality specific to the "GPS" device class.
|
7
|
+
* Primarily, this includes reporting of latitude/longitude, velocity/heading
|
8
|
+
* and time.
|
9
|
+
*/
|
10
|
+
|
11
|
+
void Init_phidgets_native_gps(VALUE m_Phidget) {
|
12
|
+
VALUE c_Device = rb_const_get(m_Phidget, rb_intern("Device"));
|
13
|
+
|
14
|
+
VALUE c_Gps = rb_define_class_under(m_Phidget,"GPS",c_Device);
|
15
|
+
|
16
|
+
/*
|
17
|
+
* Document-method: new
|
18
|
+
* call-seq:
|
19
|
+
* new(serial_number)
|
20
|
+
*
|
21
|
+
* All phidget objects are created from the device serial number. Serial numbers
|
22
|
+
* are required to be Fixnums (aka "unsigned integers").
|
23
|
+
*/
|
24
|
+
rb_define_method(c_Gps, "initialize", gps_initialize, 1);
|
25
|
+
|
26
|
+
/*
|
27
|
+
* Document-method: close
|
28
|
+
* call-seq:
|
29
|
+
* close -> nil
|
30
|
+
*
|
31
|
+
* This method will unregister the phidget event handlers, and free up all
|
32
|
+
* API resources associated with the phidget. This is an optional, but useful
|
33
|
+
* way to remove the object's overhead before the GC kicks in and actually
|
34
|
+
* frees the resource.
|
35
|
+
*/
|
36
|
+
rb_define_method(c_Gps, "close", gps_close, 0);
|
37
|
+
|
38
|
+
/*
|
39
|
+
* Document-method: sample_rate
|
40
|
+
* call-seq:
|
41
|
+
* sample_rate -> FixNum
|
42
|
+
*
|
43
|
+
* For most Phidgets, an event handler processes the device state changes at
|
44
|
+
* some regular interval. For these devices, this method will return the rate
|
45
|
+
* of state changes measured in Hz.
|
46
|
+
*/
|
47
|
+
rb_define_method(c_Gps, "sample_rate", gps_sample_rate, 0);
|
48
|
+
|
49
|
+
/*
|
50
|
+
* Document-method: latitude
|
51
|
+
* call-seq:
|
52
|
+
* latitude -> Float
|
53
|
+
*
|
54
|
+
* Returns the current latititude, as reported by the most recent gps update.
|
55
|
+
*/
|
56
|
+
rb_define_method(c_Gps, "latitude", gps_latitude, 0);
|
57
|
+
|
58
|
+
/*
|
59
|
+
* Document-method: longitude
|
60
|
+
* call-seq:
|
61
|
+
* longitude -> Float
|
62
|
+
*
|
63
|
+
* Returns the current longitude, as reported by the most recent gps update.
|
64
|
+
*/
|
65
|
+
rb_define_method(c_Gps, "longitude", gps_longitude, 0);
|
66
|
+
|
67
|
+
/*
|
68
|
+
* Document-method: altitude
|
69
|
+
* call-seq:
|
70
|
+
* altitude -> Float
|
71
|
+
*
|
72
|
+
* Returns the current altitude in meters, as reported by the most recent gps update.
|
73
|
+
*/
|
74
|
+
rb_define_method(c_Gps, "altitude", gps_altitude, 0);
|
75
|
+
|
76
|
+
/*
|
77
|
+
* Document-method: heading
|
78
|
+
* call-seq:
|
79
|
+
* heading -> Float
|
80
|
+
*
|
81
|
+
* Returns the current heading in degrees, as reported by the most recent gps update.
|
82
|
+
*/
|
83
|
+
rb_define_method(c_Gps, "heading", gps_heading, 0);
|
84
|
+
|
85
|
+
/*
|
86
|
+
* Document-method: velocity
|
87
|
+
* call-seq:
|
88
|
+
* velocity -> Float
|
89
|
+
*
|
90
|
+
* Returns the current velocity in km/h, as reported by the most recent gps update.
|
91
|
+
*/
|
92
|
+
rb_define_method(c_Gps, "velocity", gps_velocity, 0);
|
93
|
+
|
94
|
+
/*
|
95
|
+
* Document-method: is_fixed?
|
96
|
+
* call-seq:
|
97
|
+
* is_fixed? -> Boolean
|
98
|
+
*
|
99
|
+
* Returns true or false, indicating whether the gps is fixed (aka "locked").
|
100
|
+
*/
|
101
|
+
rb_define_method(c_Gps, "is_fixed?", gps_is_fixed, 0);
|
102
|
+
|
103
|
+
/*
|
104
|
+
* Document-method: now_at_utc
|
105
|
+
* call-seq:
|
106
|
+
* now_at_utc -> Time
|
107
|
+
*
|
108
|
+
* Returns the GPS-reported time, in the UTC zone.
|
109
|
+
*/
|
110
|
+
rb_define_method(c_Gps, "now_at_utc", gps_now_at_utc, 0);
|
111
|
+
|
112
|
+
}
|
113
|
+
|
114
|
+
VALUE gps_initialize(VALUE self, VALUE serial) {
|
115
|
+
PhidgetInfo *info = device_info(self);
|
116
|
+
|
117
|
+
GpsInfo *gps_info = ALLOC(GpsInfo);
|
118
|
+
memset(gps_info, 0, sizeof(GpsInfo));
|
119
|
+
|
120
|
+
gps_info->sample_rate = sample_create();
|
121
|
+
|
122
|
+
CPhidgetGPSHandle gps = 0;
|
123
|
+
|
124
|
+
ensure(CPhidgetGPS_create(&gps));
|
125
|
+
|
126
|
+
ensure(CPhidgetGPS_set_OnPositionChange_Handler( gps, gps_on_position_change, info));
|
127
|
+
ensure(CPhidgetGPS_set_OnPositionFixStatusChange_Handler(gps, gps_on_fix_change, info));
|
128
|
+
|
129
|
+
info->handle = (CPhidgetHandle)gps;
|
130
|
+
info->on_type_detach = gps_on_detach;
|
131
|
+
info->on_type_free = gps_on_free;
|
132
|
+
info->type_info = gps_info;
|
133
|
+
|
134
|
+
return rb_call_super(1, &serial);
|
135
|
+
}
|
136
|
+
|
137
|
+
VALUE gps_close(VALUE self) {
|
138
|
+
PhidgetInfo *info = device_info(self);
|
139
|
+
|
140
|
+
ensure(CPhidgetGPS_set_OnPositionChange_Handler((CPhidgetGPSHandle)info->handle, NULL, NULL));
|
141
|
+
ensure(CPhidgetGPS_set_OnPositionFixStatusChange_Handler((CPhidgetGPSHandle)info->handle, NULL, NULL));
|
142
|
+
|
143
|
+
return rb_call_super(0,NULL);
|
144
|
+
}
|
145
|
+
|
146
|
+
VALUE gps_sample_rate(VALUE self) {
|
147
|
+
GpsInfo *gps_info = device_type_info(self);
|
148
|
+
|
149
|
+
return INT2FIX(gps_info->sample_rate->in_hz);
|
150
|
+
}
|
151
|
+
|
152
|
+
VALUE gps_latitude(VALUE self) {
|
153
|
+
GpsInfo *gps_info = device_type_info(self);
|
154
|
+
|
155
|
+
return (gps_info->is_latitude_known) ? DBL2NUM(gps_info->latitude) : Qnil;
|
156
|
+
}
|
157
|
+
|
158
|
+
VALUE gps_longitude(VALUE self) {
|
159
|
+
GpsInfo *gps_info = device_type_info(self);
|
160
|
+
|
161
|
+
return (gps_info->is_longitude_known) ? DBL2NUM(gps_info->longitude) : Qnil;
|
162
|
+
}
|
163
|
+
|
164
|
+
VALUE gps_altitude(VALUE self) {
|
165
|
+
GpsInfo *gps_info = device_type_info(self);
|
166
|
+
|
167
|
+
return (gps_info->is_altitude_known) ? DBL2NUM(gps_info->altitude) : Qnil;
|
168
|
+
}
|
169
|
+
|
170
|
+
VALUE gps_heading(VALUE self) {
|
171
|
+
GpsInfo *gps_info = device_type_info(self);
|
172
|
+
|
173
|
+
return (gps_info->is_heading_known) ? DBL2NUM(gps_info->heading) : Qnil;
|
174
|
+
}
|
175
|
+
|
176
|
+
VALUE gps_velocity(VALUE self) {
|
177
|
+
GpsInfo *gps_info = device_type_info(self);
|
178
|
+
|
179
|
+
return (gps_info->is_velocity_known) ? DBL2NUM(gps_info->velocity) : Qnil;
|
180
|
+
}
|
181
|
+
|
182
|
+
VALUE gps_is_fixed(VALUE self) {
|
183
|
+
GpsInfo *gps_info = device_type_info(self);
|
184
|
+
|
185
|
+
return (gps_info->is_fixed) ? Qtrue : Qfalse;
|
186
|
+
}
|
187
|
+
|
188
|
+
VALUE gps_now_at_utc(VALUE self) {
|
189
|
+
GpsInfo *gps_info = device_type_info(self);
|
190
|
+
|
191
|
+
if (!gps_info->is_now_at_utc_known) return Qnil;
|
192
|
+
|
193
|
+
VALUE c_Time = rb_const_get(rb_cObject, rb_intern("Time"));
|
194
|
+
|
195
|
+
char *now_as_string = ALLOC_N(char, 28);
|
196
|
+
sprintf(now_as_string, "%04d-%02d-%02d %02d:%02d:%02d.%03d UTC",
|
197
|
+
gps_info->now_at_utc.tm_year,
|
198
|
+
gps_info->now_at_utc.tm_mon,
|
199
|
+
gps_info->now_at_utc.tm_mday,
|
200
|
+
gps_info->now_at_utc.tm_hour,
|
201
|
+
gps_info->now_at_utc.tm_min,
|
202
|
+
gps_info->now_at_utc.tm_sec,
|
203
|
+
gps_info->now_at_utc_ms);
|
204
|
+
|
205
|
+
VALUE now = rb_funcall(c_Time, rb_intern("parse"), 2,
|
206
|
+
rb_str_new2(now_as_string),
|
207
|
+
rb_str_new2("%Y-%m-%d %H:%M:%S.%3N") );
|
208
|
+
|
209
|
+
xfree(now_as_string);
|
210
|
+
|
211
|
+
return now;
|
212
|
+
}
|
@@ -0,0 +1,203 @@
|
|
1
|
+
#include "phidgets_native.h"
|
2
|
+
|
3
|
+
int CCONV interfacekit_on_attach(CPhidgetHandle phid, void *userptr) {
|
4
|
+
PhidgetInfo *info = userptr;
|
5
|
+
InterfaceKitInfo *ifkit_info = info->type_info;
|
6
|
+
CPhidgetInterfaceKitHandle interfacekit = (CPhidgetInterfaceKitHandle) phid;
|
7
|
+
|
8
|
+
report(CPhidgetInterfaceKit_getInputCount(interfacekit, &ifkit_info->digital_input_count));
|
9
|
+
ifkit_info->is_digital_input_count_known = true;
|
10
|
+
|
11
|
+
report(CPhidgetInterfaceKit_getOutputCount(interfacekit, &ifkit_info->digital_output_count));
|
12
|
+
ifkit_info->is_digital_output_count_known = true;
|
13
|
+
|
14
|
+
report(CPhidgetInterfaceKit_getSensorCount(interfacekit, &ifkit_info->analog_input_count));
|
15
|
+
ifkit_info->is_analog_input_count_known = true;
|
16
|
+
|
17
|
+
// Allocate space for our state collections:
|
18
|
+
ifkit_info->digital_input_states = ALLOC_N(int, ifkit_info->digital_input_count);
|
19
|
+
ifkit_info->analog_input_states = ALLOC_N(int, ifkit_info->analog_input_count);
|
20
|
+
|
21
|
+
// Allocate our data_rate-related collections
|
22
|
+
if (ifkit_info->analog_input_count_prior != ifkit_info->analog_input_count) {
|
23
|
+
if(ifkit_info->data_rates) xfree(ifkit_info->data_rates);
|
24
|
+
if(ifkit_info->data_rates_max) xfree(ifkit_info->data_rates_max);
|
25
|
+
if(ifkit_info->data_rates_min) xfree(ifkit_info->data_rates_min);
|
26
|
+
if(ifkit_info->sensor_change_triggers) xfree(ifkit_info->sensor_change_triggers);
|
27
|
+
if(ifkit_info->digital_sample_rates) xfree(ifkit_info->digital_sample_rates);
|
28
|
+
if(ifkit_info->analog_sample_rates) xfree(ifkit_info->analog_sample_rates);
|
29
|
+
if(ifkit_info->digital_output_states) xfree(ifkit_info->digital_output_states);
|
30
|
+
|
31
|
+
ifkit_info->data_rates = ALLOC_N(int, ifkit_info->analog_input_count);
|
32
|
+
ifkit_info->data_rates_max = ALLOC_N(int, ifkit_info->analog_input_count);
|
33
|
+
ifkit_info->data_rates_min = ALLOC_N(int, ifkit_info->analog_input_count);
|
34
|
+
ifkit_info->sensor_change_triggers = ALLOC_N(int, ifkit_info->analog_input_count);
|
35
|
+
ifkit_info->digital_output_states = ALLOC_N(int, ifkit_info->digital_output_count);
|
36
|
+
|
37
|
+
ifkit_info->digital_sample_rates = ALLOC_N(SampleRate, ifkit_info->digital_input_count);
|
38
|
+
ifkit_info->analog_sample_rates = ALLOC_N(SampleRate, ifkit_info->analog_input_count);
|
39
|
+
|
40
|
+
memset(ifkit_info->digital_output_states, 0, sizeof(int) * ifkit_info->digital_output_count);
|
41
|
+
memset(ifkit_info->digital_sample_rates, 0, sizeof(SampleRate) * ifkit_info->digital_input_count);
|
42
|
+
memset(ifkit_info->analog_sample_rates, 0, sizeof(SampleRate) * ifkit_info->analog_input_count);
|
43
|
+
|
44
|
+
for(int i=0;i<ifkit_info->analog_input_count;i++) {
|
45
|
+
ifkit_info->data_rates[i] = DEFAULT_INTERFACEKIT_DATA_RATE;
|
46
|
+
ifkit_info->sensor_change_triggers[i] = DEFAULT_INTERFACEKIT_CHANGE_TRIGGER;
|
47
|
+
|
48
|
+
report(CPhidgetInterfaceKit_getDataRateMax(interfacekit, i, &ifkit_info->data_rates_max[i]));
|
49
|
+
report(CPhidgetInterfaceKit_getDataRateMin(interfacekit, i, &ifkit_info->data_rates_min[i]));
|
50
|
+
}
|
51
|
+
|
52
|
+
ifkit_info->is_data_rates_known = true;
|
53
|
+
}
|
54
|
+
|
55
|
+
// If the interfacekit isn't what we expect, we need to perform a change:
|
56
|
+
report(interfacekit_assert_ratiometric_state( info ));
|
57
|
+
|
58
|
+
// Set the data-rate/sensor-thresholds
|
59
|
+
for(int i=0;i<ifkit_info->analog_input_count;i++) {
|
60
|
+
if (ifkit_info->data_rates[i] > 0) {
|
61
|
+
report(CPhidgetInterfaceKit_setSensorChangeTrigger(interfacekit, i, 0));
|
62
|
+
report(CPhidgetInterfaceKit_setDataRate(interfacekit, i, ifkit_info->data_rates[i]));
|
63
|
+
} else {
|
64
|
+
report(CPhidgetInterfaceKit_setDataRate(interfacekit, i, 0));
|
65
|
+
report(CPhidgetInterfaceKit_setSensorChangeTrigger(interfacekit, i, ifkit_info->sensor_change_triggers[i]));
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
// Read in all of our initial input values:
|
70
|
+
for(int i=0; i<ifkit_info->digital_input_count; i++)
|
71
|
+
report(CPhidgetInterfaceKit_getInputState(interfacekit,i, &ifkit_info->digital_input_states[i]));
|
72
|
+
|
73
|
+
for(int i=0; i<ifkit_info->digital_output_count; i++)
|
74
|
+
report(CPhidgetInterfaceKit_setOutputState(interfacekit,i, ifkit_info->digital_output_states[i]));
|
75
|
+
|
76
|
+
for(int i=0; i<ifkit_info->analog_input_count; i++)
|
77
|
+
if (ifkit_info->rationmetric_changed_usec == 0)
|
78
|
+
// We only read these in if we haven't recently been changed ratiometric status:
|
79
|
+
report(CPhidgetInterfaceKit_getSensorValue(interfacekit,i, &ifkit_info->analog_input_states[i]));
|
80
|
+
else
|
81
|
+
ifkit_info->analog_input_states[i] = 0;
|
82
|
+
|
83
|
+
return 0;
|
84
|
+
}
|
85
|
+
|
86
|
+
int CCONV interfacekit_on_detach(CPhidgetHandle phid, void *userptr) {
|
87
|
+
PhidgetInfo *info = userptr;
|
88
|
+
InterfaceKitInfo *ifkit_info = info->type_info;
|
89
|
+
CPhidgetInterfaceKitHandle interfacekit = (CPhidgetInterfaceKitHandle)phid;
|
90
|
+
|
91
|
+
// This is used to determine whethere to preserve the allocated memory on reattach:
|
92
|
+
ifkit_info->analog_input_count_prior = ifkit_info->analog_input_count;
|
93
|
+
|
94
|
+
// Free the polled resources:
|
95
|
+
xfree(ifkit_info->digital_input_states);
|
96
|
+
ifkit_info->digital_input_states = NULL;
|
97
|
+
|
98
|
+
xfree(ifkit_info->analog_input_states);
|
99
|
+
ifkit_info->analog_input_states = NULL;
|
100
|
+
|
101
|
+
// Zero the sample trackers:
|
102
|
+
memset(ifkit_info->digital_sample_rates, 0, sizeof(SampleRate) * ifkit_info->digital_input_count);
|
103
|
+
memset(ifkit_info->analog_sample_rates, 0, sizeof(SampleRate) * ifkit_info->analog_input_count);
|
104
|
+
|
105
|
+
return 0;
|
106
|
+
}
|
107
|
+
|
108
|
+
void interfacekit_on_free(void *type_info) {
|
109
|
+
InterfaceKitInfo *ifkit_info = type_info;
|
110
|
+
|
111
|
+
if(ifkit_info->data_rates)
|
112
|
+
xfree(ifkit_info->data_rates);
|
113
|
+
if(ifkit_info->data_rates_min)
|
114
|
+
xfree(ifkit_info->data_rates_min);
|
115
|
+
if(ifkit_info->data_rates_max)
|
116
|
+
xfree(ifkit_info->data_rates_max);
|
117
|
+
if(ifkit_info->sensor_change_triggers)
|
118
|
+
xfree(ifkit_info->sensor_change_triggers);
|
119
|
+
if (ifkit_info->digital_input_states)
|
120
|
+
xfree(ifkit_info->digital_input_states);
|
121
|
+
if (ifkit_info->digital_output_states)
|
122
|
+
xfree(ifkit_info->digital_output_states);
|
123
|
+
if (ifkit_info->analog_input_states)
|
124
|
+
xfree(ifkit_info->analog_input_states);
|
125
|
+
if(ifkit_info->digital_sample_rates)
|
126
|
+
xfree(ifkit_info->digital_sample_rates);
|
127
|
+
if(ifkit_info->analog_sample_rates)
|
128
|
+
xfree(ifkit_info->analog_sample_rates);
|
129
|
+
if (ifkit_info)
|
130
|
+
xfree(ifkit_info);
|
131
|
+
return;
|
132
|
+
}
|
133
|
+
|
134
|
+
int interfacekit_on_digital_change(CPhidgetInterfaceKitHandle interfacekit, void *userptr, int index, int inputState) {
|
135
|
+
PhidgetInfo *info = userptr;
|
136
|
+
InterfaceKitInfo *ifkit_info = info->type_info;
|
137
|
+
|
138
|
+
sample_tick(&ifkit_info->digital_sample_rates[index], NULL);
|
139
|
+
|
140
|
+
if (ifkit_info->digital_input_states)
|
141
|
+
ifkit_info->digital_input_states[index] = inputState;
|
142
|
+
|
143
|
+
return 0;
|
144
|
+
}
|
145
|
+
|
146
|
+
int interfacekit_on_analog_change(CPhidgetInterfaceKitHandle interfacekit, void *userptr, int index, int sensorValue) {
|
147
|
+
PhidgetInfo *info = userptr;
|
148
|
+
InterfaceKitInfo *ifkit_info = info->type_info;
|
149
|
+
|
150
|
+
sample_tick(&ifkit_info->analog_sample_rates[index], NULL);
|
151
|
+
|
152
|
+
if (ifkit_info->analog_input_states) {
|
153
|
+
if (ifkit_info->rationmetric_changed_usec == 0)
|
154
|
+
ifkit_info->analog_input_states[index] = sensorValue;
|
155
|
+
else {
|
156
|
+
// We need to wait 50 milliseconds before accepting values after a ratiometric
|
157
|
+
// state change. If we're in this path, it's TBD whether 50 ms has passed
|
158
|
+
int usec_difference;
|
159
|
+
struct timeval now;
|
160
|
+
gettimeofday(&now, NULL);
|
161
|
+
|
162
|
+
usec_difference = ( now.tv_usec +
|
163
|
+
( (now.tv_usec < ifkit_info->rationmetric_changed_usec) ? 1000000 : 0) -
|
164
|
+
ifkit_info->rationmetric_changed_usec );
|
165
|
+
|
166
|
+
// Did we wait long enough between a ratiometric status change:
|
167
|
+
if ( usec_difference > INTERFACEKIT_RATIOMETRIC_RESET_USECS ) {
|
168
|
+
ifkit_info->rationmetric_changed_usec = 0;
|
169
|
+
|
170
|
+
// And sure, go ahead and accepti this value:
|
171
|
+
ifkit_info->analog_input_states[index] = sensorValue;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
return 0;
|
177
|
+
}
|
178
|
+
|
179
|
+
int interfacekit_assert_ratiometric_state(PhidgetInfo *info) {
|
180
|
+
InterfaceKitInfo *ifkit_info = info->type_info;
|
181
|
+
CPhidgetInterfaceKitHandle interfacekit = (CPhidgetInterfaceKitHandle) info->handle;
|
182
|
+
int ret = 0;
|
183
|
+
|
184
|
+
int is_ratiometric_already;
|
185
|
+
ret = CPhidgetInterfaceKit_getRatiometric(interfacekit, &is_ratiometric_already);
|
186
|
+
if (ret != EPHIDGET_OK) return ret;
|
187
|
+
|
188
|
+
if (ifkit_info->is_ratiometric != (ifkit_info->is_ratiometric == PTRUE) ) {
|
189
|
+
ret = CPhidgetInterfaceKit_setRatiometric(interfacekit, (ifkit_info->is_ratiometric) ? PTRUE : PFALSE );
|
190
|
+
if (ret != EPHIDGET_OK) return ret;
|
191
|
+
|
192
|
+
// Zero-out the analog struct:
|
193
|
+
memset(ifkit_info->analog_input_states, 0, sizeof(int) * ifkit_info->analog_input_count);
|
194
|
+
|
195
|
+
// We need to wait 50ms after this change before we start to read in values:
|
196
|
+
struct timeval now;
|
197
|
+
gettimeofday(&now, NULL);
|
198
|
+
|
199
|
+
ifkit_info->rationmetric_changed_usec = (now.tv_usec == 0) ? 1 : now.tv_usec;
|
200
|
+
}
|
201
|
+
|
202
|
+
return EPHIDGET_OK;
|
203
|
+
}
|