Skip to content
Prev Previous commit
Next Next commit
Update character_lcd.py
  • Loading branch information
profbrady authored Apr 12, 2019
commit 4ffe6dedf2889c1bdc24bb410dcde2a371cb91cd
24 changes: 22 additions & 2 deletions adafruit_character_lcd/character_lcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def __init__(self, rs, en, d4, d5, d6, d7, columns, lines
# itialize to 0,0
Copy link
Collaborator

Choose a reason for hiding this comment

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

I figured you mean initialize here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, done

self.row = 0
self.column = 0
self._column_align = False
# pylint: enable-msg=too-many-arguments

def home(self):
Expand Down Expand Up @@ -201,6 +202,17 @@ def clear(self):
"""
self._write8(_LCD_CLEARDISPLAY)
time.sleep(0.003)

@property
def column_align(self):
"""If True, message text after '\n' starts directly below start of first
character in message. If False, text after '\n' starts at column zero.
Copy link
Collaborator

@makermelissa makermelissa Apr 12, 2019

Choose a reason for hiding this comment

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

Been looking into this since you submitted changes. It looks like it's failing in travis because the \n's need to be escaped. Instead of '\n' use '\\n' (two slashes. I had to use three for formatting the comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

"""
return self._column_align

@column_align.setter
def column_align(self, enable):
self._column_align = enable
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add some type checking here, so something like:

        if isinstance(enable, bool):
            self._column_align = enable
        else:
            raise ValueError('The column_align value must be either True or False')


@property
def cursor(self):
Expand Down Expand Up @@ -234,8 +246,9 @@ def cursor(self, show):
self._write8(_LCD_DISPLAYCONTROL | self.displaycontrol)

def cursor_position(self, column, row):
"""Move the cursor to position ``column``, ``row``

"""Move the cursor to position ``column``, ``row`` for the next
message only. Displaying a message resets the cursor position to (0, 0).

:param column: column location
:param row: row location
"""
Expand Down Expand Up @@ -369,6 +382,13 @@ def message(self, message):
# which case start on the opposite side of the display if cursor_position
# is (0,0) or not set. Start second line at same column as first line when
# cursor_position is set
if self.displaymode & _LCD_ENTRYLEFT > 0:
col = self.column * self._column_align
else:
if self._column_align:
col = self.column
else:
col = self.columns - 1
self.cursor_position(col, line)
# Write string to display
else:
Expand Down