diff --git a/CLC-qthing/SiliconTorch/Service/FxCyanF.cpp b/CLC-qthing/SiliconTorch/Service/FxCyanF.cpp index a4564dea3532cda82981123d863f3508430476b3..d85ee3b911e610a35f8eded1fe271c013ca4be05 100644 --- a/CLC-qthing/SiliconTorch/Service/FxCyanF.cpp +++ b/CLC-qthing/SiliconTorch/Service/FxCyanF.cpp @@ -1,6 +1,7 @@ #include "FxCyanF.hpp" // C++ system level +#include <cmath> // #include <cstring> // memset, strncmp // #include <cstdlib> // TODO: is this for memcpy? // #include <functional> @@ -10,6 +11,7 @@ // project specific #include <Types.hpp> +#include "SiliconTorch/FxCyanF.hpp" #include "SiliconTorch/NVSExplorer.hpp" // qthing stuff @@ -26,16 +28,69 @@ namespace SiliconTorch { setNameSpace("fxCyan"); // TODO: "FxCyanF" } + void FxCyanF::start() { - ESP_LOGW(getName().c_str(), "Starting service[ %s ] with order[ %d ] *WHOOP* *WHOOP*", getName().c_str(), getStartOrder()); + + const char* TAG = getName().c_str(); + + if (fxCyan != NULL) { + ESP_LOGW(TAG, "Service already running!"); + return; + } + + + fxCyan = new SiliconTorch::FxCyanF::FxCyanF(); + + u32 frq = SiliconTorch::FxCyanF::DefaultFrequency; + u8 res = SiliconTorch::FxCyanF::DefaultResolution; + + frq = NVSExplorer::NVSExplorer::instance().getUnsignedInt(getNameSpace(), "frequency", frq); + res = NVSExplorer::NVSExplorer::instance().getUnsignedInt(getNameSpace(), "resolution", res); + + + ESP_LOGI(TAG, "Configuring: FxCyanF{ frequency[ %d Hz ] resolution[ %d Bit ] }", frq, res); + fxCyan->setFrqRes(frq, res); + + + for (u8 ch = 0; ch < SiliconTorch::FxCyanF::MAX_CHANNELS; ch++) { + + char buffer[32]; + snprintf(buffer, 32, "ch%d_gpio", ch); + + u8 gpio = NVSExplorer::NVSExplorer::instance().getUnsignedInt(getNameSpace(), buffer, 0xFF) & 0xFF; + + snprintf(buffer, 32, "ch%d_pwm", ch); + f32 pwm = NVSExplorer::NVSExplorer::instance().getFloat(getNameSpace(), buffer); + + // NaN == "no value stored" or any other reading error + if (std::isnan(pwm)) pwm = 0.0f; + + if (gpio != 0xFF) { // key exists + + if ( fxCyan->addChannel(gpio, pwm) ) { // channel creation successful + + ESP_LOGI(TAG, "Configuring: FxCyanF{ channel[ %d ] gpio[ %d ] pwm[ %f ] }", ch, gpio, pwm); + + fxCyan->setPWM(ch, pwm); + + } else { + ESP_LOGW(TAG, "Configuring: FxCyanF{ channel[ %d ] gpio[ %d ] } FAILED[âŒ]", ch, gpio); + break; + } + + } else { + break; + } + } + + } - void FxCyanF::stop() { - ESP_LOGW(getName().c_str(), "Stopping service[ %s ] *sad service noises*", getName().c_str()); + + SiliconTorch::FxCyanF::FxCyanF* FxCyanF::getFxCyanF() const { + return fxCyan; } - // str name() { return "FxCyanF"; } - // str nameSpace() { return "fxCyan"; } // TODO: "FxCyanF" } diff --git a/CLC-qthing/SiliconTorch/Service/FxCyanF.hpp b/CLC-qthing/SiliconTorch/Service/FxCyanF.hpp index 7e6ede720f6af33a39b5b06e4e8e570fa447fbc9..b9f7d6ac63a00edef4f54f58218bcc6b46675a7d 100644 --- a/CLC-qthing/SiliconTorch/Service/FxCyanF.hpp +++ b/CLC-qthing/SiliconTorch/Service/FxCyanF.hpp @@ -11,6 +11,7 @@ // project specific #include <Types.hpp> #include "Service.hpp" +#include "SiliconTorch/FxCyanF.hpp" // qthing stuff // #include <qthing> @@ -20,6 +21,7 @@ namespace SiliconTorch { namespace Service { + class FxCyanF : public ServiceManager::Service { public: @@ -29,10 +31,12 @@ namespace SiliconTorch { void start(); - + SiliconTorch::FxCyanF::FxCyanF* getFxCyanF() const; private: + SiliconTorch::FxCyanF::FxCyanF* fxCyan = NULL; + };