Module: MatrixCreator::DriverBase

Defined in:
lib/matrix_creator/driver_base.rb

Overview

Module: DriverBase

Base communication for generic drivers

Class Method Summary collapse

Class Method Details

.detect(base_port, decoder, options = {}, block = nil) ⇒ Array

Detects and returns information from a generic driver

Examples:

Detect value from a driver and return data

MatrixCreator::DriverBase.detect(8888, MatrixMalos::Imu, max_resp: 3)

Detect value from a driver and process data immediatly when received

MatrixCreator::DriverBase.detect(8888, MatrixMalos::Imu, max_resp: 3) { |data|
  // Do something with data
}

Parameters:

  • base_port (Integer)

    indicates the base port to communicate to the driver

  • decoder

    ProtoBuf to use for decoding returned data

  • options (Hash) (defaults to: {})

    of keys and values that can contain speed, max_resp and/or max_secs

Returns:

  • (Array)

    elements detected in JSON format



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/matrix_creator/driver_base.rb', line 28

def self.detect(base_port, decoder, options = {}, block = nil)
  @driver_comm = MatrixCreator::Comm.new(base_port)

  # Setup Driver
  config = MatrixMalos::DriverConfig.new(
    delay_between_updates: options[:speed] || 1.0,
    timeout_after_last_ping: 4.0
  )
  @driver_comm.send_configuration(config)

  # Query Driver
  result = @driver_comm.perform(decoder, options, block)

  # Destroy context
  @driver_comm.destroy

  result
end