phidgets-ffi 0.1.2 → 0.1.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.
@@ -66,4 +66,4 @@ $stdin.getc
66
66
  CPhidgetDictionary_close(dictionary);
67
67
  CPhidgetDictionary_delete(dictionary);
68
68
 
69
- sleep 10
69
+ sleep 10
@@ -58,4 +58,4 @@ print "You have 20 seconds to attach/detach the interface kit. It should activat
58
58
  sleep 10
59
59
 
60
60
  CPhidget_close(ifkit)
61
- CPhidget_delete(ifkit)
61
+ CPhidget_delete(ifkit)
@@ -8,4 +8,3 @@ if !(res = Phidgets::FFI::CPhidget_getLibraryVersion(ptr))
8
8
  else
9
9
  puts ptr.get_pointer(0).read_string
10
10
  end
11
-
@@ -19,16 +19,16 @@ ptr2 = FFI::MemoryPointer.new(:int)
19
19
  count.get_int(0).times do |i|
20
20
  device = devices[0].get_pointer(i*4) #On Mac OS X, it is i*4
21
21
  # device = devices[0].get_pointer(i*4) #On Linux, it is i*8
22
-
22
+
23
23
  Common.getDeviceName(device, ptr1)
24
24
  name = ptr1.get_pointer(0).read_string
25
25
 
26
26
  Common.getSerialNumber(device, ptr2)
27
27
  serial_number = ptr2.get_int(0)
28
-
28
+
29
29
  Common.getDeviceVersion(device, ptr2)
30
30
  version = ptr2.get_int(0)
31
-
31
+
32
32
  print "Device #{i+1}: #{name} v#{version} - Serial Number #{serial_number}\n"
33
33
  end
34
34
 
@@ -6,24 +6,23 @@ puts "Library Version: #{Phidgets::FFI.library_version}"
6
6
  rfid = Phidgets::RFID.new
7
7
 
8
8
  puts "Wait for PhidgetRFID to attached..."
9
-
9
+
10
10
  #The following method runs when the PhidgetRFID is attached to the system
11
11
  rfid.on_attach do |device, obj|
12
-
13
- puts "Device attributes: #{device.attributes} attached"
14
- puts "Class: #{device.device_class}"
12
+ puts "Device attributes: #{device.attributes} attached"
13
+ puts "Class: #{device.device_class}"
15
14
  puts "Id: #{device.id}"
16
15
  puts "Serial number: #{device.serial_number}"
17
16
  puts "# Digital Outputs: #{device.outputs.size}"
18
-
17
+
19
18
  rfid.outputs[0].state = true
20
19
  puts rfid.outputs.inspect
21
-
20
+
22
21
  rfid.antenna = true
23
22
  rfid.led = true
24
23
  sleep 1
25
24
  end
26
-
25
+
27
26
  rfid.on_detach do |device, obj|
28
27
  puts "#{device.attributes.inspect} detached"
29
28
  end
@@ -35,7 +34,7 @@ end
35
34
  rfid.on_output_change do |device, output, state, obj|
36
35
  puts "Output #{output.index}'s state has changed to #{state}"
37
36
  end
38
-
37
+
39
38
  rfid.on_tag do |device, tag, obj|
40
39
  puts "Tag #{tag} detected"
41
40
  end
@@ -44,10 +43,10 @@ rfid.on_tag_lost do |device, tag, obj|
44
43
  puts "Tag #{tag} removed"
45
44
  end
46
45
 
47
- puts "Please insert a tag to read read ..."
46
+ puts "Please insert a tag to read read ..."
48
47
 
49
48
  sleep 3
50
-
49
+
51
50
  if(rfid.attached?)
52
51
  sleep 1
53
52
 
@@ -55,13 +54,12 @@ if(rfid.attached?)
55
54
  puts "Tag present: #{rfid.tag_present}"
56
55
  puts "Last tag: #{rfid.last_tag}"
57
56
  puts "Last tag proto: #{rfid.last_tag_protocol}"
58
-
57
+
59
58
  # Example for writing to a tag:
