2016-02-04 17:19:21 +01:00
|
|
|
#ifndef HALINTERFACES_H
|
|
|
|
|
#define HALINTERFACES_H
|
|
|
|
|
|
2016-05-09 17:49:24 +02:00
|
|
|
#include "HalConfiguration.h"
|
|
|
|
|
|
2016-05-10 16:04:39 +02:00
|
|
|
// Utility functions
|
|
|
|
|
|
2016-05-09 17:49:24 +02:00
|
|
|
#ifdef ENABLE_DEBUG
|
2016-05-10 16:04:39 +02:00
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
2016-05-09 17:49:24 +02:00
|
|
|
#define DEBUG(msg) \
|
|
|
|
|
Serial.println(msg); \
|
|
|
|
|
Serial.flush();
|
|
|
|
|
#define DEBUGF(msg, ...) \
|
|
|
|
|
static char buffer[80];\
|
|
|
|
|
snprintf(buffer, sizeof(buffer), msg, __VA_ARGS__);\
|
|
|
|
|
Serial.println(buffer);\
|
|
|
|
|
Serial.flush();
|
|
|
|
|
#else
|
|
|
|
|
#define DEBUG(msg)
|
|
|
|
|
#define DEBUGF(msg, ...)
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-02-24 21:51:16 +01:00
|
|
|
|
2016-05-10 16:04:39 +02:00
|
|
|
inline void pulse(short pin, short count)
|
|
|
|
|
{
|
|
|
|
|
while (--count >= 0)
|
|
|
|
|
{
|
|
|
|
|
digitalWrite(INDICATOR_PIN, HIGH);
|
|
|
|
|
delay(150);
|
|
|
|
|
digitalWrite(INDICATOR_PIN, LOW);
|
|
|
|
|
if (count != 0) delay(200);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// INTERFACES
|
|
|
|
|
|
2016-05-02 10:56:15 +02:00
|
|
|
class Sensor
|
2016-02-04 17:19:21 +01:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual void setup() = 0;
|
2016-02-24 14:37:48 +01:00
|
|
|
};
|
2016-05-10 16:04:39 +02:00
|
|
|
class Protocol
|
2016-02-24 14:37:48 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2016-05-10 16:04:39 +02:00
|
|
|
virtual void setup() = 0;
|
2016-02-24 14:37:48 +01:00
|
|
|
};
|
2016-02-04 17:19:21 +01:00
|
|
|
|
2016-05-10 16:04:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
struct PowerData
|
|
|
|
|
{
|
|
|
|
|
unsigned int consumption;
|
|
|
|
|
};
|
|
|
|
|
class SensorPowerConsumption : public Sensor
|
2016-02-04 17:19:21 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2016-05-10 16:04:39 +02:00
|
|
|
// returns number of pulses from power meter
|
|
|
|
|
virtual void read(PowerData& data) = 0;
|
2016-02-24 14:37:48 +01:00
|
|
|
};
|
2016-05-10 16:04:39 +02:00
|
|
|
class ProtocolPowerConsumption : public Protocol
|
2016-02-04 17:19:21 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2016-05-10 16:04:39 +02:00
|
|
|
virtual void send(const PowerData& data) = 0;
|
2016-02-24 14:37:48 +01:00
|
|
|
};
|
2016-02-04 17:19:21 +01:00
|
|
|
|
|
|
|
|
|
2016-05-10 16:04:39 +02:00
|
|
|
struct TemperatureData
|
2016-02-04 17:19:21 +01:00
|
|
|
{
|
2016-05-10 16:04:39 +02:00
|
|
|
float temperature;
|
2016-05-29 22:23:29 +02:00
|
|
|
float humidity;
|
2016-02-24 14:37:48 +01:00
|
|
|
};
|
2016-05-10 16:04:39 +02:00
|
|
|
class SensorTemperature : public Sensor
|
2016-02-24 21:51:16 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2016-05-10 16:04:39 +02:00
|
|
|
virtual void read(TemperatureData& data) = 0;
|
2016-02-24 21:51:16 +01:00
|
|
|
};
|
|
|
|
|
class ProtocolTemperature : public Protocol
|
|
|
|
|
{
|
|
|
|
|
public:
|
2016-05-10 16:04:39 +02:00
|
|
|
virtual void send(const TemperatureData& data) = 0;
|
2016-02-24 21:51:16 +01:00
|
|
|
};
|
|
|
|
|
|
2016-05-10 16:04:39 +02:00
|
|
|
|
|
|
|
|
struct LightData
|
|
|
|
|
{
|
|
|
|
|
unsigned int lumen;
|
|
|
|
|
};
|
|
|
|
|
class SensorLight : public Sensor
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
virtual void read(LightData& data) = 0;
|
|
|
|
|
};
|
2016-02-24 21:51:16 +01:00
|
|
|
class ProtocolLight : public Protocol
|
|
|
|
|
{
|
|
|
|
|
public:
|
2016-05-10 16:04:39 +02:00
|
|
|
virtual void send(const LightData& data) = 0;
|
2016-02-24 21:51:16 +01:00
|
|
|
};
|
|
|
|
|
|
2016-05-10 16:04:39 +02:00
|
|
|
|
2016-02-24 21:51:16 +01:00
|
|
|
#endif // HALINTERFACES_H
|