Display_Lib_RPI 2.3.0
A C++ Library to connect electronic displays to Linux single board computers.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
HT16K33plus_Model1 Class Reference

class to control Ht16K33 , supports 7 9 14 and 16 segment displays More...

#include <HT16K33plus_Model1_RDL.hpp>

Public Types

enum  TextAlignment_e : uint8_t { AlignLeft = 0 , AlignRight = 1 , AlignRightZeros = 2 }
 
enum  BlinkFreq_e : uint8_t { BLINKOFF = 0x81 , BLINKON2HZ = 0x83 , BLINKON1HZ = 0x85 , BLINKON0_5HZ = 0x87 }
 
enum  DecimalPoint_e : uint8_t { DecPointOff = 0 , DecPointOn = 1 }
 
enum  DisplayType_e : uint8_t { SegType7 = 7 , SegType9 = 9 , SegType14 = 14 , SegType16 = 16 }
 

Public Member Functions

 HT16K33plus_Model1 (int I2Cdevice, int I2Caddress, int I2Cflags)
 Constructor for class HT16K33plus_Model1.
 
rdlib::Return_Codes_e Display_I2C_ON (void)
 Switch on the I2C.
 
rdlib::Return_Codes_e Display_I2C_OFF (void)
 End I2C operations.
 
int DisplayCheckConnection (void)
 checks if Display on I2C bus
 
int DisplayI2CErrorGet (void) const
 get I2C error Flag
 
uint16_t DisplayI2CErrorTimeoutGet (void) const
 Gets the I2C timeout, used in the event of an I2C write error.
 
void DisplayI2CErrorTimeoutSet (uint16_t)
 Sets the I2C timeout, in the event of an I2C write error.
 
uint8_t DisplayI2CErrorRetryNumGet (void) const
 Gets the I2C error retry attempts, used in the event of an I2C write error.
 
void DisplayI2CErrorRetryNumSet (uint8_t)
 Sets the I2C error retry attempts used in the event of an I2C write error.
 
void DisplayInit (uint8_t brightLevel, BlinkFreq_e blink, uint8_t numOfDigits, DisplayType_e dtype)
 Initializes the HT16K33 display with specified settings.
 
void DisplayOn (void)
 Turns on the display with the previously set blink setting.
 
void DisplayOff (void)
 Turns off the display.
 
void DisplaySleep (void)
 Puts the display into standby mode. Turn off System oscillator.
 
void DisplayNormal (void)
 Restores the display to normal operation mode. Turn on System oscillator.
 
void DisplayResetDefault (void)
 Resets the display to default settings.
 
void setBrightness (uint8_t value)
 Sets the display brightness level.
 
uint8_t getBrightness () const
 Gets the current brightness level.
 
void setBlink (BlinkFreq_e value)
 Sets the display blink frequency.
 
BlinkFreq_e getBlink () const
 Gets the current blink frequency setting.
 
DisplayType_e getDisplayType () const
 Gets the display type.
 
void ClearDigits (void)
 Clears all digits on the display.
 
void displayRawData (uint8_t digitPos, uint16_t value)
 Sends raw segment data to a specific digit position.
 
rdlib::Return_Codes_e displayChar (uint8_t digitPos, char c, DecimalPoint_e dp)
 Displays a single character at the specified digit position.
 
rdlib::Return_Codes_e displayText (const char *text, TextAlignment_e TextAlignment)
 Displays a text string on display.
 
rdlib::Return_Codes_e displayText (const char *text)
 Display a text string on display.
 
rdlib::Return_Codes_e displayHexChar (uint8_t digitPos, char hex)
 Send Hexadecimal value to seven segment.
 
rdlib::Return_Codes_e displayIntNum (int32_t number, TextAlignment_e TextAlignment)
 Display an integer and leading zeros optional.
 
rdlib::Return_Codes_e displayFloatNum (float number, TextAlignment_e TextAlignment, uint8_t fractionDigits)
 Displays a floating-point number on the display.
 

Private Member Functions

rdlib::Return_Codes_e displayMultiSegNum (uint8_t digitPos, char c, DecimalPoint_e dp)
 Displays a character on multi-segment displays (9, 14, or 16 segments).
 
