2021-01-03 22:43:35 +01:00
|
|
|
#ifndef TASK_MANAGER_H_
|
|
|
|
|
#define TASK_MANAGER_H_
|
|
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
#include <configuration.h>
|
2021-01-04 23:10:23 +01:00
|
|
|
#include <BoardFinder.h>
|
2021-01-30 22:47:24 +01:00
|
|
|
#include <Display.h>
|
2021-01-04 23:10:23 +01:00
|
|
|
|
|
|
|
|
#include "TaskQueue.h"
|
2021-01-03 22:43:35 +01:00
|
|
|
|
2021-01-30 22:47:24 +01:00
|
|
|
enum TaskDisplayState
|
|
|
|
|
{
|
|
|
|
|
Error,
|
|
|
|
|
Warning,
|
|
|
|
|
Okay,
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-03 22:43:35 +01:00
|
|
|
class Task
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-01-30 22:47:24 +01:00
|
|
|
Task(String & name, int taskId) : _state(Okay), _stateInfo("Booting"), _name(name), _taskId(taskId) {}
|
|
|
|
|
Task(const char * name, int taskId) : _state(Okay), _stateInfo("Booting"), _name(name), _taskId(taskId) {}
|
2021-01-03 22:43:35 +01:00
|
|
|
virtual ~Task() {}
|
|
|
|
|
|
|
|
|
|
String getName() const { return _name; }
|
2021-01-09 13:38:48 +01:00
|
|
|
int getTaskId() const { return _taskId; }
|
2021-01-03 22:43:35 +01:00
|
|
|
|
2021-01-30 22:47:24 +01:00
|
|
|
TaskDisplayState getState() const { return _state; }
|
|
|
|
|
String getStateInfo() const { return _stateInfo; }
|
|
|
|
|
|
2021-01-04 23:10:23 +01:00
|
|
|
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) = 0;
|
2021-01-03 22:43:35 +01:00
|
|
|
virtual bool loop(std::shared_ptr<Configuration> config) = 0;
|
|
|
|
|
|
2021-01-30 22:47:24 +01:00
|
|
|
protected:
|
|
|
|
|
TaskDisplayState _state;
|
|
|
|
|
String _stateInfo;
|
|
|
|
|
|
2021-01-03 22:43:35 +01:00
|
|
|
private:
|
|
|
|
|
String _name;
|
2021-01-09 13:38:48 +01:00
|
|
|
int _taskId;
|
2021-01-03 22:43:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TaskManager
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-01-04 23:10:23 +01:00
|
|
|
static TaskManager & instance()
|
2021-01-09 13:38:48 +01:00
|
|
|
{
|
|
|
|
|
static TaskManager _instance;
|
|
|
|
|
return _instance;
|
|
|
|
|
}
|
2021-01-04 23:10:23 +01:00
|
|
|
|
|
|
|
|
~TaskManager() {}
|
2021-01-03 22:43:35 +01:00
|
|
|
|
|
|
|
|
void addTask(std::shared_ptr<Task> task);
|
2021-01-04 23:10:23 +01:00
|
|
|
std::shared_ptr<Task> getTask(const char * name);
|
2021-01-30 22:47:24 +01:00
|
|
|
std::list<std::shared_ptr<Task>> getTasks();
|
2021-01-03 22:43:35 +01:00
|
|
|
|
2021-01-04 23:10:23 +01:00
|
|
|
bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig);
|
2021-01-03 22:43:35 +01:00
|
|
|
bool loop(std::shared_ptr<Configuration> config);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::list<std::shared_ptr<Task>> _tasks;
|
|
|
|
|
|
2021-01-04 23:10:23 +01:00
|
|
|
TaskManager();
|
|
|
|
|
TaskManager(const TaskManager &);
|
|
|
|
|
TaskManager & operator = (const TaskManager &);
|
2021-01-03 22:43:35 +01:00
|
|
|
};
|
|
|
|
|
|
2021-01-30 22:47:24 +01:00
|
|
|
class StatusFrame : public DisplayFrame
|
|
|
|
|
{
|
|
|
|
|
public:
|
2021-01-30 22:53:06 +01:00
|
|
|
explicit StatusFrame(const std::list<std::shared_ptr<Task>> & tasks) : _tasks(tasks) {}
|
2021-01-30 22:47:24 +01:00
|
|
|
virtual ~StatusFrame() {}
|
|
|
|
|
void drawStatusPage(Bitmap & bitmap) override;
|
|
|
|
|
|
|
|
|
|
bool isPrio() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::list<std::shared_ptr<Task>> _tasks;
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-03 22:43:35 +01:00
|
|
|
#endif
|