Skip to main content
AD�?b
Senior
November 28, 2020
Solved

STM32F746G-DISCO, TouchGFX

  • November 28, 2020
  • 10 replies
  • 1924 views

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

This topic has been closed for replies.
Best answer by MM..1

replace attached files and try continue

10 replies

MM..1
Super User
November 29, 2020

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.

AD�?b
AD�?bAuthor
Senior
November 30, 2020

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 */

MM..1
Super User
November 30, 2020

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
AD�?bAuthor
Senior
November 30, 2020

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.

MM..1
MM..1Best answer
Super User
December 4, 2020

replace attached files and try continue

AD�?b
AD�?bAuthor
Senior
December 5, 2020

He

I figured out the problem. I make the clock in main.c and send it to the screen.

best regards

Andrzej

AD�?b
AD�?bAuthor
Senior
December 4, 2020

Thank You