Reformat project using clang-format

This commit is contained in:
Lorow
2026-01-06 22:51:24 +01:00
parent 567d3ebd75
commit 555e290d71
70 changed files with 3282 additions and 3428 deletions

View File

@@ -13,7 +13,7 @@
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32)
#include <esp_log.h>
static const char *TAG = "[AdcSampler]";
static const char* TAG = "[AdcSampler]";
// Static member initialization
adc_oneshot_unit_handle_t AdcSampler::shared_unit_ = nullptr;
@@ -22,11 +22,11 @@ AdcSampler::~AdcSampler()
{
if (cali_handle_)
{
#if defined(CONFIG_IDF_TARGET_ESP32S3)
#if defined(CONFIG_IDF_TARGET_ESP32S3)
adc_cali_delete_scheme_curve_fitting(cali_handle_);
#elif defined(CONFIG_IDF_TARGET_ESP32)
#elif defined(CONFIG_IDF_TARGET_ESP32)
adc_cali_delete_scheme_line_fitting(cali_handle_);
#endif
#endif
cali_handle_ = nullptr;
}
}
@@ -68,8 +68,8 @@ bool AdcSampler::init(int gpio, adc_atten_t atten, adc_bitwidth_t bitwidth, size
// Try calibration (requires eFuse data)
// ESP32-S3 uses curve-fitting, ESP32 uses line-fitting
esp_err_t cal_err = ESP_FAIL;
#if defined(CONFIG_IDF_TARGET_ESP32S3)
#if defined(CONFIG_IDF_TARGET_ESP32S3)
// ESP32-S3 curve fitting calibration
adc_cali_curve_fitting_config_t cal_cfg = {
.unit_id = unit_,
@@ -78,7 +78,7 @@ bool AdcSampler::init(int gpio, adc_atten_t atten, adc_bitwidth_t bitwidth, size
.bitwidth = bitwidth_,
};
cal_err = adc_cali_create_scheme_curve_fitting(&cal_cfg, &cali_handle_);
#elif defined(CONFIG_IDF_TARGET_ESP32)
#elif defined(CONFIG_IDF_TARGET_ESP32)
// ESP32 line-fitting calibration is per-unit, not per-channel
adc_cali_line_fitting_config_t cal_cfg = {
.unit_id = unit_,
@@ -86,8 +86,8 @@ bool AdcSampler::init(int gpio, adc_atten_t atten, adc_bitwidth_t bitwidth, size
.bitwidth = bitwidth_,
};
cal_err = adc_cali_create_scheme_line_fitting(&cal_cfg, &cali_handle_);
#endif
#endif
if (cal_err == ESP_OK)
{
cali_inited_ = true;
@@ -187,11 +187,10 @@ bool AdcSampler::configure_channel(int gpio, adc_atten_t atten, adc_bitwidth_t b
esp_err_t err = adc_oneshot_config_channel(shared_unit_, channel_, &chan_cfg);
if (err != ESP_OK)
{
ESP_LOGE(TAG, "adc_oneshot_config_channel failed (GPIO %d, CH %d): %s",
gpio, static_cast<int>(channel_), esp_err_to_name(err));
ESP_LOGE(TAG, "adc_oneshot_config_channel failed (GPIO %d, CH %d): %s", gpio, static_cast<int>(channel_), esp_err_to_name(err));
return false;
}
return true;
}
#endif // CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32
#endif // CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32

View File

@@ -21,10 +21,10 @@
#include "sdkconfig.h"
#if defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32)
#include "esp_adc/adc_oneshot.h"
#include <vector>
#include "esp_adc/adc_cali.h"
#include "esp_adc/adc_cali_scheme.h"
#include <vector>
#include "esp_adc/adc_oneshot.h"
/**
* @class AdcSampler
@@ -35,15 +35,15 @@
*/
class AdcSampler
{
public:
public:
AdcSampler() = default;
~AdcSampler();
// Non-copyable, non-movable (owns hardware resources)
AdcSampler(const AdcSampler &) = delete;
AdcSampler &operator=(const AdcSampler &) = delete;
AdcSampler(AdcSampler &&) = delete;
AdcSampler &operator=(AdcSampler &&) = delete;
AdcSampler(const AdcSampler&) = delete;
AdcSampler& operator=(const AdcSampler&) = delete;
AdcSampler(AdcSampler&&) = delete;
AdcSampler& operator=(AdcSampler&&) = delete;
/**
* @brief Initialize the ADC channel on the shared ADC1 oneshot unit
@@ -53,10 +53,7 @@ public:
* @param window_size Moving average window size (>=1)
* @return true on success, false on failure
*/
bool init(int gpio,
adc_atten_t atten = ADC_ATTEN_DB_12,
adc_bitwidth_t bitwidth = ADC_BITWIDTH_DEFAULT,
size_t window_size = 1);
bool init(int gpio, adc_atten_t atten = ADC_ATTEN_DB_12, adc_bitwidth_t bitwidth = ADC_BITWIDTH_DEFAULT, size_t window_size = 1);
/**
* @brief Perform one ADC conversion and update filtered value
@@ -68,15 +65,21 @@ public:
* @brief Get the filtered ADC reading in millivolts
* @return Filtered voltage in mV
*/
int getFilteredMilliVolts() const { return filtered_mv_; }
int getFilteredMilliVolts() const
{
return filtered_mv_;
}
/**
* @brief Check if ADC sampling is supported on current platform
* @return true if supported
*/
static constexpr bool isSupported() { return true; }
static constexpr bool isSupported()
{
return true;
}
private:
private:
// Hardware initialization helpers
bool ensure_unit();
bool configure_channel(int gpio, adc_atten_t atten, adc_bitwidth_t bitwidth);
@@ -85,7 +88,7 @@ private:
* @brief Platform-specific GPIO to ADC channel mapping
* @note Implemented separately in AdcSampler_esp32.cpp and AdcSampler_esp32s3.cpp
*/
static bool map_gpio_to_channel(int gpio, adc_unit_t &unit, adc_channel_t &channel);
static bool map_gpio_to_channel(int gpio, adc_unit_t& unit, adc_channel_t& channel);
// Shared ADC1 oneshot handle (single instance for all AdcSampler objects)
static adc_oneshot_unit_handle_t shared_unit_;
@@ -110,10 +113,22 @@ private:
// Stub for unsupported targets to keep interfaces consistent
class AdcSampler
{
public:
bool init(int /*gpio*/, int /*atten*/ = 0, int /*bitwidth*/ = 0, size_t /*window_size*/ = 1) { return false; }
bool sampleOnce() { return false; }
int getFilteredMilliVolts() const { return 0; }
static constexpr bool isSupported() { return false; }
public:
bool init(int /*gpio*/, int /*atten*/ = 0, int /*bitwidth*/ = 0, size_t /*window_size*/ = 1)
{
return false;
}
bool sampleOnce()
{
return false;
}
int getFilteredMilliVolts() const
{
return 0;
}
static constexpr bool isSupported()
{
return false;
}
};
#endif

View File

@@ -19,9 +19,9 @@
#if defined(CONFIG_IDF_TARGET_ESP32)
bool AdcSampler::map_gpio_to_channel(int gpio, adc_unit_t &unit, adc_channel_t &channel)
bool AdcSampler::map_gpio_to_channel(int gpio, adc_unit_t& unit, adc_channel_t& channel)
{
unit = ADC_UNIT_1; // Only use ADC1 to avoid Wi-Fi conflict
unit = ADC_UNIT_1; // Only use ADC1 to avoid Wi-Fi conflict
// ESP32: ADC1 GPIO mapping (GPIO32-39)
switch (gpio)

View File

@@ -21,9 +21,9 @@
#if defined(CONFIG_IDF_TARGET_ESP32S3)
bool AdcSampler::map_gpio_to_channel(int gpio, adc_unit_t &unit, adc_channel_t &channel)
bool AdcSampler::map_gpio_to_channel(int gpio, adc_unit_t& unit, adc_channel_t& channel)
{
unit = ADC_UNIT_1; // Only use ADC1 to avoid Wi-Fi conflict
unit = ADC_UNIT_1; // Only use ADC1 to avoid Wi-Fi conflict
// ESP32-S3: ADC1 on GPIO110 → CH0CH9
if (gpio >= 1 && gpio <= 10)
@@ -36,4 +36,4 @@ bool AdcSampler::map_gpio_to_channel(int gpio, adc_unit_t &unit, adc_channel_t &
return false;
}
#endif // CONFIG_IDF_TARGET_ESP32S3
#endif // CONFIG_IDF_TARGET_ESP32S3

View File

@@ -9,7 +9,7 @@
#include "BatteryMonitor.hpp"
#include <esp_log.h>
static const char *TAG = "[BatteryMonitor]";
static const char* TAG = "[BatteryMonitor]";
bool BatteryMonitor::setup()
{
@@ -86,8 +86,8 @@ float BatteryMonitor::voltageToPercentage(int voltage_mv)
// Linear interpolation between lookup table points
for (size_t i = 0; i < soc_lookup_.size() - 1; ++i)
{
const auto &high = soc_lookup_[i];
const auto &low = soc_lookup_[i + 1];
const auto& high = soc_lookup_[i];
const auto& low = soc_lookup_[i + 1];
if (volts <= high.voltage_mv && volts >= low.voltage_mv)
{

View File

@@ -20,7 +20,6 @@
#include "AdcSampler.hpp"
#include "sdkconfig.h"
/**
* @struct BatteryStatus
* @brief Battery status information
@@ -48,7 +47,7 @@ struct BatteryStatus
*/
class BatteryMonitor
{
public:
public:
BatteryMonitor() = default;
~BatteryMonitor() = default;
@@ -87,7 +86,7 @@ public:
#endif
}
private:
private:
/**
* @brief Li-ion/Li-Po voltage to SOC lookup table entry
*/
@@ -102,7 +101,7 @@ private:
* Based on typical 3.7V nominal Li-ion/Li-Po cell characteristics
*/
static constexpr std::array<VoltageSOC, 12> soc_lookup_ = {{
{4200.0f, 100.0f}, // Fully charged
{4200.0f, 100.0f}, // Fully charged
{4060.0f, 90.0f},
{3980.0f, 80.0f},
{3920.0f, 70.0f},
@@ -112,10 +111,10 @@ private:
{3770.0f, 30.0f},
{3740.0f, 20.0f},
{3680.0f, 10.0f},
{3450.0f, 5.0f}, // Low battery warning
{3300.0f, 0.0f}, // Empty / cutoff voltage
{3450.0f, 5.0f}, // Low battery warning
{3300.0f, 0.0f}, // Empty / cutoff voltage
}};
float scale_{1.0f}; // Voltage divider scaling factor
mutable AdcSampler adc_; // ADC sampler instance (BSP layer)
float scale_{1.0f}; // Voltage divider scaling factor
mutable AdcSampler adc_; // ADC sampler instance (BSP layer)
};

View File

@@ -9,7 +9,7 @@
#include "CurrentMonitor.hpp"
#include <esp_log.h>
static const char *TAG = "[CurrentMonitor]";
static const char* TAG = "[CurrentMonitor]";
void CurrentMonitor::setup()
{
@@ -40,7 +40,7 @@ float CurrentMonitor::getCurrentMilliAmps() const
if (!AdcSampler::isSupported())
return 0.0f;
const int shunt_milliohm = CONFIG_MONITORING_LED_SHUNT_MILLIOHM; // mΩ
const int shunt_milliohm = CONFIG_MONITORING_LED_SHUNT_MILLIOHM; // mΩ
if (shunt_milliohm <= 0)
return 0.0f;

View File

@@ -17,8 +17,8 @@
*/
#include <cstdint>
#include "sdkconfig.h"
#include "AdcSampler.hpp"
#include "sdkconfig.h"
/**
* @class CurrentMonitor
@@ -34,7 +34,7 @@
*/
class CurrentMonitor
{
public:
public:
CurrentMonitor() = default;
~CurrentMonitor() = default;
@@ -54,8 +54,8 @@ public:
#endif
}
private:
mutable AdcSampler adc_; // ADC sampler instance (BSP layer)
private:
mutable AdcSampler adc_; // ADC sampler instance (BSP layer)
};
#endif

View File

@@ -10,7 +10,7 @@
#include <esp_log.h>
#include "sdkconfig.h"
static const char *TAG = "[MonitoringManager]";
static const char* TAG = "[MonitoringManager]";
void MonitoringManager::setup()
{
@@ -18,11 +18,8 @@ void MonitoringManager::setup()
if (CurrentMonitor::isEnabled())
{
cm_.setup();
ESP_LOGI(TAG, "LED current monitoring enabled. Interval=%dms, Samples=%d, Gain=%d, R=%dmΩ",
CONFIG_MONITORING_LED_INTERVAL_MS,
CONFIG_MONITORING_LED_SAMPLES,
CONFIG_MONITORING_LED_GAIN,
CONFIG_MONITORING_LED_SHUNT_MILLIOHM);
ESP_LOGI(TAG, "LED current monitoring enabled. Interval=%dms, Samples=%d, Gain=%d, R=%dmΩ", CONFIG_MONITORING_LED_INTERVAL_MS,
CONFIG_MONITORING_LED_SAMPLES, CONFIG_MONITORING_LED_GAIN, CONFIG_MONITORING_LED_SHUNT_MILLIOHM);
}
else
{
@@ -36,11 +33,8 @@ void MonitoringManager::setup()
if (BatteryMonitor::isEnabled())
{
bm_.setup();
ESP_LOGI(TAG, "Battery monitoring enabled. Interval=%dms, Samples=%d, R-Top=%dΩ, R-Bottom=%dΩ",
CONFIG_MONITORING_BATTERY_INTERVAL_MS,
CONFIG_MONITORING_BATTERY_SAMPLES,
CONFIG_MONITORING_BATTERY_DIVIDER_R_TOP_OHM,
CONFIG_MONITORING_BATTERY_DIVIDER_R_BOTTOM_OHM);
ESP_LOGI(TAG, "Battery monitoring enabled. Interval=%dms, Samples=%d, R-Top=%dΩ, R-Bottom=%dΩ", CONFIG_MONITORING_BATTERY_INTERVAL_MS,
CONFIG_MONITORING_BATTERY_SAMPLES, CONFIG_MONITORING_BATTERY_DIVIDER_R_TOP_OHM, CONFIG_MONITORING_BATTERY_DIVIDER_R_BOTTOM_OHM);
}
else
{
@@ -77,9 +71,9 @@ 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()
@@ -105,7 +99,7 @@ void MonitoringManager::run()
while (true)
{
now_tick = xTaskGetTickCount();
TickType_t wait_ticks = pdMS_TO_TICKS(50); // Default wait time
TickType_t wait_ticks = pdMS_TO_TICKS(50); // Default wait time
#if CONFIG_MONITORING_LED_CURRENT
if (CurrentMonitor::isEnabled() && now_tick >= next_tick_led)

View File

@@ -35,7 +35,7 @@
*/
class MonitoringManager
{
public:
public:
MonitoringManager() = default;
~MonitoringManager() = default;
@@ -57,8 +57,8 @@ public:
return CurrentMonitor::isEnabled() || BatteryMonitor::isEnabled();
}
private:
static void taskEntry(void *arg);
private:
static void taskEntry(void* arg);
void run();
TaskHandle_t task_{nullptr};