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
@@ -0,0 +1,229 @@
1
+
2
+ #include "phidgets.h"
3
+
4
+ #define CURRENT_INPUT_CURRENT_CHANGE_CALLBACK 0
5
+
6
+
7
+ VALUE ph_current_input_init(VALUE self) {
8
+ ph_data_t *ph = get_ph_data(self);
9
+ ph_raise(PhidgetCurrentInput_create((PhidgetCurrentInputHandle *)(&(ph->handle))));
10
+ return self;
11
+ }
12
+
13
+ VALUE ph_current_input_get_current(VALUE self) {
14
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCurrentInput_getCurrent);
15
+ }
16
+
17
+ VALUE ph_current_input_get_min_current(VALUE self) {
18
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCurrentInput_getMinCurrent);
19
+ }
20
+
21
+ VALUE ph_current_input_get_max_current(VALUE self) {
22
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCurrentInput_getMaxCurrent);
23
+ }
24
+
25
+ VALUE ph_current_input_get_current_change_trigger(VALUE self) {
26
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCurrentInput_getCurrentChangeTrigger);
27
+ }
28
+
29
+ VALUE ph_current_input_set_current_change_trigger(VALUE self, VALUE trigger) {
30
+ ph_raise(PhidgetCurrentInput_setCurrentChangeTrigger((PhidgetCurrentInputHandle)get_ph_handle(self), NUM2DBL(trigger)));
31
+ return Qnil;
32
+ }
33
+
34
+ VALUE ph_current_input_get_min_current_change_trigger(VALUE self) {
35
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCurrentInput_getMinCurrentChangeTrigger);
36
+ }
37
+
38
+ VALUE ph_current_input_get_max_current_change_trigger(VALUE self) {
39
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetCurrentInput_getMaxCurrentChangeTrigger);
40
+ }
41
+
42
+ VALUE ph_current_input_get_data_interval(VALUE self) {
43
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetCurrentInput_getDataInterval);
44
+ }
45
+
46
+ VALUE ph_current_input_set_data_interval(VALUE self, VALUE interval) {
47
+ ph_raise(PhidgetCurrentInput_setDataInterval((PhidgetCurrentInputHandle)get_ph_handle(self), NUM2UINT(interval)));
48
+ return Qnil;
49
+ }
50
+
51
+ VALUE ph_current_input_get_min_data_interval(VALUE self) {
52
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetCurrentInput_getMinDataInterval);
53
+ }
54
+
55
+ VALUE ph_current_input_get_max_data_interval(VALUE self) {
56
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetCurrentInput_getMaxDataInterval);
57
+ }
58
+
59
+ VALUE ph_current_input_get_power_supply(VALUE self) {
60
+ return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetCurrentInput_getPowerSupply);
61
+ }
62
+
63
+ VALUE ph_current_input_set_power_supply(VALUE self, VALUE power_supply) {
64
+ ph_raise(PhidgetCurrentInput_setPowerSupply((PhidgetCurrentInputHandle)get_ph_handle(self), NUM2INT(power_supply)));
65
+ return Qnil;
66
+ }
67
+
68
+
69
+ void CCONV ph_current_input_on_current_change(PhidgetCurrentInputHandle phid, void *userPtr, double current) {
70
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
71
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
72
+ callback_data->arg1 = DBL2NUM(current);
73
+ callback_data->arg2 = Qnil;
74
+ callback_data->arg3 = Qnil;
75
+ callback_data->arg4 = Qnil;
76
+ sem_post(&callback_data->callback_called);
77
+ }
78
+
79
+ VALUE ph_current_input_set_on_current_change_handler(VALUE self, VALUE handler) {
80
+ ph_data_t *ph = get_ph_data(self);
81
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[CURRENT_INPUT_CURRENT_CHANGE_CALLBACK];
82
+ if( TYPE(handler) == T_NIL ) {
83
+ callback_data->callback = T_NIL;
84
+ callback_data->exit = true;
85
+ ph_raise(PhidgetCurrentInput_setOnCurrentChangeHandler((PhidgetCurrentInputHandle)ph->handle, NULL, (void *)NULL));
86
+ sem_post(&callback_data->callback_called);
87
+ } else {
88
+ callback_data->exit = false;
89
+ callback_data->phidget = self;
90
+ callback_data->callback = handler;
91
+ ph_raise(PhidgetCurrentInput_setOnCurrentChangeHandler((PhidgetCurrentInputHandle)ph->handle, ph_current_input_on_current_change, (void *)callback_data));
92
+ ph_callback_thread(callback_data);
93
+ }
94
+ return Qnil;
95
+ }
96
+
97
+
98
+ void Init_current_input() {
99
+ VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
100
+ VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
101
+ VALUE ph_current_input = rb_define_class_under(ph_module, "CurrentInput", ph_common);
102
+
103
+
104
+ /* Document-method: new
105
+ * call-seq: new
106
+ *
107
+ * Creates a Phidget CurrentInput object.
108
+ */
109
+ rb_define_method(ph_current_input, "initialize", ph_current_input_init, 0);
110
+
111
+ /* Document-method: getCurrent
112
+ * call-seq: getCurrent -> current
113
+ *
114
+ * The most recent current value that the channel has reported.
115
+ * This value will always be between MinCurrent and MaxCurrent.
116
+ */
117
+ rb_define_method(ph_current_input, "getCurrent", ph_current_input_get_current, 0);
118
+ rb_define_alias(ph_current_input, "current", "getCurrent");
119
+
120
+ /* Document-method: getMinCurrent
121
+ * call-seq: getMinCurrent -> current
122
+ *
123
+ * The minimum value the CurrentChange event will report.
124
+ */
125
+ rb_define_method(ph_current_input, "getMinCurrent", ph_current_input_get_min_current, 0);
126
+ rb_define_alias(ph_current_input, "min_current", "getMinCurrent");
127
+
128
+ /* Document-method: getMaxCurrent
129
+ * call-seq: getMaxCurrent -> current
130
+ *
131
+ * The maximum value the CurrentChange event will report.
132
+ */
133
+ rb_define_method(ph_current_input, "getMaxCurrent", ph_current_input_get_max_current, 0);
134
+ rb_define_alias(ph_current_input, "max_current", "getMaxCurrent");
135
+
136
+ /* Document-method: getCurrentChangeTrigger
137
+ * call-seq: getCurrentChangeTrigger -> trigger
138
+ *
139
+ * The channel will not issue a CurrentChange event until the current value has changed by the amount specified by the CurrentChangeTrigger.
140
+ * Setting the CurrentChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
141
+ */
142
+ rb_define_method(ph_current_input, "getCurrentChangeTrigger", ph_current_input_get_current_change_trigger, 0);
143
+ rb_define_alias(ph_current_input, "current_change_trigger", "getCurrentChangeTrigger");
144
+
145
+ /* Document-method: setCurrentChangeTrigger
146
+ * call-seq: setCurrentChangeTrigger(trigger)
147
+ *
148
+ * The channel will not issue a CurrentChange event until the current value has changed by the amount specified by the CurrentChangeTrigger.
149
+ * Setting the CurrentChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
150
+ */
151
+ rb_define_method(ph_current_input, "setCurrentChangeTrigger", ph_current_input_set_current_change_trigger, 1);
152
+ rb_define_alias(ph_current_input, "current_change_trigger=", "setCurrentChangeTrigger");
153
+
154
+ /* Document-method: getMinCurrentChangeTrigger
155
+ * call-seq: getMinCurrentChangeTrigger -> trigger
156
+ *
157
+ * The minimum value that CurrentChangeTrigger can be set to.
158
+ */
159
+ rb_define_method(ph_current_input, "getMinCurrentChangeTrigger", ph_current_input_get_min_current_change_trigger, 0);
160
+ rb_define_alias(ph_current_input, "min_current_change_trigger", "getMinCurrentChangeTrigger");
161
+
162
+ /* Document-method: getMaxCurrentChangeTrigger
163
+ * call-seq: getMaxCurrentChangeTrigger -> trigger
164
+ *
165
+ * The maximum value that CurrentChangeTrigger can be set to.
166
+ */
167
+ rb_define_method(ph_current_input, "getMaxCurrentChangeTrigger", ph_current_input_get_max_current_change_trigger, 0);
168
+ rb_define_alias(ph_current_input, "max_current_change_trigger", "getMaxCurrentChangeTrigger");
169
+
170
+ /* Document-method: getDataInterval
171
+ * call-seq: getDataInterval -> interval
172
+ *
173
+ * The DataInterval is the time that must elapse before the channel will fire another CurrentChange event.
174
+ * The data interval is bounded by MinDataInterval and MaxDataInterval.
175
+ * The timing between CurrentChange events can also affected by the CurrentChangeTrigger.
176
+ */
177
+ rb_define_method(ph_current_input, "getDataInterval", ph_current_input_get_data_interval, 0);
178
+ rb_define_alias(ph_current_input, "data_interval", "getDataInterval");
179
+
180
+ /* Document-method: setDataInterval
181
+ * call-seq: setDataInterval(interval)
182
+ *
183
+ * The DataInterval is the time that must elapse before the channel will fire another CurrentChange event.
184
+ * The data interval is bounded by MinDataInterval and MaxDataInterval.
185
+ * The timing between CurrentChange events can also affected by the CurrentChangeTrigger.
186
+ */
187
+ rb_define_method(ph_current_input, "setDataInterval", ph_current_input_set_data_interval, 1);
188
+ rb_define_alias(ph_current_input, "data_interval=", "setDataInterval");
189
+
190
+ /* Document-method: getMinDataInterval
191
+ * call-seq: getMinDataInterval -> interval
192
+ *
193
+ * The minimum value that DataInterval can be set to.
194
+ */
195
+ rb_define_method(ph_current_input, "getMinDataInterval", ph_current_input_get_min_data_interval, 0);
196
+ rb_define_alias(ph_current_input, "min_data_interval", "getMinDataInterval");
197
+
198
+ /* Document-method: getMaxDataInterval
199
+ * call-seq: getMaxDataInterval -> interval
200
+ *
201
+ * The maximum value that DataInterval can be set to.
202
+ */
203
+ rb_define_method(ph_current_input, "getMaxDataInterval", ph_current_input_get_max_data_interval, 0);
204
+ rb_define_alias(ph_current_input, "max_data_interval", "getMaxDataInterval");
205
+
206
+ /* Document-method: getPowerSupply
207
+ * call-seq: getPowerSupply -> power_supply
208
+ *
209
+ * Choose the power supply voltage.
210
+ * Set this to the voltage specified in the attached sensor's data sheet to power it.
211
+ * Set to POWER_SUPPLY_OFF to turn off the supply to save power.
212
+ */
213
+ rb_define_method(ph_current_input, "getPowerSupply", ph_current_input_get_power_supply, 0);
214
+ rb_define_alias(ph_current_input, "power_supply", "getPowerSupply");
215
+
216
+ /* Document-method: setPowerSupply
217
+ * call-seq: setPowerSupply(power_supply)
218
+ *
219
+ * Choose the power supply voltage.
220
+ * Set this to the voltage specified in the attached sensor's data sheet to power it.
221
+ * Set to POWER_SUPPLY_OFF to turn off the supply to save power.
222
+ */
223
+ rb_define_method(ph_current_input, "setPowerSupply", ph_current_input_set_power_supply, 1);
224
+ rb_define_alias(ph_current_input, "power_supply=", "setPowerSupply");
225
+
226
+
227
+ rb_define_private_method(ph_current_input, "ext_setOnCurrentChangeHandler", ph_current_input_set_on_current_change_handler, 1);
228
+ }
229
+
@@ -0,0 +1,562 @@
1
+
2
+ #include "phidgets.h"
3
+
4
+ #define DC_MOTOR_BACK_EMF_CHANGE_CALLBACK 0
5
+ #define DC_MOTOR_BRAKING_STRENGTH_CHANGE_CALLBACK 1
6
+ #define DC_MOTOR_VELOCITY_UPDATE_CALLBACK 2
7
+
8
+
9
+ VALUE ph_dc_motor_init(VALUE self) {
10
+ ph_data_t *ph = get_ph_data(self);
11
+ ph_raise(PhidgetDCMotor_create((PhidgetDCMotorHandle *)(&(ph->handle))));
12
+ return self;
13
+ }
14
+
15
+ VALUE ph_dc_motor_get_acceleration(VALUE self) {
16
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getAcceleration);
17
+ }
18
+
19
+ VALUE ph_dc_motor_set_acceleration(VALUE self, VALUE accel) {
20
+ ph_raise(PhidgetDCMotor_setAcceleration((PhidgetDCMotorHandle)get_ph_handle(self), NUM2DBL(accel)));
21
+ return Qnil;
22
+ }
23
+
24
+ VALUE ph_dc_motor_get_min_acceleration(VALUE self) {
25
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMinAcceleration);
26
+ }
27
+
28
+ VALUE ph_dc_motor_get_max_acceleration(VALUE self) {
29
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMaxAcceleration);
30
+ }
31
+
32
+ VALUE ph_dc_motor_get_back_emf(VALUE self) {
33
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getBackEMF);
34
+ }
35
+
36
+ VALUE ph_dc_motor_get_back_emf_sensing_state(VALUE self) {
37
+ return ph_get_bool(get_ph_handle(self), (phidget_get_bool_func)PhidgetDCMotor_getBackEMFSensingState);
38
+ }
39
+
40
+ VALUE ph_dc_motor_set_back_emf_sensing_state(VALUE self, VALUE sensing_state) {
41
+ ph_raise(PhidgetDCMotor_setBackEMFSensingState((PhidgetDCMotorHandle)get_ph_handle(self), TYPE(sensing_state) == T_TRUE ? PTRUE : PFALSE));
42
+ return Qnil;
43
+ }
44
+
45
+ VALUE ph_dc_motor_get_braking_strength(VALUE self) {
46
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getBrakingStrength);
47
+ }
48
+
49
+ VALUE ph_dc_motor_get_min_braking_strength(VALUE self) {
50
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMinBrakingStrength);
51
+ }
52
+
53
+ VALUE ph_dc_motor_get_max_braking_strength(VALUE self) {
54
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMaxBrakingStrength);
55
+ }
56
+
57
+ VALUE ph_dc_motor_get_current_limit(VALUE self) {
58
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getCurrentLimit);
59
+ }
60
+
61
+ VALUE ph_dc_motor_set_current_limit(VALUE self, VALUE current_limit) {
62
+ ph_raise(PhidgetDCMotor_setCurrentLimit((PhidgetDCMotorHandle)get_ph_handle(self), NUM2DBL(current_limit)));
63
+ return Qnil;
64
+ }
65
+
66
+ VALUE ph_dc_motor_get_min_current_limit(VALUE self) {
67
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMinCurrentLimit);
68
+ }
69
+
70
+ VALUE ph_dc_motor_get_max_current_limit(VALUE self) {
71
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMaxCurrentLimit);
72
+ }
73
+
74
+ VALUE ph_dc_motor_get_current_regulator_gain(VALUE self) {
75
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getCurrentRegulatorGain);
76
+ }
77
+
78
+ VALUE ph_dc_motor_set_current_regulator_gain(VALUE self, VALUE gain) {
79
+ ph_raise(PhidgetDCMotor_setCurrentRegulatorGain((PhidgetDCMotorHandle)get_ph_handle(self), NUM2DBL(gain)));
80
+ return Qnil;
81
+ }
82
+
83
+ VALUE ph_dc_motor_get_min_current_regulator_gain(VALUE self) {
84
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMinCurrentRegulatorGain);
85
+ }
86
+
87
+ VALUE ph_dc_motor_get_max_current_regulator_gain(VALUE self) {
88
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMaxCurrentRegulatorGain);
89
+ }
90
+
91
+ VALUE ph_dc_motor_get_data_interval(VALUE self) {
92
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDCMotor_getDataInterval);
93
+ }
94
+
95
+ VALUE ph_dc_motor_set_data_interval(VALUE self, VALUE interval) {
96
+ ph_raise(PhidgetDCMotor_setDataInterval((PhidgetDCMotorHandle)get_ph_handle(self), NUM2UINT(interval)));
97
+ return Qnil;
98
+ }
99
+
100
+ VALUE ph_dc_motor_get_min_data_interval(VALUE self) {
101
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDCMotor_getMinDataInterval);
102
+ }
103
+
104
+ VALUE ph_dc_motor_get_max_data_interval(VALUE self) {
105
+ return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetDCMotor_getMaxDataInterval);
106
+ }
107
+
108
+ VALUE ph_dc_motor_get_fan_mode(VALUE self) {
109
+ return ph_get_int(get_ph_handle(self), (phidget_get_int_func)PhidgetDCMotor_getFanMode);
110
+ }
111
+
112
+ VALUE ph_dc_motor_set_fan_mode(VALUE self, VALUE fan_mode) {
113
+ ph_raise(PhidgetDCMotor_setFanMode((PhidgetDCMotorHandle)get_ph_handle(self), NUM2INT(fan_mode)));
114
+ return Qnil;
115
+ }
116
+
117
+ VALUE ph_dc_motor_get_target_braking_strength(VALUE self) {
118
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getTargetBrakingStrength);
119
+ }
120
+
121
+ VALUE ph_dc_motor_set_target_braking_strength(VALUE self, VALUE target_braking_strength) {
122
+ ph_raise(PhidgetDCMotor_setTargetBrakingStrength((PhidgetDCMotorHandle)get_ph_handle(self), NUM2DBL(target_braking_strength)));
123
+ return Qnil;
124
+ }
125
+
126
+ VALUE ph_dc_motor_get_target_velocity(VALUE self) {
127
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getTargetVelocity);
128
+ }
129
+
130
+ VALUE ph_dc_motor_set_target_velocity(VALUE self, VALUE target_velocity) {
131
+ ph_raise(PhidgetDCMotor_setTargetVelocity((PhidgetDCMotorHandle)get_ph_handle(self), NUM2DBL(target_velocity)));
132
+ return Qnil;
133
+ }
134
+
135
+ VALUE ph_dc_motor_get_velocity(VALUE self) {
136
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getVelocity);
137
+ }
138
+
139
+ VALUE ph_dc_motor_get_min_velocity(VALUE self) {
140
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMinVelocity);
141
+ }
142
+
143
+ VALUE ph_dc_motor_get_max_velocity(VALUE self) {
144
+ return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetDCMotor_getMaxVelocity);
145
+ }
146
+
147
+
148
+ void CCONV ph_dc_motor_on_back_emf_change(PhidgetDCMotorHandle phid, void *userPtr, double back_emf) {
149
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
150
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
151
+ callback_data->arg1 = DBL2NUM(back_emf);
152
+ callback_data->arg2 = Qnil;
153
+ callback_data->arg3 = Qnil;
154
+ callback_data->arg4 = Qnil;
155
+ sem_post(&callback_data->callback_called);
156
+ }
157
+
158
+
159
+ VALUE ph_dc_motor_set_on_back_emf_change_handler(VALUE self, VALUE handler) {
160
+ ph_data_t *ph = get_ph_data(self);
161
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[DC_MOTOR_BACK_EMF_CHANGE_CALLBACK];
162
+ if( TYPE(handler) == T_NIL ) {
163
+ callback_data->callback = T_NIL;
164
+ callback_data->exit = true;
165
+ ph_raise(PhidgetDCMotor_setOnBackEMFChangeHandler((PhidgetDCMotorHandle)ph->handle, NULL, (void *)NULL));
166
+ sem_post(&callback_data->callback_called);
167
+ } else {
168
+ callback_data->exit = false;
169
+ callback_data->phidget = self;
170
+ callback_data->callback = handler;
171
+ ph_raise(PhidgetDCMotor_setOnBackEMFChangeHandler((PhidgetDCMotorHandle)ph->handle, ph_dc_motor_on_back_emf_change, (void *)callback_data));
172
+ ph_callback_thread(callback_data);
173
+ }
174
+ return Qnil;
175
+ }
176
+
177
+
178
+ void CCONV ph_dc_motor_on_braking_strength_change(PhidgetDCMotorHandle phid, void *userPtr, double braking_strength) {
179
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
180
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
181
+ callback_data->arg1 = DBL2NUM(braking_strength);
182
+ callback_data->arg2 = Qnil;
183
+ callback_data->arg3 = Qnil;
184
+ callback_data->arg4 = Qnil;
185
+ sem_post(&callback_data->callback_called);
186
+ }
187
+
188
+
189
+ VALUE ph_dc_motor_set_on_braking_strength_change_handler(VALUE self, VALUE handler) {
190
+ ph_data_t *ph = get_ph_data(self);
191
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[DC_MOTOR_BRAKING_STRENGTH_CHANGE_CALLBACK];
192
+ if( TYPE(handler) == T_NIL ) {
193
+ callback_data->callback = T_NIL;
194
+ callback_data->exit = true;
195
+ ph_raise(PhidgetDCMotor_setOnBrakingStrengthChangeHandler((PhidgetDCMotorHandle)ph->handle, NULL, (void *)NULL));
196
+ sem_post(&callback_data->callback_called);
197
+ } else {
198
+ callback_data->exit = false;
199
+ callback_data->phidget = self;
200
+ callback_data->callback = handler;
201
+ ph_raise(PhidgetDCMotor_setOnBrakingStrengthChangeHandler((PhidgetDCMotorHandle)ph->handle, ph_dc_motor_on_braking_strength_change, (void *)callback_data));
202
+ ph_callback_thread(callback_data);
203
+ }
204
+ return Qnil;
205
+ }
206
+
207
+
208
+ void CCONV ph_dc_motor_on_velocity_update(PhidgetDCMotorHandle phid, void *userPtr, double velocity) {
209
+ ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
210
+ while(sem_wait(&callback_data->handler_ready)!=0) {};
211
+ callback_data->arg1 = DBL2NUM(velocity);
212
+ callback_data->arg2 = Qnil;
213
+ callback_data->arg3 = Qnil;
214
+ callback_data->arg4 = Qnil;
215
+ sem_post(&callback_data->callback_called);
216
+ }
217
+
218
+
219
+ VALUE ph_dc_motor_set_on_velocity_update_handler(VALUE self, VALUE handler) {
220
+ ph_data_t *ph = get_ph_data(self);
221
+ ph_callback_data_t *callback_data = &ph->dev_callbacks[DC_MOTOR_VELOCITY_UPDATE_CALLBACK];
222
+ if( TYPE(handler) == T_NIL ) {
223
+ callback_data->callback = T_NIL;
224
+ callback_data->exit = true;
225
+ ph_raise(PhidgetDCMotor_setOnVelocityUpdateHandler((PhidgetDCMotorHandle)ph->handle, NULL, (void *)NULL));
226
+ sem_post(&callback_data->callback_called);
227
+ } else {
228
+ callback_data->exit = false;
229
+ callback_data->phidget = self;
230
+ callback_data->callback = handler;
231
+ ph_raise(PhidgetDCMotor_setOnVelocityUpdateHandler((PhidgetDCMotorHandle)ph->handle, ph_dc_motor_on_velocity_update, (void *)callback_data));
232
+ ph_callback_thread(callback_data);
233
+ }
234
+ return Qnil;
235
+ }
236
+
237
+
238
+
239
+ void Init_dc_motor() {
240
+ VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
241
+ VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
242
+ VALUE ph_dc_motor = rb_define_class_under(ph_module, "DCMotor", ph_common);
243
+
244
+
245
+
246
+ /* Document-method: new
247
+ * call-seq: new
248
+ *
249
+ * Creates a Phidget DCMotor object.
250
+ */
251
+ rb_define_method(ph_dc_motor, "initialize", ph_dc_motor_init, 0);
252
+
253
+ /* Document-method: getAcceleration
254
+ * call-seq: getAcceleration -> acceleration
255
+ *
256
+ * The rate at which the controller can change the motor's Velocity.
257
+ * The acceleration is bounded by MinAccleration and MaxAcceleration.
258
+ */
259
+ rb_define_method(ph_dc_motor, "getAcceleration", ph_dc_motor_get_acceleration, 0);
260
+ rb_define_alias(ph_dc_motor, "acceleration", "getAcceleration");
261
+
262
+ /* Document-method: setAcceleration
263
+ * call-seq: setAcceleration(acceleration)
264
+ *
265
+ * The rate at which the controller can change the motor's Velocity.
266
+ * The acceleration is bounded by MinAccleration and MaxAcceleration.
267
+ */
268
+ rb_define_method(ph_dc_motor, "setAcceleration", ph_dc_motor_set_acceleration, 1);
269
+ rb_define_alias(ph_dc_motor, "acceleration=", "setAcceleration");
270
+
271
+ /* Document-method: getMinAcceleration
272
+ * call-seq: getMinAcceleration -> acceleration
273
+ *
274
+ * The minimum value that Acceleration can be set to.
275
+ */
276
+ rb_define_method(ph_dc_motor, "getMinAcceleration", ph_dc_motor_get_min_acceleration, 0);
277
+ rb_define_alias(ph_dc_motor, "min_acceleration", "getMinAcceleration");
278
+
279
+ /* Document-method: getMaxAcceleration
280
+ * call-seq: getMaxAcceleration -> acceleration
281
+ *
282
+ * The maximum value that Acceleration can be set to.
283
+ */
284
+ rb_define_method(ph_dc_motor, "getMaxAcceleration", ph_dc_motor_get_max_acceleration, 0);
285
+ rb_define_alias(ph_dc_motor, "max_acceleration", "getMaxAcceleration");
286
+
287
+ /* Document-method: getBackEMF
288
+ * call-seq: getBackEMF -> back_emf
289
+ *
290
+ * The most recent BackEMF value that the controller has reported.
291
+ */
292
+ rb_define_method(ph_dc_motor, "getBackEMF", ph_dc_motor_get_back_emf, 0);
293
+ rb_define_alias(ph_dc_motor, "back_emf", "getBackEMF");
294
+
295
+ /* Document-method: getBackEMFSensingState
296
+ * call-seq: getBackEMFSensingState -> sensing_state
297
+ *
298
+ * When BackEMFSensingState is enabled, the controller will measure and report the BackEMF.
299
+ * The motor will coast (freewheel) 5% of the time while the back EMF is being measured (800μs every 16ms).
300
+ * Therefore, at a DutyCycle of 100%, the motor will only be driven for 95% of the time.
301
+ */
302
+ rb_define_method(ph_dc_motor, "getBackEMFSensingState", ph_dc_motor_get_back_emf_sensing_state, 0);
303
+ rb_define_alias(ph_dc_motor, "back_emf_sensing_state", "getBackEMFSensingState");
304
+
305
+ /* Document-method: setBackEMFSensingState
306
+ * call-seq: setBackEMFSensingState(sensing_state)
307
+ *
308
+ * When BackEMFSensingState is enabled, the controller will measure and report the BackEMF.
309
+ * The motor will coast (freewheel) 5% of the time while the back EMF is being measured (800μs every 16ms).
310
+ * Therefore, at a DutyCycle of 100%, the motor will only be driven for 95% of the time.
311
+ */
312
+ rb_define_method(ph_dc_motor, "setBackEMFSensingState", ph_dc_motor_set_back_emf_sensing_state, 1);
313
+ rb_define_alias(ph_dc_motor, "back_emf_sensing_state=", "setBackEMFSensingState");
314
+
315
+ /* Document-method: getBrakingStrength
316
+ * call-seq: getBrakingStrength -> braking_strength
317
+ *
318
+ * The most recent braking strength value that the controller has reported.
319
+ */
320
+ rb_define_method(ph_dc_motor, "getBrakingStrength", ph_dc_motor_get_braking_strength, 0);
321
+ rb_define_alias(ph_dc_motor, "braking_strength", "getBrakingStrength");
322
+
323
+ /* Document-method: getMinBrakingStrength
324
+ * call-seq: getMinBrakingStrength -> braking_strength
325
+ *
326
+ * The minimum value that TargetBrakingStrength can be set to.
327
+ */
328
+ rb_define_method(ph_dc_motor, "getMinBrakingStrength", ph_dc_motor_get_min_braking_strength, 0);
329
+ rb_define_alias(ph_dc_motor, "min_braking_strength", "getMinBrakingStrength");
330
+
331
+ /* Document-method: getMaxBrakingStrength
332
+ * call-seq: getMaxBrakingStrength -> braking_strength
333
+ *
334
+ * The maximum value that TargetBrakingStrength can be set to.
335
+ */
336
+ rb_define_method(ph_dc_motor, "getMaxBrakingStrength", ph_dc_motor_get_max_braking_strength, 0);
337
+ rb_define_alias(ph_dc_motor, "max_braking_strength", "getMaxBrakingStrength");
338
+
339
+ /* Document-method: getCurrentLimit
340
+ * call-seq: getCurrentLimit -> current_limit
341
+ *
342
+ * The controller will limit the current through the motor to the CurrentLimit value.
343
+ */
344
+ rb_define_method(ph_dc_motor, "getCurrentLimit", ph_dc_motor_get_current_limit, 0);
345
+ rb_define_alias(ph_dc_motor, "current_limit", "getCurrentLimit");
346
+
347
+ /* Document-method: setCurrentLimit
348
+ * call-seq: setCurrentLimit(current_limit)
349
+ *
350
+ * The controller will limit the current through the motor to the CurrentLimit value.
351
+ */
352
+ rb_define_method(ph_dc_motor, "setCurrentLimit", ph_dc_motor_set_current_limit, 1);
353
+ rb_define_alias(ph_dc_motor, "current_limit=", "setCurrentLimit");
354
+
355
+ /* Document-method: getMinCurrentLimit
356
+ * call-seq: getMinCurrentLimit -> current_limit
357
+ *
358
+ * The minimum value that CurrentLimit can be set to.
359
+ */
360
+ rb_define_method(ph_dc_motor, "getMinCurrentLimit", ph_dc_motor_get_min_current_limit, 0);
361
+ rb_define_alias(ph_dc_motor, "min_current_limit", "getMinCurrentLimit");
362
+
363
+ /* Document-method: getMaxCurrentLimit
364
+ * call-seq: getMaxCurrentLimit -> current_limit
365
+ *
366
+ * The maximum value that CurrentLimit can be set to.
367
+ */
368
+ rb_define_method(ph_dc_motor, "getMaxCurrentLimit", ph_dc_motor_get_max_current_limit, 0);
369
+ rb_define_alias(ph_dc_motor, "max_current_limit", "getMaxCurrentLimit");
370
+
371
+ /* Document-method: getCurrentRegulatorGain
372
+ * call-seq: getCurrentRegulatorGain -> regulator_gain
373
+ *
374
+ * Depending on power supply voltage and motor coil inductance, current through the motor can
375
+ * change relatively slowly or extremely rapidly. A physically larger DC Motor will typically
376
+ * have a lower inductance, requiring a higher current regulator gain. A higher power supply
377
+ * voltage will result in motor current changing more rapidly, requiring a higher current regulator
378
+ * gain. If the current regulator gain is too small, spikes in current will occur, causing large
379
+ * variations in torque, and possibly damaging the motor controller. If the current regulator gain
380
+ * is too high, the current will jitter, causing the motor to sound 'rough', especially when changing directions.
381
+ * Each DC Motor we sell specifies a suitable current regulator gain.
382
+ */
383
+ rb_define_method(ph_dc_motor, "getCurrentRegulatorGain", ph_dc_motor_get_current_regulator_gain, 0);
384
+ rb_define_alias(ph_dc_motor, "current_regulator_gain", "getCurrentRegulatorGain");
385
+
386
+ /* Document-method: setCurrentRegulatorGain
387
+ * call-seq: setCurrentRegulatorGain(regulator_gain)
388
+ *
389
+ * Depending on power supply voltage and motor coil inductance, current through the motor can
390
+ * change relatively slowly or extremely rapidly. A physically larger DC Motor will typically
391
+ * have a lower inductance, requiring a higher current regulator gain. A higher power supply
392
+ * voltage will result in motor current changing more rapidly, requiring a higher current regulator
393
+ * gain. If the current regulator gain is too small, spikes in current will occur, causing large
394
+ * variations in torque, and possibly damaging the motor controller. If the current regulator gain
395
+ * is too high, the current will jitter, causing the motor to sound 'rough', especially when changing directions.
396
+ * Each DC Motor we sell specifies a suitable current regulator gain.
397
+ */
398
+ rb_define_method(ph_dc_motor, "setCurrentRegulatorGain", ph_dc_motor_set_current_regulator_gain, 1);
399
+ rb_define_alias(ph_dc_motor, "current_regulator_gain=", "setCurrentRegulatorGain");
400
+
401
+ /* Document-method: getMinCurrentRegulatorGain
402
+ * call-seq: getMinCurrentRegulatorGain -> regulator_gain
403
+ *
404
+ * The minimum value that CurrentRegulatorGain can be set to.
405
+ */
406
+ rb_define_method(ph_dc_motor, "getMinCurrentRegulatorGain", ph_dc_motor_get_min_current_regulator_gain, 0);
407
+ rb_define_alias(ph_dc_motor, "min_current_regulator_gain", "getMinCurrentRegulatorGain");
408
+
409
+ /* Document-method: getMaxCurrentRegulatorGain
410
+ * call-seq: getMaxCurrentRegulatorGain -> regulator_gain
411
+ *
412
+ * The maximum value that CurrentRegulatorGain can be set to.
413
+ */
414
+ rb_define_method(ph_dc_motor, "getMaxCurrentRegulatorGain", ph_dc_motor_get_max_current_regulator_gain, 0);
415
+ rb_define_alias(ph_dc_motor, "max_current_regulator_gain", "getMaxCurrentRegulatorGain");
416
+
417
+ /* Document-method: getDataInterval
418
+ * call-seq: getDataInterval -> interval
419
+ *
420
+ * The DataInterval is the time that must elapse before the controller will fire another update event.
421
+ * The data interval is bounded by MinDataInterval and MaxDataInterval.
422
+ */
423
+ rb_define_method(ph_dc_motor, "getDataInterval", ph_dc_motor_get_data_interval, 0);
424
+ rb_define_alias(ph_dc_motor, "data_interval", "getDataInterval");
425
+
426
+ /* Document-method: setDataInterval
427
+ * call-seq: setDataInterval(interval)
428
+ *
429
+ * The DataInterval is the time that must elapse before the controller will fire another update event.
430
+ * The data interval is bounded by MinDataInterval and MaxDataInterval.
431
+ */
432
+ rb_define_method(ph_dc_motor, "setDataInterval", ph_dc_motor_set_data_interval, 1);
433
+ rb_define_alias(ph_dc_motor, "data_interval=", "setDataInterval");
434
+
435
+ /* Document-method: getMinDataInterval
436
+ * call-seq: getMinDataInterval -> interval
437
+ *
438
+ * The minimum value that DataInterval can be set to.
439
+ */
440
+ rb_define_method(ph_dc_motor, "getMinDataInterval", ph_dc_motor_get_min_data_interval, 0);
441
+ rb_define_alias(ph_dc_motor, "min_data_interval", "getMinDataInterval");
442
+
443
+ /* Document-method: getMaxDataInterval
444
+ * call-seq: getMaxDataInterval -> interval
445
+ *
446
+ * The maximum value that DataInterval can be set to.
447
+ */
448
+ rb_define_method(ph_dc_motor, "getMaxDataInterval", ph_dc_motor_get_max_data_interval, 0);
449
+ rb_define_alias(ph_dc_motor, "max_data_interval", "getMaxDataInterval");
450
+
451
+ /* Document-method: getFanMode
452
+ * call-seq: getFanMode -> fan_mode
453
+ *
454
+ * The FanMode dictates the operating condition of the fan.
455
+ * Choose between on, off, or automatic (based on temperature).
456
+ * If the FanMode is set to automatic, the fan will turn on when the temperature
457
+ * reaches 70°C and it will remain on until the temperature falls below 55°C.
458
+ * If the FanMode is off, the controller will still turn on the fan if the temperature
459
+ * reaches 85°C and it will remain on until it falls below 70°C.
460
+ */
461
+ rb_define_method(ph_dc_motor, "getFanMode", ph_dc_motor_get_fan_mode, 0);
462
+ rb_define_alias(ph_dc_motor, "fan_mode", "getFanMode");
463
+
464
+ /* Document-method: setFanMode
465
+ * call-seq: setFanMode(fan_mode)
466
+ *
467
+ * The FanMode dictates the operating condition of the fan.
468
+ * Choose between on, off, or automatic (based on temperature).
469
+ * If the FanMode is set to automatic, the fan will turn on when the temperature
470
+ * reaches 70°C and it will remain on until the temperature falls below 55°C.
471
+ * If the FanMode is off, the controller will still turn on the fan if the temperature
472
+ * reaches 85°C and it will remain on until it falls below 70°C.
473
+ */
474
+ rb_define_method(ph_dc_motor, "setFanMode", ph_dc_motor_set_fan_mode, 1);
475
+ rb_define_alias(ph_dc_motor, "fan_mode=", "setFanMode");
476
+
477
+ /* Document-method: getTargetBrakingStrength
478
+ * call-seq: getTargetBrakingStrength -> braking_strength
479
+ *
480
+ * When a motor is not being actively driven forward or reverse, you can choose if the motor will be allowed to freely turn, or will resist being turned.
481
+ * A low TargetBrakingStrength value corresponds to free wheeling, this will have the following effects:
482
+ * The motor will continue to rotate after the controller is no longer driving the motor (i.e. Velocity is 0), due to inertia.
483
+ * The motor shaft will provide little resistance to being turned when it is stopped.
484
+ * A higher TargetBrakingStrength value will resist being turned, this will have the following effects:
485
+ * The motor will more stop more quickly if it is in motion and braking has been requested. It will fight against the rotation of the shaft.
486
+ * Braking mode is enabled by setting the Velocity to MinVelocity.
487
+ */
488
+ rb_define_method(ph_dc_motor, "getTargetBrakingStrength", ph_dc_motor_get_target_braking_strength, 0);
489
+ rb_define_alias(ph_dc_motor, "target_braking_strength", "getTargetBrakingStrength");
490
+
491
+ /* Document-method: setTargetBrakingStrength
492
+ * call-seq: setTargetBrakingStrength(braking_strength)
493
+ *
494
+ * When a motor is not being actively driven forward or reverse, you can choose if the motor will be allowed to freely turn, or will resist being turned.
495
+ * A low TargetBrakingStrength value corresponds to free wheeling, this will have the following effects:
496
+ * The motor will continue to rotate after the controller is no longer driving the motor (i.e. Velocity is 0), due to inertia.
497
+ * The motor shaft will provide little resistance to being turned when it is stopped.
498
+ * A higher TargetBrakingStrength value will resist being turned, this will have the following effects:
499
+ * The motor will more stop more quickly if it is in motion and braking has been requested. It will fight against the rotation of the shaft.
500
+ * Braking mode is enabled by setting the Velocity to MinVelocity.
501
+ */
502
+ rb_define_method(ph_dc_motor, "setTargetBrakingStrength", ph_dc_motor_set_target_braking_strength, 1);
503
+ rb_define_alias(ph_dc_motor, "target_braking_strength=", "setTargetBrakingStrength");
504
+
505
+ /* Document-method: getTargetVelocity
506
+ * call-seq: getTargetVelocity -> velocity
507
+ *
508
+ * The average voltage across the motor is based on the TargetVelocity value.
509
+ * At a constant load, increasing the target velocity will increase the speed of the motor.
510
+ * TargetVelocity is bounded by -1×MaxVelocity and MaxVelocity, where a sign change (±) is indicitave of a direction change.
511
+ * Setting TargetVelocity to MinVelocity will stop the motor. See TargetBrakingStrength for more information on stopping the motor.
512
+ * The units of TargetVelocity and Acceleration refer to 'duty cycle'. This is because the controller must rapidly switch the power
513
+ * on/off (i.e. change the duty cycle) in order to manipulate the voltage across the motor.
514
+ */
515
+ rb_define_method(ph_dc_motor, "getTargetVelocity", ph_dc_motor_get_target_velocity, 0);
516
+ rb_define_alias(ph_dc_motor, "target_velocity", "getTargetVelocity");
517
+
518
+ /* Document-method: setTargetVelocity
519
+ * call-seq: setTargetVelocity(velocity)
520
+ *
521
+ * The average voltage across the motor is based on the TargetVelocity value.
522
+ * At a constant load, increasing the target velocity will increase the speed of the motor.
523
+ * TargetVelocity is bounded by -1×MaxVelocity and MaxVelocity, where a sign change (±) is indicitave of a direction change.
524
+ * Setting TargetVelocity to MinVelocity will stop the motor. See TargetBrakingStrength for more information on stopping the motor.
525
+ * The units of TargetVelocity and Acceleration refer to 'duty cycle'. This is because the controller must rapidly switch the power
526
+ * on/off (i.e. change the duty cycle) in order to manipulate the voltage across the motor.
527
+ */
528
+ rb_define_method(ph_dc_motor, "setTargetVelocity", ph_dc_motor_set_target_velocity, 1);
529
+ rb_define_alias(ph_dc_motor, "target_velocity=", "setTargetVelocity");
530
+
531
+ /* Document-method: getVelocity
532
+ * call-seq: getVelocity -> velocity
533
+ *
534
+ * The most recent velocity value that the controller has reported.
535
+ */
536
+ rb_define_method(ph_dc_motor, "getVelocity", ph_dc_motor_get_velocity, 0);
537
+ rb_define_alias(ph_dc_motor, "velocity", "getVelocity");
538
+
539
+ /* Document-method: getMinVelocity
540
+ * call-seq: getMinVelocity -> velocity
541
+ *
542
+ * The minimum value that TargetVelocity can be set to
543
+ * Set the TargetVelocity to MinVelocity to stop the motor. See TargetBrakingStrength for more information on stopping the motor.
544
+ * TargetVelocity is bounded by -1×MaxVelocity and MaxVelocity, where a sign change (±) is indicitave of a direction change.
545
+ */
546
+ rb_define_method(ph_dc_motor, "getMinVelocity", ph_dc_motor_get_min_velocity, 0);
547
+ rb_define_alias(ph_dc_motor, "min_velocity", "getMinVelocity");
548
+
549
+ /* Document-method: getMaxVelocity
550
+ * call-seq: getMaxVelocity -> velocity
551
+ *
552
+ * The maximum value that TargetVelocity can be set to.
553
+ * TargetVelocity is bounded by -1×MaxVelocity and MaxVelocity, where a sign change (±) is indicitave of a direction change.
554
+ */
555
+ rb_define_method(ph_dc_motor, "getMaxVelocity", ph_dc_motor_get_max_velocity, 0);
556
+ rb_define_alias(ph_dc_motor, "max_velocity", "getMaxVelocity");
557
+
558
+ rb_define_private_method(ph_dc_motor, "ext_setOnBackEMFChangeHandler", ph_dc_motor_set_on_back_emf_change_handler, 1);
559
+ rb_define_private_method(ph_dc_motor, "ext_setOnBrakingStrengthChangeHandler", ph_dc_motor_set_on_braking_strength_change_handler, 1);
560
+ rb_define_private_method(ph_dc_motor, "ext_setOnVelocityUpdateHandler", ph_dc_motor_set_on_velocity_update_handler, 1);
561
+ }
562
+