Class: Denko::Display::SH1106

Inherits:
Object
  • Object
show all
Includes:
MonoOLED
Defined in:
lib/denko/display/sh1106.rb

Direct Known Subclasses

SH1107

Constant Summary collapse

ADDRESSING_MODE_DEFAULT =

SH1106/SH1107 only support page addressing mode. Can’t send all data as sequential pages and let page index auto-increment, like with horizontal addressing on the SSD1306.

0x02
RAM_X_OFFSET =
2

Constants included from MonoOLED

MonoOLED::ADDRESSING_MODE, MonoOLED::CHARGE_PUMP, MonoOLED::CLOCK, MonoOLED::COLUMNS, MonoOLED::COLUMN_ADDRESS_RANGE, MonoOLED::COLUMN_START_LOWER, MonoOLED::COLUMN_START_UPPER, MonoOLED::COM_DIRECTION, MonoOLED::COM_PIN_CONFIG, MonoOLED::CONTRAST, MonoOLED::DISPLAY_OFF, MonoOLED::DISPLAY_OFFSET, MonoOLED::DISPLAY_ON, MonoOLED::HEIGHTS, MonoOLED::I2C_ADDRESS, MonoOLED::I2C_FREQUENCY, MonoOLED::INVERT_OFF, MonoOLED::INVERT_ON, MonoOLED::MULTIPLEX_RATIO, MonoOLED::PAGE_ADDRESS_RANGE, MonoOLED::PAGE_START, MonoOLED::PIXELS_ALL_ON, MonoOLED::PIXELS_FROM_RAM, MonoOLED::PRECHARGE_PERIOD, MonoOLED::ROWS, MonoOLED::SEGMENT_REMAP, MonoOLED::START_LINE, MonoOLED::VCOM_DESELECT_LEVEL, MonoOLED::WIDTHS

Constants included from Behaviors::Lifecycle

Behaviors::Lifecycle::CALLBACK_METHODS

Instance Attribute Summary

Attributes included from Behaviors::Component

#board, #params

Attributes included from Behaviors::State

#state

Instance Method Summary collapse

Methods included from MonoOLED

#contrast=, #mutate_i2c, #mutate_spi, #off, #on, #reflect_x, #reflect_y, #rotate

Methods included from Behaviors::Lifecycle

included

Methods included from Behaviors::BusPeripheral

#atomically

Methods included from Behaviors::Component

#initialize, #micro_delay

Methods included from Behaviors::State

#update_state

Instance Method Details

#draw_partial(buffer, x_start, x_finish, p_start, p_finish, color = 1) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/denko/display/sh1106.rb', line 18

def draw_partial(buffer, x_start, x_finish, p_start, p_finish, color=1)
  x = x_start + ram_x_offset
  x_lower = (x & 0b00001111)
  x_upper = (x & 0b11110000) >> 4

  (p_start..p_finish).each do |page|
    # Set the page and column to start writing at.
    command [PAGE_START | page, COLUMN_START_LOWER | x_lower, COLUMN_START_UPPER | x_upper]

    # Get needed bytes for this page only.
    src_start       = (columns * page) + x_start
    src_end         = (columns * page) + x_finish
    partial_buffer  = buffer[src_start..src_end]

    # Send in chunks up to maximum transfer size.
    partial_buffer.each_slice(transfer_limit) { |slice| data(slice) }
  end
end

#ram_x_offsetObject

SH1106 has RAM for 132 columns, but only 128 pixels, so offset by 2 to center.



14
15
16
# File 'lib/denko/display/sh1106.rb', line 14

def ram_x_offset
  @ram_x_offset ||= self.class.const_get("RAM_X_OFFSET")
end