ppedro74 / Arduino-SerialCommands

BSD 3-Clause "New" or "Revised" License
87 stars 29 forks source link

Add function for one key commands #2

Closed fitzterra closed 5 years ago

fitzterra commented 6 years ago

The one_key functionality allows commands to be designated as "One Key" commands which means that if the command buffer is empty (no input keys received in a fresh buffer yet), and a character is then received that matched a "One Key" command, that command will be executed immediately without needing any command termination sequence.

This is mainly useful when the serial input is from a human on a keyboard to do simple things like possibly adjusting volume or any other configuration value up or down by simple "one key" presses, instead of having to enter the command character and then press enter.

Note that it re-uses the SerialCommand class as is and only adds one additional boolean to indicate if the command is a "one_key" command or not, default to false if not supplied.

This means that although there is nothing stopping you from using a string value as a command for a "one_key" command, ONLY the first character in the string will be considered for the "one_key" command.

ppedro74 commented 5 years ago

Thanks