![]() |
Display_Lib_RPI 2.3.0
A C++ Library to connect electronic displays to Linux single board computers.
|
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 |
class to control Ht16K33 , supports 7 9 14 and 16 segment displays
enum HT16K33plus_Model1::BlinkFreq_e : uint8_t |
enum HT16K33plus_Model1::DecimalPoint_e : uint8_t |
enum HT16K33plus_Model1::DisplayType_e : uint8_t |
enum HT16K33plus_Model1::TextAlignment_e : uint8_t |
HT16K33plus_Model1::HT16K33plus_Model1 | ( | int | I2CDevice, |
int | I2Caddress, | ||
int | I2CFlags | ||
) |
Constructor for class HT16K33plus_Model1.
I2CDevice | An I2C device number. |
I2Caddress | The address of a device on the I2C bus. default is 0x70. |
I2CFlags | Flags which modify an I2C open command. None are currently defined. |
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.
rdlib::Return_Codes_e HT16K33plus_Model1::Display_I2C_OFF | ( | void | ) |
End I2C operations.
rdlib::Return_Codes_e HT16K33plus_Model1::Display_I2C_ON | ( | void | ) |
Switch on the I2C.
rdlib::Return_Codes_e HT16K33plus_Model1::displayChar | ( | uint8_t | digitPosition, |
char | character, | ||
DecimalPoint_e | decimalOnPoint | ||
) |
Displays a single character at the specified digit position.
digitPosition | The position of the digit on the display (0-based index 0 = LHS). |
character | The ASCII character to display. |
decimalOnPoint | Specifies whether the decimal point should be enabled (enumeration DecimalPoint_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.
int HT16K33plus_Model1::DisplayCheckConnection | ( | void | ) |
checks if Display on I2C bus
rdlib::Return_Codes_e HT16K33plus_Model1::displayFloatNum | ( | float | number, |
TextAlignment_e | TextAlignment, | ||
uint8_t | fractionDigits | ||
) |
Displays a floating-point number on the display.
number | The floating-point number to be displayed. |
TextAlignment | Text alignment option (enumeration TextAlignment_e 2 options). |
fractionDigits | Number of fractional digits to display. |
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.
rdlib::Return_Codes_e HT16K33plus_Model1::displayHexChar | ( | uint8_t | position, |
char | hex | ||
) |
Send Hexadecimal value to seven segment.
position | The position on display |
hex | hexadecimal value (DEC) 0-15 (0x00 - 0x0F) |
int HT16K33plus_Model1::DisplayI2CErrorGet | ( | void | ) | const |
get I2C error Flag
See Error Codes at bottom of https://abyz.me.uk/lg/lgpio.html
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
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
AttemptCount | I2C retry attempts |
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
void HT16K33plus_Model1::DisplayI2CErrorTimeoutSet | ( | uint16_t | newTimeout | ) |
Sets the I2C timeout, in the event of an I2C write error.
newTimeout | I2C timeout delay in mS |
Delay between retry attempts in event of an error , mS
void HT16K33plus_Model1::DisplayInit | ( | uint8_t | brightLevel, |
BlinkFreq_e | blinklevel, | ||
uint8_t | numOfDigits, | ||
DisplayType_e | displayType | ||
) |
Initializes the HT16K33 display with specified settings.
brightLevel | Brightness level (0-15). If greater than 15, it defaults to 15. |
blinklevel | Blink frequency setting (enumeration BlinkFreq_e 4 settings). |
numOfDigits | Number of digits to be displayed. |
displayType | Type of display configuration (enumeration DisplayType_e 4 settings). |
rdlib::Return_Codes_e HT16K33plus_Model1::displayIntNum | ( | int32_t | number, |
TextAlignment_e | TextAlignment | ||
) |
Display an integer and leading zeros optional.
number | integer to display 2^32 |
TextAlignment | enum text alignment, left or right alignment or leading zeros |
|
private |
Displays a character on multi-segment displays (9, 14, or 16 segments).
digitPosition | The position of the digit on the display (0-based index, 0=LHS). |
character | The ASCII character to display. |
decimalOnPoint | Specifies whether the decimal point should be enabled (enumeration DecimalPoint_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.
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.
void HT16K33plus_Model1::displayRawData | ( | uint8_t | digitPosition, |
uint16_t | rawData | ||
) |
Sends raw segment data to a specific digit position.
digitPosition | The position of the digit on the display (0-based index). |
rawData | The 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.
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.
rdlib::Return_Codes_e HT16K33plus_Model1::displayText | ( | const char * | text | ) |
Display a text string on display.
text | pointer to a character array |
rdlib::Return_Codes_e HT16K33plus_Model1::displayText | ( | const char * | text, |
TextAlignment_e | TextAlignment | ||
) |
Displays a text string on display.
text | pointer to character array containg text string |
TextAlignment | left or right alignment |
HT16K33plus_Model1::BlinkFreq_e HT16K33plus_Model1::getBlink | ( | ) | const |
Gets the current blink frequency setting.
uint8_t HT16K33plus_Model1::getBrightness | ( | ) | const |
Gets the current brightness level.
HT16K33plus_Model1::DisplayType_e HT16K33plus_Model1::getDisplayType | ( | ) | const |
Gets the display type.
|
private |
Send command byte to display.
cmd | command byte |
|
private |
Send data buffer to via I2C.
data | The data buffer to send |
length | length of data to send |
void HT16K33plus_Model1::setBlink | ( | BlinkFreq_e | blinklevel | ) |
Sets the display blink frequency.
blinklevel | Blink frequency setting (enumeration BlinkFreq_e 4 settings). |
void HT16K33plus_Model1::setBrightness | ( | uint8_t | value | ) |
Sets the display brightness level.
value | Brightness level (0-15). If greater than 15, it defaults to 15. |
|
private |
Blink setting, 4 settings see enum
|
private |
Brightness setting 0-15
|
private |
Enum to hold chosen display type
|
staticconstexprprivate |
last character+1 in defined ASCII table 'z'''
|
staticconstexprprivate |
Offset in the ASCII table for font Start position
|
staticconstexprprivate |
Mask to switch on 14 seg decimal point
|
staticconstexprprivate |
Mask to switch on 7 seg decimal point
|
staticconstexprprivate |
Mask to switch on 9 seg decimal point
|
staticconstexprprivate |
16 Ascii table offset to reach number position
|
private |
I2C delay(in between retry attempts) in event of error in mS
|
private |
In event of I2C error, holds code
|
private |
In event of I2C error number of retry attempts
|
private |
I2C address
|
private |
An I2C device number.
|
private |
Flags which modify an I2C open command. None are currently defined.
|
private |
A number referencing an object opened by one of lgI2cOpen
|
private |
Number of digits in display max 8
|
staticconstexprprivate |
Dimming set register 0-15 XXXX-BBBB
|
staticconstexprprivate |
Display data address pointer
|
staticconstexprprivate |
Display set register Display off
|
staticconstexprprivate |
Display set register Display on
|
staticconstexprprivate |
System setup register turn on System oscillator, normal operation mode
|
staticconstexprprivate |
Turn off System oscillator, standby mode