72 lines
1.3 KiB
C++
72 lines
1.3 KiB
C++
#define DEBUG
|
|
|
|
#ifndef UTILES
|
|
#define UTILES
|
|
/*
|
|
Comprueba si es momento de actualizar las medidas, porque las actualiza cada cierto tiempo
|
|
Dado el último tiempo guardado, tt, y el tiempo que tiene que haber pasado, incre,
|
|
devuelve true si el tiempo actual ha sobrepasado a tt en incre o mas
|
|
y false, si no
|
|
*/
|
|
bool isTime( unsigned long *tt, unsigned long timer)
|
|
{
|
|
//coge el tiempo actual
|
|
unsigned long t = millis();
|
|
//si es menor que el último, actualiza el último
|
|
if (t < *tt)
|
|
{
|
|
*tt = t;
|
|
return true;
|
|
}
|
|
//si todavia no ha pasado el tiempo
|
|
if ((*tt + timer) >= t)
|
|
return false;
|
|
|
|
//si ya ha pasado el tiempo, actualiza el ultimo tiempo
|
|
*tt = t;
|
|
return true;
|
|
}
|
|
/*
|
|
* Para imprimir por el puerto COM si esta en modo DEBUG
|
|
*/
|
|
static void printCOM(char *line)
|
|
{
|
|
#ifdef DEBUG
|
|
Serial.println(line);
|
|
#endif
|
|
}
|
|
|
|
|
|
class StringSplit
|
|
{
|
|
char *str;
|
|
char* separador;
|
|
int n;
|
|
public:
|
|
StringSplit(char *src, char *sep )
|
|
{
|
|
separador=sep=sep;
|
|
n=strlen(separador);
|
|
str=src;
|
|
}
|
|
|
|
char* get()
|
|
{
|
|
if(!str)
|
|
return str;
|
|
char *res=str;
|
|
char * sig=strstr(str, separador);
|
|
|
|
if(!sig)
|
|
str=0;
|
|
else
|
|
{
|
|
str=&sig[n];
|
|
sig[0]=0;
|
|
}
|
|
return res;
|
|
}
|
|
};
|
|
|
|
#endif
|