Skip to content

Update character_lcd.py #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 12, 2019
Merged

Conversation

profbrady
Copy link
Contributor

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.

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.
@profbrady
Copy link
Contributor Author

Build failed??? What does that mean? Was this caused by my edits? I am hopeful that I can have my students use this change in an upcoming project. Forgive my stupidity, I am new to Github nor am I formally trained in programming.

@dhalbert
Copy link
Contributor

dhalbert commented Apr 9, 2019

Hi - to check the errors, click on "Details" above, then on "The build" in "The build failed". Look at the build log. On this build, looks like there's a documentation error reported on line 755.

@deshipu
Copy link

deshipu commented Apr 9, 2019

Warning, treated as error:
../README.rst:119:undefined label: bundle_installation (if the link has no caption the label must precede a section header)
The command "cd docs && sphinx-build -E -W -b html . _build/html && cd .." exited with 2.

@profbrady
Copy link
Contributor Author

profbrady commented Apr 9, 2019 via email

@kattni
Copy link
Contributor

kattni commented Apr 9, 2019

The failure is unrelated to anything you did. The README needs to be edited to fix this issue. I can walk you through what to change, @profbrady

@kattni
Copy link
Contributor

kattni commented Apr 9, 2019

@profbrady Please remove lines 116-125 from README.rst and push the changes to this PR.

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 <bundle_installation>`.

To install:

#. Download and unzip the `latest release zip <https://github.com/adafruit/Adafruit_CircuitPython_CharLCD/releases>`_.
#. Copy the unzipped ``adafruit_character_lcd`` to the ``lib`` directory on the ``CIRCUITPY`` or ``MICROPYTHON`` drive.

@profbrady
Copy link
Contributor Author

profbrady commented Apr 9, 2019 via email

@kattni
Copy link
Contributor

kattni commented Apr 9, 2019

@profbrady You need to push the branch to GitHub.

@profbrady
Copy link
Contributor Author

This is where my ignorance shows. I don't know how to push the branch.

@kattni
Copy link
Contributor

kattni commented Apr 9, 2019

@profbrady Ok, let's take a couple of steps back. Where did you make the changes to the README? Tell me the exact process you took to make those changes so I can help you figure out the next steps.

As well, you can reach me as @kattni on the Adafruit Discord. If live chat would work better for you, we can figure it out there. I'm happy to continue here if this is what works for you.

@profbrady
Copy link
Contributor Author

I went into my branch; profbrady: prof brady-patch-1 and clicked on the edit icon for the readme file. I removed the lines and clicked on Commit Changes with the commit directly to my branch toggled on.

@makermelissa
Copy link
Collaborator

It appears the readme file was updated on your master branch, but your PR is based off of the profbrady-patch-1 branch.

@profbrady
Copy link
Contributor Author

I think I edited the correct one now.

@kattni
Copy link
Contributor

kattni commented Apr 9, 2019

@profbrady You did! Well done! Your build is in behind a rather long build, so it might take a bit for Travis to run. Please be patient and we'll see if my suggestions fix the issue. :)

@profbrady
Copy link
Contributor Author

Thanks for all of the help and patience

@makermelissa
Copy link
Collaborator

I'll go ahead and test this out tonight.

@kattni
Copy link
Contributor

kattni commented Apr 9, 2019

Thank you for sticking with it and for your contribution!

@makermelissa makermelissa self-requested a review April 10, 2019 01:40
@makermelissa
Copy link
Collaborator

Hi @profbrady, I went ahead and tested this with the charlcd_mono_simpletest.py example and with these changes, it appears to be losing a bunch of the text. Could you try running this example and see what your results are? Thanks

Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

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

This seems to be losing a bunch of the text, especially on the first line.

@profbrady
Copy link
Contributor Author

I'll have to test it in the morning. I left my LCD in my office at school. I am using a standard LCD, not SPI or I2C. It is a 6 digital out variety that is about 4 years old. I ran the following code on it and it worked fine.

# Circuit 15 LCD Display
# Use 5V, not 3.3V, to power the LCD display
# Requires Mr. Brady's character_lcd.py library file
# Use the Serial button in Mu to see printed output

import time, math, digitalio
from adafruit_character_lcd import character_lcd
from board import *

#   Character LCD Config:
#   modify this if you have a different sized charlcd
lcd_columns = 16
lcd_rows = 2

#   Metro m0 Pin Config:
lcd_rs = digitalio.DigitalInOut(D12)
lcd_rs.switch_to_output()

lcd_en = digitalio.DigitalInOut(D11)
lcd_en.switch_to_output()

lcd_d7 = digitalio.DigitalInOut(D2)
lcd_d7.switch_to_output()

lcd_d6 = digitalio.DigitalInOut(D3)
lcd_d6.switch_to_output()

lcd_d5 = digitalio.DigitalInOut(D4)
lcd_d5.switch_to_output()

