se añade sensor buzzer y sensor splitter
parent
f4102900f2
commit
e963db4213
|
|
@ -17,7 +17,7 @@ class Actuador: public DomoEspSensorReceiver
|
|||
{
|
||||
float val;
|
||||
char topicOut[MAXTOPICVAR];
|
||||
char valSend[3];
|
||||
char valSend[MAX_CHAR_ENVIO];
|
||||
Cactivador activador[MAX_ACTIVADORES];
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -7,10 +7,12 @@
|
|||
#include "SensorPulsante.h"
|
||||
#include "SensorAin.h"
|
||||
#include "SensorVF.h"
|
||||
#include "SensorRF.h"
|
||||
#include "SensorTimer.h"
|
||||
#include "SensorLcd.h"
|
||||
#include "SensorBuzzer.h"
|
||||
|
||||
#include "SensorRF.h"
|
||||
#include "SensorSplitter.h"
|
||||
#include "Actuador.h"
|
||||
//----------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
#ifndef SensorBuzzerDef
|
||||
#define SensorBuzzerDef 1
|
||||
#include "Utiles.h"
|
||||
//sensor virtual
|
||||
class SensorBuzzer: public DomoEspSensorReceiver
|
||||
{
|
||||
int val;
|
||||
SonidoBuzzer buz;
|
||||
int pin;
|
||||
public:
|
||||
SensorBuzzer()
|
||||
{
|
||||
val=0;
|
||||
topic[0]=0;
|
||||
}
|
||||
void setMelodia(int i, char* melodia)
|
||||
{
|
||||
buz.Set(i, melodia);
|
||||
}
|
||||
void set(char* topic_id, int _pin)
|
||||
{
|
||||
val=0;
|
||||
strcpy(topic, topic_id);
|
||||
pin=_pin;
|
||||
}
|
||||
virtual float getVal()
|
||||
{
|
||||
return (float)val;
|
||||
}
|
||||
virtual void inicia()
|
||||
{
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(pin, 1);
|
||||
}
|
||||
virtual void SubscribeMqtt(IMqttManager* man){
|
||||
//char buffer_t[MAXTOPICVAR];
|
||||
sprintf(buffer_t, "%s/set",topic);
|
||||
man->MqttSubs(buffer_t);
|
||||
sprintf(buffer_t, "%s/pul",topic);
|
||||
man->MqttSubs(buffer_t);
|
||||
}
|
||||
virtual void OnMqtt(IMqttManager * man, char* _topic, char* payload, int tipo)
|
||||
{
|
||||
if((tipo!=Topic::SET) && (tipo!=Topic::PUL))
|
||||
return;
|
||||
if(!strcmp(_topic, topic))
|
||||
{
|
||||
if(tipo==Topic::PUL)
|
||||
{
|
||||
//reproduce melodia
|
||||
val=atoi(payload);
|
||||
if(val>=0 && val<MAX_MELODIAS)
|
||||
buz.Toca(pin, val);
|
||||
digitalWrite(pin, 1);
|
||||
}
|
||||
else if(tipo==Topic::SET)
|
||||
{
|
||||
//reproduce melodia
|
||||
char buf[5];
|
||||
char*mel=buz.getMelSubSt(payload, '~', 5, buf);
|
||||
val=atoi(buf);
|
||||
if(val>=0 && val<MAX_MELODIAS)
|
||||
buz.Set(val, mel);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
#ifndef SensorSplitterDef
|
||||
#define SensorSplitterDef 1
|
||||
#include "defines.h"
|
||||
//sensor virtual
|
||||
class SplitterSend
|
||||
{
|
||||
public:
|
||||
SplitterSend(){}
|
||||
DomoEspSensorReceiver *sen;
|
||||
};
|
||||
|
||||
class SensorSplitter: public DomoEspSensorReceiver
|
||||
{
|
||||
float val;
|
||||
SplitterSend sensorSend[MAX_ACTIVADORES];
|
||||
|
||||
public:
|
||||
SensorSplitter()
|
||||
{
|
||||
val=0;
|
||||
topic[0]=0;
|
||||
for(int i=0; i<MAX_ACTIVADORES; i++)
|
||||
sensorSend[i].sen=0;
|
||||
}
|
||||
void set(char* topic_id, float valdef)
|
||||
{
|
||||
val=valdef;
|
||||
strcpy(topic, topic_id);
|
||||
}
|
||||
void AddSens(DomoEspSensorReceiver* sen)
|
||||
{
|
||||
for(int i=0; i<MAX_ACTIVADORES; i++)
|
||||
{
|
||||
if(sensorSend[i].sen==NULL)
|
||||
{
|
||||
sensorSend[i].sen=sen;
|
||||
return;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG_PS
|
||||
|
||||
Serial.println("----------------------ERROR NO ENTRAN MAS SENSORES EN SPLITTER---------------- ");
|
||||
#endif
|
||||
}
|
||||
virtual float getVal()
|
||||
{
|
||||
return (float)val;
|
||||
}
|
||||
virtual void SubscribeMqtt(IMqttManager* man){
|
||||
//char buffer_t[MAXTOPICVAR];
|
||||
sprintf(buffer_t, "%s/set",topic);
|
||||
sprintf(buffer_t, "%s/pul",topic);
|
||||
man->MqttSubs(buffer_t);
|
||||
}
|
||||
virtual void OnMqtt(IMqttManager * man, char* _topic, char* payload, int tipo)
|
||||
{
|
||||
if(tipo!=Topic::SET || tipo!=Topic::PUL)
|
||||
return;
|
||||
if(strcmp(_topic, topic))
|
||||
return;
|
||||
|
||||
if(tipo==Topic::SET )
|
||||
{
|
||||
if(payload[0]=='X')
|
||||
{
|
||||
if(val==0)
|
||||
val=1;
|
||||
else
|
||||
val=0; }
|
||||
else
|
||||
val=atof(payload);
|
||||
for(int i=0; i<MAX_ACTIVADORES; i++)
|
||||
{
|
||||
if(sensorSend[i].sen)
|
||||
{
|
||||
sprintf(buffer_t, "%s/set",sensorSend[i].sen->topic);
|
||||
man->MqttSend(buffer_t, payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(tipo==Topic::PUL )
|
||||
{
|
||||
for(int i=0; i<MAX_ACTIVADORES; i++)
|
||||
{
|
||||
|
||||
if(sensorSend[i].sen)
|
||||
{
|
||||
sprintf(buffer_t, "%s/pul",sensorSend[i].sen->topic);
|
||||
man->MqttSend(buffer_t, payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -47,6 +47,7 @@ void MqttUtiles::resetFunc()
|
|||
ESP.wdtEnable(1);
|
||||
while(1){};
|
||||
}
|
||||
|
||||
//**************************************************************************************************************************************************
|
||||
WifiManager::WifiManager()
|
||||
{
|
||||
|
|
@ -228,3 +229,116 @@ void MqttManager::OnMqtt(char* topic, byte* payload, unsigned int length)
|
|||
}
|
||||
|
||||
//**************************************************************************************************************************************************
|
||||
MelodiaBuzzer::MelodiaBuzzer()
|
||||
{
|
||||
melodia[0]=0;
|
||||
}
|
||||
int MelodiaBuzzer::st2nota(char st)
|
||||
{
|
||||
switch(st)
|
||||
{
|
||||
case 'd':
|
||||
return 262;
|
||||
case 'r':
|
||||
return 294;
|
||||
case 'm':
|
||||
return 330;
|
||||
case 'f':
|
||||
return 349;
|
||||
case 's':
|
||||
return 392;
|
||||
case 'l':
|
||||
return 440;
|
||||
case 'i':
|
||||
return 494;
|
||||
case 'D':
|
||||
return 277;
|
||||
case 'R':
|
||||
return 311;
|
||||
case 'M':
|
||||
return 345;
|
||||
case 'F':
|
||||
return 350;
|
||||
case 'S':
|
||||
return 415;
|
||||
case 'L':
|
||||
return 466;
|
||||
case 'I':
|
||||
return 554,36;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int MelodiaBuzzer::str2t(char* st, int *t)
|
||||
{
|
||||
char buf[8];
|
||||
int n=0;
|
||||
int i;
|
||||
while(st[i]<='9' && st[i]>='0')
|
||||
{
|
||||
buf[n++]=st[i++];
|
||||
}
|
||||
buf[n]=0;
|
||||
(*t)=atoi(buf);
|
||||
return i;
|
||||
}
|
||||
void MelodiaBuzzer::Toca(int pin)
|
||||
{
|
||||
int i=0;
|
||||
int h=0, t=0;
|
||||
|
||||
while (melodia[i])
|
||||
{
|
||||
h=st2nota(melodia[i]);
|
||||
i++;
|
||||
t=0;
|
||||
i+=str2t(&melodia[i], &t);
|
||||
if(h>0)
|
||||
tone(pin, h);
|
||||
else
|
||||
noTone(pin);
|
||||
delay(t);
|
||||
}
|
||||
}
|
||||
//*************************************************
|
||||
char* SonidoBuzzer::getMelSubSt(char* orig, char caracter, int lim, char* bufOut)
|
||||
{
|
||||
char* res;
|
||||
for(int i=0; i<lim; i++)
|
||||
{
|
||||
if(orig[i]==caracter || orig[i]==0)
|
||||
{
|
||||
bufOut[i]=0;
|
||||
res=&orig[i];
|
||||
i=lim;
|
||||
}
|
||||
else
|
||||
{
|
||||
bufOut[i]=orig[i];
|
||||
}
|
||||
}
|
||||
bufOut[lim-1]=0;
|
||||
if(*res)
|
||||
res=&res[1];
|
||||
return res;
|
||||
}
|
||||
SonidoBuzzer::SonidoBuzzer()
|
||||
{
|
||||
n=0;
|
||||
}
|
||||
|
||||
void SonidoBuzzer::Toca(int pin, int imel)
|
||||
{
|
||||
if (imel<0 || imel>=n)
|
||||
return;
|
||||
mel[imel].Toca(pin);
|
||||
}
|
||||
|
||||
void SonidoBuzzer::Set(int i, char* melo)
|
||||
{
|
||||
if(i<MAX_MELODIAS)
|
||||
{
|
||||
strcpy(mel[i].melodia, melo);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ class MqttUtiles
|
|||
static void reinicia_incre( unsigned long *tt, unsigned long incre);
|
||||
static bool pasa_incre( volatile unsigned long *tt, unsigned long incre);
|
||||
static void resetFunc();
|
||||
|
||||
};
|
||||
|
||||
class MqttOnVarChangeListenner
|
||||
|
|
@ -65,4 +64,29 @@ class MqttManager
|
|||
static void OnMqtt(char* topic, uint8_t * payload, unsigned int length);
|
||||
void subscribe_mqtt();
|
||||
};
|
||||
|
||||
class MelodiaBuzzer
|
||||
{
|
||||
public:
|
||||
//melodia se compone de notas (primera letra y tiempo de duracion) silecio es #
|
||||
char melodia[MAX_CHAR_MELODIA];
|
||||
MelodiaBuzzer();
|
||||
int st2nota(char st);
|
||||
int str2t(char* st, int *t);
|
||||
|
||||
void Toca(int pin);
|
||||
};
|
||||
|
||||
class SonidoBuzzer
|
||||
{
|
||||
public:
|
||||
MelodiaBuzzer mel[MAX_MELODIAS];
|
||||
int n;
|
||||
SonidoBuzzer();
|
||||
void Toca(int pin, int melodia);
|
||||
void Set(int i, char* melo);
|
||||
char* getMelSubSt(char* orig, char caracter, int lim, char* bufOut);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -55,6 +55,7 @@ class ConfActual: public DomoEspConfig
|
|||
SensorVF sv;
|
||||
Actuador actTimer;
|
||||
SensorTimer st;
|
||||
SensorBuzzer buz;
|
||||
public:
|
||||
ConfActual()
|
||||
{
|
||||
|
|
@ -74,6 +75,9 @@ class ConfActual: public DomoEspConfig
|
|||
actTimer.set("casa/pruebas/inter", "casa/pruebas/timer", "1");
|
||||
actTimer.setId("aTimer");
|
||||
actTimer.AddActivador(&interup, '<', 1);
|
||||
buz.set("casa/pruebas/buz", D4);
|
||||
buz.setMelodia(0, "m200#100d200#0");//titu
|
||||
buz.setMelodia(1, "d200#100d200#100d200#100f200#100l300#0");//titu
|
||||
|
||||
}
|
||||
virtual void inicia(ISensorManager* man)
|
||||
|
|
@ -86,6 +90,8 @@ class ConfActual: public DomoEspConfig
|
|||
man->Add(&sv);
|
||||
man->Add(&st);
|
||||
man->Add(&actTimer);
|
||||
man->Add(&buz);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -149,6 +155,6 @@ class Confdespacho: public DomoEspConfig
|
|||
|
||||
};
|
||||
|
||||
Confdespacho ConfiguracionActual;
|
||||
ConfActual ConfiguracionActual;
|
||||
|
||||
#endif
|
||||
|
|
@ -11,12 +11,13 @@
|
|||
|
||||
//sens--------------------
|
||||
#define MAXSENS 16 //maximo de sensores totales
|
||||
//actuador
|
||||
#define MAX_ACTIVADORES 5//maximo de activadores por actuador
|
||||
#define MAX_CHAR_ENVIO 16
|
||||
|
||||
|
||||
|
||||
|
||||
#define MAXINTERRUP 8
|
||||
//MELODIA----------------------
|
||||
#define MAX_CHAR_MELODIA 64
|
||||
#define MAX_MELODIAS 4
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue