diff --git a/CLC-qthing/SiliconTorch/FxCyanF-configureFromNVS.cpp b/CLC-qthing/SiliconTorch/FxCyanF-configureFromNVS.cpp index aa15ee37d85ae7eae7bb2906cb3505a62c9f9c6e..49e83fd52a7685847586fb3360b25381630633cc 100644 --- a/CLC-qthing/SiliconTorch/FxCyanF-configureFromNVS.cpp +++ b/CLC-qthing/SiliconTorch/FxCyanF-configureFromNVS.cpp @@ -22,6 +22,8 @@ #include <SpiderLib/ObjectTypes.hpp> +const char* TAG_nvs = "FxCyanF-NVS"; + namespace SiliconTorch { @@ -31,23 +33,19 @@ namespace SiliconTorch { const str ServiceNamespace = "fxCyan"; - bool configureFromNVS(FxCyanF& target) { - - if (target.getChannelCount() > 0) { - ESP_LOGW(TAG, "Target mustn't have any channels configured"); - return false; - } - + FxCyanF* configureFromNVS() { u8 state = 0; // disabled -> 0 enabled -> 1 state = NVSExplorer::NVSExplorer::instance().getUnsignedInt(ServiceNamespace, "state", state); if (state == 0) { - ESP_LOGI(TAG, "Service[ FxCyanF ] disabled[]"); - return false; + ESP_LOGI(TAG_nvs, "Service[ FxCyanF ] disabled[âŒ]"); + return NULL; } - ESP_LOGI(TAG, "Enabling Service[ FxCyanF ]"); + FxCyanF* target = new FxCyanF(); + + ESP_LOGI(TAG_nvs, "Service[ FxCyanF ] enabling[✅]…"); u32 frq = DefaultFrequency; u8 res = DefaultResolution; @@ -56,8 +54,8 @@ namespace SiliconTorch { res = NVSExplorer::NVSExplorer::instance().getUnsignedInt(ServiceNamespace, "resolution", res); - ESP_LOGI(TAG, "Configuring: FxCyanF{ frequency[ %d Hz ] resolution[ %d Bit ] }", frq, res); - target.setFrqRes(frq, res); + ESP_LOGI(TAG_nvs, "Configuring: FxCyanF{ frequency[ %d Hz ] resolution[ %d Bit ] }", frq, res); + target->setFrqRes(frq, res); for (u8 ch = 0; ch < MAX_CHANNELS; ch++) { @@ -73,20 +71,25 @@ namespace SiliconTorch { // NaN == "no value stored" or any other reading error if (std::isnan(pwm)) pwm = 0.0f; - if (gpio != 0xFF) { + if (gpio != 0xFF) { // key exists - bool result = target.addChannel(gpio, pwm); + if ( target->addChannel(gpio, pwm) ) { // channel creation successful + + ESP_LOGI(TAG_nvs, "Configuring: FxCyanF{ channel[ %d ] gpio[ %d ] pwm[ %f ] }", ch, gpio, pwm); - // TODO: do something with result…? + target->setPWM(ch, pwm); - ESP_LOGI(TAG, "Configuring: FxCyanF{ channel[ %d ] gpio[ %d ] pwm[ %f ] }", ch, gpio, pwm); + } else { + ESP_LOGW(TAG_nvs, "Configuring: FxCyanF{ channel[ %d ] gpio[ %d ] } FAILED[âŒ]", ch, gpio); + break; + } } else { break; } } - return true; + return target; } diff --git a/CLC-qthing/SiliconTorch/FxCyanF.hpp b/CLC-qthing/SiliconTorch/FxCyanF.hpp index 52c84273e888a3e247166e10ec4cc8780281ab95..0a7d19e39b619c0db12e4e0d14912f008d5f7d30 100644 --- a/CLC-qthing/SiliconTorch/FxCyanF.hpp +++ b/CLC-qthing/SiliconTorch/FxCyanF.hpp @@ -98,7 +98,7 @@ namespace SiliconTorch { }; - bool configureFromNVS(FxCyanF& target); + FxCyanF* configureFromNVS(FxCyanF); } }