lcd_d4 = digitalio.DigitalInOut(D5)
lcd_d4.switch_to_output()

#lcd_backlight = digitalio.DigitalInOut(D13)
#lcd_backlight.switch_to_output()

#   Init the lcd class
lcd = character_lcd.Character_LCD_Mono(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows)

#   Print a 2x line message
lcd.cursor_position(1,0)
lcd.display = False
lcd.message = 'Hello,\nWorld!'
time.sleep(0.2)
for i in range(6):
    lcd.move_left()
    time.sleep(0.2)
lcd.display = True
for i in range(15):
    lcd.move_right()
    time.sleep(0.2)
for i in range(9):
    lcd.move_left()
    time.sleep(0.2)
start_time = int(time.monotonic())

while True:
    lcd.cursor_position(12,0)
    current_time = int(time.monotonic() - start_time)
    time_display = '{:03d}\nsec'.format(current_time)
    lcd.message = time_display
    time.sleep(0.1)

@makermelissa
Copy link
Collaborator

Yeah, I used a standard LCD as well. Your code works with your update, but with reverse text like in the example, it appears to break.

@profbrady
Copy link
Contributor Author

I found that I did have an I2C RGB at home. If I ran the sample code for that as is I had the same problem you did after a direction change. However, if I added lcd.cursor_position(0,0) after a direction change and before the next message command everything worked great. Maybe issuing a direction change will need to automatically reset self.row and self.column back to 0, otherwise just manually set the position after a direction change.

@profbrady
Copy link
Contributor Author

A question I have is do we want to remember the position of the cursor after displaying a message so that another message starts at the end of the previous? Or do we want to have the next message start where the previous message started; essentially where the last cursor_position() was set? Either is possible, I have just tested both.

I still haven't come up with a method to set the cursor_postion() to anything but the rightmost column when changing the text direction to right-to-left.

@makermelissa
Copy link
Collaborator

One idea may be to have a settable option that makes it behave as it did before if it's set and have it perform the way your code needs it if it's set with it being off by default so it doesn't break existing code.

@profbrady
Copy link
Contributor Author

profbrady commented Apr 10, 2019 via email

@profbrady
Copy link
Contributor Author

I just pushed a change to character_lcd.py and charled_mono_simpletest.py to implement the changes mentioned above. The demo now demonstrates the use of cursor_position().

@makermelissa
Copy link
Collaborator

Hi @profbrady, one of the reasons I wanted to avoid changing the simpletests if possible is because we would need to make changes to them all and test all of them. I think the simplest approach would be to undo the changes to the simpletest, add a property to the library that is called something like column_align with a default value of False, and if the value is set true, it runs the code with your additions. That way it won't break the examples and you'll have the feature that works with your code.

@profbrady
Copy link
Contributor Author

profbrady commented Apr 11, 2019 via email

@profbrady
Copy link
Contributor Author

I was able to take some time today to implement the property idea. The property column_align defaults to False. When False the text after a \n will start at the beginning of the line. When True it will align to the text on the previous line. This works regardless if cursor_position() is set or not and regardless of whether the text direction is left-to-right or right-to-left. The cursor_position() setting only affects the first message after it is set. After that the message start position reverts to (0, 0) since it is reset when the message is displayed. The cursor_position() setting works for both text directions and is determined from the left for left-to-right text and from the right for right-to-left text.

The current simple demo works as before, so existing code should not break. Pushing the change in a minute.

@makermelissa
Copy link
Collaborator

Ok, thanks @profbrady. I'll take a look at this shortly.

Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

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

You're very close here. I found a few more things to change. Also it looks like Travis is unhappy about some whitespace on lines 205, 251, and 398. I went ahead and tested with the original simpletest file and that seemed to work fine, so I think that's the only changes to make. Thanks for sticking with me here.


@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')

@@ -53,7 +54,7 @@
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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like there are still some changes to the simpletest, so just remove the +5

@@ -33,6 +33,7 @@
lcd.message = "Hello\nCircuitPython"
# Wait 5s
time.sleep(5)
lcd.clear()
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 remove the lcd.clear() just to keep the examples consistent.

@profbrady
Copy link
Contributor Author

@makermelissa thanks for the assistance on this. I just pushed the changes. I hope this fixes it. It is a bit exciting knowing that I am contributing to the community. I did a very small fix to simpleio about a year ago, but this was a bit more work.

Copy link
Collaborator

@makermelissa makermelissa left a comment

Choose a reason for hiding this comment

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

Looks like there's just a couple small changes that need to be made.

@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

@@ -169,6 +169,11 @@ 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
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

@makermelissa
Copy link
Collaborator

Ok, I just gave it a final test and it worked great. Thanks again for this.

@makermelissa makermelissa merged commit d0fc756 into adafruit:master Apr 12, 2019
@profbrady profbrady deleted the profbrady-patch-1 branch April 12, 2019 03:35
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants