Initial commit

This commit is contained in:
2023-11-26 20:13:49 +01:00
commit dc2dc5c58b
820 changed files with 258269 additions and 0 deletions

View File

@ -0,0 +1,7 @@
#include <gui/common/FrontendApplication.hpp>
FrontendApplication::FrontendApplication(Model& m, FrontendHeap& heap)
: FrontendApplicationBase(m, heap)
{
}

View File

@ -0,0 +1,98 @@
#include "config/touchgfx-config.h"
#include <gui/model/Model.hpp>
#include <gui/model/ModelListener.hpp>
Model::Model() :
modelListener(0),
logTextChanged_(false)
{
}
void Model::initialize(
#if defined(TOUCHGFX_ENABLED) && (TOUCHGFX_ENABLED != 0) // Used to get a compilable project for the students!
ButtonEventsHandler & buttonEventsHandler
#endif // TOUCHGFX_ENABLED
)
{
#if defined(TOUCHGFX_ENABLED) && (TOUCHGFX_ENABLED != 0)
// Subscribe to button events
bool success = buttonEventsHandler.subscribe(this);
assert(success);
#endif // TOUCHGFX_ENABLED
}
/**
* The tick method is called regularly by the TouchGFX task
*/
void Model::tick()
{
if (logTextChanged_)
{
logTextChanged_ = false;
if (logMessages_.size() > 0)
{
logTextTotal_.clear();
// Add all log messages to logTextTotal_
// New messages are at the beginning of the list, but
// need to be at the end in logTextTotal_
for (std::string str : logMessages_)
{
logTextTotal_.insert(0, str);
}
modelListener->notifyLogTextChanged(logTextTotal_);
}
else
{
modelListener->notifyClearLogMessages();
}
}
}
void Model::addLogMessage(const std::string & logMessage)
{
logMessages_.push_front(logMessage);
// Remove an old message if list is too big
if (logMessages_.size() > MAX_MESSAGES)
{
logMessages_.pop_back();
}
// Tell UI task that logText did change
logTextChanged_ = true;
}
void Model::clearLogMessages()
{
logMessages_.clear();
logTextTotal_.clear();
// Tell UI task that logText did change
logTextChanged_ = true;
}
#if defined(TOUCHGFX_ENABLED) && (TOUCHGFX_ENABLED != 0)
void Model::onButtonShortPressed(ButtonIndex buttonIndex)
{
std::string logMessage("Button ");
logMessage += std::to_string(buttonIndex);
logMessage += " short pressed\n";
addLogMessage(logMessage);
}
void Model::onButtonLongPressed(ButtonIndex buttonIndex)
{
std::string logMessage("Button ");
logMessage += std::to_string(buttonIndex);
logMessage += " long pressed\n";
addLogMessage(logMessage);
}
#endif // TOUCHGFX_ENABLED

View File

@ -0,0 +1,38 @@
#include <gui/terminal_screen/TerminalView.hpp>
#include <gui/terminal_screen/TerminalPresenter.hpp>
TerminalPresenter::TerminalPresenter(TerminalView& v)
: view(v)
{
}
void TerminalPresenter::activate()
{
}
void TerminalPresenter::deactivate()
{
}
void TerminalPresenter::clearLogMessages()
{
model->clearLogMessages();
}
void TerminalPresenter::onButtonClearLogTextClicked()
{
clearLogMessages();
}
void TerminalPresenter::notifyLogTextChanged(const std::string & logText)
{
view.updateLogText(logText);
}
void TerminalPresenter::notifyClearLogMessages()
{
view.clearLogText();
}

View File

@ -0,0 +1,82 @@
#include <gui/terminal_screen/TerminalView.hpp>
TerminalView::TerminalView():
autoScrollText_(true)
{
}
void TerminalView::setupScreen()
{
TerminalViewBase::setupScreen();
}
void TerminalView::tearDownScreen()
{
TerminalViewBase::tearDownScreen();
}
void TerminalView::onButtonClearLogTextClicked()
{
// Forward event to presenter
presenter->onButtonClearLogTextClicked();
}
void TerminalView::updateLogText(const std::string & str)
{
Unicode::fromUTF8((const unsigned char *)str.c_str(), logText_Buffer, LOGTEXT__SIZE);
logText_.resizeToCurrentTextWithAlignment(); // Update height of text area
// Check if we always need to show the end of the logs (most recent logs)
if (autoScrollText_)
{
auto scrollHeight = scrollableTextArea_.getHeight();
auto textHeight = logText_.getTextHeight();
if (logText_.getRotation() == TEXT_ROTATE_0)
{
if (textHeight > scrollHeight)
{
logText_.startMoveAnimation(logText_.getX(), // X value to scroll to
-(textHeight - scrollHeight), // Y value to scroll to
2); // Animation duration in ticks
}
}
else if (logText_.getRotation() == TEXT_ROTATE_180)
{
if (textHeight > scrollHeight)
{
// Scroll to bottom is scrolling to y == 0
logText_.startMoveAnimation(logText_.getX(), 0, 2);
}
}
}
logText_.invalidate();
}
void TerminalView::clearLogText()
{
logText_Buffer[0] = '\0';
if (logText_.getRotation() == TEXT_ROTATE_0)
{
logText_.resizeHeightToCurrentText();
logText_.startMoveAnimation(logText_.getX(), // X value to scroll to
0, // Y value to scroll to
2); // Animation duration in ticks
}
else if (logText_.getRotation() == TEXT_ROTATE_180)
{
logText_.resizeToCurrentTextWithAlignment();
logText_.startMoveAnimation(logText_.getX(), // X value to scroll to
scrollableTextArea_.getHeight() - logText_.getHeight(), // Y value to scroll to (in respect with rotated text)
2); // Animation duration in ticks
}
logText_.invalidate();
scrollableTextArea_.invalidate();
}