diff --git a/CLC-qthing/SiliconTorch/Service/CyanStripe.cpp b/CLC-qthing/SiliconTorch/Service/CyanStripe.cpp index 62ae82176297a4ad0cf3abaabfb6a7d5fba77eb3..db4cd4b056b6b5e15c164babe7ee065dfcb270cc 100644 --- a/CLC-qthing/SiliconTorch/Service/CyanStripe.cpp +++ b/CLC-qthing/SiliconTorch/Service/CyanStripe.cpp @@ -1,19 +1,20 @@ #include "CyanStripe.hpp" // C++ system level -// #include <cstring> // memset, strncmp -// #include <cstdlib> // TODO: is this for memcpy? +#include <cstdio> // sprintf // #include <functional> // ESP32 specific #include "esp_log.h" +#include "driver/gpio.h" // project specific #include <Types.hpp> #include "SiliconTorch/NVSExplorer.hpp" // qthing stuff -// #include <qthing> +#include <qthing> +#include "SiliconTorch/FxCyanRGB8.hpp" @@ -24,12 +25,11 @@ - //cyanBus = new SiliconTorch::CyanBus::CyanBus(13, 14, 12, 15, 2000000); // Pinout of CyanStripe /* auto led0 = cfg.add<qthing::leds::WS2812B_V3>(GPIO_NUM_27, 8); - cyanRGB = new SiliconTorch::FxCyanRGB8::FxCyanRGB8(8); + cyanRGB = new SiliconTorch::CyanStripe::CyanStripe(8); cyanRGB->registerUDPHandler(); cyanRGB->registerAtCyanBus(*cyanBus); @@ -39,26 +39,83 @@ +namespace SiliconTorch { + namespace Service { + namespace CyanStripe { + void CyanStripe::init() { + setName("CyanStripe"); + setNameSpace("CyanStripe"); + addWantedService("CyanBus"); + } -namespace SiliconTorch { + void CyanStripe::start() { - namespace Service { + for (u8 idx = 0; idx < MAX_CHANNELS; idx++) { - void CyanStripe::init() { - setName("CyanStripe"); - setNameSpace("CyanStripe"); // TODO: "FxCyanF" - } + ChannelInfo info = readChannelData(idx); + + if (!info.valid) break; + + ESP_LOGI(getName().c_str(), "Configuring: FxCyanRGB8{ info[ %d ] gpio[ %d ] leds[ %d ] startIdx[ %d ] }", idx, info.gpio, info.leds, info.startIdx); + + + ChannelDriver channel = { + .info = info, + .cyanRGB = new SiliconTorch::FxCyanRGB8::FxCyanRGB8(info.leds, info.startIdx) + }; + + channels.push_back(channel); + + channel.cyanRGB->registerUDPHandler(); + + // TODO: Get CyanBus from ServiceManager if it exists + // channel.cyanRGB->registerAtCyanBus(*cyanBus); + } + + } - void CyanStripe::start() { - ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); - } + void CyanStripe::configureQthingLEDs(qthing::Config* cfg) const { + for (const auto& channel : channels) { + // TODO: Sadly this is a block of *ughh* which we can't write any better :/ + + auto leds = cfg->add<qthing::leds::WS2812B_V3>((gpio_num_t)(channel.info.gpio), channel.info.leds); + auto bullshitPtr = std::shared_ptr<qthing::Animation<qthing::RGB>>(channel.cyanRGB, [](void*){}); + cfg->add<qthing::Animator<qthing::RGBW8>>(leds)->setAnimation(bullshitPtr); + } + } + + + ChannelInfo CyanStripe::readChannelData(u8 channel) const { + + NVSExplorer::NVSExplorer& nvs = NVSExplorer::NVSExplorer::instance(); + + ChannelInfo ch; + + char tmp[32]; + + std::snprintf(tmp, sizeof(tmp), "ch%d_gpio", channel); + ch.gpio = nvs.getUnsignedInt(getNameSpace(), std::string(tmp), 0xFF); + + std::snprintf(tmp, sizeof(tmp), "ch%d_leds", channel); + ch.leds = nvs.getUnsignedInt(getNameSpace(), std::string(tmp), 0); + + std::snprintf(tmp, sizeof(tmp), "ch%d_startIdx", channel); + ch.startIdx = nvs.getUnsignedInt(getNameSpace(), std::string(tmp), 0); + + ch.valid = ch.gpio < 0xFF && ch.leds > 0; + + return ch; + } + + + } } } diff --git a/CLC-qthing/SiliconTorch/Service/CyanStripe.hpp b/CLC-qthing/SiliconTorch/Service/CyanStripe.hpp index 9dc3065a62f17a02ec14d4c079896cec5f6b2371..ba69c00a60ee835a1f5c4d5a3702df7cfcfd0e79 100644 --- a/CLC-qthing/SiliconTorch/Service/CyanStripe.hpp +++ b/CLC-qthing/SiliconTorch/Service/CyanStripe.hpp @@ -1,6 +1,7 @@ #pragma once // C++ system level +#include <vector> // #include <cstring> // memset, strncmp // #include <cstdlib> // TODO: is this for memcpy? // #include <functional> @@ -13,6 +14,7 @@ #include "Service.hpp" // qthing stuff +#include "SiliconTorch/FxCyanRGB8.hpp" // #include <qthing> @@ -20,21 +22,58 @@ namespace SiliconTorch { namespace Service { - class CyanStripe : public ServiceManager::Service { + namespace CyanStripe { - public: + constexpr u8 MAX_CHANNELS = 8; - void init(); + typedef struct { - void start(); + u8 gpio = 0; + u16 leds = 0; + u16 startIdx = 0; + bool valid = false; + } ChannelInfo; - private: + typedef struct { + ChannelInfo info; + SiliconTorch::FxCyanRGB8::FxCyanRGB8* cyanRGB; - }; + } ChannelDriver; + + + class CyanStripe : public ServiceManager::Service { + + public: + + + void init(); + + void start(); + + + ChannelInfo readChannelData(u8 channel) const; // Read data from NVS + + // TODO: replace with our own LED driver! + void configureQthingLEDs(qthing::Config* cfg) const; + + + // TODO: should we block copy/assignment by default…? + CyanStripe() {}; + CyanStripe(const CyanStripe&) = delete; + CyanStripe& operator=(CyanStripe const&) = delete; + + private: + + std::vector<ChannelDriver> channels; + + + }; + + } } } diff --git a/CLC-qthing/SiliconTorch/Service/TestServices.cpp b/CLC-qthing/SiliconTorch/Service/TestServices.cpp deleted file mode 100644 index 74c18d8cf6a3b4b7f9690f213927b22f487ab355..0000000000000000000000000000000000000000 --- a/CLC-qthing/SiliconTorch/Service/TestServices.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "TestServices.hpp" - -// C++ system level -// #include <cstring> // memset, strncmp -// #include <cstdlib> // TODO: is this for memcpy? -// #include <functional> - -// ESP32 specific -#include "esp_log.h" - -// project specific -#include <Types.hpp> -#include "SiliconTorch/NVSExplorer.hpp" - -// qthing stuff -// #include <qthing> - - - -namespace SiliconTorch { - - namespace Service { - - - void Cycle0::init() { - - addRequiredService("Cycle1"); - - setName("Cycle0"); - setNameSpace("Cycle0"); - } - - void Cycle0::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); } - - - - void Cycle1::init() { - - addRequiredService("Cycle0"); - - setName("Cycle1"); - setNameSpace("Cycle1"); - } - - void Cycle1::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); } - - - - - - void AAA::init() { - setName("AAA"); - setNameSpace("AAA"); - } - - void AAA::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); } - - void BBB::init() { - - addRequiredService("AAA"); - - setName("BBB"); - setNameSpace("BBB"); - } - - void BBB::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); } - - void CCC::init() { - - addRequiredService("BBB"); - - setName("CCC"); - setNameSpace("CCC"); - } - - void CCC::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); } - - void WantsAAA::init() { - - addWantedService("AAA"); - - setName("WantsAAA"); - setNameSpace("WantsAAA"); - } - - void WantsAAA::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); } - - - void ABC::init() { - - addRequiredService("AAA"); - addRequiredService("BBB"); - addRequiredService("CCC"); - - setName("ABC"); - setNameSpace("ABC"); - } - - void ABC::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); } - - void ABCD::init() { - - addWantedService("AAA"); - addRequiredService("BBB"); - addRequiredService("CCC"); - addRequiredService("ABC"); - - setName("ABCD"); - setNameSpace("ABCD"); - } - - void ABCD::start() {ESP_LOGW(getName().c_str(), "Starting service[ %s ] *WHOOP* *WHOOP*", getName().c_str()); } - - - - - } -} diff --git a/CLC-qthing/SiliconTorch/Service/TestServices.hpp b/CLC-qthing/SiliconTorch/Service/TestServices.hpp deleted file mode 100644 index 5322fd32abd06be492ee514673131f802fb90da0..0000000000000000000000000000000000000000 --- a/CLC-qthing/SiliconTorch/Service/TestServices.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once - -// C++ system level -// #include <cstring> // memset, strncmp -// #include <cstdlib> // TODO: is this for memcpy? -// #include <functional> - -// ESP32 specific -#include "esp_log.h" - -// project specific -#include <Types.hpp> -#include "Service.hpp" - -// qthing stuff -// #include <qthing> - - -namespace SiliconTorch { - - namespace Service { - - class Cycle0 : public ServiceManager::Service { - public: - void init(); - void start(); - }; - - class Cycle1 : public ServiceManager::Service { - public: - void init(); - void start(); - }; - - - class AAA : public ServiceManager::Service { - public: - void init(); - void start(); - }; - - class BBB : public ServiceManager::Service { - public: - void init(); - void start(); - }; - - class CCC : public ServiceManager::Service { - public: - void init(); - void start(); - }; - - class WantsAAA : public ServiceManager::Service { - public: - void init(); - void start(); - }; - - class ABC : public ServiceManager::Service { - public: - void init(); - void start(); - }; - - class ABCD : public ServiceManager::Service { - public: - void init(); - void start(); - }; - - - } -} diff --git a/CLC-qthing/SiliconTorch/Service/__services__.cpp b/CLC-qthing/SiliconTorch/Service/__services__.cpp index c9110871e47694426893fb54e14a89c0b72b72a2..def22a373d801058aebd3c935e8b2b118a8211fa 100644 --- a/CLC-qthing/SiliconTorch/Service/__services__.cpp +++ b/CLC-qthing/SiliconTorch/Service/__services__.cpp @@ -6,7 +6,6 @@ #include "CyanStripe.hpp" -#include "TestServices.hpp" namespace SiliconTorch { @@ -17,18 +16,7 @@ namespace SiliconTorch { mgr->registerService(new SiliconTorch::Service::FxCyanF()); mgr->registerService(new SiliconTorch::Service::FxPublish()); - mgr->registerService(new SiliconTorch::Service::CyanStripe()); - - - mgr->registerService(new SiliconTorch::Service::ABC()); - mgr->registerService(new SiliconTorch::Service::ABCD()); - mgr->registerService(new SiliconTorch::Service::Cycle0()); - mgr->registerService(new SiliconTorch::Service::Cycle1()); - mgr->registerService(new SiliconTorch::Service::AAA()); - mgr->registerService(new SiliconTorch::Service::BBB()); - mgr->registerService(new SiliconTorch::Service::CCC()); - mgr->registerService(new SiliconTorch::Service::WantsAAA()); - + mgr->registerService(new SiliconTorch::Service::CyanStripe::CyanStripe()); }