2022-01-07 21:02:27 +01:00
# include <Arduino.h>
# include <ESPUI.h>
2022-01-08 03:14:26 +01:00
# include <EEPROM.h>
# include "lubeapp.h"
2022-01-07 21:02:27 +01:00
2022-01-08 03:14:26 +01:00
extern sLubeConfig LubeConfig ;
2022-01-07 21:02:27 +01:00
2022-01-08 03:14:26 +01:00
uint16_t tab_lube ;
uint16_t tab_wheel ;
uint16_t tab_tank ;
uint16_t num_lubedist_normal ;
uint16_t num_lubedist_rain ;
2022-01-07 21:02:27 +01:00
2022-01-08 03:14:26 +01:00
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 ;
2022-01-07 21:02:27 +01:00
2022-01-08 03:14:26 +01:00
void numberCall ( Control * sender , int type )
{
2022-01-07 21:02:27 +01:00
Serial . print ( " Slider: ID: " ) ;
2022-01-08 03:14:26 +01:00
Serial . print ( sender - > label ) ;
2022-01-07 21:02:27 +01:00
Serial . print ( " , Value: " ) ;
2022-01-08 03:14:26 +01:00
Serial . println ( sender - > value ) ;
}
void wheelcalc ( Control * sender , int type )
{
static uint32_t wheel_ppr = 0 ;
static uint32_t wheel_dist = 0 ;
2022-01-07 21:02:27 +01:00
2022-01-08 03:14:26 +01:00
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 )
{
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 ;
2022-01-07 21:02:27 +01:00
2022-01-08 03:14:26 +01:00
EEPROM . begin ( 512 ) ;
EEPROM . put ( 0 , LubeConfig ) ;
EEPROM . commit ( ) ;
EEPROM . end ( ) ;
}
2022-01-07 21:02:27 +01:00
}
2022-01-08 03:14:26 +01:00
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 ) ;
2022-01-07 23:36:02 +01:00
2022-01-08 03:14:26 +01:00
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 ) ;
2022-01-07 23:36:02 +01:00
2022-01-08 03:14:26 +01:00
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 " ) ;
}