Añadido sensor lcd y config despacho
parent
d36cbf477a
commit
f4102900f2
|
|
@ -9,6 +9,7 @@
|
|||
#include "SensorVF.h"
|
||||
#include "SensorRF.h"
|
||||
#include "SensorTimer.h"
|
||||
#include "SensorLcd.h"
|
||||
|
||||
#include "Actuador.h"
|
||||
//----------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -0,0 +1,195 @@
|
|||
#ifndef SensorLcdDef
|
||||
#define SensorLcdDef 1
|
||||
#include "defines.h"
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
#define MAX_SENS_PAN 2
|
||||
class PantallaLcd
|
||||
{
|
||||
public:
|
||||
PantallaLcd()
|
||||
{
|
||||
msg[0]=0;
|
||||
}
|
||||
char msg[MAX_CHAR_PAN_LCD];
|
||||
DomoEspSensorReceiver* sen[MAX_SENS_PAN];
|
||||
};
|
||||
|
||||
|
||||
//sensor virtual
|
||||
class SensorLcd : public DomoEspSensorReceiver
|
||||
{
|
||||
float val;
|
||||
LiquidCrystal *lcd;
|
||||
int nchar;
|
||||
int nlin;
|
||||
int npan;
|
||||
int apan;
|
||||
unsigned long tiempo_sens;
|
||||
unsigned long incre_tsens;
|
||||
|
||||
|
||||
PantallaLcd pan[MAX_PAN_LCD];
|
||||
public:
|
||||
SensorLcd()
|
||||
{
|
||||
val = 0;
|
||||
topic[0] = 0;
|
||||
lcd = 0;
|
||||
npan=0;
|
||||
apan=0;
|
||||
|
||||
}
|
||||
void set(char* topic_id, LiquidCrystal * _lcd, int _nchar, int lineas, int seg)
|
||||
{
|
||||
val = 0;
|
||||
strcpy(topic, topic_id);
|
||||
lcd = _lcd;
|
||||
incre_tsens = 1000 * seg;
|
||||
nchar = _nchar;
|
||||
nlin = lineas;
|
||||
|
||||
}
|
||||
void AddPan(char* msg, DomoEspSensorReceiver *sen1=0, DomoEspSensorReceiver *sen2=0)
|
||||
{
|
||||
if(npan<MAX_PAN_LCD)
|
||||
{
|
||||
strcpy(pan[npan].msg, msg);
|
||||
pan[npan].sen[0]=sen1;
|
||||
pan[npan].sen[1]=sen2;
|
||||
npan++;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG_PS
|
||||
Serial.println("----------------------ERROR NO ENTRAN MAS pantallas en lcd---------------- ");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
virtual float getVal()
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
virtual void inicia()
|
||||
{
|
||||
lcd->begin(nchar, nlin);
|
||||
MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
||||
}
|
||||
|
||||
virtual void procesa(IMqttManager* man, int tiempo)
|
||||
{
|
||||
if(MqttUtiles::pasa_incre(&tiempo_sens, incre_tsens))
|
||||
{
|
||||
apan=(apan+1)%npan;
|
||||
muestraPan();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void SubscribeMqtt(IMqttManager* man) {
|
||||
//char buffer_t[MAXTOPICVAR];
|
||||
sprintf(buffer_t, "%s/set", topic);
|
||||
man->MqttSubs(buffer_t);
|
||||
}
|
||||
virtual void OnMqtt(IMqttManager* man, char* _topic, char* payload, int tipo)
|
||||
{
|
||||
if (tipo != Topic::SET)
|
||||
return;
|
||||
if (!strcmp(_topic, topic))
|
||||
{
|
||||
Muestra(payload);
|
||||
MqttUtiles::reinicia_incre(&tiempo_sens, incre_tsens);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
void muestraPan()
|
||||
{
|
||||
if(npan<=0)
|
||||
return;
|
||||
#ifdef DEBUG_PS
|
||||
Serial.println("SenLcd muestraPan:");
|
||||
Serial.println(apan);
|
||||
#endif
|
||||
char msg[MAX_CHAR_PAN_LCD];
|
||||
char val1[6];
|
||||
char val2[6];
|
||||
|
||||
if(pan[apan].sen[0])
|
||||
dtostrf(pan[apan].sen[0]->getVal(),3, 2, val1);
|
||||
if(pan[apan].sen[0])
|
||||
dtostrf(pan[apan].sen[1]->getVal(),3, 2, val2);
|
||||
|
||||
sprintf(msg, pan[apan].msg, val1,val2);
|
||||
Muestra(msg);
|
||||
|
||||
}
|
||||
void Muestra(char * txt)
|
||||
{
|
||||
#ifdef DEBUG_PS
|
||||
Serial.println("SenLcd muestra: ");
|
||||
Serial.println(txt);
|
||||
#endif
|
||||
int linea=0;
|
||||
int i=0;
|
||||
char* ini=txt;
|
||||
bool sigue=true;
|
||||
while(sigue && linea<nlin)
|
||||
{
|
||||
if((ini[i]=='\n') || (ini[i]==0))
|
||||
{
|
||||
Muestra(ini, i, linea);
|
||||
if(*ini==0)
|
||||
{
|
||||
sigue=false;
|
||||
}
|
||||
else
|
||||
{
|
||||
ini=&ini[i+1];
|
||||
}
|
||||
i=0;
|
||||
linea++;
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
i++;
|
||||
|
||||
}
|
||||
while(linea<nlin)
|
||||
{
|
||||
Muestra("", 0, linea);
|
||||
linea++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void Muestra(char * txt,int nStr, int linea)
|
||||
{
|
||||
char buf[MAXTOPICVAR];
|
||||
|
||||
if (nStr > nchar)
|
||||
nStr= nchar;
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < nchar; i++)
|
||||
if (i < nStr)
|
||||
buf[i] = txt[i];
|
||||
else
|
||||
buf[i] = ' ';
|
||||
|
||||
buf[nchar] = 0;
|
||||
#ifdef DEBUG_PS
|
||||
Serial.println("SenLcd muestraFin: ");
|
||||
Serial.println(buf);
|
||||
#endif
|
||||
lcd->setCursor(0, linea);
|
||||
lcd->print(buf);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -92,8 +92,63 @@ class ConfActual: public DomoEspConfig
|
|||
}
|
||||
|
||||
};
|
||||
class Confdespacho: public DomoEspConfig
|
||||
{
|
||||
SensorDHT dht;
|
||||
SensorAin nivelLuz;
|
||||
SensorLcd senlcd;
|
||||
|
||||
SensorRF tcocina;
|
||||
SensorRF hcocina;
|
||||
SensorRF tdesp;
|
||||
SensorRF hdesp;
|
||||
SensorRF tsal;
|
||||
SensorRF hsal;
|
||||
LiquidCrystal lcd{D5,D6,D3,D2,D1,D0};
|
||||
|
||||
public:
|
||||
Confdespacho()
|
||||
{
|
||||
|
||||
strcpy(ssidWifi,"IdhunAux");//nombre wifi
|
||||
strcpy(ideEsp,"Esp8266_Despacho");//idenitificador del esp (sera único)
|
||||
|
||||
dht.set(D4, "casa/desp");
|
||||
nivelLuz.set(0,"casa/desp/luz",0, 0);
|
||||
|
||||
senlcd.set("casa/desp/lcd", &lcd, 16,2, 7);
|
||||
tcocina.set("casa/cocina/t");
|
||||
hcocina.set("casa/cocina/h");
|
||||
tsal.set("casa/Salon/t");
|
||||
hsal.set("casa/Salon/h");
|
||||
tdesp.set("casa/desp/t");
|
||||
hdesp.set("casa/desp/h");
|
||||
senlcd.AddPan("T cocina: %s\nH cocina: %s",&tcocina, &hcocina);
|
||||
senlcd.AddPan("T desp: %s\nH desp: %s",&tdesp, &hdesp);
|
||||
senlcd.AddPan("T salon: %s\nH salon: %s",&tsal, &hsal);
|
||||
|
||||
}
|
||||
virtual void inicia(ISensorManager* man)
|
||||
{
|
||||
man->Add(&dht);
|
||||
man->Add(&nivelLuz);
|
||||
man->Add(&senlcd);
|
||||
|
||||
man->Add(&tcocina);
|
||||
man->Add(&hcocina);
|
||||
|
||||
man->Add(&tdesp);
|
||||
man->Add(&hdesp);
|
||||
|
||||
man->Add(&tsal);
|
||||
man->Add(&hsal);
|
||||
|
||||
|
||||
ConfActual ConfiguracionActual;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Confdespacho ConfiguracionActual;
|
||||
|
||||
#endif
|
||||
|
|
@ -2,11 +2,10 @@
|
|||
#define DefinesDef 1
|
||||
|
||||
#define DEBUG_PS 1
|
||||
#define CON_WOL 0
|
||||
#define CON_LCD 0
|
||||
|
||||
#define MAXTOPICVAR 32//maximo de caracteres de los topic de las variables
|
||||
|
||||
#define MAX_CHAR_PAN_LCD 35//MAXIMO DE CARACTRES POR PANTALLA LCD
|
||||
#define MAX_PAN_LCD 3//MAXIMO DE PANTALLAS POR SENSOR LCD
|
||||
//vars--------------------
|
||||
#define MAXSTR 2024//maximo de caracteres para str
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue