cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746G-DISCO, TouchGFX

AD�?b
Senior

Hi

I made a timer. I send seconds and minutes to Model and to main.c.

I want seconds and minutes to be visible in main.c.

Now they are only visible after changing the screen.

What I have to do?

best regards

Andrzej

1 ACCEPTED SOLUTION

Accepted Solutions

replace attached files and try continue

View solution in original post

10 REPLIES 10
MM..1
Chief II

Hi Andrzej,

minutes and seconds is special, maybe connected to RTC, but any variables created in Model can be as extern accessible in main or any place, where extern is included.

I mean you now create it in screen, this dont work when you use more as one screen , because this variables exist only while screen is showed.

And when you plan your timer count alltime, then update values must be in Model tick, not screen handletick.

That's what I have done and it doesn't work.

What to improve?

#ifndef MODEL_HPP
#define MODEL_HPP
 
#include <touchgfx/hal/types.hpp>
 
#include "stdint.h"
 
class ModelListener;
 
class Model
{
public:
	Model();
 
	void bind(ModelListener *listener)
	{
		modelListener = listener;
	}
 
	void tick();
 
	void saveMinCurrent(uint8_t saveMinCurrent)
	{
		min_current = saveMinCurrent;
	}
 
	void saveSecCurrent(uint8_t saveSecCurrent)
	{
		sec_current = saveSecCurrent;
	}
 
	uint8_t getSecCurrent()
	{
		return sec_current;
	}
 
protected:
 
	uint8_t min_current;
	uint8_t sec_current;
	
	ModelListener *modelListener;
};
 
#endif // MODEL_HPP
#include <gui/model/Model.hpp>
#include <gui/model/ModelListener.hpp>
 
#include "FreeRTOS.h"
#include "queue.h"
#include "task.h"
 
extern uint8_t min_current;
extern uint8_t sec_current;
 
extern "C"
{
xQueueHandle messageQ4;
xQueueHandle messageQ5;
}
 
Model::Model() :
		modelListener(0)
{
	
	messageQ4 = xQueueGenericCreate(1, 1, 0);
	messageQ5 = xQueueGenericCreate(1, 1, 0);
	
}
 
void Model::tick()
{
	
	xQueueSend(messageQ4, &min_current, 0); // send minutes current
	xQueueSend(messageQ5, &sec_current, 0); // send secons current
 
}
 
 
/* USER CODE BEGIN 4 */
 
uint8_t min_current;
uint8_t sec_current;
 
xQueueHandle messageQ4;
xQueueHandle messageQ5;
 
void StartSecondTask(void const *argument)
{
	for (;;)
	{
receive seconds
		if(xQueueReceive(messageQ4, &min_current, 0) == pdTRUE); // receive minutes current
		if(xQueueReceive(messageQ5, &sec_current, 0) == pdTRUE); // receive seconds current
 
		osDelay(1);
	}
 
}
/* USER CODE END 4 */

No you dont uderstand me. I explain use simple shared memory variables.

Your code try use queues , but this is not strictly necessary on one core multithread.

Simply create one header file sharedvars.h

extern uint8_t min_current;
extern uint8_t sec_current;

then in Model.hpp remove protected and too functions get save...

and in Model.cpp

#include <gui/model/Model.hpp>
#include <gui/model/ModelListener.hpp>
 
#include "FreeRTOS.h"
#include "queue.h"
#include "task.h"
 
uint8_t min_current;
uint8_t sec_current;
 
Model::Model() :
		modelListener(0)
{
	
}
 
void Model::tick()
{
// do here what you need with sec and min for example call screen update methods
	
}
 

in main or other task.c

#include "sharedvars.h"
 
void StartSecondTask(void const *argument)
{
	for (;;)
	{
//do what you need with sec and min for example read RTC and write to sec_current...
           sec_current = 22;
		osDelay(1);
	}
 
}

AD�?b
Senior

Thanks for the hint.

Take into account that I am not very advanced with TouchGFX and C ++. So far I have worked at C.

Tomorrow I will analyze what you wrote.

I'll create a simple program and send it all.

He MM..1

I tested but it doesn't work as I want.

I made a simple example.

Two screens: 1. sets the end of timing 2. counts time.

In main.c I want to compare min with min_current and set the output signal depending on it.

The variable min is passed to main.c when the screen changes. So does the min_current variable. However, only after changing the screen. But I want it to be visible on a regular basis.

I sent the entire project. Please help.

best regards

Andrzej

Hi Andrzej,

my code give you classic C usage in TouchGFX , but you still use C++ and quees. Then now you have big chaos in variables.

I check your code and same named variables you declare in main, then in Model, then as protectd in model.hpp, screen1.hpp and screen2.hpp.

Realy you now have five not connected variables named min_current ...

uint8_t start;
uint8_t stop;
uint8_t min_current;
uint8_t min;
uint32_t time_current;
 
//in header file you need add too
#ifdef __cplusplus
 extern "C" {
#endif
 
extern uint8_t start,stop,min,min_current;
 
#ifdef __cplusplus
}
#endif

this code must exist only once, in all other .c or .cpp you only use extern or include extern defs.

I use struct for better organize.

And then in protected create only local screen vars for compare.

Example for you

void ScreenStopView::handleTickEvent()
{
if(loca_showmin != min_current) {
       loca_showmin=min_current;
	Unicode::snprintf(AreaCurrentBuffer, AREACURRENT_SIZE, "%d", min_current);
 
	AreaCurrent.invalidate();
      }
}
 //increment is moved to model for count alltime
void Model::tick()
{
	time_current++;
	min_current = time_current / (60 * 60);
}

I am going back to the first proposal because I am lost.

I continue with the "device" program I sent. I start from the beginning. device.touchGFX unchanged.

I will write step by step and ask for advice.

Do I have to declare the min variable in ScreenStartView.hpp and sharedvars.h?

How do I pass the min variable to main.c?

replace attached files and try continue

AD�?b
Senior

Thank You