wifi settings prep

This commit is contained in:
2021-08-25 12:35:09 +02:00
parent 73518dda4f
commit 1cfd6f9bef
9 changed files with 153 additions and 151 deletions

View File

@@ -9,6 +9,8 @@
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"initializer_list": "cpp"
"initializer_list": "cpp",
"string_view": "cpp",
"ranges": "cpp"
}
}

View File

@@ -15,6 +15,8 @@ framework = arduino
monitor_speed = 115200
lib_deps =
glmnet/Dsmr@^0.3
juerd/ESP-WiFiSettings @ ^3.8.0
lib_ldf_mode = deep+
compile_flags =
-std=c++11
;compile_flags =
; -std=c++11
board_build.filesystem = littlefs

View File

@@ -1,13 +1,44 @@
#include "connection.h"
String wifiState;
FS *filesystem = &SPIFFS;
void initWifiConnection(void)
{
// Set custom callback functions
WiFiSettings.onSuccess = []()
{
wifiState = "Success";
};
WiFiSettings.onFailure = []()
{
wifiState = "Failed";
};
WiFiSettings.onWaitLoop = []()
{
wifiState = "Waiting";
return 500; // Delay next function call by 500ms
};
// Callback functions do not have to be lambda's, e.g.
// WiFiSettings.onPortalWaitLoop = blink;
// Define custom settings saved by WifiSettings
// These will return the default if nothing was set before
String host = WiFiSettings.string("server_host", "default.example.org");
int port = WiFiSettings.integer("server_port", 443);
// Connect to WiFi with a timeout of 30 seconds
// Launches the portal if the connection failed
WiFiSettings.connect(true, 30);
}
void initConnection(void)
{
filesystem->begin();
initWifiConnection();
}
void handleConnection(void)
{
}
wifiStrength getWifiStrength(void)
{
return signal_3;
}

View File

@@ -1,5 +1,9 @@
#pragma once
#include <littleFS.h>
#include <WiFiSettings.h>
void initConnection( void );
void handleConnection(void);

View File

@@ -0,0 +1 @@
hello world!

View File

