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.
Files changed (88) hide show
  1. data/History.txt +10 -2
  2. data/README.rdoc +41 -18
  3. data/Rakefile +31 -20
  4. data/bin/phidget +29 -44
  5. data/ext/phidgets/extconf.rb +14 -0
  6. data/ext/phidgets/phidgets.c +272 -0
  7. data/ext/phidgets/phidgets.h +82 -0
  8. data/ext/phidgets/phidgets_accelerometer.c +165 -0
  9. data/ext/phidgets/phidgets_advanced_servo.c +567 -0
  10. data/ext/phidgets/phidgets_analog.c +139 -0
  11. data/ext/phidgets/phidgets_bridge.c +263 -0
  12. data/ext/phidgets/phidgets_common.c +454 -0
  13. data/ext/phidgets/phidgets_dictionary.c +279 -0
  14. data/ext/phidgets/phidgets_encoder.c +249 -0
  15. data/ext/phidgets/phidgets_frequency_counter.c +241 -0
  16. data/ext/phidgets/phidgets_gps.c +235 -0
  17. data/ext/phidgets/phidgets_interface_kit.c +340 -0
  18. data/ext/phidgets/phidgets_ir.c +251 -0
  19. data/ext/phidgets/phidgets_led.c +178 -0
  20. data/ext/phidgets/phidgets_manager.c +366 -0
  21. data/ext/phidgets/phidgets_motor_control.c +642 -0
  22. data/ext/phidgets/phidgets_phsensor.c +208 -0
  23. data/ext/phidgets/phidgets_rfid.c +281 -0
  24. data/ext/phidgets/phidgets_servo.c +276 -0
  25. data/ext/phidgets/phidgets_spatial.c +369 -0
  26. data/ext/phidgets/phidgets_stepper.c +560 -0
  27. data/ext/phidgets/phidgets_temp_sensor.c +295 -0
  28. data/ext/phidgets/phidgets_text_lcd.c +381 -0
  29. data/ext/phidgets/phidgets_text_led.c +107 -0
  30. data/ext/phidgets/phidgets_weight_sensor.c +113 -0
  31. data/lib/phidgets/accelerometer.rb +25 -0
  32. data/lib/phidgets/advanced_servo.rb +49 -0
  33. data/lib/phidgets/analog.rb +8 -0
  34. data/lib/phidgets/bridge.rb +25 -0
  35. data/lib/phidgets/common.rb +75 -190
  36. data/lib/phidgets/dictionary.rb +53 -0
  37. data/lib/phidgets/encoder.rb +49 -0
  38. data/lib/phidgets/frequency_counter.rb +25 -0
  39. data/lib/phidgets/gps.rb +37 -0
  40. data/lib/phidgets/interfacekit.rb +38 -128
  41. data/lib/phidgets/ir.rb +50 -0
  42. data/lib/phidgets/led.rb +8 -0
  43. data/lib/phidgets/manager.rb +67 -119
  44. data/lib/phidgets/motor_control.rb +110 -0
  45. data/lib/phidgets/ph_sensor.rb +25 -0
  46. data/lib/phidgets/rfid.rb +38 -111
  47. data/lib/phidgets/servo.rb +12 -95
  48. data/lib/phidgets/spatial.rb +25 -0
  49. data/lib/phidgets/stepper.rb +61 -0
  50. data/lib/phidgets/temperature_sensor.rb +25 -0
  51. data/lib/phidgets/text_lcd.rb +8 -0
  52. data/lib/phidgets/text_led.rb +8 -0
  53. data/lib/phidgets/weight_sensor.rb +25 -0
  54. data/lib/phidgets.rb +22 -3
  55. data/phidgets.gemspec +42 -0
  56. data/test/test_accelerometer.rb +47 -0
  57. data/test/test_advanced_servo.rb +152 -0
  58. data/test/test_analog.rb +45 -0
  59. data/test/test_bridge.rb +77 -0
  60. data/test/test_common.rb +167 -0
  61. data/test/test_dictionary.rb +82 -0
  62. data/test/test_encoder.rb +67 -0
  63. data/test/test_frequency_counter.rb +67 -0
  64. data/test/test_gps.rb +67 -0
  65. data/test/test_helper.rb +1 -0
  66. data/test/test_interfacekit.rb +86 -182
  67. data/test/test_ir.rb +57 -0
  68. data/test/test_led.rb +55 -0
  69. data/test/test_manager.rb +94 -0
  70. data/test/test_motor_control.rb +172 -0
  71. data/test/test_phidgets.rb +14 -6
  72. data/test/test_phsensor.rb +62 -0
  73. data/test/test_rfid.rb +77 -0
  74. data/test/test_servo.rb +67 -0
  75. data/test/test_spatial.rb +112 -0
  76. data/test/test_stepper.rb +163 -0
  77. data/test/test_temp_sensor.rb +87 -0
  78. data/test/test_text_lcd.rb +115 -0
  79. data/test/test_text_led.rb +35 -0
  80. data/test/test_weight_sensor.rb +32 -0
  81. metadata +165 -75
  82. data/Manifest.txt +0 -21
  83. data/PostInstall.txt +0 -3
  84. data/README.txt +0 -87
  85. data/lib/phidgets/phidgets.rb +0 -225
  86. data/script/console +0 -10
  87. data/script/destroy +0 -14
  88. data/script/generate +0 -14
