Go Down

Topic: Areas for discussion. (Read 4 times) previous topic - next topic

gbulmer

#20
Apr 03, 2010, 12:44 am Last Edit: Apr 03, 2010, 12:45 am by gbulmer Reason: 1
I didn't want
Code: [Select]
Serial.println("x", x, "y", y, "z", z);
I'd like improvements of the serial monitor to provide:
a. clear screen/window,
b. position the text cursor to a specific row and column for subsequent print (maybe position within current row)
c. clear current row
d. return text cursor to start of line with '\r' (rather than forcing a newline)

I don't mind how it is achieved. mem would prefer it not to consume precious Arduino team time, and suggest that it could be an existing Open Source terminal.

On the Arduino side, I would expect these capabilities to be nicely wrapped up as methods in the Serial class to make it easy to use. The same capability may be exposed as 'magic' characters which could be embedded in character strings and Serial.print()'ed.

mem and I would like it to be easier to create tabular output.

I would be satisfied with something that returns the character length of each type of printed item, e.g. if Serial.print(int) prints on the serial monitor, then Serial.length(int) would return the number of characters that would be printed. Then I'd like something to make it easy to pad with spaces, e.g. Serial.pad(int) would print 0 or more spaces. That would be enough for me to do tabular layouts.

I hope this is clearer, and that I haven't misinterpreted mem.
GB-)

mem

I like gbulmer's suggested enhancements to serial monitor, and I would add one more - an option to send  '\r' at the end of the string when the Send button is pressed to make it easier for a sketch to determine the end of an input string.

think that tabular output is needed as much with LCD as with Serial, so would want to see something along the lines of roypardi's suggestion that includes the ability to control the padding between fields so they can be lined up.

The ability to print multiple fields can be done now using a method published by Mikal Hart here: http://www.arduino.cc/playground/Main/StreamingOutput
Its syntax is a C++ standard but I wonder if it looks a little scary to non-technical people?

so for me, the higher priority is something simple that can print a line at a time that includes control over the width of a field so printed values can line up on serial or lcd (or ethernet).  

roypardi

Quote
The ability to print multiple fields can be done now using a method published by Mikal Hart here: http://www.arduino.cc/playground/Main/StreamingOutput
Its syntax is a C++ standard but I wonder if it looks a little scary to non-technical people?


Took a look at that link. I'm not exactly non-technical but I have no idea what the relevant line (below) is doing.
Does this compile as is? class T?

[size=10]
Code: [Select]
template<class T> inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; } [/size]

mem

#23
Apr 03, 2010, 07:25 am Last Edit: Apr 03, 2010, 07:29 am by mem Reason: 1
That line defines the output capability but it does not need to be visible within the sketch. there is a version that hides that line  in a library: http://arduiniana.org/libraries/streaming/

the downloid is here: http://arduiniana.org/Streaming/Streaming4.zip

I have just modifed the playground article to include the link to Mikal's less scary library version.

gbulmer

#24
Apr 03, 2010, 05:24 pm Last Edit: Apr 03, 2010, 06:12 pm by gbulmer Reason: 1
Quote
The ability to print multiple fields can be done now using a method published by Mikal Hart here: http://www.arduino.cc/playground/Main/StreamingOutput
Its syntax is a C++ standard but I wonder if it looks a little scary to non-technical people?


I used to write C++ professionally (before Java and Erlang came along  :)), and I was fine with the "<<" operator overloading on Streams. IMHO, we got a bit 'punchy' back in those days, and used overloaded operators for anything and everything. I felt it had got to a point where the editor needed to be smarter than me to figure out which code was actually going to be applied, so that it could show me the appropriate definition.

IMHO, one of the beautiful aspects of Arduino is the taste and restraint that the team has used to keep things clear and approachable.

I have no objection to folks using operator overloading. But I feel it is hard enough for new programmers to get to a point where they are happy to manipulate bits with "<<" and ">>", and that overloading to create different semantics may create confusion. I feel that is not what Arduino is about (I realise I am not an authority). I would beg that overloading "<<" for printing be eschewed in Arduino's IDE examples, as it seems a leap too far for the new programmer.

If folks want a more compact way to print, just overload a new member function so that it can be used like:

Serial.out("y=").out(y).out(" x=").out(y<<3).newline();

I accept this is not as pretty and compact as the "<<" overloaded operator, but it reduces confusion compared to:

Serial << "y=" << y << "x=" << (y << 3) << endl;
x = y << 3;

Just to emphasise the point, who can see the error in the operator overloading example?

Example:
Code: [Select]
Serial << "GPS unit #" << gpsno << " reports lat/long of " << lat << "/" << long;

Answer:
long is a type, not a variable, so this doesn't compile.

I found it easier to spot the error when I saw:
Code: [Select]
Serial.print(long);
which also doesn't compile. (AFAIK, the page history says it has been like this since 22nd January.)

(I apologise for not fixing it. I was tempted to fix it, but I wanted to leave it so folks looking at the entire example can see and appreciate how hard this stuff is. I'd only read this as a result of mem's post, and I 'read' it more than once, and missed it :-( )

I would observe that this has been referenced several times in this thread, and presumably read, and no one has raised this concern. I think it suggests that it is not easy to understand.

Just my $0.02 worth
GB

Go Up