Work on EEPROM-Stuff

This commit is contained in:
Marcel Peterkau 2022-01-08 03:14:26 +01:00
parent 435a0e1f5a
commit 2e3a9f6e3f
7 changed files with 126 additions and 72 deletions

View File

@ -18,10 +18,11 @@ board = d1_mini
framework = arduino framework = arduino
upload_protocol = esptool upload_protocol = esptool
;upload_port = 10.0.1.90 upload_speed = 921600
;upload_port = ChainLube_DDEFB2
;upload_protocol = espota ;upload_protocol = espota
;upload_flags = ;upload_flags =
; --auth=${wifi_cred.admin_pass} ; --auth=${wifi_cred.admin_password}
build_flags = build_flags =
!python git_rev_macro.py !python git_rev_macro.py
@ -30,20 +31,16 @@ build_flags =
-DADMIN_PASSWORD=${wifi_cred.admin_password} -DADMIN_PASSWORD=${wifi_cred.admin_password}
-DWIFI_AP_PASSWORD=${wifi_cred.wifi_ap_password} -DWIFI_AP_PASSWORD=${wifi_cred.wifi_ap_password}
;-DDEBUG
-fexceptions
build_unflags = -fno-exceptions
build_type = debug
board_build.filesystem = littlefs board_build.filesystem = littlefs
monitor_filters = esp8266_exception_decoder monitor_filters = esp8266_exception_decoder
monitor_speed = 115200 monitor_speed = 115200
board_build.ldscript = eagle.flash.4m3m.ld board_build.ldscript = eagle.flash.4m.ld
lib_ldf_mode = deep lib_ldf_mode = deep
lib_deps = lib_deps =
olikraus/U8g2 @ ^2.28.8 olikraus/U8g2 @ ^2.28.8
joaolopesf/RemoteDebug @ ^2.1.2 joaolopesf/RemoteDebug @ ^2.1.2
fastled/FastLED @ ^3.5.0 fastled/FastLED @ ^3.5.0
sstaub/Ticker @ ^4.2.0 sstaub/Ticker @ ^4.2.0
s00500/ESPUI @ ^2.0.0

View File

@ -1,6 +1,6 @@
#include <Arduino.h> #include "lubeapp.h"
void RunLubeApp() void RunLubeApp(sLubeConfig *cfg)
{ {
} }

View File

@ -0,0 +1,23 @@
#ifndef _LUBEAPP_H_
#define _LUBEAPP_H_
#include <Arduino.h>
typedef struct tLubeConfig
{
uint32_t DistancePerLube_Default = 0;
uint32_t DistancePerLube_Rain = 0;
uint32_t tankCapacity_ml = 320;
uint32_t amountPerDose_µl = 0;
uint32_t tankRemain_µl = 0;
uint8_t TankRemindAtPercentage = 30;
uint8_t PulsePerRevolution = 1;
uint32_t TireWidth_mm = 150;
uint32_t TireWidthHeight_Ratio = 70;
uint32_t RimDiameter_Inch = 18;
uint32_t DistancePerRevolution_mm = 2000;
} sLubeConfig;
extern void RunLubeApp(sLubeConfig *cfg);
#endif

View File