60
59
  #rfid.write("Some tag..", Phidgets::FFI::RFIDTagProtocol[:PhidgetTAG])
61
-
62
60
  rescue Phidgets::Error::UnknownVal => e
63
61
  puts "Exception caught: #{e.message}"
64
62
  end
65
63
  end
66
64
 
67
- rfid.close
65
+ rfid.close
@@ -4,14 +4,13 @@ require 'phidgets-ffi'
4
4
  puts "Library Version: #{Phidgets::FFI.library_version}"
5
5
 
6
6
  servo = Phidgets::Servo.new
7
-
7
+
8
8
  puts "Wait for PhidgetServo to attached..."
9
9
 
10
10
  #The following method runs when the PhidgetServo is attached to the system
11
11
  servo.on_attach do |device, obj|
12
-
13
- puts "Device attributes: #{device.attributes} attached"
14
- puts "Class: #{device.device_class}"
12
+ puts "Device attributes: #{device.attributes} attached"
13
+ puts "Class: #{device.device_class}"
15
14
  puts "Id: #{device.id}"
16
15
  puts "Serial number: #{device.serial_number}"
17
16
  puts "Version: #{device.version}"
@@ -21,9 +20,8 @@ servo.on_attach do |device, obj|
21
20
  device.servos[0].type = Phidgets::FFI::ServoType[:default]
22
21
  puts "Setting servo parameters: #{device.servos[0].set_servo_parameters(600, 2000, 120)}"
23
22
  sleep 1
24
-
25
23
  end
26
-
24
+
27
25
  servo.on_detach do |device, obj|
28
26
  puts "#{device.attributes.inspect} detached"
29
27
  end
@@ -6,25 +6,24 @@ puts "Library Version: #{Phidgets::FFI.library_version}"
6
6
  spatial = Phidgets::Spatial.new
7
7
 
8
8
  puts "Wait for PhidgetSpatial to attached..."
9
-
9
+
10
10
  #The following method runs when the PhidgetSpatial is attached to the system
11
11
  spatial.on_attach do |device, obj|
12
-
13
- puts "Device attributes: #{device.attributes} attached"
14
- puts "Class: #{device.device_class}"
12
+ puts "Device attributes: #{device.attributes} attached"
13
+ puts "Class: #{device.device_class}"
15
14
  puts "Id: #{device.id}"
16
15
  puts "Serial number: #{device.serial_number}"
17
16
  puts "Version: #{device.version}"
18
17
  puts "# Accelerometer Axes: #{device.accelerometer_axes.size}"
19
18
  puts "# Compass Axes: #{device.compass_axes.size}"
20
- puts "# Gyro Axes: #{device.gyro_axes.size}"
21
-
22
- device.accelerometer_axes.size.times do |i|
19
+ puts "# Gyro Axes: #{device.gyro_axes.size}"
20
+
21
+ device.accelerometer_axes.size.times do |i|
23
22
  puts "Acceleration Axis[#{i}]: #{device.accelerometer_axes[i].acceleration}"
24
23
  puts "Acceleration Axis[#{i}] Min: #{device.accelerometer_axes[i].acceleration_min}"
25
24
  puts "Acceleration Axis[#{i}] Max: #{device.accelerometer_axes[i].acceleration_max}"
26
25
  end
27
-
26
+
28
27
  device.compass_axes.size.times do |i|
29
28
  #Even when there is a compass chip, sometimes there won't be valid data in the event.
30
29
  begin
@@ -32,6 +31,7 @@ spatial.on_attach do |device, obj|
32
31
  rescue Phidgets::Error::UnknownVal => e
33
32
  puts "Exception caught: #{e.message}"
34
33
  end
34
+
35
35
  puts "Compass Axis[#{i}] Min: #{device.compass_axes[i].magnetic_field_min}"
36
36
  puts "Compass Axis[#{i}] Max: #{device.compass_axes[i].magnetic_field_max}"
37
37
  end
@@ -41,9 +41,8 @@ spatial.on_attach do |device, obj|
41
41
  puts "Gyro Axis[#{i}] Min: #{device.gyro_axes[i].angular_rate_min}"
