Skip to content

Commit

Permalink
TFT hardcoded, version displaying
Browse files Browse the repository at this point in the history
  • Loading branch information
peteGSX committed Dec 23, 2024
1 parent e27c516 commit d429564
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Configurator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ void Configurator::initialise() {
AtFinder::setup(100, _controller);
AtFinder::setLogger(_logger);
_displayManager->createDisplayList();
_displayManager->startDisplays();
LOG(LogLevel::MESSAGE, "EX-Display version %s", VERSION);
_displayManager->displayStartupInfo(VERSION);
}

Stream *Configurator::getConsoleStream() { return _consoleStream; }
Expand Down
31 changes: 30 additions & 1 deletion DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/

#include "DisplayManager.h"
#ifndef PIO_UNIT_TESTING // Cannot create physical displays with Platform IO testing
#include "TFT_eSPIDisplay.h"
#endif // PIO_UNIT_TESTING

DisplayManager::DisplayManager() : _firstDisplay(nullptr), _logger(nullptr), _nextDisplayId(0) {}

Expand All @@ -39,7 +42,33 @@ void DisplayManager::addDisplay(DisplayInterface *display) {
current->setNext(display);
}

void DisplayManager::createDisplayList() {}
void DisplayManager::createDisplayList() {
#ifndef PIO_UNIT_TESTING // Cannot create physical displays with Platform IO testing
TFT_eSPIDisplay *tft = new TFT_eSPIDisplay();
addDisplay(tft);
#endif // PIO_UNIT_TESTING
}

void DisplayManager::startDisplays() {
LOG(LogLevel::DEBUG, "DisplayManager::startDisplays()");
if (_firstDisplay == nullptr) {
return;
}
for (auto *display = _firstDisplay; display; display = display->getNext()) {
display->begin();
}
}

void DisplayManager::displayStartupInfo(const char *version) {
LOG(LogLevel::DEBUG, "DisplayManager::displayStartupInfo(%s)", version);
// Do nothing if we don't have a DisplayManager or any displays
if (_firstDisplay == nullptr) {
return;
}
for (auto *display = _firstDisplay; display; display = display->getNext()) {
display->displayStartupInfo(version);
}
}

DisplayInterface *DisplayManager::getFirstDisplay() { return _firstDisplay; }

Expand Down
7 changes: 7 additions & 0 deletions DisplayManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class DisplayManager {
/// @brief Parses the displays configured in myConfig.h and creates the list of displays
void createDisplayList();

/// @brief Call the begin() method for all associated Display instances
void startDisplays();

/// @brief Calls the displayStartupInfo of all Display instances to display the version
/// @param version EX-Display version
void displayStartupInfo(const char *version);

/// @brief Get the first DisplayInterface derived instance in the list of displays
/// @return Pointer to the first instance
DisplayInterface *getFirstDisplay();
Expand Down
29 changes: 21 additions & 8 deletions TFT_eSPIDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,43 @@ TFT_eSPIDisplay::TFT_eSPIDisplay() {
}

void TFT_eSPIDisplay::begin() {
LOG(LogLevel::DEBUG, "TFT_eSPIDisplay::begin[%d]()", _displayId);
_tft->init();
_tft->setFreeFont(&FreeMono12pt7b);
_tft->setTextSize(1);
_tft->setRotation(1);
_tft->setTextColor(_textColour);
_tft->fillScreen(_backgroundColour);
}

void TFT_eSPIDisplay::clearScreen() { _tft->fillScreen(_backgroundColour); }
void TFT_eSPIDisplay::clearScreen() {
LOG(LogLevel::DEBUG, "TFT_eSPIDisplay::clearScreen[%d]() - colour %d", _displayId, _backgroundColour);
_tft->fillScreen(_backgroundColour);
}

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

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

void TFT_eSPIDisplay::displayStartupInfo(const char *version) {
LOG(LogLevel::DEBUG, "TFT_eSPIDisplay::displayStartupInfo(%s)", version);
LOG(LogLevel::DEBUG, "TFT_eSPIDisplay::displayStartupInfo[%d](%s)", _displayId, version);
_tft->setFreeFont(&FreeMono12pt7b);
_tft->fillScreen(_backgroundColour);
_tft->setTextColor(_textColour);
_tft->drawString("EX-Display", 0, 20);
_tft->drawString("Version: ", 0, 40);
_tft->drawString(version, 100, 40);
_tft->drawString(version, 120, 40);
}

TFT_eSPI *TFT_eSPIDisplay::getTFT_eSPIInstance() { return _tft; }
TFT_eSPI *TFT_eSPIDisplay::getTFT_eSPIInstance() {
LOG(LogLevel::DEBUG, "TFT_eSPIDisplay::getTFT_eSPIInstance[%d]", _displayId);
return _tft;
}

TFT_eSPIDisplay::~TFT_eSPIDisplay() {}
TFT_eSPIDisplay::~TFT_eSPIDisplay() {
delete _tft;
_tft = nullptr;
}

#endif // PIO_UNIT_TESTING
54 changes: 54 additions & 0 deletions test/unit/test_displays/test_DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include "DisplayManager.h"
#include "Version.h"
#include "test/mocks/MockDisplay.h"
#include <gtest/gtest.h>

Expand Down Expand Up @@ -71,3 +72,56 @@ TEST_F(DisplayManagerTests, CreateDisplayList) {

delete displayManager;
}

/// @brief Validate the startDisplays() method correctly calls all display begin() methods
TEST_F(DisplayManagerTests, StartDisplays) {
// Create DisplayManager and some mock displays
DisplayManager *displayManager = new DisplayManager();
MockDisplay *display0 = new MockDisplay();
MockDisplay *display1 = new MockDisplay();
MockDisplay *display2 = new MockDisplay();

// Add to DisplayManager and should now have correct IDs
displayManager->addDisplay(display0);
displayManager->addDisplay(display1);
displayManager->addDisplay(display2);

// Set up expectation each mock display's displayStartupInfo() method should be called with the correct version
EXPECT_CALL(*display0, begin()).Times(1);
EXPECT_CALL(*display1, begin()).Times(1);
EXPECT_CALL(*display2, begin()).Times(1);

// Call the method
displayManager->startDisplays();

// Clean up
delete displayManager;
}

/// @brief Validate the displayStartupInfo() method correct calls all display methods
TEST_F(DisplayManagerTests, DisplayStartupInfo) {
// Create DisplayManager and some mock displays
DisplayManager *displayManager = new DisplayManager();
MockDisplay *display0 = new MockDisplay();
MockDisplay *display1 = new MockDisplay();
MockDisplay *display2 = new MockDisplay();

// Set the current version
const char *version = VERSION;

// Add to DisplayManager and should now have correct IDs
displayManager->addDisplay(display0);
displayManager->addDisplay(display1);
displayManager->addDisplay(display2);

// Set up expectation each mock display's displayStartupInfo() method should be called with the correct version
EXPECT_CALL(*display0, displayStartupInfo(StrEq(version))).Times(1);
EXPECT_CALL(*display1, displayStartupInfo(StrEq(version))).Times(1);
EXPECT_CALL(*display2, displayStartupInfo(StrEq(version))).Times(1);

// Call the method
displayManager->displayStartupInfo(version);

// Clean up
delete displayManager;
}

0 comments on commit d429564

Please sign in to comment.