Skip to content
This repository was archived by the owner on Sep 30, 2019. It is now read-only.

Adding End of Line handling and support for 20x4 displays #43

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions Adafruit_CharLCDPlate/Adafruit_CharLCDPlate.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ def write(self, value, char_mode=False):
# ----------------------------------------------------------------------
# Utility methods

def begin(self, cols, lines):
def begin(self, cols = 16, lines = 2):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This defaults the begin statement to the 16x2 display

self.currline = 0
self.cols = cols
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be changed to "self.numcols" Not sure how to do that...
We already passed var, I just need access to the column count later to know how long each row of characters can be.

self.numlines = lines
self.clear()

Expand Down Expand Up @@ -404,13 +405,35 @@ def createChar(self, location, bitmap):
self.write(self.LCD_SETDDRAMADDR)


def message(self, text):
""" Send string to LCD. Newline wraps to second line"""
lines = str(text).split('\n') # Split at newline(s)
for i, line in enumerate(lines): # For each substring...
if i > 0: # If newline(s),
self.write(0xC0) # set DDRAM address to 2nd line
self.write(line, True) # Issue substring
def message(self, text, limitMode = 0):
""" Send string to LCD. Newline wraps to next line"""
lines = str(text).split('\n') # Split at newline(s)
for i, line in enumerate(lines): # For each substring...
if i == 1: # If newline(s),
self.write(0xC0) # set DDRAM address to 2nd line
elif i == 2:
self.write(0x94)
elif i >= 3:
self.write(0xD4)
"""Now depending on the limit mode set by the function call this will handle """
lineLength = len(line)
limit = self.numcols
if limitMode <= 0:
self.write(line, True)
elif lineLength >= limit and limitMode == 1:
'''With the limit mode set to 1 the line is truncated
at the number of columns available on the display'''
limitedLine = line[0:self.numcols]
self.write(limitedLine, True)
elif lineLength >= limit and limitMode == 2:
'''With the limit mode set to 2 the line is truncated
at the number of columns minus 3 to add in an elipse'''
limitedLine = line[0:self.numcols-3]+'...'
self.write(limitedLine, True)
elif lineLength >= limit and limitMode >= 3:
'''Future todo, add in proper, "line after line" cariage return'''
else:
self.write(line, True)


def backlight(self, color):
Expand Down