feat: add oled screen lib
This commit is contained in:
parent
ddefd7e15f
commit
d814d16733
53
IOT/lib/OledScreen/include/OledScreen.h
Normal file
53
IOT/lib/OledScreen/include/OledScreen.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#ifndef OLED_SCREEN_H
|
||||||
|
#define OLED_SCREEN_H
|
||||||
|
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
|
||||||
|
|
||||||
|
class OledScreen {
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Oled Screen object
|
||||||
|
*
|
||||||
|
* @param screenWidth The width of the screen
|
||||||
|
* @param screenHeight The height of the screen
|
||||||
|
* @param oledResetPin The pin used to reset the screen (default: -1)
|
||||||
|
*/
|
||||||
|
OledScreen(int screenWidth, int screenHeight, int oledResetPin = -1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief display welcome screen
|
||||||
|
*/
|
||||||
|
void welcome();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief print the total amount on the screen
|
||||||
|
*
|
||||||
|
* @param amount The total amount to print in centimes
|
||||||
|
*/
|
||||||
|
void printAmount(int amount);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clear the screen
|
||||||
|
*/
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief messsage for wifi waiting
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void wifiWaiting();
|
||||||
|
|
||||||
|
|
||||||
|
void printVal(String distance, String poid, String humitemp);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Adafruit_SSD1306* display;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
76
IOT/lib/OledScreen/src/OledScreeen.cpp
Normal file
76
IOT/lib/OledScreen/src/OledScreeen.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#include "../include/OledScreen.h"
|
||||||
|
|
||||||
|
OledScreen::OledScreen(int screenWidth, int screenHeight, int oledResetPin) {
|
||||||
|
this->display = new Adafruit_SSD1306(screenWidth, screenHeight, &Wire, oledResetPin);
|
||||||
|
if (!display->begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
|
||||||
|
Serial.println(F("SSD1306 allocation failed"));
|
||||||
|
for (;;); // Don't proceed, loop forever
|
||||||
|
}
|
||||||
|
this->display->clearDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OledScreen::welcome() {
|
||||||
|
this->display->clearDisplay();
|
||||||
|
this->display->setCursor(0, 0);
|
||||||
|
this->display->setTextSize(2);
|
||||||
|
this->display->setTextColor(WHITE);
|
||||||
|
this->display->println(F("\nBienvenue!"));
|
||||||
|
this->display->display();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OledScreen::printVal(String distance, String poid, String humitemp){
|
||||||
|
this->display->clearDisplay();
|
||||||
|
this->display->setCursor(0, 0);
|
||||||
|
this->display->setTextSize(2);
|
||||||
|
this->display->setTextColor(WHITE);
|
||||||
|
this->display->print(F("Dist:"));
|
||||||
|
this->display->print(distance);
|
||||||
|
this->display->println();
|
||||||
|
this->display->print(F("Poids:"));
|
||||||
|
this->display->print(poid);
|
||||||
|
this->display->println();
|
||||||
|
this->display->print(F("humi:"));
|
||||||
|
this->display->print(humitemp.substring(0,humitemp.indexOf("/")));
|
||||||
|
this->display->println();
|
||||||
|
this->display->print(F("temp:"));
|
||||||
|
this->display->print(humitemp.substring(humitemp.indexOf("/")+1,humitemp.length()));
|
||||||
|
this->display->println();
|
||||||
|
this->display->display();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void OledScreen::printAmount(int amount) {
|
||||||
|
this->display->clearDisplay();
|
||||||
|
this->display->setCursor(0, 0);
|
||||||
|
this->display->setTextSize(2);
|
||||||
|
this->display->setTextColor(WHITE);
|
||||||
|
this->display->println(F(" Total: "));
|
||||||
|
this->display->println();
|
||||||
|
|
||||||
|
this->display->print(amount / 100);
|
||||||
|
this->display->print(F(","));
|
||||||
|
int centimes = amount % 100;
|
||||||
|
if (centimes < 10) {
|
||||||
|
this->display->print(F("0"));
|
||||||
|
}
|
||||||
|
this->display->println(centimes);
|
||||||
|
this->display->print(F(" EUR"));
|
||||||
|
this->display->display();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OledScreen::wifiWaiting() {
|
||||||
|
this->clear();
|
||||||
|
this->display->setCursor(0, 0);
|
||||||
|
this->display->setTextSize(2);
|
||||||
|
this->display->setTextColor(WHITE);
|
||||||
|
this->display->println(F("Connection\n"));
|
||||||
|
this->display->println(F(" WiFi...\n"));
|
||||||
|
this->display->println();
|
||||||
|
this->display->display();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OledScreen::clear() {
|
||||||
|
this->display->clearDisplay();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user