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

ST: Service implementation

parent 068f773b
No related branches found
No related tags found
No related merge requests found
#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"
}
......
......@@ -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;
};
......
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