big changes:

- task manager working now in round robbin and returning after every task to arduino
- adding a system class which is managing all bigger things
This commit is contained in:
Peter Buchegger 2021-03-21 22:29:31 +01:00
parent 5a1a091fc7
commit 52d41dd9f6
27 changed files with 216 additions and 121 deletions

View file

@ -5,6 +5,9 @@
Display::Display() : _disp(0), _statusFrame(0), _displayOff(false), _displaySaveMode(false) {
}
Display::~Display() {
}
void Display::setup(std::shared_ptr<BoardConfig> boardConfig) {
if (boardConfig->OledReset != 0) {
pinMode(boardConfig->OledReset, OUTPUT);

View file

@ -25,13 +25,8 @@ public:
class Display {
public:
static Display &instance() {
static Display _instance;
return _instance;
}
~Display() {
}
Display();
~Display();
void setup(std::shared_ptr<BoardConfig> boardConfig);
void turn180();
@ -56,10 +51,6 @@ private:
bool _displayOff;
bool _displaySaveMode;
Display();
Display(const Display &);
Display &operator=(const Display &);
void activateDisplay();
void deactivateDisplay();
};

24
lib/System/System.cpp Normal file
View file

@ -0,0 +1,24 @@
#include "System.h"
System::System(std::shared_ptr<BoardConfig> boardConfig, std::shared_ptr<Configuration> userConfig) : _boardConfig(boardConfig), _userConfig(userConfig) {
}
System::~System() {
}
std::shared_ptr<BoardConfig> System::getBoardConfig() const {
return _boardConfig;
}
std::shared_ptr<Configuration> System::getUserConfig() const {
return _userConfig;
}
TaskManager &System::getTaskManager() {
return _taskManager;
}
Display &System::getDisplay() {
return _display;
}

28
lib/System/System.h Normal file
View file

@ -0,0 +1,28 @@
#ifndef SYSTEM_H_
#define SYSTEM_H_
#include <memory>
#include "TaskManager.h"
#include <BoardFinder.h>
#include <Display.h>
#include <configuration.h>
class System {
public:
System(std::shared_ptr<BoardConfig> boardConfig, std::shared_ptr<Configuration> userConfig);
~System();
std::shared_ptr<BoardConfig> getBoardConfig() const;
std::shared_ptr<Configuration> getUserConfig() const;
TaskManager & getTaskManager();
Display & getDisplay();
private:
std::shared_ptr<BoardConfig> _boardConfig;
std::shared_ptr<Configuration> _userConfig;
TaskManager _taskManager;
Display _display;
};
#endif

View file

@ -23,24 +23,30 @@ std::list<std::shared_ptr<Task>> TaskManager::getTasks() {
return _tasks;
}
bool TaskManager::setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) {
bool TaskManager::setup(std::shared_ptr<System> system) {
logPrintlnV("will setup all tasks...");
for (std::shared_ptr<Task> &elem : _tasks) {
logPrintW("call setup from ");
logPrintlnW(elem->getName());
if (!elem->setup(config, boardConfig)) {
return false;
}
elem->setup(system);
}
_nextTask = _tasks.begin();
return true;
}
bool TaskManager::loop(std::shared_ptr<Configuration> config) {
bool TaskManager::loop(std::shared_ptr<System> system) {
// logPrintlnD("will loop all tasks...");
if (_nextTask == _tasks.end()) {
_nextTask = _tasks.begin();
}
bool ret = (*_nextTask)->loop(system);
_nextTask++;
return ret;
for (std::shared_ptr<Task> &elem : _tasks) {
// logPrintD("call loop from ");
// logPrintlnD(elem->getName());
if (!elem->loop(config)) {
if (!elem->loop(system)) {
return false;
}
}

View file

@ -2,14 +2,17 @@
#define TASK_MANAGER_H_
#include <Arduino.h>
#include <BoardFinder.h>
#include <Display.h>
#include <configuration.h>
#include <list>
#include <memory>
#include <BoardFinder.h>
#include <Display.h>
#include <configuration.h>
#include "TaskQueue.h"
class System;
enum TaskDisplayState
{
Error,
@ -40,8 +43,8 @@ public:
return _stateInfo;
}
virtual bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig) = 0;
virtual bool loop(std::shared_ptr<Configuration> config) = 0;
virtual bool setup(std::shared_ptr<System> system) = 0;
virtual bool loop(std::shared_ptr<System> system) = 0;
protected:
TaskDisplayState _state;
@ -54,11 +57,7 @@ private:
class TaskManager {
public:
static TaskManager &instance() {
static TaskManager _instance;
return _instance;
}
TaskManager();
~TaskManager() {
}
@ -66,15 +65,12 @@ public:
std::shared_ptr<Task> getTask(const char *name);
std::list<std::shared_ptr<Task>> getTasks();
bool setup(std::shared_ptr<Configuration> config, std::shared_ptr<BoardConfig> boardConfig);
bool loop(std::shared_ptr<Configuration> config);
bool setup(std::shared_ptr<System> system);
bool loop(std::shared_ptr<System> system);
private:
std::list<std::shared_ptr<Task>> _tasks;
TaskManager();
TaskManager(const TaskManager &);
TaskManager &operator=(const TaskManager &);
std::list<std::shared_ptr<Task>> _tasks;
std::list<std::shared_ptr<Task>>::iterator _nextTask;
};
class StatusFrame : public DisplayFrame {
@ -91,4 +87,6 @@ private:
std::list<std::shared_ptr<Task>> _tasks;
};
#include "System.h"
#endif