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