FEATURE: converted driver into singleton (only one display possible and necessary)

This commit is contained in:
Robin Dietzel 2022-12-09 16:31:23 +01:00
parent ece7ecf905
commit e019c23620
2 changed files with 22 additions and 4 deletions

View File

@ -11,9 +11,24 @@ namespace floatpump{
class LCD_I2C_Driver {
private:
LCD_I2C_Driver(I2C_HandleTypeDef &handle, uint16_t displayAddr);
// Disable following constructors
LCD_I2C_Driver(LCD_I2C_Driver const&);
void operator=(LCD_I2C_Driver const&);
public:
LCD_I2C_Driver(I2C_HandleTypeDef &handle, uint16_t displayAddr, uint8_t rows = 4, uint8_t cols = 20)
: m_handle(handle), m_displayAddr(displayAddr) {};
static LCD_I2C_Driver& getInstance(I2C_HandleTypeDef &handle, uint16_t displayAddr)
{
static LCD_I2C_Driver instance(handle, (uint16_t) displayAddr);
return instance;
}
public:
//TODO: fix this
//LCD_I2C_Driver(LCD_I2C_Driver const&) = delete;
//void operator=(LCD_I2C_Driver const&) = delete;
// Functions sending text
void LCDSendCString(char *str);
@ -59,7 +74,6 @@ namespace floatpump{
void m_lcdSendCmnd(char cmnd);
};
} // floatpump
#endif //FLOATPUMP_LCD_I2C_DRIVER_H

View File

@ -39,7 +39,11 @@ namespace floatpump {
HAL_I2C_Master_Transmit(&m_handle, m_displayAddr, (uint8_t *) data_t, 4, 100);
}
void LCD_I2C_Driver::LCDInitialize() {
LCD_I2C_Driver::LCD_I2C_Driver(I2C_HandleTypeDef &handle, uint16_t displayAddr) {
m_handle = handle;
m_displayAddr = displayAddr;
// Initialization by Instruction (from HD44780U Datasheet)
HAL_Delay(50); // wait for >40ms
m_lcdSendCmnd(0x30);