phidgets 0.1.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -3,23 +3,19 @@
3
3
  module Phidgets
4
4
  class Accelerometer < Common
5
5
 
6
- unless RUBY_VERSION < '1.9.0'
7
-
8
- # call-seq:
9
- # setOnAccelerationChangeHandler(proc=nil, &block)
10
- #
11
- # Sets an acceleration change event handler. This is called when the acceleration changes by more then the change trigger.
12
- #
13
- def setOnAccelerationChangeHandler(cb_proc = nil, &cb_block)
14
- @on_acceleration_change_thread.kill if defined? @on_acceleration_change_thread
15
- callback = cb_proc || cb_block
16
- @on_acceleration_change_thread = Thread.new {ext_setOnAccelerationChangeHandler(callback)}
17
- end
18
-
19
- alias :on_acceleration_change :setOnAccelerationChangeHandler
20
-
6
+ # call-seq:
7
+ # setOnAccelerationChangeHandler(proc=nil, &block)
8
+ #
9
+ # Sets an acceleration change event handler. This is called when the acceleration changes by more then the change trigger.
10
+ #
11
+ def setOnAccelerationChangeHandler(cb_proc = nil, &cb_block)
12
+ @on_acceleration_change_thread.kill if defined? @on_acceleration_change_thread and @on_acceleration_change_thread.alive?
13
+ callback = cb_proc || cb_block
14
+ @on_acceleration_change_thread = Thread.new {ext_setOnAccelerationChangeHandler(callback)}
21
15
  end
22
16
 
17
+ alias :on_acceleration_change :setOnAccelerationChangeHandler
18
+
23
19
  end
24
20
  end
25
21
 
@@ -0,0 +1,45 @@
1
+
2
+
3
+ module Phidgets
4
+ class BLDCMotor < Common
5
+
6
+ # call-seq:
7
+ # setOnBrakingStrengthChangeHandler(proc=nil, &block)
8
+ #
9
+ # Assigns a handler that will be called when the Stopped event occurs.
10
+ #
11
+ def setOnBrakingStrengthChangeHandler(cb_proc = nil, &cb_block)
12
+ @on_braking_strength_change_thread.kill if defined? @on_braking_strength_change_thread and @on_braking_strength_change_thread.alive?
13
+ callback = cb_proc || cb_block
14
+ @on_braking_strength_change_thread = Thread.new {ext_setOnBrakingStrengthChangeHandler(callback)}
15
+ end
16
+
17
+ # call-seq:
18
+ # setOnPositionChangeHandler(proc=nil, &block)
19
+ #
20
+ # Assigns a handler that will be called when the PositionChange event occurs.
21
+ #
22
+ def setOnPositionChangeHandler(cb_proc = nil, &cb_block)
23
+ @on_position_change_thread.kill if defined? @on_position_change_thread and @on_position_change_thread.alive?
24
+ callback = cb_proc || cb_block
25
+ @on_position_change_thread = Thread.new {ext_setOnPositionChangeHandler(callback)}
26
+ end
27
+
28
+ # call-seq:
29
+ # setOnVelocityUpdateHandler(proc=nil, &block)
30
+ #
31
+ # Assigns a handler that will be called when the VelocityChange event occurs.
32
+ #
33
+ def setOnVelocityUpdateHandler(cb_proc = nil, &cb_block)
34
+ @on_velocity_update_thread.kill if defined? @on_velocity_update_thread and @on_velocity_update_thread.alive?
35
+ callback = cb_proc || cb_block
36
+ @on_velocity_update_thread = Thread.new {ext_setOnVelocityUpdateHandler(callback)}
37
+ end
38
+
39
+ alias :on_braking_strength_change :setOnBrakingStrengthChangeHandler
40
+ alias :on_position_change :setOnPositionChangeHandler
41
+ alias :on_velocity_update :setOnVelocityUpdateHandler
42
+
43
+ end
44
+ end
45
+
@@ -0,0 +1,33 @@
1
+
2
+
3
+ module Phidgets
4
+ class CapacitiveTouch < Common
5
+
6
+ # call-seq:
7
+ # setOnTouchEndHandler(proc=nil, &block)
8
+ #
9
+ # Assigns a handler that will be called when the TouchEnd event occurs.
10
+ #
11
+ def setOnTouchEndHandler(cb_proc = nil, &cb_block)
12
+ @on_touch_end_thread.kill if defined? @on_touch_end_thread and @on_touch_end_thread.alive?
13
+ callback = cb_proc || cb_block
14
+ @on_touch_end_thread = Thread.new {ext_setOnTouchEndHandler(callback)}
15
+ end
16
+
17
+ # call-seq:
18
+ # setOnTouchHandler(proc=nil, &block)
19
+ #
20
+ # Assigns a handler that will be called when the PositionChange event occurs.
21
+ #
22
+ def setOnTouchHandler(cb_proc = nil, &cb_block)
23
+ @on_touch_thread.kill if defined? @on_touch_thread and @on_touch_thread.alive?
24
+ callback = cb_proc || cb_block
25
+ @on_touch_thread = Thread.new {ext_setOnTouchHandler(callback)}
26
+ end
27
+
28
+ alias :on_touch_end :setOnTouchEndHandler
29
+ alias :on_touch :setOnTouchHandler
30
+
31
+ end
32
+ end
33
+
@@ -3,83 +3,54 @@ module Phidgets
3
3
  class Common
