Skip to content

Refactor original code to remove reference to Abstract Base Class #12

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 2 commits into from
Nov 10, 2021
Merged
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
28 changes: 23 additions & 5 deletions sparkfun_serlcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
__repo__ = "https://github.com/fourstix/Sparkfun_CircuitPython_SerLCD.git"

# imports
# from abc import ABC, abstractmethod // Please no abstractmethods, CircuitPython is not Python 3
from time import sleep
from micropython import const

Expand Down Expand Up @@ -139,10 +138,10 @@ def _map_range(value, in_min, in_max, out_min, out_max):

return int(result)

# base class
# abstract base class
class Sparkfun_SerLCD:
"""Abstract base class for Sparkfun AVR-Based Serial LCD display.
Use the appropriate driver communcation subclass Sprarkfun_SerLCD_I2C()
Use the appropriate driver communcation subclass Sparkfun_SerLCD_I2C()
for I2C, Sparkfun_SerLCD_SPI() for SPI or Sparkfun_SerLCD_UART for UART.
"""
# pylint: disable=too-many-instance-attributes
Expand Down Expand Up @@ -382,6 +381,27 @@ def set_contrast(self, value):
self._write_bytes(data)
sleep(0.010)

def set_i2c_address(self, new_address):
"""Change the I2C Address. 0x72 is the default.
Note that this change is persistent. If anything goes wrong
you may need to do a hardware reset to unbrick the display.

byte new_addr - new i2c address"""
# Mask new address to byte
new_address &= 0x00FF
# Transmit to device on old address
data = bytearray()
# Send contrast command
data.append(_SETTING_COMMAND)
data.append(_ADDRESS_COMMAND) # 0x19
data.append(new_address)
self._write_bytes(data)
# Update our own address so we can still talk to the display
self._change_i2c_address(new_address)

# This may take awhile
sleep(0.050)

def scroll_display_left(self, count=1):
"""Scroll the display to the left"""
self._special_command(_LCD_CURSORSHIFT | _LCD_DISPLAYMOVE | _LCD_MOVELEFT, count)
Expand Down Expand Up @@ -442,11 +462,9 @@ def default_splash_screen(self):

# abstract methods

# @abstractmethod
def _write_bytes(self, data):
pass

# @abstractmethod
def _change_i2c_address(self, addr):
pass

Expand Down