Michael Shimniok / Mbed 2 deprecated DataBus

Dependencies:   mbed Watchdog SDFileSystem DigoleSerialDisp

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers util.h Source File

util.h

00001 #ifndef __UTIL_H
00002 #define __UTIL_H
00003 
00004 /** Utility routines */
00005 
00006 #define clamp360(x) clamp((x), 0, 360.0, false)
00007 #define clamp180(x) clamp((x), -180.0, 180.0, true)
00008 
00009 #ifndef M_PI
00010 #define M_PI 3.14159265358979323846
00011 #endif
00012 
00013 /**
00014  * Clamp value between min and max. Specify which of the two are inclusive
00015  * @param v is the value to clamp
00016  * @param min is the minimum value, inclusive if flip==false, exclusive otherwise
00017  * @param max is the maximum value, inclusive if flip==true, exclusive otherwise
00018  * @param flip determines whether min or max is inclusive
00019  * @return the clamped value
00020  */
00021 float clamp(float v, float min, float max, bool flip);
00022 
00023 /** Convert char to integer */
00024 int ctoi(char c);
00025 
00026 /** Convert string to floating point */
00027 double cvstof(char *s);
00028 
00029 /** Convert unsigned long to string
00030  *
00031  * @param n is the unsigned long to convert
00032  * @returns char * to static char array
00033  */
00034 char *cvntos(unsigned long n);
00035 
00036 /** Convert signed long to string
00037  *
00038  * @param n is the signed long to convert
00039  * @returns char * to static char array
00040  */
00041 char *cvitos(long n);
00042 
00043 /** Convert float/double to string
00044  *
00045  * @param number is the floating point number to convert
00046  * @param digits is the number of digits after the decimal point
00047  * @return char * to static char array
00048  */
00049 char *cvftos(double number, int digits);
00050 
00051 /** Tokenize a string 
00052  * @param s is the string to tokenize
00053  * @param max is the maximum number of characters
00054  * @param delim is the character delimiter on which to tokenize
00055  * @returns t is the pointer to the next token
00056  */
00057 char *split(char *s, char *t, int max, char delim);
00058 
00059 #endif