Help with strings
MacGeek117
Posts: 747
I'm building a project with ComFile Tech's IntelliLCD. The commands are supposed to be given in string form (i.e. "Line 1,1,100,100;"). The Prop Tool spits out a error message when I replace the numbers with variables.
Help!!!!
RoboGeek
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"I reject your reality and subsitute my own!"
Adam Savage, Mythbusters
www.parallax.com
www.goldmine-elec.com
www.expresspcb.com
www.startrek.com
·
lcd.str(string("line ",x1,y1,x2,y2,";"))
Help!!!!
RoboGeek
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"I reject your reality and subsitute my own!"
Adam Savage, Mythbusters
www.parallax.com
www.goldmine-elec.com
www.expresspcb.com
www.startrek.com
·
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
STRING() ist not PRINTF()
There are some attempts to prepare a PRINTF, but the hard thing are missing function pointers...
You best do it the "standard way":
lcd.str(string("line "))
lcd.dec(X1)
lcd.out(",")
etc, etc...
RoboGeek
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"I reject your reality and subsitute my own!"
Adam Savage, Mythbusters
www.parallax.com
www.goldmine-elec.com
www.expresspcb.com
www.startrek.com
·
Someday Spin will have function pointers and — who knows? — maybe even variable-length argument lists. (I'm sure the interpreter will support the former; I'm not so sure about the latter.) Until then, Format is a little awkward, but it works.
-Phil
I looked at your format object and I find the mechanism rather complex.
The task can be accomplished much simpler I think. For the javelin I wrote
a Format class some years ago. There are 3 basic methods: printf, sprintf and bprintf.
The bprintf is the core routine, it takes a buffer, an index value,·a control string and a value parameter.
It returns an updated index value. This makes it easy to assemble an output string
in memory for a sprintf with multiple arguments.
For a target output
· sprintf("this is module %s the second argument value is %d",value,number)
it becomes
· char buf[noparse][[/noparse]128];
· int k;
· k = bprintf(buf,0,"this is module %s",value);
· k = bprintf(buf,k," the second argument value is %d",number);
· buf[noparse][[/noparse]k] = 0;
Now simply send buf to whatever output driver
The type of the value parameter is known by the control character in the control string,
for %s it is a string, for %d it is an integer value etc. If there is no control character,
the value parameter is just a dummy. (eg. sprintf(buf,"text without formatters",0))
The sprintf simply calls bprintf with index value 0 and automatically adds a closing null.
The printf outputs to the debug serial out, which would be pin SOUT on the spin stamp.
Converting my javelin Format class to Spin is next on my list for spin code.
regards peter
I have not tested it and floating point is not supported, but it
works on the javelin so it should work on the propeller.
See the bprintf and bscanf descriptions for info how to use it.
regards peter
Post Edited (Peter Verkaik) : 12/12/2007 5:38:16 PM GMT
For bscanf, no hex characters were scanned.
This has been fixed in the attachement.
regards peter
RoboGeek
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"I reject your reality and subsitute my own!"
Adam Savage, Mythbusters
www.parallax.com
www.goldmine-elec.com
www.expresspcb.com
www.startrek.com
·
http://forums.parallax.com/showthread.php?p=694892
This updated version uses byte[noparse][[/noparse]str] to access the bytes in a string.
str[noparse][[/noparse]h] when str is a passed value does not seem to work.
I am having trouble when converting an integer value, though
I am convinced the logic is ok (works on the javelin). I you care to take·a look
that would be great.
regards peter
(a)
> str[noparse][[/noparse]h] when str is a passed value does not seem to work.
I am not sure what you expect... No it will not work, as it is assumed to be a LONG
(b) You are using >= and <= rather than => and =<
Unfortunately, changing all the occurences did not resolve the issue·I am having.
regards peter
http://forums.parallax.com/showthread.php?p=694892
But it is solved now. Adapting to a new language takes time.
regards peter