4
4
 
5
5
  # call-seq:
6
- # open(args)
6
+ # setOnAttachHandler(proc=nil, &block)
7
7
  #
8
- # Opens a Phidget. Will attempt to make the correct open call (openLabel, openRemote, openRemoteIP, etc)
9
- # based on the arguments passed in. Args can either be a serial number or a hash of arguments. If it is a
10
- # hash, the following keys may be used: :serial_number, :label, :server_id, :address, :port, :password.
8
+ # Assigns a handler that will be called when the Attach event occurs.
11
9
  #
12
- def open(args)
13
- args = {:serial_number => args.to_i} unless args.is_a? Hash
14
- if args.key? :server_id
15
- return open_remote(args[:serial_number], args[:server_id], args[:password]) if args.key? :serial_number
16
- return open_label_remote(args[:label], args[:server_id], args[:password]) if args.key? :label
17
- elsif args.key? :address
18
- return open_remote_ip(args[:serial_number], args[:address], args[:port], args[:password]) if args.key? :serial_number
19
- return open_label_remote_ip(args[:label], args[:address], args[:port], args[:password]) if args.key? :label
20
- else
21
- return ext_open(args[:serial_number]) if args.key? :serial_number
22
- return open_label(args[:label]) if args.key? :label
23
- end
24
- raise Phidgets::Error::InvalidArg.new
10
+ def setOnAttachHandler(cb_proc = nil, &cb_block)
11
+ @on_attach_thread.kill if defined? @on_attach_thread
12
+ callback = cb_proc || cb_block
13
+ @on_attach_thread = Thread.new {ext_setOnAttachHandler(callback)}
25
14
  end
26
15
 
16
+ # call-seq:
17
+ # setOnDetachHandler(proc=nil, &block)
18
+ #
19
+ # Assigns a handler that will be called when the Detach event occurs.
20
+ #
21
+ def setOnDetachHandler(cb_proc = nil, &cb_block)
22
+ @on_detach_thread.kill if defined? @on_detach_thread
23
+ callback = cb_proc || cb_block
24
+ @on_detach_thread = Thread.new {ext_setOnDetachHandler(callback)}
25
+ end
27
26
 
