dbrgn / RPLCD

A Raspberry Pi LCD library for the widely used Hitachi HD44780 controller, written in Python. GPIO (parallel) and I²C modes supported.
https://rplcd.readthedocs.io/en/latest/
MIT License
262 stars 72 forks source link

Decompose I2C Char LCD class into i2c_expander Based Classess. #129

Open codenio opened 3 years ago

codenio commented 3 years ago

Thanks for this excellent project. Exploring the internals of i2c LCD supported, I came across

class CharLCD(BaseCharLCD):
    def __init__(self, i2c_expander, address, expander_params=None, port=1,
                       cols=20, rows=4, dotsize=8,
                       charmap='A02',
                       auto_linebreaks=True,
                       backlight_enabled=True):

that takes i2c_expander as a parameter and does a comparision in all it's methods for executing corresponding actions. I feel that decomposing this complex class into simpler i2c_expander Based Classes, like

class PCF8574CharLCD(BaseCharLCD):
    def __init__(self, address, port=1,
                       cols=20, rows=4, dotsize=8,
                       .... ):

class MCP23008CharLCD(BaseCharLCD):
    def __init__(self, address, expander_params=None, port=1,
                       cols=20, rows=4, dotsize=8,
                       .... ):

which enhances code readability, maintainability, development, and testing.

do let me know your thoughts..! -codenio