Skip to content

Commit

Permalink
uc1701: Add x_offset (Used to add horizontal offset on SSD1306/SH1106…
Browse files Browse the repository at this point in the history
… displays) (Klipper3d#3284)

Signed-off-by: RJ Patawaran <rjpatawaran@me.com>
  • Loading branch information
rjpatawaran authored and dmbutyugin committed Sep 12, 2020
1 parent ef48a4f commit 9de6bd8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions config/example-extras.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1901,6 +1901,8 @@
# Set the Vcomh value on SSD1306/SH1106 displays. This value is
# associated with a "smearing" effect on some OLED displays.
# The value may range from 0 to 63. Default is 0.
#x_offset: 0
# Set the horizontal offset value on SSD1306/SH1106 displays. Default is 0.
#invert: FALSE
# TRUE inverts the pixels on certain OLED (SSD1306/SH1106) displays
# The default is FALSE
Expand Down
13 changes: 9 additions & 4 deletions klippy/extras/display/uc1701.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
TextGlyphs = { 'right_arrow': '\x1a', 'degrees': '\xf8' }

class DisplayBase:
def __init__(self, io, columns=128):
def __init__(self, io, columns=128, x_offset=0):
self.send = io.send
# framebuffers
self.columns = columns
self.x_offset = x_offset
self.vram = [bytearray(self.columns) for i in range(8)]
self.all_framebuffers = [(self.vram[i], bytearray('~'*self.columns), i)
for i in range(8)]
Expand Down Expand Up @@ -71,6 +72,7 @@ def write_text(self, x, y, data):
if x + len(data) > 16:
data = data[:16 - min(x, 16)]
pix_x = x * 8
pix_x += self.x_offset
page_top = self.vram[y * 2]
page_bot = self.vram[y * 2 + 1]
for c in bytearray(data):
Expand All @@ -83,6 +85,7 @@ def write_graphics(self, x, y, data):
return
bits_top, bits_bot = self._swizzle_bits(data)
pix_x = x * 8
pix_x += self.x_offset
page_top = self.vram[y * 2]
page_bot = self.vram[y * 2 + 1]
for i in range(8):
Expand All @@ -93,6 +96,7 @@ def write_glyph(self, x, y, glyph_name):
if icon is not None and x < 15:
# Draw icon in graphics mode
pix_x = x * 8
pix_x += self.x_offset
page_idx = y * 2
self.vram[page_idx][pix_x:pix_x+16] = icon[0]
self.vram[page_idx + 1][pix_x:pix_x+16] = icon[1]
Expand Down Expand Up @@ -192,7 +196,7 @@ def init(self):

# The SSD1306 supports both i2c and "4-wire" spi
class SSD1306(DisplayBase):
def __init__(self, config, columns=128):
def __init__(self, config, columns=128, x_offset=0):
cs_pin = config.get("cs_pin", None)
if cs_pin is None:
io = I2C(config, 60)
Expand All @@ -201,7 +205,7 @@ def __init__(self, config, columns=128):
io = SPI4wire(config, "dc_pin")
io_bus = io.spi
self.reset = ResetHelper(config.get("reset_pin", None), io_bus)
DisplayBase.__init__(self, io, columns)
DisplayBase.__init__(self, io, columns, x_offset)
self.contrast = config.getint('contrast', 239, minval=0, maxval=255)
self.vcomh = config.getint('vcomh', 0, minval=0, maxval=63)
self.invert = config.getboolean('invert', False)
Expand Down Expand Up @@ -232,4 +236,5 @@ def init(self):
# the SH1106 is SSD1306 compatible with up to 132 columns
class SH1106(SSD1306):
def __init__(self, config):
SSD1306.__init__(self, config, 132)
x_offset = config.getint('x_offset', 0, minval=0, maxval=3)
SSD1306.__init__(self, config, 132, x_offset=x_offset)

0 comments on commit 9de6bd8

Please sign in to comment.