phidgets 0.1.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +3 -0
  3. data/README.rdoc +32 -43
  4. data/Rakefile +4 -2
  5. data/bin/phidget +18 -72
  6. data/ext/phidgets/extconf.rb +5 -8
  7. data/ext/phidgets/phidgets.c +708 -173
  8. data/ext/phidgets/phidgets.h +54 -35
  9. data/ext/phidgets/phidgets_accelerometer.c +193 -109
  10. data/ext/phidgets/phidgets_bldc_motor.c +529 -0
  11. data/ext/phidgets/phidgets_capacitive_touch.c +302 -0
  12. data/ext/phidgets/phidgets_common.c +570 -315
  13. data/ext/phidgets/phidgets_current_input.c +229 -0
  14. data/ext/phidgets/phidgets_dc_motor.c +562 -0
  15. data/ext/phidgets/phidgets_dictionary.c +154 -213
  16. data/ext/phidgets/phidgets_digital_input.c +127 -0
  17. data/ext/phidgets/phidgets_digital_output.c +288 -0
  18. data/ext/phidgets/phidgets_distance_sensor.c +295 -0
  19. data/ext/phidgets/phidgets_encoder.c +211 -192
  20. data/ext/phidgets/phidgets_frequency_counter.c +310 -177
  21. data/ext/phidgets/phidgets_gps.c +226 -164
  22. data/ext/phidgets/phidgets_gyroscope.c +195 -0
  23. data/ext/phidgets/phidgets_hub.c +39 -0
  24. data/ext/phidgets/phidgets_humidity_sensor.c +200 -0
  25. data/ext/phidgets/phidgets_ir.c +211 -171
  26. data/ext/phidgets/phidgets_lcd.c +512 -0
  27. data/ext/phidgets/phidgets_light_sensor.c +200 -0
  28. data/ext/phidgets/phidgets_log.c +263 -0
  29. data/ext/phidgets/phidgets_magnetometer.c +279 -0
  30. data/ext/phidgets/phidgets_manager.c +86 -297
  31. data/ext/phidgets/phidgets_motor_position_controller.c +787 -0
  32. data/ext/phidgets/phidgets_phsensor.c +200 -152
  33. data/ext/phidgets/phidgets_power_guard.c +144 -0
  34. data/ext/phidgets/phidgets_pressure_sensor.c +200 -0
  35. data/ext/phidgets/phidgets_rc_servo.c +672 -0
  36. data/ext/phidgets/phidgets_resistance_input.c +227 -0
  37. data/ext/phidgets/phidgets_rfid.c +107 -221
  38. data/ext/phidgets/phidgets_sound_sensor.c +284 -0
  39. data/ext/phidgets/phidgets_spatial.c +124 -318
  40. data/ext/phidgets/phidgets_stepper.c +457 -430
  41. data/ext/phidgets/phidgets_temp_sensor.c +223 -228
  42. data/ext/phidgets/phidgets_voltage_input.c +428 -0
  43. data/ext/phidgets/phidgets_voltage_output.c +167 -0
  44. data/ext/phidgets/phidgets_voltage_ratio_input.c +435 -0
  45. data/lib/phidgets.rb +21 -14
  46. data/lib/phidgets/accelerometer.rb +11 -15
  47. data/lib/phidgets/bldc_motor.rb +45 -0
  48. data/lib/phidgets/capacitive_touch.rb +33 -0
  49. data/lib/phidgets/common.rb +40 -69
  50. data/lib/phidgets/current_input.rb +21 -0
  51. data/lib/phidgets/dc_motor.rb +45 -0
  52. data/lib/phidgets/dictionary.rb +30 -39
  53. data/lib/phidgets/digital_input.rb +21 -0
  54. data/lib/phidgets/digital_output.rb +56 -0
  55. data/lib/phidgets/distance_sensor.rb +33 -0
  56. data/lib/phidgets/encoder.rb +1 -29
  57. data/lib/phidgets/frequency_counter.rb +23 -14
  58. data/lib/phidgets/gps.rb +34 -26
  59. data/lib/phidgets/gyroscope.rb +21 -0
  60. data/lib/phidgets/humidity_sensor.rb +21 -0
  61. data/lib/phidgets/ir.rb +34 -39
  62. data/lib/phidgets/light_sensor.rb +21 -0
  63. data/lib/phidgets/magnetometer.rb +21 -0
  64. data/lib/phidgets/manager.rb +18 -66
  65. data/lib/phidgets/motor_position_controller.rb +45 -0
  66. data/lib/phidgets/ph_sensor.rb +2 -6
  67. data/lib/phidgets/pressure_sensor.rb +21 -0
  68. data/lib/phidgets/rc_servo.rb +58 -0
  69. data/lib/phidgets/resistance_input.rb +21 -0
  70. data/lib/phidgets/rfid.rb +22 -38
  71. data/lib/phidgets/sound_sensor.rb +21 -0
  72. data/lib/phidgets/spatial.rb +11 -15
  73. data/lib/phidgets/stepper.rb +48 -50
  74. data/lib/phidgets/temperature_sensor.rb +11 -15
  75. data/lib/phidgets/version.rb +5 -0
  76. data/lib/phidgets/voltage_input.rb +34 -0
  77. data/lib/phidgets/voltage_output.rb +23 -0
  78. data/lib/phidgets/voltage_ratio_input.rb +34 -0
  79. data/phidgets.gemspec +3 -22
  80. data/test/test_accelerometer.rb +42 -23
  81. data/test/test_bldc_motor.rb +134 -0
  82. data/test/test_capacitive_touch.rb +82 -0
  83. data/test/test_common.rb +125 -108
  84. data/test/test_current_input.rb +62 -0
  85. data/test/test_dc_motor.rb +146 -0
  86. data/test/test_dictionary.rb +22 -54
  87. data/test/test_digital_input.rb +30 -0
  88. data/test/test_digital_output.rb +70 -0
  89. data/test/test_distance_sensor.rb +76 -0
  90. data/test/test_encoder.rb +45 -38
  91. data/test/test_frequency_counter.rb +71 -36
  92. data/test/test_gps.rb +29 -38
  93. data/test/test_gyroscope.rb +54 -0
  94. data/test/test_helper.rb +0 -1
  95. data/test/test_hub.rb +14 -0
  96. data/test/test_humidity_sensor.rb +58 -0
  97. data/test/test_ir.rb +34 -34
  98. data/test/test_lcd.rb +146 -0
  99. data/test/test_light_sensor.rb +58 -0
  100. data/test/test_magnetometer.rb +78 -0
  101. data/test/test_manager.rb +10 -79
  102. data/test/test_motor_control.rb +146 -108
  103. data/test/test_phidgets.rb +2 -14
  104. data/test/test_phsensor.rb +46 -34
  105. data/test/test_power_guard.rb +42 -0
  106. data/test/test_pressure_sensor.rb +58 -0
  107. data/test/test_rc_servo.rb +174 -0
  108. data/test/test_resistance_input.rb +66 -0
  109. data/test/test_rfid.rb +15 -54
  110. data/test/test_sound_sensor.rb +78 -0
  111. data/test/test_spatial.rb +19 -85
  112. data/test/test_stepper.rb +89 -98
  113. data/test/test_temp_sensor.rb +42 -47
  114. data/test/test_voltage_input.rb +102 -0
  115. data/test/test_voltage_output.rb +46 -0
  116. data/test/test_voltage_ratio_input.rb +102 -0
  117. metadata +72 -89
  118. data/ext/phidgets/phidgets_advanced_servo.c +0 -567
  119. data/ext/phidgets/phidgets_analog.c +0 -139
  120. data/ext/phidgets/phidgets_bridge.c +0 -263
  121. data/ext/phidgets/phidgets_interface_kit.c +0 -340
  122. data/ext/phidgets/phidgets_led.c +0 -178
  123. data/ext/phidgets/phidgets_motor_control.c +0 -642
  124. data/ext/phidgets/phidgets_servo.c +0 -276
  125. data/ext/phidgets/phidgets_text_lcd.c +0 -381
  126. data/ext/phidgets/phidgets_text_led.c +0 -107
  127. data/ext/phidgets/phidgets_weight_sensor.c +0 -113
  128. data/lib/phidgets/advanced_servo.rb +0 -49
  129. data/lib/phidgets/analog.rb +0 -8
  130. data/lib/phidgets/bridge.rb +0 -25
  131. data/lib/phidgets/interfacekit.rb +0 -49
  132. data/lib/phidgets/led.rb +0 -8
  133. data/lib/phidgets/motor_control.rb +0 -110
  134. data/lib/phidgets/servo.rb +0 -23
  135. data/lib/phidgets/text_lcd.rb +0 -8
  136. data/lib/phidgets/text_led.rb +0 -8
  137. data/lib/phidgets/weight_sensor.rb +0 -25
  138. data/test/test_advanced_servo.rb +0 -152
  139. data/test/test_analog.rb +0 -45
  140. data/test/test_bridge.rb +0 -77
  141. data/test/test_interfacekit.rb +0 -97
  142. data/test/test_led.rb +0 -55
  143. data/test/test_servo.rb +0 -67
  144. data/test/test_text_lcd.rb +0 -115
  145. data/test/test_text_led.rb +0 -35
  146. data/test/test_weight_sensor.rb +0 -32
