Skip to content
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

Update lcd_api.py to correct the behavior with \n #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 8 additions & 12 deletions lcd/lcd_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ class LcdApi:
"""Implements the API for talking with HD44780 compatible character LCDs.
This class only knows what commands to send to the LCD, and not how to get
them to the LCD.

It is expected that a derived class will implement the hal_xxx functions.
"""

Expand Down Expand Up @@ -103,7 +102,6 @@ def display_off(self):

def backlight_on(self):
"""Turns the backlight on.

This isn't really an LCD command, but some modules have backlight
controls, so this allows the hal to pass through the command.
"""
Expand All @@ -112,7 +110,6 @@ def backlight_on(self):

def backlight_off(self):
"""Turns the backlight off.

This isn't really an LCD command, but some modules have backlight
controls, so this allows the hal to pass through the command.
"""
Expand Down Expand Up @@ -140,7 +137,7 @@ def putchar(self, char):
if self.implied_newline:
# self.implied_newline means we advanced due to a wraparound,
# so if we get a newline right after that we ignore it.
self.implied_newline = False
pass
else:
self.cursor_x = self.num_columns
else:
Expand All @@ -150,9 +147,12 @@ def putchar(self, char):
self.cursor_x = 0
self.cursor_y += 1
self.implied_newline = (char != '\n')
if self.cursor_y >= self.num_lines:
self.cursor_y = 0
self.move_to(self.cursor_x, self.cursor_y)
if self.cursor_y >= self.num_lines:
self.cursor_y = 0
self.move_to(0, self.cursor_y)
else:
self.implied_newline = False


def putstr(self, string):
"""Write the indicated string to the LCD at the current cursor
Expand All @@ -175,29 +175,25 @@ def custom_char(self, location, charmap):

def hal_backlight_on(self):
"""Allows the hal layer to turn the backlight on.

If desired, a derived HAL class will implement this function.
"""
pass

def hal_backlight_off(self):
"""Allows the hal layer to turn the backlight off.

If desired, a derived HAL class will implement this function.
"""
pass

def hal_write_command(self, cmd):
"""Write a command to the LCD.

It is expected that a derived HAL class will implement this
function.
"""
raise NotImplementedError

def hal_write_data(self, data):
"""Write data to the LCD.

It is expected that a derived HAL class will implement this
function.
"""
Expand All @@ -209,4 +205,4 @@ def hal_write_data(self, data):
# of hal_sleep_us in their hal layer and it will be used instead.
def hal_sleep_us(self, usecs):
"""Sleep for some time (given in microseconds)."""
time.sleep_us(usecs) # NOTE this is not part of Standard Python library, specific hal layers will need to override this
time.sleep_us(usecs) # NOTE this is not part of Standard Python library, specific hal layers will need to override this