void SendCmd (uint8_t cmd)
 Send command byte to display.
 
void SendData (const unsigned char *data, size_t length)
 Send data buffer to via I2C.
 

Private Attributes

int _I2CAddress = 0x70
 
int _I2CDevice = 1
 
int _I2CFlags = 0
 
int _I2CHandle = 0
 
uint16_t _I2C_ErrorDelay = 100
 
uint8_t _I2C_ErrorRetryNum = 3
 
int _I2C_ErrorFlag = 0
 
BlinkFreq_e _blinkSetting = BLINKOFF
 
DisplayType_e _displayType = SegType7
 
uint8_t _brightness = 7
 
uint8_t _numOfDigits = 4
 

Static Private Attributes

static constexpr uint8_t HT16K33_DDAPTR = 0x00
 
static constexpr uint8_t HT16K33_NORMAL = 0x21
 
static constexpr uint8_t HT16K33_STANDBY = 0x20
 
static constexpr uint8_t HT16K33_DISPLAYON = 0x81
 
static constexpr uint8_t HT16K33_DISPLAYOFF = 0x80
 
static constexpr uint8_t HT16K33_BRIGHTNESS = 0xE0
 
static constexpr uint8_t _HT_ASCIIOffset = 0x20
 
static constexpr uint8_t _HT_HEXoffset = 0x10
 
static constexpr uint8_t _HT_ASCIIEnd = 0x7B
 
static constexpr uint8_t _HT_DEC_POINT_7_MASK = 0x80
 
static constexpr uint16_t _HT_DEC_POINT_9_MASK = 0x0200
 
static constexpr uint16_t _HT_DEC_POINT_14_MASK = 0x4000
 

Detailed Description

class to control Ht16K33 , supports 7 9 14 and 16 segment displays

Member Enumeration Documentation

◆ BlinkFreq_e

Display blinking frequency XXXX-XB1B0X settings Display register D10 D9 -> (B1, B0)

Enumerator
BLINKOFF 

Blinking off

BLINKON2HZ 

2 Hertz

BLINKON1HZ 

1 Hertz

BLINKON0_5HZ 

0.5 Hertz

◆ DecimalPoint_e

Activate Decimal point segment

Enumerator
DecPointOff 

Decimal point segment off

DecPointOn 

Decimal point segment on

◆ DisplayType_e

The Display Type

Enumerator
SegType7 

7 segment display

SegType9 

9 segment display

SegType14 

14 segment display

SegType16 

16 segment display

◆ TextAlignment_e

Alignment of text on display

Enumerator
AlignLeft 

Align text to the left on display

AlignRight 

Align text to the right on display

AlignRightZeros 

Add leading zeros to the text

Constructor & Destructor Documentation

◆ HT16K33plus_Model1()

HT16K33plus_Model1::HT16K33plus_Model1 ( int  I2CDevice,
int  I2Caddress,
int  I2CFlags 
)

Constructor for class HT16K33plus_Model1.

Parameters
I2CDeviceAn I2C device number.
I2CaddressThe address of a device on the I2C bus. default is 0x70.
I2CFlagsFlags which modify an I2C open command. None are currently defined.

Member Function Documentation

◆ ClearDigits()

void HT16K33plus_Model1::ClearDigits ( void  )

Clears all digits on the display.

Iterates through all digit positions and replaces each character with a blank space. The decimal points are also turned off.

◆ Display_I2C_OFF()

rdlib::Return_Codes_e HT16K33plus_Model1::Display_I2C_OFF ( void  )

End I2C operations.

Returns
error for failure to close a I2C bus device
  1. rdlib::Success
  2. rdlib::I2CcloseFail

◆ Display_I2C_ON()

rdlib::Return_Codes_e HT16K33plus_Model1::Display_I2C_ON ( void  )

Switch on the I2C.

Note
Start I2C operations.
Returns
error for failure to init a I2C bus
  1. rdlib::Success
  2. rdlib::I2CbeginFail

◆ displayChar()

rdlib::Return_Codes_e HT16K33plus_Model1::displayChar ( uint8_t  digitPosition,
char  character,
DecimalPoint_e  decimalOnPoint 
)

Displays a single character at the specified digit position.

