Skip to main content
February 19, 2020
Question

Problem with interface with physical buttons

  • February 19, 2020
  • 2 replies
  • 1348 views

Hello!

I try to create intefrace with physical buttons, following this instruction https://touchgfx.zendesk.com/hc/en-us/articles/205074551-Interfacing-with-physical-buttons

  1. I Added  ../Middlewares/ST/touchgfx/framework/include/platform/driver/button to include path
  2. I created file Keysamper.cpp and added to it

#include "KeySampler.hpp"
#include "touchgfx/HAL/Buttons.hpp"
using namespace touchgfx;
void KeySampler::init()
{
 //Initialise gpio for buttons here 
}
bool KeySampler::sample(uint8_t &key)
{
// unsigned int buttons = ...; //sample GPIO
 //Return true if button 1 was pressed, save 1 to key argument 
 //Return true if button 2 was pressed, save 2 to key argument 
// ...
 return false;
}

3. I created file Keysampler.hpp and added to it

class KeySampler : public touchgfx::ButtonController
{
public:
 KeySampler() {
 init();
 }
 virtual ~KeySampler() {}
 virtual void init();
 virtual bool sample(uint8_t& key);
};

4. I modified file TouchGFXConfiguration.hpp

KeySampler btnCtrl;
 
void touchgfx_init()
{
 Bitmap::registerBitmapDatabase(BitmapDatabase::getInstance(), BitmapDatabase::getInstanceSize());
 TypedText::registerTexts(&texts);
 Texts::setLanguage(0);
 
 FontManager::setFontProvider(&fontProvider);
 
 FrontendHeap& heap = FrontendHeap::getInstance();
 (void)heap; // we need to obtain the reference above to initialize the frontend heap.
 
 hal.initialize();
 hal.enableLCDControllerInterrupt();
 hal.enableInterrupts();
	 hal.setButtonController(&btnCtrl); //Enable button controller
}

6. try to complie, got errors

..\Drivers\KeySampler.hpp(1): error: #276: name followed by "::" must be a class or namespace name

 class KeySampler : public touchgfx::ButtonController

..\Drivers\KeySampler.hpp(1): error: #262: not a class or struct name

 class KeySampler : public touchgfx::ButtonController

..\Drivers\KeySampler.hpp(9): error: #20: identifier "uint8_t" is undefined

   virtual bool sample(uint8_t& key);

../TouchGFX/target/generated/TouchGFXConfiguration.cpp(38): error: #20: identifier "KeySampler" is undefined

 KeySampler btnCtrl;

What's wrong?

This topic has been closed for replies.

2 replies

Alexandre RENOUX
Visitor II
February 19, 2020

Hello,

What do you use to compile your code ? IAR, TouchGFX Designer or something else ?

I created an empty project with a box as a background and a tiled image using the application template for STM32F746G_DISCO and compiled using IAR and TouchGFX Designer. I do not get the error you encounter.

/Alexandre

February 19, 2020

I can't understand you.

I asked about interface with physical buttons. You wrote me about empty project with image.

​Did you configure interface with physical buttons?

Phisicysical buttons is GPIO.​

Alexandre RENOUX
Visitor II
February 19, 2020

Sorry I did not specified it but I implemented the files you are talking about in your post and which can be also found in the article you linked.

Alexandre RENOUX
Visitor II
February 19, 2020

I think your error comes from your Keysampler.hpp file. You should include the header file for ButtonController, otherwise, it cannot know from which class it should inherit from.

Here is a corrected version :

#ifndef KEYSAMPLER_HPP
#define KEYSAMPLER_HPP
 
#include <platform/driver/button/ButtonController.hpp>
 
class KeySampler : public touchgfx::ButtonController
{
public:
 KeySampler() {
 init();
 }
 virtual ~KeySampler() {}
 virtual void init();
 virtual bool sample(uint8_t& key);
};
 
#endif /* KEYSAMPLER_HPP */

If you still have compiling errors, please feel free to post again and we will see how to resolve it.

February 19, 2020

Thanks! Compiling is without errors.

Works good!