SegLCDLib
Loading...
Searching...
No Matches
SegLCDLib Class Referenceabstract

Abstract base class for LCD segment display drivers. More...

#include <SegLCDLib.h>

Inheritance diagram for SegLCDLib:
SegDriver_3Wire SegDriver_PCx85 SegDriver_HT1621 SegDriver_HT1622 SegDriver_VK0192 SegDriver_PCF85176 SegLCD_PCx85_Raw SegLCD_HT1621_4SegDegree SegLCD_HT1621_6SegBat SegLCD_HT1621_LCM0844 SegLCD_HT1621_LCM59011 SegLCD_HT1621_LCM88128 SegLCD_HT1621_Raw SegLCD_HT1622_10Dig16Seg SegLCD_HT1622_Raw SegLCD_VK0192_5DigSigBattProgress SegLCD_VK0192_Raw SegDriver_PCF8576 SegLCD_PCF85176_2Row4DigSigBatPwr SegLCD_PCF85176_4DR821B SegLCD_PCF85176_6DigitSignalBatteryProgress SegLCD_PCF85176_OneDigit SegLCD_PCF85176_T1T2Lcd SegLCD_PCF85176_TempHumidity

Public Types

enum  BacklightMode { BACKLIGHT_DIGITAL , BACKLIGHT_PWM }
 Backlight mode for GPIO control. More...
 

Public Member Functions

virtual ~SegLCDLib ()
 Virtual destructor to ensure proper cleanup in derived classes.
 
virtual void init ()=0
 Logical display sections that can be targeted by higher-level rendering logic.
 
virtual void clear ()
 Clear all visible segments on the display.
 
void home ()
 Set cursor to 0, 0 without clear display.
 
virtual void setCursor (uint8_t row, uint8_t col)
 Set cursor on exact digit.
 
virtual size_t write (uint8_t ch)
 
virtual void command (uint8_t command)=0
 Send RAW command to controller.
 
virtual void on ()=0
 Turn the display on.
 
virtual void off ()=0
 Turn the display off.
 
void initBacklight (int8_t backlightPin, BacklightMode backlightMode=BACKLIGHT_DIGITAL, bool backlightActiveHigh=true)
 Initialize GPIO backlight control.
 
virtual void setBacklight (bool state)
 Set backlight state (on/off).
 
virtual void setBacklight (int brightness)
 Set backlight brightness (0-255).
 
void setAutoFlush (bool enable)
 Enable or disable autoflush mode.
 
bool getAutoFlush () const
 Get current autoflush state.
 
virtual void flush ()
 Flush all buffered changes to the display.
 
virtual void flush (uint8_t startAddr, uint8_t length)
 Flush specific range of buffered changes to the display.
 
const uint8_t * getRamBuffer () const
 Get pointer to internal RAM buffer (read-only).
 
size_t getRamBufferSize () const
 Get size of internal RAM buffer in bytes.
 

Protected Member Functions

void _setFlag (uint8_t mask)
 Set a specific flag bit.
 
void _clearFlag (uint8_t mask)
 Clear a specific flag bit.
 
bool _isFlagSet (uint8_t mask) const
 Check if a specific flag bit is set.
 
void _clearAllFlags ()
 Clear all flags.
 
bool _dotWrite (uint8_t ch, int8_t minCol, int8_t maxCol, int8_t ramOffset)
 Write decimal point.
 
void _dotClearCur (int8_t minCol, int8_t maxCol)
 Clear current decimal (overwrite).
 
void _colonClearIfNotFlagged (uint8_t ch, uint8_t colonCol, uint8_t colonFlag)
 Clear colon if its flag is not set.
 
virtual void _setDecimal (uint8_t row, uint8_t col, bool state)
 Virtual method for setting decimal point.
 
virtual void _setColon (uint8_t row, uint8_t col, bool state)
 Virtual method for setting colon.
 
void _allocateBuffer (size_t size)
 Allocate RAM buffer for display data.
 
void _writeRamMasked (uint8_t data, uint8_t address, uint8_t mask=0xFF)
 Write to display RAM with nibble-aware masking support.
 
virtual void _writeRam (uint8_t data, uint8_t address)=0
 Low-level method to write a single byte to display RAM.
 
virtual void _writeRam (uint8_t *data, size_t length, uint8_t address)=0
 Low-level method to write a data buffer to display RAM.
 
uint8_t _get_char_value (char ch)
 Helper method to convert a character to its segment representation.
 
uint16_t _get_16char_value (char ch)
 Helper method to convert a character to its 16-segment representation.
 

Protected Attributes

bool _autoFlush = true
 Autoflush mode enabled flag (default: true for LCD API 1.0 compatibility).
 
int8_t _backlightPin = -1
 Backlight GPIO pin (-1 if disabled)
 
BacklightMode _backlightMode = BACKLIGHT_DIGITAL
 Backlight mode (DIGITAL or PWM)
 
bool _backlightActiveHigh = true
 Backlight active high flag.
 
uint8_t _backlightBrightness = 0
 Cached backlight brightness.
 
uint8_t _displayFlags = 0
 LEDC channel for old ESP32 Arduino Core (2.0.x)
 
uint8_t * _ramBuffer = nullptr
 Dynamic RAM buffer for display data (allocated by derived classes).
 
size_t _ramBufferSize = 0
 Size of allocated RAM buffer in bytes.
 
uint8_t _cursorRow = 0
 Current Row.
 
uint8_t _cursorCol = 0
 Current Column.
 

Static Protected Attributes

static constexpr uint8_t FLAG_PENDING_DOT = 0x80
 Common flag for decimal handling when RAM offset is 0.
 

Detailed Description

Abstract base class for LCD segment display drivers.

This class defines the generic interface required by all LCD segment drivers, including display control, character output, and data writing methods.

Member Enumeration Documentation

◆ BacklightMode

Backlight mode for GPIO control.

Enumerator
BACKLIGHT_DIGITAL 

Digital on/off mode.

BACKLIGHT_PWM 

PWM brightness control (0-255)

Constructor & Destructor Documentation

◆ ~SegLCDLib()

SegLCDLib::~SegLCDLib ( )
virtual

Virtual destructor to ensure proper cleanup in derived classes.

Member Function Documentation

◆ _allocateBuffer()

void SegLCDLib::_allocateBuffer ( size_t  size)
protected

Allocate RAM buffer for display data.

Parameters
sizeBuffer size in bytes

◆ _clearAllFlags()

void SegLCDLib::_clearAllFlags ( )
protected

Clear all flags.

◆ _clearFlag()

void SegLCDLib::_clearFlag ( uint8_t  mask)
protected

Clear a specific flag bit.

Parameters
maskBitmask with bit(s) to clear

◆ _colonClearIfNotFlagged()

void SegLCDLib::_colonClearIfNotFlagged ( uint8_t  ch,
uint8_t  colonCol,
uint8_t  colonFlag 
)
protected

Clear colon if its flag is not set.

Internal helper for display-specific write() implementations.

Parameters
chCharacter being processed
colonColColon position
colonFlagFlag bit for this colon

◆ _dotClearCur()

void SegLCDLib::_dotClearCur ( int8_t  minCol,
int8_t  maxCol 
)
protected

Clear current decimal (overwrite).

Internal helper for display-specific write() implementations.

Parameters
minColMinimum valid column
maxColMaximum valid column

◆ _dotWrite()

bool SegLCDLib::_dotWrite ( uint8_t  ch,
int8_t  minCol,
int8_t  maxCol,
int8_t  ramOffset 
)
protected

Write decimal point.

Internal helper for display-specific write() implementations.

Parameters
chCharacter to process
minColMinimum valid column for decimal
maxColMaximum valid column for decimal
ramOffsetRAM offset for decimal (-1, 0, or +1)
Returns
true if character '.' was processed

◆ _get_16char_value()

uint16_t SegLCDLib::_get_16char_value ( char  ch)
protected

Helper method to convert a character to its 16-segment representation.

◆ _get_char_value()

uint8_t SegLCDLib::_get_char_value ( char  ch)
protected

Helper method to convert a character to its segment representation.

◆ _isFlagSet()

bool SegLCDLib::_isFlagSet ( uint8_t  mask) const
protected

Check if a specific flag bit is set.

Parameters
maskBitmask with bit(s) to check
Returns
true if all bits in mask are set

◆ _setColon()

virtual void SegLCDLib::_setColon ( uint8_t  row,
uint8_t  col,
bool  state 
)
inlineprotectedvirtual

◆ _setDecimal()

virtual void SegLCDLib::_setDecimal ( uint8_t  row,
uint8_t  col,
bool  state 
)
inlineprotectedvirtual

◆ _setFlag()

void SegLCDLib::_setFlag ( uint8_t  mask)
protected

