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,279 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
|
5
|
+
VALUE ph_dictionary_allocate(VALUE klass);
|
6
|
+
void ph_dictionary_free(ph_data_t *ph);
|
7
|
+
VALUE ph_dictionary_init(VALUE self);
|
8
|
+
VALUE ph_dictionary_open_remote(VALUE self, VALUE server_id, VALUE password);
|
9
|
+
VALUE ph_dictionary_open_remote_ip(VALUE self, VALUE address, VALUE port, VALUE password);
|
10
|
+
VALUE ph_dictionary_close(VALUE self);
|
11
|
+
VALUE ph_dictionary_get_key(VALUE self, VALUE key);
|
12
|
+
VALUE ph_dictionary_add_key(VALUE self, VALUE key, VALUE value, VALUE persist);
|
13
|
+
VALUE ph_dictionary_remove_key(VALUE self, VALUE pattern);
|
14
|
+
VALUE ph_dictionary_get_server_id(VALUE self);
|
15
|
+
VALUE ph_dictionary_get_server_address(VALUE self);
|
16
|
+
VALUE ph_dictionary_get_server_status(VALUE self);
|
17
|
+
|
18
|
+
#ifdef PH_CALLBACK
|
19
|
+
VALUE ph_dictionary_set_on_key_change_handler(VALUE self, VALUE handler);
|
20
|
+
VALUE ph_dictionary_remove_on_key_change_handler(VALUE self, VALUE listener);
|
21
|
+
VALUE ph_dictionary_set_on_server_connect_handler(VALUE self, VALUE handler);
|
22
|
+
VALUE ph_dictionary_set_on_server_disconnect_handler(VALUE self, VALUE handler);
|
23
|
+
int ph_dictionary_on_server_connect(CPhidgetDictionaryHandle phid, void *userPtr);
|
24
|
+
int ph_dictionary_on_server_disconnect(CPhidgetDictionaryHandle phid, void *userPtr);
|
25
|
+
#endif
|
26
|
+
|
27
|
+
|
28
|
+
VALUE Init_phidgets_dictionary(VALUE ph_module) {
|
29
|
+
VALUE ph_dictionary = rb_define_class_under(ph_module, "Dictionary", rb_cObject);
|
30
|
+
rb_define_alloc_func(ph_dictionary, ph_dictionary_allocate);
|
31
|
+
|
32
|
+
/* Document-method: new
|
33
|
+
* call-seq: new
|
34
|
+
*
|
35
|
+
* Creates a Phidget Dictionary object.
|
36
|
+
*/
|
37
|
+
rb_define_method(ph_dictionary, "initialize", ph_dictionary_init, 0);
|
38
|
+
|
39
|
+
/* Document-method: openRemote
|
40
|
+
* call-seq: openRemote(server_id, password)
|
41
|
+
*
|
42
|
+
* Opens a Phidget dictionary by ServerID. Note that this requires Bonjour (mDNS) to be running on both the host and the server.
|
43
|
+
*/
|
44
|
+
rb_define_method(ph_dictionary, "openRemote", ph_dictionary_open_remote, 2);
|
45
|
+
|
46
|
+
/* Document-method: openRemoteIP
|
47
|
+
* call-seq: openRemoteIP(address, port, password)
|
48
|
+
*
|
49
|
+
* Opens a Phidget dictionary by address and port.
|
50
|
+
*/
|
51
|
+
rb_define_method(ph_dictionary, "openRemoteIP", ph_dictionary_open_remote_ip, 3);
|
52
|
+
|
53
|
+
/* Document-method: close
|
54
|
+
* call-seq: close
|
55
|
+
*
|
56
|
+
* Closes the connection to a Phidget Dictionary.
|
57
|
+
*/
|
58
|
+
rb_define_method(ph_dictionary, "close", ph_dictionary_close, 0);
|
59
|
+
|
60
|
+
/* Document-method: getKey
|
61
|
+
* call-seq: getKey(key) -> value
|
62
|
+
*
|
63
|
+
* Gets a key value. If more then one key matches, only the first value is returned.
|
64
|
+
*/
|
65
|
+
rb_define_method(ph_dictionary, "getKey", ph_dictionary_get_key, 1);
|
66
|
+
|
67
|
+
/* Document-method: addKey
|
68
|
+
* call-seq: addKey(key, value, persistent)
|
69
|
+
*
|
70
|
+
* Adds a key/value pair to the dictionary. Or, changes an existing key's value.
|
71
|
+
*/
|
72
|
+
rb_define_method(ph_dictionary, "addKey", ph_dictionary_add_key, 3);
|
73
|
+
|
74
|
+
/* Document-method: removeKey
|
75
|
+
* call-seq: removeKey(pattern)
|
76
|
+
*
|
77
|
+
* Removes a set of keys from the dictionary.
|
78
|
+
*/
|
79
|
+
rb_define_method(ph_dictionary, "removeKey", ph_dictionary_remove_key, 1);
|
80
|
+
|
81
|
+
/* Document-method: getServerID
|
82
|
+
* call-seq: getServerID -> server_id
|
83
|
+
*
|
84
|
+
* Gets the server ID.
|
85
|
+
*/
|
86
|
+
rb_define_method(ph_dictionary, "getServerID", ph_dictionary_get_server_id, 0);
|
87
|
+
|
88
|
+
/* Document-method: getServerAddress
|
89
|
+
* call-seq: getServerAddress -> [address, port]
|
90
|
+
*
|
91
|
+
* Gets the address and port.
|
92
|
+
*/
|
93
|
+
rb_define_method(ph_dictionary, "getServerAddress", ph_dictionary_get_server_address, 0);
|
94
|
+
|
95
|
+
/* Document-method: getServerStatus
|
96
|
+
* call-seq: getServerStatus -> status
|
97
|
+
*
|
98
|
+
* Gets the connected to server status.
|
99
|
+
*/
|
100
|
+
rb_define_method(ph_dictionary, "getServerStatus", ph_dictionary_get_server_status, 0);
|
101
|
+
|
102
|
+
#ifdef PH_CALLBACK
|
103
|
+
|
104
|
+
/* Document-method: setOnKeyChangeHandler
|
105
|
+
* call-seq: setOnKeyChangeHandler(proc=nil, &block)
|
106
|
+
*
|
107
|
+
* ** NOT IMPLEMENTED **
|
108
|
+
*/
|
109
|
+
rb_define_method(ph_dictionary, "setOnKeyChangeHandler", ph_dictionary_set_on_key_change_handler, 1);
|
110
|
+
|
111
|
+
/* Document-method: removeOnKeyChangeHandler
|
112
|
+
* call-seq: removeOnKeyChangeHandler(listener)
|
113
|
+
*
|
114
|
+
* ** NOT IMPLEMENTED **
|
115
|
+
*/
|
116
|
+
rb_define_method(ph_dictionary, "removeOnKeyChangeHandler", ph_dictionary_remove_on_key_change_handler, 1);
|
117
|
+
rb_define_private_method(ph_dictionary, "ext_setOnServerConnectHandler", ph_dictionary_set_on_server_connect_handler, 1);
|
118
|
+
rb_define_private_method(ph_dictionary, "ext_setOnServerDisconnectHandler", ph_dictionary_set_on_server_disconnect_handler, 1);
|
119
|
+
rb_define_alias(ph_dictionary, "on_key_change", "setOnKeyChangeHandler");
|
120
|
+
rb_define_alias(ph_dictionary, "remove_on_key_change", "removeOnKeyChangeHandler");
|
121
|
+
#endif
|
122
|
+
|
123
|
+
rb_define_alias(ph_dictionary, "open_remote", "openRemote");
|
124
|
+
rb_define_alias(ph_dictionary, "open_remote_ip", "openRemoteIP");
|
125
|
+
rb_define_alias(ph_dictionary, "server_id", "getServerID");
|
126
|
+
rb_define_alias(ph_dictionary, "get_key", "getKey");
|
127
|
+
rb_define_alias(ph_dictionary, "add_key", "addKey");
|
128
|
+
rb_define_alias(ph_dictionary, "remove_key", "removeKey");
|
129
|
+
rb_define_alias(ph_dictionary, "server_address", "getServerAddress");
|
130
|
+
rb_define_alias(ph_dictionary, "server_status", "getServerStatus");
|
131
|
+
|
132
|
+
return ph_dictionary;
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
VALUE ph_dictionary_allocate(VALUE klass) {
|
138
|
+
ph_data_t *ph;
|
139
|
+
VALUE self = Data_Make_Struct(klass, ph_data_t, 0, ph_dictionary_free, ph);
|
140
|
+
memset(ph, 0, sizeof(ph_data_t));
|
141
|
+
return self;
|
142
|
+
}
|
143
|
+
|
144
|
+
void ph_dictionary_free(ph_data_t *ph) {
|
145
|
+
if (ph && ph->handle) {
|
146
|
+
CPhidgetDictionary_close((CPhidgetDictionaryHandle)ph->handle);
|
147
|
+
CPhidgetDictionary_delete((CPhidgetDictionaryHandle)ph->handle);
|
148
|
+
ph->handle = NULL;
|
149
|
+
}
|
150
|
+
if(ph) xfree(ph);
|
151
|
+
}
|
152
|
+
|
153
|
+
VALUE ph_dictionary_init(VALUE self) {
|
154
|
+
ph_data_t *ph = get_ph_data(self);
|
155
|
+
ph_raise(CPhidgetDictionary_create((CPhidgetDictionaryHandle *)(&(ph->handle))));
|
156
|
+
return self;
|
157
|
+
}
|
158
|
+
|
159
|
+
VALUE ph_dictionary_open_remote(VALUE self, VALUE server_id, VALUE password) {
|
160
|
+
CPhidgetDictionaryHandle handle = (CPhidgetDictionaryHandle)get_ph_handle(self);
|
161
|
+
ph_raise(CPhidgetDictionary_openRemote(handle, StringValueCStr(server_id), StringValueCStr(password)));
|
162
|
+
return Qnil;
|
163
|
+
}
|
164
|
+
|
165
|
+
VALUE ph_dictionary_open_remote_ip(VALUE self, VALUE address, VALUE port, VALUE password) {
|
166
|
+
CPhidgetDictionaryHandle handle = (CPhidgetDictionaryHandle)get_ph_handle(self);
|
167
|
+
ph_raise(CPhidgetDictionary_openRemoteIP(handle, StringValueCStr(address), FIX2INT(port), StringValueCStr(password)));
|
168
|
+
return Qnil;
|
169
|
+
}
|
170
|
+
|
171
|
+
VALUE ph_dictionary_close(VALUE self) {
|
172
|
+
CPhidgetDictionaryHandle handle = (CPhidgetDictionaryHandle)get_ph_handle(self);
|
173
|
+
ph_raise(CPhidgetDictionary_close(handle));
|
174
|
+
return Qnil;
|
175
|
+
}
|
176
|
+
|
177
|
+
VALUE ph_dictionary_get_key(VALUE self, VALUE key) {
|
178
|
+
#define VALUE_LEN 512
|
179
|
+
CPhidgetDictionaryHandle handle = (CPhidgetDictionaryHandle)get_ph_handle(self);
|
180
|
+
char value[VALUE_LEN];
|
181
|
+
ph_raise(CPhidgetDictionary_getKey(handle, StringValueCStr(key), value, VALUE_LEN));
|
182
|
+
return rb_str_new2(value);
|
183
|
+
}
|
184
|
+
|
185
|
+
VALUE ph_dictionary_add_key(VALUE self, VALUE key, VALUE value, VALUE persist) {
|
186
|
+
CPhidgetDictionaryHandle handle = (CPhidgetDictionaryHandle)get_ph_handle(self);
|
187
|
+
ph_raise(CPhidgetDictionary_addKey(handle, StringValueCStr(key), StringValueCStr(value), TYPE(persist) == T_TRUE ? PTRUE : PFALSE));
|
188
|
+
return Qnil;
|
189
|
+
}
|
190
|
+
|
191
|
+
VALUE ph_dictionary_remove_key(VALUE self, VALUE pattern) {
|
192
|
+
CPhidgetDictionaryHandle handle = (CPhidgetDictionaryHandle)get_ph_handle(self);
|
193
|
+
ph_raise(CPhidgetDictionary_removeKey(handle, StringValueCStr(pattern)));
|
194
|
+
return Qnil;
|
195
|
+
}
|
196
|
+
|
197
|
+
VALUE ph_dictionary_get_server_id(VALUE self) {
|
198
|
+
CPhidgetDictionaryHandle handle = (CPhidgetDictionaryHandle)get_ph_handle(self);
|
199
|
+
const char *server_id;
|
200
|
+
ph_raise(CPhidgetDictionary_getServerID(handle, &server_id));
|
201
|
+
return rb_str_new2(server_id);
|
202
|
+
}
|
203
|
+
|
204
|
+
VALUE ph_dictionary_get_server_address(VALUE self) {
|
205
|
+
CPhidgetDictionaryHandle handle = (CPhidgetDictionaryHandle)get_ph_handle(self);
|
206
|
+
const char *address;
|
207
|
+
int port;
|
208
|
+
ph_raise(CPhidgetDictionary_getServerAddress(handle, &address, &port));
|
209
|
+
return rb_ary_new3(2, rb_str_new2(address), INT2FIX(port));
|
210
|
+
}
|
211
|
+
|
212
|
+
VALUE ph_dictionary_get_server_status(VALUE self) {
|
213
|
+
CPhidgetDictionaryHandle handle = (CPhidgetDictionaryHandle)get_ph_handle(self);
|
214
|
+
int server_status;
|
215
|
+
ph_raise(CPhidgetDictionary_getServerStatus(handle, &server_status));
|
216
|
+
return INT2FIX(server_status);
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
#ifdef PH_CALLBACK
|
221
|
+
VALUE ph_dictionary_set_on_key_change_handler(VALUE self, VALUE handler) {
|
222
|
+
ph_raise(EPHIDGET_NOTIMPLEMENTED);
|
223
|
+
return Qnil;
|
224
|
+
}
|
225
|
+
|
226
|
+
VALUE ph_dictionary_remove_on_key_change_handler(VALUE self, VALUE listener) {
|
227
|
+
ph_raise(EPHIDGET_NOTIMPLEMENTED);
|
228
|
+
return Qnil;
|
229
|
+
}
|
230
|
+
|
231
|
+
VALUE ph_dictionary_set_on_server_connect_handler(VALUE self, VALUE handler) {
|
232
|
+
ph_data_t *ph = get_ph_data(self);
|
233
|
+
ph_callback_data_t *callback_data = &ph->server_connect_callback;
|
234
|
+
if( TYPE(handler) == T_NIL ) {
|
235
|
+
callback_data->exit = true;
|
236
|
+
ph_raise(CPhidgetDictionary_set_OnServerConnect_Handler((CPhidgetDictionaryHandle)ph->handle, NULL, (void *)NULL));
|
237
|
+
} else {
|
238
|
+
callback_data->called = false;
|
239
|
+
callback_data->exit = false;
|
240
|
+
callback_data->phidget = self;
|
241
|
+
callback_data->callback = handler;
|
242
|
+
ph_raise(CPhidgetDictionary_set_OnServerConnect_Handler((CPhidgetDictionaryHandle)ph->handle, ph_dictionary_on_server_connect, (void *)callback_data));
|
243
|
+
ph_callback_thread(callback_data);
|
244
|
+
}
|
245
|
+
return Qnil;
|
246
|
+
}
|
247
|
+
|
248
|
+
VALUE ph_dictionary_set_on_server_disconnect_handler(VALUE self, VALUE handler) {
|
249
|
+
ph_data_t *ph = get_ph_data(self);
|
250
|
+
ph_callback_data_t *callback_data = &ph->server_disconnect_callback;
|
251
|
+
if( TYPE(handler) == T_NIL ) {
|
252
|
+
callback_data->exit = true;
|
253
|
+
ph_raise(CPhidgetDictionary_set_OnServerDisconnect_Handler((CPhidgetDictionaryHandle)ph->handle, NULL, (void *)NULL));
|
254
|
+
} else {
|
255
|
+
callback_data->called = false;
|
256
|
+
callback_data->exit = false;
|
257
|
+
callback_data->phidget = self;
|
258
|
+
callback_data->callback = handler;
|
259
|
+
ph_raise(CPhidgetDictionary_set_OnServerDisconnect_Handler((CPhidgetDictionaryHandle)ph->handle, ph_dictionary_on_server_disconnect, (void *)callback_data));
|
260
|
+
ph_callback_thread(callback_data);
|
261
|
+
}
|
262
|
+
return Qnil;
|
263
|
+
}
|
264
|
+
|
265
|
+
|
266
|
+
int ph_dictionary_on_server_connect(CPhidgetDictionaryHandle phid, void *userPtr) {
|
267
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
268
|
+
callback_data->called = true;
|
269
|
+
return EPHIDGET_OK;
|
270
|
+
}
|
271
|
+
|
272
|
+
|
273
|
+
int ph_dictionary_on_server_disconnect(CPhidgetDictionaryHandle phid, void *userPtr) {
|
274
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
275
|
+
callback_data->called = true;
|
276
|
+
return EPHIDGET_OK;
|
277
|
+
}
|
278
|
+
#endif
|
279
|
+
|
@@ -0,0 +1,249 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
|
5
|
+
VALUE ph_encoder_init(VALUE self);
|
6
|
+
VALUE ph_encoder_get_input_count(VALUE self);
|
7
|
+
VALUE ph_encoder_get_input_state(VALUE self, VALUE index);
|
8
|
+
VALUE ph_encoder_get_encoder_count(VALUE self);
|
9
|
+
VALUE ph_encoder_get_position(VALUE self, VALUE index);
|
10
|
+
VALUE ph_encoder_set_position(VALUE self, VALUE index, VALUE position);
|
11
|
+
VALUE ph_encoder_get_index_position(VALUE self, VALUE index);
|
12
|
+
VALUE ph_encoder_get_enabled(VALUE self, VALUE index);
|
13
|
+
VALUE ph_encoder_set_enabled(VALUE self, VALUE index, VALUE state);
|
14
|
+
|
15
|
+
#ifdef PH_CALLBACK
|
16
|
+
VALUE ph_encoder_set_on_input_change_handler(VALUE self, VALUE handler);
|
17
|
+
VALUE ph_encoder_set_on_position_change_handler(VALUE self, VALUE handler);
|
18
|
+
VALUE ph_encoder_set_on_index_handler(VALUE self, VALUE handler);
|
19
|
+
int ph_encoder_on_input_change(CPhidgetEncoderHandle phid, void *userPtr, int index, int state);
|
20
|
+
int ph_encoder_on_position_change(CPhidgetEncoderHandle phid, void *userPtr, int index, int time, int change);
|
21
|
+
int ph_encoder_on_index(CPhidgetEncoderHandle phid, void *userPtr, int index, int index_pos);
|
22
|
+
#endif
|
23
|
+
|
24
|
+
|
25
|
+
VALUE Init_phidgets_encoder(VALUE ph_module, VALUE ph_common) {
|
26
|
+
VALUE ph_encoder = rb_define_class_under(ph_module, "Encoder", ph_common);
|
27
|
+
|
28
|
+
/* Document-method: new
|
29
|
+
* call-seq: new
|
30
|
+
*
|
31
|
+
* Creates a Phidget Encoder object.
|
32
|
+
*/
|
33
|
+
rb_define_method(ph_encoder, "initialize", ph_encoder_init, 0);
|
34
|
+
|
35
|
+
/* Document-method: getInputCount
|
36
|
+
* call-seq: getInputCount -> count
|
37
|
+
*
|
38
|
+
* Gets the number of digital inputs supported by this board.
|
39
|
+
*/
|
40
|
+
rb_define_method(ph_encoder, "getInputCount", ph_encoder_get_input_count, 0);
|
41
|
+
|
42
|
+
/* Document-method: getInputState
|
43
|
+
* call-seq: getInputState(index) -> true or false
|
44
|
+
*
|
45
|
+
* Gets the state of a digital input.
|
46
|
+
*/
|
47
|
+
rb_define_method(ph_encoder, "getInputState", ph_encoder_get_input_state, 1);
|
48
|
+
|
49
|
+
/* Document-method: getEncoderCount
|
50
|
+
* call-seq: getEncoderCount -> count
|
51
|
+
*
|
52
|
+
* Gets the number of encoder inputs supported by this board.
|
53
|
+
*/
|
54
|
+
rb_define_method(ph_encoder, "getEncoderCount", ph_encoder_get_encoder_count, 0);
|
55
|
+
|
56
|
+
/* Document-method: getPosition
|
57
|
+
* call-seq: getPosition(index) -> position
|
58
|
+
*
|
59
|
+
* Gets the current position of an encoder.
|
60
|
+
*/
|
61
|
+
rb_define_method(ph_encoder, "getPosition", ph_encoder_get_position, 1);
|
62
|
+
|
63
|
+
/* Document-method: setPosition
|
64
|
+
* call-seq: setPosition(index, position)
|
65
|
+
*
|
66
|
+
* Sets the current position of an encoder.
|
67
|
+
*/
|
68
|
+
rb_define_method(ph_encoder, "setPosition", ph_encoder_set_position, 2);
|
69
|
+
|
70
|
+
/* Document-method: getIndexPosition
|
71
|
+
* call-seq: getIndexPosition(index) -> position
|
72
|
+
*
|
73
|
+
* Gets the position of the last index pulse, as referenced to getPosition. This will raise Phidgets::Error::UnknownVal
|
74
|
+
* if there hasn't been an index event, or if the encoder doesn't support index.
|
75
|
+
*/
|
76
|
+
rb_define_method(ph_encoder, "getIndexPosition", ph_encoder_get_index_position, 1);
|
77
|
+
|
78
|
+
/* Document-method: getEnabled
|
79
|
+
* call-seq: getEnabled(index) -> true or false
|
80
|
+
*
|
81
|
+
* Gets the enabled state of an encoder. This is whether the encoder is powered or not.
|
82
|
+
*/
|
83
|
+
rb_define_method(ph_encoder, "getEnabled", ph_encoder_get_enabled, 1);
|
84
|
+
|
85
|
+
/* Document-method: setEnabled
|
86
|
+
* call-seq: setEnabled(index, state)
|
87
|
+
*
|
88
|
+
* Sets the enabled state of an encoder. This is whether the encoder is powered or not.
|
89
|
+
*/
|
90
|
+
rb_define_method(ph_encoder, "setEnabled", ph_encoder_set_enabled, 2);
|
91
|
+
|
92
|
+
#ifdef PH_CALLBACK
|
93
|
+
rb_define_private_method(ph_encoder, "ext_setOnInputChangeHandler", ph_encoder_set_on_input_change_handler, 1);
|
94
|
+
rb_define_private_method(ph_encoder, "ext_setOnPositionChangeHandler", ph_encoder_set_on_position_change_handler, 1);
|
95
|
+
rb_define_private_method(ph_encoder, "ext_setOnIndexHandler", ph_encoder_set_on_index_handler, 1);
|
96
|
+
#endif
|
97
|
+
|
98
|
+
rb_define_alias(ph_encoder, "input_count", "getInputCount");
|
99
|
+
rb_define_alias(ph_encoder, "input_state", "getInputState");
|
100
|
+
rb_define_alias(ph_encoder, "encoder_count", "getEncoderCount");
|
101
|
+
rb_define_alias(ph_encoder, "position", "getPosition");
|
102
|
+
rb_define_alias(ph_encoder, "set_position", "setPosition");
|
103
|
+
rb_define_alias(ph_encoder, "index_position", "getIndexPosition");
|
104
|
+
rb_define_alias(ph_encoder, "enabled?", "getEnabled");
|
105
|
+
rb_define_alias(ph_encoder, "set_enabled", "setEnabled");
|
106
|
+
|
107
|
+
return ph_encoder;
|
108
|
+
}
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
VALUE ph_encoder_init(VALUE self) {
|
113
|
+
ph_data_t *ph = get_ph_data(self);
|
114
|
+
ph_raise(CPhidgetEncoder_create((CPhidgetEncoderHandle *)(&(ph->handle))));
|
115
|
+
return self;
|
116
|
+
}
|
117
|
+
|
118
|
+
VALUE ph_encoder_get_input_count(VALUE self) {
|
119
|
+
CPhidgetEncoderHandle handle = (CPhidgetEncoderHandle)get_ph_handle(self);
|
120
|
+
int count;
|
121
|
+
ph_raise(CPhidgetEncoder_getInputCount(handle, &count));
|
122
|
+
return INT2FIX(count);
|
123
|
+
}
|
124
|
+
|
125
|
+
VALUE ph_encoder_get_input_state(VALUE self, VALUE index) {
|
126
|
+
CPhidgetEncoderHandle handle = (CPhidgetEncoderHandle)get_ph_handle(self);
|
127
|
+
int state;
|
128
|
+
ph_raise(CPhidgetEncoder_getInputState(handle, FIX2INT(index), &state));
|
129
|
+
return state == PTRUE ? Qtrue : Qfalse;
|
130
|
+
}
|
131
|
+
|
132
|
+
VALUE ph_encoder_get_encoder_count(VALUE self) {
|
133
|
+
CPhidgetEncoderHandle handle = (CPhidgetEncoderHandle)get_ph_handle(self);
|
134
|
+
int count;
|
135
|
+
ph_raise(CPhidgetEncoder_getEncoderCount(handle, &count));
|
136
|
+
return INT2FIX(count);
|
137
|
+
}
|
138
|
+
|
139
|
+
VALUE ph_encoder_get_position(VALUE self, VALUE index) {
|
140
|
+
CPhidgetEncoderHandle handle = (CPhidgetEncoderHandle)get_ph_handle(self);
|
141
|
+
int position;
|
142
|
+
ph_raise(CPhidgetEncoder_getPosition(handle, FIX2INT(index), &position));
|
143
|
+
return INT2FIX(position);
|
144
|
+
}
|
145
|
+
|
146
|
+
VALUE ph_encoder_set_position(VALUE self, VALUE index, VALUE position) {
|
147
|
+
CPhidgetEncoderHandle handle = (CPhidgetEncoderHandle)get_ph_handle(self);
|
148
|
+
ph_raise(CPhidgetEncoder_setPosition(handle, FIX2INT(index), FIX2INT(position)));
|
149
|
+
return Qnil;
|
150
|
+
}
|
151
|
+
|
152
|
+
VALUE ph_encoder_get_index_position(VALUE self, VALUE index) {
|
153
|
+
CPhidgetEncoderHandle handle = (CPhidgetEncoderHandle)get_ph_handle(self);
|
154
|
+
int position;
|
155
|
+
ph_raise(CPhidgetEncoder_getIndexPosition(handle, FIX2INT(index), &position));
|
156
|
+
return INT2FIX(position);
|
157
|
+
}
|
158
|
+
|
159
|
+
VALUE ph_encoder_get_enabled(VALUE self, VALUE index) {
|
160
|
+
CPhidgetEncoderHandle handle = (CPhidgetEncoderHandle)get_ph_handle(self);
|
161
|
+
int state;
|
162
|
+
ph_raise(CPhidgetEncoder_getEnabled(handle, FIX2INT(index), &state));
|
163
|
+
return state == PTRUE ? Qtrue : Qfalse;
|
164
|
+
}
|
165
|
+
|
166
|
+
VALUE ph_encoder_set_enabled(VALUE self, VALUE index, VALUE state) {
|
167
|
+
CPhidgetEncoderHandle handle = (CPhidgetEncoderHandle)get_ph_handle(self);
|
168
|
+
ph_raise(CPhidgetEncoder_setEnabled(handle, FIX2INT(index), TYPE(state) == T_TRUE ? PTRUE : PFALSE));
|
169
|
+
return Qnil;
|
170
|
+
}
|
171
|
+
|
172
|
+
|
173
|
+
#ifdef PH_CALLBACK
|
174
|
+
VALUE ph_encoder_set_on_input_change_handler(VALUE self, VALUE handler) {
|
175
|
+
ph_data_t *ph = get_ph_data(self);
|
176
|
+
ph_callback_data_t *callback_data = &ph->dev_callback_1;
|
177
|
+
if( TYPE(handler) == T_NIL ) {
|
178
|
+
callback_data->exit = true;
|
179
|
+
ph_raise(CPhidgetEncoder_set_OnInputChange_Handler((CPhidgetEncoderHandle)ph->handle, NULL, (void *)NULL));
|
180
|
+
} else {
|
181
|
+
callback_data->called = false;
|
182
|
+
callback_data->exit = false;
|
183
|
+
callback_data->phidget = self;
|
184
|
+
callback_data->callback = handler;
|
185
|
+
ph_raise(CPhidgetEncoder_set_OnInputChange_Handler((CPhidgetEncoderHandle)ph->handle, ph_encoder_on_input_change, (void *)callback_data));
|
186
|
+
ph_callback_thread(callback_data);
|
187
|
+
}
|
188
|
+
return Qnil;
|
189
|
+
}
|
190
|
+
|
191
|
+
|
192
|
+
VALUE ph_encoder_set_on_position_change_handler(VALUE self, VALUE handler) {
|
193
|
+
ph_data_t *ph = get_ph_data(self);
|
194
|
+
ph_callback_data_t *callback_data = &ph->dev_callback_2;
|
195
|
+
if( TYPE(handler) == T_NIL ) {
|
196
|
+
callback_data->exit = true;
|
197
|
+
ph_raise(CPhidgetEncoder_set_OnPositionChange_Handler((CPhidgetEncoderHandle)ph->handle, NULL, (void *)NULL));
|
198
|
+
} else {
|
199
|
+
callback_data->called = false;
|
200
|
+
callback_data->exit = false;
|
201
|
+
callback_data->phidget = self;
|
202
|
+
callback_data->callback = handler;
|
203
|
+
ph_raise(CPhidgetEncoder_set_OnPositionChange_Handler((CPhidgetEncoderHandle)ph->handle, ph_encoder_on_position_change, (void *)callback_data));
|
204
|
+
ph_callback_thread(callback_data);
|
205
|
+
}
|
206
|
+
return Qnil;
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
VALUE ph_encoder_set_on_index_handler(VALUE self, VALUE handler) {
|
211
|
+
ph_data_t *ph = get_ph_data(self);
|
212
|
+
ph_callback_data_t *callback_data = &ph->dev_callback_3;
|
213
|
+
if( TYPE(handler) == T_NIL ) {
|
214
|
+
callback_data->exit = true;
|
215
|
+
ph_raise(CPhidgetEncoder_set_OnIndex_Handler((CPhidgetEncoderHandle)ph->handle, NULL, (void *)NULL));
|
216
|
+
} else {
|
217
|
+
callback_data->called = false;
|
218
|
+
callback_data->exit = false;
|
219
|
+
callback_data->phidget = self;
|
220
|
+
callback_data->callback = handler;
|
221
|
+
ph_raise(CPhidgetEncoder_set_OnIndex_Handler((CPhidgetEncoderHandle)ph->handle, ph_encoder_on_index, (void *)callback_data));
|
222
|
+
ph_callback_thread(callback_data);
|
223
|
+
}
|
224
|
+
return Qnil;
|
225
|
+
}
|
226
|
+
|
227
|
+
|
228
|
+
int ph_encoder_on_input_change(CPhidgetEncoderHandle phid, void *userPtr, int index, int state) {
|
229
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
230
|
+
callback_data->called = true;
|
231
|
+
return EPHIDGET_OK;
|
232
|
+
}
|
233
|
+
|
234
|
+
|
235
|
+
int ph_encoder_on_position_change(CPhidgetEncoderHandle phid, void *userPtr, int index, int time, int change) {
|
236
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
237
|
+
callback_data->called = true;
|
238
|
+
return EPHIDGET_OK;
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
int ph_encoder_on_index(CPhidgetEncoderHandle phid, void *userPtr, int index, int index_pos) {
|
243
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
244
|
+
callback_data->called = true;
|
245
|
+
return EPHIDGET_OK;
|
246
|
+
}
|
247
|
+
|
248
|
+
#endif
|
249
|
+
|