cancel
Showing results for 
Search instead for 
Did you mean: 

Buttons digital selection with hardware external buttons

f.padoan
Associate II

Hi, I have a fix menu of three buttons which are fixed for all my screens, when I use the simulator in TouchGFX I can just click on top of each button, but in the real hardware I only have one button to scroll right or left throw all the digital buttons available and another hardware button to select.

 

How can I made the preselection of each digital button with the hardware buttons, in others words to see the state of selected button but not made the action before the button selection is pressed?

1 REPLY 1
Panchev68
Senior

that's how it is with me, hope it helps. this is for encoder but for external buttons it is analgogic.

file: TouchGFX\target\TouchGFXHAL.cpp

 

 

/* USER CODE BEGIN TouchGFXHAL.cpp */

#include "Project/TouchGFX/CButtonController.hpp"

using namespace touchgfx;

void TouchGFXHAL::initialize ()
{
    // Calling parent implementation of initialize().
    //
    // To overwrite the generated implementation, omit call to parent function
    // and implemented needed functionality here.
    // Please note, HAL::initialize() must be called to initialize the framework.

    TouchGFXGeneratedHAL::initialize ();

    // --- Add My Button Controller ---

    auto & buton_controller = CButtonController::getInstance ();
    buton_controller.init ();
    setButtonController (&buton_controller);
}
/// \file CButtonController.hpp

#pragma once
#include "EKeyCodes.hpp"
#include "Project/BSP/BSP.hpp"
#include <platform/driver/button/ButtonController.hpp>

/// \brief Button Controller class
/// \include{doc} CButtonController.md
class CButtonController : public touchgfx::ButtonController
{
public:

    /// \brief Initialize Button Controller
    void init () override
    {
        BSP::Encoder.init ();
    }

    /// \brief Read Button Controller Code
    /// \param key - keycode
    /// \return bool - is new code
    bool sample (uint8_t & key) override
    {
        using EEventCode = BSP::CEncoder::EEventCode;

        switch (BSP::Encoder.tick ())
        {
        case EEventCode::NONE:
            key = EKeyCodes::NONE;
            return false;
        case EEventCode::BUTTON_PUSH:
            key = EKeyCodes::BUTTON_PUSH;
            break;
        case EEventCode::BUTTON_PULL:
            key = EKeyCodes::BUTTON_PULL;
            break;
        case EEventCode::BUTTON_HOLD:
            key = EKeyCodes::BUTTON_HOLD;
            break;
        case EEventCode::ENCODER_CW:
            key = EKeyCodes::ENCODER_CW;
            break;
        case EEventCode::ENCODER_CCW:
            key = EKeyCodes::ENCODER_CCW;
            break;
        }

        return true;
    }

    /// \brief Get the Singleton Instance
    /// \return CButtonController&
    static CButtonController &
        getInstance ()

    {
        static CButtonController instance;
        return instance;
    }

    ~CButtonController () = default;

private:

    CButtonController () = default;
};