Fixed WDT timer code, still not dynamic
This commit is contained in:
parent
2ba3c42a5e
commit
20023c48e0
5 changed files with 69 additions and 30 deletions
|
|
@ -2,22 +2,17 @@
|
|||
A interrupt based sensor device that reads multiple sensors and transmits
|
||||
the data to a central location.
|
||||
*/
|
||||
#if (ARDUINO >= 100)
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#endif
|
||||
#include <Wire.h>
|
||||
|
||||
#include "HalInterfaces.h"
|
||||
#include "HalDefinitions.h"
|
||||
#include "HalConfiguration.h"
|
||||
#include "HalInterfaces.h"
|
||||
#include "HalInclude.h"
|
||||
#include "Interrupt.h"
|
||||
|
||||
|
||||
Interrupt* interrupt;
|
||||
|
||||
unsigned int timerMultiplierMAX;
|
||||
#define TIMER_MULTIPLIER_MAX \
|
||||
POWER_TIMER_MULTIPLIER * TEMPERATURE_TIMER_MULTIPLIER * LIGHT_TIMER_MULTIPLIER
|
||||
unsigned int timerMultiplier = 0;
|
||||
|
||||
// Sensors
|
||||
|
|
@ -36,12 +31,13 @@ void timerInterruptFunc();
|
|||
|
||||
void setup()
|
||||
{
|
||||
timerMultiplierMAX = POWER_TIMER_MULTIPLIER * TEMPERATURE_TIMER_MULTIPLIER * LIGHT_TIMER_MULTIPLIER; // Find a lowest common denominator
|
||||
Interrupt::setCallback(timerInterruptFunc);
|
||||
Interrupt::setupTimerInterrupt(60*1000); // one minute scheduled interrupt
|
||||
|
||||
#ifdef ENABLE_DEBUG
|
||||
Serial.begin(9600);
|
||||
#endif
|
||||
|
||||
// Setup Sensors and protocols
|
||||
#ifdef POWERCON_ENABLED
|
||||
DEBUG("Setup POWERCON_SENSOR");
|
||||
powerSensor = new POWERCON_SENSOR;
|
||||
powerSensor->setup();
|
||||
powerProtocol = new POWERCON_PROTOCOL;
|
||||
|
|
@ -49,6 +45,7 @@ void setup()
|
|||
#endif
|
||||
|
||||
#ifdef TEMPERATURE_ENABLED
|
||||
DEBUG("Setup TEMPERATURE_SENSOR");
|
||||
tempSensor = new TEMPERATURE_SENSOR;
|
||||
tempSensor->setup();
|
||||
tempProtocol = new TEMPERATURE_PROTOCOL;
|
||||
|
|
@ -56,28 +53,38 @@ void setup()
|
|||
#endif
|
||||
|
||||
#ifdef LIGHT_ENABLED
|
||||
DEBUG("Setup LIGHT_SENSOR");
|
||||
lightSensor = new LIGHT_SENSOR;
|
||||
lightSensor->setup();
|
||||
lightProtocol = new LIGHT_PROTOCOL;
|
||||
lightProtocol->setup();
|
||||
#endif
|
||||
|
||||
DEBUG("Setup INTERRUPT");
|
||||
Interrupt::setCallback(timerInterruptFunc);
|
||||
Interrupt::setupWatchDogInterrupt(TIMER_MILLISECOND); // one minute scheduled interrupt
|
||||
|
||||
DEBUG("Ready");
|
||||
}
|
||||
|
||||
|
||||
void timerInterruptFunc()
|
||||
{
|
||||
++timerMultiplier;
|
||||
if (timerMultiplier > timerMultiplierMAX)
|
||||
if (timerMultiplier > TIMER_MULTIPLIER_MAX)
|
||||
timerMultiplier = 1;
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
noInterrupts();
|
||||
|
||||
// Send power consumption
|
||||
#ifdef POWERCON_ENABLED
|
||||
if(timerMultiplier == POWER_TIMER_MULTIPLIER)
|
||||
{
|
||||
unsigned int consumption = powerSensor->getConsumption();
|
||||
DEBUGF("Read POWERCON_SENSOR= consumption:%d", consumption);
|
||||
powerSensor->reset();
|
||||
powerProtocol->setConsumption(consumption);
|
||||
powerProtocol->send();
|
||||
|
|
@ -90,6 +97,7 @@ void loop()
|
|||
{
|
||||
unsigned int temperature = tempSensor->getTemperature();
|
||||
unsigned int humidity = tempSensor->getHumidity();
|
||||
DEBUGF("Read TEMPERATURE_SENSOR= temperature:%d, humidity:%d", temperature, humidity);
|
||||
tempProtocol->setTemperature(temperature);
|
||||
tempProtocol->setHumidity(humidity);
|
||||
tempProtocol->send();
|
||||
|
|
@ -97,14 +105,20 @@ void loop()
|
|||
#endif
|
||||
|
||||
// Handle light sensor
|
||||
#ifdef TEMPERATURE_ENABLED
|
||||
#ifdef LIGHT_ENABLED
|
||||
if(timerMultiplier == LIGHT_TIMER_MULTIPLIER)
|
||||
{
|
||||
unsigned int lumen = lightSensor->getLuminosity();
|
||||
DEBUG("Read LIGHT_SENSOR= lumen:%d", lumen);
|
||||
lightProtocol->setLuminosity(lumen);
|
||||
lightProtocol->send();
|
||||
}
|
||||
#endif
|
||||
|
||||
interrupts();
|
||||
|
||||
DEBUG("Sleeping");
|
||||
Interrupt::sleep();
|
||||
DEBUG("Wakeup");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue