Skip to main content
WLewe
Associate III
November 7, 2019
Solved

I was able to implement a modal keyboard. I can type in the box and everything is nice. When I try to move my typed text to a wildcard, I get the value "3216" instead of the typed value.

  • November 7, 2019
  • 1 reply
  • 1078 views
// 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();
}

This topic has been closed for replies.
Best answer by Martin KJELDSEN

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);

1 reply

Martin KJELDSEN
Martin KJELDSENBest answer
Principal III
November 8, 2019

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);

WLewe
WLeweAuthor
Associate III
November 8, 2019

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.