Parameters
digitPositionThe position of the digit on the display (0-based index 0 = LHS).
characterThe ASCII character to display.
decimalOnPointSpecifies whether the decimal point should be enabled (enumeration DecimalPoint_e).
Returns
Return code indicating success or an error (enumeration rdlib::Return_Codes_e).

If the character is out of the supported ASCII font range, an error is logged and a corresponding error code is returned. If the display type is not 7-segment, the function delegates to displayMultiSegNum(). Otherwise, the function retrieves the 7-segment font data, applies the decimal point if needed, and sends the data to the display.

◆ DisplayCheckConnection()

int HT16K33plus_Model1::DisplayCheckConnection ( void  )

checks if Display on I2C bus

Returns
lg Error codes, LG_OKAY 0x00 = Success
Note
Error codes are here https://abyz.me.uk/lg/lgpio.html prints error code text to console

◆ displayFloatNum()

rdlib::Return_Codes_e HT16K33plus_Model1::displayFloatNum ( float  number,
TextAlignment_e  TextAlignment,
uint8_t  fractionDigits 
)

Displays a floating-point number on the display.

Parameters
numberThe floating-point number to be displayed.
TextAlignmentText alignment option (enumeration TextAlignment_e 2 options).
fractionDigitsNumber of fractional digits to display.
Returns
Return code indicating success or an error (enumeration rdlib::Return_Codes_e).

Converts the floating-point number into a formatted string and displays it on the device. If the total number of required digits (integer + fractional + sign) exceeds the available display space, an error is returned. Leading zero alignment is not supported.

◆ displayHexChar()

rdlib::Return_Codes_e HT16K33plus_Model1::displayHexChar ( uint8_t  position,
char  hex 
)

Send Hexadecimal value to seven segment.

Parameters
positionThe position on display
hexhexadecimal value (DEC) 0-15 (0x00 - 0x0F)
Returns
Will return an error if not hexadecimal.

◆ DisplayI2CErrorGet()

int HT16K33plus_Model1::DisplayI2CErrorGet ( void  ) const

get I2C error Flag

See Error Codes at bottom of https://abyz.me.uk/lg/lgpio.html

Returns
I2C error flag

◆ DisplayI2CErrorRetryNumGet()

uint8_t HT16K33plus_Model1::DisplayI2CErrorRetryNumGet ( void  ) const

Gets the I2C error retry attempts, used in the event of an I2C write error.

Number of times to retry in event of an error

Returns
_I2C_ErrorRetryNum

◆ DisplayI2CErrorRetryNumSet()

void HT16K33plus_Model1::DisplayI2CErrorRetryNumSet ( uint8_t  AttemptCount)

Sets the I2C error retry attempts used in the event of an I2C write error.

Number of times to retry in event of an error

Parameters
AttemptCountI2C retry attempts

◆ DisplayI2CErrorTimeoutGet()

uint16_t HT16K33plus_Model1::DisplayI2CErrorTimeoutGet ( void  ) const

Gets the I2C timeout, used in the event of an I2C write error.

Delay between retry attempts in event of an error , mS

Returns
I2C timeout delay in mS, _I2C_ErrorDelay

◆ DisplayI2CErrorTimeoutSet()

void HT16K33plus_Model1::DisplayI2CErrorTimeoutSet ( uint16_t  newTimeout)

Sets the I2C timeout, in the event of an I2C write error.

Parameters
newTimeoutI2C timeout delay in mS

Delay between retry attempts in event of an error , mS

◆ DisplayInit()

void HT16K33plus_Model1::DisplayInit ( uint8_t  brightLevel,
BlinkFreq_e  blinklevel,
uint8_t  numOfDigits,
DisplayType_e  displayType 
)

Initializes the HT16K33 display with specified settings.

Parameters
brightLevelBrightness level (0-15). If greater than 15, it defaults to 15.
blinklevelBlink frequency setting (enumeration BlinkFreq_e 4 settings).
numOfDigitsNumber of digits to be displayed.
displayTypeType of display configuration (enumeration DisplayType_e 4 settings).

◆ displayIntNum()

rdlib::Return_Codes_e HT16K33plus_Model1::displayIntNum ( int32_t  number,
TextAlignment_e  TextAlignment 
)