28
- unless RUBY_VERSION < '1.9.0'
29
-
30
- # call-seq:
31
- # setOnAttachHandler(proc=nil, &block)
32
- #
33
- # Sets an attach handler callback function. This is called when this Phidget is plugged into the system, and is ready for use.
34
- #
35
- def setOnAttachHandler(cb_proc = nil, &cb_block)
36
- @on_attach_thread.kill if defined? @on_attach_thread
37
- callback = cb_proc || cb_block
38
- @on_attach_thread = Thread.new {ext_setOnAttachHandler(callback)}
39
- end
40
-
41
- # call-seq:
42
- # setOnDetachHandler(proc=nil, &block)
43
- #
44
- # Sets a detach handler callback function. This is called when this Phidget is unplugged from the system.
45
- #
46
- def setOnDetachHandler(cb_proc = nil, &cb_block)
47
- @on_detach_thread.kill if defined? @on_detach_thread
48
- callback = cb_proc || cb_block
49
- @on_detach_thread = Thread.new {ext_setOnDetachHandler(callback)}
50
- end
51
-
52
- # call-seq:
53
- # setOnServerConnectHandler(proc=nil, &block)
54
- #
55
- # Sets a server connect handler callback function. This is used for opening Phidgets remotely,
56
- # and is called when a connection to the sever has been made.
57
- #
58
- def setOnServerConnectHandler(cb_proc = nil, &cb_block)
59
- @on_server_connect_thread.kill if defined? @on_server_connect_thread
60
- callback = cb_proc || cb_block
61
- @on_server_connect_thread = Thread.new {ext_setOnServerConnectHandler(callback)}
62
- end
63
-
64
- # call-seq:
65
- # setOnServerDisconnectHandler(proc=nil, &block)
66
- #
67
- # Sets a server disconnect handler callback function. This is used for opening Phidgets remotely,
68
- # and is called when a connection to the server has been lost.
69
- #
70
- def setOnServerDisconnectHandler(cb_proc = nil, &cb_block)
71
- @on_server_disconnect_thread.kill if defined? @on_server_disconnect_thread
72
- callback = cb_proc || cb_block
73
- @on_server_disconnect_thread = Thread.new {ext_setOnServerDisconnectHandler(callback)}
74
- end
75
-
76
- alias :on_attach :setOnAttachHandler
77
- alias :on_detach :setOnDetachHandler
78
- alias :on_server_connect :setOnServerConnectHandler
79
- alias :on_server_disconnect :setOnServerDisconnectHandler
27
+ # call-seq:
28
+ # setOnErrorHandler(proc=nil, &block)
29
+ #
30
+ # Assigns a handler that will be called when the Error event occurs.
31
+ #
32
+ def setOnErrorHandler(cb_proc = nil, &cb_block)
33
+ @on_error_thread.kill if defined? @on_error_thread
34
+ callback = cb_proc || cb_block
35
+ @on_error_thread = Thread.new {ext_setOnErrorHandler(callback)}
36
+ end
80
37
 
38
+ # call-seq:
39
+ # setOnPropertyChangeHandler(proc=nil, &block)
40
+ #
41
+ # Assigns a handler that will be called when the PropertyChange event occurs.
42
+ #
43
+ def setOnPropertyChangeHandler(cb_proc = nil, &cb_block)
44
+ @on_property_change_thread.kill if defined? @on_property_change_thread
45
+ callback = cb_proc || cb_block
46
+ @on_property_change_thread = Thread.new {ext_setOnPropertyChangeHandler(callback)}
81
47
  end
82
48
 
49
+ alias :on_attach :setOnAttachHandler
50
+ alias :on_detach :setOnDetachHandler
51
+ alias :on_error :setOnErrorHandler
52
+ alias :on_property_change :setOnPropertyChangeHandler
53
+
83
54
  end
84
55
  end
85
56
 
@@ -0,0 +1,21 @@
1
+
2
+
3
+ module Phidgets
4
+ class CurrentInput < Common
5
+
6
+ # call-seq:
7
+ # setOnCurrentChangeHandler(proc=nil, &block)
8
+ #
9
+ # Assigns a handler that will be called when the CurrentChange event occurs.
10
+ #
11
+ def setOnCurrentChangeHandler(cb_proc = nil, &cb_block)
12
+ @on_current_change_thread.kill if defined? @on_current_change_thread and @on_current_change_thread.alive?
13
+ callback = cb_proc || cb_block
14
+ @on_current_change_thread = Thread.new {ext_setOnCurrentChangeHandler(callback)}
15
+ end
16
+
17
+ alias :on_current_change :setOnCurrentChangeHandler
18
+
19
+ end
20
+ end
21
+
@@ -0,0 +1,45 @@
1
+
2
+
3
+ module Phidgets
4
+ class DCMotor < Common
5
+
6
+ # call-seq:
7
+ # setOnBackEMFChangeHandler(proc=nil, &block)
8
+ #
9
+ # Assigns a handler that will be called when the BackEMFChange event occurs.
10
+ #
11
+ def setOnBackEMFChangeHandler(cb_proc = nil, &cb_block)
12
+ @on_back_emf_change_thread.kill if defined? @on_back_emf_change_thread and @on_back_emf_change_thread.alive?
13
+ callback = cb_proc || cb_block
14
+ @on_back_emf_change_thread = Thread.new {ext_setOnBackEMFChangeHandler(callback)}
15
+ end
16
+
17
+ # call-seq:
18
+ # setOnBrakingStrengthChangeHandler(proc=nil, &block)
19
+ #
20
+ # Assigns a handler that will be called when the Stopped event occurs.
21
+ #
22
+ def setOnBrakingStrengthChangeHandler(cb_proc = nil, &cb_block)
23
+ @on_braking_strength_change_thread.kill if defined? @on_braking_strength_change_thread and @on_braking_strength_change_thread.alive?
24
+ callback = cb_proc || cb_block
25
+ @on_braking_strength_change_thread = Thread.new {ext_setOnBrakingStrengthChangeHandler(callback)}
26
+ end
27
+
28
+ # call-seq:
29
+ # setOnVelocityUpdateHandler(proc=nil, &block)
30
+ #
31
+ # Assigns a handler that will be called when the VelocityChange event occurs.
32
+ #
33
+ def setOnVelocityUpdateHandler(cb_proc = nil, &cb_block)
34
+ @on_velocity_update_thread.kill if defined? @on_velocity_update_thread and @on_velocity_update_thread.alive?
35
+ callback = cb_proc || cb_block
36
+ @on_velocity_update_thread = Thread.new {ext_setOnVelocityUpdateHandler(callback)}
37
+ end
38
+
39
+ alias :on_back_emf_change :setOnBackEMFChangeHandler
40
+ alias :on_braking_strength_change :setOnBrakingStrengthChangeHandler
41
+ alias :on_velocity_update :setOnVelocityUpdateHandler
42
+
43
+ end
44
+ end
45
+
@@ -1,53 +1,44 @@
1
1
 
