Class: Device::Display

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

Constant Summary collapse

MAIN_BMP =
"main.bmp"

Class Method Summary collapse

Class Method Details

.adapterObject



5
6
7
# File 'lib/device/display.rb', line 5

def self.adapter
  Device.adapter::Display
end

.clear(line = nil) ⇒ Object

Clean display

Parameters:

  • line (Fixnum) (defaults to: nil)

    Line to clear



44
45
46
47
48
49
50
51
# File 'lib/device/display.rb', line 44

def self.clear(line = nil)
  if line.nil?
    STDOUT.fresh
    adapter.clear
  else
    adapter.clear_line line
  end
end

.main_imageObject



73
74
75
76
77
78
79
80
# File 'lib/device/display.rb', line 73

def self.main_image
  file = main_image_format
  if File.exists?("./shared/#{file}")
    file
  else
    MAIN_BMP
  end
end

Display buffer

Parameters:

  • buf (String)

    Text to be printed.

  • row (Fixnum) (defaults to: nil)

    Row to start display.

  • column (Fixnum) (defaults to: nil)

    Column to start display.

Returns:

  • (NilClass)

    nil.



15
16
17
18
19
20
21
# File 'lib/device/display.rb', line 15

def self.print(buf, row = nil, column = nil)
  if row.nil? && column.nil?
    STDOUT.print(buf)
  else
    adapter.print_in_line(buf, row, column)
  end
end

Display bitmap

Parameters:

  • path (String)

    path

  • row (Fixnum) (defaults to: 0)

    Row to start display.

  • column (Fixnum) (defaults to: 0)

    Column to start display.

Returns:

  • (NilClass)

    nil.



33
34
35
36
37
38
39
# File 'lib/device/display.rb', line 33

def self.print_bitmap(path, row = 0, column = 0)
  if File.exists?(path)
    adapter.display_bitmap(path, row, column)
  else
    false
  end
end


23
24
25
# File 'lib/device/display.rb', line 23

def self.print_line(buf, row = 0, column = 0)
  self.print(buf, row, column)
end


68
69
70
71
# File 'lib/device/display.rb', line 68

def self.print_main_image
  bmp = "./shared/#{self.main_image}"
  self.print_bitmap(bmp,0,0) if File.exists?(bmp)
end

Print image in slot of status bar

Parameters:

  • slot (Fixnum)

    Status bar slot.

  • image_path (String)

    Path to image, or send nil to clear the slot.

Returns:

  • (NilClass)

    Failure.

  • (TrueClass)

    Success.



59
60
61
62
63
64
65
66
# File 'lib/device/display.rb', line 59

def self.print_status_bar(slot, image_path)
  slots = self.adapter.status_bar_slots_available - 1
  if (0..slots).include?(slot)
    if image_path.nil? || File.exists?(image_path)
      self.adapter.print_status_bar(slot, image_path)
    end
  end
end