42
42
  puts "Gyro Axis[#{i}] Max: #{device.gyro_axes[i].angular_rate_max}"
43
43
  end
44
-
45
44
  end
46
-
45
+
47
46
  spatial.on_detach do |device, obj|
48
47
  puts "#{device.attributes.inspect} detached"
49
48
  end
@@ -56,15 +55,15 @@ spatial.on_spatial_data do |device, acceleration, magnetic_field, angular_rate|
56
55
  if acceleration.size > 0
57
56
  puts "Acceleration: #{acceleration[0]}, #{acceleration[1]}, #{acceleration[2]}"
58
57
  end
59
-
60
- if magnetic_field.size > 0
61
- puts "Magnetic field: #{magnetic_field[0]}, #{magnetic_field[1]}, #{magnetic_field[2]}"
62
- end
63
-
58
+
59
+ if magnetic_field.size > 0
60
+ puts "Magnetic field: #{magnetic_field[0]}, #{magnetic_field[1]}, #{magnetic_field[2]}"
61
+ end
62
+
64
63
  if angular_rate.size > 0
65
- puts "Angular rate: #{angular_rate[0]}, #{angular_rate[1]}, #{angular_rate[2]}"
66
- end
67
- end
64
+ puts "Angular rate: #{angular_rate[0]}, #{angular_rate[1]}, #{angular_rate[2]}"
65
+ end
66
+ end
68
67
 
69
68
  sleep 2
70
69
 
@@ -6,31 +6,29 @@ puts "Library Version: #{Phidgets::FFI.library_version}"
6
6
  st = Phidgets::Stepper.new
7
7
 
8
8
  puts "Wait for PhidgetStepper to attached..."
9
-
9
+
10
10
  #The following method runs when the PhidgetStepper is attached to the system
11
11
  st.on_attach do |device, obj|
12
-
13
- puts "Device attributes: #{device.attributes} attached"
14
- puts "Class: #{device.device_class}"
12
+ puts "Device attributes: #{device.attributes} attached"
13
+ puts "Class: #{device.device_class}"
15
14
  puts "Id: #{device.id}"
16
15
  puts "Serial number: #{device.serial_number}"
17
16
  puts "Version: #{device.version}"
18
17
  puts "# Inputs: #{device.inputs.size}"
19
18
  puts "# Steppers: #{device.steppers.size}"
20
-
19
+
21
20
  puts "Digital input[0] state: #{device.inputs[0].state}"
22
-
21
+
23
22
  device.steppers[0].engaged = true
24
-
23
+
25
24
  device.steppers[0].acceleration = (device.steppers[0].acceleration_min) * 2
26
- device.steppers[0].velocity_limit = (device.steppers[0].velocity_max) / 2
25
+ device.steppers[0].velocity_limit = (device.steppers[0].velocity_max) / 2
27
26
 
28
27
  begin
29
28
  puts "Stepper 0: Current Position: #{device.steppers[0].current_position}"
30
29
  rescue Phidgets::Error::UnknownVal => e
31
30
  puts "Exception caught: #{e.message}"
32
31
  end
33
-
34
32
  end
35
33
 
36
34
  st.on_detach do |device, obj|
@@ -42,19 +40,19 @@ st.on_error do |device, obj, code, description|
42
40
  end
43
41
 
44
42
  st.on_input_change do |device, input, state, obj|
45
- print "Input #{input.index}'s state has changed to #{state}\n"
43
+ print "Input #{input.index}'s state has changed to #{state}\n"
46
44
  end
47
45
 
48
46
  st.on_velocity_change do |device, stepper, velocity, obj|
49
- puts "Stepper #{stepper.index}'s velocity has changed to #{velocity}"
47
+ puts "Stepper #{stepper.index}'s velocity has changed to #{velocity}"
50
48
  end
51
49
 
52
50
  st.on_position_change do |device, stepper, position, obj|
53
- puts "Stepper #{stepper.index}'s position has changed to #{position}"
51
+ puts "Stepper #{stepper.index}'s position has changed to #{position}"
54
52
  end
55
53
 
