phidgets-ffi 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/LICENSE +9 -0
- data/README.rdoc +59 -0
- data/Rakefile +2 -0
- data/examples/ffi/dictionary.rb +59 -0
- data/examples/ffi/interface_kit.rb +44 -0
- data/examples/ffi/library_version.rb +11 -0
- data/examples/ffi/log.rb +11 -0
- data/examples/ffi/manager.rb +35 -0
- data/examples/ffi/servo.rb +67 -0
- data/examples/interface_kit.rb +20 -0
- data/examples/log.rb +9 -0
- data/examples/manager.rb +17 -0
- data/examples/servo.rb +36 -0
- data/lib/phidgets-ffi.rb +17 -0
- data/lib/phidgets-ffi/common.rb +222 -0
- data/lib/phidgets-ffi/error.rb +11 -0
- data/lib/phidgets-ffi/ffi/common.rb +50 -0
- data/lib/phidgets-ffi/ffi/constants.rb +109 -0
- data/lib/phidgets-ffi/ffi/core_ext.rb +17 -0
- data/lib/phidgets-ffi/ffi/dictionary.rb +44 -0
- data/lib/phidgets-ffi/ffi/interface_kit.rb +39 -0
- data/lib/phidgets-ffi/ffi/log.rb +36 -0
- data/lib/phidgets-ffi/ffi/manager.rb +36 -0
- data/lib/phidgets-ffi/ffi/servo.rb +50 -0
- data/lib/phidgets-ffi/interface_kit.rb +212 -0
- data/lib/phidgets-ffi/log.rb +28 -0
- data/lib/phidgets-ffi/manager.rb +109 -0
- data/lib/phidgets-ffi/phidgets-ffi.rb +6 -0
- data/lib/phidgets-ffi/servo.rb +112 -0
- data/lib/phidgets-ffi/version.rb +5 -0
- data/phidgets-ffi.gemspec +23 -0
- metadata +133 -0
@@ -0,0 +1,11 @@
|
|
1
|
+
module Phidgets
|
2
|
+
module Error
|
3
|
+
@errors = {}
|
4
|
+
Phidgets::FFI::ErrorCodes.to_hash.each_pair do |sym, num|
|
5
|
+
eval "@errors[num] = (#{sym.to_s.split("_").map(&:capitalize).join} = Class.new(Exception))"
|
6
|
+
end
|
7
|
+
def self.exception_for(error_code)
|
8
|
+
@errors[error_code]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Phidgets
|
2
|
+
module FFI
|
3
|
+
class Error < Exception; end
|
4
|
+
attach_function :CPhidget_open, [:phid, :int], :int #int CPhidget_open(CPhidgetHandle phid, int serialNumber);
|
5
|
+
attach_function :CPhidget_openLabel, [:phid, :string], :int #int CPhidget_openLabel(CPhidgetHandle phid, const char *label);
|
6
|
+
attach_function :CPhidget_close, [:phid], :int #int CPhidget_close(CPhidgetHandle phid);
|
7
|
+
attach_function :CPhidget_delete, [:phid], :int #int CPhidget_delete(CPhidgetHandle phid);
|
8
|
+
callback :CPhidget_set_OnDetach_Callback, [:phid, :user_ptr], :int
|
9
|
+
attach_function :CPhidget_set_OnDetach_Handler, [:phid, :CPhidget_set_OnDetach_Callback, :user_ptr], :int #int CPhidget_set_OnDetach_Handler(CPhidgetHandle phid, int( *fptr)(CPhidgetHandle phid, void *userPtr), void *userPtr);
|
10
|
+
callback :CPhidget_set_OnAttach_Callback, [:phid, :user_ptr], :int
|
11
|
+
attach_function :CPhidget_set_OnAttach_Handler, [:phid, :CPhidget_set_OnAttach_Callback, :user_ptr], :int #int CPhidget_set_OnAttach_Handler(CPhidgetHandle phid, int( *fptr)(CPhidgetHandle phid, void *userPtr), void *userPtr);
|
12
|
+
callback :CPhidget_set_OnServerConnect_Callback, [:phid, :user_ptr], :int
|
13
|
+
attach_function :CPhidget_set_OnServerConnect_Handler, [:phid, :CPhidget_set_OnServerConnect_Callback, :user_ptr], :int #int CPhidget_set_OnServerConnect_Handler(CPhidgetHandle phid, int ( *fptr)(CPhidgetHandle phid, void *userPtr), void *userPtr);
|
14
|
+
callback :CPhidget_set_OnServerDisconnect_Callback, [:phid, :user_ptr], :int
|
15
|
+
attach_function :CPhidget_set_OnServerDisconnect_Handler, [:phid, :CPhidget_set_OnServerDisconnect_Callback, :user_ptr], :int #int CPhidget_set_OnServerDisconnect_Handler(CPhidgetHandle phid, int ( *fptr)(CPhidgetHandle phid, void *userPtr), void *userPtr);
|
16
|
+
callback :CPhidget_set_OnError_Callback, [:phid, :user_ptr, :int, :string], :int
|
17
|
+
attach_function :CPhidget_set_OnError_Handler, [:phid, :CPhidget_set_OnError_Callback, :user_ptr], :int #int CPhidget_set_OnError_Handler(CPhidgetHandle phid, int( *fptr)(CPhidgetHandle phid, void *userPtr, int errorCode, const char *errorString), void *userPtr);
|
18
|
+
attach_function :CPhidget_getDeviceName, [:phid, :pointer], :int #int CPhidget_getDeviceName(CPhidgetHandle phid, const char **deviceName);
|
19
|
+
attach_function :CPhidget_getSerialNumber, [:phid, :pointer], :int #int CPhidget_getSerialNumber(CPhidgetHandle phid, int *serialNumber);
|
20
|
+
attach_function :CPhidget_getDeviceVersion, [:phid, :pointer], :int #int CPhidget_getDeviceVersion(CPhidgetHandle phid, int *deviceVersion);
|
21
|
+
attach_function :CPhidget_getDeviceStatus, [:phid, :pointer], :int #int CPhidget_getDeviceStatus(CPhidgetHandle phid, int *deviceStatus);
|
22
|
+
attach_function :CPhidget_getLibraryVersion, [:pointer], :int
|
23
|
+
attach_function :CPhidget_getDeviceType, [:phid, :pointer], :int #int CPhidget_getDeviceType(CPhidgetHandle phid, const char **deviceType);
|
24
|
+
attach_function :CPhidget_getDeviceLabel, [:phid, :pointer], :int #int CPhidget_getDeviceLabel(CPhidgetHandle phid, const char **deviceLabel);
|
25
|
+
attach_function :CPhidget_setDeviceLabel, [:phid, :string], :int #int CPhidget_setDeviceLabel(CPhidgetHandle phid, const char *deviceLabel);
|
26
|
+
attach_function :CPhidget_getErrorDescription, [:int, :pointer], :int #int CPhidget_getErrorDescription(int errorCode, const char **errorString);
|
27
|
+
attach_function :CPhidget_waitForAttachment, [:phid, :int], :int #int CPhidget_waitForAttachment(CPhidgetHandle phid, int milliseconds);
|
28
|
+
attach_function :CPhidget_getServerID, [:phid, :pointer], :int #int CPhidget_getServerID(CPhidgetHandle phid, const char **serverID);
|
29
|
+
attach_function :CPhidget_getServerAddress, [:phid, :pointer, :pointer], :int #int CPhidget_getServerAddress(CPhidgetHandle phid, const char **address, int *port);
|
30
|
+
attach_function :CPhidget_getServerStatus, [:phid, :pointer], :int #int CPhidget_getServerStatus(CPhidgetHandle phid, int *serverStatus);
|
31
|
+
attach_function :CPhidget_getDeviceID, [:phid, :pointer], :int #int CPhidget_getDeviceID(CPhidgetHandle phid, CPhidget_DeviceID *deviceID);
|
32
|
+
attach_function :CPhidget_getDeviceClass, [:phid, :pointer], :int #int CPhidget_getDeviceClass(CPhidgetHandle phid, CPhidget_DeviceClass *deviceClass);
|
33
|
+
callback :CPhidget_set_OnWillSleep_Callback, [:user_ptr], :int
|
34
|
+
attach_function :CPhidget_set_OnWillSleep_Handler, [:CPhidget_set_OnWillSleep_Callback, :user_ptr], :int #int CPhidget_set_OnWillSleep_Handler(int( *fptr)(void *userPtr), void *userPtr);
|
35
|
+
callback :CPhidget_set_OnWakeup_Callback, [:user_ptr], :int
|
36
|
+
attach_function :CPhidget_set_OnWakeup_Handler, [:CPhidget_set_OnWakeup_Callback, :user_ptr], :int #int CPhidget_set_OnWakeup_Handler(int( *fptr)(void *userPtr), void *userPtr);
|
37
|
+
|
38
|
+
module Common
|
39
|
+
def self.method_missing(method, *args, &block)
|
40
|
+
if ::Phidgets::FFI.respond_to?("CPhidget_#{method}".to_sym)
|
41
|
+
if (rs = ::Phidgets::FFI.send("CPhidget_#{method}".to_sym, *args, &block)) != 0
|
42
|
+
raise Phidgets::Error.exception_for(rs), Phidgets::FFI.error_description(rs)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
super(method, *args, &block)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module Phidgets
|
2
|
+
module FFI
|
3
|
+
typedef :pointer, :phid
|
4
|
+
typedef :pointer, :user_ptr
|
5
|
+
|
6
|
+
DeviceStatus = enum(
|
7
|
+
:detached, 0,
|
8
|
+
:attached
|
9
|
+
)
|
10
|
+
|
11
|
+
DeviceClass = enum(
|
12
|
+
:accelerometer, 2,
|
13
|
+
:advanced_servo, 3,
|
14
|
+
:encoder, 4,
|
15
|
+
:analog, 22,
|
16
|
+
:bridge, 23,
|
17
|
+
:frequency_counter, 21,
|
18
|
+
:gps, 5,
|
19
|
+
:interface_kit, 7,
|
20
|
+
:ir, 19,
|
21
|
+
:led, 8,
|
22
|
+
:motor_control, 9,
|
23
|
+
:ph_sensor, 10,
|
24
|
+
:rfid, 11,
|
25
|
+
:servo, 12,
|
26
|
+
:spatial, 20,
|
27
|
+
:stepper, 13,
|
28
|
+
:temperature_sensor, 14,
|
29
|
+
:text_lcd, 15,
|
30
|
+
:text_led, 16,
|
31
|
+
:weight_sensor, 17
|
32
|
+
)
|
33
|
+
|
34
|
+
DeviceID = enum(
|
35
|
+
:accelerometer_3axis, 0x07E,
|
36
|
+
:advanced_servo_1motor, 0x082,
|
37
|
+
:advanced_servo_8motor, 0x03A,
|
38
|
+
:analog_4output, 0x037,
|
39
|
+
:bipolar_stepper_1motor, 0x07B,
|
40
|
+
:bridge_4input, 0x03B,
|
41
|
+
:encoder_1encoder_1input, 0x04B,
|
42
|
+
:encoder_hs_1encoder, 0x080,
|
43
|
+
:encoder_hs_4encoder_4input, 0x04F,
|
44
|
+
:frequency_counter_2input, 0x035,
|
45
|
+
:gps, 0x079,
|
46
|
+
:interface_kit_0_0_4, 0x040,
|
47
|
+
:interface_kit_0_0_8, 0x081,
|
48
|
+
:interface_kit_0_16_16, 0x044,
|
49
|
+
:interface_kit_2_2_2, 0x036,
|
50
|
+
:interface_kit_8_8_8, 0x045,
|
51
|
+
:interface_kit_8_8_8_w_lcd, 0x07D,
|
52
|
+
:ir, 0x04D,
|
53
|
+
:led_64_adv, 0x04C,
|
54
|
+
:linear_touch, 0x076,
|
55
|
+
:motor_control_1motor, 0x03E,
|
56
|
+
:motor_control_hc_2motor, 0x059,
|
57
|
+
:rfid_2output, 0x031,
|
58
|
+
:rotary_touch, 0x077,
|
59
|
+
:spatial_accel_3axis, 0x07F,
|
60
|
+
:spatial_accel_gyro_compass, 0x033,
|
61
|
+
:temperature_sensor, 0x070,
|
62
|
+
:temperature_sensor_4, 0x032,
|
63
|
+
:sensor_ir, 0x03C,
|
64
|
+
:textlcd_2x20_w_8_8_8, 0x17D,
|
65
|
+
:textlcd_adapter, 0x03D,
|
66
|
+
:unipolar_stepper_4motor, 0x07A,
|
67
|
+
:accelerometer_2axis, 0x071,
|
68
|
+
:interface_kit_0_8_8_w_lcd, 0x053,
|
69
|
+
:interface_kit_4_8_8, 4,
|
70
|
+
:led_64, 0x04A,
|
71
|
+
:motorcontrol_LV_2motor_4input, 0x058,
|
72
|
+
:ph_sensor, 0x074,
|
73
|
+
:rfid, 0x030,
|
74
|
+
:servo_1motor, 0x039,
|
75
|
+
:servo_1motor_old, 2,
|
76
|
+
:servo_4motor, 0x038,
|
77
|
+
:servo_4motor_old, 3,
|
78
|
+
:textlcd_2x20, 0x052,
|
79
|
+
:textlcd_2x20_w_0_8_8, 0x153,
|
80
|
+
:textled_1x8, 0x049,
|
81
|
+
:textled_4x8, 0x048,
|
82
|
+
:weight_sensor, 0x072
|
83
|
+
)
|
84
|
+
|
85
|
+
ErrorCodes = enum(
|
86
|
+
:ok, 0,
|
87
|
+
:not_found,
|
88
|
+
:no_memory,
|
89
|
+
:unexpected,
|
90
|
+
:invalid_arg,
|
91
|
+
:not_attached,
|
92
|
+
:interrupted,
|
93
|
+
:invalid,
|
94
|
+
:network,
|
95
|
+
:unknown_val,
|
96
|
+
:bad_password,
|
97
|
+
:unsupported,
|
98
|
+
:duplicate,
|
99
|
+
:timeout,
|
100
|
+
:out_of_bounds,
|
101
|
+
:event,
|
102
|
+
:network_not_connected,
|
103
|
+
:wrong_device,
|
104
|
+
:closed,
|
105
|
+
:bad_version,
|
106
|
+
:error_code_count
|
107
|
+
)
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Array
|
2
|
+
def to_varargs
|
3
|
+
return nil if empty?
|
4
|
+
self.map { |a|
|
5
|
+
case
|
6
|
+
when a.kind_of?(String)
|
7
|
+
[:string, a]
|
8
|
+
when a.kind_of?(Fixnum)
|
9
|
+
[:long_long, a]
|
10
|
+
when a.kind_of?(Float)
|
11
|
+
[:double, a]
|
12
|
+
else
|
13
|
+
raise Phidgets::FFI::Error, "Unsupported vararg type: #{a.class}"
|
14
|
+
end
|
15
|
+
}.flatten
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Phidgets
|
2
|
+
module FFI
|
3
|
+
typedef :pointer, :dict
|
4
|
+
|
5
|
+
KeyChangeReason = enum(
|
6
|
+
:changed, 1,
|
7
|
+
:added,
|
8
|
+
:removed,
|
9
|
+
:unchanged
|
10
|
+
)
|
11
|
+
attach_function :CPhidgetDictionary_create, [:dict], :int #int CPhidgetDictionary_create(CPhidgetDictionaryHandle *dict);
|
12
|
+
attach_function :CPhidgetDictionary_close, [:dict], :int #int CPhidgetDictionary_close(CPhidgetDictionaryHandle dict);
|
13
|
+
attach_function :CPhidgetDictionary_delete, [:dict], :int #int CPhidgetDictionary_delete(CPhidgetDictionaryHandle dict);
|
14
|
+
callback :CPhidgetDictionary_set_OnError_Callback, [:dict, :pointer, :int, :string], :int
|
15
|
+
attach_function :CPhidgetDictionary_set_OnError_Handler, [:dict, :CPhidgetDictionary_set_OnError_Callback, :pointer], :int #int CPhidgetDictionary_set_OnError_Handler(CPhidgetDictionaryHandle dict, int( *fptr)(CPhidgetDictionaryHandle, void *userPtr, int errorCode, const char *errorString), void *userPtr);
|
16
|
+
attach_function :CPhidgetDictionary_addKey, [:dict, :string, :string, :int], :int #int CPhidgetDictionary_addKey(CPhidgetDictionaryHandle dict, const char *key, const char *value, int persistent);
|
17
|
+
attach_function :CPhidgetDictionary_removeKey, [:dict, :string], :int #int CPhidgetDictionary_removeKey(CPhidgetDictionaryHandle dict, const char *pattern);
|
18
|
+
attach_function :CPhidgetDictionary_getKey, [:dict, :string, :pointer, :int], :int #int CPhidgetDictionary_getKey(CPhidgetDictionaryHandle dict, const char *key, char *value, int valuelen);
|
19
|
+
callback :CPhidgetDictionary_set_OnServerConnect_Callback, [:dict, :pointer], :int
|
20
|
+
attach_function :CPhidgetDictionary_set_OnServerConnect_Handler, [:dict, :CPhidgetDictionary_set_OnServerConnect_Callback, :pointer], :int #int CPhidgetDictionary_set_OnServerConnect_Handler(CPhidgetDictionaryHandle dict, int ( *fptr)(CPhidgetDictionaryHandle dict, void *userPtr), void *userPtr);
|
21
|
+
callback :CPhidgetDictionary_set_OnServerDisconnect_Callback, [:dict, :pointer], :int
|
22
|
+
attach_function :CPhidgetDictionary_set_OnServerDisconnect_Handler, [:dict, :CPhidgetDictionary_set_OnServerDisconnect_Callback, :pointer], :int #int CPhidgetDictionary_set_OnServerDisconnect_Handler(CPhidgetDictionaryHandle dict, int ( *fptr)(CPhidgetDictionaryHandle dict, void *userPtr), void *userPtr);
|
23
|
+
attach_function :CPhidgetDictionary_getServerID, [:dict, :pointer], :int #int CPhidgetDictionary_getServerID(CPhidgetDictionaryHandle dict, const char **serverID);
|
24
|
+
attach_function :CPhidgetDictionary_getServerAddress, [:dict, :pointer, :pointer], :int #int CPhidgetDictionary_getServerAddress(CPhidgetDictionaryHandle dict, const char **address, int *port);
|
25
|
+
attach_function :CPhidgetDictionary_getServerStatus, [:dict, :pointer], :int #int CPhidgetDictionary_getServerStatus(CPhidgetDictionaryHandle dict, int *serverStatus);
|
26
|
+
attach_function :CPhidgetDictionary_openRemote, [:dict, :string, :string], :int #int CPhidgetDictionary_openRemote(CPhidgetDictionaryHandle dict, const char *serverID, const char *password);
|
27
|
+
attach_function :CPhidgetDictionary_openRemoteIP, [:dict, :string, :int, :string], :int #int CPhidgetDictionary_openRemoteIP(CPhidgetDictionaryHandle dict, const char *address, int port, const char *password);
|
28
|
+
callback :CPhidgetDictionary_set_OnKeyChange_Callback, [:dict, :pointer, :string, :string, KeyChangeReason], :int
|
29
|
+
attach_function :CPhidgetDictionary_set_OnKeyChange_Handler, [:dict, :pointer, :string, :CPhidgetDictionary_set_OnKeyChange_Callback, :pointer], :int #int CPhidgetDictionary_set_OnKeyChange_Handler(CPhidgetDictionaryHandle dict, CPhidgetDictionaryListenerHandle *dictlistener, const char *pattern, CPhidgetDictionary_OnKeyChange_Function fptr, void *userPtr);
|
30
|
+
attach_function :CPhidgetDictionary_remove_OnKeyChange_Handler, [:dict], :int #int CPhidgetDictionary_remove_OnKeyChange_Handler(CPhidgetDictionaryListenerHandle dictlistener);
|
31
|
+
|
32
|
+
module CPhidgetDictionary
|
33
|
+
def self.method_missing(method, *args, &block)
|
34
|
+
if ::Phidgets::FFI.respond_to?("CPhidgetDictionary_#{method}".to_sym)
|
35
|
+
if (rs = ::Phidgets::FFI.send("CPhidgetDictionary_#{method}".to_sym, *args, &block)) != 0
|
36
|
+
raise Phidgets::Error.exception_for(rs), Phidgets::FFI.error_description(rs)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
super(method, *args, &block)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Phidgets
|
2
|
+
module FFI
|
3
|
+
attach_function :CPhidgetInterfaceKit_create, [:phid], :int #int CPhidgetInterfaceKit_create(CPhidgetInterfaceKitHandle *phid);
|
4
|
+
attach_function :CPhidgetInterfaceKit_getInputCount, [:phid, :pointer], :int #int CPhidgetInterfaceKit_getInputCount(CPhidgetInterfaceKitHandle phid, int *count);
|
5
|
+
attach_function :CPhidgetInterfaceKit_getInputState, [:phid, :int, :pointer], :int #int CPhidgetInterfaceKit_getInputState(CPhidgetInterfaceKitHandle phid, int index, int *inputState);
|
6
|
+
callback :CPhidgetInterfaceKit_set_OnInputChange_Callback, [:phid, :user_ptr, :int, :int], :int
|
7
|
+
attach_function :CPhidgetInterfaceKit_set_OnInputChange_Handler, [:phid, :CPhidgetInterfaceKit_set_OnInputChange_Callback, :user_ptr], :int #int CPhidgetInterfaceKit_set_OnInputChange_Handler(CPhidgetInterfaceKitHandle phid, int ( *fptr)(CPhidgetInterfaceKitHandle phid, void *userPtr, int index, int inputState), void *userPtr);
|
8
|
+
attach_function :CPhidgetInterfaceKit_getOutputCount, [:phid, :pointer], :int #int CPhidgetInterfaceKit_getOutputCount(CPhidgetInterfaceKitHandle phid, int *count);
|
9
|
+
attach_function :CPhidgetInterfaceKit_getOutputState, [:phid, :int, :pointer], :int #int CPhidgetInterfaceKit_getOutputState(CPhidgetInterfaceKitHandle phid, int index, int *outputState);
|
10
|
+
attach_function :CPhidgetInterfaceKit_setOutputState, [:phid, :int, :int], :int #int CPhidgetInterfaceKit_setOutputState(CPhidgetInterfaceKitHandle phid, int index, int outputState);
|
11
|
+
callback :CPhidgetInterfaceKit_set_OnOutputChange_Callback, [:phid, :user_ptr, :int, :int], :int
|
12
|
+
attach_function :CPhidgetInterfaceKit_set_OnOutputChange_Handler, [:phid, :CPhidgetInterfaceKit_set_OnOutputChange_Callback, :user_ptr], :int #int CPhidgetInterfaceKit_set_OnOutputChange_Handler(CPhidgetInterfaceKitHandle phid, int ( *fptr)(CPhidgetInterfaceKitHandle phid, void *userPtr, int index, int outputState), void *userPtr);
|
13
|
+
attach_function :CPhidgetInterfaceKit_getSensorCount, [:phid, :pointer], :int #int CPhidgetInterfaceKit_getSensorCount(CPhidgetInterfaceKitHandle phid, int *count);
|
14
|
+
attach_function :CPhidgetInterfaceKit_getSensorValue, [:phid, :int, :pointer], :int #int CPhidgetInterfaceKit_getSensorValue(CPhidgetInterfaceKitHandle phid, int index, int *sensorValue);
|
15
|
+
attach_function :CPhidgetInterfaceKit_getSensorRawValue, [:phid, :int, :pointer], :int #int CPhidgetInterfaceKit_getSensorRawValue(CPhidgetInterfaceKitHandle phid, int index, int *sensorRawValue);
|
16
|
+
callback :CPhidgetInterfaceKit_set_OnSensorChange_Callback, [:phid, :user_ptr, :int, :int], :int
|
17
|
+
attach_function :CPhidgetInterfaceKit_set_OnSensorChange_Handler, [:phid, :CPhidgetInterfaceKit_set_OnSensorChange_Callback, :user_ptr], :int #int CPhidgetInterfaceKit_set_OnSensorChange_Handler(CPhidgetInterfaceKitHandle phid, int ( *fptr)(CPhidgetInterfaceKitHandle phid, void *userPtr, int index, int sensorValue), void *userPtr);
|
18
|
+
attach_function :CPhidgetInterfaceKit_getSensorChangeTrigger, [:phid, :int, :pointer], :int #int CPhidgetInterfaceKit_getSensorChangeTrigger(CPhidgetInterfaceKitHandle phid, int index, int *trigger);
|
19
|
+
attach_function :CPhidgetInterfaceKit_setSensorChangeTrigger, [:phid, :int, :int], :int #int CPhidgetInterfaceKit_setSensorChangeTrigger(CPhidgetInterfaceKitHandle phid, int index, int trigger);
|
20
|
+
attach_function :CPhidgetInterfaceKit_getRatiometric, [:phid, :pointer], :int #int CPhidgetInterfaceKit_getRatiometric(CPhidgetInterfaceKitHandle phid, int *ratiometric);
|
21
|
+
attach_function :CPhidgetInterfaceKit_setRatiometric, [:phid, :int], :int #int CPhidgetInterfaceKit_setRatiometric(CPhidgetInterfaceKitHandle phid, int ratiometric);
|
22
|
+
attach_function :CPhidgetInterfaceKit_getDataRate, [:phid, :int, :pointer], :int #int CPhidgetInterfaceKit_getDataRate(CPhidgetInterfaceKitHandle phid, int index, int *milliseconds);
|
23
|
+
attach_function :CPhidgetInterfaceKit_setDataRate, [:phid, :int, :int], :int #int CPhidgetInterfaceKit_setDataRate(CPhidgetInterfaceKitHandle phid, int index, int milliseconds);
|
24
|
+
attach_function :CPhidgetInterfaceKit_getDataRateMax, [:phid, :int, :pointer], :int #int CPhidgetInterfaceKit_getDataRateMax(CPhidgetInterfaceKitHandle phid, int index, int *max);
|
25
|
+
attach_function :CPhidgetInterfaceKit_getDataRateMin, [:phid, :int, :pointer], :int #int CPhidgetInterfaceKit_getDataRateMin(CPhidgetInterfaceKitHandle phid, int index, int *min);
|
26
|
+
|
27
|
+
module CPhidgetInterfaceKit
|
28
|
+
def self.method_missing(method, *args, &block)
|
29
|
+
if ::Phidgets::FFI.respond_to?("CPhidgetInterfaceKit_#{method}".to_sym)
|
30
|
+
if (rs = ::Phidgets::FFI.send("CPhidgetInterfaceKit_#{method}".to_sym, *args, &block)) != 0
|
31
|
+
raise Phidgets::Error.exception_for(rs), Phidgets::FFI.error_description(rs)
|
32
|
+
end
|
33
|
+
else
|
34
|
+
super(method, *args, &block)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Phidgets
|
2
|
+
module FFI
|
3
|
+
LogLevel = enum(
|
4
|
+
:critical, 1,
|
5
|
+
:error,
|
6
|
+
:warning,
|
7
|
+
:debug,
|
8
|
+
:info,
|
9
|
+
:verbose
|
10
|
+
)
|
11
|
+
|
12
|
+
attach_function :CPhidget_enableLogging, [LogLevel, :string], :int #int CPhidget_enableLogging(CPhidgetLog_level level, const char *outputFile);
|
13
|
+
attach_function :CPhidget_disableLogging, [], :int #int CPhidget_disableLogging();
|
14
|
+
attach_function :CPhidget_log, [LogLevel, :string, :string, :varargs], :int #int CPhidget_log(CPhidgetLog_level level, const char *id, const char *message, ...);
|
15
|
+
|
16
|
+
module Log
|
17
|
+
def self.log(loglevel, identifier, message, *args)
|
18
|
+
if !args.empty?
|
19
|
+
::Phidgets::FFI::CPhidget_log(loglevel, identifier, message, *args.to_varargs)
|
20
|
+
else
|
21
|
+
::Phidgets::FFI::CPhidget_log(loglevel, identifier, message)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.method_missing(method, *args, &block)
|
26
|
+
if ::Phidgets::FFI.respond_to?("CPhidget_#{method}".to_sym)
|
27
|
+
if (rs = ::Phidgets::FFI.send("CPhidget_#{method}".to_sym, *args, &block)) != 0
|
28
|
+
raise Phidgets::Error.exception_for(rs), Phidgets::FFI.error_description(rs)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
super(method, *args, &block)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Phidgets
|
2
|
+
module FFI
|
3
|
+
typedef :pointer, :phidm
|
4
|
+
|
5
|
+
attach_function :CPhidgetManager_create, [:phidm], :int #int CPhidgetManager_create(CPhidgetManagerHandle *phidm);
|
6
|
+
attach_function :CPhidgetManager_open, [:phidm], :int #int CPhidgetManager_open(CPhidgetManagerHandle phidm);
|
7
|
+
attach_function :CPhidgetManager_close, [:phidm], :int #int CPhidgetManager_close(CPhidgetManagerHandle phidm);
|
8
|
+
attach_function :CPhidgetManager_delete, [:phidm], :int #int CPhidgetManager_delete(CPhidgetManagerHandle phidm);
|
9
|
+
callback :CPhidgetManager_set_OnAttach_Callback, [:phid, :user_ptr], :int
|
10
|
+
attach_function :CPhidgetManager_set_OnAttach_Handler, [:phidm, :CPhidgetManager_set_OnAttach_Callback, :user_ptr], :int #int CPhidgetManager_set_OnAttach_Handler(CPhidgetManagerHandle phidm, int ( *fptr)(CPhidgetHandle phid, void *userPtr), void *userPtr);
|
11
|
+
callback :CPhidgetManager_set_OnDetach_Callback, [:phid, :user_ptr], :int
|
12
|
+
attach_function :CPhidgetManager_set_OnDetach_Handler, [:phidm, :CPhidgetManager_set_OnDetach_Callback, :user_ptr], :int #int CPhidgetManager_set_OnDetach_Handler(CPhidgetManagerHandle phidm, int ( *fptr)(CPhidgetHandle phid, void *userPtr), void *userPtr);
|
13
|
+
attach_function :CPhidgetManager_getAttachedDevices, [:phidm, :pointer, :pointer], :int #int CPhidgetManager_getAttachedDevices(CPhidgetManagerHandle phidm, CPhidgetHandle *phidArray[], int *count);
|
14
|
+
attach_function :CPhidgetManager_freeAttachedDevicesArray, [:pointer], :int #int CPhidgetManager_freeAttachedDevicesArray(CPhidgetHandle phidArray[]);
|
15
|
+
callback :CPhidgetManager_set_OnError_Callback, [:phidm, :user_ptr, :int, :string], :int
|
16
|
+
attach_function :CPhidgetManager_set_OnError_Handler, [:phidm, :CPhidgetManager_set_OnError_Callback, :user_ptr], :int #int CPhidgetManager_set_OnError_Handler(CPhidgetManagerHandle phidm, int( *fptr)(CPhidgetManagerHandle phidm, void *userPtr, int errorCode, const char *errorString), void *userPtr);
|
17
|
+
callback :CPhidgetManager_set_OnServerConnect_Callback, [:phidm, :user_ptr], :int
|
18
|
+
attach_function :CPhidgetManager_set_OnServerConnect_Handler, [:phidm, :CPhidgetManager_set_OnServerConnect_Callback, :user_ptr], :int #int CPhidgetManager_set_OnServerConnect_Handler(CPhidgetManagerHandle phidm, int ( *fptr)(CPhidgetManagerHandle phidm, void *userPtr), void *userPtr);
|
19
|
+
callback :CPhidgetManager_set_OnServerDisconnect_Callback, [:phidm, :user_ptr], :int
|
20
|
+
attach_function :CPhidgetManager_set_OnServerDisconnect_Handler, [:phidm, :CPhidgetManager_set_OnServerDisconnect_Callback, :user_ptr], :int #int CPhidgetManager_set_OnServerDisconnect_Handler(CPhidgetManagerHandle phidm, int ( *fptr)(CPhidgetManagerHandle phidm, void *userPtr), void *userPtr);
|
21
|
+
attach_function :CPhidgetManager_getServerID, [:phidm, :pointer], :int #int CPhidgetManager_getServerID(CPhidgetManagerHandle phidm, const char **serverID);
|
22
|
+
attach_function :CPhidgetManager_getServerAddress, [:phidm, :pointer, :pointer], :int#int CPhidgetManager_getServerAddress(CPhidgetManagerHandle phidm, const char **address, int *port);
|
23
|
+
|
24
|
+
module CPhidgetManager
|
25
|
+
def self.method_missing(method, *args, &block)
|
26
|
+
if ::Phidgets::FFI.respond_to?("CPhidgetManager_#{method}".to_sym)
|
27
|
+
if (rs = ::Phidgets::FFI.send("CPhidgetManager_#{method}".to_sym, *args, &block)) != 0
|
28
|
+
raise Phidgets::Error.exception_for(rs), Phidgets::FFI.error_description(rs)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
super(method, *args, &block)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Phidgets
|
2
|
+
module FFI
|
3
|
+
ServoType = enum(
|
4
|
+
:default, 1,
|
5
|
+
:raw_us_mode,
|
6
|
+
:hitec_hs322hd,
|
7
|
+
:hitec_hS5245mg,
|
8
|
+
:hitec_805bb,
|
9
|
+
:hitec_hs422,
|
10
|
+
:towerpro_mg90,
|
11
|
+
:hitec_hsr1425cr,
|
12
|
+
:hitec_hs785hb,
|
13
|
+
:hitec_hs485hb,
|
14
|
+
:hitec_hs645mg,
|
15
|
+
:hitec_815bb,
|
16
|
+
:firgelli_l12_30_50_06_r,
|
17
|
+
:firgelli_l12_50_100_06_r,
|
18
|
+
:firgelli_l12_50_210_06_r,
|
19
|
+
:firgelli_l12_100_50_06_r,
|
20
|
+
:firgelli_l12_100_100_06_r,
|
21
|
+
:user_defind
|
22
|
+
)
|
23
|
+
|
24
|
+
attach_function :CPhidgetServo_create, [:phid], :int #int CPhidgetServo_create(CPhidgetServoHandle *phid);
|
25
|
+
attach_function :CPhidgetServo_getMotorCount, [:phid, :pointer], :int # int CPhidgetServo_getMotorCount(CPhidgetServoHandle phid, int *count);
|
26
|
+
attach_function :CPhidgetServo_getPosition, [:phid, :int, :pointer], :int #int CPhidgetServo_getPosition(CPhidgetServoHandle phid, int index, double *position);
|
27
|
+
attach_function :CPhidgetServo_setPosition, [:phid, :int, :double], :int #int CPhidgetServo_setPosition(CPhidgetServoHandle phid, int index, double position);
|
28
|
+
attach_function :CPhidgetServo_getPositionMax, [:phid, :int, :pointer], :int #int CPhidgetServo_getPositionMax(CPhidgetServoHandle phid, int index, double *max);
|
29
|
+
attach_function :CPhidgetServo_getPositionMin, [:phid, :int, :pointer], :int #int CPhidgetServo_getPositionMin(CPhidgetServoHandle phid, int index, double *min);
|
30
|
+
callback :CPhidgetServo_set_OnPositionChange_Callback, [:phid, :user_ptr, :int, :double], :int
|
31
|
+
attach_function :CPhidgetServo_set_OnPositionChange_Handler, [:phid, :CPhidgetServo_set_OnPositionChange_Callback, :user_ptr], :int #int CPhidgetServo_set_OnPositionChange_Handler(CPhidgetServoHandle phid, int ( *fptr)(CPhidgetServoHandle phid, void *userPtr, int index, double position), void *userPtr);
|
32
|
+
attach_function :CPhidgetServo_getEngaged, [:phid, :int, :pointer], :int #int CPhidgetServo_getEngaged(CPhidgetServoHandle phid, int index, int *engagedState);
|
33
|
+
attach_function :CPhidgetServo_setEngaged, [:phid, :int, :int], :int #int CPhidgetServo_setEngaged(CPhidgetServoHandle phid, int index, int engagedState);
|
34
|
+
attach_function :CPhidgetServo_getServoType, [:phid, :int, :pointer], :int #int CPhidgetServo_getServoType(CPhidgetServoHandle phid, int index, CPhidget_ServoType *servoType);
|
35
|
+
attach_function :CPhidgetServo_setServoType, [:phid, :int, ServoType], :int #int CPhidgetServo_setServoType(CPhidgetServoHandle phid, int index, CPhidget_ServoType servoType);
|
36
|
+
attach_function :CPhidgetServo_setServoParameters, [:phid, :int, :double, :double, :double], :int #int CPhidgetServo_setServoParameters(CPhidgetServoHandle phid, int index, double min_us,double max_us,double degrees);
|
37
|
+
|
38
|
+
module CPhidgetServo
|
39
|
+
def self.method_missing(method, *args, &block)
|
40
|
+
if ::Phidgets::FFI.respond_to?("CPhidgetServo_#{method}".to_sym)
|
41
|
+
if (rs = ::Phidgets::FFI.send("CPhidgetServo_#{method}".to_sym, *args, &block)) != 0
|
42
|
+
raise Phidgets::Error.exception_for(rs), Phidgets::FFI.error_description(rs)
|
43
|
+
end
|
44
|
+
else
|
45
|
+
super(method, *args, &block)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,212 @@
|
|
1
|
+
module Phidgets
|
2
|
+
class InterfaceKit
|
3
|
+
|
4
|
+
Klass = Phidgets::FFI::CPhidgetInterfaceKit
|
5
|
+
include Phidgets::Common
|
6
|
+
|
7
|
+
attr_reader :inputs, :outputs, :sensors
|
8
|
+
|
9
|
+
def initialize(serial_number=-1, &block)
|
10
|
+
create
|
11
|
+
open(serial_number)
|
12
|
+
wait_for_attachment
|
13
|
+
load_inputs
|
14
|
+
load_outputs
|
15
|
+
load_sensors
|
16
|
+
if block_given?
|
17
|
+
yield self
|
18
|
+
close
|
19
|
+
delete
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def attributes
|
24
|
+
super.merge({
|
25
|
+
:inputs => inputs.size,
|
26
|
+
:outputs => outputs.size,
|
27
|
+
:sensors => sensors.size,
|
28
|
+
})
|
29
|
+
end
|
30
|
+
|
31
|
+
def on_input_change(obj=nil, &block)
|
32
|
+
@on_input_change_obj = obj
|
33
|
+
@on_input_change = Proc.new { |device, obj_ptr, index, state|
|
34
|
+
yield @inputs[index], (state == 0 ? false : true), object_for(obj_ptr)
|
35
|
+
}
|
36
|
+
Klass.set_OnInputChange_Handler(@handle, @on_input_change, pointer_for(obj))
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_output_change(obj=nil, &block)
|
40
|
+
@on_output_change_obj = obj
|
41
|
+
@on_output_change = Proc.new { |device, obj_ptr, index, state|
|
42
|
+
yield @outputs[index], (state == 0 ? false : true), object_for(obj_ptr)
|
43
|
+
}
|
44
|
+
Klass.set_OnOutputChange_Handler(@handle, @on_output_change, pointer_for(obj))
|
45
|
+
end
|
46
|
+
|
47
|
+
def on_sensor_change(obj=nil, &block)
|
48
|
+
@on_sensor_change_obj = obj
|
49
|
+
@on_sensor_change = Proc.new { |device, obj_ptr, index, value|
|
50
|
+
yield @sensors[index], value, object_for(obj_ptr)
|
51
|
+
}
|
52
|
+
Klass.set_OnSensorChange_Handler(@handle, @on_sensor_change, pointer_for(obj))
|
53
|
+
end
|
54
|
+
|
55
|
+
def ratiometric
|
56
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
57
|
+
Klass.getRatiometric(@handle, ptr)
|
58
|
+
(ptr.get_int(0) == 0) ? false : true
|
59
|
+
end
|
60
|
+
alias_method :ratiometric?, :ratiometric
|
61
|
+
|
62
|
+
def ratiometric=(val)
|
63
|
+
tmp = val ? 1 : 0
|
64
|
+
Klass.setRatiometric(@handle, tmp)
|
65
|
+
|
66
|
+
val
|
67
|
+
end
|
68
|
+
private
|
69
|
+
|
70
|
+
def load_inputs
|
71
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
72
|
+
Klass.getInputCount(@handle, ptr)
|
73
|
+
|
74
|
+
@inputs = []
|
75
|
+
ptr.get_int(0).times do |i|
|
76
|
+
@inputs << InterfaceKitInput.new(@handle, i)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def load_outputs
|
81
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
82
|
+
Klass.getOutputCount(@handle, ptr)
|
83
|
+
|
84
|
+
@outputs = []
|
85
|
+
ptr.get_int(0).times do |i|
|
86
|
+
@outputs << InterfaceKitOutput.new(@handle, i)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def load_sensors
|
91
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
92
|
+
Klass.getSensorCount(@handle, ptr)
|
93
|
+
|
94
|
+
@sensors = []
|
95
|
+
ptr.get_int(0).times do |i|
|
96
|
+
@sensors << InterfaceKitSensor.new(@handle, i)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
class InterfaceKitInput
|
102
|
+
Klass = Phidgets::FFI::CPhidgetInterfaceKit
|
103
|
+
|
104
|
+
attr_reader :index
|
105
|
+
|
106
|
+
def initialize(handle, index)
|
107
|
+
@handle, @index = handle, index.to_i
|
108
|
+
end
|
109
|
+
|
110
|
+
def state
|
111
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
112
|
+
Klass.getInputState(@handle, @index, ptr)
|
113
|
+
(ptr.get_int(0) == 0) ? false : true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
class InterfaceKitOutput
|
118
|
+
Klass = Phidgets::FFI::CPhidgetInterfaceKit
|
119
|
+
|
120
|
+
attr_reader :index
|
121
|
+
|
122
|
+
def initialize(handle, index)
|
123
|
+
@handle, @index = handle, index.to_i
|
124
|
+
end
|
125
|
+
|
126
|
+
def state=(val)
|
127
|
+
tmp = val ? 1 : 0
|
128
|
+
Klass.setOutputState(@handle, @index, tmp)
|
129
|
+
|
130
|
+
val
|
131
|
+
end
|
132
|
+
|
133
|
+
def state
|
134
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
135
|
+
Klass.getOutputState(@handle, @index, ptr)
|
136
|
+
(ptr.get_int(0) == 0) ? false : true
|
137
|
+
end
|
138
|
+
|
139
|
+
def on
|
140
|
+
state == true
|
141
|
+
end
|
142
|
+
alias_method :on?, :state
|
143
|
+
|
144
|
+
def off
|
145
|
+
!on
|
146
|
+
end
|
147
|
+
alias_method :off?, :off
|
148
|
+
end
|
149
|
+
|
150
|
+
class InterfaceKitSensor
|
151
|
+
Klass = Phidgets::FFI::CPhidgetInterfaceKit
|
152
|
+
|
153
|
+
attr_reader :index
|
154
|
+
|
155
|
+
def initialize(handle, index)
|
156
|
+
@handle, @index = handle, index.to_i
|
157
|
+
end
|
158
|
+
|
159
|
+
def inspect
|
160
|
+
"#<#{self.class} @value=#{value}, @raw_value=#{raw_value}, @rate=#{rate}, @trigger=#{trigger}, @max_rate=#{max_rate}, @min_rate=#{min_rate}>"
|
161
|
+
end
|
162
|
+
|
163
|
+
def value
|
164
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
165
|
+
Klass.getSensorValue(@handle, @index, ptr)
|
166
|
+
ptr.get_int(0)
|
167
|
+
end
|
168
|
+
alias_method :to_i, :value
|
169
|
+
|
170
|
+
def raw_value
|
171
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
172
|
+
Klass.getSensorRawValue(@handle, @index, ptr)
|
173
|
+
ptr.get_int(0)
|
174
|
+
end
|
175
|
+
|
176
|
+
def trigger
|
177
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
178
|
+
Klass.getSensorChangeTrigger(@handle, @index, ptr)
|
179
|
+
ptr.get_int(0)
|
180
|
+
end
|
181
|
+
|
182
|
+
def trigger=(val)
|
183
|
+
Klass.setSensorChangeTrigger(@handle, @index, val.to_i)
|
184
|
+
|
185
|
+
val.to_i
|
186
|
+
end
|
187
|
+
|
188
|
+
def max_rate
|
189
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
190
|
+
Klass.getDataRateMax(@handle, @index, ptr)
|
191
|
+
ptr.get_int(0)
|
192
|
+
end
|
193
|
+
|
194
|
+
def min_rate
|
195
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
196
|
+
Klass.getDataRateMin(@handle, @index, ptr)
|
197
|
+
ptr.get_int(0)
|
198
|
+
end
|
199
|
+
|
200
|
+
def rate
|
201
|
+
ptr = ::FFI::MemoryPointer.new(:int)
|
202
|
+
Klass.getDataRate(@handle, @index, ptr)
|
203
|
+
ptr.get_int(0)
|
204
|
+
end
|
205
|
+
|
206
|
+
def rate=(val)
|
207
|
+
Klass.setDataRate(@handle, @index, val.to_i)
|
208
|
+
|
209
|
+
val.to_i
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|