Add initial version of the Build and release action

This commit is contained in:
Lorow
2025-11-10 19:27:05 +01:00
parent 96016909c5
commit c3ea42c4d0
26 changed files with 339 additions and 32 deletions

View File

@@ -1,6 +1,34 @@
idf_component_register(SRCS
"Monitoring/CurrentMonitor.cpp"
"Monitoring/MonitoringManager.cpp"
INCLUDE_DIRS "Monitoring"
REQUIRES driver esp_adc Helpers
set(
requires
Helpers
)
if ("$ENV{IDF_TARGET}" STREQUAL "esp32s3")
list(APPEND requires
driver
esp_adc
)
endif()
set(
source_files
""
)
if ("$ENV{IDF_TARGET}" STREQUAL "esp32s3")
list(APPEND source_files
"Monitoring/CurrentMonitor_esp32s3.cpp"
"Monitoring/MonitoringManager_esp32s3.cpp"
)
else()
list(APPEND source_files
"Monitoring/CurrentMonitor_esp32.cpp"
"Monitoring/MonitoringManager_esp32.cpp"
)
endif()
idf_component_register(SRCS ${source_files}
INCLUDE_DIRS "Monitoring"
REQUIRES ${requires}
)

View File

@@ -6,7 +6,8 @@
#include <vector>
#include "sdkconfig.h"
class CurrentMonitor {
class CurrentMonitor
{
public:
CurrentMonitor();
~CurrentMonitor() = default;
@@ -25,15 +26,15 @@ public:
// Whether monitoring is enabled by Kconfig
static constexpr bool isEnabled()
{
#ifdef CONFIG_MONITORING_LED_CURRENT
#ifdef CONFIG_MONITORING_LED_CURRENT
return true;
#else
#else
return false;
#endif
#endif
}
private:
#if CONFIG_MONITORING_LED_CURRENT
#ifdef CONFIG_MONITORING_LED_CURRENT
void init_adc();
int read_mv_once();
int gpio_to_adc_channel(int gpio);

View File

@@ -0,0 +1,42 @@
#include "CurrentMonitor.hpp"
#include <esp_log.h>
static const char *TAG_CM = "[CurrentMonitor]";
CurrentMonitor::CurrentMonitor()
{
// empty as esp32 doesn't support this
// but without a separate implementation, the linker will complain :c
}
void CurrentMonitor::setup()
{
ESP_LOGI(TAG_CM, "LED current monitoring disabled");
}
float CurrentMonitor::getCurrentMilliAmps() const
{
return 0.0f;
}
float CurrentMonitor::pollAndGetMilliAmps()
{
sampleOnce();
return getCurrentMilliAmps();
}
void CurrentMonitor::sampleOnce()
{
(void)0;
}
#ifdef CONFIG_MONITORING_LED_CURRENT
void CurrentMonitor::init_adc()
{
}
int CurrentMonitor::read_mv_once()
{
return 0;
}
#endif

View File

@@ -2,7 +2,7 @@
#include <esp_log.h>
#include <cmath>
#if CONFIG_MONITORING_LED_CURRENT
#ifdef CONFIG_MONITORING_LED_CURRENT
#include "esp_adc/adc_oneshot.h"
#include "esp_adc/adc_cali.h"
#include "esp_adc/adc_cali_scheme.h"
@@ -12,14 +12,14 @@ static const char *TAG_CM = "[CurrentMonitor]";
CurrentMonitor::CurrentMonitor()
{
#if CONFIG_MONITORING_LED_CURRENT
#ifdef CONFIG_MONITORING_LED_CURRENT
samples_.assign(CONFIG_MONITORING_LED_SAMPLES, 0);
#endif
}
void CurrentMonitor::setup()
{
#if CONFIG_MONITORING_LED_CURRENT
#ifdef CONFIG_MONITORING_LED_CURRENT
init_adc();
#else
ESP_LOGI(TAG_CM, "LED current monitoring disabled");
@@ -28,7 +28,7 @@ void CurrentMonitor::setup()
float CurrentMonitor::getCurrentMilliAmps() const
{
#if CONFIG_MONITORING_LED_CURRENT
#ifdef CONFIG_MONITORING_LED_CURRENT
const int shunt_milliohm = CONFIG_MONITORING_LED_SHUNT_MILLIOHM; // mΩ
if (shunt_milliohm <= 0)
return 0.0f;
@@ -48,7 +48,7 @@ float CurrentMonitor::pollAndGetMilliAmps()
void CurrentMonitor::sampleOnce()
{
#if CONFIG_MONITORING_LED_CURRENT
#ifdef CONFIG_MONITORING_LED_CURRENT
int mv = read_mv_once();
// Divide by analog gain/divider factor to get shunt voltage
if (CONFIG_MONITORING_LED_GAIN > 0)
@@ -76,7 +76,7 @@ void CurrentMonitor::sampleOnce()
#endif
}
#if CONFIG_MONITORING_LED_CURRENT
#ifdef CONFIG_MONITORING_LED_CURRENT
static adc_oneshot_unit_handle_t s_adc_handle = nullptr;
static adc_cali_handle_t s_cali_handle = nullptr;

View File

@@ -4,9 +4,9 @@
#include <atomic>
#include "CurrentMonitor.hpp"
class MonitoringManager {
class MonitoringManager
{
public:
void setup();
void start();
void stop();
@@ -15,7 +15,7 @@ public:
float getCurrentMilliAmps() const { return last_current_ma_.load(); }
private:
static void taskEntry(void* arg);
static void taskEntry(void *arg);
void run();
TaskHandle_t task_{nullptr};

View File

@@ -0,0 +1,25 @@
#include "MonitoringManager.hpp"
#include <esp_log.h>
static const char *TAG_MM = "[MonitoringManager]";
void MonitoringManager::setup()
{
ESP_LOGI(TAG_MM, "Monitoring disabled by Kconfig");
}
void MonitoringManager::start()
{
}
void MonitoringManager::stop()
{
}
void MonitoringManager::taskEntry(void *arg)
{
}
void MonitoringManager::run()
{
}

View File

@@ -2,11 +2,11 @@
#include <esp_log.h>
#include "sdkconfig.h"
static const char* TAG_MM = "[MonitoringManager]";
static const char *TAG_MM = "[MonitoringManager]";
void MonitoringManager::setup()
{
#if CONFIG_MONITORING_LED_CURRENT
#ifdef CONFIG_MONITORING_LED_CURRENT
cm_.setup();
ESP_LOGI(TAG_MM, "Monitoring enabled. Interval=%dms, Samples=%d, Gain=%d, R=%dmΩ",
CONFIG_MONITORING_LED_INTERVAL_MS,
@@ -20,7 +20,7 @@ void MonitoringManager::setup()
void MonitoringManager::start()
{
#if CONFIG_MONITORING_LED_CURRENT
#ifdef CONFIG_MONITORING_LED_CURRENT
if (task_ == nullptr)
{
xTaskCreate(&MonitoringManager::taskEntry, "MonitoringTask", 2048, this, 1, &task_);
@@ -38,14 +38,14 @@ void MonitoringManager::stop()
}
}
void MonitoringManager::taskEntry(void* arg)
void MonitoringManager::taskEntry(void *arg)
{
static_cast<MonitoringManager*>(arg)->run();
static_cast<MonitoringManager *>(arg)->run();
}
void MonitoringManager::run()
{
#if CONFIG_MONITORING_LED_CURRENT
#ifdef CONFIG_MONITORING_LED_CURRENT
while (true)
{
float ma = cm_.pollAndGetMilliAmps();