2019-10-07 12:54 PM
I have a simple repeat button that increments a value as you hold it in. However, I would like to change the repeat button on release so that the next time it is held in, it decrements the value.
I'm new to object orientated programming as well so a complete answer will be highly appreciated. Thanks
Solved! Go to Solution.
2023-03-10 05:35 AM
Weird. Are you sill using repeatButton (even though it seems to work exactly the same as normal button with ClickListener) ? Can you show your code ?
2023-03-10 06:41 AM
I didn't use repeatButton. But I also tried the repeatButton, it didn't work.
As long as the button is pressed, the LED does not stay on.
My Parameter_Setting View
Parameter_SettingView.hpp
#ifndef PARAMETER_SETTINGVIEW_HPP
#define PARAMETER_SETTINGVIEW_HPP
#include <gui_generated/parameter_setting_screen/Parameter_SettingViewBase.hpp>
#include <gui/parameter_setting_screen/Parameter_SettingPresenter.hpp>
class Parameter_SettingView : public Parameter_SettingViewBase
{
public:
Parameter_SettingView();
virtual ~Parameter_SettingView() {}
virtual void setupScreen();
virtual void tearDownScreen();
void buttonClickHandler(const Button& b,const ClickEvent& e);
protected:
Callback<Parameter_SettingView, const Button&,const ClickEvent&> buttonClickedCallback;
};
#endif // PARAMETER_SETTINGVIEW_HPP
Parameter_SettingView.cpp
#include <gui/parameter_setting_screen/Parameter_SettingView.hpp>
#include "main.h"
Parameter_SettingView::Parameter_SettingView():
buttonClickedCallback(this,&Parameter_SettingView::buttonClickHandler)
{
}
void Parameter_SettingView::setupScreen()
{
Parameter_SettingViewBase::setupScreen();
button1.setClickAction(buttonClickedCallback);
}
void Parameter_SettingView::tearDownScreen()
{
Parameter_SettingViewBase::tearDownScreen();
}
void Parameter_SettingView::buttonClickHandler(const Button& b,const ClickEvent& e)
{
if(&b==&button1) // button1 -> your button name
{
switch(e.getType())
{
case ClickEvent::PRESSED:
HAL_GPIO_WritePin(BUT3_LED_RD_GPIO_Port, BUT3_LED_RD_Pin, GPIO_PIN_SET);
// Set LED on here !!
break;
default:
HAL_GPIO_WritePin(BUT3_LED_RD_GPIO_Port, BUT3_LED_RD_Pin, GPIO_PIN_RESET);
// this handles REALEASED and CANCEL- events !
// Set LED off here !!
break;
}
}
}
2023-03-10 07:31 AM
OK, with quick look everything seems to be correct. Is your electronic a custom board or some Discovery etc ? Just wonder could it be a problem in the touch regonition system since you seem to have problems with various type of implementations for this simple led control function.
2023-03-13 12:16 AM
My electronic board is a custom board. I don't think there is a problem with the led control, because I can flash the led in other algorithms. There are 10 different screen views, dozens of buttons, pictures, etc. in my project. My software is almost finished.
In the pressed routine, I tried not only led but also relay and register control. The problem is always the same. When the button is pressed, it enters the Pressed routine, it works correctly, and the led turns on. But although the button is still pressed, the realeased routine runs and the led turns off. I think the problem is that it cannot detect that the button is still pressed.
2023-03-13 12:59 AM
Ok so this is terrible codding on my part but in my example I used a flex button which calls a function on "click" (instead of on "release" like other buttons) and just check in the handleTickEvent function if the button is still pressed at every tick using the getPressed() function (the documentation mentions getPressedState() but the code imposes getPressed() instead, there might be a need to update the API). Once it is released the animation is canceled, in your case you call the function you want to finish. If you need the activate function to be called all the time/at every tick when the button is pressed you can just put an "else" to the "if (flexButton1.getPressed() == false)" in the handleTickEvent() function.
Would that work in your case ? Works on an stm32h7b3dk board I have, so if it does not work on your board then the issue is the touch handling.
/Romain
2023-03-17 04:47 AM
I tried the sample app you suggested. Unfortunately, it still goes into the not pressed routine while the button is pressed.
I found a solution like this. I have defined a variable in the touchscreen driver software to the state where it stays pressed. I created an interaction function when the button is pressed. In the function routine of the "screenview.cpp" software, I defined the button being pressed with a variable. I checked both these variables in the handleTickEvent routine in screenview.cpp. If the button is pressed, the led stays on, when it is not pressed, the led goes off.
It worked this way.