class PiLite::Commands

Public Class Methods

new(port, params) click to toggle source
# File lib/pilite.rb, line 21
def initialize(port, params)
  @serial = SerialPort.new(port, params)
end
start(port = "/dev/ttyAMA0", params = {baudrate: 9600}) { |pilite| ... } click to toggle source
# File lib/pilite.rb, line 29
def self.start(port = "/dev/ttyAMA0", params = {baudrate: 9600}, &block)
  @@pilite = PiLite::Commands.new(port, params) unless @@pilite

  if block_given?
    yield @@pilite 
  else
    return @@pilite
  end
end

Public Instance Methods

all(action) click to toggle source

turn on/off all LEDs @param action [Symbol] :on / :off

# File lib/pilite.rb, line 76
def all(action)
  command "ALL,#{action.to_s.upcase}"
end
bar(column, value) click to toggle source

draw a bar at given column with provided value (this command does not overwrite the screen) @param column [Number] column number (1 ~ 14) @param value [Number] percentage (0 ~ 100)

# File lib/pilite.rb, line 55
def bar(column, value)
  command "B#{column},#{value}"
end
char(column, row, char) click to toggle source

print a character at given column/row @param column [Number] column number (1 ~ 14) @param row [Number] row number (1 ~ 9) @param char [String] character

# File lib/pilite.rb, line 90
def char(column, row, char)
  command "T#{column},#{row},#{char}"
end
fbuffer(bits) click to toggle source

print framebuffer @param bits [String/Array] array of 0/1s for each LED’s state (0:off, 1:on, 14 x 9 total)

# File lib/pilite.rb, line 47
def fbuffer(bits)
  bits = bits.join if bits.kind_of? Array
  command "F#{bits}"
end
pixel(column, row, action) click to toggle source

do an action on a pixel at given column/row @param column [Number] column number (1 ~ 14) @param row [Number] row number (1 ~ 9) @param action [Symbol] :on / :off / :toggle

# File lib/pilite.rb, line 70
def pixel(column, row, action)
  command "P#{column},#{row},#{action.to_s.upcase}"
end
scroll(offset) click to toggle source

scroll to left or right with given offset @param offset [Number] -1 ~ -14: shift to right / 1 ~ 14: shift to left

# File lib/pilite.rb, line 82
def scroll(offset)
  command "SCROLL#{offset}"
end
speed(value) click to toggle source

change scroll speed @param value [Number] scrolling delay from 1ms to 1000ms (default: 80)

# File lib/pilite.rb, line 41
def speed(value)
  command "SPEED#{value}"
end
text(str) click to toggle source

print text (will be scrolled automatically) @param str [String] text

# File lib/pilite.rb, line 96
def text(str)
  @serial.write("#{str}\r")
end
vumeter(row, value) click to toggle source

draw VU meter @param row [Number] row number (1 ~ 2) @param value [Number] percentage (0 ~ 100)

# File lib/pilite.rb, line 62
def vumeter(row, value)
  command "V#{row},#{value}"
end

Private Instance Methods

command(cmd) click to toggle source
# File lib/pilite.rb, line 24
def command(cmd)
  @serial.write("$$$#{cmd}\r")
end