2019-09-26 08:58 AM
Hi all,
For debugging purposes I would like to add hardware button presses to the simulator view in order to be able to better mimic the hardware that we run on (keypresses are working on the hardware already). I've edited the makefile used to build the simulator to include my added code, and I followed the same procedure of creating a KeySampler class that is of the type touchgfx::ButtonController and added the
static_cast<HALSDL2&>(hal).setButtonController(&btn);
To main.cpp. Right now for simplicity's sake the sample function of the class always returns "true" with the button press value hard coded to match one that should produce a reaction on the screen. Despite this the simulator GUI does not respond to the "button press". Using the touchgfx_printf() shows that the initialization for the KeySampler is being called, but that the sample function is not. Am I taking the wrong approach? Does this work differently in the simulator HAL than the hardware HAL?
Thank you,
Don
Solved! Go to Solution.
2019-09-27 11:59 AM
I've figured out how to best mimic button presses for my application. It took a change to 'FrontendApplication.cpp" and its corresponding header. The implementation will vary for different designs but mine ended up looking like this:
hpp:
#ifndef FRONTENDAPPLICATION_HPP
#define FRONTENDAPPLICATION_HPP
#include <gui_generated/common/FrontendApplicationBase.hpp>
#include <Windows.h>
class FrontendHeap;
using namespace touchgfx;
class FrontendApplication : public FrontendApplicationBase
{
public:
FrontendApplication(Model& m, FrontendHeap& heap);
virtual ~FrontendApplication() { }
void handleTickEvent();
private:
virtual void sampleKeys(){
if(GetKeyState('1') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<0));
}
else if(GetKeyState('2') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<1));
}
else if(GetKeyState('3') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<2));
}
else if(GetKeyState('4') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<3));
}
else if(GetKeyState('5') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<4));
}
else if(GetKeyState('6') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<5));
}
else if(GetKeyState('7') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<6));
}
else if(GetKeyState('8') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<7));
}
return;
}
};
#endif
.cpp:
#include <gui/common/FrontendApplication.hpp>
void FrontendApplication::handleTickEvent()
{
model.tick();
FrontendApplicationBase::handleTickEvent();
this->sampleKeys();
}
FrontendApplication::FrontendApplication(Model& m, FrontendHeap& heap)
: FrontendApplicationBase(m, heap)
{
}
This will align the number keys 1-8 with the hardware keys on the device we are generating the template for.
2019-09-27 07:19 AM
#ifdef SIMULATOR
void FrontendApplication::handleKeyEvent(uint8_t c)
{
touchgfx::MVPApplication::handleKeyEvent(c);
if (c == 'a')
{
model.aPressed();
return;
}
if (c == 'b')
{
model.bPressed();
return;
}
....
}
#endif
2019-09-27 07:22 AM
@DWeie - My initial idea was to see how far i could get by simply posting some code, but i changed my mind :)
The idea here is that you have access to the model, the same interface that your tasks do, so you can use the simulator to simulate an external event.
What i described in the above snippet is a manual way of doing it. You can also react to button pressed from within the designer which can generate the code for you. Take a look and see what works for you.
/Martin
2019-09-27 07:49 AM
Thanks for the response Martin. I'm adding some code similar to what you've posted but I'm getting an error
gui/src/common/FrontendApplication.cpp:11:51: error: no 'void FrontendApplication::handleKeyEvent(uint8_t)' member function declared in class 'FrontendApplication'
Looking into the .hpp files seems to support this error message since I can't find a declaration of 'handleKeyEvent' that is part of the FrontendApplication class. If it's not defined it seems doubtful to me that the function would be called 'under the hood'. I'm sure I'm missing something important so I'll keep looking to see what I can figure out. The goal here is to write code that will be added as part of the template we generate so that all future projects using this template will seamlessly emulate the hardware they are meant to run on. Will the code you posted be portable between projects? I'm a bit of a cpp novice so I may be misunderstanding it, but it seems to me that the model needs to already have button presses defined in the model or there will be errors using this code.
2019-09-27 07:54 AM
Thanks for the response Martin. I'm adding some code similar to what you've posted but I'm getting an error
gui/src/common/FrontendApplication.cpp:11:51: error: no 'void FrontendApplication::handleKeyEvent(uint8_t)' member function declared in class 'FrontendApplication'
Looking into the .hpp files seems to support this error message since I can't find a declaration of 'handleKeyEvent' that is part of the FrontendApplication class. If it's not defined it seems doubtful to me that the function would be called 'under the hood'. I'm sure I'm missing something important so I'll keep looking to see what I can figure out. The goal here is to write code that will be added as part of the template we generate so that all future projects using this template will seamlessly emulate the hardware they are meant to run on. Will the code you posted be portable between projects? I'm a bit of a cpp novice so I may be misunderstanding it, but it seems to me that the model needs to already have button presses defined in the model or there will be errors using this code.
2019-09-27 11:59 AM
I've figured out how to best mimic button presses for my application. It took a change to 'FrontendApplication.cpp" and its corresponding header. The implementation will vary for different designs but mine ended up looking like this:
hpp:
#ifndef FRONTENDAPPLICATION_HPP
#define FRONTENDAPPLICATION_HPP
#include <gui_generated/common/FrontendApplicationBase.hpp>
#include <Windows.h>
class FrontendHeap;
using namespace touchgfx;
class FrontendApplication : public FrontendApplicationBase
{
public:
FrontendApplication(Model& m, FrontendHeap& heap);
virtual ~FrontendApplication() { }
void handleTickEvent();
private:
virtual void sampleKeys(){
if(GetKeyState('1') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<0));
}
else if(GetKeyState('2') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<1));
}
else if(GetKeyState('3') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<2));
}
else if(GetKeyState('4') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<3));
}
else if(GetKeyState('5') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<4));
}
else if(GetKeyState('6') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<5));
}
else if(GetKeyState('7') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<6));
}
else if(GetKeyState('8') & 0x8000){
FrontendApplicationBase::handleKeyEvent((1<<7));
}
return;
}
};
#endif
.cpp:
#include <gui/common/FrontendApplication.hpp>
void FrontendApplication::handleTickEvent()
{
model.tick();
FrontendApplicationBase::handleTickEvent();
this->sampleKeys();
}
FrontendApplication::FrontendApplication(Model& m, FrontendHeap& heap)
: FrontendApplicationBase(m, heap)
{
}
This will align the number keys 1-8 with the hardware keys on the device we are generating the template for.