2020-02-18 08:39 PM
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
#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?
2020-02-19 04:50 AM
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
2020-02-19 04:56 AM
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.
2020-02-19 04:58 AM
I use keil, and my project comiled good. But I can't compile it with physyical buttons library
2020-02-19 05:04 AM
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.
2020-02-19 05:08 AM
Can you upload your ptoject here? For keil, if you can.
2020-02-19 05:30 AM
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.
2020-02-19 09:34 AM
Thanks! Compiling is without errors.
Works good!
2020-02-19 09:54 AM
Only one problem
Then I make changes in CubeMX project, changes in TouchGFXConfiguration.cpp not saving ((
Can you make in future versions of CubeMX possibility to use something like /* USER CODE BEGIN 2 */ /* USER CODE END 2 */ ?
2020-02-19 10:42 AM
All working very well.
I checked many iteractions, triggered by button click.
But then I add iteraction which changes TextArea after buttonclick - program goes to HardFault immediatly after start.
What's wrong?