update
This commit is contained in:
@ -6,9 +6,12 @@ class Display;
|
||||
class InputEvent;
|
||||
class InputSource;
|
||||
|
||||
struct Task {
|
||||
struct Loopable {
|
||||
virtual void handleEvent(const InputEvent& event) {}
|
||||
virtual void loop() = 0;
|
||||
};
|
||||
|
||||
struct Task : public virtual Loopable {
|
||||
virtual void onStart() {};
|
||||
virtual void onStop() {};
|
||||
|
||||
@ -24,6 +27,7 @@ struct Task {
|
||||
|
||||
void start() { Log.info("* Starting %s...", name); state = Running; onStart(); }
|
||||
void stop() { Log.info("* Stopping %s...", name); onStop(); state = Stopped; }
|
||||
virtual bool isFigment() const { return false; }
|
||||
|
||||
const char* name = 0;
|
||||
State state = Running;
|
||||
@ -35,6 +39,7 @@ struct Figment: public Task {
|
||||
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; }
|
||||
};
|
||||
|
||||
struct FigmentFunc: public Figment {
|
||||
|
@ -39,3 +39,9 @@ BufferedInputSource::setEvent(InputEvent &&evt)
|
||||
{
|
||||
m_lastEvent = std::move(evt);
|
||||
}
|
||||
|
||||
void
|
||||
BufferedInputSource::setEvent(InputEvent::Intent intent, Variant &&v)
|
||||
{
|
||||
m_lastEvent = InputEvent{intent, std::move(v)};
|
||||
}
|
||||
|
@ -42,20 +42,50 @@ private:
|
||||
|
||||
struct InputEvent: public Variant {
|
||||
enum Intent {
|
||||
// An empty non-event
|
||||
None,
|
||||
|
||||
// An input from the user, for other tasks to translate into canonical
|
||||
// types. Makes for easy button re-mapping on the fly.
|
||||
UserInput,
|
||||
|
||||
//
|
||||
// The canonical types
|
||||
//
|
||||
// Hardware inputs
|
||||
ButtonPress,
|
||||
Acceleration,
|
||||
NetworkStatus,
|
||||
NetworkActivity,
|
||||
|
||||
// Power management
|
||||
PowerToggle,
|
||||
SetPower,
|
||||
SetBrightness,
|
||||
|
||||
// Animation sequencing
|
||||
PreviousPattern,
|
||||
NextPattern,
|
||||
SetPattern,
|
||||
SetColor,
|
||||
Acceleration,
|
||||
FirmwareUpdate,
|
||||
NetworkStatus,
|
||||
PreviousScene,
|
||||
NextScene,
|
||||
SetScene,
|
||||
|
||||
// Timekeeping
|
||||
ScheduleChange,
|
||||
|
||||
// Task management
|
||||
StartThing,
|
||||
StopThing,
|
||||
UserInput,
|
||||
|
||||
// Configuration
|
||||
SetDisplayOffset,
|
||||
SetDisplayLength,
|
||||
SetColor,
|
||||
SaveConfigurationRequest,
|
||||
|
||||
// Firmware events
|
||||
FirmwareUpdate,
|
||||
};
|
||||
|
||||
template<typename Value>
|
||||
@ -103,7 +133,20 @@ public:
|
||||
|
||||
protected:
|
||||
void setEvent(InputEvent &&evt);
|
||||
void setEvent(InputEvent::Intent intent, Variant &&v);
|
||||
|
||||
private:
|
||||
InputEvent m_lastEvent;
|
||||
};
|
||||
|
||||
class InputMapper: public BufferedInputSource {
|
||||
public:
|
||||
InputMapper(std::function<InputEvent(const InputEvent)> f) : BufferedInputSource(), m_func(f) {}
|
||||
|
||||
void handleEvent(const InputEvent& evt) override {
|
||||
setEvent(m_func(evt));
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<InputEvent(const InputEvent)> m_func;
|
||||
};
|
||||
|
@ -34,7 +34,9 @@ MainLoop::loop()
|
||||
}
|
||||
}
|
||||
for(Task* task : scheduler) {
|
||||
//Log.info("Running %s", task->name);
|
||||
task->loop();
|
||||
//Log.info("next");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,6 @@ private:
|
||||
std::array<T, Size> m_items;
|
||||
};
|
||||
|
||||
|
||||
struct MainLoop {
|
||||
Scheduler scheduler;
|
||||
|
||||
|
@ -7,7 +7,11 @@ Renderer::loop()
|
||||
for(Display* dpy : m_displays) {
|
||||
for(Figment* figment : m_figments) {
|
||||
if (figment->state == Task::Running) {
|
||||
//Log.info("Rendering %s", figment->name);
|
||||
figment->render(dpy);
|
||||
//Log.info("next");
|
||||
} else {
|
||||
//Log.info("Not rendering %s", figment->name);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user