1
0

add screen library

This commit is contained in:
2024-01-13 19:15:18 +01:00
parent 7b660f0fe2
commit 65ff5de90f
533 changed files with 113575 additions and 2 deletions

View File

@ -0,0 +1,24 @@
#ifndef FRONTENDAPPLICATION_HPP
#define FRONTENDAPPLICATION_HPP
#include <gui_generated/common/FrontendApplicationBase.hpp>
class FrontendHeap;
using namespace touchgfx;
class FrontendApplication : public FrontendApplicationBase
{
public:
FrontendApplication(Model& m, FrontendHeap& heap);
virtual ~FrontendApplication() { }
virtual void handleTickEvent()
{
model.tick();
FrontendApplicationBase::handleTickEvent();
}
private:
};
#endif // FRONTENDAPPLICATION_HPP

View File

@ -0,0 +1,74 @@
#ifndef FRONTENDHEAP_HPP
#define FRONTENDHEAP_HPP
#include <gui_generated/common/FrontendHeapBase.hpp>
class FrontendHeap : public FrontendHeapBase
{
public:
/* List any user-defined view types here*/
typedef touchgfx::meta::TypeList< touchgfx::meta::Nil, //Replace this with first user-defined type
touchgfx::meta::Nil //List must always end with meta::Nil !
> UserDefinedViewTypes;
/* List any user-defined presenter types here*/
typedef touchgfx::meta::TypeList< touchgfx::meta::Nil, //Replace this with first user-defined type
touchgfx::meta::Nil //List must always end with meta::Nil !
> UserDefinedPresenterTypes;
/* List any user-defined transition types here*/
typedef touchgfx::meta::TypeList< touchgfx::meta::Nil, //Replace this with first user-defined type
touchgfx::meta::Nil //List must always end with meta::Nil !
> UserDefinedTransitionTypes;
/* Calculate largest view, both from generated and user-defined typelists */
typedef touchgfx::meta::select_type_maxsize< UserDefinedViewTypes >::type MaxUserViewType;
typedef touchgfx::meta::TypeList< MaxGeneratedViewType,
touchgfx::meta::TypeList< MaxUserViewType,
touchgfx::meta::Nil
> > CombinedViewTypes;
typedef touchgfx::meta::select_type_maxsize< CombinedViewTypes >::type MaxViewType;
/* Calculate largest presenter, both from generated and user-defined typelists */
typedef touchgfx::meta::select_type_maxsize< UserDefinedPresenterTypes >::type MaxUserPresenterType;
typedef touchgfx::meta::TypeList< MaxGeneratedPresenterType,
touchgfx::meta::TypeList< MaxUserPresenterType,
touchgfx::meta::Nil
> > CombinedPresenterTypes;
typedef touchgfx::meta::select_type_maxsize< CombinedPresenterTypes >::type MaxPresenterType;
/* Calculate largest transition, both from generated and user-defined typelists */
typedef touchgfx::meta::select_type_maxsize< UserDefinedTransitionTypes >::type MaxUserTransitionType;
typedef touchgfx::meta::TypeList< MaxGeneratedTransitionType,
touchgfx::meta::TypeList< MaxUserTransitionType,
touchgfx::meta::Nil
> > CombinedTransitionTypes;
typedef touchgfx::meta::select_type_maxsize< CombinedTransitionTypes >::type MaxTransitionType;
static FrontendHeap& getInstance()
{
static FrontendHeap instance;
return instance;
}
touchgfx::Partition< CombinedPresenterTypes, 1 > presenters;
touchgfx::Partition< CombinedViewTypes, 1 > views;
touchgfx::Partition< CombinedTransitionTypes, 1 > transitions;
Model model;
FrontendApplication app;
private:
FrontendHeap() : FrontendHeapBase(presenters, views, transitions, app),
app(model, *this)
{
gotoStartScreen(app);
}
};
#endif // FRONTENDHEAP_HPP

View File

