|
@@ -1,10 +1,9 @@
|
|
|
-# -*- coding: utf-8 -*-
|
|
|
"""
|
|
|
Author: Tobias Müller
|
|
|
-Date: 30.06.2023
|
|
|
-Version: 0.9
|
|
|
+Date: 13.09.2023
|
|
|
+Version: 1.0
|
|
|
|
|
|
-This file contains classes for LCD, Button and Led control.
|
|
|
+This file contains a class for a LCD.
|
|
|
"""
|
|
|
|
|
|
############################## Modules ##############################
|
|
@@ -15,6 +14,9 @@ import re
|
|
|
############################## Code ##############################
|
|
|
|
|
|
class LCD:
|
|
|
+ """
|
|
|
+ Class to control a DOGS104-A LC-Display.
|
|
|
+ """
|
|
|
|
|
|
############################## Attributes ##############################
|
|
|
|
|
@@ -73,6 +75,20 @@ class LCD:
|
|
|
lcd_ascii_rom: int|str = "ROM B",
|
|
|
lcd_line_mode: int = 0,
|
|
|
lcd_direction_top: int|bool = False):
|
|
|
+ """
|
|
|
+ Initialize LCD. Alls arguments can be changed later as a property.
|
|
|
+
|
|
|
+ Args:
|
|
|
+ i2c_sda_pin (int | str, optional): Set SDA-Pin for I2C-Bus. Defaults to 2.
|
|
|
+ i2c_scl_pin (int | str, optional): Set SCL-Pin for I2C-Bus. Defaults to 3.
|
|
|
+ i2c_frequency (int | str, optional): Set I2C frequency. Defaults to "STANDARD_MODE".
|
|
|
+ lcd_backlight_pin (int | str, optional): Set LCD backlight pin. Defaults to 28.
|
|
|
+ lcd_brightness (int, optional): Set LCD brightness in percent. Defaults to 100.
|
|
|
+ lcd_contrast (int, optional): Set LCD contrast in percent. Defaults to 60.
|
|
|
+ lcd_ascii_rom (int | str, optional): Set ASCII-ROM. Defaults to "ROM B".
|
|
|
+ lcd_line_mode (int, optional): Set LCD line mode for 2-, 3- or 4-lines. Defaults to 0.
|
|
|
+ lcd_direction_top (int | bool, optional): Set LCD direction to top. Defaults to False.
|
|
|
+ """
|
|
|
|
|
|
# Check and store input values
|
|
|
self.__i2c_bus, self.__i2c_sda_pin, self.__i2c_scl_pin = self.__check_i2c_ports(i2c_sda_pin,
|
|
@@ -449,7 +465,15 @@ class LCD:
|
|
|
|
|
|
############################## Methods public ##############################
|
|
|
|
|
|
- def change_i2c_port(self, i2c_sda_pin: int|str, i2c_scl_pin: int|str):
|
|
|
+ def change_i2c_port(self, i2c_sda_pin: int|str, i2c_scl_pin: int|str):
|
|
|
+ """
|
|
|
+ Used to change I2C port.
|
|
|
+
|
|
|
+ Args:
|
|
|
+ i2c_sda_pin (int | str): SDA-Pin of I2C Port
|
|
|
+ i2c_scl_pin (int | str): SCL-Pin of I2C Port
|
|
|
+ """
|
|
|
+
|
|
|
self.__check_i2c_ports(i2c_sda_pin, i2c_scl_pin)
|
|
|
self.__deinit_i2c()
|
|
|
(self.__i2c_bus,
|
|
@@ -458,6 +482,17 @@ class LCD:
|
|
|
self.__init_i2c()
|
|
|
|
|
|
def print(self, text: str, **keywords):
|
|
|
+ """
|
|
|
+ Used to print text on the LCD.
|
|
|
+
|
|
|
+ Args:
|
|
|
+ text (str): Text, which is printed on the LCD.
|
|
|
+ Keywords:
|
|
|
+ row (int): Row to start printing. Defaults to 1.
|
|
|
+ column (int): Column to start printing. Defaults to 1.
|
|
|
+ auto_line_break (int | bool): Breaks the line automatically. Defaults to True.
|
|
|
+ """
|
|
|
+
|
|
|
def check_text(text: str):
|
|
|
if not isinstance(text, str):
|
|
|
raise ValueError(f"Value \"{text}\" of \"text\" is not type \"str\"!")
|
|
@@ -498,6 +533,16 @@ class LCD:
|
|
|
self.__i2c.writeto(self.__i2c_address, bytes(buffer))
|
|
|
|
|
|
def clear(self, **keywords):
|
|
|
+ """
|
|
|
+ Used to clear the LCD. If the keywords row or column are not used,
|
|
|
+ the method will clear the whole display.
|
|
|
+
|
|
|
+ Keywords:
|
|
|
+ row (int): Row to start printing. Defaults to 1.
|
|
|
+ column (int): Column to start printing. Defaults to 1.
|
|
|
+ auto_line_break (int | bool): Breaks the line automatically. Defaults to True.
|
|
|
+ """
|
|
|
+
|
|
|
buffer = []
|
|
|
if len(keywords) == 0:
|
|
|
buffer.append(self.__lcd_control_para["CONTROL_BYTE"])
|
|
@@ -517,6 +562,15 @@ class LCD:
|
|
|
self.__i2c.writeto(self.__i2c_address, bytes(buffer))
|
|
|
|
|
|
def read(self, **keywords):
|
|
|
+ """
|
|
|
+ Used to read from the LCD.
|
|
|
+
|
|
|
+ Keywords:
|
|
|
+ row (int): Row to start reading from. Defaults to 1.
|
|
|
+ column (int): Column to start reading from. Defaults to 1.
|
|
|
+ separate (int | bool): Separate each line into a list. Defaults to False.
|
|
|
+ """
|
|
|
+
|
|
|
def remove_whitespace(text: str):
|
|
|
textlen = len(text)
|
|
|
endpos = textlen
|
|
@@ -557,3 +611,4 @@ class LCD:
|
|
|
if __name__ == "__main__":
|
|
|
lcd = LCD(lcd_line_mode=0x03)
|
|
|
lcd.print("Hochschule Anhalt")
|
|
|
+ lcd.lcd_brightness = 50
|