Skip to content
Snippets Groups Projects
Commit e7feceb5 authored by fxk8y's avatar fxk8y :spider:
Browse files

Better API; fixing bugs; loading default PWM value from NVS by now

parent ee48c49e
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include <SpiderLib/ObjectTypes.hpp> #include <SpiderLib/ObjectTypes.hpp>
const char* TAG_nvs = "FxCyanF-NVS";
namespace SiliconTorch { namespace SiliconTorch {
...@@ -31,23 +33,19 @@ namespace SiliconTorch { ...@@ -31,23 +33,19 @@ namespace SiliconTorch {
const str ServiceNamespace = "fxCyan"; const str ServiceNamespace = "fxCyan";
bool configureFromNVS(FxCyanF& target) { FxCyanF* configureFromNVS() {
if (target.getChannelCount() > 0) {
ESP_LOGW(TAG, "Target mustn't have any channels configured");
return false;
}
u8 state = 0; // disabled -> 0 enabled -> 1 u8 state = 0; // disabled -> 0 enabled -> 1
state = NVSExplorer::NVSExplorer::instance().getUnsignedInt(ServiceNamespace, "state", state); state = NVSExplorer::NVSExplorer::instance().getUnsignedInt(ServiceNamespace, "state", state);
if (state == 0) { if (state == 0) {
ESP_LOGI(TAG, "Service[ FxCyanF ] disabled[]"); ESP_LOGI(TAG_nvs, "Service[ FxCyanF ] disabled[]");
return false; return NULL;
} }
ESP_LOGI(TAG, "Enabling Service[ FxCyanF ]"); FxCyanF* target = new FxCyanF();
ESP_LOGI(TAG_nvs, "Service[ FxCyanF ] enabling[✅]…");
u32 frq = DefaultFrequency; u32 frq = DefaultFrequency;
u8 res = DefaultResolution; u8 res = DefaultResolution;
...@@ -56,8 +54,8 @@ namespace SiliconTorch { ...@@ -56,8 +54,8 @@ namespace SiliconTorch {
res = NVSExplorer::NVSExplorer::instance().getUnsignedInt(ServiceNamespace, "resolution", res); res = NVSExplorer::NVSExplorer::instance().getUnsignedInt(ServiceNamespace, "resolution", res);
ESP_LOGI(TAG, "Configuring: FxCyanF{ frequency[ %d Hz ] resolution[ %d Bit ] }", frq, res); ESP_LOGI(TAG_nvs, "Configuring: FxCyanF{ frequency[ %d Hz ] resolution[ %d Bit ] }", frq, res);
target.setFrqRes(frq, res); target->setFrqRes(frq, res);
for (u8 ch = 0; ch < MAX_CHANNELS; ch++) { for (u8 ch = 0; ch < MAX_CHANNELS; ch++) {
...@@ -73,20 +71,25 @@ namespace SiliconTorch { ...@@ -73,20 +71,25 @@ namespace SiliconTorch {
// NaN == "no value stored" or any other reading error // NaN == "no value stored" or any other reading error
if (std::isnan(pwm)) pwm = 0.0f; 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 { } else {
break; break;
} }
} }
return true; return target;
} }
......
...@@ -98,7 +98,7 @@ namespace SiliconTorch { ...@@ -98,7 +98,7 @@ namespace SiliconTorch {
}; };
bool configureFromNVS(FxCyanF& target); FxCyanF* configureFromNVS(FxCyanF);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment