feat: add display of counter value
This commit is contained in:
parent
9766a15a3a
commit
d6712d80d6
5 changed files with 115 additions and 8 deletions
57
lib/GazDisplay/GazDisplay.cpp
Normal file
57
lib/GazDisplay/GazDisplay.cpp
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
#include "GazDisplay.h"
|
||||||
|
|
||||||
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST);
|
||||||
|
|
||||||
|
DisplayError displayInit()
|
||||||
|
{
|
||||||
|
if (OLED_RST >= 0)
|
||||||
|
{
|
||||||
|
pinMode(OLED_RST, OUTPUT);
|
||||||
|
digitalWrite(OLED_RST, LOW);
|
||||||
|
delay(20);
|
||||||
|
digitalWrite(OLED_RST, HIGH);
|
||||||
|
}
|
||||||
|
Wire.begin(OLED_SDA, OLED_SCL);
|
||||||
|
|
||||||
|
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
|
||||||
|
{
|
||||||
|
Serial.println("[OLED] Ecran non détecté !");
|
||||||
|
return DisplayError::INIT_FAILED;
|
||||||
|
}
|
||||||
|
display.clearDisplay();
|
||||||
|
display.display();
|
||||||
|
|
||||||
|
return DisplayError::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayGasIndex(uint32_t pulses)
|
||||||
|
{
|
||||||
|
float indexM3 = pulses * 0.010f;
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
|
||||||
|
// Titre
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setTextColor(SSD1306_WHITE);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.println("Index gaz");
|
||||||
|
|
||||||
|
// Ligne
|
||||||
|
display.drawLine(0, 10, 128, 10, SSD1306_WHITE);
|
||||||
|
|
||||||
|
// Valeur en grand
|
||||||
|
display.setTextSize(2);
|
||||||
|
display.setCursor(0, 18);
|
||||||
|
display.printf("%.3f", indexM3);
|
||||||
|
|
||||||
|
// Unité
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setCursor(112, 25);
|
||||||
|
display.println("m3");
|
||||||
|
|
||||||
|
// Impulsions en petit
|
||||||
|
display.setCursor(0, 54);
|
||||||
|
display.printf("Impulsions : %lu", pulses);
|
||||||
|
|
||||||
|
display.display();
|
||||||
|
}
|
||||||
21
lib/GazDisplay/GazDisplay.h
Normal file
21
lib/GazDisplay/GazDisplay.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
|
||||||
|
#define OLED_SDA 21
|
||||||
|
#define OLED_SCL 22
|
||||||
|
#define OLED_RST -1
|
||||||
|
|
||||||
|
#define SCREEN_WIDTH 128
|
||||||
|
#define SCREEN_HEIGHT 64
|
||||||
|
|
||||||
|
enum class DisplayError : int16_t {
|
||||||
|
OK = 0,
|
||||||
|
INIT_FAILED = -1
|
||||||
|
};
|
||||||
|
|
||||||
|
void displayInit();
|
||||||
|
void displayGasIndex(uint32_t pulses);
|
||||||
|
|
||||||
|
|
@ -19,4 +19,7 @@ build_flags =
|
||||||
-DT3_V1_6_SX1276
|
-DT3_V1_6_SX1276
|
||||||
|
|
||||||
lib_deps =
|
lib_deps =
|
||||||
|
adafruit/Adafruit SSD1306 @ ^2.5.15
|
||||||
|
adafruit/Adafruit GFX Library @ ^1.12.1
|
||||||
|
adafruit/Adafruit BusIO @ ^1.16.3
|
||||||
jgromes/RadioLib@6.6.0
|
jgromes/RadioLib@6.6.0
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define MAX_RESTART 3
|
#define MAX_RESTART 1
|
||||||
|
#define MAX_FATAL_RESTART 3
|
||||||
|
|
||||||
uint64_t joinEUI = 0x35f48318e1324e2e;
|
uint64_t joinEUI = 0x35f48318e1324e2e;
|
||||||
uint64_t devEUI = 0x0586fe41112d83d9;
|
uint64_t devEUI = 0x0586fe41112d83d9;
|
||||||
|
|
|
||||||
39
src/main.cpp
39
src/main.cpp
|
|
@ -1,8 +1,10 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <LoRaTransmitter.h>
|
#include <LoRaTransmitter.h>
|
||||||
#include <SimuGaz.h>
|
#include <SimuGaz.h>
|
||||||
|
#include <GazDisplay.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
RTC_DATA_ATTR uint8_t fatalRestartCount = 0;
|
||||||
RTC_DATA_ATTR uint8_t restartCount = 0;
|
RTC_DATA_ATTR uint8_t restartCount = 0;
|
||||||
|
|
||||||
ITransmitter* transmitter = new LoRaTransmitter(
|
ITransmitter* transmitter = new LoRaTransmitter(
|
||||||
|
|
@ -17,21 +19,34 @@ void fatalError(const char* msg){
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
if (restartCount < MAX_RESTART) {
|
if (fatalRestartCount < MAX_FATAL_RESTART) {
|
||||||
restartCount++;
|
fatalRestartCount++;
|
||||||
Serial.printf("[FATAL] Redémarrage %d/3\n", restartCount);
|
Serial.printf("[FATAL] Redémarrage %d/3\n", fatalRestartCount);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.printf("[FATAL] %d redémarrages : l'appareil entre en sommeil profond permanent\n", MAX_RESTART);
|
Serial.printf("[FATAL] %d redémarrages : l'appareil entre en sommeil profond permanent\n", MAX_FATAL_RESTART);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
esp_deep_sleep_start();
|
esp_deep_sleep_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateDailyGasPayload(uint8_t *payload){
|
void nonCriticalError(const char* msg){
|
||||||
uint32_t pulses = simulateGasPulses(86400);
|
Serial.printf("[Error] %s\n", msg);
|
||||||
|
Serial.flush();
|
||||||
|
delay(100);
|
||||||
|
|
||||||
|
if (restartCount < MAX_RESTART) {
|
||||||
|
restartCount++;
|
||||||
|
Serial.printf("[Error] Tentative de redémarrage\n", restartCount);
|
||||||
|
Serial.flush();
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.printf("[Error] %d redémarrage : l'appareil continue en mode dégradé\n", MAX_RESTART);
|
||||||
|
}
|
||||||
|
|
||||||
|
void generateDailyGasPayload(uint32_t pulses, uint8_t *payload){
|
||||||
payload[0] = (pulses >> 24) & 0xFF;
|
payload[0] = (pulses >> 24) & 0xFF;
|
||||||
payload[1] = (pulses >> 16) & 0xFF;
|
payload[1] = (pulses >> 16) & 0xFF;
|
||||||
payload[2] = (pulses >> 8) & 0xFF;
|
payload[2] = (pulses >> 8) & 0xFF;
|
||||||
|
|
@ -41,6 +56,10 @@ void generateDailyGasPayload(uint8_t *payload){
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(2000);
|
delay(2000);
|
||||||
|
|
||||||
|
if (displayInit() != DisplayError::OK){
|
||||||
|
nonCriticalError("Initialisation du périphérique d'affichage échouée");
|
||||||
|
}
|
||||||
|
|
||||||
if (transmitter->init() != TransmitError::OK){
|
if (transmitter->init() != TransmitError::OK){
|
||||||
fatalError("Initialisation du périphérique radio échouée");
|
fatalError("Initialisation du périphérique radio échouée");
|
||||||
|
|
@ -53,9 +72,15 @@ void setup() {
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
uint8_t payload[4];
|
uint8_t payload[4];
|
||||||
generateDailyGasPayload(payload);
|
uint32_t pulses = simulateGasPulses(86400);
|
||||||
|
|
||||||
|
displayGasIndex(pulses);
|
||||||
|
|
||||||
|
generateDailyGasPayload(pulses, payload);
|
||||||
transmitter->send(payload, sizeof(payload));
|
transmitter->send(payload, sizeof(payload));
|
||||||
|
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
|
|
||||||
|
delay(2000);
|
||||||
esp_deep_sleep(60000000);
|
esp_deep_sleep(60000000);
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue