Skip to content

serge-14/smartserial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Smart Serial library for Arduino

Download latest version from here

Using library

Import library

Include following libraries:

#include <SmartSerial.h> // Actual Smart Serial implementation
#include <SerialStream.h> // Smart Serial stream wrapper for Arduino SDK Serial class
#include <CommandStorage.h> // Command storage

Define following variables:

SerialStream stream; // Wrapper for Serial
CommandStorage<16> storage; // Storage for 16 commands

// Smart Serial with following parameters:
// 12 - Maximum node counts
// 8 -  Maximum keyword size,in this case we can have maximum 8 letters per keyword
// 2 -  Maximum count of child commands per node
// 16 - Buffer size
// 4 -  Maximum parameters count for the command
GenericSmartSerial<12, 8, 2, 16, 4> smartSerial(&stream);

Register command:

void commandShowTime()
{
    DateTime now = g_Clock.getTime();
    now.print();
}

void setup()
{
    ...

    smartSerial.registerCommand("show time", storage.wrap(commandShowTime));

    ...
}

And polling new commands:

void loop()
{
    smartSerial.poll();
}

Nodes

There are two parameters MaxNodeCount and CommandsPerNode which may be unclear. Both defines size of the tree which is going to be build in GenericSmartSerial.

MaxNodeCount - maximum amount of tree nodes can be created to hold commands

CommandsPerNode - maximum amount of children a node can have

For example, by adding commands:

alarm enable at
alarm reset

following tree is going to be created:

alarm
 |- enable
 |  |- at (command holder)
 |- reset (command holder)

It will consume 4 nodes in total.

About

Protocol for communicating over serial port for Arduino

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors