figments: figment: redefine task startup state semantics
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
This commit is contained in:
parent
b33885e9f5
commit
2848c8ad12
@ -22,16 +22,14 @@ struct Task : public virtual Loopable {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Task() {}
|
Task() {}
|
||||||
explicit Task(State initialState) : Task(0, initialState) {}
|
explicit Task(const char* name) : name(name) {}
|
||||||
explicit Task(const char* name) : Task(name, Running) {}
|
|
||||||
Task(const char* name, State initialState) : name(name), state(initialState) {}
|
|
||||||
|
|
||||||
void start() { state = Running; onStart(); }
|
void start() { state = Running; onStart(); }
|
||||||
void stop() { onStop(); state = Stopped; }
|
void stop() { onStop(); state = Stopped; }
|
||||||
virtual bool isFigment() const { return false; }
|
virtual bool isFigment() const { return false; }
|
||||||
|
|
||||||
const char* name = "";
|
const char* name = "";
|
||||||
State state = Running;
|
State state = Stopped;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TaskFunc: public Task {
|
struct TaskFunc: public Task {
|
||||||
@ -42,9 +40,7 @@ struct TaskFunc: public Task {
|
|||||||
|
|
||||||
struct Figment: public Task {
|
struct Figment: public Task {
|
||||||
Figment() : Task() {}
|
Figment() : Task() {}
|
||||||
explicit Figment(State initialState) : Task(initialState) {}
|
|
||||||
explicit Figment(const char* name) : Task(name) {}
|
explicit Figment(const char* name) : Task(name) {}
|
||||||
Figment(const char* name, State initialState) : Task(name, initialState) {}
|
|
||||||
virtual void render(Display* dpy) const = 0;
|
virtual void render(Display* dpy) const = 0;
|
||||||
bool isFigment() const override { return true; }
|
bool isFigment() const override { return true; }
|
||||||
};
|
};
|
||||||
|
@ -114,8 +114,6 @@ class InputSource: public Task {
|
|||||||
public:
|
public:
|
||||||
InputSource() : Task() {init();}
|
InputSource() : Task() {init();}
|
||||||
explicit InputSource(const char* name) : Task(name) {init();}
|
explicit InputSource(const char* name) : Task(name) {init();}
|
||||||
explicit InputSource(Task::State initialState) : Task(initialState) {init();}
|
|
||||||
InputSource(const char* name, Task::State initialState) : Task(name, initialState) {init();}
|
|
||||||
void loop() override;
|
void loop() override;
|
||||||
void onStart() override;
|
void onStart() override;
|
||||||
virtual InputEvent read() = 0;
|
virtual InputEvent read() = 0;
|
||||||
@ -134,7 +132,6 @@ class InputFunc : public InputSource {
|
|||||||
public:
|
public:
|
||||||
InputFunc(std::function<InputEvent(void)> f) : InputSource(), m_func(f) {}
|
InputFunc(std::function<InputEvent(void)> f) : InputSource(), m_func(f) {}
|
||||||
InputFunc(std::function<InputEvent(void)> f, const char* name) : InputSource(name), m_func(f) {}
|
InputFunc(std::function<InputEvent(void)> f, const char* name) : InputSource(name), m_func(f) {}
|
||||||
InputFunc(std::function<InputEvent(void)> f, const char* name, Task::State initialState) : InputSource(name, initialState), m_func(f) {}
|
|
||||||
|
|
||||||
InputEvent read() override {
|
InputEvent read() override {
|
||||||
return m_func();
|
return m_func();
|
||||||
|
@ -30,7 +30,7 @@ private:
|
|||||||
// Particle. This allows for multiple devices with wildly different displays to
|
// Particle. This allows for multiple devices with wildly different displays to
|
||||||
// run the same code
|
// run the same code
|
||||||
struct ConfigService: public Task {
|
struct ConfigService: public Task {
|
||||||
ConfigService() : Task("Configuration") {}
|
ConfigService() : Task("Configuration") {state = Task::Running;}
|
||||||
void onStart();
|
void onStart();
|
||||||
void loop() override;
|
void loop() override;
|
||||||
void handleEvent(const InputEvent &evt) override;
|
void handleEvent(const InputEvent &evt) override;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
class LogService : public Task {
|
class LogService : public Task {
|
||||||
public:
|
public:
|
||||||
LogService() : Task("Logging") {}
|
LogService() : Task("Logging") {state = Task::Running;}
|
||||||
void handleEvent(const InputEvent& event) override;
|
void handleEvent(const InputEvent& event) override;
|
||||||
void loop() override {}
|
void loop() override {}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ class Platform : public Task {
|
|||||||
static int s_timezone;
|
static int s_timezone;
|
||||||
static char s_deviceID[15];
|
static char s_deviceID[15];
|
||||||
public:
|
public:
|
||||||
Platform() : Task("Platform") {}
|
Platform() : Task("Platform") {state = Task::Running;}
|
||||||
static BootOptions bootopts;
|
static BootOptions bootopts;
|
||||||
static void setTimezone(int tz) { s_timezone = tz; }
|
static void setTimezone(int tz) { s_timezone = tz; }
|
||||||
static int getTimezone() { return s_timezone; }
|
static int getTimezone() { return s_timezone; }
|
||||||
|
@ -6,6 +6,7 @@ Sequencer::Sequencer() :
|
|||||||
Task("SceneSequencer"),
|
Task("SceneSequencer"),
|
||||||
m_idx(0)
|
m_idx(0)
|
||||||
{
|
{
|
||||||
|
state = Task::Running;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "Chimes.h"
|
#include "Chimes.h"
|
||||||
#include "../Static.h"
|
#include "../Static.h"
|
||||||
|
|
||||||
ChimesAnimation::ChimesAnimation() : Figment("Chimes", Task::Stopped) {
|
ChimesAnimation::ChimesAnimation() : Figment("Chimes") {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChimesAnimation::randomize() {
|
void ChimesAnimation::randomize() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "Drain.h"
|
#include "Drain.h"
|
||||||
#include "../Static.h"
|
#include "../Static.h"
|
||||||
|
|
||||||
DrainAnimation::DrainAnimation() : Figment("Drain", Task::Stopped) {}
|
DrainAnimation::DrainAnimation() : Figment("Drain") {}
|
||||||
|
|
||||||
void DrainAnimation::loop() {
|
void DrainAnimation::loop() {
|
||||||
EVERY_N_MILLISECONDS(8) {
|
EVERY_N_MILLISECONDS(8) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "Flashlight.h"
|
#include "Flashlight.h"
|
||||||
#include "../Static.h"
|
#include "../Static.h"
|
||||||
|
|
||||||
Flashlight::Flashlight() : Figment("Flashlight", Task::Stopped) {
|
Flashlight::Flashlight() : Figment("Flashlight") {
|
||||||
m_blobs.forEach([](Blob &blob) {
|
m_blobs.forEach([](Blob &blob) {
|
||||||
blob.setHue(random(255));
|
blob.setHue(random(255));
|
||||||
blob.setSaturation(10);
|
blob.setSaturation(10);
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
template<uint8_t MaxBrightness = 255, uint32_t MaxMilliAmps = 500, uint32_t Voltage = 5>
|
template<uint8_t MaxBrightness = 255, uint32_t MaxMilliAmps = 500, uint32_t Voltage = 5>
|
||||||
class Power: public Figment {
|
class Power: public Figment {
|
||||||
public:
|
public:
|
||||||
Power() : Figment("Power") {}
|
Power() : Figment("Power") {state = Task::Running;}
|
||||||
|
|
||||||
void handleEvent(const InputEvent& evt) override {
|
void handleEvent(const InputEvent& evt) override {
|
||||||
switch (evt.intent) {
|
switch (evt.intent) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "SolidAnimation.h"
|
#include "SolidAnimation.h"
|
||||||
#include "../Static.h"
|
#include "../Static.h"
|
||||||
|
|
||||||
SolidAnimation::SolidAnimation() : Figment("Solid", Task::Stopped) {
|
SolidAnimation::SolidAnimation() : Figment("Solid") {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SolidAnimation::randomize() {
|
void SolidAnimation::randomize() {
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
template<int Period>
|
template<int Period>
|
||||||
class ColorSequenceInput: public InputSource {
|
class ColorSequenceInput: public InputSource {
|
||||||
public:
|
public:
|
||||||
ColorSequenceInput(const std::vector<CRGB> &colors, const char* name, Task::State initialState)
|
ColorSequenceInput(const std::vector<CRGB> &colors, const char* name)
|
||||||
: InputSource(name, initialState), m_colors(colors) {}
|
: InputSource(name), m_colors(colors) {}
|
||||||
|
|
||||||
InputEvent read() override {
|
InputEvent read() override {
|
||||||
EVERY_N_SECONDS(Period) {
|
EVERY_N_SECONDS(Period) {
|
||||||
|
@ -65,7 +65,7 @@ InputFunc randomPulse([]() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return InputEvent{};
|
return InputEvent{};
|
||||||
}, "Pulse", Task::Stopped);
|
}, "Pulse");
|
||||||
|
|
||||||
REGISTER_TASK(randomPulse);
|
REGISTER_TASK(randomPulse);
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ ColorSequenceInput<9> idleCycle{{
|
|||||||
CRGB(128, 0, 128), // Purple
|
CRGB(128, 0, 128), // Purple
|
||||||
CRGB(255, 255, 255), // White
|
CRGB(255, 255, 255), // White
|
||||||
CRGB(0, 255, 255), // Cyan
|
CRGB(0, 255, 255), // Cyan
|
||||||
}, "IdleColors", Task::Stopped};
|
}, "IdleColors"};
|
||||||
|
|
||||||
REGISTER_TASK(idleCycle);
|
REGISTER_TASK(idleCycle);
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ ColorSequenceInput<7> rainbowCycle{{
|
|||||||
CRGB(0, 255, 0), // Green
|
CRGB(0, 255, 0), // Green
|
||||||
CRGB(0, 0, 255), // Blue
|
CRGB(0, 0, 255), // Blue
|
||||||
CRGB(128, 0, 128), // Purple
|
CRGB(128, 0, 128), // Purple
|
||||||
}, "Rainbow", Task::Stopped};
|
}, "Rainbow"};
|
||||||
|
|
||||||
REGISTER_TASK(rainbowCycle);
|
REGISTER_TASK(rainbowCycle);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user