massive Update
This commit is contained in:
@@ -39,6 +39,10 @@
|
||||
#include "led_colors.h"
|
||||
#include "obd2_kline.h"
|
||||
#include "obd2_can.h"
|
||||
#include "buttoncontrol.h"
|
||||
#include "button_actions.h"
|
||||
#include "ledcontrol.h"
|
||||
|
||||
|
||||
#ifdef FEATURE_ENABLE_WIFI_CLIENT
|
||||
#include <ESP8266WiFiMulti.h>
|
||||
@@ -59,12 +63,10 @@ Adafruit_NeoPixel leds(1, GPIO_LED, NEO_RGB + NEO_KHZ800);
|
||||
|
||||
// Function-Prototypes
|
||||
void IRAM_ATTR trigger_ISR();
|
||||
void LED_Process(uint8_t override = false, uint32_t setColor = LED_DEFAULT_COLOR);
|
||||
#ifdef FEATURE_ENABLE_OLED
|
||||
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(-1);
|
||||
void Display_Process();
|
||||
#endif
|
||||
void Button_Process();
|
||||
void toggleWiFiAP(bool shutdown = false);
|
||||
void SystemShutdown(bool restart = false);
|
||||
uint32_t Process_Impulse_WheelSpeed();
|
||||
@@ -134,7 +136,7 @@ void setup()
|
||||
Serial.print("\nEE-Init done");
|
||||
|
||||
// Initialize LEDs
|
||||
leds.begin();
|
||||
LEDControl_Init(GPIO_LED);
|
||||
Serial.print("\nLED-Init done");
|
||||
|
||||
// Initialize based on the chosen speed source (CAN, GPS, Impulse)
|
||||
@@ -175,6 +177,8 @@ void setup()
|
||||
pinMode(GPIO_BUTTON, INPUT_PULLUP);
|
||||
pinMode(GPIO_PUMP, OUTPUT);
|
||||
|
||||
ButtonControl_Init(GPIO_BUTTON, buttonActions, buttonActionCount);
|
||||
|
||||
// Set up OTA updates
|
||||
ArduinoOTA.setPort(8266);
|
||||
ArduinoOTA.setHostname(globals.DeviceName);
|
||||
@@ -249,8 +253,8 @@ void loop()
|
||||
|
||||
// Process button input, manage LED behavior, perform EEPROM tasks, handle webserver operations,
|
||||
// process Diagnostic Trouble Codes (DTC), and manage debugging
|
||||
Button_Process();
|
||||
LED_Process();
|
||||
ButtonControl_Update();
|
||||
LEDControl_Update();
|
||||
EEPROM_Process();
|
||||
Webserver_Process();
|
||||
DTC_Process();
|
||||
@@ -340,208 +344,6 @@ void trigger_ISR()
|
||||
wheel_pulse++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Manages LED behavior based on the current system status and user overrides.
|
||||
*
|
||||
* This function handles LED behavior, including startup animations, confirmation animations for
|
||||
* normal and rain modes, indication for purge, error, shutdown, and normal operation. It supports
|
||||
* user overrides to set a specific LED color. The LED status is determined by the current system
|
||||
* status, and specific LED patterns are displayed accordingly.
|
||||
*
|
||||
* @param override Flag indicating whether to override the LED behavior (0: No override, 1: Override, 2: Resume previous state).
|
||||
* @param SetColor The color to set when overriding the LED behavior.
|
||||
*/
|
||||
void LED_Process(uint8_t override, uint32_t SetColor)
|
||||
{
|
||||
// Enumeration to represent LED status
|
||||
typedef enum
|
||||
{
|
||||
LED_Startup,
|
||||
LED_Normal,
|
||||
LED_Confirm_Normal,
|
||||
LED_Rain,
|
||||
LED_Confirm_Rain,
|
||||
LED_Purge,
|
||||
LED_Error,
|
||||
LED_Shutdown,
|
||||
LED_Override
|
||||
} tLED_Status;
|
||||
|
||||
// Static variables to track LED status, system status, override color, and previous LED status
|
||||
static tSystem_Status oldSysStatus = sysStat_Startup;
|
||||
static tLED_Status LED_Status = LED_Startup;
|
||||
static uint32_t LED_override_color = 0;
|
||||
static tLED_Status LED_ResumeOverrideStatus = LED_Startup;
|
||||
|
||||
// Variables for managing LED animation timing
|
||||
uint8_t color = 0;
|
||||
uint32_t timer = 0;
|
||||
uint32_t animtimer = 0;
|
||||
static uint32_t timestamp = 0;
|
||||
timer = millis();
|
||||
|
||||
// Handle LED overrides
|
||||
if (override == 1)
|
||||
{
|
||||
if (LED_Status != LED_Override)
|
||||
{
|
||||
LED_ResumeOverrideStatus = LED_Status;
|
||||
Debug_pushMessage("Override LED_Status\n");
|
||||
}
|
||||
LED_Status = LED_Override;
|
||||
LED_override_color = SetColor;
|
||||
}
|
||||
|
||||
if (override == 2)
|
||||
{
|
||||
if (LED_Status == LED_Override)
|
||||
{
|
||||
LED_Status = LED_ResumeOverrideStatus;
|
||||
Debug_pushMessage("Resume LED_Status\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Update LED status when system status changes
|
||||
if (oldSysStatus != globals.systemStatus)
|
||||
{
|
||||
switch (globals.systemStatus)
|
||||
{
|
||||
case sysStat_Startup:
|
||||
LED_Status = LED_Startup;
|
||||
Debug_pushMessage("sysStat: Startup\n");
|
||||
break;
|
||||
case sysStat_Normal:
|
||||
timestamp = timer + 3500;
|
||||
LED_Status = LED_Confirm_Normal;
|
||||
Debug_pushMessage("sysStat: Normal\n");
|
||||
break;
|
||||
case sysStat_Rain:
|
||||
timestamp = timer + 3500;
|
||||
LED_Status = LED_Confirm_Rain;
|
||||
Debug_pushMessage("sysStat: Rain\n");
|
||||
break;
|
||||
case sysStat_Purge:
|
||||
LED_Status = LED_Purge;
|
||||
Debug_pushMessage("sysStat: Purge\n");
|
||||
break;
|
||||
case sysStat_Error:
|
||||
LED_Status = LED_Error;
|
||||
Debug_pushMessage("sysStat: Error\n");
|
||||
break;
|
||||
case sysStat_Shutdown:
|
||||
LED_Status = LED_Shutdown;
|
||||
Debug_pushMessage("sysStat: Shutdown\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
oldSysStatus = globals.systemStatus;
|
||||
}
|
||||
|
||||
// Handle different LED statuses
|
||||
switch (LED_Status)
|
||||
{
|
||||
case LED_Startup:
|
||||
leds.setBrightness(LubeConfig.LED_Max_Brightness);
|
||||
|
||||
if (globals.TankPercentage < LubeConfig.TankRemindAtPercentage)
|
||||
leds.setPixelColor(0, LED_STARTUP_TANKWARN);
|
||||
else
|
||||
leds.setPixelColor(0, LED_STARTUP_NORMAL);
|
||||
break;
|
||||
|
||||
case LED_Confirm_Normal:
|
||||
animtimer = timer % 500;
|
||||
color = map(animtimer / 2, 0, 250, 0, LubeConfig.LED_Max_Brightness);
|
||||
leds.setPixelColor(0, LED_NORMAL_COLOR);
|
||||
if (animtimer < 250)
|
||||
leds.setBrightness(color);
|
||||
else
|
||||
leds.setBrightness(LubeConfig.LED_Max_Brightness - color);
|
||||
|
||||
if (timestamp < timer)
|
||||
{
|
||||
LED_Status = LED_Normal;
|
||||
Debug_pushMessage("LED_Status: Confirm -> Normal\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case LED_Normal:
|
||||
leds.setBrightness(LubeConfig.LED_Min_Brightness);
|
||||
leds.setPixelColor(0, LED_NORMAL_COLOR);
|
||||
|
||||
if (timer % 2000 > 1950 && LubeConfig.LED_Mode_Flash == true)
|
||||
leds.setBrightness(LubeConfig.LED_Max_Brightness);
|
||||
else if (timer % 2000 > 1500 && WiFi.getMode() != WIFI_OFF)
|
||||
leds.setPixelColor(0, LED_WIFI_BLINK);
|
||||
|
||||
break;
|
||||
|
||||
case LED_Confirm_Rain:
|
||||
animtimer = timer % 500;
|
||||
color = map(animtimer / 2, 0, 250, 0, LubeConfig.LED_Max_Brightness);
|
||||
leds.setPixelColor(0, LED_RAIN_COLOR);
|
||||
if (animtimer < 250)
|
||||
leds.setBrightness(color);
|
||||
else
|
||||
leds.setBrightness(LubeConfig.LED_Max_Brightness - color);
|
||||
if (timestamp < timer)
|
||||
{
|
||||
LED_Status = LED_Rain;
|
||||
Debug_pushMessage("LED_Status: Confirm -> Rain\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case LED_Rain:
|
||||
leds.setBrightness(LubeConfig.LED_Min_Brightness);
|
||||
leds.setPixelColor(0, LED_RAIN_COLOR);
|
||||
|
||||
if (timer % 2000 > 1950 && LubeConfig.LED_Mode_Flash == true)
|
||||
leds.setBrightness(LubeConfig.LED_Max_Brightness);
|
||||
else if (timer % 2000 > 1500 && WiFi.getMode() != WIFI_OFF)
|
||||
leds.setPixelColor(0, LED_WIFI_BLINK);
|
||||
|
||||
break;
|
||||
|
||||
case LED_Purge:
|
||||
timer = timer % 500;
|
||||
color = map(timer / 2, 0, 250, LubeConfig.LED_Min_Brightness, LubeConfig.LED_Max_Brightness);
|
||||
leds.setPixelColor(0, LED_PURGE_COLOR);
|
||||
if (timer < 250)
|
||||
leds.setBrightness(color);
|
||||
else
|
||||
leds.setBrightness(LubeConfig.LED_Max_Brightness - color);
|
||||
break;
|
||||
|
||||
case LED_Error:
|
||||
leds.setBrightness(LubeConfig.LED_Max_Brightness);
|
||||
leds.setPixelColor(0, timer % 500 > 250 ? LED_ERROR_BLINK : 0);
|
||||
break;
|
||||
|
||||
case LED_Shutdown:
|
||||
timer = timer % 600;
|
||||
leds.setPixelColor(0, LED_SHUTDOWN_BLINK);
|
||||
if (timer < 500)
|
||||
{
|
||||
color = map(timer, 0, 500, LubeConfig.LED_Max_Brightness, LubeConfig.LED_Min_Brightness);
|
||||
leds.setBrightness(color);
|
||||
}
|
||||
else
|
||||
{
|
||||
leds.setBrightness(LubeConfig.LED_Min_Brightness);
|
||||
}
|
||||
break;
|
||||
|
||||
case LED_Override:
|
||||
leds.setBrightness(LubeConfig.LED_Max_Brightness);
|
||||
leds.setPixelColor(0, LED_override_color);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
leds.show();
|
||||
}
|
||||
|
||||
#ifdef FEATURE_ENABLE_OLED
|
||||
/**
|
||||
@@ -597,119 +399,6 @@ void Display_Process()
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Processes the button input and performs corresponding actions based on button state and timing.
|
||||
*
|
||||
* This function handles the button input, detecting button presses and executing actions based on
|
||||
* predefined time delays. Actions include toggling WiFi, starting purge, toggling operating modes,
|
||||
* and displaying feedback through LEDs. The function utilizes an enumeration to track button actions
|
||||
* and manages the timing for different actions.
|
||||
*/
|
||||
void Button_Process()
|
||||
{
|
||||
// Time delays for different button actions
|
||||
#define BUTTON_ACTION_DELAY_TOGGLEMODE 500
|
||||
#define BUTTON_ACTION_DELAY_PURGE 3500
|
||||
#define BUTTON_ACTION_DELAY_WIFI 6500
|
||||
#define BUTTON_ACTION_DELAY_NOTHING 9500
|
||||
|
||||
// Enumeration to represent button actions
|
||||
typedef enum buttonAction_e
|
||||
{
|
||||
BTN_INACTIVE,
|
||||
BTN_NOTHING,
|
||||
BTN_TOGGLEMODE,
|
||||
BTN_TOGGLEWIFI,
|
||||
BTN_STARTPURGE
|
||||
} buttonAction_t;
|
||||
|
||||
// Static variables to track button state and timing
|
||||
static uint32_t buttonTimestamp = 0;
|
||||
static buttonAction_t buttonAction = BTN_INACTIVE;
|
||||
|
||||
// Check if button is pressed (LOW)
|
||||
if (digitalRead(GPIO_BUTTON) == LOW)
|
||||
{
|
||||
// Update button timestamp on the first button press
|
||||
if (buttonTimestamp == 0)
|
||||
buttonTimestamp = millis();
|
||||
|
||||
// Check and execute actions based on predefined time delays
|
||||
if (buttonTimestamp + BUTTON_ACTION_DELAY_NOTHING < millis())
|
||||
{
|
||||
LED_Process(1, COLOR_WARM_WHITE);
|
||||
buttonAction = BTN_NOTHING;
|
||||
}
|
||||
else if (buttonTimestamp + BUTTON_ACTION_DELAY_WIFI < millis())
|
||||
{
|
||||
LED_Process(1, LED_WIFI_BLINK);
|
||||
buttonAction = BTN_TOGGLEWIFI;
|
||||
}
|
||||
else if (buttonTimestamp + BUTTON_ACTION_DELAY_PURGE < millis())
|
||||
{
|
||||
LED_Process(1, LED_PURGE_COLOR);
|
||||
buttonAction = BTN_STARTPURGE;
|
||||
}
|
||||
else if (buttonTimestamp + BUTTON_ACTION_DELAY_TOGGLEMODE < millis())
|
||||
{
|
||||
uint32_t color = globals.systemStatus == sysStat_Normal ? LED_RAIN_COLOR : LED_NORMAL_COLOR;
|
||||
LED_Process(1, color);
|
||||
buttonAction = BTN_TOGGLEMODE;
|
||||
}
|
||||
}
|
||||
else // Button is released
|
||||
{
|
||||
// Execute corresponding actions based on the detected button action
|
||||
if (buttonAction != BTN_INACTIVE)
|
||||
{
|
||||
switch (buttonAction)
|
||||
{
|
||||
case BTN_TOGGLEWIFI:
|
||||
toggleWiFiAP();
|
||||
Debug_pushMessage("Starting WiFi AP\n");
|
||||
break;
|
||||
|
||||
case BTN_STARTPURGE:
|
||||
globals.systemStatus = sysStat_Purge;
|
||||
globals.purgePulses = LubeConfig.BleedingPulses;
|
||||
Debug_pushMessage("Starting Purge\n");
|
||||
break;
|
||||
|
||||
case BTN_TOGGLEMODE:
|
||||
switch (globals.systemStatus)
|
||||
{
|
||||
case sysStat_Normal:
|
||||
globals.systemStatus = sysStat_Rain;
|
||||
globals.resumeStatus = sysStat_Rain;
|
||||
break;
|
||||
|
||||
case sysStat_Rain:
|
||||
globals.systemStatus = sysStat_Normal;
|
||||
globals.resumeStatus = sysStat_Normal;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Debug_pushMessage("Toggling Mode\n");
|
||||
break;
|
||||
|
||||
case BTN_NOTHING:
|
||||
default:
|
||||
Debug_pushMessage("Nothing or invalid\n");
|
||||
break;
|
||||
}
|
||||
|
||||
// Display feedback through LEDs
|
||||
LED_Process(2);
|
||||
}
|
||||
|
||||
// Reset button state and timestamp
|
||||
buttonAction = BTN_INACTIVE;
|
||||
buttonTimestamp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Toggles the WiFi functionality based on the current status.
|
||||
*
|
||||
@@ -788,6 +477,36 @@ void SystemShutdown(bool restart)
|
||||
}
|
||||
}
|
||||
|
||||
void onToggleMode()
|
||||
{
|
||||
if (globals.systemStatus == sysStat_Normal)
|
||||
{
|
||||
globals.systemStatus = sysStat_Rain;
|
||||
globals.resumeStatus = sysStat_Rain;
|
||||
}
|
||||
else if (globals.systemStatus == sysStat_Rain)
|
||||
{
|
||||
globals.systemStatus = sysStat_Normal;
|
||||
globals.resumeStatus = sysStat_Normal;
|
||||
}
|
||||
Debug_pushMessage("Toggling Mode\n");
|
||||
}
|
||||
|
||||
void onStartPurge()
|
||||
{
|
||||
globals.systemStatus = sysStat_Purge;
|
||||
globals.purgePulses = LubeConfig.BleedingPulses;
|
||||
Debug_pushMessage("Starting Purge\n");
|
||||
}
|
||||
|
||||
|
||||
void onWashMode()
|
||||
{
|
||||
Debug_pushMessage("Wash mode start\n");
|
||||
// Hier könntest du später gezieltes Nachölen implementieren
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Processes the impulses from the wheel speed sensor and converts them into traveled distance.
|
||||
*
|
||||
|
Reference in New Issue
Block a user