Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 7 months ago.
Using Serial functuions from Terminal - is it safe?
Hi
I have just tested the following code which uses the Terminal library.
It seems to work fine - however I am using functions such as scanf and baud which are public functions in the mbed Serial class and not the Terminal class.
Why does this work ? Inheritance?
Is this safe ? what is good practice in a situation like this.
Many thanks
P
Terminal & Serial
#include "mbed.h" #include "Terminal.h" Terminal term(USBTX, USBRX); // tx, rx int main() { int x; char name[20]; term.baud(4800); term.cls(); term.printf("Hello what is your Name? : "); term.scanf("%s",&name); term.printf("\n\nHello %s\n\n",name); term.printf("\n\n\rEnter a value for X: "); term.scanf("%i",&x); term.printf("\n\rThank you X = %i", x); }
3 Answers
11 years, 7 months ago.
It is handy to link which library you use, I assume: http://mbed.org/users/simon/code/Terminal/
It is indeed inheritance which makes it work, and it is safe and good practice to use it like this, quite some parts of the mbed library also use it. In the terminal.h file there is:
class Terminal : public Serial {
This means that the Terminal class inherits all functions of the Serial class, and they are all available for the user (well the public functions of the Serial class, protected functions stay protected).
11 years, 7 months ago.
Thank you for your response Erik
Yes I am using http://mbed.org/users/simon/code/Terminal/
One more question: Is there a table showing the relationship between the int passed and the colour generated by the foreground() function.
I do not want all possible colours - just a representative set of examples.
P
11 years, 7 months ago.
Hi Pronchious,
In Terminal.cpp, you'll see the colour conversion "rgb888tobgr111( )", and in a quick look at the code, it generates a 3-bit value - taking only the most significant bit of the 24-bit RGB that you pass in. As this is for color versions of ANSI/VT100 systems, this does not surprise me. It then encodes that color into the escape sequence for the terminal. It does not appear to leverage the "Bright" option. Please see the Wiki - ANSI colors articles, and compare this to the implementation in Terminal.cpp.