Display an integer and leading zeros optional.

Parameters
numberinteger to display 2^32
TextAlignmentenum text alignment, left or right alignment or leading zeros
Returns
will return error user tries to display if too much data

◆ displayMultiSegNum()

rdlib::Return_Codes_e HT16K33plus_Model1::displayMultiSegNum ( uint8_t  digitPosition,
char  character,
DecimalPoint_e  decimalOnPoint 
)
private

Displays a character on multi-segment displays (9, 14, or 16 segments).

Parameters
digitPositionThe position of the digit on the display (0-based index, 0=LHS).
characterThe ASCII character to display.
decimalOnPointSpecifies whether the decimal point should be enabled (enumeration DecimalPoint_e).
Returns
Return code indicating success or an error (enumeration rdlib::Return_Codes_e).

Converts the ASCII character into the appropriate segment mapping for the display type (9-segment, 14-segment, or 16-segment). The decimal point is applied if applicable. The processed data is then sent to the display.

◆ DisplayOn()

void HT16K33plus_Model1::DisplayOn ( void  )

Turns on the display with the previously set blink setting.

Sends the command to enable the display, using the stored blink setting.

◆ displayRawData()

void HT16K33plus_Model1::displayRawData ( uint8_t  digitPosition,
uint16_t  rawData 
)

Sends raw segment data to a specific digit position.

Parameters
digitPositionThe position of the digit on the display (0-based index).
rawDataThe raw segment data to be displayed (bit-mapped for the display type).

This function allows direct control of the display segments by sending raw data. The rawData value is split into two bytes and transmitted to the display.

◆ DisplayResetDefault()

void HT16K33plus_Model1::DisplayResetDefault ( void  )

Resets the display to default settings.

This function restores normal operation mode, sets brightness to a default level of 7, and turns the display on with the stored blink setting.

◆ displayText() [1/2]

rdlib::Return_Codes_e HT16K33plus_Model1::displayText ( const char *  text)

Display a text string on display.

Parameters
textpointer to a character array
Returns
error code if string is nullptr or too long
Note
Dots are removed from string and dot on preceding digit switched on "abc.def" will be shown as "abcdef" with c decimal point turned on, Unless the Display is sixteen segment.

◆ displayText() [2/2]

rdlib::Return_Codes_e HT16K33plus_Model1::displayText ( const char *  text,
TextAlignment_e  TextAlignment 
)

Displays a text string on display.

Parameters
textpointer to character array containg text string
TextAlignmentleft or right alignment
Note
This method is overloaded, see also DisplayText(char *) leading zeros is not currently an option as a workaround user can add them to string before hand.
Returns
WIll return error for null pointer string or leading zeros option requested

◆ getBlink()

HT16K33plus_Model1::BlinkFreq_e HT16K33plus_Model1::getBlink ( ) const

Gets the current blink frequency setting.

Returns
The current blink frequency (enumeration BlinkFreq_e).

◆ getBrightness()

uint8_t HT16K33plus_Model1::getBrightness ( ) const

Gets the current brightness level.

Returns
The current brightness level (0-15).

◆ getDisplayType()

HT16K33plus_Model1::DisplayType_e HT16K33plus_Model1::getDisplayType ( ) const

Gets the display type.

Returns
The current display type setting (enumeration DisplayType_e).

◆ SendCmd()

void HT16K33plus_Model1::SendCmd ( uint8_t  cmd)
private

Send command byte to display.

Parameters
cmdcommand byte
Note
if debug flag == true ,will output data on I2C failures.

◆ SendData()

void HT16K33plus_Model1::SendData ( const unsigned char *  data,
size_t  length 
)
private

Send data buffer to via I2C.

Parameters
dataThe data buffer to send
lengthlength of data to send
Note
if debug flag is true, will output data on I2C failures.

◆ setBlink()

void HT16K33plus_Model1::setBlink ( BlinkFreq_e  blinklevel)

Sets the display blink frequency.

Parameters
blinklevelBlink frequency setting (enumeration BlinkFreq_e 4 settings).

◆ setBrightness()

void HT16K33plus_Model1::setBrightness ( uint8_t  value)

Sets the display brightness level.

