I've just released my first Arduino-specific library, SerialUI. I use it to provide user interfaces (menus, sub-menus and commands) for my Arduino projects, through the serial line. It provides built-in functions like menu hierarchy navigation and on-line help.
You can find details and documentation at SerialUI – Inductive-Kickback.com. If you're interested in this type of functionality, or in Arduino libraries in general, I'd appreciate any comments, questions and/or feedback.
This is the first release, so it may still have some rough edges. Also, it uses dynamic memory allocation and the HardwareSerial, making it kinda heavy (a simple test program will compile around 7k). I'm working on some config flags that will allow you to sacrifice a little flexibility and RAM for savings on the flash size side. Anything else that might be useful or of interest?
The example file is SuperBlinker.pde, maybe SuperBlinker.ino is better.
The example uses a baudrate ot 115200, perhaps the default of 9600 is better.
I need to set CR + LF or LF in the serial monitor to see the menu. Only the CR doesn't work. You have that well documented, but I think it should work in all situations.
Do you use real tabs for indent ? I would prefer 2 or 4 spaces.
At 9600 baud, there is a timing issue. The received command is handled, but not the whole command is received yet.
The example file is SuperBlinker.pde, maybe SuperBlinker.ino is better.
Ah, hadn't noticed this (new?) convention... not sure what the difference is, will look it up and adjust.
The example uses a baudrate ot 115200, perhaps the default of 9600 is better.
Yeah, makes sense.
I need to set CR + LF or LF in the serial monitor to see the menu. Only the CR doesn't work. You have that well documented, but I think it should work in all situations.
The problem here is Serial.readBytesUntil(), which expects a single char--so there's no way to use it with CR+LF in any case... guess I could just hand-roll the functionality and use a peek() if I hit a CR.
Do you use real tabs for indent ? I would prefer 2 or 4 spaces.
Guess so (Eclipse default). I've always preferred tabs for indentation, personally... what's the rationale for spaces?
At 9600 baud, there is a timing issue. The received command is handled, but not the whole command is received yet.
I was unable to reproduce this @ 9600 baud--were you using the "SuperBlinker" example (which explicitly uses setTimeout()) or the simple example from the usage page?
To be able to handle CR or LF or CRLF, you can use the fact that CRLF is always in that order.
You could test for CR or LF and assume that both are end of line.
If it is CR, set a flag to ignore a following LF.
Any other character resets the flag.
Tabs or spaces? I'm a 'spaces'-man. I don't know why.
I used the SuperBlinker example. I didn't know there was a specific timeout.
Ok, I created a new readBytesToEOL() that handles all standard line-terminations. It's setup to block when called, until the EOL or max length is read, so it deals with the issue of the slow baud connections too.
Downside is that it'll block forever if there's no input, unlike readBytesUntil()... I'm not certain how much of a problem that is. Also set the example default to 9600 baud.
I didn't look into the code. I just run the example.
The settings command was split into, but I was not able to repeat it. So I scrolled back and dump that part here:
+++ Welcome to the SuperBlinker +++
Enter '?' to list available options.
> ?
*** Help for: SuperBlinker Main Menu
information Retrieve data and current settings
enable Enable/disable device
settings Perform setup and config
quit Exit SerialUI
? List available menu items
> ??
*** Help for: SuperBlinker Main Menu
information Retrieve data and current settings
enable Enable/disable device
settings Perform setup and config
quit Exit SerialUI
? List available menu items
> ?
*** Help for: SuperBlinker Main Menu
information Retrieve data and current settings
enable Enable/disable device
settings Perform setup and config
quit Exit SerialUI
? List available menu items
> ?
*** Help for: SuperBlinker Main Menu
information Retrieve data and current settings
enable Enable/disable device
settings Perform setup and config
quit Exit SerialUI
? List available menu items
> information
(Called 'show_info' from menu: SuperBlinker Main Menu)
ID:
Color--> R:0 G:0 B:0
Device is OFF
>
> INFORMATION
ERROR Unknown selection: INFORMATION
Enter '?' for available options
>
> enable
enable
>
> sett
ERROR Unknown selection: sett
Enter '?' for available options
> ings
ERROR Unknown selection: ings
Enter '?' for available options
>