moved menu lib to git server
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* @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::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 LcdWrapper::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 LcdWrapper::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 LcdWrapper::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;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* @file displayWrapper.h
|
||||
* @author Alexander Klein (alex@kleiax.de)
|
||||
* @brief Contains the LcdWrapper class
|
||||
* @version 0.1
|
||||
* @date 2023-01-08
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LCD_WRAPPER_H
|
||||
#define LCD_WRAPPER_H
|
||||
|
||||
#include <iostream>
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
#include <displayWrapper.h>
|
||||
|
||||
#define DISPLAY_WRAPPER_ROWS 16
|
||||
#define DISPLAY_WRAPPER_LINES 2
|
||||
|
||||
/**
|
||||
* @brief A class for the Menu class to print information
|
||||
*
|
||||
* This class inherits the DisplayWrapper class as a interface.
|
||||
* The class takes the information to print from any thread. The
|
||||
* loop function has to be called to print the data.
|
||||
*/
|
||||
class LcdWrapper : public DisplayWrapper {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new Lcd Wrapper object
|
||||
*
|
||||
* @param lcd
|
||||
*/
|
||||
LcdWrapper(LiquidCrystal_I2C* lcd);
|
||||
|
||||
/**
|
||||
* @brief Print the saved data
|
||||
*
|
||||
*/
|
||||
void loop();
|
||||
|
||||
/**
|
||||
* @brief Empty the buffer
|
||||
*
|
||||
*/
|
||||
void clear() override;
|
||||
|
||||
/**
|
||||
* @brief Set point where data to be saved
|
||||
*
|
||||
* @param row
|
||||
* @param line
|
||||
*/
|
||||
void setCursor(uint8_t row, uint8_t line) override;
|
||||
|
||||
/**
|
||||
* @brief Save the data to be printed
|
||||
*
|
||||
* @param str
|
||||
*/
|
||||
void print(const char *str) override;
|
||||
|
||||
|
||||
private:
|
||||
LiquidCrystal_I2C* lcd;
|
||||
char data[DISPLAY_WRAPPER_LINES][DISPLAY_WRAPPER_ROWS];
|
||||
|
||||
uint8_t cursorRow = 0;
|
||||
uint8_t cursorLine = 0;
|
||||
|
||||
bool changed = false;
|
||||
};
|
||||
|
||||
#endif // DISPLAY_WRAPPER_H
|
||||
Reference in New Issue
Block a user