(risking repeating myself... this built-in editor is an ABOMINATION, you hear me?! Bloody abomination!)
In code samples, I had to replace greater/smaller symbols on includes (which are normally required for system file includes, although some compilers are lenient) by " ", because the code tag does not disarm html and the pointy braces are swallowed...
(next to all the other shenanigans the editor does)
NOTE that it also stripped some comments apparently, because of an unfortunate sequence of symbols, i saw one where the comment text is there, but not the comment-starting characters... so that won't compile.
even though the guy is quite entertaining and provides world-class hand holding, I couldn't make it more than maybe 1/2 way through his videos (pointed to above) without going cross-eyed. I'm probably not cut out for this kind of SW work.
Well, C++, especially in the form used by that venerable library (which I have not used myself but it rings very familiar, must be around for ages), is only called "high level language" by close-to-hardware people High level concepts will look verbose in it.
But also, a full fledged GUI toolkit will support a certain expected complexity of UI, and to achieve it in a uniform way, there is a raised bar wrt minimum effort to make even less complex things. At least with that kind of language.
I wonder whether, if it exists, a GUI toolkit designed for C++11/14/..., could be more slim with regards to boilerplate code. But I'm not up to date there.
I quickly looked at the video, the idioms used in wxWidgets seem pretty familiar (well there are similar ones across GUI toolkits, but sometimes subtly different, which can be confusing).
It looks reasonably lean for that kind of stuff.
One guy there mentioned this, to reduce the manual coding effort:
https://en.wikipedia.org/wiki/WxFormBuilder
Geany, heh. Not looked at it, but it sounds like one of those billion come-and-go little tools in Linux. If it does what you want and it's not too bad if in a year support (bugfixes, development) is ceased, then I guess it's ok.
If you'd like to consider something more time-tested and probably worked on for a while:
Well, a lot of people use Eclipse with CDT plugin for C++ development. If your computer was new when XP was current, I'm not sure how much fun running a current Ubuntu and then Eclipse would be, though... it does not have the reputation of being the snappiest of software... Well it's Java based.
There is also Code::Blocks, which has been around for over 10 years, and is a lot "old-computer-friendlier" than Eclipse. Like Eclipse, it can be customized heavily, which can at first also be a burden. (the last stable release is from 2017, but don't be fooled, there are very current "nightlies", there is active development).
Btw, Code::Blocks uses wxWidgets for its GUI stuff, IIRC.
There is something from MS which is IIRC open source and much leaner than the actual VisualStudio, it's called "visual studio code", it has been 2..3 years since I used it, but it was nice as a lean editor with a couple of handy IDE-like features, without the bulk.
Serial port: Look into how to set it to "raw mode", that deactivates all the HW terminal nonsense for stuff that was cool before I was born.
It is mentioned e.g. here, and there are code samples for different setup scenarios:
https://www.cmrr.umn.edu/~strupp/serial.html
But yeah, this stuff carries a lot of historical baggage.
If you want to spend the time, this text was quite illuminating, but I forgot 80% of the details again
https://www.linusakesson.net/programming/tty/
As for console I/O:
I have not used it yet, but ncurses is definitely the go to thing these days, it is very widely used.
You *can* get something like kbhit and getch, but it seems very cumbersome, and you can screw things up and then your terminal doesn't work properly anymore if your program exits and you didn't set things back to normal properly
I will throw in some code here for both, no guarantees, from when I fiddled around with this once.
Serial port: you'll have to look what the serial drivers are named on your system and replace the string with "ttyTHS", perhaps, this was on some embedded system.
This opens one with some common options. For details, refer to the links in the comments, I probably won't remember them, I' very poor at remembering such things and almost always have to look stuff like that up.
#include"fcntl.h" #include"unistd.h" #include"termios.h" #include"sys/ioctl.h" static int serial_init(int uartNum) { static const auto filePath = std::string( "/dev/ttyTHS" ) + std::to_string( uartNum - 1 ); // e.g. "/dev/ttyTHS3" int fileHandle = -1; if ( (fileHandle = ::open(filePath.c_str(), O_RDWR | O_NOCTTY | O_NDELAY)) raw mode: https://linux.die.net/man/3/tcsetattr cfsetospeed( &options, baud ); cfsetispeed( &options, baud ); tcsetattr( fileHandle, TCSANOW, &options ); tcflush( fileHandle, TCIFLUSH ); return fileHandle; } static int serial_shutdown(int fileHandle) { return ::close( fileHandle ); } static int serial_echo_once(int fileHandle) { static const char prefix[] = "ECHO: "; static const int prefixLen = sizeof(prefix)-1; // without the terminating 0. char buf[ 128 ]; strcpy( buf, prefix ); int numbytes = ::read( fileHandle, buf + prefixLen, sizeof(buf)-prefixLen ); if (numbytes > 0) ::write( fileHandle, buf, prefixLen + numbytes ); return numbytes; }
KBHIT: Yeah, here also a kind of raw mode is enabled... to disable the normal handling of key presses by the system.
#include "sys/ioctl.h" #include "termios.h" static void raw_mode_enable() { termios term; tcgetattr(0, &term); term.c_lflag &= ~(ICANON | ECHO); // Disable echo as well tcsetattr(0, TCSANOW, &term); } static void raw_mode_disable() { termios term; tcgetattr(0, &term); term.c_lflag |= ICANON | ECHO; tcsetattr(0, TCSANOW, &term); //--- tcflush(0, TCIFLUSH); // Clear stdin to prevent characters appearing on prompt } static bool kbhit() { int byteswaiting; ioctl(0, FIONREAD, &byteswaiting); return byteswaiting > 0; }
The usage would be like this:
- enable raw mode on terminal
- call kbhit
- after it returns, get the char with getchar() and process
- disable raw mode again (or the console won't work properly)