cancel
Showing results for 
Search instead for 
Did you mean: 

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.

WLewe
Associate III
// 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();
}

1 ACCEPTED SOLUTION

Accepted Solutions
Martin KJELDSEN
Chief III

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

View solution in original post

3 REPLIES 3
Martin KJELDSEN
Chief III

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

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.

No problem :) Good luck! Let me know if there's anything.

/Martin