2
2
  module Phidgets
3
- class Dictionary
3
+ class Dictionary < Common
4
4
 
5
5
  # call-seq:
6
- # open(args)
6
+ # setOnAddHandler(proc=nil, &block)
7
7
  #
8
- # Opens a Dictionary. Will attempt to make the correct open call (openRemote, openRemoteIP) based
9
- # on the arguments passed in. Args is a hash and the following keys may be used:
10
- # :server_id, :address, :port, :password.
8
+ # Assigns a handler that will be called when the Add event occurs.
11
9
  #
12
- def open(args)
13
- if args.key? :server_id
14
- return open_remote(args[:server_id], args[:password])
15
- elsif args.key? :address
16
- return open_remote_ip(args[:address], args[:port], args[:password])
17
- end
18
- raise Phidgets::Error::InvalidArg.new
10
+ def setOnAddHandler(cb_proc = nil, &cb_block)
11
+ @on_add_thread.kill if defined? @on_add_thread and @on_add_thread.alive?
12
+ callback = cb_proc || cb_block
13
+ @on_add_thread = Thread.new {ext_setOnAddHandler(callback)}
19
14
  end
20
15
 
16
+ # call-seq:
17
+ # setOnRemoveHandler(proc=nil, &block)
18
+ #
19
+ # Assigns a handler that will be called when the Remove event occurs.
20
+ #
21
+ def setOnRemoveHandler(cb_proc = nil, &cb_block)
22
+ @on_remove_thread.kill if defined? @on_remove_thread and @on_remove_thread.alive?
23
+ callback = cb_proc || cb_block
24
+ @on_remove_thread = Thread.new {ext_setOnRemoveHandler(callback)}
25
+ end
21
26
 
22
- unless RUBY_VERSION < '1.9.0'
23
-
24
- # call-seq:
25
- # setOnServerConnectHandler(proc=nil, &block)
26
- #
27
- # Sets a server connect handler callback function. This is called when a connection to the sever has been made.
28
- #
29
- def setOnServerConnectHandler(cb_proc = nil, &cb_block)
30
- @on_server_connect_thread.kill if defined? @on_server_connect_thread
31
- callback = cb_proc || cb_block
32
- @on_server_connect_thread = Thread.new {ext_setOnServerConnectHandler(callback)}
33
- end
34
-
35
- # call-seq:
36
- # setOnServerDisconnectHandler(proc=nil, &block)
37
- #
38
- # Sets a server disconnect handler callback function. This is called when a connection to the server has been lost.
39
- #
40
- def setOnServerDisconnectHandler(cb_proc = nil, &cb_block)
41
- @on_server_disconnect_thread.kill if defined? @on_server_disconnect_thread
42
- callback = cb_proc || cb_block
43
- @on_server_disconnect_thread = Thread.new {ext_setOnServerDisconnectHandler(callback)}
44
- end
45
-
46
- alias :on_server_connect :setOnServerConnectHandler
47
- alias :on_server_disconnect :setOnServerDisconnectHandler
48
-
27
+ # call-seq:
28
+ # setOnUpdateHandler(proc=nil, &block)
29
+ #
30
+ # Assigns a handler that will be called when the Update event occurs.
31
+ #
32
+ def setOnUpdateHandler(cb_proc = nil, &cb_block)
33
+ @on_update_thread.kill if defined? @on_update_thread and @on_update_thread.alive?
34
+ callback = cb_proc || cb_block
35
+ @on_update_thread = Thread.new {ext_setOnUpdateHandler(callback)}
49
36
  end