Parameters
valueBrightness level (0-15). If greater than 15, it defaults to 15.

Member Data Documentation

◆ _blinkSetting

BlinkFreq_e HT16K33plus_Model1::_blinkSetting = BLINKOFF
private

Blink setting, 4 settings see enum

◆ _brightness

uint8_t HT16K33plus_Model1::_brightness = 7
private

Brightness setting 0-15

◆ _displayType

DisplayType_e HT16K33plus_Model1::_displayType = SegType7
private

Enum to hold chosen display type

◆ _HT_ASCIIEnd

constexpr uint8_t HT16K33plus_Model1::_HT_ASCIIEnd = 0x7B
staticconstexprprivate

last character+1 in defined ASCII table 'z'''

◆ _HT_ASCIIOffset

constexpr uint8_t HT16K33plus_Model1::_HT_ASCIIOffset = 0x20
staticconstexprprivate

Offset in the ASCII table for font Start position

◆ _HT_DEC_POINT_14_MASK

constexpr uint16_t HT16K33plus_Model1::_HT_DEC_POINT_14_MASK = 0x4000
staticconstexprprivate

Mask to switch on 14 seg decimal point

◆ _HT_DEC_POINT_7_MASK

constexpr uint8_t HT16K33plus_Model1::_HT_DEC_POINT_7_MASK = 0x80
staticconstexprprivate

Mask to switch on 7 seg decimal point

◆ _HT_DEC_POINT_9_MASK

constexpr uint16_t HT16K33plus_Model1::_HT_DEC_POINT_9_MASK = 0x0200
staticconstexprprivate

Mask to switch on 9 seg decimal point

◆ _HT_HEXoffset

constexpr uint8_t HT16K33plus_Model1::_HT_HEXoffset = 0x10
staticconstexprprivate

16 Ascii table offset to reach number position

◆ _I2C_ErrorDelay

uint16_t HT16K33plus_Model1::_I2C_ErrorDelay = 100
private

I2C delay(in between retry attempts) in event of error in mS

◆ _I2C_ErrorFlag

int HT16K33plus_Model1::_I2C_ErrorFlag = 0
private

In event of I2C error, holds code

◆ _I2C_ErrorRetryNum

uint8_t HT16K33plus_Model1::_I2C_ErrorRetryNum = 3
private

In event of I2C error number of retry attempts

◆ _I2CAddress

int HT16K33plus_Model1::_I2CAddress = 0x70
private

I2C address

◆ _I2CDevice

int HT16K33plus_Model1::_I2CDevice = 1
private

An I2C device number.

◆ _I2CFlags

int HT16K33plus_Model1::_I2CFlags = 0
private

Flags which modify an I2C open command. None are currently defined.

◆ _I2CHandle

int HT16K33plus_Model1::_I2CHandle = 0
private

A number referencing an object opened by one of lgI2cOpen

◆ _numOfDigits

uint8_t HT16K33plus_Model1::_numOfDigits = 4
private

Number of digits in display max 8

◆ HT16K33_BRIGHTNESS

constexpr uint8_t HT16K33plus_Model1::HT16K33_BRIGHTNESS = 0xE0
staticconstexprprivate

Dimming set register 0-15 XXXX-BBBB

◆ HT16K33_DDAPTR

constexpr uint8_t HT16K33plus_Model1::HT16K33_DDAPTR = 0x00
staticconstexprprivate

Display data address pointer

◆ HT16K33_DISPLAYOFF

constexpr uint8_t HT16K33plus_Model1::HT16K33_DISPLAYOFF = 0x80
staticconstexprprivate

Display set register Display off

◆ HT16K33_DISPLAYON

constexpr uint8_t HT16K33plus_Model1::HT16K33_DISPLAYON = 0x81
staticconstexprprivate

Display set register Display on

◆ HT16K33_NORMAL

constexpr uint8_t HT16K33plus_Model1::HT16K33_NORMAL = 0x21
staticconstexprprivate

System setup register turn on System oscillator, normal operation mode

◆ HT16K33_STANDBY

constexpr uint8_t HT16K33plus_Model1::HT16K33_STANDBY = 0x20
staticconstexprprivate

Turn off System oscillator, standby mode


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