diff --git a/lib/GazDisplay/GazDisplay.cpp b/lib/GazDisplay/GazDisplay.cpp new file mode 100644 index 0000000..0728d3e --- /dev/null +++ b/lib/GazDisplay/GazDisplay.cpp @@ -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(); +} \ No newline at end of file diff --git a/lib/GazDisplay/GazDisplay.h b/lib/GazDisplay/GazDisplay.h new file mode 100644 index 0000000..3b757fc --- /dev/null +++ b/lib/GazDisplay/GazDisplay.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include + +#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 +}; + +DisplayError displayInit(); +void displayGasIndex(uint32_t pulses); +