From 2848c8ad12dff42bb34c3896ce0c26400edafd8c Mon Sep 17 00:00:00 2001 From: Torrie Fischer Date: Sat, 18 Feb 2023 16:33:09 +0100 Subject: [PATCH] figments: figment: redefine task startup state semantics --- lib/Figments/Figment.h | 8 ++------ lib/Figments/Input.h | 3 --- src/Config.h | 2 +- src/LogService.h | 2 +- src/Platform.h | 2 +- src/Sequencer.cpp | 1 + src/animations/Chimes.cpp | 2 +- src/animations/Drain.cpp | 2 +- src/animations/Flashlight.cpp | 2 +- src/animations/Power.h | 2 +- src/animations/SolidAnimation.cpp | 2 +- src/inputs/ColorCycle.h | 4 ++-- src/main.cpp | 6 +++--- 13 files changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/Figments/Figment.h b/lib/Figments/Figment.h index 4da9659..c19734a 100644 --- a/lib/Figments/Figment.h +++ b/lib/Figments/Figment.h @@ -22,16 +22,14 @@ struct Task : public virtual Loopable { }; Task() {} - explicit Task(State initialState) : Task(0, initialState) {} - explicit Task(const char* name) : Task(name, Running) {} - Task(const char* name, State initialState) : name(name), state(initialState) {} + explicit Task(const char* name) : name(name) {} void start() { state = Running; onStart(); } void stop() { onStop(); state = Stopped; } virtual bool isFigment() const { return false; } const char* name = ""; - State state = Running; + State state = Stopped; }; struct TaskFunc: public Task { @@ -42,9 +40,7 @@ struct TaskFunc: public Task { struct Figment: public Task { Figment() : Task() {} - explicit Figment(State initialState) : Task(initialState) {} explicit Figment(const char* name) : Task(name) {} - Figment(const char* name, State initialState) : Task(name, initialState) {} virtual void render(Display* dpy) const = 0; bool isFigment() const override { return true; } }; diff --git a/lib/Figments/Input.h b/lib/Figments/Input.h index af8d4f6..242ea18 100644 --- a/lib/Figments/Input.h +++ b/lib/Figments/Input.h @@ -114,8 +114,6 @@ class InputSource: public Task { public: InputSource() : Task() {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 onStart() override; virtual InputEvent read() = 0; @@ -134,7 +132,6 @@ class InputFunc : public InputSource { public: InputFunc(std::function f) : InputSource(), m_func(f) {} InputFunc(std::function f, const char* name) : InputSource(name), m_func(f) {} - InputFunc(std::function f, const char* name, Task::State initialState) : InputSource(name, initialState), m_func(f) {} InputEvent read() override { return m_func(); diff --git a/src/Config.h b/src/Config.h index b158c8a..e98ac1a 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ private: // Particle. This allows for multiple devices with wildly different displays to // run the same code struct ConfigService: public Task { - ConfigService() : Task("Configuration") {} + ConfigService() : Task("Configuration") {state = Task::Running;} void onStart(); void loop() override; void handleEvent(const InputEvent &evt) override; diff --git a/src/LogService.h b/src/LogService.h index 129c1bc..cdb2c82 100644 --- a/src/LogService.h +++ b/src/LogService.h @@ -2,7 +2,7 @@ class LogService : public Task { public: - LogService() : Task("Logging") {} + LogService() : Task("Logging") {state = Task::Running;} void handleEvent(const InputEvent& event) override; void loop() override {} diff --git a/src/Platform.h b/src/Platform.h index 271955c..2cde7e2 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -7,7 +7,7 @@ class Platform : public Task { static int s_timezone; static char s_deviceID[15]; public: - Platform() : Task("Platform") {} + Platform() : Task("Platform") {state = Task::Running;} static BootOptions bootopts; static void setTimezone(int tz) { s_timezone = tz; } static int getTimezone() { return s_timezone; } diff --git a/src/Sequencer.cpp b/src/Sequencer.cpp index a62b9a2..5d6ef7a 100644 --- a/src/Sequencer.cpp +++ b/src/Sequencer.cpp @@ -6,6 +6,7 @@ Sequencer::Sequencer() : Task("SceneSequencer"), m_idx(0) { + state = Task::Running; } void diff --git a/src/animations/Chimes.cpp b/src/animations/Chimes.cpp index 1babca9..f31c84f 100644 --- a/src/animations/Chimes.cpp +++ b/src/animations/Chimes.cpp @@ -1,7 +1,7 @@ #include "Chimes.h" #include "../Static.h" -ChimesAnimation::ChimesAnimation() : Figment("Chimes", Task::Stopped) { +ChimesAnimation::ChimesAnimation() : Figment("Chimes") { } void ChimesAnimation::randomize() { diff --git a/src/animations/Drain.cpp b/src/animations/Drain.cpp index a9ab2fa..cc45d95 100644 --- a/src/animations/Drain.cpp +++ b/src/animations/Drain.cpp @@ -1,7 +1,7 @@ #include "Drain.h" #include "../Static.h" -DrainAnimation::DrainAnimation() : Figment("Drain", Task::Stopped) {} +DrainAnimation::DrainAnimation() : Figment("Drain") {} void DrainAnimation::loop() { EVERY_N_MILLISECONDS(8) { diff --git a/src/animations/Flashlight.cpp b/src/animations/Flashlight.cpp index c7d458a..3564ff1 100644 --- a/src/animations/Flashlight.cpp +++ b/src/animations/Flashlight.cpp @@ -1,7 +1,7 @@ #include "Flashlight.h" #include "../Static.h" -Flashlight::Flashlight() : Figment("Flashlight", Task::Stopped) { +Flashlight::Flashlight() : Figment("Flashlight") { m_blobs.forEach([](Blob &blob) { blob.setHue(random(255)); blob.setSaturation(10); diff --git a/src/animations/Power.h b/src/animations/Power.h index 5422ba9..b1c404c 100644 --- a/src/animations/Power.h +++ b/src/animations/Power.h @@ -4,7 +4,7 @@ template class Power: public Figment { public: - Power() : Figment("Power") {} + Power() : Figment("Power") {state = Task::Running;} void handleEvent(const InputEvent& evt) override { switch (evt.intent) { diff --git a/src/animations/SolidAnimation.cpp b/src/animations/SolidAnimation.cpp index 7964053..8de1289 100644 --- a/src/animations/SolidAnimation.cpp +++ b/src/animations/SolidAnimation.cpp @@ -1,7 +1,7 @@ #include "SolidAnimation.h" #include "../Static.h" -SolidAnimation::SolidAnimation() : Figment("Solid", Task::Stopped) { +SolidAnimation::SolidAnimation() : Figment("Solid") { } void SolidAnimation::randomize() { diff --git a/src/inputs/ColorCycle.h b/src/inputs/ColorCycle.h index c220e8b..3a0ab24 100644 --- a/src/inputs/ColorCycle.h +++ b/src/inputs/ColorCycle.h @@ -4,8 +4,8 @@ template class ColorSequenceInput: public InputSource { public: - ColorSequenceInput(const std::vector &colors, const char* name, Task::State initialState) - : InputSource(name, initialState), m_colors(colors) {} + ColorSequenceInput(const std::vector &colors, const char* name) + : InputSource(name), m_colors(colors) {} InputEvent read() override { EVERY_N_SECONDS(Period) { diff --git a/src/main.cpp b/src/main.cpp index e1735f4..facb15a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -65,7 +65,7 @@ InputFunc randomPulse([]() { } } return InputEvent{}; -}, "Pulse", Task::Stopped); +}, "Pulse"); REGISTER_TASK(randomPulse); @@ -157,7 +157,7 @@ ColorSequenceInput<9> idleCycle{{ CRGB(128, 0, 128), // Purple CRGB(255, 255, 255), // White CRGB(0, 255, 255), // Cyan -}, "IdleColors", Task::Stopped}; +}, "IdleColors"}; REGISTER_TASK(idleCycle); @@ -167,7 +167,7 @@ ColorSequenceInput<7> rainbowCycle{{ CRGB(0, 255, 0), // Green CRGB(0, 0, 255), // Blue CRGB(128, 0, 128), // Purple -}, "Rainbow", Task::Stopped}; +}, "Rainbow"}; REGISTER_TASK(rainbowCycle);