@@ -1,142 +1,108 @@
#include "display.h"
SSD1306Wire display(0x3c, SDA, SCL);
bool initOK = false;
OLEDDisplayUi ui(&display);
e_displayStates displayState = DISPLAY_INIT;
uint32_t lastDisplayCycle = 0;
uint32_t lastDisplayUpdate = 0;
int screenW = 128;
int screenH = 64;
int clockCenterX = screenW / 2;
int clockCenterY = ((screenH - 16) / 2) + 16; // top yellow part is 16 px height
int clockRadius = 23;
// utility function for digital clock display: prints leading 0
String twoDigits(int digits)
void drawDSMRstats(void)
{
if (digits < 10)
{
String i = '0' + String(digits);
return i;
}
else
{
return String(digits);
}
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 0, "DSMR stats:");
display.drawString(0, 11, getMsgCount());
}
void msOverlay(OLEDDisplay *display, OLEDDisplayUiState *state)
void drawElecFrame(void)
{
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 0, "Electricity:");
display.drawString(0, 11, getElecDelivered());
display.drawString(0, 22, getElecReturned());
}
void initFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
void drawGasFrame(void)
{
// draw an xbm image.
// Please note that everything that should be transitioned
// needs to be drawn relative to x and y
//display->drawXbm(x + 34, y + 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(ArialMT_Plain_16);
display->drawString(64 + x, 8 + y, "DU-DSMR-W");
//display->
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 0, getGasDelivered());
}
void DSMRStatsFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
void drawInitFrame(void)
{
// Demonstrates the 3 included default sizes. The fonts come from SSD1306Fonts.h file
// Besides the default fonts there will be a program to convert TrueType fonts into this format
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(ArialMT_Plain_10);
display->drawString(0 + x, 0 + y, "DSMR stats:");
display->drawString(0 + x, 11 + y, getMsgCount());
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.setFont(ArialMT_Plain_16);
display.drawString(64, 12, "DU-DSMR-W");
display.drawXbm(0, 0, wifiicon10x10_width, wifiicon10x10_height, wifi10x10_png_bits);
display.drawXbm(16,0, download_cloud_solid_png_width, download_cloud_solid_png_height, download_cloud_solid_png_bits);
}
void ElecFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(ArialMT_Plain_10);
display->drawString(0 + x, 0 + y, "Electricity:");
display->drawString(0 + x, 11 + y, getElecDelivered());
display->drawString(0 + x, 22 + y, getElecReturned());
}
void GasFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(ArialMT_Plain_10);
display->drawString(0 + x, 0 + y, getGasDelivered());
}
void drawFrame5(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
}
// This array keeps function pointers to all frames
// frames are the single views that slide in
FrameCallback frames[] = {initFrame, DSMRStatsFrame, ElecFrame, GasFrame};//, drawFrame5};
// how many frames are there?
int frameCount = 4;
// Overlays are statically drawn on top of a frame eg. a clock
//OverlayCallback overlays[] = {msOverlay};
//int overlaysCount = 1;
void initDisplay(void)
{
// The ESP is capable of rendering 60fps in 80Mhz mode
// but that won't give you much time for anything else
// run it in 160Mhz mode or just set it to 30 fps
ui.setTargetFPS(30);
display.init();
// Customize the active and inactive symbol
//ui.setActiveSymbol(activeSymbol);
//ui.setInactiveSymbol(inactiveSymbol);
drawInitFrame();
display.display();
// You can change this to
// TOP, LEFT, BOTTOM, RIGHT
ui.setIndicatorPosition(RIGHT);
Serial.printf("initdisplay: h=%u, w=%u\n", display.height(), display.width());
}
// Defines where the first frame is located in the bar.
ui.setIndicatorDirection(LEFT_RIGHT);
// You can change the transition that is used
// SLIDE_LEFT, SLIDE_RIGHT, SLIDE_UP, SLIDE_DOWN
ui.setFrameAnimation(SLIDE_UP);
// Add frames
ui.setFrames(frames, frameCount);
// Add overlays
//ui.setOverlays(overlays, overlaysCount);
//ui.disableAllIndicators();
// Initialising the UI will init the display too.
ui.init();
Serial.printf("initdisplay: h=%u, w=%u", display.height(), display.width());
//display.flipScreenVertically();
e_displayStates nextFrame(void)
{
displayState = static_cast<e_displayStates>(static_cast<int>(displayState) + 1);
if (displayState == DISPLAU_LAST)
{
displayState = DISPLAY_DSMR1;
}
return displayState;
}
void handleDisplay(void)
{
int remainingTimeBudget = ui.update();
uint32_t timeNow = millis();
if (remainingTimeBudget > 0)
if (timeNow - lastDisplayUpdate > DISPLAY_CYCLE_TIME)
{
// You can do some work here
// Don't do stuff if you are below your
// time budget.
Serial.println(remainingTimeBudget);
//delay(remainingTimeBudget);
//lastDisplayUpdate
display.clear();
switch (displayState)
{
case DISPLAY_INIT:
{
drawInitFrame();
}
break;
case DISPLAY_DSMR1:
{
drawElecFrame();
}
break;
case DISPLAY_DSMR2:
{
drawGasFrame();
}
break;
case DISPLAY_DSMR3:
{
drawDSMRstats();
}
break;
default:
{
displayState = nextFrame();
}
break;
}
display.display();
lastDisplayUpdate = timeNow;
}
if (timeNow - lastDisplayCycle > DISPLAY_CYCLE_TIME)
{
displayState = nextFrame();
lastDisplayCycle = timeNow;
}
}

View File

@@ -1,12 +1,23 @@
#pragma once
#include "Arduino.h"
#include "OLEDDisplayUi.h"
#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"`
#include "SSD1306Wire.h"
#include "board.h"
#include "images.h"
#include "dsmrhandler.h"
#include "connection.h"
#define DISPLAY_UPDATE_TIME 200
#define DISPLAY_CYCLE_TIME 3000
typedef enum{
DISPLAY_INIT,
DISPLAY_DSMR1,
DISPLAY_DSMR2,
DISPLAY_DSMR3,
DISPLAU_LAST
}e_displayStates;
void initDisplay(void);
void handleDisplay(void);

View File

@@ -1,34 +1,21 @@
#pragma once
#include "Arduino.h"
#define WiFi_Logo_width 60
#define WiFi_Logo_height 36
const uint8_t WiFi_Logo_bits[] {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF,
0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00,
0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C,
0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00,
0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C,
0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00,
0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C,
0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00,
0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C,
0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00,
0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F,
0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00,
0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF,
0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00,
0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
#define wifiicon10x10_width 13
#define wifiicon10x10_height 10
const PROGMEM uint8_t wifi10x10_png_bits[] = {
0xf0, 0x01, 0x0c, 0x06, 0x02, 0x08, 0xf0, 0x01, 0x08, 0x02, 0x00, 0x00,
0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00
};
#define download_cloud_solid_png_width 18
#define download_cloud_solid_png_height 9
const PROGMEM uint8_t download_cloud_solid_png_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0xb9, 0x03, 0x5b, 0x12, 0x01,
0x55, 0x12, 0x01, 0x51, 0x13, 0x01, 0x91, 0x13, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00 };
const uint8_t activeSymbol[] = {
B00000000,

View File

@@ -4,7 +4,6 @@
#include "connection.h"
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
@@ -18,7 +17,6 @@ void setup() {
void loop() {
// put your main code here, to run repeatedly:
Serial.print(".|.ß");
handleDisplay();
handleConnection();
}