2024-08-22 08:13 AM
Hi,
I am playing with a G071RB evalboard + GFX01M2 display shield atm and noticed some faulty code being generated by TouchGFX designer 4.24.0. The evalboard features a User Button and the display shield has a joystick-like control element with 5 contacts
The TouchGFX Designer generates a MB1642ButtonController.cpp which has bugs in the getKeyState method.
First failure is to return characters instead of integers, e.g.
keyPressed = '5'
instead of
keyPressed = 5
this fails when compared with
"Key": 5
configured in the .touchgfx file. Because of that no button press is registered.
Second
For the User Button on the evalboard the same method returns 0 (zero).
keyPressed = 0;
But zero is also the default value, so the button press is ignored. Changed it to return 1 and voilà, it works.
The code generated:
"PhysicalButtons": [
{
"Key": 1,
"Name": "BUTTON_USER"
},
{
"Key": 5,
"Name": "BUTTON_CENTER"
}
],
uint8_t MB1642ButtonController::getKeyState(void)
{
uint8_t keyPressed = 0;
if (touchgfx::HAL::getInstance()->getDisplayOrientation() == touchgfx::ORIENTATION_PORTRAIT)
{
if (HAL_GPIO_ReadPin(BUTTON_CENTER_GPIO_Port, BUTTON_CENTER_Pin) == GPIO_PIN_RESET)
{
keyPressed = '5'; // Corresponds to keyboard keypad center
}
else if (HAL_GPIO_ReadPin(BUTTON_LEFT_GPIO_Port, BUTTON_LEFT_Pin) == GPIO_PIN_RESET)
{
keyPressed = '4'; // Corresponds to keyboard keypad left
}
else if (HAL_GPIO_ReadPin(BUTTON_RIGHT_GPIO_Port, BUTTON_RIGHT_Pin) == GPIO_PIN_RESET)
{
keyPressed = '6'; // Corresponds to keyboard keypad right
}
else if (HAL_GPIO_ReadPin(BUTTON_UP_GPIO_Port, BUTTON_UP_Pin) == GPIO_PIN_RESET)
{
keyPressed = '8'; // Corresponds to keyboard keypad up
}
else if (HAL_GPIO_ReadPin(BUTTON_DOWN_GPIO_Port, BUTTON_DOWN_Pin) == GPIO_PIN_RESET)
{
keyPressed = '2'; // Corresponds to keyboard keypad down
}
//Blue user button on Nucleo boad
else if (HAL_GPIO_ReadPin(BUTTON_USER_GPIO_Port, BUTTON_USER_Pin) == GPIO_PIN_RESET)
{
keyPressed = '0';
}
}
else
{
if (HAL_GPIO_ReadPin(BUTTON_CENTER_GPIO_Port, BUTTON_CENTER_Pin) == GPIO_PIN_RESET)
{
keyPressed = '5'; // Corresponds to keyboard keypad enter
}
else if (HAL_GPIO_ReadPin(BUTTON_LEFT_GPIO_Port, BUTTON_LEFT_Pin) == GPIO_PIN_RESET)
{
keyPressed = '8'; // Corresponds to keyboard keypad up
}
else if (HAL_GPIO_ReadPin(BUTTON_RIGHT_GPIO_Port, BUTTON_RIGHT_Pin) == GPIO_PIN_RESET)
{
keyPressed = '2'; // Corresponds to keyboard keypad down
}
else if (HAL_GPIO_ReadPin(BUTTON_UP_GPIO_Port, BUTTON_UP_Pin) == GPIO_PIN_RESET)
{
keyPressed = '6'; // Corresponds to keyboard keypad right
}
else if (HAL_GPIO_ReadPin(BUTTON_DOWN_GPIO_Port, BUTTON_DOWN_Pin) == GPIO_PIN_RESET)
{
keyPressed = '4'; // Corresponds to keyboard keypad left
}
//Blue user button on Nucleo boad
else if (HAL_GPIO_ReadPin(BUTTON_USER_GPIO_Port, BUTTON_USER_Pin) == GPIO_PIN_RESET)
{
keyPressed = '0';
}
}
return keyPressed;
}
The fixed code:
uint8_t MB1642ButtonController::getKeyState(void)
{
uint8_t keyPressed = 0;
if (touchgfx::HAL::getInstance()->getDisplayOrientation() == touchgfx::ORIENTATION_PORTRAIT)
{
if (HAL_GPIO_ReadPin(BUTTON_CENTER_GPIO_Port, BUTTON_CENTER_Pin) == GPIO_PIN_RESET)
{
keyPressed = 5; // Corresponds to keyboard keypad center
}
else if (HAL_GPIO_ReadPin(BUTTON_LEFT_GPIO_Port, BUTTON_LEFT_Pin) == GPIO_PIN_RESET)
{
keyPressed = 4; // Corresponds to keyboard keypad left
}
else if (HAL_GPIO_ReadPin(BUTTON_RIGHT_GPIO_Port, BUTTON_RIGHT_Pin) == GPIO_PIN_RESET)
{
keyPressed = 6; // Corresponds to keyboard keypad right
}
else if (HAL_GPIO_ReadPin(BUTTON_UP_GPIO_Port, BUTTON_UP_Pin) == GPIO_PIN_RESET)
{
keyPressed = 8; // Corresponds to keyboard keypad up
}
else if (HAL_GPIO_ReadPin(BUTTON_DOWN_GPIO_Port, BUTTON_DOWN_Pin) == GPIO_PIN_RESET)
{
keyPressed = 2; // Corresponds to keyboard keypad down
}
//Blue user button on Nucleo boad
else if (HAL_GPIO_ReadPin(BUTTON_USER_GPIO_Port, BUTTON_USER_Pin) == GPIO_PIN_RESET)
{
keyPressed = 1;
}
}
else
{
if (HAL_GPIO_ReadPin(BUTTON_CENTER_GPIO_Port, BUTTON_CENTER_Pin) == GPIO_PIN_RESET)
{
keyPressed = 5; // Corresponds to keyboard keypad enter
}
else if (HAL_GPIO_ReadPin(BUTTON_LEFT_GPIO_Port, BUTTON_LEFT_Pin) == GPIO_PIN_RESET)
{
keyPressed = 8; // Corresponds to keyboard keypad up
}
else if (HAL_GPIO_ReadPin(BUTTON_RIGHT_GPIO_Port, BUTTON_RIGHT_Pin) == GPIO_PIN_RESET)
{
keyPressed = 2; // Corresponds to keyboard keypad down
}
else if (HAL_GPIO_ReadPin(BUTTON_UP_GPIO_Port, BUTTON_UP_Pin) == GPIO_PIN_RESET)
{
keyPressed = 6; // Corresponds to keyboard keypad right
}
else if (HAL_GPIO_ReadPin(BUTTON_DOWN_GPIO_Port, BUTTON_DOWN_Pin) == GPIO_PIN_RESET)
{
keyPressed = 4; // Corresponds to keyboard keypad left
}
//Blue user button on Nucleo boad
else if (HAL_GPIO_ReadPin(BUTTON_USER_GPIO_Port, BUTTON_USER_Pin) == GPIO_PIN_RESET)
{
keyPressed = 1;
}
}
return keyPressed;
}
Solved! Go to Solution.
2024-08-28 12:58 AM
Hello @__Michael__ ,
This is intended, the use of char is made in a way that you can use the keyboard in the simulator.
In the drop menu of interaction, when you select the button, you will have to select the ascii number of the char (for example : '5' is 53).
I hope it helps,
Best regards,
2024-08-28 12:58 AM
Hello @__Michael__ ,
This is intended, the use of char is made in a way that you can use the keyboard in the simulator.
In the drop menu of interaction, when you select the button, you will have to select the ascii number of the char (for example : '5' is 53).
I hope it helps,
Best regards,
2024-08-28 02:57 AM
Ok, that makes sense.
Feel a bit dumb now.
Thank you a lot for your help.