#19 - Modified Text Input Widget performance - Now with 100% more line feed
Well, here is another modification to make a widget work how I at least think it could (and possibly temporary… see my supplanted multi-coloured button above )
NOTE: This is NOT intended to undermine what Blynk has made… just add in my own personal preferences to somthing I wish to use in a particular way.
The text Input widget is great… easy to use and compact, compared to the Terminal input option. Only one thing… It doesn’t act like a ‘true’ (IMHO) text input. No EOL, ‘carriage return’ or clearing upon hitting return. All by design? Perhaps
Well, here is my simple code mod to supply all those “missing” features
You can still use the Widget as intended, or with the addition of a space and two periods (customisable) followed by the return key. you can get a cleared widget and a new line in the resulting string.
Due to the need for a SPACE to “clear” the widget… some post processing is used to remove a single leading SPACE from your string, if present.
String textIn; // declare global variable
//===== Modified Text Input Widget - BLYNK Function =====
BLYNK_WRITE(V0) {
String textIn = param.asStr(); // Get string from Text Input Widget
if (textIn.startsWith(" ")) { // If it has a leading SPACE...
textIn.remove(0, 1); // ...remove it.
}
if (textIn.endsWith(" ..")) { // If it has customisable EOL indicator, In my case SPACE and 2 PERIODS...
textIn.replace(" ..", "\n"); // ...replace with newline command
Blynk.virtualWrite(V0, " "); // "clear" the Text Input field. A null "" will not work, so needs a space
}
Serial.print(textIn); // Show string output as intended, or do whatever you want with the string.
Blynk.virtualWrite(vPin, textIn); // Like send it to a terminal Widget
}
So if you want or need a truer text entry feeling, with carriage return effects… this…
…can become this, just by ending with a SPACE and 2 PERIODS (customisable)
To give this output…
And for the fun of it, here is some code to add a Clear Terminal button.
//===== Clear Terminal Widget =====
BLYNK_WRITE(vPin) { // Button Widget
if (param.asInt()) {
Blynk.virtualWrite(vPin, "clr"); // Clears terminal if button state is 1
}
}