56
54
  st.on_current_change do |device, stepper, current, obj|
57
- puts "Stepper #{stepper.index}'s current has changed to #{current}"
55
+ puts "Stepper #{stepper.index}'s current has changed to #{current}"
58
56
  end
59
57
 
60
58
  sleep 5
@@ -67,21 +65,21 @@ if(st.attached?)
67
65
  sleep 2
68
66
 
69
67
  puts 'Moving to position 1200'
70
- st.steppers[0].target_position = 1200
68
+ st.steppers[0].target_position = 1200
71
69
  sleep 2
72
70
 
73
71
  puts 'Moving to position 0'
74
72
  st.steppers[0].target_position = 0
75
73
  sleep 2
76
-
74
+
77
75
  if (st.steppers[0].stopped == true)
78
76
  puts 'Stepper 0 has stopped'
79
77
  else
80
78
  puts 'Stepper 0 has not stopped yet'
81
79
  end
82
-
83
- st.steppers[0].engaged = false
80
+
81
+ st.steppers[0].engaged = false
84
82
  end
85
83
 
86
84
  sleep 1
87
- st.close
85
+ st.close
@@ -6,18 +6,17 @@ puts "Library Version: #{Phidgets::FFI.library_version}"
6
6
  temp = Phidgets::TemperatureSensor.new
7
7
 
8
8
  puts "Wait for PhidgetTemperatureSensor to attached..."
9
-
9
+
10
10
  #The following method runs when the PhidgetTemperatureSensor is attached to the system
11
11
  temp.on_attach do |device, obj|
12
-
13
- puts "Device attributes: #{device.attributes} attached"
14
- puts "Class: #{device.device_class}"
12
+ puts "Device attributes: #{device.attributes} attached"
13
+ puts "Class: #{device.device_class}"
15
14
  puts "Id: #{device.id}"
16
15
  puts "Serial number: #{device.serial_number}"
17
16
  puts "Version: #{device.version}"
18
17
  puts "# Inputs: #{device.thermocouples.size}"
19
-
20
- begin
18
+
19
+ begin
21
20
  puts temp.thermocouples[0].inspect
22
21
  temp.thermocouples[0].sensitivity = 0.02
23
22
  puts "Thermocouple Type: #{temp.thermocouples[0].type = Phidgets::FFI::TemperatureSensorThermocoupleTypes[:thermocouple_type_k_type]}"
@@ -29,9 +28,8 @@ temp.on_attach do |device, obj|
29
28
  rescue Phidgets::Error::UnknownVal => e
30
29
  puts "Exception caught: #{e.message}"
31
30
  end
32
-
33
31
  end
34
-
32
+
35
33
  temp.on_detach do |device, obj|
36
34
  puts "#{device.attributes.inspect} detached"
37
35
  end
@@ -42,8 +40,8 @@ end
42
40
 
43
41
  temp.on_temperature_change do |device, input, temperature, obj|
44
42
  puts "Input #{input.index}'s temperature changed to #{temperature}"
45
- end
43
+ end
46
44
 
47
45
  sleep 5
48
46
 
49
- temp.close
47
+ temp.close
@@ -6,12 +6,11 @@ puts "Library Version: #{Phidgets::FFI.library_version}"
6
6
  lcd = Phidgets::TextLCD.new
7
7
 
8
8
  puts "Wait for PhidgetTextLCD to attached..."
9
-
9
+
10
10
  #The following method runs when the PhidgetTextLCD is attached to the system
11
11
  lcd.on_attach do |device, obj|
12
-
13
- puts "Device attributes: #{device.attributes} attached"
14
- puts "Class: #{device.device_class}"
12
+ puts "Device attributes: #{device.attributes} attached"
13
+ puts "Class: #{device.device_class}"
15
14
  puts "Id: #{device.id}"
16
15
  puts "Serial number: #{device.serial_number}"
17
16
  puts "Version: #{device.version}"
@@ -25,11 +24,11 @@ lcd.on_attach do |device, obj|
25
24
  puts "# screens: #{device.screens.size}"
26
25
 
