Class: PiLite::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/pilite.rb

Constant Summary collapse

@@pilite =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.start(port = "/dev/ttyAMA0", params = {baudrate: 9600}, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
# 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

Instance Method Details

#all(action) ⇒ Object

turn on/off all LEDs

Parameters:

  • action (Symbol)

    :on / :off



76
77
78
# File 'lib/pilite.rb', line 76

def all(action)
  command "ALL,#{action.to_s.upcase}"
end

#bar(column, value) ⇒ Object

draw a bar at given column with provided value (this command does not overwrite the screen)

Parameters:

  • column (Number)

    column number (1 ~ 14)

  • value (Number)

    percentage (0 ~ 100)



55
56
57
# File 'lib/pilite.rb', line 55

def bar(column, value)
  command "B#{column},#{value}"
end

#char(column, row, char) ⇒ Object

print a character at given column/row

Parameters:

  • column (Number)

    column number (1 ~ 14)

  • row (Number)

    row number (1 ~ 9)

  • char (String)

    character



90
91
92
# File 'lib/pilite.rb', line 90

def char(column, row, char)
  command "T#{column},#{row},#{char}"
end

#fbuffer(bits) ⇒ Object

print framebuffer

Parameters:

  • bits (String/Array)

    array of 0/1s for each LED’s state (0:off, 1:on, 14 x 9 total)



47
48
49
50
# 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) ⇒ Object

do an action on a pixel at given column/row

Parameters:

  • column (Number)

    column number (1 ~ 14)

  • row (Number)

    row number (1 ~ 9)

  • action (Symbol)

    :on / :off / :toggle



70
71
72
# File 'lib/pilite.rb', line 70

def pixel(column, row, action)
  command "P#{column},#{row},#{action.to_s.upcase}"
end

#scroll(offset) ⇒ Object

scroll to left or right with given offset

Parameters:

  • offset (Number)

    -1 ~ -14: shift to right / 1 ~ 14: shift to left



82
83
84
# File 'lib/pilite.rb', line 82

def scroll(offset)
  command "SCROLL#{offset}"
end

#speed(value) ⇒ Object

change scroll speed

Parameters:

  • value (Number)

    scrolling delay from 1ms to 1000ms (default: 80)



41
42
43
# File 'lib/pilite.rb', line 41

def speed(value)
  command "SPEED#{value}"
end

#text(str) ⇒ Object

print text (will be scrolled automatically)

Parameters:

  • str (String)

    text



96
97
98
# File 'lib/pilite.rb', line 96

def text(str)
  @serial.write("#{str}\r")
end

#vumeter(row, value) ⇒ Object

draw VU meter

Parameters:

  • row (Number)

    row number (1 ~ 2)

  • value (Number)

    percentage (0 ~ 100)



62
63
64
# File 'lib/pilite.rb', line 62

def vumeter(row, value)
  command "V#{row},#{value}"
end