Class: SSD1306::Cursor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCursor

Returns a new instance of Cursor


5
6
7
8
9
# File 'lib/SSD1306/cursor.rb', line 5

def initialize
  @size = 1
  @x_pos = 0
  @y_pos = 0
end

Instance Attribute Details

#sizeObject

Returns the value of attribute size


3
4
5
# File 'lib/SSD1306/cursor.rb', line 3

def size
  @size
end

#x_posObject

Returns the value of attribute x_pos


3
4
5
# File 'lib/SSD1306/cursor.rb', line 3

def x_pos
  @x_pos
end

#y_posObject

Returns the value of attribute y_pos


3
4
5
# File 'lib/SSD1306/cursor.rb', line 3

def y_pos
  @y_pos
end

Instance Method Details

#buffer_index(page_offset = 0) ⇒ Object


43
44
45
46
# File 'lib/SSD1306/cursor.rb', line 43

def buffer_index(page_offset = 0)
  page = @y_pos / 8
  index = (page*128 + page_offset*128) + @x_pos
end

#incrementObject


25
26
27
28
29
30
31
# File 'lib/SSD1306/cursor.rb', line 25

def increment
  if @x_pos >= (127 - 6*@size)
    newline
  else
    @x_pos += (6*@size)
  end
end

#newlineObject


33
34
35
36
# File 'lib/SSD1306/cursor.rb', line 33

def newline
  @x_pos = 0
  @y_pos += 8*@size
end

#position_in_bufferObject


48
49
50
51
52
53
# File 'lib/SSD1306/cursor.rb', line 48

def position_in_buffer
  index = buffer_index
  page = @y_pos / 8
  offset = @y_pos % 8
  {index: index, x: @x_pos, page: page, page_offset: offset}
end

#resetObject


11
12
13
14
# File 'lib/SSD1306/cursor.rb', line 11

def reset
  reset_pos
  reset_size
end

#reset_posObject


16
17
18
19
# File 'lib/SSD1306/cursor.rb', line 16

def reset_pos
  @x_pos = 0
  @y_pos = 0
end

#reset_sizeObject


21
22
23
# File 'lib/SSD1306/cursor.rb', line 21

def reset_size
  @size = 1
end

#set_pos(x, y) ⇒ Object


38
39
40
41
# File 'lib/SSD1306/cursor.rb', line 38

def set_pos(x, y)
  @x_pos = x
  @y_pos = y
end