Module: Denko::Display::MonoOLED
- Includes:
- Behaviors::BusPeripheral, Behaviors::Lifecycle
- Defined in:
- lib/denko/display/mono_oled.rb
Constant Summary collapse
- I2C_ADDRESS =
I2C Defaults
0x3C- I2C_FREQUENCY =
400_000- PIXELS_FROM_RAM =
Single byte (no need to OR with anything)
0xA4- PIXELS_ALL_ON =
0xA5- INVERT_OFF =
0xA6- INVERT_ON =
0xA7- DISPLAY_OFF =
0xAE- DISPLAY_ON =
0xAF- CONTRAST =
Double byte (following byte sets value)
0x81- COLUMN_START_LOWER =
Single byte. OR with value. These are for page addressing mode only.
0x00- COLUMN_START_UPPER =
lower 4 bytes of column
0x10- PAGE_START =
upper 4 bytes of column
0xB0- ADDRESSING_MODE =
Double byte. Following byte sets value.
0x20- ADDRESSING_MODE_DEFAULT =
Values:
0x00 = horizontal (Pages auto-increment. Used for SSD1306) 0x01 = vertical 0x02 = page (Default. Page and column must be set each time. Needed on SH1106, SH1107) 0x00- COLUMN_ADDRESS_RANGE =
Triple byte. Following 2 bytes sets value. For H/V addressing modes only.
0x21- PAGE_ADDRESS_RANGE =
0x22- START_LINE =
Single byte. OR with value.
0x40- SEGMENT_REMAP =
Value: lowest 6 bits set RAM start line (default 0b000000)
0xA0- COM_DIRECTION =
Value: 0x00 = default, 0x01 = column draw order reversed (horizontal reflection)
0xC0- CHARGE_PUMP =
Double-byte commands. Following byte sets value.
0x8D- MULTIPLEX_RATIO =
Value: 0x10 = disable/external, 0x14 = enable/internal
0xA8- DISPLAY_OFFSET =
Value: rows of display - 1
0xD3- COM_PIN_CONFIG =
Value: lowest 5 bits. Vertically shifts COM by that amount.
0xDA- CLOCK =
Double-byte commands. Following byte sets value.
0xD5- PRECHARGE_PERIOD =
Lowest 4 bits = divider. Upper 4 bits = oscillator frequency.
0xD9- VCOM_DESELECT_LEVEL =
Lowest 4 bits = phase 1. Upper 4 bits = phase 2. 0xF1 for internal charge pump. 0x22 for external.
0xDB- WIDTHS =
Valid widths and heights for displays
[64,96,128]
- HEIGHTS =
[16,32,48,64,128]
- COLUMNS =
Default to a 128x64 display.
128- ROWS =
64
Constants included from Behaviors::Lifecycle
Behaviors::Lifecycle::CALLBACK_METHODS
Instance Attribute Summary
Attributes included from Behaviors::Component
Attributes included from Behaviors::State
Instance Method Summary collapse
- #contrast=(value) ⇒ Object
- #draw_partial(buffer, x_min, x_max, p_min, p_max) ⇒ Object
- #mutate_i2c ⇒ Object
- #mutate_spi ⇒ Object
- #off ⇒ Object
- #on ⇒ Object
- #reflect_x ⇒ Object
- #reflect_y ⇒ Object
- #rotate ⇒ Object
Methods included from Behaviors::Lifecycle
Methods included from Behaviors::BusPeripheral
Methods included from Behaviors::Component
Methods included from Behaviors::State
Instance Method Details
#contrast=(value) ⇒ Object
166 167 168 169 |
# File 'lib/denko/display/mono_oled.rb', line 166 def contrast=(value) raise ArgumentError, "contrast must be in range 0..255" if (value < 0 || value > 255) command [CONTRAST, value] end |
#draw_partial(buffer, x_min, x_max, p_min, p_max) ⇒ Object
188 189 190 |
# File 'lib/denko/display/mono_oled.rb', line 188 def draw_partial(buffer, x_min, x_max, p_min, p_max) raise NotImplementedError, "#draw_partial must be implemented for each class including MonoOLED" end |
#mutate_i2c ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/denko/display/mono_oled.rb', line 88 def mutate_i2c singleton_class.class_eval do include I2C::Peripheral include PixelCommon # Commands are I2C messages prefixed with 0x00. def command(bytes) i2c_write([0x00] + bytes) end # Data are I2C messages prefixed with 0x40. def data(bytes) i2c_write([0x40] + bytes) end # Data prefix always takes one byte, so subtract that. def transfer_limit @transfer_limit ||= bus.board.i2c_limit - 1 end end end |
#mutate_spi ⇒ Object
110 111 112 113 114 |
# File 'lib/denko/display/mono_oled.rb', line 110 def mutate_spi singleton_class.class_eval do include SPICommon end end |
#off ⇒ Object
158 159 160 |
# File 'lib/denko/display/mono_oled.rb', line 158 def off command [DISPLAY_OFF] end |
#on ⇒ Object
162 163 164 |
# File 'lib/denko/display/mono_oled.rb', line 162 def on command [DISPLAY_ON] end |
#reflect_x ⇒ Object
171 172 173 174 175 |
# File 'lib/denko/display/mono_oled.rb', line 171 def reflect_x # Swap @seg_remap to the other value and write it. @seg_remap = (@seg_remap == 0x00) ? 0x01 : 0x00 command [SEGMENT_REMAP | @seg_remap] end |
#reflect_y ⇒ Object
177 178 179 180 181 |
# File 'lib/denko/display/mono_oled.rb', line 177 def reflect_y # Swap @com_direction to the other value and write it. @com_direction = (@com_direction == 0x00) ? 0x08 : 0x00 command [COM_DIRECTION | @com_direction] end |
#rotate ⇒ Object
183 184 185 186 |
# File 'lib/denko/display/mono_oled.rb', line 183 def rotate reflect_x reflect_y end |