-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfigurator.cpp
84 lines (72 loc) · 3.3 KB
/
Configurator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* © 2024 Peter Cole
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* It is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Configurator.h"
#include "AtFinder.h"
#ifndef PIO_UNIT_TESTING
#include "CreateUserDevices.h"
#endif // PIO_UNIT_TESTING
Configurator::Configurator(Stream *consoleStream, Stream *commandStationStream, LogLevel logLevel)
: _consoleStream(consoleStream), _commandStationStream(commandStationStream) {
_logger = new Logger(_consoleStream);
_logger->setLogLevel(logLevel);
_displayManager = new DisplayManager();
_displayManager->setLogger(_logger);
_inputManager = new InputManager();
_inputManager->setLogger(_logger);
_screenManager = new ScreenManager();
_screenManager->setLogger(_logger);
unsigned long pauseDisplayUpdates = STARTUP_INFO_DELAY + millis();
_controller = new Controller(_consoleStream, _commandStationStream, _displayManager, _inputManager, _screenManager,
_logger, pauseDisplayUpdates);
}
void Configurator::initialise() {
LOG(LogLevel::LOG_DEBUG, "Configurator::initialise()");
AtFinder::setLogger(_logger); // Set the AtFinder logger for debug etc.
AtFinder::setup(100, _controller); // Setup AtFinder to call back to Controller
_displayManager->createDisplays(); // Create user defined displays from myConfig.h
_inputManager->setCallback(_controller); // Input uses the Controller for callbacks
_inputManager->createInput(); // Create user defined input from myConfig.h
// If the user defined input requires a display instance, set it
if (_inputManager->getInput() != nullptr && _inputManager->getInput()->needsDisplay() != -1) {
uint8_t displayId = _inputManager->getInput()->needsDisplay();
DisplayInterface *display = _displayManager->getDisplayById(displayId);
if (display != nullptr) {
_inputManager->setDisplay(display);
} else {
LOG(LogLevel::LOG_ERROR, "Could not get display ID %d required by the input, user input not available", displayId);
}
}
}
Stream *Configurator::getConsoleStream() { return _consoleStream; }
Stream *Configurator::getCommandStationStream() { return _commandStationStream; }
Logger *Configurator::getLogger() { return _logger; }
Controller *Configurator::getController() { return _controller; }
DisplayManager *Configurator::getDisplayManager() { return _displayManager; }
InputManager *Configurator::getInputManager() { return _inputManager; }
ScreenManager *Configurator::getScreenManager() { return _screenManager; }
Configurator::~Configurator() {
AtFinder::cleanUp();
delete _controller;
delete _logger;
delete _displayManager;
delete _inputManager;
delete _screenManager;
_controller = nullptr;
_logger = nullptr;
_displayManager = nullptr;
_screenManager = nullptr;
}