Skip to content

Commit 55f787a

Browse files
authored
Merge pull request #12 from fourstix/b_refactor
Refactor original code to remove reference to Abstract Base Class
2 parents 044ef59 + 73de71f commit 55f787a

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

sparkfun_serlcd.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
__repo__ = "https://github.com/fourstix/Sparkfun_CircuitPython_SerLCD.git"
6161

6262
# imports
63-
# from abc import ABC, abstractmethod // Please no abstractmethods, CircuitPython is not Python 3
6463
from time import sleep
6564
from micropython import const
6665

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

140139
return int(result)
141140

142-
# base class
141+
# abstract base class
143142
class Sparkfun_SerLCD:
144143
"""Abstract base class for Sparkfun AVR-Based Serial LCD display.
145-
Use the appropriate driver communcation subclass Sprarkfun_SerLCD_I2C()
144+
Use the appropriate driver communcation subclass Sparkfun_SerLCD_I2C()
146145
for I2C, Sparkfun_SerLCD_SPI() for SPI or Sparkfun_SerLCD_UART for UART.
147146
"""
148147
# pylint: disable=too-many-instance-attributes
@@ -382,6 +381,27 @@ def set_contrast(self, value):
382381
self._write_bytes(data)
383382
sleep(0.010)
384383

384+
def set_i2c_address(self, new_address):
385+
"""Change the I2C Address. 0x72 is the default.
386+
Note that this change is persistent. If anything goes wrong
387+
you may need to do a hardware reset to unbrick the display.
388+
389+
byte new_addr - new i2c address"""
390+
# Mask new address to byte
391+
new_address &= 0x00FF
392+
# Transmit to device on old address
393+
data = bytearray()
394+
# Send contrast command
395+
data.append(_SETTING_COMMAND)
396+
data.append(_ADDRESS_COMMAND) # 0x19
397+
data.append(new_address)
398+
self._write_bytes(data)
399+
# Update our own address so we can still talk to the display
400+
self._change_i2c_address(new_address)
401+
402+
# This may take awhile
403+
sleep(0.050)
404+
385405
def scroll_display_left(self, count=1):
386406
"""Scroll the display to the left"""
387407
self._special_command(_LCD_CURSORSHIFT | _LCD_DISPLAYMOVE | _LCD_MOVELEFT, count)
@@ -442,11 +462,9 @@ def default_splash_screen(self):
442462

443463
# abstract methods
444464

445-
# @abstractmethod
446465
def _write_bytes(self, data):
447466
pass
448467

449-
# @abstractmethod
450468
def _change_i2c_address(self, addr):
451469
pass
452470

0 commit comments

Comments
 (0)