WebUI config stuff
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
#include <Arduino.h>
|
||||
#include <ESPUI.h>
|
||||
#include <EEPROM.h>
|
||||
#include "lubeapp.h"
|
||||
|
||||
extern sLubeConfig LubeConfig;
|
||||
#include "config.h"
|
||||
|
||||
uint16_t tab_lube;
|
||||
uint16_t tab_wheel;
|
||||
uint16_t tab_tank;
|
||||
uint16_t tab_maintenance;
|
||||
uint16_t tab_store;
|
||||
|
||||
uint16_t num_lubedist_normal;
|
||||
uint16_t num_lubedist_rain;
|
||||
uint16_t button_lubedist;
|
||||
|
||||
uint16_t num_wheel_width;
|
||||
uint16_t num_wheel_ratio;
|
||||
@@ -17,66 +18,109 @@ uint16_t num_wheel_rim;
|
||||
uint16_t button_wheelcalc;
|
||||
uint16_t num_wheel_ppr;
|
||||
uint16_t num_wheel_dist;
|
||||
uint16_t button_wheel;
|
||||
|
||||
void numberCall(Control *sender, int type)
|
||||
uint16_t num_tank_capacity;
|
||||
uint16_t num_tank_notify;
|
||||
|
||||
uint16_t label_tankRemain;
|
||||
uint16_t button_reset_tank;
|
||||
uint16_t num_purge_pulses;
|
||||
uint16_t button_purge;
|
||||
|
||||
uint16_t button_store;
|
||||
uint16_t button_reload;
|
||||
uint16_t label_storeStatus;
|
||||
|
||||
void SettingChanged_Callback(Control *sender, int type)
|
||||
{
|
||||
Serial.print("Slider: ID: ");
|
||||
Serial.print(sender->label);
|
||||
Serial.print(", Value: ");
|
||||
Serial.println(sender->value);
|
||||
if (sender->id == num_lubedist_normal)
|
||||
LubeConfig.DistancePerLube_Default = ESPUI.getControl(num_lubedist_normal)->value.toInt();
|
||||
else if (sender->id == num_lubedist_rain)
|
||||
LubeConfig.DistancePerLube_Rain = ESPUI.getControl(num_lubedist_rain)->value.toInt();
|
||||
else if (sender->id == num_wheel_width)
|
||||
LubeConfig.TireWidth_mm = ESPUI.getControl(num_wheel_width)->value.toInt();
|
||||
else if (sender->id == num_wheel_ratio)
|
||||
LubeConfig.TireWidthHeight_Ratio = ESPUI.getControl(num_wheel_ratio)->value.toInt();
|
||||
else if (sender->id == num_wheel_rim)
|
||||
LubeConfig.RimDiameter_Inch = ESPUI.getControl(num_wheel_rim)->value.toInt();
|
||||
else if (sender->id == num_wheel_ppr)
|
||||
LubeConfig.PulsePerRevolution = ESPUI.getControl(num_wheel_ppr)->value.toInt();
|
||||
else if (sender->id == num_wheel_dist)
|
||||
LubeConfig.DistancePerRevolution_mm = ESPUI.getControl(num_wheel_dist)->value.toInt();
|
||||
else if (sender->id == num_tank_capacity)
|
||||
LubeConfig.tankCapacity_ml = ESPUI.getControl(num_tank_capacity)->value.toInt();
|
||||
else if (sender->id == num_tank_notify)
|
||||
LubeConfig.TankRemindAtPercentage = ESPUI.getControl(num_tank_notify)->value.toInt();
|
||||
}
|
||||
|
||||
void wheelcalc(Control *sender, int type)
|
||||
void buttons_Callback(Control *sender, int type)
|
||||
{
|
||||
static uint32_t wheel_ppr = 0;
|
||||
static uint32_t wheel_dist = 0;
|
||||
if (type != B_UP) return;
|
||||
|
||||
if (sender->id == num_wheel_ppr)
|
||||
wheel_ppr = sender->value.toInt();
|
||||
if (sender->id == num_wheel_dist)
|
||||
wheel_dist = sender->value.toInt();
|
||||
|
||||
if (type == B_UP && sender->id == button_wheelcalc)
|
||||
if (sender->id == button_wheelcalc)
|
||||
{
|
||||
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));
|
||||
LubeConfig.DistancePerRevolution_mm = (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(LubeConfig.DistancePerRevolution_mm));
|
||||
}
|
||||
if (type == B_UP && sender->id == button_wheel)
|
||||
{
|
||||
LubeConfig.DistancePerRevolution_mm = wheel_dist;
|
||||
LubeConfig.PulsePerRevolution = wheel_ppr;
|
||||
|
||||
EEPROM.begin(512);
|
||||
EEPROM.put(0, LubeConfig);
|
||||
EEPROM.commit();
|
||||
EEPROM.end();
|
||||
if(sender->id == button_reset_tank)
|
||||
{
|
||||
LubeConfig.tankRemain_µl = LubeConfig.tankCapacity_ml * 1000;
|
||||
ESPUI.print(label_tankRemain, String(LubeConfig.tankRemain_µl / 1000));
|
||||
}
|
||||
|
||||
if(sender->id == button_purge)
|
||||
{
|
||||
int pulses = ESPUI.getControl(num_purge_pulses)->value.toInt();
|
||||
Serial.printf("Starting to Purge with %d pulses", pulses);
|
||||
}
|
||||
|
||||
|
||||
if (sender->id == button_store)
|
||||
{
|
||||
StoreConfig_EEPROM();
|
||||
ESPUI.print(label_storeStatus, "Successfully Stored Settings");
|
||||
}
|
||||
|
||||
if (sender->id == button_reload)
|
||||
{
|
||||
GetConfig_EEPROM();
|
||||
ESPUI.print(label_storeStatus, "Successfully Reloaded Settings");
|
||||
}
|
||||
}
|
||||
|
||||
void initWebUI(void)
|
||||
void initWebUI()
|
||||
{
|
||||
|
||||
tab_lube = ESPUI.addControl(ControlType::Tab, "Schmierung", "Schmierung");
|
||||
tab_wheel = ESPUI.addControl(ControlType::Tab, "Wegesignal", "Wegesignal");
|
||||
tab_lube = ESPUI.addControl(ControlType::Tab, "Dosierung", "Dosierung");
|
||||
tab_wheel = ESPUI.addControl(ControlType::Tab, "Erfassung", "Erfassung");
|
||||
tab_tank = ESPUI.addControl(ControlType::Tab, "Tank", "Tank");
|
||||
tab_maintenance = ESPUI.addControl(ControlType::Tab, "Wartung", "Wartung");
|
||||
tab_store = ESPUI.addControl(ControlType::Tab, "Speichern", "Speichern");
|
||||
|
||||
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_lubedist_normal = ESPUI.addControl(ControlType::Number, "Öl-Impuls alle x Meter (Normal)", String(LubeConfig.DistancePerLube_Default), ControlColor::Emerald, tab_lube, &SettingChanged_Callback);
|
||||
num_lubedist_rain = ESPUI.addControl(ControlType::Number, "Öl-Impuls alle x Meter (Regen)", String(LubeConfig.DistancePerLube_Rain), ControlColor::Emerald, tab_lube, &SettingChanged_Callback);
|
||||
|
||||
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);
|
||||
num_wheel_width = ESPUI.addControl(ControlType::Number, "Reifenbreite (mm)", String(LubeConfig.TireWidth_mm), ControlColor::Peterriver, tab_wheel, &SettingChanged_Callback);
|
||||
num_wheel_ratio = ESPUI.addControl(ControlType::Number, "Höhe/Breite-Verhältniss", String(LubeConfig.TireWidthHeight_Ratio), ControlColor::Peterriver, tab_wheel, &SettingChanged_Callback);
|
||||
num_wheel_rim = ESPUI.addControl(ControlType::Number, "Felgendurchmesser (Zoll)", String(LubeConfig.RimDiameter_Inch), ControlColor::Peterriver, tab_wheel, &SettingChanged_Callback);
|
||||
button_wheelcalc = ESPUI.addControl(ControlType::Button, "Abrollumfang aus Reifendaten berechnen", "Berechnen", ControlColor::Peterriver, tab_wheel, &buttons_Callback);
|
||||
num_wheel_dist = ESPUI.addControl(ControlType::Number, "Wegstrecke pro Umdrehung (mm)", String(LubeConfig.DistancePerRevolution_mm), ControlColor::Wetasphalt, tab_wheel, &SettingChanged_Callback);
|
||||
num_wheel_ppr = ESPUI.addControl(ControlType::Number, "Sensorimpulse pro Umdrehung", String(LubeConfig.PulsePerRevolution), ControlColor::Wetasphalt, tab_wheel, &SettingChanged_Callback);
|
||||
|
||||
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);
|
||||
num_tank_capacity = ESPUI.addControl(ControlType::Number, "Tankinhalt maximal (ml)", String(LubeConfig.tankCapacity_ml), ControlColor::Carrot, tab_tank, &SettingChanged_Callback);
|
||||
num_tank_notify = ESPUI.addControl(ControlType::Number, "Tankinhalt Warnung (%)", String(LubeConfig.TankRemindAtPercentage), ControlColor::Carrot, tab_tank, &SettingChanged_Callback);
|
||||
|
||||
label_tankRemain = ESPUI.addControl(ControlType::Label, "Tankinhalt verbleibend (ml, geschätzt)",String(LubeConfig.tankRemain_µl / 1000), ControlColor::Alizarin, tab_maintenance);
|
||||
button_reset_tank = ESPUI.addControl(ControlType::Button, "Tankinhalt zurücksetzen", "Reset", ControlColor::Alizarin, tab_maintenance, &buttons_Callback);
|
||||
num_purge_pulses = ESPUI.addControl(ControlType::Number, "Entlüftung Impulse", "10", ControlColor::Alizarin, tab_maintenance);
|
||||
button_purge = ESPUI.addControl(ControlType::Button, "Leitung Entlüften", "Start", ControlColor::Alizarin, tab_maintenance, &buttons_Callback);
|
||||
|
||||
button_store = ESPUI.addControl(ControlType::Button, "Einstellungen permanent speichern", "Speichern", ControlColor::Turquoise, tab_store, &buttons_Callback);
|
||||
button_reload = ESPUI.addControl(ControlType::Button, "Einstellungen neu laden", "Laden", ControlColor::Turquoise, tab_store, &buttons_Callback);
|
||||
label_storeStatus = ESPUI.addControl(ControlType::Label, "Status", "", ControlColor::Turquoise, tab_store);
|
||||
|
||||
ESPUI.begin("Souko's ChainLube Mk1");
|
||||
}
|
||||
|
Reference in New Issue
Block a user