2019-11-07 01:43 PM
// Here is my code for when the enter button is clicked:
void MainScreenView::EnterButtonClickedFunction() {
Unicode::UnicodeChar STRING = keyboard.getBuffer();
updateWildcard(STRING);
targetVacValvePercent.resizeToCurrentText();
targetVacValvePercent.invalidate();
// Close Modal Window
targetPercentModalWindow.setVisible(false);
targetPercentModalWindow.invalidate();
keyboard.setVisible(false);
keyboard.invalidate();
enterValueButton.setVisible(false);
closeModalWindowButton.setVisible(false);
}
// Here is my update Wildcard text:
void MainScreenView::updateWildcard(uint16_t text)
{
Unicode::snprintf(targetVacValvePercentBuffer, 5, "%d", text);
targetVacValvePercent.invalidate();
}
Solved! Go to Solution.
2019-11-08 05:48 AM
Hi @WLewe,
getBuffer() will most likely return not ONE UnicodeChar but a pointer to an array of UnicodeChar.
Fix that, and make sure the string you get from the Keyboard buffer is '\0' terminated
Also notice that you're only copying 5 characters and that the format is %d (integer).
If you want to copy the keyboard buffer into another buffer you should use Unicode::strncpy.
/**
* @fn static uint16_t Unicode::strncpy(UnicodeChar* RESTRICT dst, const UnicodeChar* RESTRICT src, uint16_t maxchars);
*
* @brief Copy a string to a destination buffer, UnicodeChar to UnicodeChar version.
*
* Copy a string to a destination buffer, UnicodeChar to UnicodeChar version. Stops if it
* encounters a zero-termination, in which case the zero-termination is included in
* the destination string. Otherwise copies maxchars.
*
* @param [out] dst The destination buffer. Must have a size of at least maxchars.
* @param [in] src The source string (UnicodeChars)
* @param maxchars Maximum number of characters to copy.
*
* @return The number of characters copied (excluding zero-termination if encountered)
*
* @warning If there is no null-termination among the first n UnicodeChars of src,
* the string placed in destination will NOT be zero-terminated!
*/
static uint16_t strncpy(UnicodeChar* RESTRICT dst, const UnicodeChar* RESTRICT src, uint16_t maxchars);
2019-11-08 05:48 AM
Hi @WLewe,
getBuffer() will most likely return not ONE UnicodeChar but a pointer to an array of UnicodeChar.
Fix that, and make sure the string you get from the Keyboard buffer is '\0' terminated
Also notice that you're only copying 5 characters and that the format is %d (integer).
If you want to copy the keyboard buffer into another buffer you should use Unicode::strncpy.
/**
* @fn static uint16_t Unicode::strncpy(UnicodeChar* RESTRICT dst, const UnicodeChar* RESTRICT src, uint16_t maxchars);
*
* @brief Copy a string to a destination buffer, UnicodeChar to UnicodeChar version.
*
* Copy a string to a destination buffer, UnicodeChar to UnicodeChar version. Stops if it
* encounters a zero-termination, in which case the zero-termination is included in
* the destination string. Otherwise copies maxchars.
*
* @param [out] dst The destination buffer. Must have a size of at least maxchars.
* @param [in] src The source string (UnicodeChars)
* @param maxchars Maximum number of characters to copy.
*
* @return The number of characters copied (excluding zero-termination if encountered)
*
* @warning If there is no null-termination among the first n UnicodeChars of src,
* the string placed in destination will NOT be zero-terminated!
*/
static uint16_t strncpy(UnicodeChar* RESTRICT dst, const UnicodeChar* RESTRICT src, uint16_t maxchars);
2019-11-08 02:12 PM
Thank you, yes strncpy definitely makes more sense given the context of what I am doing. Ill keep working on this! Thank you so much.
2019-11-11 12:14 AM
No problem :) Good luck! Let me know if there's anything.
/Martin