Skip to content

Commit

Permalink
Figure out segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
peteGSX committed Dec 23, 2024
1 parent d429564 commit a34c8ab
Show file tree
Hide file tree
Showing 17 changed files with 321 additions and 38 deletions.
4 changes: 3 additions & 1 deletion Configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Configurator::Configurator(Stream *consoleStream, Stream *commandStationStream,
_logger->setLogLevel(logLevel);
_displayManager = new DisplayManager();
_displayManager->setLogger(_logger);
_controller = new Controller(_consoleStream, _commandStationStream, _displayManager, _logger);
_screenManager = new ScreenManager();
_screenManager->setLogger(_logger);
_controller = new Controller(_consoleStream, _commandStationStream, _displayManager, _screenManager, _logger);
}

void Configurator::initialise() {
Expand Down
15 changes: 10 additions & 5 deletions Configurator.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,28 @@ class Configurator {
/// @return Pointer to the Logger
Logger *getLogger();

/// @brief Get the DisplayManager instance for this Configurator
/// @return Pointer to the DisplayManager;
DisplayManager *getDisplayManager();

/// @brief Get the ScreenManager instance for this Configurator
/// @return Pointer to the ScreenManager
ScreenManager *getScreenManager();

/// @brief Get the Controller instance for this Configurator
/// @return Pointer to the Controller
Controller *getController();

/// @brief Get the DisplayManager instance for this Configurator
/// @return Pointer to the DisplayManager();
DisplayManager *getDisplayManager();

/// @brief Destructor for the Configurator
~Configurator();

private:
Stream *_consoleStream;
Stream *_commandStationStream;
Logger *_logger;
Controller *_controller;
DisplayManager *_displayManager;
ScreenManager *_screenManager;
Controller *_controller;
};

#endif // CONFIGURATOR_H
29 changes: 20 additions & 9 deletions Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,39 @@
#include "Controller.h"

Controller::Controller(Stream *consoleStream, Stream *commandStationStream, DisplayManager *displayManager,
Logger *logger)
: _consoleStream(consoleStream), _commandStationStream(commandStationStream), _displayManager(displayManager) {
_screenManager = new ScreenManager();
ScreenManager *screenManager, Logger *logger)
: _consoleStream(consoleStream), _commandStationStream(commandStationStream), _displayManager(displayManager),
_screenManager(screenManager) {
_logger = logger;
if (_logger != nullptr) {
_screenManager->setLogger(_logger);
}
}

void Controller::update() {
if (_commandStationStream->available()) {
if (_commandStationStream != nullptr && _commandStationStream->available()) {
char csChar = _commandStationStream->read();
AtFinder::processInputChar(csChar);
}
if (_consoleStream->available()) {
if (_consoleStream != nullptr && _consoleStream->available()) {
char consoleChar = _consoleStream->read();
AtFinder::processInputChar(consoleChar);
}
if (_displayManager != nullptr && _screenManager != nullptr) {
for (auto *display = _displayManager->getFirstDisplay(); display; display = display->getNext()) {
Screen *screen = _screenManager->getScreenById(display->getScreenId());
for (ScreenRow *row = screen->getFirstScreenRow(); row; row = row->getNext()) {
if (row->needsRedraw()) {
display->displayRow(row->getId(), row->getText());
}
}
}
}
}

void Controller::updateScreen(uint8_t screenId, uint8_t row, const char *text) {
LOG(LogLevel::DEBUG, "Controller::updateScreen(%d, %d, %s)", screenId, row, text);
if (_screenManager == nullptr) {
LOG(LogLevel::DEBUG, "Controller::_screenManager == nullptr");
return;
}
Screen *screen = _screenManager->updateScreen(screenId);
if (screen != nullptr) {
screen->updateScreenRow(row, text);
Expand All @@ -50,7 +61,7 @@ void Controller::updateScreen(uint8_t screenId, uint8_t row, const char *text) {
void Controller::onInputAction(InputAction action) { LOG(LogLevel::DEBUG, "Controller::onInputAction(%d)", action); }

Controller::~Controller() {
delete _screenManager;
_displayManager = nullptr;
_screenManager = nullptr;
_consoleStream = nullptr;
_commandStationStream = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
class Controller : public CallbackInterface {
public:
/// @brief Constructor for the Controller
Controller(Stream *consoleStream, Stream *commandStationStream, DisplayManager *displayManager, Logger *logger);
Controller(Stream *consoleStream, Stream *commandStationStream, DisplayManager *displayManager,
ScreenManager *screenManager, Logger *logger);

/// @brief Processes all ongoing activities, monitoring streams, receiving user input, updates displays, etc.
/// Call at least once per main loop iteration
Expand All @@ -52,7 +53,6 @@ class Controller : public CallbackInterface {
Stream *_consoleStream;
Stream *_commandStationStream;
DisplayManager *_displayManager;
Logger *_logger;
ScreenManager *_screenManager;
};

Expand Down
4 changes: 2 additions & 2 deletions DisplayInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class DisplayInterface {
/// @param text Text to be displayed on this row
/// @param underlined (Optional) Flag to underline this row - default false
/// @param column (Optional) Column to start displaying the text, column being width of a character (not pixels)
virtual void displayRow(int row, const char *text, bool underlined = false, int column = 0) = 0;
virtual void displayRow(uint8_t row, const char *text, bool underlined = false, uint8_t column = 0) = 0;

/// @brief Clear the specified row
/// @param row Row number as specified in the SCREEN() command (not pixels)
virtual void clearRow(int row) = 0;
virtual void clearRow(uint8_t row) = 0;

/// @brief Display the startup screen with software version
/// @param version EX-Display version
Expand Down
5 changes: 5 additions & 0 deletions Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ void Screen::setNext(Screen *screen) { _next = screen; }
Screen *Screen::getNext() { return _next; }

void Screen::updateScreenRow(uint8_t screenRowId, const char *text) {
if (text == nullptr) {
return;
}
LOG(LogLevel::DEBUG, "Screen::updateScreenRow[%d](%d, %s)", _screenId, screenRowId, text);
// Check if it exists already
ScreenRow *updateRow = getScreenRowById(screenRowId);
// If not, create and add to the list unless this is supposed to delete it with ""
Expand Down Expand Up @@ -76,6 +80,7 @@ Screen::~Screen() {
void Screen::_addScreenRow(uint8_t screenRowId, const char *text) {
LOG(LogLevel::DEBUG, "Screen::_addScreenRow(%d, %s)", screenRowId, text);
ScreenRow *newRow = new ScreenRow(screenRowId);
newRow->setText(text);
if (_logger != nullptr) {
newRow->setLogger(_logger);
}
Expand Down
23 changes: 20 additions & 3 deletions ScreenRow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "ScreenRow.h"

ScreenRow::ScreenRow(uint8_t screenRowId)
: _screenRowId(screenRowId), _text(nullptr), _next(nullptr), _logger(nullptr) {}
: _screenRowId(screenRowId), _text(nullptr), _next(nullptr), _logger(nullptr), _needsRedraw(true) {}

uint8_t ScreenRow::getId() { return _screenRowId; }

Expand All @@ -27,15 +27,32 @@ void ScreenRow::setNext(ScreenRow *screenRow) { _next = screenRow; }
ScreenRow *ScreenRow::getNext() { return _next; }

void ScreenRow::setText(const char *text) {
_text = text;
if (text == nullptr) {
return;
}
if (_text) {
delete[] _text;
_text = nullptr;
}
_text = new char[strlen(text) + 1];
strcpy(_text, text);
_needsRedraw = true;
LOG(LogLevel::DEBUG, "ScreenRow::setText(%s)", _text);
}

const char *ScreenRow::getText() { return _text; }
const char *ScreenRow::getText() {
_needsRedraw = false;
return _text;
}

void ScreenRow::setLogger(Logger *logger) { _logger = logger; }

bool ScreenRow::needsRedraw() { return _needsRedraw; }

ScreenRow::~ScreenRow() {
if (_text) {
delete[] _text;
}
_text = nullptr;
_next = nullptr;
_logger = nullptr;
Expand Down
7 changes: 6 additions & 1 deletion ScreenRow.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,19 @@ class ScreenRow {
/// @param logger Pointer to the Logger
void setLogger(Logger *logger);

/// @brief Test if this row needs to be redrawn
/// @return true|false
bool needsRedraw();

/// @brief Destructor for each ScreenRow instance
~ScreenRow();

private:
uint8_t _screenRowId;
const char *_text;
char *_text;
ScreenRow *_next;
Logger *_logger;
bool _needsRedraw;
};

#endif // SCREENROW_H
4 changes: 2 additions & 2 deletions TFT_eSPIDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ void TFT_eSPIDisplay::clearScreen() {
_tft->fillScreen(_backgroundColour);
}

void TFT_eSPIDisplay::displayRow(int row, const char *text, bool underlined, int column) {
void TFT_eSPIDisplay::displayRow(uint8_t row, const char *text, bool underlined, uint8_t column) {
LOG(LogLevel::DEBUG, "TFT_eSPIDisplay::displayRow[%d](%d, %s, %d, %d)", _displayId, row, text, underlined, column);
}

void TFT_eSPIDisplay::clearRow(int row) { LOG(LogLevel::DEBUG, "TFT_eSPIDisplay::clearRow[%d](%d)", _displayId, row); }
void TFT_eSPIDisplay::clearRow(uint8_t row) { LOG(LogLevel::DEBUG, "TFT_eSPIDisplay::clearRow[%d](%d)", _displayId, row); }

void TFT_eSPIDisplay::displayStartupInfo(const char *version) {
LOG(LogLevel::DEBUG, "TFT_eSPIDisplay::displayStartupInfo[%d](%s)", _displayId, version);
Expand Down
4 changes: 2 additions & 2 deletions TFT_eSPIDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ class TFT_eSPIDisplay : public DisplayInterface {
/// @param text Text to be displayed on this row
/// @param underlined (Optional) Flag to underline this row - default false
/// @param column (Optional) Column to start displaying the text, column being width of a character (not pixels)
void displayRow(int row, const char *text, bool underlined = false, int column = 0) override;
void displayRow(uint8_t row, const char *text, bool underlined = false, uint8_t column = 0) override;

/// @brief Clear the specified row
/// @param row Row number as specified in the SCREEN() command (not pixels)
void clearRow(int row) override;
void clearRow(uint8_t row) override;

/// @brief Display the startup screen with software version
/// @param version EX-Display version
Expand Down
13 changes: 7 additions & 6 deletions docs/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,13 @@ TIMESTAMP = NO
# normally produced when WARNINGS is set to YES.
# The default value is: NO.

EXTRACT_ALL = NO
EXTRACT_ALL = YES

# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
# be included in the documentation.
# The default value is: NO.

EXTRACT_PRIVATE = NO
EXTRACT_PRIVATE = YES

# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual
# methods of a class will be included in the documentation.
Expand All @@ -542,7 +542,7 @@ EXTRACT_PACKAGE = NO
# included in the documentation.
# The default value is: NO.

EXTRACT_STATIC = NO
EXTRACT_STATIC = YES

# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
# locally in source files will be included in the documentation. If set to NO,
Expand Down Expand Up @@ -1032,7 +1032,8 @@ FILE_PATTERNS = *.c \
*.vhdl \
*.ucf \
*.qsf \
*.ice
*.ice \
*.ino

# The RECURSIVE tag can be used to specify whether or not subdirectories should
# be searched for input files as well.
Expand Down Expand Up @@ -2817,7 +2818,7 @@ DOT_GRAPH_MAX_NODES = 50
# Minimum value: 0, maximum value: 1000, default value: 0.
# This tag requires that the tag HAVE_DOT is set to YES.

MAX_DOT_GRAPH_DEPTH = 0
MAX_DOT_GRAPH_DEPTH = 3

# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output
# files in one run (i.e. multiple -o and -T options on the command line). This
Expand All @@ -2826,7 +2827,7 @@ MAX_DOT_GRAPH_DEPTH = 0
# The default value is: NO.
# This tag requires that the tag HAVE_DOT is set to YES.

DOT_MULTI_TARGETS = NO
DOT_MULTI_TARGETS = YES

# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page
# explaining the meaning of the various boxes and arrows in the dot generated
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

extensions = [
'breathe',
'sphinx.ext.autodoc',
'sphinx.ext.graphviz'
]

Expand Down
Loading

0 comments on commit a34c8ab

Please sign in to comment.