Class: Ev3dev::Screen

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

Constant Summary collapse

PATH =
"/dev/fb0"
FRAME_BUFFER_SIZE =

24 line length * 128 rows

3072
BLANK_IMAGE =
Array.new(FRAME_BUFFER_SIZE){ 0 }.pack("C*")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScreen

Returns a new instance of Screen.



25
26
27
28
# File 'lib/ev3dev/screen.rb', line 25

def initialize
  raise "couldn't find screen attributes" unless File.exist?(PATH)
  @imgs = []
end

Instance Attribute Details

#imgsObject

Returns the value of attribute imgs.



23
24
25
# File 'lib/ev3dev/screen.rb', line 23

def imgs
  @imgs
end

Instance Method Details

#load(image_file) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/ev3dev/screen.rb', line 30

def load(image_file)
  raise "couldn't load a image file except .mono format" unless image_file.end_with?('.mono')

  file_size = File.size(image_file)
  raise "file size:#{file_size} is not correct:(#{FRAME_BUFFER_SIZE})" unless file_size == FRAME_BUFFER_SIZE

  @imgs << File.binread(image_file)
end

#load_blankObject



39
40
41
# File 'lib/ev3dev/screen.rb', line 39

def load_blank
  @imgs << BLANK_IMAGE
end

#showObject



43
44
45
46
47
48
49
# File 'lib/ev3dev/screen.rb', line 43

def show
  if @imgs.size >= 2
    File.binwrite(PATH, @imgs.shift)
  else
    File.binwrite(PATH, @imgs.first)
  end
end

#show_blankObject



51
52
53
# File 'lib/ev3dev/screen.rb', line 51

def show_blank
  File.binwrite(PATH, BLANK_IMAGE)
end