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



41
42
43
44
45
46
47
48
# File 'lib/device/display.rb', line 41

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

.main_imageObject



70
71
72
73
74
75
76
77
# File 'lib/device/display.rb', line 70

def self.main_image
  if adapter.respond_to?(:main_image) &&
    File.exists?("./shared/#{adapter.main_image}")
    adapter.main_image
  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.

Raises:

  • (File::FileError)


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

def self.print_bitmap(path, row = 0, column = 0)
  raise(File::FileError, path) unless File.exists?(path)
  adapter.display_bitmap(path, row, column)
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


65
66
67
68
# File 'lib/device/display.rb', line 65

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.



56
57
58
59
60
61
62
63
# File 'lib/device/display.rb', line 56

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