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

ST: WS2812 LED service dev

parent d869ffff
No related branches found
No related tags found
No related merge requests found
#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;
}
}
}
}
......
#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;
};
}
}
}
#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()); }
}
}
#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();
};
}
}
......@@ -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());
}
......
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