phidgets 0.1.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.txt +3 -0
- data/README.rdoc +32 -43
- data/Rakefile +4 -2
- data/bin/phidget +18 -72
- data/ext/phidgets/extconf.rb +5 -8
- data/ext/phidgets/phidgets.c +708 -173
- data/ext/phidgets/phidgets.h +54 -35
- data/ext/phidgets/phidgets_accelerometer.c +193 -109
- data/ext/phidgets/phidgets_bldc_motor.c +529 -0
- data/ext/phidgets/phidgets_capacitive_touch.c +302 -0
- data/ext/phidgets/phidgets_common.c +570 -315
- data/ext/phidgets/phidgets_current_input.c +229 -0
- data/ext/phidgets/phidgets_dc_motor.c +562 -0
- data/ext/phidgets/phidgets_dictionary.c +154 -213
- data/ext/phidgets/phidgets_digital_input.c +127 -0
- data/ext/phidgets/phidgets_digital_output.c +288 -0
- data/ext/phidgets/phidgets_distance_sensor.c +295 -0
- data/ext/phidgets/phidgets_encoder.c +211 -192
- data/ext/phidgets/phidgets_frequency_counter.c +310 -177
- data/ext/phidgets/phidgets_gps.c +226 -164
- data/ext/phidgets/phidgets_gyroscope.c +195 -0
- data/ext/phidgets/phidgets_hub.c +39 -0
- data/ext/phidgets/phidgets_humidity_sensor.c +200 -0
- data/ext/phidgets/phidgets_ir.c +211 -171
- data/ext/phidgets/phidgets_lcd.c +512 -0
- data/ext/phidgets/phidgets_light_sensor.c +200 -0
- data/ext/phidgets/phidgets_log.c +263 -0
- data/ext/phidgets/phidgets_magnetometer.c +279 -0
- data/ext/phidgets/phidgets_manager.c +86 -297
- data/ext/phidgets/phidgets_motor_position_controller.c +787 -0
- data/ext/phidgets/phidgets_phsensor.c +200 -152
- data/ext/phidgets/phidgets_power_guard.c +144 -0
- data/ext/phidgets/phidgets_pressure_sensor.c +200 -0
- data/ext/phidgets/phidgets_rc_servo.c +672 -0
- data/ext/phidgets/phidgets_resistance_input.c +227 -0
- data/ext/phidgets/phidgets_rfid.c +107 -221
- data/ext/phidgets/phidgets_sound_sensor.c +284 -0
- data/ext/phidgets/phidgets_spatial.c +124 -318
- data/ext/phidgets/phidgets_stepper.c +457 -430
- data/ext/phidgets/phidgets_temp_sensor.c +223 -228
- data/ext/phidgets/phidgets_voltage_input.c +428 -0
- data/ext/phidgets/phidgets_voltage_output.c +167 -0
- data/ext/phidgets/phidgets_voltage_ratio_input.c +435 -0
- data/lib/phidgets.rb +21 -14
- data/lib/phidgets/accelerometer.rb +11 -15
- data/lib/phidgets/bldc_motor.rb +45 -0
- data/lib/phidgets/capacitive_touch.rb +33 -0
- data/lib/phidgets/common.rb +40 -69
- data/lib/phidgets/current_input.rb +21 -0
- data/lib/phidgets/dc_motor.rb +45 -0
- data/lib/phidgets/dictionary.rb +30 -39
- data/lib/phidgets/digital_input.rb +21 -0
- data/lib/phidgets/digital_output.rb +56 -0
- data/lib/phidgets/distance_sensor.rb +33 -0
- data/lib/phidgets/encoder.rb +1 -29
- data/lib/phidgets/frequency_counter.rb +23 -14
- data/lib/phidgets/gps.rb +34 -26
- data/lib/phidgets/gyroscope.rb +21 -0
- data/lib/phidgets/humidity_sensor.rb +21 -0
- data/lib/phidgets/ir.rb +34 -39
- data/lib/phidgets/light_sensor.rb +21 -0
- data/lib/phidgets/magnetometer.rb +21 -0
- data/lib/phidgets/manager.rb +18 -66
- data/lib/phidgets/motor_position_controller.rb +45 -0
- data/lib/phidgets/ph_sensor.rb +2 -6
- data/lib/phidgets/pressure_sensor.rb +21 -0
- data/lib/phidgets/rc_servo.rb +58 -0
- data/lib/phidgets/resistance_input.rb +21 -0
- data/lib/phidgets/rfid.rb +22 -38
- data/lib/phidgets/sound_sensor.rb +21 -0
- data/lib/phidgets/spatial.rb +11 -15
- data/lib/phidgets/stepper.rb +48 -50
- data/lib/phidgets/temperature_sensor.rb +11 -15
- data/lib/phidgets/version.rb +5 -0
- data/lib/phidgets/voltage_input.rb +34 -0
- data/lib/phidgets/voltage_output.rb +23 -0
- data/lib/phidgets/voltage_ratio_input.rb +34 -0
- data/phidgets.gemspec +3 -22
- data/test/test_accelerometer.rb +42 -23
- data/test/test_bldc_motor.rb +134 -0
- data/test/test_capacitive_touch.rb +82 -0
- data/test/test_common.rb +125 -108
- data/test/test_current_input.rb +62 -0
- data/test/test_dc_motor.rb +146 -0
- data/test/test_dictionary.rb +22 -54
- data/test/test_digital_input.rb +30 -0
- data/test/test_digital_output.rb +70 -0
- data/test/test_distance_sensor.rb +76 -0
- data/test/test_encoder.rb +45 -38
- data/test/test_frequency_counter.rb +71 -36
- data/test/test_gps.rb +29 -38
- data/test/test_gyroscope.rb +54 -0
- data/test/test_helper.rb +0 -1
- data/test/test_hub.rb +14 -0
- data/test/test_humidity_sensor.rb +58 -0
- data/test/test_ir.rb +34 -34
- data/test/test_lcd.rb +146 -0
- data/test/test_light_sensor.rb +58 -0
- data/test/test_magnetometer.rb +78 -0
- data/test/test_manager.rb +10 -79
- data/test/test_motor_control.rb +146 -108
- data/test/test_phidgets.rb +2 -14
- data/test/test_phsensor.rb +46 -34
- data/test/test_power_guard.rb +42 -0
- data/test/test_pressure_sensor.rb +58 -0
- data/test/test_rc_servo.rb +174 -0
- data/test/test_resistance_input.rb +66 -0
- data/test/test_rfid.rb +15 -54
- data/test/test_sound_sensor.rb +78 -0
- data/test/test_spatial.rb +19 -85
- data/test/test_stepper.rb +89 -98
- data/test/test_temp_sensor.rb +42 -47
- data/test/test_voltage_input.rb +102 -0
- data/test/test_voltage_output.rb +46 -0
- data/test/test_voltage_ratio_input.rb +102 -0
- metadata +72 -89
- data/ext/phidgets/phidgets_advanced_servo.c +0 -567
- data/ext/phidgets/phidgets_analog.c +0 -139
- data/ext/phidgets/phidgets_bridge.c +0 -263
- data/ext/phidgets/phidgets_interface_kit.c +0 -340
- data/ext/phidgets/phidgets_led.c +0 -178
- data/ext/phidgets/phidgets_motor_control.c +0 -642
- data/ext/phidgets/phidgets_servo.c +0 -276
- data/ext/phidgets/phidgets_text_lcd.c +0 -381
- data/ext/phidgets/phidgets_text_led.c +0 -107
- data/ext/phidgets/phidgets_weight_sensor.c +0 -113
- data/lib/phidgets/advanced_servo.rb +0 -49
- data/lib/phidgets/analog.rb +0 -8
- data/lib/phidgets/bridge.rb +0 -25
- data/lib/phidgets/interfacekit.rb +0 -49
- data/lib/phidgets/led.rb +0 -8
- data/lib/phidgets/motor_control.rb +0 -110
- data/lib/phidgets/servo.rb +0 -23
- data/lib/phidgets/text_lcd.rb +0 -8
- data/lib/phidgets/text_led.rb +0 -8
- data/lib/phidgets/weight_sensor.rb +0 -25
- data/test/test_advanced_servo.rb +0 -152
- data/test/test_analog.rb +0 -45
- data/test/test_bridge.rb +0 -77
- data/test/test_interfacekit.rb +0 -97
- data/test/test_led.rb +0 -55
- data/test/test_servo.rb +0 -67
- data/test/test_text_lcd.rb +0 -115
- data/test/test_text_led.rb +0 -35
- data/test/test_weight_sensor.rb +0 -32
@@ -0,0 +1,200 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
#define LIGHT_SENSOR_ILLUMINANCE_CHANGE_CALLBACK 0
|
5
|
+
|
6
|
+
|
7
|
+
VALUE ph_light_init(VALUE self) {
|
8
|
+
ph_data_t *ph = get_ph_data(self);
|
9
|
+
ph_raise(PhidgetLightSensor_create((PhidgetLightSensorHandle *)(&(ph->handle))));
|
10
|
+
return self;
|
11
|
+
}
|
12
|
+
|
13
|
+
VALUE ph_light_get_data_interval(VALUE self) {
|
14
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetLightSensor_getDataInterval);
|
15
|
+
}
|
16
|
+
|
17
|
+
VALUE ph_light_set_data_interval(VALUE self, VALUE interval) {
|
18
|
+
ph_raise(PhidgetLightSensor_setDataInterval((PhidgetLightSensorHandle)get_ph_handle(self), NUM2UINT(interval)));
|
19
|
+
return Qnil;
|
20
|
+
}
|
21
|
+
|
22
|
+
VALUE ph_light_get_min_data_interval(VALUE self) {
|
23
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetLightSensor_getMinDataInterval);
|
24
|
+
}
|
25
|
+
|
26
|
+
VALUE ph_light_get_max_data_interval(VALUE self) {
|
27
|
+
return ph_get_uint(get_ph_handle(self), (phidget_get_uint_func)PhidgetLightSensor_getMaxDataInterval);
|
28
|
+
}
|
29
|
+
|
30
|
+
VALUE ph_light_get_illuminance(VALUE self) {
|
31
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetLightSensor_getIlluminance);
|
32
|
+
}
|
33
|
+
|
34
|
+
VALUE ph_light_get_min_illuminance(VALUE self) {
|
35
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetLightSensor_getMinIlluminance);
|
36
|
+
}
|
37
|
+
|
38
|
+
VALUE ph_light_get_max_illuminance(VALUE self) {
|
39
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetLightSensor_getMaxIlluminance);
|
40
|
+
}
|
41
|
+
|
42
|
+
VALUE ph_light_get_illuminance_change_trigger(VALUE self) {
|
43
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetLightSensor_getIlluminanceChangeTrigger);
|
44
|
+
}
|
45
|
+
|
46
|
+
VALUE ph_light_set_illuminance_change_trigger(VALUE self, VALUE change_trigger) {
|
47
|
+
ph_raise(PhidgetLightSensor_setIlluminanceChangeTrigger((PhidgetLightSensorHandle)get_ph_handle(self), NUM2DBL(change_trigger)));
|
48
|
+
return Qnil;
|
49
|
+
}
|
50
|
+
|
51
|
+
VALUE ph_light_get_min_illuminance_change_trigger(VALUE self) {
|
52
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetLightSensor_getMinIlluminanceChangeTrigger);
|
53
|
+
}
|
54
|
+
|
55
|
+
VALUE ph_light_get_max_illuminance_change_trigger(VALUE self) {
|
56
|
+
return ph_get_double(get_ph_handle(self), (phidget_get_double_func)PhidgetLightSensor_getMaxIlluminanceChangeTrigger);
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
void CCONV ph_light_on_illuminance_change(PhidgetLightSensorHandle phid, void *userPtr, double illuminance) {
|
61
|
+
ph_callback_data_t *callback_data = ((ph_callback_data_t *)userPtr);
|
62
|
+
while(sem_wait(&callback_data->handler_ready)!=0) {};
|
63
|
+
callback_data->arg1 = DBL2NUM(illuminance);
|
64
|
+
callback_data->arg2 = Qnil;
|
65
|
+
callback_data->arg3 = Qnil;
|
66
|
+
callback_data->arg4 = Qnil;
|
67
|
+
sem_post(&callback_data->callback_called);
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
VALUE ph_light_set_on_illuminance_change_handler(VALUE self, VALUE handler) {
|
72
|
+
ph_data_t *ph = get_ph_data(self);
|
73
|
+
ph_callback_data_t *callback_data = &ph->dev_callbacks[LIGHT_SENSOR_ILLUMINANCE_CHANGE_CALLBACK];
|
74
|
+
if( TYPE(handler) == T_NIL ) {
|
75
|
+
callback_data->callback = T_NIL;
|
76
|
+
callback_data->exit = true;
|
77
|
+
ph_raise(PhidgetLightSensor_setOnIlluminanceChangeHandler((PhidgetLightSensorHandle)ph->handle, NULL, (void *)NULL));
|
78
|
+
sem_post(&callback_data->callback_called);
|
79
|
+
} else {
|
80
|
+
callback_data->exit = false;
|
81
|
+
callback_data->phidget = self;
|
82
|
+
callback_data->callback = handler;
|
83
|
+
ph_raise(PhidgetLightSensor_setOnIlluminanceChangeHandler((PhidgetLightSensorHandle)ph->handle, ph_light_on_illuminance_change, (void *)callback_data));
|
84
|
+
ph_callback_thread(callback_data);
|
85
|
+
}
|
86
|
+
return Qnil;
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
void Init_light() {
|
91
|
+
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
92
|
+
VALUE ph_common = rb_const_get(ph_module, rb_intern("Common"));
|
93
|
+
VALUE ph_light = rb_define_class_under(ph_module, "LightSensor", ph_common);
|
94
|
+
|
95
|
+
/* Document-method: new
|
96
|
+
* call-seq: new
|
97
|
+
*
|
98
|
+
* Creates a Phidget LightSensor object.
|
99
|
+
*/
|
100
|
+
rb_define_method(ph_light, "initialize", ph_light_init, 0);
|
101
|
+
|
102
|
+
/* Document-method: getDataInterval
|
103
|
+
* call-seq: getDataInterval -> interval
|
104
|
+
*
|
105
|
+
* The DataInterval is the time that must elapse before the channel will fire another IlluminanceChange event.
|
106
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
107
|
+
* The timing between IlluminanceChange events can also affected by the IlluminanceChangeTrigger.
|
108
|
+
*/
|
109
|
+
rb_define_method(ph_light, "getDataInterval", ph_light_get_data_interval, 0);
|
110
|
+
rb_define_alias(ph_light, "data_interval", "getDataInterval");
|
111
|
+
|
112
|
+
/* Document-method: setDataInterval
|
113
|
+
* call-seq: setDataInterval(interval)
|
114
|
+
*
|
115
|
+
* The DataInterval is the time that must elapse before the channel will fire another IlluminanceChange event.
|
116
|
+
* The data interval is bounded by MinDataInterval and MaxDataInterval.
|
117
|
+
* The timing between IlluminanceChange events can also affected by the IlluminanceChangeTrigger.
|
118
|
+
*/
|
119
|
+
rb_define_method(ph_light, "setDataInterval", ph_light_set_data_interval, 1);
|
120
|
+
rb_define_alias(ph_light, "data_interval=", "setDataInterval");
|
121
|
+
|
122
|
+
/* Document-method: getMinDataInterval
|
123
|
+
* call-seq: getMinDataInterval -> interval
|
124
|
+
*
|
125
|
+
* The minimum value that DataInterval can be set to.
|
126
|
+
*/
|
127
|
+
rb_define_method(ph_light, "getMinDataInterval", ph_light_get_min_data_interval, 0);
|
128
|
+
rb_define_alias(ph_light, "min_data_interval", "getMinDataInterval");
|
129
|
+
|
130
|
+
/* Document-method: getMaxDataInterval
|
131
|
+
* call-seq: getMaxDataInterval -> interval
|
132
|
+
*
|
133
|
+
* The maximum value that DataInterval can be set to.
|
134
|
+
*/
|
135
|
+
rb_define_method(ph_light, "getMaxDataInterval", ph_light_get_max_data_interval, 0);
|
136
|
+
rb_define_alias(ph_light, "max_data_interval", "getMaxDataInterval");
|
137
|
+
|
138
|
+
/* Document-method: getIlluminance
|
139
|
+
* call-seq: getIlluminance -> illuminance
|
140
|
+
*
|
141
|
+
* The most recent illuminance value that the channel has reported.
|
142
|
+
* This value will always be between MinIlluminance and MaxIlluminance.
|
143
|
+
*/
|
144
|
+
rb_define_method(ph_light, "getIlluminance", ph_light_get_illuminance, 0);
|
145
|
+
rb_define_alias(ph_light, "illuminance", "getIlluminance");
|
146
|
+
|
147
|
+
/* Document-method: getMinIlluminance
|
148
|
+
* call-seq: getMinIlluminance -> illuminance
|
149
|
+
*
|
150
|
+
* The minimum value that the IlluminanceChange event will report.
|
151
|
+
*/
|
152
|
+
rb_define_method(ph_light, "getMinIlluminance", ph_light_get_min_illuminance, 0);
|
153
|
+
rb_define_alias(ph_light, "min_illuminance", "getMinIlluminance");
|
154
|
+
|
155
|
+
/* Document-method: getMaxIlluminance
|
156
|
+
* call-seq: getMaxIlluminance -> illuminance
|
157
|
+
*
|
158
|
+
* The maximum value that the IlluminanceChange event will report.
|
159
|
+
*/
|
160
|
+
rb_define_method(ph_light, "getMaxIlluminance", ph_light_get_max_illuminance, 0);
|
161
|
+
rb_define_alias(ph_light, "max_illuminance", "getMaxIlluminance");
|
162
|
+
|
163
|
+
/* Document-method: getIlluminanceChangeTrigger
|
164
|
+
* call-seq: getIlluminanceChangeTrigger -> change_trigger
|
165
|
+
*
|
166
|
+
* The channel will not issue a IlluminanceChange event until the illuminance value has changed by the amount specified by the IlluminanceChangeTrigger.
|
167
|
+
* Setting the IlluminanceChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
|
168
|
+
*/
|
169
|
+
rb_define_method(ph_light, "getIlluminanceChangeTrigger", ph_light_get_illuminance_change_trigger, 0);
|
170
|
+
rb_define_alias(ph_light, "illuminance_change_trigger", "getIlluminanceChangeTrigger");
|
171
|
+
|
172
|
+
/* Document-method: setIlluminanceChangeTrigger
|
173
|
+
* call-seq: setIlluminanceChangeTrigger(change_trigger)
|
174
|
+
*
|
175
|
+
* The channel will not issue a IlluminanceChange event until the illuminance value has changed by the amount specified by the IlluminanceChangeTrigger.
|
176
|
+
* Setting the IlluminanceChangeTrigger to 0 will result in the channel firing events every DataInterval. This is useful for applications that implement their own data filtering.
|
177
|
+
*/
|
178
|
+
rb_define_method(ph_light, "setIlluminanceChangeTrigger", ph_light_set_illuminance_change_trigger, 1);
|
179
|
+
rb_define_alias(ph_light, "illuminance_change_trigger=", "setIlluminanceChangeTrigger");
|
180
|
+
|
181
|
+
/* Document-method: getMinIlluminanceChangeTrigger
|
182
|
+
* call-seq: getMinIlluminanceChangeTrigger -> change_trigger
|
183
|
+
*
|
184
|
+
* The minimum value that IlluminanceChangeTrigger can be set to.
|
185
|
+
*/
|
186
|
+
rb_define_method(ph_light, "getMinIlluminanceChangeTrigger", ph_light_get_min_illuminance_change_trigger, 0);
|
187
|
+
rb_define_alias(ph_light, "min_illuminance_change_trigger", "getMinIlluminanceChangeTrigger");
|
188
|
+
|
189
|
+
/* Document-method: getMaxIlluminanceChangeTrigger
|
190
|
+
* call-seq: getMaxIlluminanceChangeTrigger -> change_trigger
|
191
|
+
*
|
192
|
+
* The maximum value that IlluminanceChangeTrigger can be set to.
|
193
|
+
*/
|
194
|
+
rb_define_method(ph_light, "getMaxIlluminanceChangeTrigger", ph_light_get_max_illuminance_change_trigger, 0);
|
195
|
+
rb_define_alias(ph_light, "max_illuminance_change_trigger", "getMaxIlluminanceChangeTrigger");
|
196
|
+
|
197
|
+
|
198
|
+
rb_define_private_method(ph_light, "ext_setOnIlluminanceChangeHandler", ph_light_set_on_illuminance_change_handler, 1);
|
199
|
+
}
|
200
|
+
|
@@ -0,0 +1,263 @@
|
|
1
|
+
|
2
|
+
#include "phidgets.h"
|
3
|
+
|
4
|
+
|
5
|
+
VALUE ph_log_enable(VALUE self, VALUE level, VALUE output_file);
|
6
|
+
VALUE ph_log_disable(VALUE self);
|
7
|
+
VALUE ph_log_get_level(VALUE self);
|
8
|
+
VALUE ph_log_set_level(VALUE self, VALUE level);
|
9
|
+
VALUE ph_log_log(VALUE self, VALUE level, VALUE message);
|
10
|
+
VALUE ph_log_loge(VALUE self, VALUE file, VALUE line, VALUE function, VALUE source, VALUE level, VALUE message);
|
11
|
+
VALUE ph_log_rotate(VALUE self);
|
12
|
+
VALUE ph_log_is_rotating(VALUE self);
|
13
|
+
VALUE ph_log_get_rotating(VALUE self);
|
14
|
+
VALUE ph_log_set_rotating(VALUE self, VALUE size, VALUE keep_count);
|
15
|
+
VALUE ph_log_enable_rotating(VALUE self);
|
16
|
+
VALUE ph_log_disable_rotating(VALUE self);
|
17
|
+
VALUE ph_log_add_source(VALUE self, VALUE source, VALUE level);
|
18
|
+
VALUE ph_log_get_source_level(VALUE self, VALUE source);
|
19
|
+
VALUE ph_log_set_source_level(VALUE self, VALUE source, VALUE level);
|
20
|
+
VALUE ph_log_get_sources(VALUE self);
|
21
|
+
|
22
|
+
|
23
|
+
void Init_logging() {
|
24
|
+
VALUE ph_module = rb_const_get(rb_cObject, rb_intern("Phidgets"));
|
25
|
+
VALUE ph_log = rb_define_class_under(ph_module, "Log", rb_cObject);
|
26
|
+
|
27
|
+
rb_define_const(ph_log, "CRITICAL", INT2FIX(PHIDGET_LOG_CRITICAL));
|
28
|
+
rb_define_const(ph_log, "ERROR", INT2FIX(PHIDGET_LOG_ERROR));
|
29
|
+
rb_define_const(ph_log, "WARNING", INT2FIX(PHIDGET_LOG_WARNING));
|
30
|
+
rb_define_const(ph_log, "DEBUG", INT2FIX(PHIDGET_LOG_DEBUG));
|
31
|
+
rb_define_const(ph_log, "INFO", INT2FIX(PHIDGET_LOG_INFO));
|
32
|
+
rb_define_const(ph_log, "VERBOSE", INT2FIX(PHIDGET_LOG_VERBOSE));
|
33
|
+
|
34
|
+
/*
|
35
|
+
* Document-method: enable
|
36
|
+
* call-seq: enable(log_level, output_file)
|
37
|
+
*
|
38
|
+
* Enables logging.
|
39
|
+
*/
|
40
|
+
rb_define_singleton_method(ph_log, "enable", ph_log_enable, 2);
|
41
|
+
|
42
|
+
/*
|
43
|
+
* Document-method: disable
|
44
|
+
* call-seq: disable
|
45
|
+
*
|
46
|
+
* Disables logging.
|
47
|
+
*/
|
48
|
+
rb_define_singleton_method(ph_log, "disable", ph_log_disable, 0);
|
49
|
+
|
50
|
+
/*
|
51
|
+
* Document-method: getLevel
|
52
|
+
* call-seq: getLevel
|
53
|
+
*
|
54
|
+
* Gets the log level for the phidget22 source.
|
55
|
+
*/
|
56
|
+
rb_define_singleton_method(ph_log, "getLevel", ph_log_get_level, 0);
|
57
|
+
|
58
|
+
/*
|
59
|
+
* Document-method: setLevel
|
60
|
+
* call-seq: setLevel
|
61
|
+
*
|
62
|
+
* Sets the log level for all sources not prefaced with _phidget22.
|
63
|
+
*/
|
64
|
+
rb_define_singleton_method(ph_log, "setLevel", ph_log_set_level, 1);
|
65
|
+
|
66
|
+
/*
|
67
|
+
* Document-method: log
|
68
|
+
* call-seq: log(log_level, msg)
|
69
|
+
*
|
70
|
+
* Appends a message to the log.
|
71
|
+
*/
|
72
|
+
rb_define_singleton_method(ph_log, "log", ph_log_log, 2);
|
73
|
+
|
74
|
+
/*
|
75
|
+
* Document-method: loge
|
76
|
+
* call-seq: loge(file, line, function, source, log_level, msg)
|
77
|
+
*
|
78
|
+
* Writes a message to the Phidget library log from a specified source.
|
79
|
+
*/
|
80
|
+
rb_define_singleton_method(ph_log, "loge", ph_log_loge, 6);
|
81
|
+
|
82
|
+
/*
|
83
|
+
* Document-method: rotate
|
84
|
+
* call-seq: rotate
|
85
|
+
*
|
86
|
+
* Manually rotate the log file. This will only have an effect if automatic rotation is disabled and the log file is larger than the specified maximum file size.
|
87
|
+
*/
|
88
|
+
rb_define_singleton_method(ph_log, "rotate", ph_log_rotate, 0);
|
89
|
+
|
90
|
+
/*
|
91
|
+
* Document-method: isRotating
|
92
|
+
* call-seq: isRotating
|
93
|
+
*
|
94
|
+
* Determines if the library is automatically rotating the log file.
|
95
|
+
*/
|
96
|
+
rb_define_singleton_method(ph_log, "isRotating", ph_log_is_rotating, 0);
|
97
|
+
|
98
|
+
/*
|
99
|
+
* Document-method: getRotating
|
100
|
+
* call-seq: getRotating
|
101
|
+
*
|
102
|
+
* Gets the current log rotation parameters.
|
103
|
+
*/
|
104
|
+
rb_define_singleton_method(ph_log, "getRotating", ph_log_get_rotating, 0);
|
105
|
+
|
106
|
+
/*
|
107
|
+
* Document-method: setRotating
|
108
|
+
* call-seq: setRotating(size, keep_count)
|
109
|
+
*
|
110
|
+
* Sets log rotation parameters.
|
111
|
+
*/
|
112
|
+
rb_define_singleton_method(ph_log, "setRotating", ph_log_set_rotating, 2);
|
113
|
+
|
114
|
+
/*
|
115
|
+
* Document-method: enableRotating
|
116
|
+
* call-seq: enableRotating
|
117
|
+
*
|
118
|
+
* Enables automatic rotation of the log file (the default).
|
119
|
+
*/
|
120
|
+
rb_define_singleton_method(ph_log, "enableRotating", ph_log_enable_rotating, 0);
|
121
|
+
|
122
|
+
/*
|
123
|
+
* Document-method: disableRotating
|
124
|
+
* call-seq: disableRotating
|
125
|
+
*
|
126
|
+
* Disables automatic rotation of the log file.
|
127
|
+
*/
|
128
|
+
rb_define_singleton_method(ph_log, "disableRotating", ph_log_disable_rotating, 0);
|
129
|
+
|
130
|
+
/*
|
131
|
+
* Document-method: addSource
|
132
|
+
* call-seq: addSource(source, level)
|
133
|
+
*
|
134
|
+
* Adds a source to the Phidget logging system. This is useful for declaring a source and setting its log level before sending any messages.
|
135
|
+
*/
|
136
|
+
rb_define_singleton_method(ph_log, "addSource", ph_log_add_source, 2);
|
137
|
+
|
138
|
+
/*
|
139
|
+
* Document-method: getSourceLevel
|
140
|
+
* call-seq: getSourceLevel(source)
|
141
|
+
*
|
142
|
+
* Gets the log level of the specified log source.
|
143
|
+
*/
|
144
|
+
rb_define_singleton_method(ph_log, "getSourceLevel", ph_log_get_source_level, 1);
|
145
|
+
|
146
|
+
/*
|
147
|
+
* Document-method: setSourceLevel
|
148
|
+
* call-seq: setSourceLevel(source, level)
|
149
|
+
*
|
150
|
+
* Sets the log level of the specified log source.
|
151
|
+
*/
|
152
|
+
rb_define_singleton_method(ph_log, "setSourceLevel", ph_log_set_source_level, 2);
|
153
|
+
|
154
|
+
/*
|
155
|
+
* Document-method: getSources
|
156
|
+
* call-seq: getSources
|
157
|
+
*
|
158
|
+
* Gets an array of log sources in the system.
|
159
|
+
*/
|
160
|
+
rb_define_singleton_method(ph_log, "getSources", ph_log_get_sources, 0);
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
VALUE ph_log_enable(VALUE self, VALUE level, VALUE output_file) {
|
165
|
+
ph_raise(PhidgetLog_enable(NUM2INT(level), StringValueCStr(output_file)));
|
166
|
+
return Qnil;
|
167
|
+
}
|
168
|
+
|
169
|
+
VALUE ph_log_disable(VALUE self) {
|
170
|
+
ph_raise(PhidgetLog_disable());
|
171
|
+
return Qnil;
|
172
|
+
}
|
173
|
+
|
174
|
+
VALUE ph_log_get_level(VALUE self) {
|
175
|
+
Phidget_LogLevel level;
|
176
|
+
ph_raise(PhidgetLog_getLevel(&level));
|
177
|
+
return INT2NUM(level);
|
178
|
+
}
|
179
|
+
|
180
|
+
VALUE ph_log_set_level(VALUE self, VALUE level) {
|
181
|
+
ph_raise(PhidgetLog_setLevel(NUM2INT(level)));
|
182
|
+
return Qnil;
|
183
|
+
}
|
184
|
+
|
185
|
+
VALUE ph_log_log(VALUE self, VALUE level, VALUE message) {
|
186
|
+
ph_raise(PhidgetLog_log(NUM2INT(level), StringValueCStr(message)));
|
187
|
+
return Qnil;
|
188
|
+
}
|
189
|
+
|
190
|
+
VALUE ph_log_loge(VALUE self, VALUE file, VALUE line, VALUE function, VALUE source, VALUE level, VALUE message) {
|
191
|
+
ph_raise(PhidgetLog_loge( StringValueCStr(file), NUM2INT(line), StringValueCStr(function), StringValueCStr(source), NUM2INT(level), StringValueCStr(message)));
|
192
|
+
return Qnil;
|
193
|
+
}
|
194
|
+
|
195
|
+
VALUE ph_log_rotate(VALUE self) {
|
196
|
+
ph_raise(PhidgetLog_rotate());
|
197
|
+
return Qnil;
|
198
|
+
}
|
199
|
+
|
200
|
+
VALUE ph_log_is_rotating(VALUE self) {
|
201
|
+
int rotating;
|
202
|
+
ph_raise(PhidgetLog_isRotating(&rotating));
|
203
|
+
return rotating == PTRUE ? Qtrue : Qfalse;
|
204
|
+
}
|
205
|
+
|
206
|
+
VALUE ph_log_get_rotating(VALUE self) {
|
207
|
+
uint64_t size;
|
208
|
+
int count;
|
209
|
+
ph_raise(PhidgetLog_getRotating(&size, &count));
|
210
|
+
return rb_ary_new3(2, ULL2NUM(size), INT2NUM(count));
|
211
|
+
}
|
212
|
+
|
213
|
+
VALUE ph_log_set_rotating(VALUE self, VALUE size, VALUE keep_count) {
|
214
|
+
ph_raise(PhidgetLog_setRotating(NUM2ULL(size), NUM2INT(keep_count)));
|
215
|
+
return Qnil;
|
216
|
+
}
|
217
|
+
|
218
|
+
VALUE ph_log_enable_rotating(VALUE self) {
|
219
|
+
ph_raise(PhidgetLog_enableRotating());
|
220
|
+
return Qnil;
|
221
|
+
}
|
222
|
+
|
223
|
+
VALUE ph_log_disable_rotating(VALUE self) {
|
224
|
+
ph_raise(PhidgetLog_disableRotating());
|
225
|
+
return Qnil;
|
226
|
+
}
|
227
|
+
|
228
|
+
VALUE ph_log_add_source(VALUE self, VALUE source, VALUE level) {
|
229
|
+
ph_raise(PhidgetLog_addSource(StringValueCStr(source), NUM2INT(level)));
|
230
|
+
return Qnil;
|
231
|
+
}
|
232
|
+
|
233
|
+
VALUE ph_log_get_source_level(VALUE self, VALUE source) {
|
234
|
+
Phidget_LogLevel level;
|
235
|
+
ph_raise(PhidgetLog_getSourceLevel(StringValueCStr(source), &level));
|
236
|
+
return INT2NUM(level);
|
237
|
+
}
|
238
|
+
|
239
|
+
VALUE ph_log_set_source_level(VALUE self, VALUE source, VALUE level) {
|
240
|
+
ph_raise(PhidgetLog_setSourceLevel(StringValueCStr(source), NUM2INT(level)));
|
241
|
+
return Qnil;
|
242
|
+
}
|
243
|
+
|
244
|
+
VALUE ph_log_get_sources(VALUE self) {
|
245
|
+
PhidgetReturnCode rc;
|
246
|
+
const char **sources;
|
247
|
+
uint32_t count;
|
248
|
+
VALUE ary = rb_ary_new();
|
249
|
+
|
250
|
+
ph_raise(PhidgetLog_getSources(NULL, &count));
|
251
|
+
sources = malloc(sizeof(const char *) * count);
|
252
|
+
|
253
|
+
rc = PhidgetLog_getSources(sources, &count);
|
254
|
+
if( rc != EPHIDGET_OK ) {
|
255
|
+
free(sources);
|
256
|
+
ph_raise(rc);
|
257
|
+
}
|
258
|
+
|
259
|
+
for(uint32_t i=0; i<count; i++) rb_ary_push(ary, rb_str_new2(sources[i]));
|
260
|
+
free(sources);
|
261
|
+
return ary;
|
262
|
+
}
|
263
|
+
|