@@ -0,0 +1,295 @@
1
+
2
+ #include "phidgets.h"
3
+
4
+
5
+ VALUE ph_temp_init(VALUE self);
6
+ VALUE ph_temp_get_temperature_input_count(VALUE self);
7
+ VALUE ph_temp_get_temperature(VALUE self, VALUE index);
8
+ VALUE ph_temp_get_temperature_min(VALUE self, VALUE index);
9
+ VALUE ph_temp_get_temperature_max(VALUE self, VALUE index);
10
+ VALUE ph_temp_get_temperature_change_trigger(VALUE self, VALUE index);
11
+ VALUE ph_temp_set_temperature_change_trigger(VALUE self, VALUE index, VALUE temperature);
12
+ VALUE ph_temp_get_potential(VALUE self, VALUE index);
13
+ VALUE ph_temp_get_potential_min(VALUE self, VALUE index);
14
+ VALUE ph_temp_get_potential_max(VALUE self, VALUE index);
15
+ VALUE ph_temp_get_ambient_temperature(VALUE self);
16
+ VALUE ph_temp_get_ambient_temperature_min(VALUE self);
17
+ VALUE ph_temp_get_ambient_temperature_max(VALUE self);
18
+ VALUE ph_temp_get_thermocouple_type(VALUE self, VALUE index);
19
+ VALUE ph_temp_set_thermocouple_type(VALUE self, VALUE index, VALUE thermocouple);
20
+
21
+ #ifdef PH_CALLBACK
22
+ VALUE ph_temp_set_on_temperature_change_handler(VALUE self, VALUE handler);
23
+ int ph_temp_on_temperature_change(CPhidgetTemperatureSensorHandle phid, void *userPtr, int index, double temperature);
24
+ #endif
25
+
26
+
27
+ VALUE Init_phidgets_temp(VALUE ph_module, VALUE ph_common) {
28
+ VALUE ph_temp = rb_define_class_under(ph_module, "TemperatureSensor", ph_common);
29
+
30
+ rb_define_const(ph_temp, "K_TYPE", INT2FIX(PHIDGET_TEMPERATURE_SENSOR_K_TYPE));
31
+ rb_define_const(ph_temp, "J_TYPE", INT2FIX(PHIDGET_TEMPERATURE_SENSOR_J_TYPE));
32
+ rb_define_const(ph_temp, "E_TYPE", INT2FIX(PHIDGET_TEMPERATURE_SENSOR_E_TYPE));
33
+ rb_define_const(ph_temp, "T_TYPE", INT2FIX(PHIDGET_TEMPERATURE_SENSOR_T_TYPE));
34
+
35
+ /* Document-method: new
36
+ * call-seq: new
37
+ *
38
+ * Creates a Phidget TemperatureSensor object.
39
+ */
40
+ rb_define_method(ph_temp, "initialize", ph_temp_init, 0);
41
+
42
+ /* Document-method: getTemperatureInputCount
43
+ * call-seq: getTemperatureInputCount -> count
44
+ *
45
+ * Gets the number of thermocouple inputs supported by this board.
46
+ */
47
+ rb_define_method(ph_temp, "getTemperatureInputCount", ph_temp_get_temperature_input_count, 0);
48
+
49
+ /* Document-method: getTemperature
50
+ * call-seq: getTemperature(index) -> temperature
51
+ *
52
+ * Gets the temperature measured by a thermocouple input.
53
+ */
54
+ rb_define_method(ph_temp, "getTemperature", ph_temp_get_temperature, 1);
55
+
56
+ /* Document-method: getTemperatureMin
57
+ * call-seq: getTemperatureMin(index) -> temperature
58
+ *
59
+ * Gets the minimum temperature that can be measured by a thermocouple input. This depends on the type
60
+ * of thermocouple attached, as well as the ambient temperature.
61
+ */
62
+ rb_define_method(ph_temp, "getTemperatureMin", ph_temp_get_temperature_min, 1);
63
+
64
+ /* Document-method: getTemperatureMax
65
+ * call-seq: getTemperatureMax(index) -> temperature
66
+ *
67
+ * Gets the maximum temperature that can be measured by a thermocouple input. This depends on the type
68
+ * of thermocouple attached, as well as the ambient temperature.
69
+ */
70
+ rb_define_method(ph_temp, "getTemperatureMax", ph_temp_get_temperature_max, 1);
71
+
72
+ /* Document-method: getTemperatureChangeTrigger
73
+ * call-seq: getTemperatureChangeTrigger(index) -> trigger
74
+ *
75
+ * Gets the change trigger for a thermocouple input.
76
+ */
77
+ rb_define_method(ph_temp, "getTemperatureChangeTrigger", ph_temp_get_temperature_change_trigger, 1);
78
+
79
+ /* Document-method: setTemperatureChangeTrigger
80
+ * call-seq: setTemperatureChangeTrigger(index, trigger)
81
+ *
82
+ * Sets the change trigger for a thermocouple input.
83
+ */
84
+ rb_define_method(ph_temp, "setTemperatureChangeTrigger", ph_temp_set_temperature_change_trigger, 2);
85
+
86
+ /* Document-method: getPotential
87
+ * call-seq: getPotential(index) -> potential
88
+ *
89
+ * Gets the currently sensed potential for a thermocouple input.
90
+ */
91
+ rb_define_method(ph_temp, "getPotential", ph_temp_get_potential, 1);
92
+
93
+ /* Document-method: getPotentialMin
94
+ * call-seq: getPotentialMin(index) -> potential
95
+ *
96
+ * Gets the minimum potential that a thermocouple input can measure.
97
+ */
98
+ rb_define_method(ph_temp, "getPotentialMin", ph_temp_get_potential_min, 1);
99
+
100
+ /* Document-method: getPotentialMax
101
+ * call-seq: getPotentialMax(index) -> potential
102
+ *
103
+ * Gets the maximum potential that a thermocouple input can measure.
104
+ */
105
+ rb_define_method(ph_temp, "getPotentialMax", ph_temp_get_potential_max, 1);
106
+
107
+ /* Document-method: getAmbientTemperature
108
+ * call-seq: getAmbientTemperature -> temperature
109
+ *
110
+ * Gets the ambient (board) temperature.
111
+ */
112
+ rb_define_method(ph_temp, "getAmbientTemperature", ph_temp_get_ambient_temperature, 0);
113
+
114
+ /* Document-method: getAmbientTemperatureMin
115
+ * call-seq: getAmbientTemperatureMin -> temperature
116
+ *
117
+ * Gets the minimum temperature that the ambient onboard temperature sensor can measure.
118
+ */
119
+ rb_define_method(ph_temp, "getAmbientTemperatureMin", ph_temp_get_ambient_temperature_min, 0);
120
+
121
+ /* Document-method: getAmbientTemperatureMax
122
+ * call-seq: getAmbientTemperatureMax -> temperature
123
+ *
124
+ * Gets the maximum temperature that the ambient onboard temperature sensor can measure.
125
+ */
126
+ rb_define_method(ph_temp, "getAmbientTemperatureMax", ph_temp_get_ambient_temperature_max, 0);
127
+
128
+ /* Document-method: getThermocoupleType
129
+ * call-seq: getThermocoupleType(index) -> type
130
+ *
131
+ * Gets the type of thermocouple set to be at a thermocouple input. By default this is K-Type.
132
+ */
133
+ rb_define_method(ph_temp, "getThermocoupleType", ph_temp_get_thermocouple_type, 1);
134
+
135
+ /* Document-method: setThermocoupleType
136
+ * call-seq: setThermocoupleType(index, type)
137
+ *
138
+ * Sets the type of thermocouple plugged into a thermocouple input. By default this is K-Type.
139
+ */
140
+ rb_define_method(ph_temp, "setThermocoupleType", ph_temp_set_thermocouple_type, 2);
141
+
142
+ #ifdef PH_CALLBACK
143
+ rb_define_private_method(ph_temp, "ext_setOnTemperatureChangeHandler", ph_temp_set_on_temperature_change_handler, 1);
144
+ #endif
145
+
146
+ rb_define_alias(ph_temp, "temperature_input_count", "getTemperatureInputCount");
147
+ rb_define_alias(ph_temp, "temperature", "getTemperature");
148
+ rb_define_alias(ph_temp, "temperature_min", "getTemperatureMin");
149
+ rb_define_alias(ph_temp, "temperature_max", "getTemperatureMax");
150
+ rb_define_alias(ph_temp, "temperature_change_trigger", "getTemperatureChangeTrigger");
151
+ rb_define_alias(ph_temp, "set_temperature_change_trigger", "setTemperatureChangeTrigger");
152
+ rb_define_alias(ph_temp, "potential", "getPotential");
153
+ rb_define_alias(ph_temp, "potential_min", "getPotentialMin");
154
+ rb_define_alias(ph_temp, "potential_max", "getPotentialMax");
155
+ rb_define_alias(ph_temp, "ambient_temperature", "getAmbientTemperature");
156
+ rb_define_alias(ph_temp, "ambient_temperature_min", "getAmbientTemperatureMin");
157
+ rb_define_alias(ph_temp, "ambient_temperature_max", "getAmbientTemperatureMax");
158
+ rb_define_alias(ph_temp, "thermocouple_type", "getThermocoupleType");
159
+ rb_define_alias(ph_temp, "set_thermocouple_type", "setThermocoupleType");
160
+
161
+ return ph_temp;
162
+ }
163
+
164
+
165
+
166
+ VALUE ph_temp_init(VALUE self) {
167
+ ph_data_t *ph = get_ph_data(self);
168
+ ph_raise(CPhidgetTemperatureSensor_create((CPhidgetTemperatureSensorHandle *)(&(ph->handle))));
169
+ return self;
170
+ }
171
+
172
+ VALUE ph_temp_get_temperature_input_count(VALUE self) {
173
+ CPhidgetTemperatureSensorHandle handle = (CPhidgetTemperatureSensorHandle)get_ph_handle(self);
174
+ int count;
175
+ ph_raise(CPhidgetTemperatureSensor_getTemperatureInputCount(handle, &count));
176
+ return INT2FIX(count);
177
+ }
178
+
179
+ VALUE ph_temp_get_temperature(VALUE self, VALUE index) {
180
+ CPhidgetTemperatureSensorHandle handle = (CPhidgetTemperatureSensorHandle)get_ph_handle(self);
181
+ double temperature;
182
+ ph_raise(CPhidgetTemperatureSensor_getTemperature(handle, FIX2INT(index), &temperature));
183
+ return rb_float_new(temperature);
184
+ }
185
+
186
+ VALUE ph_temp_get_temperature_min(VALUE self, VALUE index) {
187
+ CPhidgetTemperatureSensorHandle handle = (CPhidgetTemperatureSensorHandle)get_ph_handle(self);
188
+ double temperature;
189
+ ph_raise(CPhidgetTemperatureSensor_getTemperatureMin(handle, FIX2INT(index), &temperature));
190
+ return rb_float_new(temperature);
191
+ }
192
+
193
+ VALUE ph_temp_get_temperature_max(VALUE self, VALUE index) {
194
+ CPhidgetTemperatureSensorHandle handle = (CPhidgetTemperatureSensorHandle)get_ph_handle(self);
195
+ double temperature;
196
+ ph_raise(CPhidgetTemperatureSensor_getTemperatureMax(handle, FIX2INT(index), &temperature));
197
+ return rb_float_new(temperature);
198
+ }
199
+
200
+ VALUE ph_temp_get_temperature_change_trigger(VALUE self, VALUE index) {
201
+ CPhidgetTemperatureSensorHandle handle = (CPhidgetTemperatureSensorHandle)get_ph_handle(self);
202
+ double temperature;
203
+ ph_raise(CPhidgetTemperatureSensor_getTemperatureChangeTrigger(handle, FIX2INT(index), &temperature));
204
+ return rb_float_new(temperature);
205
+ }
206
+
207
+ VALUE ph_temp_set_temperature_change_trigger(VALUE self, VALUE index, VALUE temperature) {
208
+ CPhidgetTemperatureSensorHandle handle = (CPhidgetTemperatureSensorHandle)get_ph_handle(self);
209
+ ph_raise(CPhidgetTemperatureSensor_setTemperatureChangeTrigger(handle, FIX2INT(index), NUM2DBL(temperature)));
210
+ return Qnil;
211
+ }
212
+
213
+ VALUE ph_temp_get_potential(VALUE self, VALUE index) {
214
+ CPhidgetTemperatureSensorHandle handle = (CPhidgetTemperatureSensorHandle)get_ph_handle(self);
215
+ double potential;
216
+ ph_raise(CPhidgetTemperatureSensor_getPotential(handle, FIX2INT(index), &potential));
217
+ return rb_float_new(potential);
218
+ }
219
+
220
+ VALUE ph_temp_get_potential_min(VALUE self, VALUE index) {
221
+ CPhidgetTemperatureSensorHandle handle = (CPhidgetTemperatureSensorHandle)get_ph_handle(self);
222
+ double potential;
223
+ ph_raise(CPhidgetTemperatureSensor_getPotentialMin(handle, FIX2INT(index), &potential));
224
+ return rb_float_new(potential);
225
+ }
226
+
227
+ VALUE ph_temp_get_potential_max(VALUE self, VALUE index) {
228
+ CPhidgetTemperatureSensorHandle handle = (CPhidgetTemperatureSensorHandle)get_ph_handle(self);
229
+ double potential;
230
+ ph_raise(CPhidgetTemperatureSensor_getPotentialMax(handle, FIX2INT(index), &potential));
231
+ return rb_float_new(potential);
232
+ }
233
+
234
+ VALUE ph_temp_get_ambient_temperature(VALUE self) {
235
+ CPhidgetTemperatureSensorHandle handle = (CPhidgetTemperatureSensorHandle)get_ph_handle(self);
236
+ double temperature;
237
+ ph_raise(CPhidgetTemperatureSensor_getAmbientTemperature(handle, &temperature));
238
+ return rb_float_new(temperature);
239
+ }
240
+
241
+ VALUE ph_temp_get_ambient_temperature_min(VALUE self) {
242
+ CPhidgetTemperatureSensorHandle handle = (CPhidgetTemperatureSensorHandle)get_ph_handle(self);
243
+ double temperature;
244
+ ph_raise(CPhidgetTemperatureSensor_getAmbientTemperatureMin(handle, &temperature));
245
+ return rb_float_new(temperature);
246
+ }
247
+
248
+ VALUE ph_temp_get_ambient_temperature_max(VALUE self) {
249
+ CPhidgetTemperatureSensorHandle handle = (CPhidgetTemperatureSensorHandle)get_ph_handle(self);
250
+ double temperature;
251
+ ph_raise(CPhidgetTemperatureSensor_getAmbientTemperatureMax(handle, &temperature));
252
+ return rb_float_new(temperature);
253
+ }
254
+
255
+ VALUE ph_temp_get_thermocouple_type(VALUE self, VALUE index) {
256
+ CPhidgetTemperatureSensorHandle handle = (CPhidgetTemperatureSensorHandle)get_ph_handle(self);
257
+ CPhidgetTemperatureSensor_ThermocoupleType type;
258
+ ph_raise(CPhidgetTemperatureSensor_getThermocoupleType(handle, FIX2INT(index), &type));
259
+ return INT2FIX(type);
260
+ }
261
+
262
+ VALUE ph_temp_set_thermocouple_type(VALUE self, VALUE index, VALUE type) {
263
+ CPhidgetTemperatureSensorHandle handle = (CPhidgetTemperatureSensorHandle)get_ph_handle(self);
264
+ ph_raise(CPhidgetTemperatureSensor_setThermocoupleType(handle, FIX2INT(index), (CPhidgetTemperatureSensor_ThermocoupleType)FIX2INT(type)));
265
+ return Qnil;
266
+ }
267
+
268
+
269
+ #ifdef PH_CALLBACK
270
+ VALUE ph_temp_set_on_temperature_change_handler(VALUE self, VALUE handler) {
271
+ ph_data_t *ph = get_ph_data(self);
272
+ ph_callback_data_t *callback_data = &ph->dev_callback_1;
273
+ if( TYPE(handler) == T_NIL ) {
274
+ callback_data->exit = true;
275
+ ph_raise(CPhidgetTemperatureSensor_set_OnTemperatureChange_Handler((CPhidgetTemperatureSensorHandle)ph->handle, NULL, (void *)NULL));
276
+ } else {
277
+ callback_data->called = false;
278
+ callback_data->exit = false;
279
+ callback_data->phidget = self;
280
+ callback_data->callback = handler;
281
+ ph_raise(CPhidgetTemperatureSensor_set_OnTemperatureChange_Handler((CPhidgetTemperatureSensorHandle)ph->handle, ph_temp_on_temperature_change, (void *)callback_data));
282
+ ph_callback_thread(callback_data);
283
+ }
284
+ return Qnil;
285
+ }
286
+
287
+
288
+ int ph_temp_on_temperature_change(CPhidgetTemperatureSensorHandle phid, void *userPtr, int index, double temperature) {
289
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
290
+ callback_data->called = true;
291
+ return EPHIDGET_OK;
292
+ }
293
+
294
+ #endif
295
+
@@ -0,0 +1,381 @@
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
+ VALUE Init_phidgets_textlcd(VALUE ph_module, VALUE ph_common) {
30
+ VALUE ph_textlcd = rb_define_class_under(ph_module, "TextLCD", ph_common);
31
+
32
+ /* no screen attached */
33
+ rb_define_const(ph_textlcd, "SCREEN_NONE", INT2FIX(PHIDGET_TEXTLCD_SCREEN_NONE));
34
+ /* 1 row, 8 column screen */
35
+ rb_define_const(ph_textlcd, "SCREEN_1x8", INT2FIX(PHIDGET_TEXTLCD_SCREEN_1x8));
36
+ /* 2 row, 8 column screen */
37
+ rb_define_const(ph_textlcd, "SCREEN_2x8", INT2FIX(PHIDGET_TEXTLCD_SCREEN_2x8));
38
+ /* 1 row, 16 column screen */
39
+ rb_define_const(ph_textlcd, "SCREEN_1x16", INT2FIX(PHIDGET_TEXTLCD_SCREEN_1x16));
40
+ /* 2 row, 16 column screen */
41
+ rb_define_const(ph_textlcd, "SCREEN_2x16", INT2FIX(PHIDGET_TEXTLCD_SCREEN_2x16));
42
+ /* 4 row, 16 column screen */
43
+ rb_define_const(ph_textlcd, "SCREEN_4x16", INT2FIX(PHIDGET_TEXTLCD_SCREEN_4x16));
44
+ /* 2 row, 20 column screen */
45
+ rb_define_const(ph_textlcd, "SCREEN_2x20", INT2FIX(PHIDGET_TEXTLCD_SCREEN_2x20));
46
+ /* 4 row, 20 column screen */
47
+ rb_define_const(ph_textlcd, "SCREEN_4x20", INT2FIX(PHIDGET_TEXTLCD_SCREEN_4x20));
48
+ /* 2 row, 24 column screen */
49
+ rb_define_const(ph_textlcd, "SCREEN_2x24", INT2FIX(PHIDGET_TEXTLCD_SCREEN_2x24));
50
+ /* 1 row, 40 column screen */
51
+ rb_define_const(ph_textlcd, "SCREEN_1x40", INT2FIX(PHIDGET_TEXTLCD_SCREEN_1x40));
52
+ /* 2 row, 40 column screen */
53
+ rb_define_const(ph_textlcd, "SCREEN_2x40", INT2FIX(PHIDGET_TEXTLCD_SCREEN_2x40));
54
+ /* 4 row, 40 column screen (special case, requires both screen connections) */
55
+ rb_define_const(ph_textlcd, "SCREEN_4x40", INT2FIX(PHIDGET_TEXTLCD_SCREEN_4x40));
56
+
57
+ /* Document-method: new
58
+ * call-seq: new
59
+ *
60
+ * Creates a Phidget TextLCD object.
61
+ */
62
+ rb_define_method(ph_textlcd, "initialize", ph_textlcd_init, 0);
63
+
64
+ /* Document-method: getRowCount
65
+ * call-seq: getRowCount -> count
66
+ *
67
+ * Gets the number of rows supported by this display.
68
+ */
69
+ rb_define_method(ph_textlcd, "getRowCount", ph_textlcd_get_row_count, 0);
70
+
71
+ /* Document-method: getColumnCount
72
+ * call-seq: getColumnCount -> count
73
+ *
74
+ * Gets the number of columns per supported by this display.
75
+ */
76
+ rb_define_method(ph_textlcd, "getColumnCount", ph_textlcd_get_column_count, 0);
77
+
78
+ /* Document-method: getBacklight
79
+ * call-seq: getBacklight -> true or false
80
+ *
81
+ * Gets the state of the backlight.
82
+ */
83
+ rb_define_method(ph_textlcd, "getBacklight", ph_textlcd_get_backlight, 0);
84
+
85
+ /* Document-method: setBacklight
86
+ * call-seq: setBacklight(state)
87
+ *
88
+ * Sets the state of the backlight.
89
+ */
90
+ rb_define_method(ph_textlcd, "setBacklight", ph_textlcd_set_backlight, 1);
91
+
92
+ /* Document-method: getBrightness
93
+ * call-seq: getBrightness -> brightness
94
+ *
95
+ * Gets the brightness of the backlight. Not supported on all TextLCDs
96
+ */
97
+ rb_define_method(ph_textlcd, "getBrightness", ph_textlcd_get_brightness, 0);
98
+
99
+ /* Document-method: setBrightness
100
+ * call-seq: setBrightness(brightness)
101
+ *
102
+ * Sets the brightness of the backlight. Not supported on all TextLCDs
103
+ */
104
+ rb_define_method(ph_textlcd, "setBrightness", ph_textlcd_set_brightness, 1);
105
+
106
+ /* Document-method: getContrast
107
+ * call-seq: getContrast -> contrast
108
+ *
109
+ * Gets the last set contrast value.
110
+ */
111
+ rb_define_method(ph_textlcd, "getContrast", ph_textlcd_get_contrast, 0);
112
+
113
+ /* Document-method: setContrast
114
+ * call-seq: setContrast(contrast)
115
+ *
116
+ * Sets the last set contrast value.
117
+ */
118
+ rb_define_method(ph_textlcd, "setContrast", ph_textlcd_set_contrast, 1);
119
+
120
+ /* Document-method: getCursorOn
121
+ * call-seq: getCursorOn -> true or false
122
+ *
123
+ * Gets the cursor visible state.
124
+ */
125
+ rb_define_method(ph_textlcd, "getCursorOn", ph_textlcd_get_cursor_on, 0);
126
+
127
+ /* Document-method: setCursorOn
128
+ * call-seq: setCursorOn(state)
129
+ *
130
+ * Sets the cursor visible state.
131
+ */
132
+ rb_define_method(ph_textlcd, "setCursorOn", ph_textlcd_set_cursor_on, 1);
133
+
134
+ /* Document-method: getCursorBlink
135
+ * call-seq: getCursorBlink -> true or false
136
+ *
137
+ * Gets the cursor blink state.
138
+ */
139
+ rb_define_method(ph_textlcd, "getCursorBlink", ph_textlcd_get_cursor_blink, 0);
140
+
141
+ /* Document-method: setCursorBlink
142
+ * call-seq: setCursorBlink(state)
143
+ *
144
+ * Sets the cursor blink state.
145
+ */
146
+ rb_define_method(ph_textlcd, "setCursorBlink", ph_textlcd_set_cursor_blink, 1);
147
+
148
+ /* Document-method: setCustomCharacter
149
+ * call-seq: setCustomCharacter(index, var1, var2)
150
+ *
151
+ * Sets a custom character. See the product manual for more information.
152
+ */
153
+ rb_define_method(ph_textlcd, "setCustomCharacter", ph_textlcd_set_custom_character, 3);
154
+
155
+ /* Document-method: setDisplayCharacter
156
+ * call-seq: setDisplayCharacter(index, column, character)
157
+ *
158
+ * Sets a single character on the display.
159
+ */
160
+ rb_define_method(ph_textlcd, "setDisplayCharacter", ph_textlcd_set_display_character, 3);
161
+
162
+ /* Document-method: setDisplayString
163
+ * call-seq: setDisplayString(index, string)
164
+ *
165
+ * Sets a row on the display.
166
+ */
167
+ rb_define_method(ph_textlcd, "setDisplayString", ph_textlcd_set_display_string, 2);
168
+
169
+ /* Document-method: getScreenCount
170
+ * call-seq: getScreenCount -> count
171
+ *
172
+ * Gets the number of Display supported by this TextLCD
173
+ */
174
+ rb_define_method(ph_textlcd, "getScreenCount", ph_textlcd_get_screen_count, 0);
175
+
176
+ /* Document-method: getScreen
177
+ * call-seq: getScreen -> index
178
+ *
179
+ * Gets the active screen.
180
+ */
181
+ rb_define_method(ph_textlcd, "getScreen", ph_textlcd_get_screen, 0);
182
+
183
+ /* Document-method: setScreen
184
+ * call-seq: setScreen(index)
185
+ *
186
+ * Sets the active screen. This is the screen that all subsequent API calls will apply to.
187
+ */
188
+ rb_define_method(ph_textlcd, "setScreen", ph_textlcd_set_screen, 1);
189
+
190
+ /* Document-method: getScreenSize
191
+ * call-seq: getScreenSize -> size
192
+ *
193
+ * Gets the screen size.
194
+ */
195
+ rb_define_method(ph_textlcd, "getScreenSize", ph_textlcd_get_screen_size, 0);
196
+
197
+ /* Document-method: setScreenSize
198
+ * call-seq: setScreenSize(size)
199
+ *
200
+ * Sets the active screen size. Only supported on the TextLCD Adapter.
201
+ */
202
+ rb_define_method(ph_textlcd, "setScreenSize", ph_textlcd_set_screen_size, 1);
203
+
204
+ /* Document-method: initScreen
205
+ * call-seq: initScreen
206
+ *
207
+ * Initializes the active screen. Only supported on the TextLCD adapter. This should be called
208
+ * if a screen is attached after power up, or to clear the screen after setting the size.
209
+ */
210
+ rb_define_method(ph_textlcd, "initScreen", ph_textlcd_init_screen, 0);
211
+
212
+ rb_define_alias(ph_textlcd, "row_count", "getRowCount");
213
+ rb_define_alias(ph_textlcd, "column_count", "getColumnCount");
214
+ rb_define_alias(ph_textlcd, "backlight?", "getBacklight");
215
+ rb_define_alias(ph_textlcd, "backlight=", "setBacklight");
216
+ rb_define_alias(ph_textlcd, "brightness", "getBrightness");
217
+ rb_define_alias(ph_textlcd, "brightness=", "setBrightness");
218
+ rb_define_alias(ph_textlcd, "contrast", "getContrast");
219
+ rb_define_alias(ph_textlcd, "contrast=", "setContrast");
220
+ rb_define_alias(ph_textlcd, "cursor_on?", "getCursorOn");
221
+ rb_define_alias(ph_textlcd, "cursor_on=", "setCursorOn");
222
+ rb_define_alias(ph_textlcd, "cursor_blink?", "getCursorBlink");
223
+ rb_define_alias(ph_textlcd, "cursor_blink=", "setCursorBlink");
224
+ rb_define_alias(ph_textlcd, "custom_character", "setCustomCharacter");
225
+ rb_define_alias(ph_textlcd, "display_character", "setDisplayCharacter");
226
+ rb_define_alias(ph_textlcd, "display_string", "setDisplayString");
227
+ rb_define_alias(ph_textlcd, "screen_count", "getScreenCount");
228
+ rb_define_alias(ph_textlcd, "screen", "getScreen");
229
+ rb_define_alias(ph_textlcd, "screen=", "setScreen");
230
+ rb_define_alias(ph_textlcd, "screen_size", "getScreenSize");
231
+ rb_define_alias(ph_textlcd, "screen_size=", "setScreenSize");
232
+ rb_define_alias(ph_textlcd, "init_screen", "initScreen");
233
+
234
+ return ph_textlcd;
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
+