50
37
 
38
+ alias :on_add :setOnAddHandler
39
+ alias :on_remove :setOnRemoveHandler
40
+ alias :on_update :setOnUpdateHandler
41
+
51
42
  end
52
43
  end
53
44
 
@@ -0,0 +1,21 @@
1
+
2
+
3
+ module Phidgets
4
+ class DigitalInput < Common
5
+
6
+ # call-seq:
7
+ # setOnStateChangeHandler(proc=nil, &block)
8
+ #
9
+ # Set a digital input change handler. This is called when a digital input changes.
10
+ #
11
+ def setOnStateChangeHandler(cb_proc = nil, &cb_block)
12
+ @on_state_change_thread.kill if defined? @on_state_change_thread and @on_state_change_thread.alive?
13
+ callback = cb_proc || cb_block
14
+ @on_state_change_thread = Thread.new {ext_setOnStateChangeHandler(callback)}
15
+ end
16
+
17
+ alias :on_state_change :setOnStateChangeHandler
18
+
19
+ end
20
+ end
21
+
@@ -0,0 +1,56 @@
1
+
2
+
3
+ module Phidgets
4
+ class DigitalOutput < Common
5
+
6
+ # call-seq:
7
+ # setDutyCycle_async(duty_cycle, proc=nil, &block)
8
+ #
9
+ # The DutyCycle represents the fraction of time the output is on (high).
10
+ # This will override the State setting on the channel.
11
+ # A DutyCycle of 1.0 translates to a high output, a DutyCycle of 0 translates to a low output.
12
+ # This is equivalent to setting a State of TRUE and FALSE respectively.
13
+ # A DutyCycle of 0.5 translates to an output that is high half the time, which results in an average output voltage of (output voltage x 0.5)
14
+ # You can use the DutyCycle to create a dimming effect on LEDs.
15
+ # If the DigitalOutput channel you are using does not support PWM, then this value may only be set to 1.0 or 0.0.
16
+ #
17
+ def setDutyCycle_async(duty_cycle, cb_proc = nil, &cb_block)
18
+ @duty_cycle_async_thread.kill if defined? @duty_cycle_async_thread and @duty_cycle_async_thread.alive?
19
+ callback = cb_proc || cb_block
20
+ @duty_cycle_async_thread = Thread.new {ext_setDutyCycle_async(duty_cycle, callback)}
21
+ end
22
+
23
+ alias :set_duty_cycle_async :setDutyCycle_async
24
+
25
+ # call-seq:
26
+ # setLEDCurrentLimit_async(duty_cycle, proc=nil, &block)
27
+ #
28
+ # The LEDCurrentLimit is the maximum amount of current that the controller will provide to the output.
29
+ # Reference the data sheet of the LED you are using before setting this value.
30
+ #
31
+ def setLEDCurrentLimit_async(current_limit, cb_proc = nil, &cb_block)
32
+ @led_current_limit_async_thread.kill if defined? @led_current_limit_async_thread and @led_current_limit_async_thread.alive?
33
+ callback = cb_proc || cb_block
34
+ @led_current_limit_async_thread = Thread.new {ext_setLEDCurrentLimit_async(current_limit, callback)}
35
+ end
36
+
37
+ alias :set_led_current_limit_async :setLEDCurrentLimit_async
38
+
39
+ # call-seq:
40
+ # setState_async(state, proc=nil, &block)
41
+ #
42
+ # The State will dictate whether the output is constantly high (TRUE) or low (FALSE).
43
+ # This will override any DutyCycle that may have been set on the channel.
44
+ # Setting the State to TRUE is the same as setting DutyCycle to 1.0, and setting the State to FALSE is the same as setting a DutyCycle of 0.0.
45
+ #
46
+ def setState_async(state, cb_proc = nil, &cb_block)
47
+ @state_async_thread.kill if defined? @state_async_thread and @state_async_thread.alive?
48
+ callback = cb_proc || cb_block
49
+ @state_async_thread = Thread.new {ext_setState_async(state, callback)}
50
+ end
51
+
52
+ alias :set_state_async :setState_async
53
+
54
+ end
55
+ end
56
+