Giter Club home page Giter Club logo

Comments (5)

VasilKalchev avatar VasilKalchev commented on September 21, 2024

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.

Fettkeewl avatar Fettkeewl commented on September 21, 2024

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.

VasilKalchev avatar VasilKalchev commented on September 21, 2024

"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.

Fettkeewl avatar Fettkeewl commented on September 21, 2024

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.

VasilKalchev avatar VasilKalchev commented on September 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.