From eb4ff375805799c0ed9fdd5ef6a494c8b5f68645 Mon Sep 17 00:00:00 2001 From: Torrie Fischer Date: Sat, 18 Feb 2023 16:18:57 +0100 Subject: [PATCH] platform: auto-register figments, now that we have json config --- src/Platform.cpp | 6 +++++- src/Platform.h | 31 +++++++++++++++++++++++++++++++ src/main.cpp | 23 ++++++----------------- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/Platform.cpp b/src/Platform.cpp index b8f389e..20dcfa3 100644 --- a/src/Platform.cpp +++ b/src/Platform.cpp @@ -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; } } diff --git a/src/Platform.h b/src/Platform.h index 3989270..271955c 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -54,6 +54,29 @@ class Platform : public Task { } } + struct figment_iterator: public std::iterator { + 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(cur->task); } + }; + struct task_iterator: public std::iterator { 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); } diff --git a/src/main.cpp b/src/main.cpp index 3496dde..4b53f75 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -154,22 +154,6 @@ private: STATIC_ALLOC(BPM); STATIC_TASK(BPM); -// Render all layers to the displays -Renderer renderer{ - {&dpy}, - { - Static::instance(), - Static::instance(), - Static::instance(), - Static::instance(), - Static::instance(), - &inputBlip, - &power, - } -}; - -REGISTER_TASK(renderer); - Renderer configRenderer{ {&dpy}, {Static::instance(), /*&configDisplay,*/ Static::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{Platform::beginTasks(), Platform::endTasks()}}; // Tune in, if (Platform::bootopts.isSafeMode) { @@ -473,6 +456,12 @@ void setup() { //runner = &configApp; } else { Log.notice(u8"🌌 Starting Figment..."); + // Render all layers to the displays + Renderer* renderer = new Renderer({&dpy}, std::vector{Platform::beginFigments(), Platform::endFigments()}); + + std::vector defaultTasks{Platform::beginTasks(), Platform::endTasks()}; + defaultTasks.push_back(renderer); + runner = new MainLoop{std::vector{defaultTasks.begin(), defaultTasks.end()}}; } Serial.flush(); runner->start();