cancel
Showing results for 
Search instead for 
Did you mean: 

How does Clicklistener work?

mehmet06
Associate II

Hello

I'm an amateur Touchgfx user.
I've completed many challenging tasks with Touchgfx, but I need a very simple one.
I want to set the output port high for the duration of a keystroke.

I used the ClickListener instructions in the program, but they didn't work.
I tried creating Box1 the same way and it works perfectly.
With this code, it works while I hold the button down, and stops when I release it, just as I wanted.

void BRHZLView::boxClickHandler( const Box& b, const ClickEvent& evt)
{

if (evt.getType() == ClickEvent::PRESSED) {
HAL_GPIO_WritePin(GPIOG, BZR_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(GPIOB, PST_I_Pin, GPIO_PIN_SET);

} else if(evt.getType() == ClickEvent::RELEASED){

HAL_GPIO_WritePin(GPIOG, BZR_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOB, PST_I_Pin, GPIO_PIN_RESET);

}

But the flexbutton group keeps giving definition errors, and the program won't compile.
I'm using Stm32h7b3i Evk, and the definitions in the base file don't match the definitions at https://support.touchgfx.com/docs/development/ui-development/touchgfx-engine-features/mixins.

The program gives an error.
Could you please provide a link to a sample program?

 

_Base.hpp

/*********************************************************************************/
/********** THIS FILE IS GENERATED BY TOUCHGFX DESIGNER, DO NOT MODIFY ***********/
/*********************************************************************************/
#ifndef BRHZLVIEWBASE_HPP
#define BRHZLVIEWBASE_HPP

#include <gui/common/FrontendApplication.hpp>
#include <mvp/View.hpp>
#include <gui/brhzl_screen/BRHZLPresenter.hpp>
#include <touchgfx/widgets/Box.hpp>
#include <touchgfx/widgets/Image.hpp>
#include <touchgfx/widgets/BoxWithBorder.hpp>
#include <touchgfx/containers/buttons/Buttons.hpp>
#include <touchgfx/widgets/TextArea.hpp>
#include <touchgfx/mixins/ClickListener.hpp>
#include <touchgfx/widgets/TextAreaWithWildcard.hpp>

class BRHZLViewBase : public touchgfx::View<BRHZLPresenter>
{
public:
    BRHZLViewBase();
    virtual ~BRHZLViewBase();
    virtual void setupScreen();

    /*
     * Virtual Action Handlers
     */
    virtual void P_Gde()
    {
        // Override and implement this function in BRHZL
    }
    virtual void P_ILR()
    {
        // Override and implement this function in BRHZL
    }
    virtual void P_GRI()
    {
        // Override and implement this function in BRHZL
    }

protected:
    FrontendApplication& application() {
        return *static_cast<FrontendApplication*>(touchgfx::Application::getInstance());
    }

    /*
     * Member Declarations
     */
    touchgfx::Box __background;
    touchgfx::Image image1;
    touchgfx::BoxWithBorder boxWithBorder1;
    touchgfx::ImageButtonStyle< touchgfx::TouchButtonTrigger >  bck2;
    touchgfx::TextArea textArea1;
    touchgfx::TextArea textArea2;
    touchgfx::Image image2;
    touchgfx::ClickListener< touchgfx::TextButtonStyle< touchgfx::ImageButtonStyle< touchgfx::TouchButtonTrigger >  >  > P_ileri;
    touchgfx::ClickListener< touchgfx::TextButtonStyle< touchgfx::ImageButtonStyle< touchgfx::TouchButtonTrigger >  >  > P_geri;
    touchgfx::ClickListener< touchgfx::Box > box1;
    touchgfx::TextArea pgmi;
    touchgfx::ImageButtonStyle< touchgfx::ToggleButtonTrigger >  pg_ok;
    touchgfx::TextAreaWithOneWildcard hrkt_bar;
    touchgfx::TextButtonStyle< touchgfx::ImageButtonStyle< touchgfx::TouchButtonTrigger >  >  ileri2;
    touchgfx::ClickListener< touchgfx::TextButtonStyle< touchgfx::BoxWithBorderButtonStyle< touchgfx::ClickButtonTrigger >  >  > button1;

    /*
     * Wildcard Buffers
     */
    static const uint16_t HRKT_BAR_SIZE = 10;
    touchgfx::Unicode::UnicodeChar hrkt_barBuffer[HRKT_BAR_SIZE];

private:

    /*
     * Callback Declarations
     */
    touchgfx::Callback<BRHZLViewBase, const touchgfx::AbstractButtonContainer&> flexButtonCallback;

    /*
     * Callback Handler Declarations
     */
    void flexButtonCallbackHandler(const touchgfx::AbstractButtonContainer& src);

};

#endif // BRHZLVIEWBASE_HPP

 

2 REPLIES 2
mehmet06
Associate II
#ifndef BRHZLVIEW_HPP
#define BRHZLVIEW_HPP
#include <gui_generated/brhzl_screen/BRHZLViewBase.hpp>
#include <gui/brhzl_screen/BRHZLPresenter.hpp>

class BRHZLView : public BRHZLViewBase
{
public:
    BRHZLView();
    virtual ~BRHZLView() {}
    virtual void setupScreen();
    virtual void tearDownScreen();
    virtual void P_Gde();
    //  virtual void P_ILR();
    // virtual void P_GRI();

    virtual void HIZALA(uint8_t PILERI,uint8_t PGERI,uint8_t PSTOP);

      virtual void handleTickEvent();
    //void boxClickHandler(const Box& b, const ClickEvent& evt);
    void ButtonCallbackHandler(const TouchButtonTrigger& b , const  ClickEvent& evt);

protected:
         
         // Callback<BRHZLView, const Box&, const ClickEvent&> boxClickedCallback;

    Callback<BRHZLView, const  TouchButtonTrigger& , const  ClickEvent&> ButtonCallback;
};

#endif // BRHZLVIEW_HPP
mehmet06
Associate II
#include <gui/brhzl_screen/BRHZLView.hpp>
#include "main.h"


uint8_t pgde=0,PILERI=0,PGERI=0,PSTOP=0;


// BRHZLView::BRHZLView(): boxClickedCallback(this, &BRHZLView::boxClickHandler) { }

// BRHZLView::BRHZLView(): flexButtonCallback(this, &BRHZLView::flexButtonCallbackHandler) { }
BRHZLView::BRHZLView():ButtonCallback(this,&BRHZLView::ButtonCallbackHandler)
{

}

void BRHZLView::setupScreen()
{
    BRHZLViewBase::setupScreen();

    P_ileri.setAction(ButtonCallback);
 //box1.setClickAction(boxClickedCallback);
}

void BRHZLView::tearDownScreen()
{
    BRHZLViewBase::tearDownScreen();

}

 void BRHZLView::handleTickEvent()
{

}

 

void BRHZLView::setupScreen()

{

BRHZLViewBase::setupScreen();

 

P_ileri.setAction(ButtonCallback); // <<-- Now it only gives an error here

//box1.setClickAction(boxClickedCallback);

}

error mesage : 

C:/Users/Mehmet/Desktop/H7B-EV/POLYWELD/TouchGFX/gui/src/brhzl_screen/BRHZLView.cpp:20:23: error: cannot convert 'touchgfx::Callback<BRHZLView, const touchgfx::TouchButtonTrigger&, const touchgfx::ClickEvent&>' to 'touchgfx::GenericCallback<const touchgfx::AbstractButtonContainer&>&'

20 | P_ileri.setAction(ButtonCallback);

| ^~~~~~~~~~~~~~

| |

| touchgfx::Callback<BRHZLView, const touchgfx::TouchButtonTrigger&, const touchgfx::ClickEvent&>