usando onTimer
parent
809b2e6d64
commit
32b9e4e8e5
|
|
@ -8,8 +8,7 @@ class SensorAin: public DomoEspSensorReceiver
|
||||||
bool negado;
|
bool negado;
|
||||||
uint8_t pin;
|
uint8_t pin;
|
||||||
float dif;
|
float dif;
|
||||||
unsigned long t;
|
Ctimer timer;
|
||||||
unsigned long incre;
|
|
||||||
public:
|
public:
|
||||||
virtual float getVal()
|
virtual float getVal()
|
||||||
{
|
{
|
||||||
|
|
@ -18,8 +17,8 @@ class SensorAin: public DomoEspSensorReceiver
|
||||||
SensorAin(){}
|
SensorAin(){}
|
||||||
void set(uint8_t _pin, char* topic_id, bool _negado, float _dif)
|
void set(uint8_t _pin, char* topic_id, bool _negado, float _dif)
|
||||||
{
|
{
|
||||||
t=0;
|
timer.inicia();
|
||||||
incre=1000;
|
timer.set(1);
|
||||||
dif=_dif;
|
dif=_dif;
|
||||||
negado=_negado;
|
negado=_negado;
|
||||||
pin=_pin;
|
pin=_pin;
|
||||||
|
|
@ -29,7 +28,7 @@ class SensorAin: public DomoEspSensorReceiver
|
||||||
virtual void procesa(IMqttManager * man, int tiempo)
|
virtual void procesa(IMqttManager * man, int tiempo)
|
||||||
{
|
{
|
||||||
//mirar para configurar por interrupcion
|
//mirar para configurar por interrupcion
|
||||||
if((dif!=0 && MqttUtiles::pasa_incre(&t, incre)) || tiempo==2)
|
if((dif!=0 && timer.onTimerReset()) || tiempo==2)
|
||||||
{
|
{
|
||||||
float val_act;
|
float val_act;
|
||||||
if(negado)
|
if(negado)
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,7 @@ class SensorLcd : public DomoEspSensorReceiver
|
||||||
int nlin;
|
int nlin;
|
||||||
int npan;
|
int npan;
|
||||||
int apan;
|
int apan;
|
||||||
unsigned long tiempo_sens;
|
Ctimer timer;
|
||||||
unsigned long incre_tsens;
|
|
||||||
|
|
||||||
|
|
||||||
PantallaLcd pan[MAX_PAN_LCD];
|
PantallaLcd pan[MAX_PAN_LCD];
|
||||||
|
|
@ -45,7 +44,7 @@ public:
|
||||||
val = 0;
|
val = 0;
|
||||||
strcpy(topic, topic_id);
|
strcpy(topic, topic_id);
|
||||||
lcd = _lcd;
|
lcd = _lcd;
|
||||||
incre_tsens = 1000 * seg;
|
timer.set(seg);
|
||||||
nchar = _nchar;
|
nchar = _nchar;
|
||||||
nlin = lineas;
|
nlin = lineas;
|
||||||
|
|
||||||
|
|
@ -74,12 +73,12 @@ public:
|
||||||
virtual void inicia()
|
virtual void inicia()
|
||||||
{
|
{
|
||||||
lcd->begin(nchar, nlin);
|
lcd->begin(nchar, nlin);
|
||||||
MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
timer.inicia();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void procesa(IMqttManager* man, int tiempo)
|
virtual void procesa(IMqttManager* man, int tiempo)
|
||||||
{
|
{
|
||||||
if(MqttUtiles::pasa_incre(&tiempo_sens, incre_tsens))
|
if(timer.onTimerReset())
|
||||||
{
|
{
|
||||||
apan=(apan+1)%npan;
|
apan=(apan+1)%npan;
|
||||||
muestraPan();
|
muestraPan();
|
||||||
|
|
@ -98,7 +97,7 @@ public:
|
||||||
if (!strcmp(_topic, topic))
|
if (!strcmp(_topic, topic))
|
||||||
{
|
{
|
||||||
Muestra(payload);
|
Muestra(payload);
|
||||||
MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
timer.inicia();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,7 @@ class SensorPulsante: public DomoEspSensorReceiver
|
||||||
bool val;
|
bool val;
|
||||||
bool valDef;
|
bool valDef;
|
||||||
uint8_t pin;
|
uint8_t pin;
|
||||||
unsigned long tiempo_sens;
|
Ctimer timer;
|
||||||
unsigned long incre_tsens;
|
|
||||||
bool espera;
|
bool espera;
|
||||||
public:
|
public:
|
||||||
virtual float getVal()
|
virtual float getVal()
|
||||||
|
|
@ -18,7 +17,7 @@ class SensorPulsante: public DomoEspSensorReceiver
|
||||||
SensorPulsante()
|
SensorPulsante()
|
||||||
{
|
{
|
||||||
espera=false;
|
espera=false;
|
||||||
incre_tsens=500;
|
timer.setmilis(500);
|
||||||
}
|
}
|
||||||
void set(uint8_t _pin, char* topic_id, bool _valDef)
|
void set(uint8_t _pin, char* topic_id, bool _valDef)
|
||||||
{
|
{
|
||||||
|
|
@ -29,14 +28,14 @@ class SensorPulsante: public DomoEspSensorReceiver
|
||||||
}
|
}
|
||||||
void setIncremento(int milis)
|
void setIncremento(int milis)
|
||||||
{
|
{
|
||||||
incre_tsens=milis;
|
timer.setmilis(milis);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void procesa(IMqttManager * man, int tiempo)
|
virtual void procesa(IMqttManager * man, int tiempo)
|
||||||
{
|
{
|
||||||
//mirar para configurar por interrupcion
|
//mirar para configurar por interrupcion
|
||||||
int val_ac=val;
|
int val_ac=val;
|
||||||
if(!espera || MqttUtiles::pasa_incre(&tiempo_sens, incre_tsens))
|
if(!espera || timer.onTimer())
|
||||||
{
|
{
|
||||||
val_ac=digitalRead(pin);
|
val_ac=digitalRead(pin);
|
||||||
espera=false;
|
espera=false;
|
||||||
|
|
@ -53,7 +52,7 @@ class SensorPulsante: public DomoEspSensorReceiver
|
||||||
sprintf(buffer_t, "%s/pul",topic);
|
sprintf(buffer_t, "%s/pul",topic);
|
||||||
man->MqttSend(buffer_t, buffer_p);
|
man->MqttSend(buffer_t, buffer_p);
|
||||||
//delay(100);
|
//delay(100);
|
||||||
MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
timer.inicia();
|
||||||
espera=true;
|
espera=true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,39 +9,6 @@
|
||||||
|
|
||||||
#include "Utiles.h"
|
#include "Utiles.h"
|
||||||
//**************************************************************************************************************************************************
|
//**************************************************************************************************************************************************
|
||||||
|
|
||||||
void MqttUtiles::reinicia_incre( unsigned long *tt, unsigned long incre)
|
|
||||||
{
|
|
||||||
*tt=millis();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MqttUtiles::pasa_incre( unsigned long *tt, unsigned long incre)
|
|
||||||
{
|
|
||||||
unsigned long t=millis();
|
|
||||||
if(t<*tt)
|
|
||||||
{
|
|
||||||
*tt=t;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if((*tt+incre)>=t)
|
|
||||||
return false;
|
|
||||||
*tt=t;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MqttUtiles::pasa_incre( volatile unsigned long *tt, unsigned long incre)
|
|
||||||
{
|
|
||||||
unsigned long t=millis();
|
|
||||||
if(t<*tt)
|
|
||||||
{
|
|
||||||
*tt=t;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if((*tt+incre)>=t)
|
|
||||||
return false;
|
|
||||||
*tt=t;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
void MqttUtiles::resetFunc()
|
void MqttUtiles::resetFunc()
|
||||||
{
|
{
|
||||||
ESP.wdtEnable(1);
|
ESP.wdtEnable(1);
|
||||||
|
|
@ -56,7 +23,10 @@ void MqttUtiles::resetFunc()
|
||||||
{
|
{
|
||||||
incre=1000*incremento_seg;
|
incre=1000*incremento_seg;
|
||||||
}
|
}
|
||||||
|
void Ctimer::setmilis(int milis)
|
||||||
|
{
|
||||||
|
incre=milis;
|
||||||
|
}
|
||||||
void Ctimer::inicia()
|
void Ctimer::inicia()
|
||||||
{
|
{
|
||||||
t=millis();
|
t=millis();
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,6 @@ class WiFiClient;
|
||||||
class MqttUtiles
|
class MqttUtiles
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static bool pasa_incre( unsigned long *tt, unsigned long incre);
|
|
||||||
static void reinicia_incre( unsigned long *tt, unsigned long incre);
|
|
||||||
static bool pasa_incre( volatile unsigned long *tt, unsigned long incre);
|
|
||||||
static void resetFunc();
|
static void resetFunc();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -21,6 +18,8 @@ class Ctimer
|
||||||
Ctimer();
|
Ctimer();
|
||||||
|
|
||||||
void set(int incremento_seg);
|
void set(int incremento_seg);
|
||||||
|
void setmilis(int milis);
|
||||||
|
|
||||||
|
|
||||||
void inicia();//inicia contador de incremento
|
void inicia();//inicia contador de incremento
|
||||||
bool onTimer();//devuelve true si ha pasado el tiempo
|
bool onTimer();//devuelve true si ha pasado el tiempo
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue