2016-02-01 17:52:17 +01:00
|
|
|
/*
|
|
|
|
|
A interrupt based sensor device that reads multiple sensors and transmits
|
|
|
|
|
the data to a central location.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-24 14:37:48 +01:00
|
|
|
InterruptUtil timerInterrupt;
|
2016-02-01 17:52:17 +01:00
|
|
|
|
2016-02-24 14:37:48 +01:00
|
|
|
unsigned int timerMultiplierMAX;
|
|
|
|
|
unsigned int timerMultiplier = 0;
|
|
|
|
|
|
|
|
|
|
// Sensors
|
|
|
|
|
HardwarePowerConsumption powerSensor;
|
2016-02-24 15:31:51 +01:00
|
|
|
HardwareTemperature tempSensor;
|
2016-02-24 14:37:48 +01:00
|
|
|
HardwareLight lightSensor;
|
|
|
|
|
|
|
|
|
|
// Protocols
|
|
|
|
|
HardwarePowerConsumption powerProtocol;
|
2016-02-24 15:31:51 +01:00
|
|
|
HardwareTemperature tempProtocol;
|
2016-02-24 14:37:48 +01:00
|
|
|
HardwareLight lightProtocol;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-24 15:31:51 +01:00
|
|
|
void timerInterrupt();
|
|
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
|
{
|
|
|
|
|
timerMultipleMAX = POWER_TIMER_MULTIPLIER * TEMPERATURE_TIMER_MULTIPLIER * LIGHT_TIMER_MULTIPLIER; // Find a lowest common denominator
|
|
|
|
|
pinInterrupt = InterruptUtil(timerInterrupt);
|
|
|
|
|
pinInterrupt.setupTimerInterrupt(60*1000); // one minute scheduled interrupt
|
|
|
|
|
|
|
|
|
|
// Setup Sensors and protocols
|
|
|
|
|
#ifdef POWERCON_ENABLED
|
|
|
|
|
powerSensor = POWERCON_HARDWARE;
|
|
|
|
|
powerSensor.setup();
|
|
|
|
|
powerProtocol = POWERCON_PROTOCOL;
|
|
|
|
|
powerProtocol.setup();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef TEMPERATURE_ENABLED
|
|
|
|
|
tempSensor = TEMPERATURE_HARDWARE;
|
|
|
|
|
tempSensor.setup();
|
|
|
|
|
tempProtocol = TEMPERATURE_PROTOCOL;
|
|
|
|
|
tempProtocol.setup();
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef LIGHT_ENABLED
|
|
|
|
|
lightSensor = LIGHT_HARDWARE;
|
|
|
|
|
lightSensor.setup();
|
|
|
|
|
lightProtocol = LIGHT_PROTOCOL;
|
|
|
|
|
lightProtocol.setup();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {}
|
|
|
|
|
|
|
|
|
|
|
2016-02-24 14:37:48 +01:00
|
|
|
void timerInterrupt()
|
2016-02-11 16:31:03 +01:00
|
|
|
{
|
2016-02-24 14:37:48 +01:00
|
|
|
++timerMultiplier;
|
|
|
|
|
if (timerMultiplier > timerMultiplierMAX)
|
|
|
|
|
timerMultiplier = 1;
|
2016-02-01 17:52:17 +01:00
|
|
|
|
2016-02-24 14:37:48 +01:00
|
|
|
// Send power consumption
|
2016-02-24 15:31:51 +01:00
|
|
|
#ifdef POWERCON_ENABLED
|
|
|
|
|
if(timerMultiplier == POWER_TIMER_MULTIPLIER)
|
|
|
|
|
{
|
|
|
|
|
unsigned int consumption = powerSensor.getConsumption();
|
|
|
|
|
powerSensor.reset();
|
|
|
|
|
powerProtocol.setConsumption(consumption);
|
|
|
|
|
powerProtocol.send();
|
|
|
|
|
}
|
2016-02-24 14:37:48 +01:00
|
|
|
#endif
|
2016-02-01 17:52:17 +01:00
|
|
|
|
2016-02-24 14:37:48 +01:00
|
|
|
// Handle temperature sensor
|
2016-02-24 15:31:51 +01:00
|
|
|
#ifdef TEMPERATURE_ENABLED
|
2016-02-24 14:37:48 +01:00
|
|
|
if(timerMultiplier == TEMPERATURE_TIMER_MULTIPLIER)
|
|
|
|
|
{
|
2016-02-24 15:31:51 +01:00
|
|
|
unsigned int temperature = tempSensor.getTemperature();
|
|
|
|
|
unsigned int humidity = tempSensor.getHumidity();
|
|
|
|
|
tempProtocol.setTemperature(temperature);
|
|
|
|
|
tempProtocol.setHumidity(humidity);
|
|
|
|
|
tempProtocol.send();
|
2016-02-24 14:37:48 +01:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Handle light sensor
|
2016-02-24 15:31:51 +01:00
|
|
|
#ifdef TEMPERATURE_ENABLED
|
2016-02-24 14:37:48 +01:00
|
|
|
if(timerMultiplier == LIGHT_TIMER_MULTIPLIER)
|
|
|
|
|
{
|
|
|
|
|
unsigned int lumen = lightSensor.getLuminosity();
|
|
|
|
|
lightProtocol.setLuminosity(lumen);
|
|
|
|
|
lightProtocol.send();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2016-02-01 17:52:17 +01:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|