Hi all,
I'm a Arduino beginner, happily uploaded my blinking sketch a couple weeks ago. After writing and uploading some experimenting sketches, I realised I need some extent of integration. So I wrote this small helper library, where I can bind a task function to a command name, and register it to the system. I then can call each task by sending its command name to Arduino via Serial (or via other means).
It's a trivial idea and trivial implementation, but I found it's triggering my imagination. After registering some simple tasks, I can then use these tasks as building blocks and do something more useful by combing them. So I'd like to share it here.
It's called "Neutrino" (named after a small, chargeless particle which is also a building block of the universe), and the Github page contains a very detailed introduction. Very birefly, it's as follows.
/* First, include and define a global Neutrino object. */
#include <Neutrino.h>
Neutrino neu = Neutrino(true); // define a global task handler. "true" to automatically add a "_help" command.
// ... other codes
/* Second, define your task functions. Each task function should take no arguments and return an int8_t type variable as its exit code. */
int8_t led_control()
{
// your codes to control some led
return 0; // an exit code
}
/*Third, register each task you defined above to a command name. (Usually in "setup" function but not compulsory.) */
neu.add_command("led", led_control); // Here the led_control function is bind to "led" command. */
/* Last, when you get some command stirng(possibly from Serial, sent by a user), you can parse it and run the corresponding task:
uint8_t retval = neu.parse_command(command); //Here "command" is a string variable.
/* To display the help information (a list of all commands available): */
neu.print_help_info();
When the bool variable in the constructor is set to "true", a command "_help" is automatically registered, which simply call "neu.print_help_info();" Therefore, when a user needs to recall the available command names, she/he can simply send a "_help" command.
There are more to come, of course, and I'll be happy if people find it interesting. Meanwhile, I'd also like to receive any suggestion or advice from experienced Arduino developers.
Cheers and happy coding! 8)