cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F746G-DISCO, hardware button, STM32CubeIDE

AD�?b
Senior

Hi

How to change the screen or widget with the hardware button?

best regards

Andrzej

1 ACCEPTED SOLUTION

Accepted Solutions
Peter BENSCH
ST Employee

You should follow the structure of Model-View-Presenter, e.g.

  • get the status of the hardware button outside of TouchGFX within main.c, e.g. via interrupt and a callback routine setting a global variable
  • model.hpp: declare this variable (extern)
  • model.cpp:
    • check this variable e.g. in the function model::tick() which gets called at the framerate of appr. 60Hz
    • call the virtual function of the modellistener which handles the button accordingly
  • modellistener.hpp: declare a virtual function, which handles the button
  • xyzPresenter.hpp: declare the same virtual function, which handles the button
  • xyzPresenter.cpp: define the function, which handles the button

The latter function in presenter.cpp might call e.g.:

static_cast<FrontendApplication*>(Application::getInstance())->goto_yourscreen_ScreenCoverTransitionEast();

When your question is answered, please close this topic by choosing Select as Best.

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

6 REPLIES 6
Peter BENSCH
ST Employee

You should follow the structure of Model-View-Presenter, e.g.

  • get the status of the hardware button outside of TouchGFX within main.c, e.g. via interrupt and a callback routine setting a global variable
  • model.hpp: declare this variable (extern)
  • model.cpp:
    • check this variable e.g. in the function model::tick() which gets called at the framerate of appr. 60Hz
    • call the virtual function of the modellistener which handles the button accordingly
  • modellistener.hpp: declare a virtual function, which handles the button
  • xyzPresenter.hpp: declare the same virtual function, which handles the button
  • xyzPresenter.cpp: define the function, which handles the button

The latter function in presenter.cpp might call e.g.:

static_cast<FrontendApplication*>(Application::getInstance())->goto_yourscreen_ScreenCoverTransitionEast();

When your question is answered, please close this topic by choosing Select as Best.

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
AD�?b
Senior

He Peter

I will write the program one by one. I will ask you to confirm whether it should be like this?

  • get the status of the hardware button outside of TouchGFX within main.c, e.g. via interrupt and a callback routine setting a global variable

in main() end task second:

/* USER CODE BEGIN 4 */
 
 
uint8_t we_tray;
 
 
xQueueHandle messageQ6;
 
void StartSecondTask(void const *argument)
{
	for (;;)
	{
 
	
		xQueueSend(messageQ6, &we_tray, 0); // send tray
 
		if(HAL_GPIO_ReadPin(WE_GPIO_Port, WE_Pin) == GPIO_PIN_SET)
			we_tray = 1;
		else
			we_tray = 0;
 
		osDelay(1);
	}
 
}
/* USER CODE END 4 */

Best regards

Andrzej

Peter BENSCH
ST Employee

The proposed approach was the most simple one not using an RTOS, catching the press of the button using an interrupt and pass this information to the MVP structure.

Of course you can alternatively use FreeRTOS, but currently you are sending a message before you get the status of the button - I would do it the other way around. The osDelay can also be omitted, since the button is debounced externally with a capacitor.

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

I will change the order, but it does not bother me.

I am not required to act quickly.

I need to know the condition of both drawer positions.

  • model.hpp: declare this variable (extern)

in model.hpp

This is it?

class ModelListener;
 
class Model
{
public:
	Model();
 
	void bind(ModelListener *listener)
	{
		modelListener = listener;
	}
 
	void tick();	
 
protected:
	
	bool we_tray;
 
	ModelListener *modelListener;
};
 
#endif // MODEL_HPP

AD�?b
Senior
  • model.cpp:
    • check this variable e.g. in the function model::tick() which gets called at the framerate of appr. 60Hz
    • call the virtual function of the modellistener which handles the button accordingly

I have added in model.cpp and modellistener.hpp

Is it okay?

#include <gui/model/Model.hpp>
#include <gui/model/ModelListener.hpp>
 
#include "FreeRTOS.h"
#include "queue.h"
#include "task.h"
 
bool we_tray;
 
extern "C"
{
xQueueHandle messageQ6;
}
 
Model::Model() :
		modelListener(0)
{
	messageQ6 = xQueueGenericCreate(1, 1, 0);
}
 
void Model::tick()
{
	
	if (xQueueReceive(messageQ6, &we_tray, 0) == pdTRUE)
		modelListener->SetTray(we_tray);
}
 
**************************************************************************
#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 SetTray(bool we_tray) {}
 
protected:
    Model* model;
};
 
#endif // MODELLISTENER_HPP
 

AD�?b
Senior

Thank you.

I did and it works. Switches the screen.

And how to make the widget or image invisible?

best regards

Andrzej