/** * @file displayWrapper.cpp * @author Alexander Klein (alex@kleiax.de) * @brief Contains the implementation of the class LcdWrapper * @version 0.1 * @date 2023-01-08 * * @copyright Copyright (c) 2023 * */ #include "LcdWrapper.h" LcdWrapper::LcdWrapper(LiquidCrystal_I2C* lcd) { this->lcd = lcd; this->clear(); this->changed = false; } void LcdWrapper::run() { if (!this->changed) return; this->lcd->clear(); for (uint8_t i = 0; i < LcdWrapper::totalLines; i++) { this->lcd->setCursor(0, i); this->lcd->print(this->data[i]); } if (this->callback) this->callback(this->data, LcdWrapper::totalLines, LcdWrapper::totalRows); this->changed = false; } void LcdWrapper::clear() { for (uint8_t i = 0; i < LcdWrapper::totalLines; i++) { for (uint8_t j = 0; j < LcdWrapper::totalRows; j++) { data[i][j] = ' '; } } this->changed = true; } void LcdWrapper::setCursor(uint8_t row, uint8_t line) { if (row > LcdWrapper::totalRows - 1) row = LcdWrapper::totalRows - 1; if (line > LcdWrapper::totalLines - 1) line = LcdWrapper::totalLines - 1; this->cursorRow = row; this->cursorLine = line; } void LcdWrapper::print(const char *str) { uint8_t inputStringPosition = 0; for (uint8_t i = this->cursorRow; i < LcdWrapper::totalRows; i++) { if (str[inputStringPosition] == '\0') break; else this->data[this->cursorLine][i] = str[inputStringPosition]; inputStringPosition++; } this->changed = true; }