Compare commits

..

6 Commits

7 changed files with 96 additions and 25 deletions

View File

@ -85,6 +85,7 @@ struct InputEvent: public Variant {
// Configuration
SetDisplayOffset,
SetDisplayLength,
LoadConfigurationByName,
SetColor,
SaveConfigurationRequest,

View File

@ -24,10 +24,10 @@ MainLoop::loop()
for(auto figmentJob: scheduler.tasks) {
if (!strcmp(figmentJob->name, evt.asString())) {
if (jobState) {
Log.trace("Starting task %s", figmentJob->name);
Log.trace("** Starting %s", figmentJob->name);
figmentJob->start();
} else {
Log.trace("Stopping task %s", figmentJob->name);
Log.trace("** Stopping %s", figmentJob->name);
figmentJob->stop();
}
}
@ -35,9 +35,7 @@ MainLoop::loop()
}
for(Task* task : scheduler) {
if (evt.intent == InputEvent::SetPower) {
Log.notice("Event %s", task->name);
}
Log.verbose("** Eventing %s", task->name);
task->handleEvent(evt);
}
}
@ -78,12 +76,14 @@ void
MainLoop::start()
{
s_instance = this;
Log.notice("Welcome to 🌕 Figment 0.3.0");
Log.notice("*** Starting %d tasks...", scheduler.tasks.size());
Serial.flush();
for(auto task: scheduler) {
Log.notice("** Starting %s", task->name);
task->start();
}
loop();
dispatch(InputEvent::ReadyToRoll);
}

View File

@ -140,7 +140,11 @@ Platform::bootSplash()
Log.trace("Registered tasks:");
auto it = beginTasks();
while (it != endTasks()) {
Log.trace((*it)->name);
if ((*it)->isFigment()) {
Log.trace(" Figment: %s", (*it)->name);
} else {
Log.trace(" %s", (*it)->name);
}
++it;
}
}

View File

@ -54,6 +54,29 @@ class Platform : public Task {
}
}
struct figment_iterator: public std::iterator<std::input_iterator_tag, Figment*> {
TaskRegistration* cur;
explicit figment_iterator() : cur(NULL) {}
explicit figment_iterator(TaskRegistration* head) : cur(head) {
while (cur && !cur->task->isFigment()) {
cur = cur->next;
}
}
figment_iterator& operator++() {
if (cur) {
do {
cur = cur->next;
} while (cur && !cur->task->isFigment());
}
return *this;
}
figment_iterator operator++(int) {figment_iterator ret = *this; ++(*this); return ret;}
bool operator==(figment_iterator other) const { return cur == other.cur; }
bool operator!=(figment_iterator other) const { return !(*this == other); }
Figment* operator*() const { return static_cast<Figment*>(cur->task); }
};
struct task_iterator: public std::iterator<std::input_iterator_tag, Task*> {
TaskRegistration* cur;
explicit task_iterator() : cur(NULL) {}
@ -71,6 +94,14 @@ class Platform : public Task {
Task* operator*() const { return cur->task; }
};
static figment_iterator beginFigments() {
return figment_iterator(firstTask);
}
static figment_iterator endFigments() {
return figment_iterator(NULL);
}
static task_iterator beginTasks() {
return task_iterator(firstTask);
}

View File

@ -0,0 +1,33 @@
#include "InputBlip.h"
InputBlip::InputBlip()
: Figment("InputBlip")
{
}
void
InputBlip::handleEvent(const InputEvent& evt)
{
if (evt.intent != InputEvent::None) {
m_time = qadd8(m_time, 5);
}
}
void
InputBlip::loop()
{
if (m_time > 0) {
m_time--;
}
}
void
InputBlip::render(Display* dpy) const
{
if (m_time > 0) {
dpy->pixelAt(0) = CRGB(0, brighten8_video(ease8InOutApprox(m_time)), 0);
}
}
STATIC_ALLOC(InputBlip);
STATIC_TASK(InputBlip);

View File

@ -0,0 +1,13 @@
#pragma once
#include "../Figments/Figments.h"
#include "../Static.h"
class InputBlip: public Figment {
public:
InputBlip();
void handleEvent(const InputEvent& evt) override;
void loop() override;
void render(Display* dpy) const override;
private:
uint8_t m_time = 0;
};

View File

@ -154,22 +154,6 @@ private:
STATIC_ALLOC(BPM);
STATIC_TASK(BPM);
// Render all layers to the displays
Renderer renderer{
{&dpy},
{
Static<ChimesAnimation>::instance(),
Static<DrainAnimation>::instance(),
Static<SolidAnimation>::instance(),
Static<Flashlight>::instance(),
Static<UpdateStatus>::instance(),
&inputBlip,
&power,
}
};
REGISTER_TASK(renderer);
Renderer configRenderer{
{&dpy},
{Static<DrainAnimation>::instance(), /*&configDisplay,*/ Static<InputBlip>::instance(), &power}
@ -460,7 +444,6 @@ void setup() {
Log.notice(u8"💡 Starting FastLED...");
Platform::addLEDs(leds, HardwareConfig::MAX_LED_NUM);
runner = new MainLoop{std::vector<Task*>{Platform::beginTasks(), Platform::endTasks()}};
// Tune in,
if (Platform::bootopts.isSafeMode) {
@ -473,11 +456,17 @@ void setup() {
//runner = &configApp;
} else {
Log.notice(u8"🌌 Starting Figment...");
// Render all layers to the displays
Renderer* renderer = new Renderer({&dpy}, std::vector<Figment*>{Platform::beginFigments(), Platform::endFigments()});
std::vector<Task*> defaultTasks{Platform::beginTasks(), Platform::endTasks()};
defaultTasks.push_back(renderer);
runner = new MainLoop{std::vector<Task*>{defaultTasks.begin(), defaultTasks.end()}};
}
Serial.flush();
runner->start();
//Log.info(u8"💽 %lu bytes of free RAM", System.freeMemory());
Log.notice(u8"💽 %lu bytes of free RAM", Platform::freeRam());
Log.notice(u8"🚀 Setup complete! Ready to rock and roll.");
Serial.flush();
}
@ -485,7 +474,7 @@ void setup() {
// Drop out.
void loop() {
EVERY_N_SECONDS(5) {
Log.notice("FPS: %d", FastLED.getFPS());
Log.notice("FPS: %d\tRAM: %d", FastLED.getFPS(), Platform::freeRam());
}
runner->loop();
}