2024-02-28 03:08 AM
I have generated a new project with Touch GFX Designer where I created a text area and also created a button, to which I have linked an interaction. This interaction will call on a new virtual function which I then plan on integrating with my external project files. I've created my projects .c and .h files in which I'm writing a simple arithmetic calculation. Note that my project files are in C whereas the Touch GFX generated files are in C++, I now want to call the arithmetic function in the model.cpp file and I'm unable to run the simulator on the Designer as it gives me an error.
File Path for Touch GFX generated files -> C:\TouchGFXProjects\MyApplication_2\CM7\TouchGFX\gui\src
Below are the files:
view.cpp
#include <gui/screen1_screen/Screen1View.hpp>
Screen1View::Screen1View()
{
}
void Screen1View::setupScreen()
{
Screen1ViewBase::setupScreen();
}
void Screen1View::tearDownScreen()
{
Screen1ViewBase::tearDownScreen();
}
void Screen1View::ButtonClicked(){
presenter->MathTest(7, 4);
}
void Screen1View::GetResult(uint16_t Result){
char buffer[20]; // Adjust the buffer size as needed
snprintf(buffer, sizeof(buffer), "%u", Result);
Unicode::strncpy(textArea1Buffer, buffer, TEXTAREA1_SIZE);
textArea1.invalidate();
}
view.hpp
#ifndef SCREEN1VIEW_HPP
#define SCREEN1VIEW_HPP
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
#include <cstdio>
class Screen1View : public Screen1ViewBase
{
public:
Screen1View();
virtual ~Screen1View() {}
virtual void setupScreen();
virtual void tearDownScreen();
void ButtonClicked(); //remove virtual
void GetResult(uint16_t Result);
protected:
};
#endif // SCREEN1VIEW_HPP
presenter.cpp
#include <gui/screen1_screen/Screen1View.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
Screen1Presenter::Screen1Presenter(Screen1View& v)
: view(v)
{
}
void Screen1Presenter::activate()
{
}
void Screen1Presenter::deactivate()
{
}
void Screen1Presenter::MathTest(uint16_t x, uint16_t y)
{
model->MathTest(x,y);
}
void Screen1Presenter::GetResult(uint16_t Result)
{
view.GetResult(Result);
}
presenter.hpp
#ifndef SCREEN1PRESENTER_HPP
#define SCREEN1PRESENTER_HPP
#include <gui/model/ModelListener.hpp>
#include <mvp/Presenter.hpp>
using namespace touchgfx;
class Screen1View;
class Screen1Presenter : public touchgfx::Presenter, public ModelListener
{
public:
Screen1Presenter(Screen1View& 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 ~Screen1Presenter() {}
virtual void MathTest(uint16_t x, uint16_t y);
// ModelListener callback
virtual void GetResult(uint16_t result);
private:
Screen1Presenter();
Screen1View& view;
};
#endif // SCREEN1PRESENTER_HPP
Model.cpp
#include <gui/model/Model.hpp>
#include <gui/model/ModelListener.hpp>
#ifndef SIMULATOR
#include "Mytest.h"
#include "stdio.h"
#endif
Model::Model() : modelListener(0)
{
}
void Model::tick()
{
}
uint16_t Model::MathTest(uint16_t x, uint16_t y)
{
#ifdef SIMULATOR
uint16_t Result = MathOp(x,y);///
modelListener->GetResult(Result);
return Result;
#else
return 0.0;
#endif
}
Model.hpp
#ifndef MODEL_HPP
#define MODEL_HPP
#include <cstdint>
class ModelListener;
class Model
{
public:
Model();
void bind(ModelListener* listener)
{
modelListener = listener;
}
void tick();
uint16_t MathTest(uint16_t x, uint16_t y);
protected:
ModelListener* modelListener;
};
#endif // MODEL_HPP
A source file (Mytest.c) -> C:\TouchGFXProjects\MyApplication_2\CM7\Core\Src
Myfile.h -> C:\TouchGFXProjects\MyApplication_2\CM7\Core\Inc
#include "Mytest.h"
uint16_t MathOp(uint16_t x, uint16_t y)
{
return x+y;
}
#ifndef APPLICATION_USER_CORE_MYTEST_H_
#define APPLICATION_USER_CORE_MYTEST_H_
#include <stdint.h> // Include <cstdint> for uint16_t
uint16_t MathOp(uint16_t x, uint16_t y);
#endif /* APPLICATION_USER_CORE_MYTEST_H_ */
The function MathOp was created for the arithmetic calculation which was called in the model.cpp file. Below is the error from the simulator on Touch GFX Designer:
2024-02-28 03:21 AM
2024-02-28 03:38 AM - edited 2024-02-28 03:39 AM
Normally you need to add the files and include paths related to your algorithm to the makefile under the path: simulator\gcc\Makefile
Example:
ADDITIONAL_SOURCES := ../Core/Src/Blabla.c
ADDITIONAL_INCLUDE_PATHS := ../Core/Inc
2024-02-28 04:50 AM
@koderboi22 did this answer your question?
2024-02-28 05:07 AM
Hi @SofLit , unfortunately no. I tried this method but the issue still persists. I'm working with British American Tobacco and wanted to ask if it would be possible to set up a Teams meeting by any chance so that we can discuss this further ?
2024-02-28 05:11 AM
Hello,
Not possible with Teams.
May @Mohammad MORADI ESFAHANIASL can help you.
If you need a deeper analysis you can contact your local Sales/FAE.
2024-02-28 05:14 AM
Just a question: are you sure about the paths you added in the makefile?
2024-02-28 05:19 AM
Hello
You probably must also define MathOp-func as extern "C" in Mytest.h since it is called from cpp-module.
Br JTP
2024-02-28 05:22 AM
Yes, I'm certain. I will give it another check and update on this.
2024-02-28 05:24 AM
Yes we've tried that but it didn't seem to work, I will give it another go with the files above and get back to you.