añadida clase timer
parent
6dfafd1390
commit
07a0f53eb8
|
|
@ -6,8 +6,7 @@ class SensorTimer: public DomoEspSensorReceiver
|
|||
{
|
||||
bool val;
|
||||
bool valDef;
|
||||
unsigned long tiempo_sens;
|
||||
unsigned long incre_tsens;
|
||||
Ctimer t;
|
||||
|
||||
public:
|
||||
SensorTimer()
|
||||
|
|
@ -17,8 +16,7 @@ class SensorTimer: public DomoEspSensorReceiver
|
|||
}
|
||||
void set(char* topic_id, bool _valdef, int segTime)
|
||||
{
|
||||
incre_tsens=1000*segTime;
|
||||
|
||||
t.set(segTime);
|
||||
valDef=_valdef;
|
||||
val=valDef;
|
||||
strcpy(topic, topic_id);
|
||||
|
|
@ -31,7 +29,7 @@ class SensorTimer: public DomoEspSensorReceiver
|
|||
{
|
||||
if(val!=valDef)
|
||||
{
|
||||
if(MqttUtiles::pasa_incre(&tiempo_sens, incre_tsens))
|
||||
if(t.onTimer())
|
||||
{
|
||||
val=valDef;
|
||||
tiempo=2;
|
||||
|
|
@ -70,8 +68,8 @@ class SensorTimer: public DomoEspSensorReceiver
|
|||
val=1;
|
||||
else
|
||||
val=0;
|
||||
|
||||
MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
||||
t.inicia();
|
||||
//MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
||||
}
|
||||
else if(tipo==Topic::SET)
|
||||
{
|
||||
|
|
@ -80,7 +78,8 @@ class SensorTimer: public DomoEspSensorReceiver
|
|||
else
|
||||
val=atof(payload);
|
||||
if(val!=valDef)
|
||||
MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
||||
t.inicia();
|
||||
//MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
||||
}
|
||||
|
||||
if(valOld!=val)
|
||||
|
|
|
|||
|
|
@ -47,7 +47,43 @@ void MqttUtiles::resetFunc()
|
|||
ESP.wdtEnable(1);
|
||||
while(1){};
|
||||
}
|
||||
//**************************************************************************************************************************************************
|
||||
Ctimer::Ctimer()
|
||||
{
|
||||
t=0;
|
||||
}
|
||||
void Ctimer::set(int incremento_seg)
|
||||
{
|
||||
incre=1000*incremento_seg;
|
||||
}
|
||||
|
||||
void Ctimer::inicia()
|
||||
{
|
||||
t=millis();
|
||||
}
|
||||
|
||||
bool Ctimer::onTimer()
|
||||
{
|
||||
unsigned long ta=millis();
|
||||
if(ta<t)
|
||||
return true;
|
||||
if((t+incre)>=ta)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
bool Ctimer::onTimerReset()
|
||||
{
|
||||
unsigned long ta=millis();
|
||||
if(ta<t)
|
||||
{
|
||||
t=ta;
|
||||
return true;
|
||||
}
|
||||
if((t+incre)>=ta)
|
||||
return false;
|
||||
t=ta;
|
||||
return true;
|
||||
}
|
||||
//**************************************************************************************************************************************************
|
||||
WifiManager::WifiManager()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -13,6 +13,20 @@ class MqttUtiles
|
|||
static void resetFunc();
|
||||
};
|
||||
|
||||
class Ctimer
|
||||
{
|
||||
unsigned long t;
|
||||
unsigned long incre;
|
||||
public:
|
||||
Ctimer();
|
||||
|
||||
void set(int incremento_seg);
|
||||
|
||||
void inicia();//inicia contador de incremento
|
||||
bool onTimer();//devuelve true si ha pasado el tiempo
|
||||
bool onTimerReset();//pasa incremento y si ha pasado se reinicia
|
||||
};
|
||||
|
||||
class MqttOnVarChangeListenner
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
Loading…
Reference in New Issue