Skip to content

Update lcd_api.py / One linefeed too many, in case the line is filled up to the last character #29

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

Conversation

CrossLAN
Copy link

@CrossLAN CrossLAN commented Jan 3, 2021

One linefeed too many, in case the line is filled up to the last character

In case I fill the line to the last row, it skips the following line without replacement and the following line remains empty. This is independent of whether I put a \n at the end of the line or not. If I fill the display only with 19 characters instead of the 20 possible characters, the line jump to the following line works.

I walked through your code and the following change in lcd_api.py in "putchar" definition will fix this issue:

One linefeed too many, in case the line is filled up to the last character

In case I fill the line to the last row, it skips the following line without replacement and the following line remains empty. This is independent of whether I put a \n at the end of the line or not. If I fill the display only with 19 characters instead of the 20 possible characters, the line jump to the following line works.

I walked through your code and the following change in lcd_api.py in "putchar" definition will fix this issue:
@CrossLAN CrossLAN changed the title Update lcd_api.py Update lcd_api.py / One linefeed too many, in case the line is filled up to the last character Jan 3, 2021
@@ -140,7 +140,8 @@ def putchar(self, char):
self.cursor_x += 1
if self.cursor_x >= self.num_columns or char == '\n':
self.cursor_x = 0
self.cursor_y += 1
if char == '\n':
self.cursor_y += 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems to me that if you output to exactly fill the display without a \n then this change will leave the cursor at the beginning of the last line rather than at the beginning of line 0.

I'll have to write some test code to see what happens.

Copy link
Collaborator

Choose a reason for hiding this comment

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

With your proposed change, the following test:

    lcd.putstr('Line 1 - 01234567890')
    lcd.putstr('Line 2 - 01234567890')
    lcd.putstr('Line 3 - 01234567890')
    lcd.putstr('Line 4 - 01234567890')
    lcd.putstr('Line 5 - 01234567890')

results in all 5 lines printing on top of each other on the first line. Without this change, Line 5 overwrites Line 1 (which is what I would have expected).

Can you provide an example test and explain what you're seeing with and without the patch?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see the problem: If I use this:

    lcd.putstr('Line 1 - 01234567890\n')
    lcd.putstr('Line 2 - 01234567890\n')
    lcd.putstr('Line 3 - 01234567890\n')
    lcd.putstr('Line 4 - 01234567890\n')
    lcd.putstr('Line 5 - 01234567890\n')

then I get the blank lines like you describe.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I fixed the issue via 18bc2e0

@dhylands dhylands closed this Jan 9, 2021
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.

3 participants