@ -8,9 +8,12 @@
#include <RemoteDebug.h> #include <RemoteDebug.h>
#include <FastLED.h> #include <FastLED.h>
#include <Ticker.h> #include <Ticker.h>
#include <EEPROM.h>
#include "common.h" #include "common.h"
#include "rmtdbghelp.h" #include "rmtdbghelp.h"
#include "lubeapp.h"
#include "webui.h"
const char *ssid = QUOTE(WIFI_SSID); const char *ssid = QUOTE(WIFI_SSID);
const char *password = QUOTE(WIFI_PASSWORD); const char *password = QUOTE(WIFI_PASSWORD);
@ -28,18 +31,7 @@ char DeviceName[33];
volatile uint32_t wheel_pulse = 0; volatile uint32_t wheel_pulse = 0;
typedef struct tLubeConfig sLubeConfig LubeConfig;
{
uint32_t DistancePerLube_Default = 0;
uint32_t DistancePerLube_Rain = 0;
uint32_t tankCapacity_ml = 320;
uint32_t amountPerDose_µl = 0;
uint32_t tankRemain_µl = 0;
uint8_t TankRemindAtPercentage = 30;
uint8_t PulsePerRevolution = 1;
uint32_t DistancePerRevolution_mm = 2000;
} sLubeConfig;
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(-1); U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(-1);
RemoteDebug Debug; RemoteDebug Debug;
@ -53,13 +45,15 @@ void RemotDebug_printSystemInfo();
void RemoteDebug_printWifiInfo(); void RemoteDebug_printWifiInfo();
void wifiMaintainConnectionTicker_callback(); void wifiMaintainConnectionTicker_callback();
void IRAM_ATTR trigger_ISR(); void IRAM_ATTR trigger_ISR();
extern void RunLubeApp();
extern void initWebUI();
Ticker WiFiMaintainConnectionTicker(wifiMaintainConnectionTicker_callback, 1000, 0, MILLIS); Ticker WiFiMaintainConnectionTicker(wifiMaintainConnectionTicker_callback, 1000, 0, MILLIS);
void setup() void setup()
{ {
EEPROM.begin(512);
EEPROM.get(0, LubeConfig);
EEPROM.end();
system_update_cpu_freq(SYS_CPU_80MHZ); system_update_cpu_freq(SYS_CPU_80MHZ);
snprintf(DeviceName, 32, HOST_NAME, ESP.getChipId()); snprintf(DeviceName, 32, HOST_NAME, ESP.getChipId());
WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_OFF);
@ -152,7 +146,7 @@ void loop()
{ {
leds[0] = digitalRead(GPIO_BUTTON) ? CRGB::Green : CRGB::Red; leds[0] = digitalRead(GPIO_BUTTON) ? CRGB::Green : CRGB::Red;
RunLubeApp(); RunLubeApp(&LubeConfig);
WiFiMaintainConnectionTicker.update(); WiFiMaintainConnectionTicker.update();
FastLED.show(); FastLED.show();
@ -184,13 +178,16 @@ void RemotDebug_printSystemInfo()
debugA("Souko's ChainOiler Mk1"); debugA("Souko's ChainOiler Mk1");
debugA("Hostname: %s", DeviceName); debugA("Hostname: %s", DeviceName);
FlashMode_t ideMode = ESP.getFlashChipMode();
debugA("Sdk version: %s", ESP.getSdkVersion()); debugA("Sdk version: %s", ESP.getSdkVersion());
debugA("Core Version: %s", ESP.getCoreVersion().c_str()); debugA("Core Version: %s", ESP.getCoreVersion().c_str());
debugA("Boot Version: %u", ESP.getBootVersion()); debugA("Boot Version: %u", ESP.getBootVersion());
debugA("Boot Mode: %u", ESP.getBootMode()); debugA("Boot Mode: %u", ESP.getBootMode());
debugA("CPU Frequency: %u MHz", ESP.getCpuFreqMHz()); debugA("CPU Frequency: %u MHz", ESP.getCpuFreqMHz());
debugA("Reset reason: %s", ESP.getResetReason().c_str()); debugA("Reset reason: %s", ESP.getResetReason().c_str());
debugA("Flash Size: %d", ESP.getFlashChipRealSize());
debugA("Flash Size IDE: %d", ESP.getFlashChipSize());
debugA("Flash ide mode: %s", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN"));
debugA("OTA-Pass: %s", QUOTE(ADMIN_PASSWORD)); debugA("OTA-Pass: %s", QUOTE(ADMIN_PASSWORD));
} }
@ -198,6 +195,7 @@ void RemoteDebug_printWifiInfo()
{ {
} }
void wifiMaintainConnectionTicker_callback() void wifiMaintainConnectionTicker_callback()
{ {
static uint32_t WiFiFailCount = 0; static uint32_t WiFiFailCount = 0;

View File

@ -1,55 +1,82 @@
#include <Arduino.h> #include <Arduino.h>
#include <ESPUI.h> #include <ESPUI.h>
#include <EEPROM.h>
#include "lubeapp.h"
uint16_t button1; extern sLubeConfig LubeConfig;
uint16_t switchOne;
uint16_t status;
void initWebUI(); uint16_t tab_lube;
uint16_t tab_wheel;
uint16_t tab_tank;
uint16_t num_lubedist_normal;
uint16_t num_lubedist_rain;
uint16_t num_wheel_width;
uint16_t num_wheel_ratio;
uint16_t num_wheel_rim;
uint16_t button_wheelcalc;
uint16_t num_wheel_ppr;
uint16_t num_wheel_dist;
uint16_t button_wheel;
void slider( Control* sender, int type ) { void numberCall(Control *sender, int type)
{
Serial.print("Slider: ID: "); Serial.print("Slider: ID: ");
Serial.print(sender->id); Serial.print(sender->label);
Serial.print(", Value: "); Serial.print(", Value: ");
Serial.println(sender->value); Serial.println(sender->value);
} }
void wheelcalc(Control *sender, int type)
{
static uint32_t wheel_ppr = 0;
static uint32_t wheel_dist = 0;
void initWebUI (void){ if (sender->id == num_wheel_ppr)
wheel_ppr = sender->value.toInt();
if (sender->id == num_wheel_dist)
wheel_dist = sender->value.toInt();
uint16_t tab_lube = ESPUI.addControl( ControlType::Tab, "Schmierung", "Schmierung" ); if (type == B_UP && sender->id == button_wheelcalc)
uint16_t tab_tank = ESPUI.addControl( ControlType::Tab, "Tank", "Tank" ); {
uint16_t tab_wifi = ESPUI.addControl( ControlType::Tab, "WiFi", "WiFi" ); LubeConfig.TireWidth_mm = ESPUI.getControl(num_wheel_width)->value.toInt();
LubeConfig.RimDiameter_Inch = ESPUI.getControl(num_wheel_rim)->value.toInt();
LubeConfig.TireWidthHeight_Ratio = ESPUI.getControl(num_wheel_ratio)->value.toInt();
wheel_dist = (uint32_t)((((((float)LubeConfig.TireWidthHeight_Ratio / 100.0) * (float)LubeConfig.TireWidth_mm) * 2.0) + ((float)LubeConfig.RimDiameter_Inch * 25.4)) * 3.1416);
ESPUI.updateControlValue(num_wheel_dist, String(wheel_dist));
}
if (type == B_UP && sender->id == button_wheel)
{
LubeConfig.DistancePerRevolution_mm = wheel_dist;
LubeConfig.PulsePerRevolution = wheel_ppr;
ESPUI.addControl( ControlType::Slider, "Distanz Normal", "10000", ControlColor::Alizarin, tab_lube, &slider ); EEPROM.begin(512);
ESPUI.addControl( ControlType::Slider, "Distanz Regen", "10000", ControlColor::Alizarin, tab_lube, &slider ); EEPROM.put(0, LubeConfig);
/* EEPROM.commit();
// shown above all tabs EEPROM.end();
status = ESPUI.addControl( ControlType::Label, "Status:", "Stop", ControlColor::Turquoise ); }
uint16_t select1 = ESPUI.addControl( ControlType::Select, "Select:", "", ControlColor::Alizarin, tab1, &selectExample );
ESPUI.addControl( ControlType::Option, "Option1", "Opt1", ControlColor::Alizarin, select1 );
ESPUI.addControl( ControlType::Option, "Option2", "Opt2", ControlColor::Alizarin, select1 );
ESPUI.addControl( ControlType::Option, "Option3", "Opt3", ControlColor::Alizarin, select1 );
ESPUI.addControl( ControlType::Text, "Text Test:", "a Text Field", ControlColor::Alizarin, tab1, &textCall );
// tabbed controls
ESPUI.addControl( ControlType::Label, "Millis:", "0", ControlColor::Emerald, tab1 );
button1 = ESPUI.addControl( ControlType::Button, "Push Button", "Press", ControlColor::Peterriver, tab1, &buttonCallback );
ESPUI.addControl( ControlType::Button, "Other Button", "Press", ControlColor::Wetasphalt, tab1, &buttonExample );
ESPUI.addControl( ControlType::PadWithCenter, "Pad with center", "", ControlColor::Sunflower, tab2, &padExample );
ESPUI.addControl( ControlType::Pad, "Pad without center", "", ControlColor::Carrot, tab3, &padExample );
switchOne = ESPUI.addControl( ControlType::Switcher, "Switch one", "", ControlColor::Alizarin, tab3, &switchExample );
ESPUI.addControl( ControlType::Switcher, "Switch two", "", ControlColor::None, tab3, &otherSwitchExample );
ESPUI.addControl( ControlType::Slider, "Slider one", "30", ControlColor::Alizarin, tab1, &slider );
ESPUI.addControl( ControlType::Slider, "Slider two", "100", ControlColor::Alizarin, tab3, &slider );
ESPUI.addControl( ControlType::Number, "Number:", "50", ControlColor::Alizarin, tab3, &numberCall );
*/
ESPUI.begin("ESPUI Control");
} }
void initWebUI(void)
{
tab_lube = ESPUI.addControl(ControlType::Tab, "Schmierung", "Schmierung");
tab_wheel = ESPUI.addControl(ControlType::Tab, "Wegesignal", "Wegesignal");
tab_tank = ESPUI.addControl(ControlType::Tab, "Tank", "Tank");
num_lubedist_normal = ESPUI.addControl(ControlType::Number, "Distanz Normal (m)", String(LubeConfig.DistancePerLube_Default), ControlColor::Wetasphalt, tab_lube, &numberCall);
num_lubedist_rain = ESPUI.addControl(ControlType::Number, "Distanz Regen (m)", String(LubeConfig.DistancePerLube_Rain), ControlColor::Wetasphalt, tab_lube, &numberCall);
num_wheel_width = ESPUI.addControl(ControlType::Number, "Reifenbreite (mm)", String(LubeConfig.TireWidth_mm), ControlColor::Dark, tab_wheel, &wheelcalc);
num_wheel_ratio = ESPUI.addControl(ControlType::Number, "Höhe/Breite-Verhältniss", String(LubeConfig.TireWidthHeight_Ratio), ControlColor::Dark, tab_wheel, &wheelcalc);
num_wheel_rim = ESPUI.addControl(ControlType::Number, "Felgendurchmesser (Zoll)", String(LubeConfig.RimDiameter_Inch), ControlColor::Dark, tab_wheel, &wheelcalc);
button_wheelcalc = ESPUI.addControl(ControlType::Button, "Abrollumfang", "Berechnen", ControlColor::Dark, tab_wheel, &wheelcalc);
num_wheel_dist = ESPUI.addControl(ControlType::Number, "Strecke pro Umdrehung (mm)", String(LubeConfig.DistancePerRevolution_mm), ControlColor::Wetasphalt, tab_wheel, &wheelcalc);
num_wheel_ppr = ESPUI.addControl(ControlType::Number, "Pulse pro Umdrehung", String(LubeConfig.PulsePerRevolution), ControlColor::Wetasphalt, tab_wheel, &wheelcalc);
button_wheel = ESPUI.addControl(ControlType::Button, "Wegesignal", "Speichern", ControlColor::Wetasphalt, tab_wheel, &wheelcalc);
ESPUI.addControl(ControlType::Number, "Tankinhalt maximal (ml)", String(LubeConfig.tankCapacity_ml), ControlColor::Wetasphalt, tab_tank, &numberCall);
ESPUI.addControl(ControlType::Number, "Tankinhalt Warnung (%)", String(LubeConfig.TankRemindAtPercentage), ControlColor::Wetasphalt, tab_tank, &numberCall);
ESPUI.begin("Souko's ChainLube Mk1");
}

View File

@ -0,0 +1,9 @@
#ifndef _WEBUI_H_
#define _WEBUI_H_
#include <Arduino.h>
void initWebUI();
#endif