From c7d02b565472af548f6bec733a563cc9df8e57b9 Mon Sep 17 00:00:00 2001 From: profbrady Date: Sat, 6 Apr 2019 11:52:07 -0400 Subject: [PATCH 01/12] Update character_lcd.py Update so `self.message` respects the `cursor_position()` settings. If `'\n'` is in a message string, the new line will be use the same column setting as the first line. --- adafruit_character_lcd/character_lcd.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/adafruit_character_lcd/character_lcd.py b/adafruit_character_lcd/character_lcd.py index 80b20dc..9d2caec 100755 --- a/adafruit_character_lcd/character_lcd.py +++ b/adafruit_character_lcd/character_lcd.py @@ -169,6 +169,10 @@ def __init__(self, rs, en, d4, d5, d6, d7, columns, lines self._message = None self._enable = None self._direction = None + # track row and column used in cursor_position + # itialize to 0,0 + self.row = 0 + self.column = 0 # pylint: enable-msg=too-many-arguments def home(self): @@ -243,6 +247,9 @@ def cursor_position(self, column, row): column = self.columns - 1 # Set location self._write8(_LCD_SETDDRAMADDR | (column + _LCD_ROW_OFFSETS[row])) + # Update self.row and self.column to match setter + self.row = row + self.column = column @property def blink(self): @@ -331,7 +338,8 @@ def message(self): @message.setter def message(self, message): self._message = message - line = 0 + # Set line to match self.row from cursor_position() + line = self.row # Track times through iteration, to act on the initial character of the message initial_character = 0 # iterate through each character @@ -340,7 +348,8 @@ def message(self, message): if initial_character == 0: # Start at (1, 1) unless direction is set right to left, in which case start # on the opposite side of the display. - col = 0 if self.displaymode & _LCD_ENTRYLEFT > 0 else self.columns - 1 + # start at self.column instead of 0 + col = self.column if self.displaymode & _LCD_ENTRYLEFT > 0 else self.columns - 1 self.cursor_position(col, line) initial_character += 1 # If character is \n, go to next line @@ -348,7 +357,8 @@ def message(self, message): line += 1 # Start the second line at (1, 1) unless direction is set right to left in which # case start on the opposite side of the display. - col = 0 if self.displaymode & _LCD_ENTRYLEFT > 0 else self.columns - 1 + # start at self.column instead of 0 + col = self.column if self.displaymode & _LCD_ENTRYLEFT > 0 else self.columns - 1 self.cursor_position(col, line) # Write string to display else: From d6338ab7e7d25c177e81fd680d6599d2da85458a Mon Sep 17 00:00:00 2001 From: profbrady Date: Tue, 9 Apr 2019 15:23:48 -0400 Subject: [PATCH 02/12] Update README.rst --- README.rst | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/README.rst b/README.rst index ffb4d81..4647b3e 100644 --- a/README.rst +++ b/README.rst @@ -113,16 +113,6 @@ Contributing Contributions are welcome! Please read our `Code of Conduct `_ before contributing to help this project stay welcoming. -Installation -============ - -This library is **NOT** built into CircuitPython to make it easy to update. To -install it either follow the directions below or :ref:`install the library bundle `. - -To install: - -#. Download and unzip the `latest release zip `_. -#. Copy the unzipped ``adafruit_character_lcd`` to the ``lib`` directory on the ``CIRCUITPY`` or ``MICROPYTHON`` drive. Building locally ================ From a6eb4efdf36f39f0b3f46e805447228be66ce012 Mon Sep 17 00:00:00 2001 From: profbrady Date: Wed, 10 Apr 2019 09:38:40 -0400 Subject: [PATCH 03/12] Update character_lcd.py --- adafruit_character_lcd/character_lcd.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/adafruit_character_lcd/character_lcd.py b/adafruit_character_lcd/character_lcd.py index 9d2caec..f990724 100755 --- a/adafruit_character_lcd/character_lcd.py +++ b/adafruit_character_lcd/character_lcd.py @@ -317,6 +317,11 @@ def display(self, enable): @property def message(self): """Display a string of text on the character LCD. + Start position is (0,0) if cursor_position is not set. + If cursor_position is set, message starts at the set + position from the left for left to right text and from + the right for right to left text. Resets cursor column + and row to (0,0) after displaying the message. The following example displays, "Hello, world!" on the LCD. @@ -346,23 +351,27 @@ def message(self, message): for character in message: # If this is the first character in the string: if initial_character == 0: - # Start at (1, 1) unless direction is set right to left, in which case start - # on the opposite side of the display. - # start at self.column instead of 0 - col = self.column if self.displaymode & _LCD_ENTRYLEFT > 0 else self.columns - 1 + # Start at (0, 0) unless direction is set right to left, in which case start + # on the opposite side of the display if cursor_position not set or (0,0) + # If cursor_position is set then starts at the specified location for + # LEFT_TO_RIGHT. If RIGHT_TO_LEFT cursor_position is determined from right. + # allows for cursor_position to work in RIGHT_TO_LEFT mode + col = self.column if self.displaymode & _LCD_ENTRYLEFT > 0 else self.columns - 1 - self.column self.cursor_position(col, line) initial_character += 1 # If character is \n, go to next line if character == '\n': line += 1 - # Start the second line at (1, 1) unless direction is set right to left in which - # case start on the opposite side of the display. - # start at self.column instead of 0 - col = self.column if self.displaymode & _LCD_ENTRYLEFT > 0 else self.columns - 1 + # Start the second line at (0, 1) unless direction is set right to left in 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 self.cursor_position(col, line) # Write string to display else: self._write8(ord(character), True) + # reset column and row to (0,0) after message is displayed + self.column, self.row = 0, 0 + def move_left(self): """Moves displayed text left one column. From 25161293a64870278ad4215730d5aef5e9fe64df Mon Sep 17 00:00:00 2001 From: profbrady Date: Wed, 10 Apr 2019 09:45:18 -0400 Subject: [PATCH 04/12] Update charlcd_mono_simpletest.py --- examples/charlcd_mono_simpletest.py | 30 ++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/examples/charlcd_mono_simpletest.py b/examples/charlcd_mono_simpletest.py index 9a47104..7275b51 100644 --- a/examples/charlcd_mono_simpletest.py +++ b/examples/charlcd_mono_simpletest.py @@ -25,14 +25,41 @@ lcd.backlight = True # Print a two line message lcd.message = "Hello\nCircuitPython" +# Wait 3s +time.sleep(3) +# Print two line message with cursor set to column 2 +lcd.clear() +lcd.cursor_position(2,0) +lcd.message = "Hello\nCircuitPython" # Wait 5s time.sleep(5) lcd.clear() +# Stars across the display one a time on second row from L to R +# using cursor_position +for i in range(16): + lcd.cursor_position(i,1) + lcd.message = "*" + time.sleep(0.1) +lcd.clear() # Print two line message right to left lcd.text_direction = lcd.RIGHT_TO_LEFT lcd.message = "Hello\nCircuitPython" # Wait 5s time.sleep(5) +# Print two line R to L message with cursor set to column 3 +lcd.clear() +lcd.text_direction = lcd.RIGHT_TO_LEFT +lcd.cursor_position(3,0) +lcd.message = "Hello\nCircuitPython" +# Wait 3s +time.sleep(3) +# Stars across the display one a time on second row from R to L +lcd.clear() +for i in range(16): + lcd.cursor_position(i,1) + lcd.message = "*" + time.sleep(0.1) +lcd.clear() # Return text direction to left to right lcd.text_direction = lcd.LEFT_TO_RIGHT # Display cursor @@ -50,10 +77,11 @@ lcd.blink = False lcd.clear() # Create message to scroll +lcd.cursor_position(5,0) scroll_msg = '<-- Scroll' lcd.message = scroll_msg # Scroll message to the left -for i in range(len(scroll_msg)): +for i in range(len(scroll_msg)+5): time.sleep(0.5) lcd.move_left() lcd.clear() From 2c1a7a4a9df41809b9a2f7908336ef003b2de666 Mon Sep 17 00:00:00 2001 From: profbrady Date: Wed, 10 Apr 2019 10:18:09 -0400 Subject: [PATCH 05/12] Update charlcd_mono_simpletest.py --- examples/charlcd_mono_simpletest.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/charlcd_mono_simpletest.py b/examples/charlcd_mono_simpletest.py index 7275b51..e537f28 100644 --- a/examples/charlcd_mono_simpletest.py +++ b/examples/charlcd_mono_simpletest.py @@ -29,7 +29,7 @@ time.sleep(3) # Print two line message with cursor set to column 2 lcd.clear() -lcd.cursor_position(2,0) +lcd.cursor_position(2, 0) lcd.message = "Hello\nCircuitPython" # Wait 5s time.sleep(5) @@ -37,7 +37,7 @@ # Stars across the display one a time on second row from L to R # using cursor_position for i in range(16): - lcd.cursor_position(i,1) + lcd.cursor_position(i, 1) lcd.message = "*" time.sleep(0.1) lcd.clear() @@ -49,14 +49,14 @@ # Print two line R to L message with cursor set to column 3 lcd.clear() lcd.text_direction = lcd.RIGHT_TO_LEFT -lcd.cursor_position(3,0) +lcd.cursor_position(3, 0) lcd.message = "Hello\nCircuitPython" # Wait 3s time.sleep(3) # Stars across the display one a time on second row from R to L lcd.clear() for i in range(16): - lcd.cursor_position(i,1) + lcd.cursor_position(i, 1) lcd.message = "*" time.sleep(0.1) lcd.clear() @@ -77,7 +77,7 @@ lcd.blink = False lcd.clear() # Create message to scroll -lcd.cursor_position(5,0) +lcd.cursor_position(5, 0) scroll_msg = '<-- Scroll' lcd.message = scroll_msg # Scroll message to the left From 5bc8ec558ae2b53a83af0e25b8f20831e1989d72 Mon Sep 17 00:00:00 2001 From: profbrady Date: Wed, 10 Apr 2019 10:22:20 -0400 Subject: [PATCH 06/12] Update character_lcd.py --- adafruit_character_lcd/character_lcd.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/adafruit_character_lcd/character_lcd.py b/adafruit_character_lcd/character_lcd.py index f990724..598e1b6 100755 --- a/adafruit_character_lcd/character_lcd.py +++ b/adafruit_character_lcd/character_lcd.py @@ -320,7 +320,7 @@ def message(self): Start position is (0,0) if cursor_position is not set. If cursor_position is set, message starts at the set position from the left for left to right text and from - the right for right to left text. Resets cursor column + the right for right to left text. Resets cursor column and row to (0,0) after displaying the message. The following example displays, "Hello, world!" on the LCD. @@ -356,15 +356,17 @@ def message(self, message): # If cursor_position is set then starts at the specified location for # LEFT_TO_RIGHT. If RIGHT_TO_LEFT cursor_position is determined from right. # allows for cursor_position to work in RIGHT_TO_LEFT mode - col = self.column if self.displaymode & _LCD_ENTRYLEFT > 0 else self.columns - 1 - self.column + col = self.column if self.displaymode & _LCD_ENTRYLEFT > 0 + else self.columns - 1 - self.column self.cursor_position(col, line) initial_character += 1 # If character is \n, go to next line if character == '\n': line += 1 - # Start the second line at (0, 1) unless direction is set right to left in 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 + # Start the second line at (0, 1) unless direction is set right to left in + # 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 self.cursor_position(col, line) # Write string to display else: @@ -372,7 +374,6 @@ def message(self, message): # reset column and row to (0,0) after message is displayed self.column, self.row = 0, 0 - def move_left(self): """Moves displayed text left one column. From 7ef2cc6c23fdc3863c328d8cf5f5e99164a84efe Mon Sep 17 00:00:00 2001 From: profbrady Date: Wed, 10 Apr 2019 10:43:57 -0400 Subject: [PATCH 07/12] Update character_lcd.py --- adafruit_character_lcd/character_lcd.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adafruit_character_lcd/character_lcd.py b/adafruit_character_lcd/character_lcd.py index 598e1b6..6c86afa 100755 --- a/adafruit_character_lcd/character_lcd.py +++ b/adafruit_character_lcd/character_lcd.py @@ -356,8 +356,10 @@ def message(self, message): # If cursor_position is set then starts at the specified location for # LEFT_TO_RIGHT. If RIGHT_TO_LEFT cursor_position is determined from right. # allows for cursor_position to work in RIGHT_TO_LEFT mode - col = self.column if self.displaymode & _LCD_ENTRYLEFT > 0 - else self.columns - 1 - self.column + if self.displaymode & _LCD_ENTRYLEFT > 0: + col = self.column + else: + col = self.columns - 1 - self.column self.cursor_position(col, line) initial_character += 1 # If character is \n, go to next line From 3d4340cef0d25f6834f4c9d6eb68ccef86560644 Mon Sep 17 00:00:00 2001 From: profbrady Date: Thu, 11 Apr 2019 07:20:12 -0400 Subject: [PATCH 08/12] Update charlcd_mono_simpletest.py --- examples/charlcd_mono_simpletest.py | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/examples/charlcd_mono_simpletest.py b/examples/charlcd_mono_simpletest.py index e537f28..914b49f 100644 --- a/examples/charlcd_mono_simpletest.py +++ b/examples/charlcd_mono_simpletest.py @@ -25,40 +25,14 @@ lcd.backlight = True # Print a two line message lcd.message = "Hello\nCircuitPython" -# Wait 3s -time.sleep(3) -# Print two line message with cursor set to column 2 -lcd.clear() -lcd.cursor_position(2, 0) -lcd.message = "Hello\nCircuitPython" # Wait 5s time.sleep(5) lcd.clear() -# Stars across the display one a time on second row from L to R -# using cursor_position -for i in range(16): - lcd.cursor_position(i, 1) - lcd.message = "*" - time.sleep(0.1) -lcd.clear() # Print two line message right to left lcd.text_direction = lcd.RIGHT_TO_LEFT lcd.message = "Hello\nCircuitPython" # Wait 5s time.sleep(5) -# Print two line R to L message with cursor set to column 3 -lcd.clear() -lcd.text_direction = lcd.RIGHT_TO_LEFT -lcd.cursor_position(3, 0) -lcd.message = "Hello\nCircuitPython" -# Wait 3s -time.sleep(3) -# Stars across the display one a time on second row from R to L -lcd.clear() -for i in range(16): - lcd.cursor_position(i, 1) - lcd.message = "*" - time.sleep(0.1) lcd.clear() # Return text direction to left to right lcd.text_direction = lcd.LEFT_TO_RIGHT @@ -77,7 +51,6 @@ lcd.blink = False lcd.clear() # Create message to scroll -lcd.cursor_position(5, 0) scroll_msg = '<-- Scroll' lcd.message = scroll_msg # Scroll message to the left From 4ffe6dedf2889c1bdc24bb410dcde2a371cb91cd Mon Sep 17 00:00:00 2001 From: profbrady Date: Thu, 11 Apr 2019 21:44:25 -0400 Subject: [PATCH 09/12] Update character_lcd.py --- adafruit_character_lcd/character_lcd.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/adafruit_character_lcd/character_lcd.py b/adafruit_character_lcd/character_lcd.py index 6c86afa..1ba8b3d 100755 --- a/adafruit_character_lcd/character_lcd.py +++ b/adafruit_character_lcd/character_lcd.py @@ -173,6 +173,7 @@ def __init__(self, rs, en, d4, d5, d6, d7, columns, lines # itialize to 0,0 self.row = 0 self.column = 0 + self._column_align = False # pylint: enable-msg=too-many-arguments def home(self): @@ -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. + """ + return self._column_align + + @column_align.setter + def column_align(self, enable): + self._column_align = enable @property def cursor(self): @@ -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 """ @@ -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: From eb8612e0c3e1c2b88266eb05d016b8ea5aad6bcd Mon Sep 17 00:00:00 2001 From: profbrady Date: Thu, 11 Apr 2019 22:36:30 -0400 Subject: [PATCH 10/12] Update charlcd_mono_simpletest.py --- examples/charlcd_mono_simpletest.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/charlcd_mono_simpletest.py b/examples/charlcd_mono_simpletest.py index 914b49f..9a47104 100644 --- a/examples/charlcd_mono_simpletest.py +++ b/examples/charlcd_mono_simpletest.py @@ -33,7 +33,6 @@ lcd.message = "Hello\nCircuitPython" # Wait 5s time.sleep(5) -lcd.clear() # Return text direction to left to right lcd.text_direction = lcd.LEFT_TO_RIGHT # Display cursor @@ -54,7 +53,7 @@ scroll_msg = '<-- Scroll' lcd.message = scroll_msg # Scroll message to the left -for i in range(len(scroll_msg)+5): +for i in range(len(scroll_msg)): time.sleep(0.5) lcd.move_left() lcd.clear() From ff1df52a0b9a4ef271c021c07f3fa5e8243fdf80 Mon Sep 17 00:00:00 2001 From: profbrady Date: Thu, 11 Apr 2019 22:44:17 -0400 Subject: [PATCH 11/12] Update character_lcd.py --- adafruit_character_lcd/character_lcd.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/adafruit_character_lcd/character_lcd.py b/adafruit_character_lcd/character_lcd.py index 1ba8b3d..3ea372b 100755 --- a/adafruit_character_lcd/character_lcd.py +++ b/adafruit_character_lcd/character_lcd.py @@ -202,7 +202,7 @@ 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 @@ -212,7 +212,10 @@ def column_align(self): @column_align.setter def column_align(self, enable): - self._column_align = enable + 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): @@ -248,7 +251,7 @@ def cursor(self, show): def cursor_position(self, 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 """ @@ -395,7 +398,7 @@ def message(self, message): self._write8(ord(character), True) # reset column and row to (0,0) after message is displayed self.column, self.row = 0, 0 - + def move_left(self): """Moves displayed text left one column. From f9d662e1079a2411852e3e9d1b17ae98d8c400de Mon Sep 17 00:00:00 2001 From: profbrady Date: Thu, 11 Apr 2019 23:23:07 -0400 Subject: [PATCH 12/12] Update character_lcd.py --- adafruit_character_lcd/character_lcd.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_character_lcd/character_lcd.py b/adafruit_character_lcd/character_lcd.py index 3ea372b..2e16cfd 100755 --- a/adafruit_character_lcd/character_lcd.py +++ b/adafruit_character_lcd/character_lcd.py @@ -170,7 +170,7 @@ def __init__(self, rs, en, d4, d5, d6, d7, columns, lines self._enable = None self._direction = None # track row and column used in cursor_position - # itialize to 0,0 + # initialize to 0,0 self.row = 0 self.column = 0 self._column_align = False @@ -205,8 +205,8 @@ def clear(self): @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. + """If True, message text after '\\n' starts directly below start of first + character in message. If False, text after '\\n' starts at column zero. """ return self._column_align