Comments (5)
What is the output of txtbuffer
on the display before formatting it with snprintf(...)
? The LiquidLine
object uses pointers to char arrays instead of char arrays directly (even though they are similar), take a look at the examples C_functions_menu
and D_buttons_menu
.
I think that the size
argument of snprintf(...)
should be 16.
from liquidmenu.
First: according to this http://www.cplusplus.com/reference/cstdio/snprintf/
size should be 17 because the output string is 17-1 due to null terminating character
I tried this below, before snprintf the screen is just blank, after snprintf I get jibberish.
All serial.prints perform normally
char txtbuffer[20] = "Empty";
LiquidLine test(2, 0, txtbuffer);
LiquidScreen testS(test);
void setup() {
Serial.begin(9600);
setupEncoder();
setupMenu();
menu.add_screen(testS);
menu = testS;
Serial.println(txtbuffer);
menu.update();
delay(5000);
snprintf(txtbuffer, 17, "BUFF: %s", "test");
Serial.println(txtbuffer);
//menu.add_screen(testS);
menu.update();
delay(10000);
}
however I tried this aswell and it atleast did output the first Char.
"E" then "B" after snprintf
char txtbuffer[20] = "Empty";
LiquidLine test(2, 0, txtbuffer[0]); //<--------- difference
LiquidScreen testS(test);
void setup() {
Serial.begin(9600);
setupEncoder();
setupMenu();
menu.add_screen(testS);
menu = testS;
Serial.println(txtbuffer);
menu.update();
delay(5000);
snprintf(txtbuffer, 17, "BUFF: %s", "test");
Serial.println(txtbuffer);
//menu.add_screen(testS);
menu.update();
delay(10000);
}
from liquidmenu.
"I tried this below, before snprintf the screen is just blank, after snprintf I get jibberish."
char txtbuffer[20]
is set to "Empty"
. If the screen doesn't print "Empty" (i.e. displays nothing or jibberish), this means that txtbuffer
isn't working before snprintf(...)
. This is expected, because the LiquidLine
object uses pointers to char arrays, not char arrays directly, it doesn't work the same way as Serial.print(...)
or lcd.print(...)
.
You should have a separate char pointer that points to txtbuffer
and use that pointer as an argument to LiquidLine
's constructor (examples: C_functions_menu
and D_buttons_menu
).
from liquidmenu.
Thank you, your suggestion worked great. Although I do not understand it.
textbuffer array is a pointer to the address of the first value of the array in memory, assigning this address to a pointer makes it usable, but using the address directly does not? How weird..
from liquidmenu.
It is weird, the library is a little hacky. It manually recognizes the data type and stores the address of the variable in a void pointer, then when printing - the variable is casted back. Take a look at bool LiquidLine::add_variable(T &variable)
, void LiquidLine::print(DisplayClass *p_liquidCrystal, bool isFocused)
and recognizeType.cpp
if you want to know how it works.
Basically, for dynamic text, you can use a char*
that can be pointed to different char arrays. And for constant text, const char*
directly.
from liquidmenu.
Related Issues (20)
- call_function() calls update() for previous menu if change_menu() is in the callback function
- API reference is 404 HOT 2
- Unable to get current menu from LiquidSystem
- 'recognizeType(int&)' is ambiguous HOT 1
- LiquidMenu objects have to be defined globally HOT 3
- Screens could link to child menus HOT 5
- Switching screens should reset focus item back to first line HOT 2
- Can't compile I2C example HOT 8
- Rotary encoder example HOT 2
- `switch_focus` iterates from the last focusable line to `_lineCount` instead of the first line HOT 6
- Blink cursor over editing position HOT 1
- Avoid creating duplicate variables HOT 1
- `delete_variable()` and `detach_function()` HOT 2
- `LiquidSystem::is_callable` makes an undesired `LiquidMenu::call_function` HOT 1
- Mixing sub-menus and scrolling lines? HOT 1
- Switch focus disappears for one step after an iteration HOT 4
- Support for the SAMD architecture HOT 1
- Optional screen refresh option when calling a function HOT 1
- [Poll] Which interface do you use to interface with the display?
- LiquidCrystal not found even if it's installed HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from liquidmenu.