2020-11-23 08:46 AM
Hi
How to change the screen or widget with the hardware button?
best regards
Andrzej
Solved! Go to Solution.
2020-11-24 01:10 AM
You should follow the structure of Model-View-Presenter, e.g.
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
2020-11-24 01:10 AM
You should follow the structure of Model-View-Presenter, e.g.
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
2020-11-24 04:37 AM
He Peter
I will write the program one by one. I will ask you to confirm whether it should be like this?
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
2020-11-24 05: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.
2020-11-24 06: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.
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
2020-11-24 10:38 AM
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
2020-11-25 04:24 AM
Thank you.
I did and it works. Switches the screen.
And how to make the widget or image invisible?
best regards
Andrzej