Sha256: 0d547c2945a8c354d4103082404b839a31804e25bf879fa90b35074ae530623e

Contents?: true

Size: 1.43 KB

Versions: 8

Compression:

Stored size: 1.43 KB

Contents

module Denko
  class Board
    UART_BAUD_RATES = [
      300, 600, 750, 1200, 2400, 4800, 9600, 19200, 31250, 38400, 57600, 74880, 115200, 230400
    ]

    # CMD = 14
    def uart_start(index, baud, listening=true)
      raise ArgumentError, "given UART: #{index} out of range. Only 1..3 supported" if (index < 1 || index > 3)
      unless UART_BAUD_RATES.include?(baud)
        raise ArgumentError, "given baud rate: #{baud} not supported. Must be in #{UART_BAUD_RATES.inspect}"
      end

      config  = index | 0b01000000
      config |= 0b10000000 if listening

      self.write Message.encode command:     14,
                                pin:         config,
                                aux_message: pack(:uint32, baud)
    end

    # CMD = 14
    def uart_stop(index)
      raise ArgumentError, "given UART: #{index} out of range. Only 1..3 supported" if (index < 1 || index > 3)
      self.write Message.encode(command: 14, pin: index)
    end

    # CMD = 15
    def uart_write(index, data)
      raise ArgumentError, "given UART: #{index} out of range. Only 1..3 supported" if (index < 1 || index > 3)

      if data.class == Array
        data = pack(:uint8, data)
      elsif data.class == String
      else
        raise ArgumentError, "data to write to UART should be Array of bytes or String. Given: #{data.inspect}"
      end

      self.write Message.encode(command: 15, pin: index, value: data.length, aux_message: data)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
denko-0.14.0 lib/denko/board/uart.rb
denko-0.13.6 lib/denko/board/uart.rb
denko-0.13.5 lib/denko/board/uart.rb
denko-0.13.4 lib/denko/board/uart.rb
denko-0.13.3 lib/denko/board/uart.rb
denko-0.13.2 lib/denko/board/uart.rb
denko-0.13.1 lib/denko/board/uart.rb
denko-0.13.0 lib/denko/board/uart.rb