27
26
  if(lcd.id.to_s == "textlcd_adapter") #the TextLCD Adapter supports screen_size and initialize_screen
28
- device.screens[0].screen_size = Phidgets::FFI::TextLCDScreenSizes[:screen_size_2x8]
27
+ device.screens[0].screen_size = Phidgets::FFI::TextLCDScreenSizes[:screen_size_2x8]
29
28
  device.screens[0].initialize_screen
30
29
  device.screens[1].initialize_screen
31
30
  end
32
-
31
+
33
32
  sleep 1
34
33
 
35
34
  device.screens[0].contrast = 100
@@ -39,9 +38,8 @@ lcd.on_attach do |device, obj|
39
38
  sleep 1
40
39
 
41
40
  puts device.screens[0].inspect
42
-
43
41
  end
44
-
42
+
45
43
  lcd.on_detach do |device, obj|
46
44
  puts "#{device.attributes.inspect} detached"
47
45
  end
@@ -53,18 +51,18 @@ end
53
51
  sleep 2
54
52
 
55
53
  if(lcd.attached?)
56
-
57
54
  sleep 3
58
-
55
+
59
56
  puts "Screen 0, # rows: #{lcd.screens[0].rows.size}"
60
57
  puts "Screen 0, # columns: #{lcd.screens[0].rows[0].maximum_length}"
61
-
58
+
62
59
  puts 'Displaying row number'
63
60
  lcd.screens[0].rows.size.times do |i|
64
61
  lcd.screens[0].rows[i].display_string = "Row #{i}"
65
62
  end
66
-
63
+
67
64
  sleep 3
65
+
68
66
  #Switching screens if supported
69
67
  if(lcd.id.to_s == "textlcd_adapter")
70
68
  puts 'Switching to the next screen'
@@ -74,28 +72,28 @@ if(lcd.attached?)
74
72
  end
75
73
 
76
74
  sleep 3
75
+
77
76
  #Storing 7 custom characters as well as displaying them.
78
77
  puts 'Displaying custom characters'
79
- lcd.custom_characters[0].set_custom_character(949247, 536)
80
- lcd.custom_characters[1].set_custom_character(1015791, 17180)
81
- lcd.custom_characters[2].set_custom_character(1048039, 549790)
82
- lcd.custom_characters[3].set_custom_character(1031395, 816095)
83
- lcd.custom_characters[4].set_custom_character(498785, 949247)
84
- lcd.custom_characters[5].set_custom_character(232480, 1015791)
85
- lcd.custom_characters[6].set_custom_character(99328, 1048039)
78
+ lcd.custom_characters[0].set_custom_character(949247, 536)
79
+ lcd.custom_characters[1].set_custom_character(1015791, 17180)
80
+ lcd.custom_characters[2].set_custom_character(1048039, 549790)
81
+ lcd.custom_characters[3].set_custom_character(1031395, 816095)
82
+ lcd.custom_characters[4].set_custom_character(498785, 949247)
83
+ lcd.custom_characters[5].set_custom_character(232480, 1015791)
84
+ lcd.custom_characters[6].set_custom_character(99328, 1048039)
86
85
  lcd.screens[0].rows[0].display_string = "#{lcd.custom_characters[0].string_code}#{lcd.custom_characters[1].string_code}#{lcd.custom_characters[2].string_code}#{lcd.custom_characters[3].string_code}#{lcd.custom_characters[4].string_code}#{lcd.custom_characters[5].string_code}#{lcd.custom_characters[6].string_code}"
87
86
 
88
87
  sleep 3
89
-
88
+
90
89
  #Display 'Hello' with ASCII Code(hexadecimal)
91
90
  puts 'Displaying characters in ASCII code'
92
91
  lcd.screens[0].rows[1].display_string = "\x48\x65\x6c\x6c\x6f"
93
-
94
-
92
+
93
+
95
94
  #Displays a single character for a specific column for a row
96
95
  lcd.screens[0].rows[1].display_character(5, 0x21) #hex code for exclamation mark in ASCII
97
-
98
96
  end
99
97
 
100
98
  sleep 5
101
- lcd.close
99
+ lcd.close