Class: Pedalog::Device
- Inherits:
-
Object
- Object
- Pedalog::Device
- Defined in:
- lib/pedalog.rb
Instance Attribute Summary collapse
-
#serial ⇒ Object
Returns the value of attribute serial.
Class Method Summary collapse
-
.find_all ⇒ Object
Finds all the connected Pedalog devices, and returns an array of Device instances to describe them.
-
.get_error_message(error) ⇒ Object
Gets a string describing an error code.
Instance Method Summary collapse
-
#read_data ⇒ Object
Returns a Data instance with this device’s current values, or nil if the device has been disconnected.
Instance Attribute Details
#serial ⇒ Object
Returns the value of attribute serial.
35 36 37 |
# File 'lib/pedalog.rb', line 35 def serial @serial end |
Class Method Details
.find_all ⇒ Object
Finds all the connected Pedalog devices, and returns an array of Device instances to describe them.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pedalog.rb', line 38 def self.find_all max_devices = Interface::pedalog_get_max_devices device = FFI::MemoryPointer.new(Interface::PedalogDevice, max_devices, false) devices = max_devices.times.collect do |i| Interface::PedalogDevice.new(device + i * Interface::PedalogDevice.size) end device_count = Interface::pedalog_find_devices(device) result = device_count.times.collect do |i| devices[i].to_native end device.free result end |
Instance Method Details
#read_data ⇒ Object
Returns a Data instance with this device’s current values, or nil if the device has been disconnected. If nil is returned, Device.find_all should be called again to update the list of connected devices.
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/pedalog.rb', line 73 def read_data device = Interface::PedalogDevice.new device.from_native(self) data = Interface::PedalogData.new result = Interface::pedalog_read_data(device, data) return nil if result == PEDALOG_ERROR_NO_DEVICE_FOUND throw Device.(result) unless result == PEDALOG_OK data.to_native end |