DvG_StreamCommand
DvG_StreamCommand.h File Reference

A lightweight Arduino library to listen to a stream, such as Serial or Wire, for incoming commands (or data packets in general) and act upon them. More...

#include <Arduino.h>

Go to the source code of this file.

Classes

class  DvG_StreamCommand
 Class to manage listening to a stream, such as Serial or Wire, for incoming ASCII commands (or ASCII data packets in general) and act upon them. More...
 
class  DvG_BinaryStreamCommand
 Class to manage listening to a stream, such as Serial or Wire, for incoming binary commands (or binary data packets in general) and act upon them. More...
 

Functions

float parseFloatInString (const char *str_in, uint16_t pos=0)
 Safely parse a float value in C-string str_in from of position pos. More...
 
bool parseBoolInString (const char *str_in, uint16_t pos=0)
 Safely parse a boolean value in C-string str_in from of position pos. More...
 
int parseIntInString (const char *str_in, uint16_t pos=0)
 Safely parse an integer value in C-string str_in from of position pos. More...
 

Detailed Description

A lightweight Arduino library to listen to a stream, such as Serial or Wire, for incoming commands (or data packets in general) and act upon them.

Author
Dennis van Gils (vangi.nosp@m.ls.d.nosp@m.ennis.nosp@m.@gma.nosp@m.il.co.nosp@m.m)

Function Documentation

◆ parseFloatInString()

float parseFloatInString ( const char *  str_in,
uint16_t  pos = 0 
)

Safely parse a float value in C-string str_in from of position pos.

Returns
The parsed float value when successful, 0.0 otherwise.

◆ parseBoolInString()

bool parseBoolInString ( const char *  str_in,
uint16_t  pos = 0 
)

Safely parse a boolean value in C-string str_in from of position pos.

Returns
  • False, when str_in is empty or pos is past the str_in length.
  • True, when the string perfectly matches 'true', 'True' or 'TRUE'.
  • Else, it will interpret the string as an integer, where 0 is considered to be false and all other integers are considered be true. Leading spaces, zeros or signs will be ignored from the integer.

◆ parseIntInString()

int parseIntInString ( const char *  str_in,
uint16_t  pos = 0 
)

Safely parse an integer value in C-string str_in from of position pos.

Returns
The parsed integer value when successful, 0 otherwise.