@ -0,0 +1,42 @@
#ifndef MAINVIEWPRESENTER_HPP
#define MAINVIEWPRESENTER_HPP
#include <gui/model/ModelListener.hpp>
#include <mvp/Presenter.hpp>
using namespace touchgfx;
class MainViewView;
class MainViewPresenter : public touchgfx::Presenter, public ModelListener
{
public:
MainViewPresenter(MainViewView& v);
/**
* The activate function is called automatically when this screen is "switched in"
* (ie. made active). Initialization logic can be placed here.
*/
virtual void activate();
/**
* The deactivate function is called automatically when this screen is "switched out"
* (ie. made inactive). Teardown functionality can be placed here.
*/
virtual void deactivate();
virtual ~MainViewPresenter() {};
void notifyModeChanged(std::string newMode) override;
void notifyFreqChanged(std::string newFreq) override;
void notifyDivTimChanged(std::string newDivTim) override;
void notifyDrawGraph(uint16_t* values, uint16_t maxSize, float xScale = 1) override;
private:
MainViewPresenter();
MainViewView& view;
};
#endif // MAINVIEWPRESENTER_HPP

View File

@ -0,0 +1,34 @@
#ifndef MAINVIEWVIEW_HPP
#define MAINVIEWVIEW_HPP
#include <gui_generated/mainview_screen/MainViewViewBase.hpp>
#include <gui/mainview_screen/MainViewPresenter.hpp>
#include <string>
class MainViewView : public MainViewViewBase
{
public:
MainViewView();
virtual ~MainViewView() {}
virtual void setupScreen();
virtual void tearDownScreen();
static MainViewView* getInstance();
void onBtnPlusPressed() override;
void onBtnMinusPressed() override;
void onCheckBoxTriggerPressed() override;
void setModeSignal(const std::string str);
void setFreqSignal(const std::string str);
void setLabelDivTime(const std::string str);
void drawGraph(uint16_t * values, uint16_t maxSize, float xScale = 1);
protected:
/*
* Singleton
*/
static MainViewView* _instance;
};
#endif // MAINVIEWVIEW_HPP

View File

@ -0,0 +1,61 @@
#ifndef MODEL_HPP
#define MODEL_HPP
#include <string>
#include "touchgfx-config.h"
#if (TOUCHGFX_FREERTOS != 0)
#include "FreeRTOS.h"
#include "queue.h"
#endif // TOUCHGFX_FREERTOS
class ModelListener;
#if (TOUCHGFX_FREERTOS != 0)
enum GUI_EVENT{
UNDEFINED=0,
FREQUENCY_EVENT,
MODE_EVENT,
DIVTIM_EVENT,
GRAPH_EVENT
};
#endif // TOUCHGFX_FREERTOS
class Model
{
public:
Model();
static Model* getInstance();
void bind(ModelListener* listener)
{
modelListener = listener;
}
void tick();
void setModeSignal(const std::string str);
void setFreqSignal(const std::string str);
void setDivTimLabel(const std::string str);
void setGraphPoints(uint16_t * values, uint16_t maxSize, float xScale = 1);
protected:
ModelListener* modelListener;
static Model* _instance;
std::string textMode;
std::string textFreq;
std::string textDivTim;
uint16_t* values; ///< Pointer to signal data.
uint16_t maxSize; ///< Maximum size of 'values' array.
float xScale; ///< X axis scaling factor.
#if (TOUCHGFX_BAREMETAL != 0)
bool flagMode;
bool flagDivTim;
bool flagFreq;
bool flagGraph;
#endif // TOUCHGFX_BAREMETAL
#if (TOUCHGFX_FREERTOS != 0)
xQueueHandle gui_msg_q;
#endif // TOUCHGFX_FREERTOS
};
#endif // MODEL_HPP

View File

