Add DisplayLib for OLED display management and enhance motor control with rotation methods
This commit is contained in:
parent
4841dc4317
commit
5d0a067fba
6 changed files with 207 additions and 21 deletions
67
lib/display/DisplayLib.cpp
Normal file
67
lib/display/DisplayLib.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
#include "DisplayLib.hpp"
|
||||
|
||||
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
|
||||
|
||||
void DisplayLib::updateDisplay(const char* title, const char* detail) {
|
||||
u8g2.clearBuffer();
|
||||
u8g2.setFont(u8g2_font_ncenB08_tr);
|
||||
u8g2.drawStr(0, 10, title);
|
||||
u8g2.setFont(u8g2_font_ncenB08_tr);
|
||||
u8g2.drawStr(0, 30, detail);
|
||||
u8g2.sendBuffer();
|
||||
}
|
||||
|
||||
void DisplayLib::welcomeScreen() {
|
||||
u8g2.clearBuffer();
|
||||
u8g2.setFont(u8g2_font_ncenB08_tr);
|
||||
u8g2.drawStr(0, 10, "Welcome to");
|
||||
u8g2.setFont(u8g2_font_ncenB08_tr);
|
||||
u8g2.drawStr(0, 30, "Elbestia");
|
||||
u8g2.sendBuffer();
|
||||
}
|
||||
|
||||
void DisplayLib::clearDisplay() {
|
||||
u8g2.clearBuffer();
|
||||
u8g2.sendBuffer();
|
||||
}
|
||||
|
||||
void DisplayLib::initDisplay() {
|
||||
u8g2.begin();
|
||||
u8g2.enableUTF8Print();
|
||||
u8g2.setFont(u8g2_font_ncenB08_tr);
|
||||
u8g2.clearBuffer();
|
||||
u8g2.sendBuffer();
|
||||
}
|
||||
|
||||
void DisplayLib::displayError(const char* error) {
|
||||
u8g2.clearBuffer();
|
||||
u8g2.setFont(u8g2_font_ncenB08_tr);
|
||||
u8g2.drawStr(0, 10, "Error:");
|
||||
u8g2.setFont(u8g2_font_ncenB08_tr);
|
||||
u8g2.drawStr(0, 30, error);
|
||||
u8g2.sendBuffer();
|
||||
}
|
||||
|
||||
void DisplayLib::displayMessage(const char* message) {
|
||||
u8g2.clearBuffer();
|
||||
u8g2.setFont(u8g2_font_ncenB08_tr);
|
||||
u8g2.drawStr(0, 10, message);
|
||||
u8g2.sendBuffer();
|
||||
}
|
||||
|
||||
void DisplayLib::printMessage(const char* message, int x, int y) {
|
||||
u8g2.clearBuffer();
|
||||
u8g2.setFont(u8g2_font_ncenB08_tr);
|
||||
u8g2.drawStr(x, y, message);
|
||||
u8g2.sendBuffer();
|
||||
}
|
||||
|
||||
void DisplayLib::printMessage(const String message, int x, int y) {
|
||||
u8g2.clearBuffer();
|
||||
u8g2.setFont(u8g2_font_ncenB08_tr);
|
||||
u8g2.drawStr(x, y, message.c_str());
|
||||
}
|
||||
|
||||
void DisplayLib::sendBuffer() {
|
||||
u8g2.sendBuffer();
|
||||
}
|
21
lib/display/DisplayLib.hpp
Normal file
21
lib/display/DisplayLib.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef DISPLAYLIB_HPP
|
||||
#define DISPLAYLIB_HPP
|
||||
|
||||
#include <U8g2lib.h>
|
||||
|
||||
class DisplayLib {
|
||||
public:
|
||||
void updateDisplay(const char* title, const char* detail);
|
||||
void welcomeScreen();
|
||||
void clearDisplay();
|
||||
void initDisplay();
|
||||
void displayError(const char* error);
|
||||
void displayMessage(const char* message);
|
||||
void printMessage(const char* message, int x, int y);
|
||||
void printMessage(const char* message, int x, int y, int size);
|
||||
void printMessage(const String message, int x, int y);
|
||||
void printMessage(const String message, int x, int y, int size);
|
||||
void sendBuffer();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue