Change folder structure
This commit is contained in:
parent
7db1eb46e2
commit
3dcd0560c2
@ -21,3 +21,4 @@ lib_deps =
|
||||
khoih-prog/ESP_WifiManager@^1.12.1
|
||||
adafruit/Adafruit GFX Library@^1.11.7
|
||||
knolleary/PubSubClient@^2.8
|
||||
lennarthennigs/Button2@^2.3.2
|
||||
|
@ -1,34 +1,4 @@
|
||||
#include <Arduino.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);
|
||||
};
|
||||
#include "./einkanalog.h"
|
||||
|
||||
EinkAnalogDisplay::EinkAnalogDisplay(GxEPD2_BW<GxEPD2_213_B72, (uint16_t)250U> *display, uint8_t dacPin)
|
||||
{
|
28
src/einkanalog/einkanalog.h
Normal file
28
src/einkanalog/einkanalog.h
Normal 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
35
src/global.h
Normal 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
14
src/helpers/mqtt.cpp
Normal 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
7
src/helpers/mqtt.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef MQTT_H
|
||||
#define MQTT_H
|
||||
#include <global.h>
|
||||
|
||||
void callback(char *topic, byte *payload, unsigned int length);
|
||||
|
||||
#endif
|
194
src/main.cpp
194
src/main.cpp
@ -1,135 +1,137 @@
|
||||
#include <Arduino.h>
|
||||
#include "global.h"
|
||||
|
||||
// Wifi
|
||||
#include <WiFi.h>
|
||||
#include <WiFiMulti.h>
|
||||
|
||||
WiFiMulti WiFiMulti;
|
||||
WiFiClient espClient;
|
||||
IPAddress server(192, 168, 2, 196);
|
||||
|
||||
// MQTT
|
||||
#include <PubSubClient.h>
|
||||
PubSubClient client(espClient);
|
||||
|
||||
// DAC
|
||||
#define DAC1 25
|
||||
|
||||
// BTN
|
||||
#define BTN_L
|
||||
#define BTN_R
|
||||
// Buttons
|
||||
Button2 btn_L, btn_R;
|
||||
|
||||
// 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));
|
||||
|
||||
#include "./einkanalog.h"
|
||||
// Helpers
|
||||
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 [");
|
||||
Serial.print(topic);
|
||||
Serial.print("] ");
|
||||
|
||||
// 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);
|
||||
switch (btn.getType())
|
||||
{
|
||||
case single_click:
|
||||
break;
|
||||
case double_click:
|
||||
Serial.print("double ");
|
||||
break;
|
||||
}
|
||||
Serial.print("click ");
|
||||
Serial.print("on button #");
|
||||
Serial.print((btn == btn_L) ? "L" : "R");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
display.init(115200);
|
||||
delay(10);
|
||||
Serial.begin(115200);
|
||||
display.init(115200);
|
||||
delay(10);
|
||||
|
||||
Serial.println("T5 Dashboard " __DATE__ " " __TIME__);
|
||||
Serial.println("T5 Dashboard " __DATE__ " " __TIME__);
|
||||
|
||||
display.fillScreen(GxEPD_WHITE);
|
||||
display.setTextColor(GxEPD_BLACK);
|
||||
display.setFont(&Pixeltype8pt7b);
|
||||
display.setRotation(1);
|
||||
display.setPartialWindow(0, 0, display.width(), display.height());
|
||||
display.firstPage();
|
||||
// Buttons
|
||||
btn_L.begin(BTN_L, INPUT_PULLUP, true);
|
||||
btn_L.setClickHandler(btnHandler);
|
||||
btn_L.setDoubleClickHandler(btnHandler);
|
||||
|
||||
ead.drawFace(0, 100, "Welcome", "", 11);
|
||||
display.nextPage();
|
||||
btn_R.begin(BTN_R, INPUT_PULLUP, true);
|
||||
btn_R.setClickHandler(btnHandler);
|
||||
btn_R.setDoubleClickHandler(btnHandler);
|
||||
|
||||
for (int8_t i = 0; i <= 100; i++)
|
||||
{
|
||||
ead.setArm(i);
|
||||
delay(20);
|
||||
}
|
||||
display.fillScreen(GxEPD_WHITE);
|
||||
display.setTextColor(GxEPD_BLACK);
|
||||
display.setFont(&Pixeltype8pt7b);
|
||||
display.setRotation(1);
|
||||
display.setPartialWindow(0, 0, display.width(), display.height());
|
||||
display.firstPage();
|
||||
|
||||
for (int8_t i = 100; i >= 0; i--)
|
||||
{
|
||||
ead.setArm(i);
|
||||
delay(20);
|
||||
}
|
||||
|
||||
// display.setCursor(0, 6);
|
||||
// // display.println("TTGO T5 V2.3 ePaper PlatformIO");
|
||||
// display.println("T5 Analog/Digital Display, " __DATE__ " " __TIME__);
|
||||
// display.nextPage();
|
||||
|
||||
WiFiMulti.addAP("Langeboomgaard", "ACvI4152EK");
|
||||
WiFiMulti.addAP("ARNE-LAPTOPV3 6821", "P3900:q5");
|
||||
|
||||
if (int stat = WiFiMulti.run() != WL_CONNECTED)
|
||||
{
|
||||
Serial.println(WiFi.status());
|
||||
display.print("WiFi connection failed");
|
||||
display.println(stat);
|
||||
ead.drawFace(0, 100, "Welcome", "", 11);
|
||||
display.nextPage();
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
// display.printf("WiFi connected to ");
|
||||
// display.println(WiFi.SSID());
|
||||
// display.print("IP address: ");
|
||||
// display.println(WiFi.localIP());
|
||||
// display.nextPage();
|
||||
for (int8_t i = 0; i <= 100; i++)
|
||||
{
|
||||
ead.setArm(i);
|
||||
delay(20);
|
||||
}
|
||||
|
||||
// delay(1000);
|
||||
for (int8_t i = 100; i >= 0; i--)
|
||||
{
|
||||
ead.setArm(i);
|
||||
delay(20);
|
||||
}
|
||||
|
||||
// display.fillScreen(GxEPD_WHITE);
|
||||
// display.nextPage();
|
||||
// display.setCursor(0, 6);
|
||||
// // display.println("TTGO T5 V2.3 ePaper PlatformIO");
|
||||
// display.println("T5 Analog/Digital Display, " __DATE__ " " __TIME__);
|
||||
// display.nextPage();
|
||||
|
||||
client.setServer(server, 1883);
|
||||
client.setCallback(callback);
|
||||
WiFiMulti.addAP("Langeboomgaard", "ACvI4152EK");
|
||||
WiFiMulti.addAP("ARNE-LAPTOPV3 6821", "P3900:q5");
|
||||
|
||||
display.fillScreen(GxEPD_WHITE);
|
||||
ead.drawFace(0, 9, "Solax Prod.", "kW", 10);
|
||||
ead.drawMeta(WiFi.localIP().toString().c_str());
|
||||
display.nextPage();
|
||||
if (int stat = WiFiMulti.run() != WL_CONNECTED)
|
||||
{
|
||||
Serial.println(WiFi.status());
|
||||
display.print("WiFi connection failed");
|
||||
display.println(stat);
|
||||
display.nextPage();
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
|
||||
// display.printf("WiFi connected to ");
|
||||
// display.println(WiFi.SSID());
|
||||
// display.print("IP address: ");
|
||||
// display.println(WiFi.localIP());
|
||||
// display.nextPage();
|
||||
|
||||
// delay(1000);
|
||||
|
||||
// display.fillScreen(GxEPD_WHITE);
|
||||
// display.nextPage();
|
||||
|
||||
client.setServer(server, 1883);
|
||||
client.setCallback(callback);
|
||||
|
||||
display.fillScreen(GxEPD_WHITE);
|
||||
ead.drawFace(0, 9, "Solax Prod.", "kW", 10);
|
||||
ead.drawMeta(WiFi.localIP().toString().c_str());
|
||||
display.nextPage();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
while (!client.connected())
|
||||
{
|
||||
Serial.print("Attempting MQTT connection...");
|
||||
// Attempt to connect
|
||||
if (client.connect("espead", "arne", "ThinkCentreM58"))
|
||||
while (!client.connected())
|
||||
{
|
||||
Serial.println("connected");
|
||||
client.subscribe("homeassistant/ead/#");
|
||||
Serial.print("Attempting MQTT connection...");
|
||||
// Attempt to connect
|
||||
if (client.connect("espead", "arne", "ThinkCentreM58"))
|
||||
{
|
||||
Serial.println("connected");
|
||||
client.subscribe("homeassistant/ead/#");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("failed, rc=");
|
||||
Serial.print(client.state());
|
||||
Serial.println(" try again in 5 seconds");
|
||||
// Wait 5 seconds before retrying
|
||||
delay(5000);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print("failed, rc=");
|
||||
Serial.print(client.state());
|
||||
Serial.println(" try again in 5 seconds");
|
||||
// Wait 5 seconds before retrying
|
||||
delay(5000);
|
||||
}
|
||||
}
|
||||
client.loop();
|
||||
|
||||
btn_L.loop();
|
||||
btn_R.loop();
|
||||
client.loop();
|
||||
}
|
Loading…
Reference in New Issue
Block a user