// define configuration settings that can be saved and loaded from the EEPROM
#define SAVE_SLEEP_MODE 0
#define SAVE_SLEEP_TIME 1
#define SAVE_SLEEP_UNIT 2
// define eeprom addresses
#define EEPROM_SLEEP_SAVED 0
#define EEPROM_SLEEP_MODE 1
#define EEPROM_SLEEP_TIME_MAJOR 2
#define EEPROM_SLEEP_TIME_MINOR 3
#define EEPROM_SLEEP_UNIT 4
#define EEPROM_SLEEP_1 5
#define EEPROM_SLEEP_2 6
#define EEPROM_SLEEP_3 7
#define EEPROM_USER_START 100
// define requests
...
...
@@ -410,39 +401,38 @@ class PowerManager {
classTimer{
public:
Timer(NodeManager*node_manager);
// start the timer which will be over when interval passes by. Unit can be either CYCLES or MINUTES
voidstart(longtarget,intunit);
// start the timer which will be over when the configured target passes by
voidstart(inttarget,intunit);
voidstart();
// stop the timer
voidstop();
// reset the timer
voidreset();
// reset the timer and start over
voidrestart();
// set the timer configuration but do not start it
voidset(longtarget,intunit);
voidset(inttarget,intunit);
voidunset();
// update the timer. To be called at every cycle
voidupdate();
// returns true if the time is over
// return true if the time is over
boolisOver();
// return true if the timer is running
boolisRunning();
// returns true if the timer has been configured
// return true if the timer has been configured
boolisConfigured();
// reset the timer and start over
voidrestart();
// return true if this is the first time the timer runs
boolisFirstRun();
// return the current elapsed time
floatgetElapsed();
// return the configured unit
intgetUnit();
// return the configured target
intgetTarget();
private:
NodeManager*_node_manager;
long_target=0;
int_unit=0;
float_elapsed=0;
bool_use_millis=false;
int_target=0;
long_elapsed=0;
long_last_millis=0;
float_sleep_time=0;
bool_is_running=false;
bool_is_configured=false;
bool_first_run=true;
};
/*
...
...
@@ -492,11 +482,10 @@ class Sensor {
voidsetSamplesInterval(intvalue);
// [7] if true will report the measure only if different than the previous one (default: false)
voidsetTrackLastValue(boolvalue);
// [8] if track last value is enabled, force to send an update after the configured number of cycles (default: -1)
voidsetForceUpdate(intvalue);
voidsetForceUpdateCycles(intvalue);
// [9] if track last value is enabled, force to send an update after the configured number of minutes (default: -1)
// [9] if track last value is enabled, force to send an update after the configured number of minutes
voidsetForceUpdateMinutes(intvalue);
// [19] if track last value is enabled, force to send an update after the configured number of hours
voidsetForceUpdateHours(intvalue);
// [10] the value type of this sensor (default: TYPE_INTEGER)
voidsetValueType(intvalue);
intgetValueType();
...
...
@@ -516,10 +505,12 @@ class Sensor {
intgetValueInt();
floatgetValueFloat();
char*getValueString();
// [15] After how many cycles the sensor will report back its measure (default: 1 cycle)
voidsetReportIntervalCycles(intvalue);
// [16] After how many minutes the sensor will report back its measure (default: 1 cycle)
// [16] After how many minutes the sensor will report back its measure (default: 10 minutes)
voidsetReportIntervalMinutes(intvalue);
// [17] After how many minutes the sensor will report back its measure (default: 10 minutes)
voidsetReportIntervalSeconds(intvalue);
// return true if the report interval has been already configured
boolisReportIntervalConfigured();
// process a remote request
voidprocess(Request&request);
// return the pin the interrupt is attached to
...
...
@@ -1338,8 +1329,6 @@ class NodeManager {
voidsetBatteryMin(floatvalue);
// [12] the expected vcc when the batter is fully charged, used to calculate the percentage (default: 3.3)
voidsetBatteryMax(floatvalue);
// [13] after how many sleeping cycles report the battery level to the controller. When reset the battery is always reported (default: -)
voidsetBatteryReportCycles(intvalue);
// [14] after how many minutes report the battery level to the controller. When reset the battery is always reported (default: 60)
voidsetBatteryReportMinutes(intvalue);
// [15] if true, the battery level will be evaluated by measuring the internal vcc without the need to connect any pin, if false the voltage divider methon will be used (default: true)
...
...
@@ -1353,18 +1342,15 @@ class NodeManager {
// [2] Send a battery level report to the controller
voidbatteryReport();
#endif
// [3] define the way the node should behave. It can be (0) IDLE (stay awake withtout executing each sensors' loop), (1) SLEEP (go to sleep for the configured interval), (2) WAIT (wait for the configured interval), (3) ALWAYS_ON (stay awake and execute each sensors' loop)
voidsetSleepMode(intvalue);
voidsetMode(intvalue);
intgetMode();
// [4] define for how long the board will sleep (default: 0)
voidsetSleepTime(intvalue);
intgetSleepTime();
// [5] define the unit of SLEEP_TIME. It can be SECONDS, MINUTES, HOURS or DAYS (default: MINUTES)
voidsetSleepUnit(intvalue);
intgetSleepUnit();
// configure the node's behavior, parameters are mode, time and unit
voidsetSleep(intvalue1,intvalue2,intvalue3);
// [3] set the duration (in seconds) of a sleep cycle
voidsetSleepSeconds(intvalue);
longgetSleepSeconds();
// [4] set the duration (in minutes) of a sleep cycle
voidsetSleepMinutes(intvalue);
// [5] set the duration (in hours) of a sleep cycle
voidsetSleepHours(intvalue);
// [29] set the duration (in days) of a sleep cycle
voidsetSleepDays(intvalue);
// [19] if enabled, when waking up from the interrupt, the board stops sleeping. Disable it when attaching e.g. a motion sensor (default: true)
voidsetSleepInterruptPin(intvalue);
// configure the interrupt pin and mode. Mode can be CHANGE, RISING, FALLING (default: MODE_NOT_DEFINED)
...
...
@@ -1431,6 +1417,11 @@ class NodeManager {
voidsetupInterrupts();
// return the pin from which the last interrupt came
intgetLastInterruptPin();
// set the default interval in minutes all the sensors will report their measures.
// If the same function is called on a specific sensor, this will not change the previously set value
// For sleeping sensors, the elapsed time can be evaluated only upon wake up (default: 10 minutes)