Skip to main content
Associate
August 24, 2023
Question

Communication between model and backend

  • August 24, 2023
  • 8 replies
  • 3163 views

Hello,

I am wondering what is a good way to tell TouchGFX with what objects of the backend to communicate. If for example my application has some backend object "Foo bar" that I want TouchGFX to communicate with, for now the only solution I see is to declare these objects with "extern Foo bar" in the model and essentially reference it as a global variable. For testing and simulation purposes it would be great to pass data (references/pointers) from the backend to the model, e.g., to the constructor. Is there an easy way to do this?

Cheers, Max

This topic has been closed for replies.

8 replies

Karl Yamashita
Principal
August 24, 2023
If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
Senior
August 24, 2023

The idea is the opposite.
in Model::tick() you check for data change and call the appropriate modelListener callback

see  : Propagating Data to UI 

There is no way to control the creation of the model instance. So the parameters in the constructor are not useful. But the model can inherit (or instantiate) your own classes that handle communication with your backend object.

CI_maxAuthor
Associate
August 25, 2023

Sure, I understand that in Model::tick() you check if some state has changed and then pass it to the modelListener. But still, you need to make the model aware of what objects to communicate with. Even having a message queue from some RTOS requires both the model and some other task to refer to some common message queue object. If there is no way to either pass data to the model constructor or pass data to the model from the backend after creation then the only way is to use global variables, right? 

Senior
August 26, 2023

I can not understand the question !

The data is in the class in the instance of the class Foo -  bar. right !?

example:

 

/// \file Project\Foo.hpp
#pragma once

class Foo
{
public:

 Foo () = default;
 ~Foo () = default;
 uint32_t Value = 0;
};

 

/// \file Project\Bar.cpp
#include "Project\Foo.hpp"

Foo bar;

 

/// \file Model.cpp
#include "Project\Foo.hpp"
extern Foo bar;

Model::Model ()
{}

void Model::tick ()
{
 static uint32_t bar_value =0;
	if (bar.Value!=bar_value)
 {
		bar_value = bar.Value;
 modelListener->notifyBarValueChanged(bar_value) ;
 }
}