@ -0,0 +1,26 @@
#ifndef MODELLISTENER_HPP
#define MODELLISTENER_HPP
#include <gui/model/Model.hpp>
class ModelListener
{
public:
ModelListener() : model(0) {}
virtual ~ModelListener() {}
void bind(Model* m)
{
model = m;
}
virtual void notifyModeChanged(std::string newMode){};
virtual void notifyFreqChanged(std::string newFreq){};
virtual void notifyDivTimChanged(std::string newDivTim){};
virtual void notifyDrawGraph(uint16_t * values, uint16_t maxSize, float xScale = 1){};
protected:
Model* model;
};
#endif // MODELLISTENER_HPP

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,34 @@
#include <gui/mainview_screen/MainViewView.hpp>
#include <gui/mainview_screen/MainViewPresenter.hpp>
MainViewPresenter::MainViewPresenter(MainViewView& v)
: view(v)
{
}
void MainViewPresenter::activate()
{
}
void MainViewPresenter::deactivate()
{
}
void MainViewPresenter::notifyModeChanged(std::string newMode){
view.setModeSignal(newMode);
}
void MainViewPresenter::notifyFreqChanged(std::string newFreq){
view.setFreqSignal(newFreq);
}
void MainViewPresenter::notifyDivTimChanged(std::string newDivTim){
view.setLabelDivTime(newDivTim);
}
void MainViewPresenter::notifyDrawGraph(uint16_t * values, uint16_t maxSize, float xScale /* = 1 */){
view.drawGraph(values, maxSize, xScale);
};

View File

@ -0,0 +1,75 @@
#include <cassert>
#include "gui/mainview_screen/MainViewView.hpp"
#include "app/gui.h"
MainViewView* MainViewView::_instance = nullptr;
MainViewView::MainViewView()
{
assert(!_instance);
if(_instance==nullptr){
_instance = this;
}
}
MainViewView* MainViewView::getInstance() {
return _instance;
}
void MainViewView::setupScreen()
{
MainViewViewBase::setupScreen();
}
void MainViewView::tearDownScreen()
{
MainViewViewBase::tearDownScreen();
}
void MainViewView::onBtnPlusPressed(){
oscilloscope::Gui::getInstance()->onButtonTimePlusPressed();
}
void MainViewView::onBtnMinusPressed(){
oscilloscope::Gui::getInstance()->onButtonTimeMinusPressed();
}
void MainViewView::onCheckBoxTriggerPressed(){
// Get actual state of the trigger checkbox by reading the status of the red LED
const bool checked = !redLedDisable.isVisible();
// Notify GUI
oscilloscope::Gui::getInstance()->onCheckBoxTriggerCheckState(checked);
}
void MainViewView::setModeSignal(const std::string str){
Unicode::fromUTF8((const unsigned char *)str.c_str(),labelSignalBuffer1,LABELSIGNALBUFFER1_SIZE);
labelSignal.invalidate();
}
void MainViewView::setFreqSignal(const std::string str){
Unicode::fromUTF8((const unsigned char *)str.c_str(),labelSignalBuffer2,LABELSIGNALBUFFER2_SIZE);
labelSignal.invalidate();
}
void MainViewView::setLabelDivTime(const std::string str){
Unicode::fromUTF8((const unsigned char *)str.c_str(),labelDivTimeBuffer,LABELDIVTIME_SIZE);
labelDivTime.invalidate();
}
void MainViewView::drawGraph(uint16_t* values, uint16_t maxSize, float xScale /* = 1 */){
chart.clear();
chartMajorXAxisGrid.setInterval(460/8); // Show 8 division on the chart
chart.setGraphRangeX(0, 460-1);
for(float addedPoints = 0, valuesIndex = 0;
(uint32_t)valuesIndex < maxSize and addedPoints < 460;
addedPoints++)
{
chart.addDataPoint(values[(uint32_t)valuesIndex]);
valuesIndex = addedPoints * xScale;
}
chart.invalidate();
}

View File

