STM32F746G-DISCO, hardware button, STM32CubeIDE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-23 8:46 AM
Hi
How to change the screen or widget with the hardware button?
best regards
Andrzej
Solved! Go to Solution.
- Labels:
-
STM32CubeIDE
-
STM32F7 Series
-
TouchGFX
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-24 1:10 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-24 1:10 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-24 4:37 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-24 5:36 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-24 6:38 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-24 10:38 AM
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-25 4:24 AM
Thank you.
I did and it works. Switches the screen.
And how to make the widget or image invisible?
best regards
Andrzej
