Convert XString (or List<char>) to char*


#1

How can i convert value from string input to char*
auto text = getValue<input_TEXT>(ctx);
here text is represented as XString of List but when I try to compile I get error \xod_packages_\packages\arduino\hardware\avr\1.6.21\cores\arduino/Print.h:75:12: note: no known conversion for argument 1 from ‘xod::List<char>’ to ‘const Printable&’

here code snippet where I use it
void evaluate(Context ctx) {
auto display = getValue<input_DEV>(ctx);
auto cursorX = getValue<input_CURSOR_X>(ctx);
auto cursorY = getValue<input_CURSOR_Y>(ctx);
auto textSize = getValue<input_TEXT_SIZE>(ctx);
auto text = getValue<input_TEXT>(ctx);
display->setTextSize(textSize);
display->setCursor(cursorX,cursorY);
display->print(text);
}


#2

Hi yzheka-rn

You can thank nkrkv for this one

Simple way:

auto TXTString = getValue<input_String>(ctx);
// Reserve a character buffer that is big enough for sure to hold the whole string.
// Do not use a too big buffer: each character occupies 1 byte of RAM for the
// duration of the current node `eveluate`’ion
char TXT[64];
// move the data from XString to the plain C string
dump(TXTString, TXT);
// the rest is the same...

Or this one adapts to the string length at the cost of a couple of CPU cycles

auto TXTString = getValue<input_String>(ctx);
// `length` returns the number of characters and you need an extra one to keep the
// terminal NUL-character used in C string representation. Initialize to 0’s to
// ensure the last char is indeed NUL
char TXT[length(TXTString) + 1] = { 0 };
// move the data from XString to the plain C string
dump(TXTString, TXT);

#3

Hey yzheka-m
Can I ask what library you are implementing? As the code looks very familiar a TFT display by any chance? I have done quite a few of them recently and I am working on another one now.
The adafruit gfx library?


#4

You are right. It is adafruit library for nokia lcd screen adaptation


#5

if you want it will be completed soon I can let you know when I upload it ?


#6

Would be great, thanks


#7

Hi yzheka-m
MCUFRIEND_kbv has been published.
It is an extended version of the adafruit gfx library it is compatible with a wide range of control chips can you please check yours against the list :slight_smile:


#8

Awesome. As soon as I will be near pc I check


#9

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.