Set a specific flag bit.

Parameters
maskBitmask with bit(s) to set

◆ _writeRam() [1/2]

virtual void SegLCDLib::_writeRam ( uint8_t *  data,
size_t  length,
uint8_t  address 
)
protectedpure virtual

Low-level method to write a data buffer to display RAM.

Parameters
dataPointer to data buffer
lengthLength of data buffer
addressStart RAM address

Implemented in SegDriver_3Wire, SegDriver_HT1622, SegDriver_PCx85, and SegDriver_VK0192.

◆ _writeRam() [2/2]

virtual void SegLCDLib::_writeRam ( uint8_t  data,
uint8_t  address 
)
protectedpure virtual

Low-level method to write a single byte to display RAM.

Parameters
dataData byte
addressRAM address

Implemented in SegDriver_3Wire, SegDriver_HT1622, SegDriver_VK0192, and SegDriver_PCx85.

◆ _writeRamMasked()

void SegLCDLib::_writeRamMasked ( uint8_t  data,
uint8_t  address,
uint8_t  mask = 0xFF 
)
protected

Write to display RAM with nibble-aware masking support.

Handles both byte-aligned and nibble-aligned addresses with read-modify-write when mask is not 0xFF. Updates internal buffer and writes to hardware.

Parameters
dataValue to write
addressRAM address (nibble-level addressing)
maskBitmask for selective bit updates (0xFF = write all bits)

◆ clear()

void SegLCDLib::clear ( )
virtual

◆ command()

virtual void SegLCDLib::command ( uint8_t  command)
pure virtual

Send RAW command to controller.

Parameters
commandRaw command byte

Implemented in SegDriver_3Wire, and SegDriver_PCx85.

◆ flush() [1/2]

void SegLCDLib::flush ( )
virtual

Flush all buffered changes to the display.

Writes the entire display buffer to the hardware. This is useful when autoflush is disabled to batch multiple write() calls into a single hardware update cycle.

Safe to call even when autoflush is enabled (no effect).

See also
setAutoFlush()

Reimplemented in SegDriver_HT1621, SegDriver_HT1622, SegDriver_PCx85, and SegDriver_VK0192.

◆ flush() [2/2]

void SegLCDLib::flush ( uint8_t  startAddr,
uint8_t  length 
)
virtual

Flush specific range of buffered changes to the display.

Writes a specific address range from the display buffer to hardware. This is an advanced API for optimizing updates when only part of the display needs to be refreshed.

For example, to update only the first row of a multi-row display:

lcd.flush(0, 6); // Update first 6 bytes (row 0)

Safe to call even when autoflush is enabled (no effect).

Parameters
startAddrStarting buffer address in bytes (RAM buffer index)
lengthNumber of bytes to flush
See also
setAutoFlush()

Reimplemented in SegDriver_HT1621, SegDriver_HT1622, SegDriver_PCx85, SegDriver_VK0192, SegDriver_HT1621, SegDriver_HT1622, SegDriver_PCx85, and SegDriver_VK0192.

◆ getAutoFlush()

bool SegLCDLib::getAutoFlush ( ) const

Get current autoflush state.

Returns
true if autoflush is enabled, false if in manual flush mode

◆ getRamBuffer()

const uint8_t * SegLCDLib::getRamBuffer ( ) const

Get pointer to internal RAM buffer (read-only).

Returns
Pointer to RAM buffer or nullptr if not allocated.

◆ getRamBufferSize()

size_t SegLCDLib::getRamBufferSize ( ) const

Get size of internal RAM buffer in bytes.

Returns
Buffer size in bytes (0 if not allocated).

◆ home()

void SegLCDLib::home ( )

Set cursor to 0, 0 without clear display.

◆ init()

◆ initBacklight()

void SegLCDLib::initBacklight ( int8_t  backlightPin,
BacklightMode  backlightMode = BACKLIGHT_DIGITAL,
bool  backlightActiveHigh = true 
)

Initialize GPIO backlight control.

Must be called from init() of concrete implementations to setup the backlight GPIO.

Parameters
backlightPinGPIO pin for backlight control (-1 to disable)
backlightModeBacklight mode (DIGITAL or PWM)
backlightActiveHightrue if backlight is active high (default), false for active low

◆ off()

virtual void SegLCDLib::off ( )
pure virtual

Turn the display off.

Implemented in SegDriver_3Wire, and SegDriver_PCx85.

