From 01af8cba3c667e6daae12d3e3108117404e6749b Mon Sep 17 00:00:00 2001 From: Marcel Peterkau Date: Fri, 19 Aug 2022 00:10:42 +0200 Subject: [PATCH] Improved Feature Control --- Software/platformio.ini | 4 ++++ Software/src/common.h | 26 ++++++++++++++++++++------ Software/src/config.cpp | 5 +++++ Software/src/globals.h | 3 ++- Software/src/lubeapp.cpp | 12 ++++++------ Software/src/main.cpp | 29 ++++++++++++++++++++--------- 6 files changed, 57 insertions(+), 22 deletions(-) diff --git a/Software/platformio.ini b/Software/platformio.ini index a00d74b..b74dd4d 100644 --- a/Software/platformio.ini +++ b/Software/platformio.ini @@ -33,8 +33,12 @@ build_flags = -DWIFI_AP_IP_GW=10,0,0,1 -DFEATURE_ENABLE_WIFI_CLIENT -DFEATURE_ENABLE_REMOTE_DEBUG + ;-DFEATURE_ENABLE_OLED ;-DFEATURE_ENABLE_CAN ;-DFEATURE_ENABLE_GPS + -DPCB_REV=2 + +build_type = debug board_build.filesystem = littlefs diff --git a/Software/src/common.h b/Software/src/common.h index 01e1e89..41dfd81 100644 --- a/Software/src/common.h +++ b/Software/src/common.h @@ -4,11 +4,25 @@ #define Q(x) #x #define QUOTE(x) Q(x) -#define GPIO_BUTTON D4 -#define GPIO_LED D3 -#define GPIO_TRIGGER D6 -#define GPIO_PUMP D0 -#define GPIO_CS_CAN D8 +#ifndef PCB_REV + #error "You must define PCB_REV" +#elif PCB_REV == 2 + #define GPIO_BUTTON D7 + #define GPIO_LED D8 + #define GPIO_TRIGGER D6 + #define GPIO_PUMP D5 +#elif PCB_REV == 1 || PCB_REV == 3 + #define GPIO_BUTTON D5 + #define GPIO_LED D6 + #define GPIO_TRIGGER D4 + #define GPIO_PUMP D3 +#elif PCB_REV >= 4 + #define GPIO_BUTTON D4 + #define GPIO_LED D3 + #define GPIO_TRIGGER D6 + #define GPIO_PUMP D0 + #define GPIO_CS_CAN D8 +#endif #ifndef HOST_NAME #define HOST_NAME "ChainLube_%06X" // Use printf-Formatting - Chip-ID (uin32_t) will be added @@ -21,7 +35,7 @@ #define OTA_DELAY 50 // ticks -> 10ms / tick #endif -#define ATOMIC_FS_UPDATE +#define ATOMIC_FS_UPDATE #ifndef ADMIN_PASSWORD #error "You need to define ADMIN_PASSWORD for OTA-Update" diff --git a/Software/src/config.cpp b/Software/src/config.cpp index 7d656e7..61882c4 100644 --- a/Software/src/config.cpp +++ b/Software/src/config.cpp @@ -54,6 +54,11 @@ void EEPROM_Process() GetPersistence_EEPROM(); globals.requestEEAction = EE_IDLE; break; + case EE_ALL_SAVE: + StorePersistence_EEPROM(); + StoreConfig_EEPROM(); + globals.requestEEAction = EE_IDLE; + break; case EE_IDLE: default: globals.requestEEAction = EE_IDLE; diff --git a/Software/src/globals.h b/Software/src/globals.h index 4e6f199..b9f5e9a 100644 --- a/Software/src/globals.h +++ b/Software/src/globals.h @@ -19,7 +19,8 @@ typedef enum eEERequest EE_CFG_SAVE, EE_CFG_LOAD, EE_PDS_SAVE, - EE_PDS_LOAD + EE_PDS_LOAD, + EE_ALL_SAVE } tEERequest; typedef struct Globals_s diff --git a/Software/src/lubeapp.cpp b/Software/src/lubeapp.cpp index e61743b..d927962 100644 --- a/Software/src/lubeapp.cpp +++ b/Software/src/lubeapp.cpp @@ -81,22 +81,22 @@ void RunLubeApp(uint32_t add_milimeters) switch (globals.systemStatus) { case sysStat_Normal: - strcpy(globals.systemStatustxt, PSTR("Normal")); + strcpy_P(globals.systemStatustxt, PSTR("Normal")); break; case sysStat_Purge: - strcpy(globals.systemStatustxt, PSTR("Purge")); + strcpy_P(globals.systemStatustxt, PSTR("Purge")); break; case sysStat_Rain: - strcpy(globals.systemStatustxt, PSTR("Rain")); + strcpy_P(globals.systemStatustxt, PSTR("Rain")); break; case sysStat_Startup: - strcpy(globals.systemStatustxt, PSTR("Startup")); + strcpy_P(globals.systemStatustxt, PSTR("Startup")); break; case sysStat_Error: - strcpy(globals.systemStatustxt, PSTR("Error")); + strcpy_P(globals.systemStatustxt, PSTR("Error")); break; case sysStat_Shutdown: - strcpy(globals.systemStatustxt, PSTR("Shutdown")); + strcpy_P(globals.systemStatustxt, PSTR("Shutdown")); break; } diff --git a/Software/src/main.cpp b/Software/src/main.cpp index 83b1d84..3c7142d 100644 --- a/Software/src/main.cpp +++ b/Software/src/main.cpp @@ -1,6 +1,8 @@ #include #include +#ifdef FEATURE_ENABLE_OLED #include +#endif #include #include @@ -45,13 +47,15 @@ Globals_t globals; uint32_t TravelDistance_highRes; volatile uint32_t wheel_pulse = 0; -U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(-1); CRGB leds[1]; // Function-Prototypes void IRAM_ATTR trigger_ISR(); void LED_Process(uint8_t override = false, CRGB setColor = CRGB::White); +#ifdef FEATURE_ENABLE_OLED +U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(-1); void Display_Process(); +#endif void Button_Process(); void toggleWiFiAP(boolean shutdown = false); void SystemShutdown(); @@ -105,11 +109,11 @@ void setup() InitEEPROM(); GetConfig_EEPROM(); GetPersistence_EEPROM(); - +#ifdef FEATURE_ENABLE_OLED u8x8.begin(); u8x8.setFont(u8x8_font_chroma48medium8_r); - - FastLED.addLeds(leds, 1); // GRB ordering is assumed +#endif + FastLED.addLeds(leds, 1); // GRB ordering is assumed switch (LubeConfig.SpeedSource) { @@ -154,7 +158,7 @@ void setup() ArduinoOTA.setPort(8266); ArduinoOTA.setHostname(globals.DeviceName); ArduinoOTA.setPassword(QUOTE(ADMIN_PASSWORD)); - +#ifdef FEATURE_ENABLE_OLED ArduinoOTA.onStart([]() { u8x8.clearDisplay(); @@ -180,12 +184,14 @@ void setup() u8x8.clearDisplay(); u8x8.drawString(0, 0, "OTA-Restart"); u8x8.refreshDisplay(); }); - +#endif ArduinoOTA.begin(); +#ifdef FEATURE_ENABLE_OLED u8x8.clearDisplay(); u8x8.drawString(0, 0, "KTM ChainLube V1"); u8x8.refreshDisplay(); +#endif initWebUI(); initGlobals(); @@ -218,7 +224,9 @@ void loop() RunLubeApp(wheelDistance); EEPROMCyclicPDSTicker.update(); +#ifdef FEATURE_ENABLE_OLED Display_Process(); +#endif Button_Process(); LED_Process(); EEPROM_Process(); @@ -277,7 +285,7 @@ void processCmdRemoteDebug() else if (lastCmd == "dumpPDS") RemoteDebug_dumpPersistance(); else if (lastCmd == "saveEE") - StoreConfig_EEPROM(); + globals.requestEEAction == EE_ALL_SAVE; else if (lastCmd == "showdtc") RemoteDebug_ShowDTCs(); } @@ -572,7 +580,7 @@ void LED_Process(uint8_t override, CRGB SetColor) } FastLED.show(); } - +#ifdef FEATURE_ENABLE_OLED void Display_Process() { static tSystem_Status oldSysStatus = sysStat_Startup; @@ -604,6 +612,7 @@ void Display_Process() } u8x8.refreshDisplay(); } +#endif void Button_Process() { @@ -740,6 +749,7 @@ uint32_t Process_Impulse_WheelSpeed() return add_milimeters; } +#ifdef FEATURE_ENABLE_REMOTE_DEBUG void RemoteDebug_ShowDTCs() { char buff_timestamp[16]; // Format: DD-hh:mm:ss:xxx @@ -766,4 +776,5 @@ void RemoteDebug_ShowDTCs() debugA("%s \t %6d \t %s", buff_timestamp, DTCStorage[i].Number, buff_active); } } -} \ No newline at end of file +} +#endif \ No newline at end of file