Change folder structure

This commit is contained in:
Arne van Iterson 2024-03-10 15:46:15 +01:00
parent 7db1eb46e2
commit 3dcd0560c2
7 changed files with 184 additions and 127 deletions

View File

@ -21,3 +21,4 @@ lib_deps =
khoih-prog/ESP_WifiManager@^1.12.1 khoih-prog/ESP_WifiManager@^1.12.1
adafruit/Adafruit GFX Library@^1.11.7 adafruit/Adafruit GFX Library@^1.11.7
knolleary/PubSubClient@^2.8 knolleary/PubSubClient@^2.8
lennarthennigs/Button2@^2.3.2

View File

@ -1,34 +1,4 @@
#include <Arduino.h> #include "./einkanalog.h"
#include <GxEPD2_BW.h>
#include <Adafruit_GFX.h>
#include "../include/fonts/Pixeltype8pt7b.h"
#include "../include/fonts/Pixeltype16pt7b.h"
#include "../include/fonts/Fipps_Regular8pt7b.h"
#include "../include/fonts/SilomBol7pt7b.h"
const unsigned char gfx_wireless[] PROGMEM = {
0x00, 0xe0, 0x10, 0xc8, 0x28, 0xa8, 0x00};
const unsigned char gfx_build[] PROGMEM = {
0x00, 0x50, 0xf8, 0x88, 0x88, 0xf8, 0x00};
class EinkAnalogDisplay
{
private:
int16_t min;
int16_t max;
uint8_t dac;
GxEPD2_BW<GxEPD2_213_B72, (uint16_t)250U> *display;
void centerText(const char *text, int16_t x, int16_t y);
public:
EinkAnalogDisplay(GxEPD2_BW<GxEPD2_213_B72, (uint16_t)250U> *display, uint8_t dacPin);
~EinkAnalogDisplay();
void drawFace(int16_t min, int16_t max, char *name, char* unit, uint8_t lines = 5);
int setArm(float value);
void drawMeta(const char *wireless_str);
};
EinkAnalogDisplay::EinkAnalogDisplay(GxEPD2_BW<GxEPD2_213_B72, (uint16_t)250U> *display, uint8_t dacPin) EinkAnalogDisplay::EinkAnalogDisplay(GxEPD2_BW<GxEPD2_213_B72, (uint16_t)250U> *display, uint8_t dacPin)
{ {

View File

@ -0,0 +1,28 @@
#ifndef EIAD_H
#define EIAD_H
#include <global.h>
const unsigned char gfx_wireless[] PROGMEM = {
0x00, 0xe0, 0x10, 0xc8, 0x28, 0xa8, 0x00};
const unsigned char gfx_build[] PROGMEM = {
0x00, 0x50, 0xf8, 0x88, 0x88, 0xf8, 0x00};
class EinkAnalogDisplay
{
private:
int16_t min;
int16_t max;
uint8_t dac;
GxEPD2_BW<GxEPD2_213_B72, (uint16_t)250U> *display;
void centerText(const char *text, int16_t x, int16_t y);
public:
EinkAnalogDisplay(GxEPD2_BW<GxEPD2_213_B72, (uint16_t)250U> *display, uint8_t dacPin);
~EinkAnalogDisplay();
void drawFace(int16_t min, int16_t max, char *name, char* unit, uint8_t lines = 5);
int setArm(float value);
void drawMeta(const char *wireless_str);
};
#endif

35
src/global.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef GLOBAL_H
#define GLOBAL_H
#include <Arduino.h>
// Wifi
#include <WiFi.h>
#include <WiFiMulti.h>
// MQTT
#include <PubSubClient.h>
// DAC
#define DAC1 25
// Buttons
#include "Button2.h"
#define BTN_L 22
#define BTN_R 21
// Display
#include <GxEPD2_BW.h>
// Fonts
#include <Adafruit_GFX.h>
#include "../include/fonts/Pixeltype8pt7b.h"
#include "../include/fonts/Pixeltype16pt7b.h"
#include "../include/fonts/Fipps_Regular8pt7b.h"
#include "../include/fonts/SilomBol7pt7b.h"
// Local helper files
#include "./einkanalog/einkanalog.h"
#include "./helpers/mqtt.h"
#endif

14
src/helpers/mqtt.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "mqtt.h"
void callback(char *topic, byte *payload, unsigned int length)
{
Serial.print("Message arrived [");
Serial.print(topic);
Serial.println("] ");
// char array[length + 1] = {};
// memcpy(array, payload, length);
// array[length] = '\0';
// Serial.println(String(array).toFloat() / 1000.0);
// ead.setArm(String(array).toFloat() / 1000.0);
}

7
src/helpers/mqtt.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef MQTT_H
#define MQTT_H
#include <global.h>
void callback(char *topic, byte *payload, unsigned int length);
#endif

View File

@ -1,47 +1,37 @@
#include <Arduino.h> #include "global.h"
// Wifi // Wifi
#include <WiFi.h>
#include <WiFiMulti.h>
WiFiMulti WiFiMulti; WiFiMulti WiFiMulti;
WiFiClient espClient; WiFiClient espClient;
IPAddress server(192, 168, 2, 196); IPAddress server(192, 168, 2, 196);
// MQTT // MQTT
#include <PubSubClient.h>
PubSubClient client(espClient); PubSubClient client(espClient);
// DAC // Buttons
#define DAC1 25 Button2 btn_L, btn_R;
// BTN
#define BTN_L
#define BTN_R
// Display // Display
#include <GxEPD2_BW.h>
GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=5*/ SS, /*DC=*/17, /*RST=*/16, /*BUSY=*/4)); GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=5*/ SS, /*DC=*/17, /*RST=*/16, /*BUSY=*/4));
#include "./einkanalog.h" // Helpers
EinkAnalogDisplay ead(&display, DAC1); EinkAnalogDisplay ead(&display, DAC1);
// Fonts
#include <Adafruit_GFX.h>
#include "../include/fonts/Pixeltype8pt7b.h"
#include "../include/fonts/Pixeltype16pt7b.h"
void callback(char *topic, byte *payload, unsigned int length) void btnHandler(Button2 &btn)
{ {
Serial.print("Message arrived ["); switch (btn.getType())
Serial.print(topic); {
Serial.print("] "); case single_click:
break;
// char array[length + 1] = {}; case double_click:
// memcpy(array, payload, length); Serial.print("double ");
// array[length] = '\0'; break;
// Serial.println(String(array).toFloat() / 1000.0); }
// ead.setArm(String(array).toFloat() / 1000.0); Serial.print("click ");
Serial.print("on button #");
Serial.print((btn == btn_L) ? "L" : "R");
Serial.println();
} }
void setup() void setup()
@ -52,6 +42,15 @@ void setup()
Serial.println("T5 Dashboard " __DATE__ " " __TIME__); Serial.println("T5 Dashboard " __DATE__ " " __TIME__);
// Buttons
btn_L.begin(BTN_L, INPUT_PULLUP, true);
btn_L.setClickHandler(btnHandler);
btn_L.setDoubleClickHandler(btnHandler);
btn_R.begin(BTN_R, INPUT_PULLUP, true);
btn_R.setClickHandler(btnHandler);
btn_R.setDoubleClickHandler(btnHandler);
display.fillScreen(GxEPD_WHITE); display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK); display.setTextColor(GxEPD_BLACK);
display.setFont(&Pixeltype8pt7b); display.setFont(&Pixeltype8pt7b);
@ -131,5 +130,8 @@ void loop()
delay(5000); delay(5000);
} }
} }
btn_L.loop();
btn_R.loop();
client.loop(); client.loop();
} }