Compare commits
No commits in common. "9b1600f00bc2481ea31c31017b47127dbd1a877b" and "f0abdc05676037770b81a17fc54b1d843293f458" have entirely different histories.
9b1600f00b
...
f0abdc0567
@ -85,7 +85,6 @@ struct InputEvent: public Variant {
|
|||||||
// Configuration
|
// Configuration
|
||||||
SetDisplayOffset,
|
SetDisplayOffset,
|
||||||
SetDisplayLength,
|
SetDisplayLength,
|
||||||
LoadConfigurationByName,
|
|
||||||
SetColor,
|
SetColor,
|
||||||
SaveConfigurationRequest,
|
SaveConfigurationRequest,
|
||||||
|
|
||||||
|
@ -24,10 +24,10 @@ MainLoop::loop()
|
|||||||
for(auto figmentJob: scheduler.tasks) {
|
for(auto figmentJob: scheduler.tasks) {
|
||||||
if (!strcmp(figmentJob->name, evt.asString())) {
|
if (!strcmp(figmentJob->name, evt.asString())) {
|
||||||
if (jobState) {
|
if (jobState) {
|
||||||
Log.trace("** Starting %s", figmentJob->name);
|
Log.trace("Starting task %s", figmentJob->name);
|
||||||
figmentJob->start();
|
figmentJob->start();
|
||||||
} else {
|
} else {
|
||||||
Log.trace("** Stopping %s", figmentJob->name);
|
Log.trace("Stopping task %s", figmentJob->name);
|
||||||
figmentJob->stop();
|
figmentJob->stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,7 +35,9 @@ MainLoop::loop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(Task* task : scheduler) {
|
for(Task* task : scheduler) {
|
||||||
Log.verbose("** Eventing %s", task->name);
|
if (evt.intent == InputEvent::SetPower) {
|
||||||
|
Log.notice("Event %s", task->name);
|
||||||
|
}
|
||||||
task->handleEvent(evt);
|
task->handleEvent(evt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,14 +78,12 @@ void
|
|||||||
MainLoop::start()
|
MainLoop::start()
|
||||||
{
|
{
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
Log.notice("Welcome to 🌕 Figment 0.3.0");
|
|
||||||
Log.notice("*** Starting %d tasks...", scheduler.tasks.size());
|
Log.notice("*** Starting %d tasks...", scheduler.tasks.size());
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
for(auto task: scheduler) {
|
for(auto task: scheduler) {
|
||||||
Log.notice("** Starting %s", task->name);
|
Log.notice("** Starting %s", task->name);
|
||||||
task->start();
|
task->start();
|
||||||
}
|
}
|
||||||
loop();
|
|
||||||
dispatch(InputEvent::ReadyToRoll);
|
dispatch(InputEvent::ReadyToRoll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,11 +140,7 @@ Platform::bootSplash()
|
|||||||
Log.trace("Registered tasks:");
|
Log.trace("Registered tasks:");
|
||||||
auto it = beginTasks();
|
auto it = beginTasks();
|
||||||
while (it != endTasks()) {
|
while (it != endTasks()) {
|
||||||
if ((*it)->isFigment()) {
|
Log.trace((*it)->name);
|
||||||
Log.trace(" Figment: %s", (*it)->name);
|
|
||||||
} else {
|
|
||||||
Log.trace(" %s", (*it)->name);
|
|
||||||
}
|
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,29 +54,6 @@ 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*> {
|
struct task_iterator: public std::iterator<std::input_iterator_tag, Task*> {
|
||||||
TaskRegistration* cur;
|
TaskRegistration* cur;
|
||||||
explicit task_iterator() : cur(NULL) {}
|
explicit task_iterator() : cur(NULL) {}
|
||||||
@ -94,14 +71,6 @@ class Platform : public Task {
|
|||||||
Task* operator*() const { return cur->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() {
|
static task_iterator beginTasks() {
|
||||||
return task_iterator(firstTask);
|
return task_iterator(firstTask);
|
||||||
}
|
}
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
#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);
|
|
@ -1,13 +0,0 @@
|
|||||||
#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;
|
|
||||||
};
|
|
27
src/main.cpp
27
src/main.cpp
@ -154,6 +154,22 @@ private:
|
|||||||
STATIC_ALLOC(BPM);
|
STATIC_ALLOC(BPM);
|
||||||
STATIC_TASK(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{
|
Renderer configRenderer{
|
||||||
{&dpy},
|
{&dpy},
|
||||||
{Static<DrainAnimation>::instance(), /*&configDisplay,*/ Static<InputBlip>::instance(), &power}
|
{Static<DrainAnimation>::instance(), /*&configDisplay,*/ Static<InputBlip>::instance(), &power}
|
||||||
@ -444,6 +460,7 @@ void setup() {
|
|||||||
|
|
||||||
Log.notice(u8"💡 Starting FastLED...");
|
Log.notice(u8"💡 Starting FastLED...");
|
||||||
Platform::addLEDs(leds, HardwareConfig::MAX_LED_NUM);
|
Platform::addLEDs(leds, HardwareConfig::MAX_LED_NUM);
|
||||||
|
runner = new MainLoop{std::vector<Task*>{Platform::beginTasks(), Platform::endTasks()}};
|
||||||
|
|
||||||
// Tune in,
|
// Tune in,
|
||||||
if (Platform::bootopts.isSafeMode) {
|
if (Platform::bootopts.isSafeMode) {
|
||||||
@ -456,17 +473,11 @@ void setup() {
|
|||||||
//runner = &configApp;
|
//runner = &configApp;
|
||||||
} else {
|
} else {
|
||||||
Log.notice(u8"🌌 Starting Figment...");
|
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();
|
Serial.flush();
|
||||||
runner->start();
|
runner->start();
|
||||||
|
|
||||||
Log.notice(u8"💽 %lu bytes of free RAM", Platform::freeRam());
|
//Log.info(u8"💽 %lu bytes of free RAM", System.freeMemory());
|
||||||
Log.notice(u8"🚀 Setup complete! Ready to rock and roll.");
|
Log.notice(u8"🚀 Setup complete! Ready to rock and roll.");
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
}
|
}
|
||||||
@ -474,7 +485,7 @@ void setup() {
|
|||||||
// Drop out.
|
// Drop out.
|
||||||
void loop() {
|
void loop() {
|
||||||
EVERY_N_SECONDS(5) {
|
EVERY_N_SECONDS(5) {
|
||||||
Log.notice("FPS: %d\tRAM: %d", FastLED.getFPS(), Platform::freeRam());
|
Log.notice("FPS: %d", FastLED.getFPS());
|
||||||
}
|
}
|
||||||
runner->loop();
|
runner->loop();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user