@ -0,0 +1,124 @@
#include <gui/model/Model.hpp>
#include <gui/model/ModelListener.hpp>
Model* Model::_instance = nullptr;
Model::Model() :
modelListener(0),
values(nullptr),
maxSize(0),
xScale(1.0f)
{
if(_instance==nullptr){
_instance = this;
}
#if (TOUCHGFX_FREERTOS != 0)
gui_msg_q = xQueueGenericCreate(5, sizeof(GUI_EVENT), 0);
#endif // TOUCHGFX_FREERTOS
#if (TOUCHGFX_BAREMETAL != 0)
flagMode = flagDivTim = flagFreq = flagGraph = false;
#endif // TOUCHGFX_BAREMETAL
}
Model* Model::getInstance() {
return _instance;
}
void Model::tick()
{
//*******************************************************
//
// HANDLE MESSAGES
//
// Check for messages from backend, with zero timeout to
// avoid blocking the UI.
//
//*******************************************************
//
#if (TOUCHGFX_FREERTOS != 0)
GUI_EVENT msg;
if (xQueueReceive(gui_msg_q, &msg, 0) == pdTRUE)
{
if(msg==FREQUENCY_EVENT){
modelListener->notifyFreqChanged(textFreq);
}
if(msg==MODE_EVENT){
modelListener->notifyModeChanged(textMode);
}
if(msg==DIVTIM_EVENT){
modelListener->notifyDivTimChanged(textDivTim);
}
if(msg==GRAPH_EVENT){
modelListener->notifyDrawGraph(values, maxSize);
}
}
#endif // TOUCHGFX_FREERTOS
#if (TOUCHGFX_BAREMETAL != 0)
if(this->flagFreq){
flagFreq=false;
modelListener->notifyFreqChanged(textFreq);
}
if(this->flagMode){
flagMode=false;
modelListener->notifyModeChanged(textMode);
}
if(this->flagDivTim){
flagDivTim=false;
modelListener->notifyDivTimChanged(textDivTim);
}
if(this->flagGraph){
flagGraph=false;
modelListener->notifyDrawGraph(values, maxSize, xScale);
}
#endif // TOUCHGFX_BAREMETAL
}
void Model::setGraphPoints(uint16_t * values, uint16_t maxSize, float xScale /* = 1 */){
this->values=values;
this->maxSize=maxSize;
this->xScale = xScale;
#if (TOUCHGFX_BAREMETAL != 0)
this->flagGraph=true;
#endif // TOUCHGFX_BAREMETAL
#if (TOUCHGFX_FREERTOS != 0)
GUI_EVENT msg = GRAPH_EVENT;
if(uxQueueMessagesWaiting(gui_msg_q)==0){
xQueueSend(gui_msg_q, &msg, 0);
}
#endif // TOUCHGFX_FREERTOS
// Makes async call to modelListener->notifyDrawGraph(...) see Model::tick()
}
void Model::setDivTimLabel(const std::string str){
textDivTim = str;
#if (TOUCHGFX_BAREMETAL != 0)
this->flagDivTim=true;
#endif // TOUCHGFX_BAREMETAL
#if (TOUCHGFX_FREERTOS != 0)
GUI_EVENT msg = DIVTIM_EVENT;
xQueueSend(gui_msg_q, &msg, 0);
#endif // TOUCHGFX_FREERTOS
}
void Model::setModeSignal(const std::string str){
textMode = str;
#if (TOUCHGFX_BAREMETAL != 0)
this->flagMode=true;
#endif // TOUCHGFX_BAREMETAL
#if (TOUCHGFX_FREERTOS != 0)
GUI_EVENT msg = MODE_EVENT;
xQueueSend(gui_msg_q, &msg, 0);
#endif // TOUCHGFX_FREERTOS
}
void Model::setFreqSignal(const std::string str){
textFreq = str;
#if (TOUCHGFX_BAREMETAL != 0)
this->flagFreq=true;
#endif // TOUCHGFX_BAREMETAL
#if (TOUCHGFX_FREERTOS != 0)
GUI_EVENT msg = FREQUENCY_EVENT;
xQueueSend(gui_msg_q, &msg, 0);
#endif // TOUCHGFX_FREERTOS
}