evitar efecto rebote
parent
519b95a0f9
commit
6dfafd1390
|
|
@ -66,7 +66,7 @@ bool negado;
|
||||||
val=!val;
|
val=!val;
|
||||||
else
|
else
|
||||||
val=(atoi(payload)==1);
|
val=(atoi(payload)==1);
|
||||||
//cambia estado relle
|
//cambia estado relleH
|
||||||
if(negado)
|
if(negado)
|
||||||
digitalWrite(pin, val==0);
|
digitalWrite(pin, val==0);
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,19 @@ class SensorPulsante: public DomoEspSensorReceiver
|
||||||
bool val;
|
bool val;
|
||||||
bool valDef;
|
bool valDef;
|
||||||
uint8_t pin;
|
uint8_t pin;
|
||||||
|
unsigned long tiempo_sens;
|
||||||
|
unsigned long incre_tsens;
|
||||||
|
bool espera;
|
||||||
public:
|
public:
|
||||||
virtual float getVal()
|
virtual float getVal()
|
||||||
{
|
{
|
||||||
return (float)val;
|
return (float)val;
|
||||||
}
|
}
|
||||||
SensorPulsante()
|
SensorPulsante()
|
||||||
{}
|
{
|
||||||
|
espera=false;
|
||||||
|
incre_tsens=500;
|
||||||
|
}
|
||||||
void set(uint8_t _pin, char* topic_id, bool _valDef)
|
void set(uint8_t _pin, char* topic_id, bool _valDef)
|
||||||
{
|
{
|
||||||
pin=_pin;
|
pin=_pin;
|
||||||
|
|
@ -22,10 +27,21 @@ class SensorPulsante: public DomoEspSensorReceiver
|
||||||
val=valDef;
|
val=valDef;
|
||||||
strcpy(topic, topic_id);
|
strcpy(topic, topic_id);
|
||||||
}
|
}
|
||||||
|
void setIncremento(int milis)
|
||||||
|
{
|
||||||
|
incre_tsens=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=digitalRead(pin);
|
int val_ac=valDef;
|
||||||
|
if(!espera || MqttUtiles::pasa_incre(&tiempo_sens, incre_tsens))
|
||||||
|
{
|
||||||
|
val_ac=digitalRead(pin);
|
||||||
|
espera=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(val_ac!=val && val_ac!=valDef)
|
if(val_ac!=val && val_ac!=valDef)
|
||||||
{
|
{
|
||||||
|
|
@ -36,7 +52,10 @@ class SensorPulsante: public DomoEspSensorReceiver
|
||||||
sprintf(buffer_p, "%d", (int)val_ac);
|
sprintf(buffer_p, "%d", (int)val_ac);
|
||||||
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);
|
||||||
|
espera=true;
|
||||||
|
|
||||||
}
|
}
|
||||||
val=val_ac;
|
val=val_ac;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue