Feature: Make RGB LED (preset colors) accessible via API/etc #3039

Fixes #3063
This commit is contained in:
proddy
2026-05-15 10:07:17 +02:00
parent 208717a896
commit 33fda705c0
15 changed files with 514 additions and 280 deletions

View File

@@ -26,6 +26,7 @@
#include "console.h"
#include "mqtt.h"
#include "telegram.h"
#include "led.h"
#ifndef EMSESP_STANDALONE
#include <esp_wifi.h>
@@ -37,8 +38,6 @@
#include <uuid/log.h>
#include <PButton.h>
#define EMSESP_RGB_WRITE rgbLedWrite
#if CONFIG_IDF_TARGET_ESP32
// there is no official API available on the original ESP32
extern "C" {
@@ -54,8 +53,6 @@ using uuid::console::Shell;
#define EMSESP_CUSTOMSUPPORT_FILE "/config/customSupport.json"
#define RGB_LED_BRIGHTNESS 20 // 255 is max brightness
namespace emsesp {
enum PHY_type : uint8_t { PHY_TYPE_NONE = 0, PHY_TYPE_LAN8720, PHY_TYPE_TLK110, PHY_TYPE_RTL8201 };
@@ -98,6 +95,7 @@ class System {
static bool command_service(const char * cmd, const char * value);
static bool command_sendmail(const char * value, const int8_t id);
static bool command_txpause(const char * value, const int8_t id);
static bool command_led(const char * value, const int8_t id);
static bool get_value_info(JsonObject root, const char * cmd);
static void get_value_json(JsonObject output, const std::string & circuit, const std::string & name, JsonVariant val);
@@ -144,7 +142,6 @@ class System {
static bool uploadFirmwareURL(const char * url = nullptr);
void led_init();
void button_init();
void commands_init();
void uart_init();
@@ -354,6 +351,10 @@ class System {
static bool set_partition(const char * partitionname);
// healthcheck flags - shared with LED for status visualization
static constexpr uint8_t HEALTHCHECK_NO_BUS = (1 << 0); // 1
static constexpr uint8_t HEALTHCHECK_NO_NETWORK = (1 << 1); // 2
private:
static uuid::log::Logger logger_;
@@ -374,15 +375,6 @@ class System {
static constexpr uint32_t BUTTON_Debounce = 40; // Debounce period to prevent flickering when pressing or releasing the button (in ms)
static constexpr uint32_t BUTTON_DblClickDelay = 250; // Max period between clicks for a double click event (in ms)
// LED flash timer
static bool led_flash_timer_;
static uint8_t led_flash_gpio_;
static uint8_t led_flash_type_;
static uint32_t led_flash_start_time_;
static uint32_t led_flash_duration_;
static void start_led_flash(uint8_t duration);
static void led_flash();
// button press delays
static constexpr uint32_t BUTTON_LongPressDelay = 3000; // Hold period for a long press event (in ms) - ~3 seconds
static constexpr uint32_t BUTTON_VLongPressDelay = 9500; // Hold period for a very long press event (in ms) - !10 seconds
@@ -393,17 +385,11 @@ class System {
#else
static constexpr uint32_t SYSTEM_CHECK_FREQUENCY = 5000; // do a system check every 5 seconds
#endif
static constexpr uint32_t HEALTHCHECK_LED_LONG_DUARATION = 1500; // 1.5 seconds
static constexpr uint32_t HEALTHCHECK_LED_FLASH_DUARATION = 150; // 150ms
static constexpr uint8_t HEALTHCHECK_NO_BUS = (1 << 0); // 1
static constexpr uint8_t HEALTHCHECK_NO_NETWORK = (1 << 1); // 2
static constexpr uint8_t LED_ON = HIGH; // LED on
#ifndef EMSESP_STANDALONE
static uuid::syslog::SyslogService syslog_;
#endif
void led_monitor();
void system_check();
static std::vector<uint8_t, AllocatorPSRAM<uint8_t>> string_range_to_vector(const std::string & range, const std::string & exclude = "");