@@ -1,276 +0,0 @@
1
-
2
- #include "phidgets.h"
3
-
4
-
5
- VALUE ph_servo_init(VALUE self);
6
- VALUE ph_servo_get_motor_count(VALUE self);
7
- VALUE ph_servo_get_position(VALUE self, VALUE index);
8
- VALUE ph_servo_get_position_min(VALUE self, VALUE index);
9
- VALUE ph_servo_get_position_max(VALUE self, VALUE index);
10
- VALUE ph_servo_set_position(VALUE self, VALUE index, VALUE position);
11
- VALUE ph_servo_get_engaged(VALUE self, VALUE index);
12
- VALUE ph_servo_set_engaged(VALUE self, VALUE index, VALUE engaged);
13
- VALUE ph_servo_get_servo_type(VALUE self, VALUE index);
14
- VALUE ph_servo_set_servo_type(VALUE self, VALUE index, VALUE type);
15
- VALUE ph_servo_set_servo_parameters(VALUE self, VALUE index, VALUE min_us, VALUE max_us, VALUE degrees);
16
-
17
- #ifdef PH_CALLBACK
18
- VALUE ph_servo_set_on_position_change_handler(VALUE self, VALUE handler);
19
- int ph_servo_on_position_change(CPhidgetServoHandle phid, void *userPtr, int index, double position);
20
- #endif
21
-
22
-
23
- void Init_servo() {
24
- VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
25
- VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
26
- VALUE ph_servo = rb_define_class_under(ph_module, "Servo", ph_common);
27
-
28
- /* Default - This is what the servo API been historically used, originally based on the Futaba FP-S148 */
29
- rb_define_const(ph_servo, "DEFAULT", INT2FIX(PHIDGET_SERVO_DEFAULT));
30
- /* Raw us mode - all position, velocity, acceleration functions are specified in microseconds rather then degrees */
31
- rb_define_const(ph_servo, "RAW_US_MODE", INT2FIX(PHIDGET_SERVO_RAW_us_MODE));
32
- /* HiTec HS-322HD Standard \Servo */
33
- rb_define_const(ph_servo, "HITEC_HS322HD", INT2FIX(PHIDGET_SERVO_HITEC_HS322HD));
34
- /* HiTec HS-5245MG Digital Mini \Servo */
35
- rb_define_const(ph_servo, "HITEC_HS5245MG", INT2FIX(PHIDGET_SERVO_HITEC_HS5245MG));
36
- /* HiTec HS-805BB Mega Quarter Scale \Servo */
37
- rb_define_const(ph_servo, "HITEC_805BB", INT2FIX(PHIDGET_SERVO_HITEC_805BB));
38
- /* HiTec HS-422 Standard \Servo */
39
- rb_define_const(ph_servo, "HITEC_HS422", INT2FIX(PHIDGET_SERVO_HITEC_HS422));
40
- /* Tower Pro MG90 Micro \Servo */
41
- rb_define_const(ph_servo, "TOWERPRO_MG90", INT2FIX(PHIDGET_SERVO_TOWERPRO_MG90));
42
- /* HiTec HSR-1425CR Continuous Rotation \Servo */
43
- rb_define_const(ph_servo, "HITEC_HSR1425CR", INT2FIX(PHIDGET_SERVO_HITEC_HSR1425CR));
44
- /* HiTec HS-785HB Sail Winch \Servo */
45
- rb_define_const(ph_servo, "HITEC_HS785HB", INT2FIX(PHIDGET_SERVO_HITEC_HS785HB));
46
- /* HiTec HS-485HB Deluxe \Servo */
47
- rb_define_const(ph_servo, "HITEC_HS485HB", INT2FIX(PHIDGET_SERVO_HITEC_HS485HB));
48
- /* HiTec HS-645MG Ultra Torque \Servo */
49
- rb_define_const(ph_servo, "HITEC_HS645MG", INT2FIX(PHIDGET_SERVO_HITEC_HS645MG));
50
- /* HiTec HS-815BB Mega Sail \Servo */
51
- rb_define_const(ph_servo, "HITEC_815BB", INT2FIX(PHIDGET_SERVO_HITEC_815BB));
52
- /* Document-const:
53
- * Firgelli L12 Linear Actuator 30mm 50\:1 */
54
- rb_define_const(ph_servo, "FIRGELLI_L12_30_50_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_30_50_06_R));
55
- /* Document-const:
56
- * Firgelli L12 Linear Actuator 50mm 100\:1 */
57
- rb_define_const(ph_servo, "FIRGELLI_L12_50_100_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_50_100_06_R));
58
- /* Document-const:
59
- * Firgelli L12 Linear Actuator 50mm 210\:1 */
60
- rb_define_const(ph_servo, "FIRGELLI_L12_50_210_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_50_210_06_R));
61
- /* Document-const:
62
- * Firgelli L12 Linear Actuator 100mm 50\:1 */
63
- rb_define_const(ph_servo, "FIRGELLI_L12_100_50_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_100_50_06_R));
64
- /* Document-const:
65
- * Firgelli L12 Linear Actuator 100mm 100\:1 */
66
- rb_define_const(ph_servo, "FIRGELLI_L12_100_100_06_R", INT2FIX(PHIDGET_SERVO_FIRGELLI_L12_100_100_06_R));
67
- /* SpringRC SM-S2313M Micro \Servo */
68
- rb_define_const(ph_servo, "SPRINGRC_SM_S2313M", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S2313M));
69
- /* SpringRC SM-S3317M Small \Servo */
70
- rb_define_const(ph_servo, "SPRINGRC_SM_S3317M", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S3317M));
71
- /* SpringRC SM-S3317SR Small Continuous Rotation \Servo */
72
- rb_define_const(ph_servo, "SPRINGRC_SM_S3317SR", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S3317SR));
73
- /* SpringRC SM-S4303R Standard Continuous Rotation \Servo */
74
- rb_define_const(ph_servo, "SPRINGRC_SM_S4303R", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S4303R));
75
- /* SpringRC SM-S4315M High Torque \Servo */
76
- rb_define_const(ph_servo, "SPRINGRC_SM_S4315M", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S4315M));
77
- /* SpringRC SM-S4315R High Torque Continuous Rotation \Servo */
78
- rb_define_const(ph_servo, "SPRINGRC_SM_S4315R", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S4315R));
79
- /* SpringRC SM-S4505B Standard \Servo */
80
- rb_define_const(ph_servo, "SPRINGRC_SM_S4505B", INT2FIX(PHIDGET_SERVO_SPRINGRC_SM_S4505B));
81
-
82
- /* Document-method: new
83
- * call-seq: new
84
- *
85
- * Creates a Phidget Servo object.
86
- */
87
- rb_define_method(ph_servo, "initialize", ph_servo_init, 0);
88
-
89
- /* Document-method: getMotorCount
90
- * call-seq: getMotorCount -> count
91
- *
92
- * Gets the number of motors supported by this controller
93
- */
94
- rb_define_method(ph_servo, "getMotorCount", ph_servo_get_motor_count, 0);
95
-
96
- /* Document-method: getPosition
97
- * call-seq: getPosition(index) -> position
98
- *
99
- * Gets the current position of a motor.
100
- */
101
- rb_define_method(ph_servo, "getPosition", ph_servo_get_position, 1);
102
-
103
- /* Document-method: getPositionMin
104
- * call-seq: getPositionMin(index) -> min
105
- *
106
- * Gets the minimum position that a motor can go to.
107
- */
108
- rb_define_method(ph_servo, "getPositionMin", ph_servo_get_position_min, 1);
109
-
110
- /* Document-method: getPositionMax
111
- * call-seq: getPositionMax(index) -> max
112
- *
113
- * Gets the maximum position that a motor can go to.
114
- */
115
- rb_define_method(ph_servo, "getPositionMax", ph_servo_get_position_max, 1);
116
-
117
- /* Document-method: setPosition
118
- * call-seq: setPosition(index, position)
119
- *
120
- * Sets the position of a motor.
121
- */
122
- rb_define_method(ph_servo, "setPosition", ph_servo_set_position, 2);
123
-
124
- /* Document-method: getEngaged
125
- * call-seq: getEngaged(index) -> true or false
126
- *
127
- * Gets the engaged state of a motor. This is whether the motor is powered or not.
128
- */
129
- rb_define_method(ph_servo, "getEngaged", ph_servo_get_engaged, 1);
130
-
131
- /* Document-method: setEngaged
132
- * call-seq: setEngaged(index, state)
133
- *
134
- * Sets the engaged state of a motor. This is whether the motor is powered or not.
135
- */
136
- rb_define_method(ph_servo, "setEngaged", ph_servo_set_engaged, 2);
137
-
138
- /* Document-method: getServoType
139
- * call-seq: getServoType(index) -> servo_type
140
- *
141
- * Gets the servo type of a motor.
142
- */
143
- rb_define_method(ph_servo, "getServoType", ph_servo_get_servo_type, 1);
144
-
145
- /* Document-method: setServoType
146
- * call-seq: setServoType(index, servo_type)
147
- *
148
- * Sets the servo type of a motor.
149
- */
150
- rb_define_method(ph_servo, "setServoType", ph_servo_set_servo_type, 2);
151
-
152
- /* Document-method: setServoParameters
153
- * call-seq: setServoParameters(index, min_us, max_us, degrees)
154
- *
155
- * Sets the servo parameters of a motor.
156
- */
157
- rb_define_method(ph_servo, "setServoParameters", ph_servo_set_servo_parameters, 4);
158
-
159
- #ifdef PH_CALLBACK
160
- rb_define_private_method(ph_servo, "ext_setOnPositionChangeHandler", ph_servo_set_on_position_change_handler, 1);
161
- #endif
162
-
163
- rb_define_alias(ph_servo, "motor_count", "getMotorCount");
164
- rb_define_alias(ph_servo, "position", "getPosition");
165
- rb_define_alias(ph_servo, "position_min", "getPositionMin");
166
- rb_define_alias(ph_servo, "position_max", "getPositionMax");
167
- rb_define_alias(ph_servo, "set_position", "setPosition");
168
- rb_define_alias(ph_servo, "engaged?", "getEngaged");
169
- rb_define_alias(ph_servo, "set_engaged", "setEngaged");
170
- rb_define_alias(ph_servo, "servo_type", "getServoType");
171
- rb_define_alias(ph_servo, "set_servo_type", "setServoType");
172
- rb_define_alias(ph_servo, "set_servo_parameters", "setServoParameters");
173
- }
174
-
175
-
176
-
177
- VALUE ph_servo_init(VALUE self) {
178
- ph_data_t *ph = get_ph_data(self);
179
- ph_raise(CPhidgetServo_create((CPhidgetServoHandle *)(&(ph->handle))));
180
- return self;
181
- }
182
-
183
- VALUE ph_servo_get_motor_count(VALUE self) {
184
- CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
185
- int count;
186
- ph_raise(CPhidgetServo_getMotorCount(handle, &count));
187
- return INT2FIX(count);
188
- }
189
-
190
- VALUE ph_servo_get_position(VALUE self, VALUE index) {
191
- CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
192
- double position;
193
- ph_raise(CPhidgetServo_getPosition(handle, FIX2INT(index), &position));
194
- return rb_float_new(position);
195
- }
196
-
197
- VALUE ph_servo_get_position_min(VALUE self, VALUE index) {
198
- CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
199
- double position;
200
- ph_raise(CPhidgetServo_getPositionMin(handle, FIX2INT(index), &position));
201
- return rb_float_new(position);
202
- }
203
-
204
- VALUE ph_servo_get_position_max(VALUE self, VALUE index) {
205
- CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
206
- double position;
207
- ph_raise(CPhidgetServo_getPositionMax(handle, FIX2INT(index), &position));
208
- return rb_float_new(position);
209
- }
210
-
211
- VALUE ph_servo_set_position(VALUE self, VALUE index, VALUE position) {
212
- CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
213
- ph_raise(CPhidgetServo_setPosition(handle, FIX2INT(index), NUM2DBL(position)));
214
- return Qnil;
215
- }
216
-
217
- VALUE ph_servo_get_engaged(VALUE self, VALUE index) {
218
- CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
219
- int engaged;
220
- ph_raise(CPhidgetServo_getEngaged(handle, FIX2INT(index), &engaged));
221
- return engaged == PTRUE ? Qtrue : Qfalse;
222
- }
223
-
224
- VALUE ph_servo_set_engaged(VALUE self, VALUE index, VALUE engaged) {
225
- CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
226
- ph_raise(CPhidgetServo_setEngaged(handle, FIX2INT(index), TYPE(engaged) == T_TRUE ? PTRUE : PFALSE));
227
- return Qnil;
228
- }
229
-
230
- VALUE ph_servo_get_servo_type(VALUE self, VALUE index) {
231
- CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
232
- CPhidget_ServoType type;
233
- ph_raise(CPhidgetServo_getServoType(handle, FIX2INT(index), &type));
234
- return INT2FIX(type);
235
- }
236
-
237
- VALUE ph_servo_set_servo_type(VALUE self, VALUE index, VALUE type) {
238
- CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
239
- ph_raise(CPhidgetServo_setServoType(handle, FIX2INT(index), (CPhidget_ServoType)FIX2INT(type)));
240
- return Qnil;
241
- }
242
-
243
- VALUE ph_servo_set_servo_parameters(VALUE self, VALUE index, VALUE min_us, VALUE max_us, VALUE degrees) {
244
- CPhidgetServoHandle handle = (CPhidgetServoHandle)get_ph_handle(self);
245
- ph_raise(CPhidgetServo_setServoParameters(handle, FIX2INT(index), NUM2DBL(min_us), NUM2DBL(max_us), NUM2DBL(degrees)));
246
- return Qnil;
247
- }
248
-
249
-
250
- #ifdef PH_CALLBACK
251
- VALUE ph_servo_set_on_position_change_handler(VALUE self, VALUE handler) {
252
- ph_data_t *ph = get_ph_data(self);
253
- ph_callback_data_t *callback_data = &ph->dev_callback_1;
254
- if( TYPE(handler) == T_NIL ) {
255
- callback_data->exit = true;
256
- ph_raise(CPhidgetServo_set_OnPositionChange_Handler((CPhidgetServoHandle)ph->handle, NULL, (void *)NULL));
257
- } else {
258
- callback_data->called = false;
259
- callback_data->exit = false;
260
- callback_data->phidget = self;
261
- callback_data->callback = handler;
262
- ph_raise(CPhidgetServo_set_OnPositionChange_Handler((CPhidgetServoHandle)ph->handle, ph_servo_on_position_change, (void *)callback_data));
263
- ph_callback_thread(callback_data);
264
- }
265
- return Qnil;
266
- }
267
-
268
-
269
- int ph_servo_on_position_change(CPhidgetServoHandle phid, void *userPtr, int index, double position) {
270
- ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
271
- callback_data->called = true;
272
- return EPHIDGET_OK;
273
- }
274
-
275
- #endif
276
-
@@ -1,381 +0,0 @@
1
-
2
- #include "phidgets.h"
3
-
4
-
5
- VALUE ph_textlcd_init(VALUE self);
6
- VALUE ph_textlcd_get_row_count(VALUE self);
7
- VALUE ph_textlcd_get_column_count(VALUE self);
8
- VALUE ph_textlcd_get_backlight(VALUE self);
9
- VALUE ph_textlcd_set_backlight(VALUE self, VALUE state);
10
- VALUE ph_textlcd_get_brightness(VALUE self);
11
- VALUE ph_textlcd_set_brightness(VALUE self, VALUE brightness);
12
- VALUE ph_textlcd_get_contrast(VALUE self);
13
- VALUE ph_textlcd_set_contrast(VALUE self, VALUE contrast);
14
- VALUE ph_textlcd_get_cursor_on(VALUE self);
15
- VALUE ph_textlcd_set_cursor_on(VALUE self, VALUE state);
16
- VALUE ph_textlcd_get_cursor_blink(VALUE self);
17
- VALUE ph_textlcd_set_cursor_blink(VALUE self, VALUE state);
18
- VALUE ph_textlcd_set_custom_character(VALUE self, VALUE index, VALUE var1, VALUE var2);
19
- VALUE ph_textlcd_set_display_character(VALUE self, VALUE index, VALUE column, VALUE character);
20
- VALUE ph_textlcd_set_display_string(VALUE self, VALUE index, VALUE string);
21
- VALUE ph_textlcd_get_screen_count(VALUE self);
22
- VALUE ph_textlcd_get_screen(VALUE self);
23
- VALUE ph_textlcd_set_screen(VALUE self, VALUE index);
24
- VALUE ph_textlcd_get_screen_size(VALUE self);
25
- VALUE ph_textlcd_set_screen_size(VALUE self, VALUE screen);
26
- VALUE ph_textlcd_init_screen(VALUE self);
27
-
28
-
29
- void Init_text_lcd() {
30
- VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
31
- VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
32
- VALUE ph_textlcd = rb_define_class_under(ph_module, "TextLCD", ph_common);
33
-
34
- /* no screen attached */
35
- rb_define_const(ph_textlcd, "SCREEN_NONE", INT2FIX(PHIDGET_TEXTLCD_SCREEN_NONE));
36
- /* 1 row, 8 column screen */
37
- rb_define_const(ph_textlcd, "SCREEN_1x8", INT2FIX(PHIDGET_TEXTLCD_SCREEN_1x8));
38
- /* 2 row, 8 column screen */
39
- rb_define_const(ph_textlcd, "SCREEN_2x8", INT2FIX(PHIDGET_TEXTLCD_SCREEN_2x8));
40
- /* 1 row, 16 column screen */
41
- rb_define_const(ph_textlcd, "SCREEN_1x16", INT2FIX(PHIDGET_TEXTLCD_SCREEN_1x16));
42
- /* 2 row, 16 column screen */
43
- rb_define_const(ph_textlcd, "SCREEN_2x16", INT2FIX(PHIDGET_TEXTLCD_SCREEN_2x16));
44
- /* 4 row, 16 column screen */
45
- rb_define_const(ph_textlcd, "SCREEN_4x16", INT2FIX(PHIDGET_TEXTLCD_SCREEN_4x16));
46
- /* 2 row, 20 column screen */
47
- rb_define_const(ph_textlcd, "SCREEN_2x20", INT2FIX(PHIDGET_TEXTLCD_SCREEN_2x20));
48
- /* 4 row, 20 column screen */
49
- rb_define_const(ph_textlcd, "SCREEN_4x20", INT2FIX(PHIDGET_TEXTLCD_SCREEN_4x20));
50
- /* 2 row, 24 column screen */
51
- rb_define_const(ph_textlcd, "SCREEN_2x24", INT2FIX(PHIDGET_TEXTLCD_SCREEN_2x24));
52
- /* 1 row, 40 column screen */
53
- rb_define_const(ph_textlcd, "SCREEN_1x40", INT2FIX(PHIDGET_TEXTLCD_SCREEN_1x40));
54
- /* 2 row, 40 column screen */
55
- rb_define_const(ph_textlcd, "SCREEN_2x40", INT2FIX(PHIDGET_TEXTLCD_SCREEN_2x40));
56
- /* 4 row, 40 column screen (special case, requires both screen connections) */
57
- rb_define_const(ph_textlcd, "SCREEN_4x40", INT2FIX(PHIDGET_TEXTLCD_SCREEN_4x40));
58
-
59
- /* Document-method: new
60
- * call-seq: new
61
- *
62
- * Creates a Phidget TextLCD object.
63
- */
64
- rb_define_method(ph_textlcd, "initialize", ph_textlcd_init, 0);
65
-
66
- /* Document-method: getRowCount
67
- * call-seq: getRowCount -> count
68
- *
69
- * Gets the number of rows supported by this display.
70
- */
71
- rb_define_method(ph_textlcd, "getRowCount", ph_textlcd_get_row_count, 0);
72
-
73
- /* Document-method: getColumnCount
74
- * call-seq: getColumnCount -> count
75
- *
76
- * Gets the number of columns per supported by this display.
77
- */
78
- rb_define_method(ph_textlcd, "getColumnCount", ph_textlcd_get_column_count, 0);
79
-
80
- /* Document-method: getBacklight
81
- * call-seq: getBacklight -> true or false
82
- *
83
- * Gets the state of the backlight.
84
- */
85
- rb_define_method(ph_textlcd, "getBacklight", ph_textlcd_get_backlight, 0);
86
-
87
- /* Document-method: setBacklight
88
- * call-seq: setBacklight(state)
89
- *
90
- * Sets the state of the backlight.
91
- */
92
- rb_define_method(ph_textlcd, "setBacklight", ph_textlcd_set_backlight, 1);
93
-
94
- /* Document-method: getBrightness
95
- * call-seq: getBrightness -> brightness
96
- *
97
- * Gets the brightness of the backlight. Not supported on all TextLCDs
98
- */
99
- rb_define_method(ph_textlcd, "getBrightness", ph_textlcd_get_brightness, 0);
100
-
101
- /* Document-method: setBrightness
102
- * call-seq: setBrightness(brightness)
103
- *
104
- * Sets the brightness of the backlight. Not supported on all TextLCDs
105
- */
106
- rb_define_method(ph_textlcd, "setBrightness", ph_textlcd_set_brightness, 1);
107
-
108
- /* Document-method: getContrast
109
- * call-seq: getContrast -> contrast
110
- *
111
- * Gets the last set contrast value.
112
- */
113
- rb_define_method(ph_textlcd, "getContrast", ph_textlcd_get_contrast, 0);
114
-
115
- /* Document-method: setContrast
116
- * call-seq: setContrast(contrast)
117
- *
118
- * Sets the last set contrast value.
119
- */
120
- rb_define_method(ph_textlcd, "setContrast", ph_textlcd_set_contrast, 1);
121
-
122
- /* Document-method: getCursorOn
123
- * call-seq: getCursorOn -> true or false
124
- *
125
- * Gets the cursor visible state.
126
- */
127
- rb_define_method(ph_textlcd, "getCursorOn", ph_textlcd_get_cursor_on, 0);
128
-
129
- /* Document-method: setCursorOn
130
- * call-seq: setCursorOn(state)
131
- *
132
- * Sets the cursor visible state.
133
- */
134
- rb_define_method(ph_textlcd, "setCursorOn", ph_textlcd_set_cursor_on, 1);
135
-
136
- /* Document-method: getCursorBlink
137
- * call-seq: getCursorBlink -> true or false
138
- *
139
- * Gets the cursor blink state.
140
- */
141
- rb_define_method(ph_textlcd, "getCursorBlink", ph_textlcd_get_cursor_blink, 0);
142
-
143
- /* Document-method: setCursorBlink
144
- * call-seq: setCursorBlink(state)
145
- *
146
- * Sets the cursor blink state.
147
- */
148
- rb_define_method(ph_textlcd, "setCursorBlink", ph_textlcd_set_cursor_blink, 1);
149
-
150
- /* Document-method: setCustomCharacter
151
- * call-seq: setCustomCharacter(index, var1, var2)
152
- *
153
- * Sets a custom character. See the product manual for more information.
154
- */
155
- rb_define_method(ph_textlcd, "setCustomCharacter", ph_textlcd_set_custom_character, 3);
156
-
157
- /* Document-method: setDisplayCharacter
158
- * call-seq: setDisplayCharacter(index, column, character)
159
- *
160
- * Sets a single character on the display.
161
- */
162
- rb_define_method(ph_textlcd, "setDisplayCharacter", ph_textlcd_set_display_character, 3);
163
-
164
- /* Document-method: setDisplayString
165
- * call-seq: setDisplayString(index, string)
166
- *
167
- * Sets a row on the display.
168
- */
169
- rb_define_method(ph_textlcd, "setDisplayString", ph_textlcd_set_display_string, 2);
170
-
171
- /* Document-method: getScreenCount
172
- * call-seq: getScreenCount -> count
173
- *
174
- * Gets the number of Display supported by this TextLCD
175
- */
176
- rb_define_method(ph_textlcd, "getScreenCount", ph_textlcd_get_screen_count, 0);
177
-
178
- /* Document-method: getScreen
179
- * call-seq: getScreen -> index
180
- *
181
- * Gets the active screen.
182
- */
183
- rb_define_method(ph_textlcd, "getScreen", ph_textlcd_get_screen, 0);
184
-
185
- /* Document-method: setScreen
186
- * call-seq: setScreen(index)
187
- *
188
- * Sets the active screen. This is the screen that all subsequent API calls will apply to.
189
- */
190
- rb_define_method(ph_textlcd, "setScreen", ph_textlcd_set_screen, 1);
191
-
192
- /* Document-method: getScreenSize
193
- * call-seq: getScreenSize -> size
194
- *
195
- * Gets the screen size.
196
- */
197
- rb_define_method(ph_textlcd, "getScreenSize", ph_textlcd_get_screen_size, 0);
198
-
199
- /* Document-method: setScreenSize
200
- * call-seq: setScreenSize(size)
201
- *
202
- * Sets the active screen size. Only supported on the TextLCD Adapter.
203
- */
204
- rb_define_method(ph_textlcd, "setScreenSize", ph_textlcd_set_screen_size, 1);
205
-
206
- /* Document-method: initScreen
207
- * call-seq: initScreen
208
- *
209
- * Initializes the active screen. Only supported on the TextLCD adapter. This should be called
210
- * if a screen is attached after power up, or to clear the screen after setting the size.
211
- */
212
- rb_define_method(ph_textlcd, "initScreen", ph_textlcd_init_screen, 0);
213
-
214
- rb_define_alias(ph_textlcd, "row_count", "getRowCount");
215
- rb_define_alias(ph_textlcd, "column_count", "getColumnCount");
216
- rb_define_alias(ph_textlcd, "backlight?", "getBacklight");
217
- rb_define_alias(ph_textlcd, "backlight=", "setBacklight");
218
- rb_define_alias(ph_textlcd, "brightness", "getBrightness");
219
- rb_define_alias(ph_textlcd, "brightness=", "setBrightness");
220
- rb_define_alias(ph_textlcd, "contrast", "getContrast");
221
- rb_define_alias(ph_textlcd, "contrast=", "setContrast");
222
- rb_define_alias(ph_textlcd, "cursor_on?", "getCursorOn");
223
- rb_define_alias(ph_textlcd, "cursor_on=", "setCursorOn");
224
- rb_define_alias(ph_textlcd, "cursor_blink?", "getCursorBlink");
225
- rb_define_alias(ph_textlcd, "cursor_blink=", "setCursorBlink");
226
- rb_define_alias(ph_textlcd, "custom_character", "setCustomCharacter");
227
- rb_define_alias(ph_textlcd, "display_character", "setDisplayCharacter");
228
- rb_define_alias(ph_textlcd, "display_string", "setDisplayString");
229
- rb_define_alias(ph_textlcd, "screen_count", "getScreenCount");
230
- rb_define_alias(ph_textlcd, "screen", "getScreen");
231
- rb_define_alias(ph_textlcd, "screen=", "setScreen");
232
- rb_define_alias(ph_textlcd, "screen_size", "getScreenSize");
233
- rb_define_alias(ph_textlcd, "screen_size=", "setScreenSize");
234
- rb_define_alias(ph_textlcd, "init_screen", "initScreen");
235
- }
236
-
237
-
238
-
239
- VALUE ph_textlcd_init(VALUE self) {
240
- ph_data_t *ph = get_ph_data(self);
241
- ph_raise(CPhidgetTextLCD_create((CPhidgetTextLCDHandle *)(&(ph->handle))));
242
- return self;
243
- }
244
-
245
- VALUE ph_textlcd_get_row_count(VALUE self) {
246
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
247
- int count;
248
- ph_raise(CPhidgetTextLCD_getRowCount(handle, &count));
249
- return INT2FIX(count);
250
- }
251
-
252
- VALUE ph_textlcd_get_column_count(VALUE self) {
253
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
254
- int count;
255
- ph_raise(CPhidgetTextLCD_getColumnCount(handle, &count));
256
- return INT2FIX(count);
257
- }
258
-
259
- VALUE ph_textlcd_get_backlight(VALUE self) {
260
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
261
- int state;
262
- ph_raise(CPhidgetTextLCD_getBacklight(handle, &state));
263
- return state == PTRUE ? Qtrue : Qfalse;
264
- }
265
-
266
- VALUE ph_textlcd_set_backlight(VALUE self, VALUE state) {
267
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
268
- ph_raise(CPhidgetTextLCD_setBacklight(handle, TYPE(state) == T_TRUE ? PTRUE : PFALSE));
269
- return Qnil;
270
- }
271
-
272
- VALUE ph_textlcd_get_brightness(VALUE self) {
273
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
274
- int brightness;
275
- ph_raise(CPhidgetTextLCD_getBrightness(handle, &brightness));
276
- return INT2FIX(brightness);
277
- }
278
-
279
- VALUE ph_textlcd_set_brightness(VALUE self, VALUE brightness) {
280
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
281
- ph_raise(CPhidgetTextLCD_setBrightness(handle, FIX2INT(brightness)));
282
- return Qnil;
283
- }
284
-
285
- VALUE ph_textlcd_get_contrast(VALUE self) {
286
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
287
- int contrast;
288
- ph_raise(CPhidgetTextLCD_getContrast(handle, &contrast));
289
- return INT2FIX(contrast);
290
- }
291
-
292
- VALUE ph_textlcd_set_contrast(VALUE self, VALUE contrast) {
293
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
294
- ph_raise(CPhidgetTextLCD_setContrast(handle, FIX2INT(contrast)));
295
- return Qnil;
296
- }
297
-
298
- VALUE ph_textlcd_get_cursor_on(VALUE self) {
299
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
300
- int state;
301
- ph_raise(CPhidgetTextLCD_getCursorOn(handle, &state));
302
- return state == PTRUE ? Qtrue : Qfalse;
303
- }
304
-
305
- VALUE ph_textlcd_set_cursor_on(VALUE self, VALUE state) {
306
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
307
- ph_raise(CPhidgetTextLCD_setCursorOn(handle, TYPE(state) == T_TRUE ? PTRUE : PFALSE));
308
- return Qnil;
309
- }
310
-
311
- VALUE ph_textlcd_get_cursor_blink(VALUE self) {
312
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
313
- int state;
314
- ph_raise(CPhidgetTextLCD_getCursorBlink(handle, &state));
315
- return state == PTRUE ? Qtrue : Qfalse;
316
- }
317
-
318
- VALUE ph_textlcd_set_cursor_blink(VALUE self, VALUE state) {
319
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
320
- ph_raise(CPhidgetTextLCD_setCursorBlink(handle, TYPE(state) == T_TRUE ? PTRUE : PFALSE));
321
- return Qnil;
322
- }
323
-
324
- VALUE ph_textlcd_set_custom_character(VALUE self, VALUE index, VALUE var1, VALUE var2) {
325
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
326
- ph_raise(CPhidgetTextLCD_setCustomCharacter(handle, FIX2INT(index), FIX2INT(var1), FIX2INT(var2)));
327
- return Qnil;
328
- }
329
-
330
- VALUE ph_textlcd_set_display_character(VALUE self, VALUE index, VALUE column, VALUE character) {
331
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
332
- char *str = StringValueCStr(character);
333
- ph_raise(CPhidgetTextLCD_setDisplayCharacter(handle, FIX2INT(index), FIX2INT(column), str[0]));
334
- return Qnil;
335
- }
336
-
337
- VALUE ph_textlcd_set_display_string(VALUE self, VALUE index, VALUE string) {
338
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
339
- ph_raise(CPhidgetTextLCD_setDisplayString(handle, FIX2INT(index), StringValueCStr(string)));
340
- return Qnil;
341
- }
342
-
343
- VALUE ph_textlcd_get_screen_count(VALUE self) {
344
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
345
- int count;
346
- ph_raise(CPhidgetTextLCD_getScreenCount(handle, &count));
347
- return INT2FIX(count);
348
- }
349
-
350
- VALUE ph_textlcd_get_screen(VALUE self) {
351
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
352
- int screen;
353
- ph_raise(CPhidgetTextLCD_getScreen(handle, &screen));
354
- return INT2FIX(screen);
355
- }
356
-
357
- VALUE ph_textlcd_set_screen(VALUE self, VALUE screen) {
358
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
359
- ph_raise(CPhidgetTextLCD_setScreen(handle, FIX2INT(screen)));
360
- return Qnil;
361
- }
362
-
363
- VALUE ph_textlcd_get_screen_size(VALUE self) {
364
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
365
- CPhidgetTextLCD_ScreenSize screen;
366
- ph_raise(CPhidgetTextLCD_getScreenSize(handle, &screen));
367
- return INT2FIX(screen);
368
- }
369
-
370
- VALUE ph_textlcd_set_screen_size(VALUE self, VALUE screen) {
371
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
372
- ph_raise(CPhidgetTextLCD_setScreenSize(handle, (CPhidgetTextLCD_ScreenSize)FIX2INT(screen)));
373
- return Qnil;
374
- }
375
-
376
- VALUE ph_textlcd_init_screen(VALUE self) {
377
- CPhidgetTextLCDHandle handle = (CPhidgetTextLCDHandle)get_ph_handle(self);
378
- ph_raise(CPhidgetTextLCD_initialize(handle));
379
- return Qnil;
380
- }
381
-