feat: gestion oled screen #48

Merged
Clement merged 5 commits from feat/oled-screen into master 2023-05-14 07:16:32 +00:00
6 changed files with 161 additions and 0 deletions

View File

@ -14,6 +14,14 @@ build_flags =
-D MONITOR_SPEED=${config.monitor_speed} -D MONITOR_SPEED=${config.monitor_speed}
; DO NOT TOUCH --- END ; DO NOT TOUCH --- END
; taille ecran oled
; 3,3v
-D OLED_WIDTH=128
-D OLED_HEIGHT=64
; pin de reset de l'ecran oled
-D OLED_RESET=-1
; DHT pin and type ; DHT pin and type
; 5v ; 5v
-D DHTTYPE=\"DHT11\" -D DHTTYPE=\"DHT11\"
@ -25,6 +33,7 @@ build_flags =
-D ULTRA_SOUND_ECHO=13 -D ULTRA_SOUND_ECHO=13
; Capteur poids ; Capteur poids
; 3,3v
-D POID_DOUT=14 -D POID_DOUT=14
-D POID_SCK=15 -D POID_SCK=15

View File

@ -10,6 +10,7 @@
#include "Ultrason.h" #include "Ultrason.h"
#include "HumiTemp.h" #include "HumiTemp.h"
#include "Balance.h" #include "Balance.h"
#include "OledScreen.h"
class Program{ class Program{
public: public:
@ -46,6 +47,12 @@ private:
*/ */
Capteur *balance; Capteur *balance;
/**
* @brief OledScreen
*
*/
OledScreen* screen;
/** /**
* @brief Réference de l'API pour les calls * @brief Réference de l'API pour les calls
* *

View File

@ -0,0 +1,59 @@
#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();
/**
* @brief show the sensor value
*
* @param distance length value
* @param poid weith value
* @param humitemp humidity and temperature value
*/
void printVal(String distance, String poid, String humitemp);
private:
Adafruit_SSD1306* display;
};
#endif

View 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();
}

View File

@ -42,6 +42,7 @@ lib_deps =
adafruit/Adafruit Unified Sensor@^1.1.9 ; adafruit sensor lib (required by DHT11) adafruit/Adafruit Unified Sensor@^1.1.9 ; adafruit sensor lib (required by DHT11)
ericksimoes/Ultrasonic@^3.0.0 ; lib capteur ultra son ericksimoes/Ultrasonic@^3.0.0 ; lib capteur ultra son
bogde/HX711@0.7.5 ; lib pour la balance bogde/HX711@0.7.5 ; lib pour la balance
adafruit/Adafruit SSD1306@^2.5.7 ; librairie pour l'ecran oled
; example: ; example:
; erropix/ESP32 AnalogWrite@^0.2 ; erropix/ESP32 AnalogWrite@^0.2

View File

@ -6,6 +6,10 @@ Program::Program(){
Serial1.begin(MONITOR_SPEED); Serial1.begin(MONITOR_SPEED);
Serial.begin(MONITOR_SPEED); Serial.begin(MONITOR_SPEED);
//////Oled Screen/////
this->screen = new OledScreen(OLED_WIDTH, OLED_HEIGHT, OLED_RESET);
this->screen->wifiWaiting();
////////API/////// ////////API///////
this->api = new API(USER_NAME, USER_PASSWORD, API_HOST); this->api = new API(USER_NAME, USER_PASSWORD, API_HOST);
this->api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1); this->api->wifiBegin(WIFI_SSID, WIFI_PASSWORD, &Serial1);
@ -16,12 +20,17 @@ Program::Program(){
this->dht = new HumiTemp(DHTPIN, DHTTYPE, DHT_FULL); this->dht = new HumiTemp(DHTPIN, DHTTYPE, DHT_FULL);
this->balance = new Balance(POID_DOUT,POID_SCK, POID_FULL); this->balance = new Balance(POID_DOUT,POID_SCK, POID_FULL);
this->balance->tar(1077); this->balance->tar(1077);
this->screen->clear();
} }
void Program::loop(){ void Program::loop(){
String distance = this->ultrasonic->read(); String distance = this->ultrasonic->read();
String humitemp = this->dht->read(); String humitemp = this->dht->read();
String poid = this->balance->read(); String poid = this->balance->read();
this->screen->printVal(distance, poid, humitemp);
this->api->sendValue(distance, TRASHCAN_ONE, this->ultrasonic->getValType(), this->ultrasonic->isFull()); this->api->sendValue(distance, TRASHCAN_ONE, this->ultrasonic->getValType(), this->ultrasonic->isFull());
Serial.print("Distance in CM = " + distance); Serial.print("Distance in CM = " + distance);