Autodrone
Multi-Domain Vehicle
utilities.h File Reference

This files contains random useful functions. More...

Go to the source code of this file.

Macros

#define white_space(c)   ((c) == ' ' || (c) == '\t')
 
#define valid_digit(c)   ((c) >= '0' && (c) <= '9')
 

Functions

float constrain (float input, float minValue, float maxValue)
 Constrains an input between two values. More...
 
uint16_t constrain16 (uint16_t input, uint16_t minValue, uint16_t maxValue)
 Constrains an input uint16_t between two values. More...
 
float standardRadianFormat (float angle)
 Puts a value in standard radian format. More...
 
uint16_t dshot3dFormat (int16_t rxCmd)
 Formats values from an iBus receiver for 3D mode. More...
 
float stringToFloat (const char *p)
 Simple and fast atof (ascii to float) function. More...
 

Detailed Description

This files contains random useful functions.

Author
Jeremy Wolfe
Date
07 MAR 2022

Macro Definition Documentation

◆ valid_digit

#define valid_digit (   c)    ((c) >= '0' && (c) <= '9')

◆ white_space

#define white_space (   c)    ((c) == ' ' || (c) == '\t')

Function Documentation

◆ constrain()

float constrain ( float  input,
float  minValue,
float  maxValue 
)

Constrains an input between two values.

Parameters
inputValue to be constrained.
minValueLower threshold.
maxValueUpper threshold.
Returns
float Constrained value.

◆ constrain16()

uint16_t constrain16 ( uint16_t  input,
uint16_t  minValue,
uint16_t  maxValue 
)

Constrains an input uint16_t between two values.

Parameters
inputValue to be constrained.
minValueLower threshold.
maxValueUpper threshold.
Returns
uint16_t Constrained value.

◆ dshot3dFormat()

uint16_t dshot3dFormat ( int16_t  rxCmd)

Formats values from an iBus receiver for 3D mode.

Parameters
rxCommandValue from iBus receiver.
Returns
uint16_t Formatted value.

◆ standardRadianFormat()

float standardRadianFormat ( float  angle)

Puts a value in standard radian format.

Parameters
angleValue to be formatted.
Returns
float Formatted value.

◆ stringToFloat()

float stringToFloat ( const char *  p)

Simple and fast atof (ascii to float) function.

Executes about 5x faster than standard MSCRT library atof()
-An attractive alternative if the number of calls is in the millions.
-Assumes input is a proper integer, fraction, or scientific format.
-Matches library atof() to 15 digits (except at extreme exponents).
-Follows atof() precedent of essentially no error checking.

09-May-2009 Tom Van Baak (tvb) www.LeapSecond.com
Parameters
*pPointer to string.
Returns
float Converted float value.