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