◆ on()

virtual void SegLCDLib::on ( )
pure virtual

Turn the display on.

Implemented in SegDriver_3Wire, and SegDriver_PCx85.

◆ setAutoFlush()

void SegLCDLib::setAutoFlush ( bool  enable)

Enable or disable autoflush mode.

In autoflush mode (default), each write() call immediately updates the display. This maintains LCD API 1.0 compatibility but can cause flicker when multiple segments are updated rapidly (e.g., writing "123.4" causes decimal point to flicker).

In manual flush mode, write() only updates the internal buffer. Call flush() to write all buffered changes to the display at once, eliminating flicker.

Example usage:

// Disable autoflush for rapid updates
lcd.setAutoFlush(false);
void loop() {
lcd.setCursor(0, 0);
lcd.print(value); // Buffer only, no HW write
lcd.flush(); // Single HW write of all changes
delay(100);
}
Parameters
enabletrue to enable autoflush (default), false for manual flush mode
See also
flush()

◆ setBacklight() [1/2]

void SegLCDLib::setBacklight ( bool  state)
virtual

Set backlight state (on/off).

Parameters
statetrue to turn backlight on, false to turn off

◆ setBacklight() [2/2]

void SegLCDLib::setBacklight ( int  brightness)
virtual

Set backlight brightness (0-255).

Parameters
brightnessBrightness level 0-255, where 0 is off and 255 is full brightness

◆ setCursor()

void SegLCDLib::setCursor ( uint8_t  row,
uint8_t  col 
)
virtual

Set cursor on exact digit.

Because LCD API is mainly used for character displays in this segment displays this function will be littlebit confusing. Because most of Segment LCD has only one row, thus this will be like row 0 and column will represent actual digit.

But if there is LCD like T1T2 LCD. Row 0 will be clock part, Row 1 will be T1: part and Row 2 will be T2: part of LCD

Parameters
rowRow, where 0-MAXROWS
colColumn 0-MAXDIGITS in current row

Reimplemented in SegLCD_HT1621_4SegDegree, SegLCD_PCF85176_4DR821B, SegLCD_PCF85176_6DigitSignalBatteryProgress, SegLCD_PCF85176_T1T2Lcd, SegLCD_PCF85176_TempHumidity, SegLCD_PCF8576_4Seg6SegMaintSegBatUnits, and SegLCD_VK0192_5DigSigBattProgress.

◆ write()

Field Documentation

◆ _autoFlush

bool SegLCDLib::_autoFlush = true
protected

Autoflush mode enabled flag (default: true for LCD API 1.0 compatibility).

◆ _backlightActiveHigh

bool SegLCDLib::_backlightActiveHigh = true
protected

Backlight active high flag.

◆ _backlightBrightness

uint8_t SegLCDLib::_backlightBrightness = 0
protected

Cached backlight brightness.

◆ _backlightMode

BacklightMode SegLCDLib::_backlightMode = BACKLIGHT_DIGITAL
protected

Backlight mode (DIGITAL or PWM)

◆ _backlightPin

int8_t SegLCDLib::_backlightPin = -1
protected

Backlight GPIO pin (-1 if disabled)

◆ _cursorCol

uint8_t SegLCDLib::_cursorCol = 0
protected

Current Column.

◆ _cursorRow

uint8_t SegLCDLib::_cursorRow = 0
protected

Current Row.

◆ _displayFlags

uint8_t SegLCDLib::_displayFlags = 0
protected

LEDC channel for old ESP32 Arduino Core (2.0.x)

Generic flag storage for display-specific state tracking.

Individual LCD implementations can use these bits to track state like:

  • Colon positions active
  • Previous dot written
  • Special characters displayed

Usage: Define bit constants in derived class, use helper methods to set/clear/check.

◆ _ramBuffer

uint8_t* SegLCDLib::_ramBuffer = nullptr
protected

Dynamic RAM buffer for display data (allocated by derived classes).

◆ _ramBufferSize

size_t SegLCDLib::_ramBufferSize = 0
protected

Size of allocated RAM buffer in bytes.

◆ FLAG_PENDING_DOT

constexpr uint8_t SegLCDLib::FLAG_PENDING_DOT = 0x80
staticconstexprprotected

Common flag for decimal handling when RAM offset is 0.

Used when decimal point shares the same RAM byte as the digit. Set when '.' is written, cleared after next character preserves it.


The documentation for this class was generated from the following files: