Comments included and code sorted
This commit is contained in:
parent
b43e238293
commit
63708eeecc
@ -1,3 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* @file WakeReason.h
|
||||||
|
* @author your name (you@domain.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2020-11-28
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2020
|
||||||
|
*
|
||||||
|
*/
|
||||||
#ifndef WAKEUP_REASON_H
|
#ifndef WAKEUP_REASON_H
|
||||||
#define WAKEUP_REASON_H
|
#define WAKEUP_REASON_H
|
||||||
|
|
||||||
@ -11,8 +21,8 @@
|
|||||||
#define WAKEUP_REASON_MODE2_WAKEUP_TIMER 8
|
#define WAKEUP_REASON_MODE2_WAKEUP_TIMER 8
|
||||||
|
|
||||||
|
|
||||||
#define WAKEUP_REASON_MOIST_CHANGE 20 //20-26
|
#define WAKEUP_REASON_MOIST_CHANGE 20 /**< <code>20-26</code> for plant0 to plant9 */
|
||||||
#define WAKEUP_REASON_PLANT_DRY 30 //30-36
|
#define WAKEUP_REASON_PLANT_DRY 30 /**< <code>30-36</code> for plant0 to plant9 */
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -9,6 +9,10 @@
|
|||||||
*
|
*
|
||||||
* @copyright Copyright (c) 2020
|
* @copyright Copyright (c) 2020
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* INCLUDES
|
||||||
|
******************************************************************************/
|
||||||
#include "PlantCtrl.h"
|
#include "PlantCtrl.h"
|
||||||
#include "ControllerConfiguration.h"
|
#include "ControllerConfiguration.h"
|
||||||
#include "HomieConfiguration.h"
|
#include "HomieConfiguration.h"
|
||||||
@ -22,8 +26,9 @@
|
|||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <OneWire.h>
|
#include <OneWire.h>
|
||||||
|
|
||||||
const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minutes */
|
/******************************************************************************
|
||||||
|
* DEFINES
|
||||||
|
******************************************************************************/
|
||||||
#define AMOUNT_SENOR_QUERYS 8
|
#define AMOUNT_SENOR_QUERYS 8
|
||||||
#define SENSOR_QUERY_SHIFTS 3
|
#define SENSOR_QUERY_SHIFTS 3
|
||||||
#define SOLAR4SENSORS 6.0f
|
#define SOLAR4SENSORS 6.0f
|
||||||
@ -31,6 +36,9 @@ const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minut
|
|||||||
#define TEMP_MAX_VALUE 85.0f
|
#define TEMP_MAX_VALUE 85.0f
|
||||||
#define HalfHour 60
|
#define HalfHour 60
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* TYPE DEFS
|
||||||
|
******************************************************************************/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
long lastActive; /**< Timestamp, a pump was activated */
|
long lastActive; /**< Timestamp, a pump was activated */
|
||||||
@ -39,7 +47,17 @@ typedef struct
|
|||||||
|
|
||||||
} rtc_plant_t;
|
} rtc_plant_t;
|
||||||
|
|
||||||
/********************* non volatile enable after deepsleep *******************************/
|
/******************************************************************************
|
||||||
|
* FUNCTION PROTOTYPES
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
int determineNextPump();
|
||||||
|
void setLastActivationForPump(int pumpId, long time);
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* NON VOLATILE VARIABLES in DEEP SLEEP
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
RTC_DATA_ATTR rtc_plant_t rtcPlant[MAX_PLANTS];
|
RTC_DATA_ATTR rtc_plant_t rtcPlant[MAX_PLANTS];
|
||||||
RTC_DATA_ATTR long gotoMode2AfterThisTimestamp = 0;
|
RTC_DATA_ATTR long gotoMode2AfterThisTimestamp = 0;
|
||||||
RTC_DATA_ATTR long rtcDeepSleepTime = 0; /**< Time, when the microcontroller shall be up again */
|
RTC_DATA_ATTR long rtcDeepSleepTime = 0; /**< Time, when the microcontroller shall be up again */
|
||||||
@ -54,14 +72,18 @@ RTC_DATA_ATTR int gCurrentPlant = 0; /**< Value Range: 1 ... 7 (0: no plant need
|
|||||||
RTC_DATA_ATTR int rtcLipoTempIndex = -1;
|
RTC_DATA_ATTR int rtcLipoTempIndex = -1;
|
||||||
RTC_DATA_ATTR int rtcWaterTempIndex = -1;
|
RTC_DATA_ATTR int rtcWaterTempIndex = -1;
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* LOCAL VARIABLES
|
||||||
|
******************************************************************************/
|
||||||
|
const unsigned long TEMPREADCYCLE = 30000; /**< Check temperature all half minutes */
|
||||||
|
|
||||||
int wakeUpReason = WAKEUP_REASON_UNDEFINED;
|
int wakeUpReason = WAKEUP_REASON_UNDEFINED;
|
||||||
bool volatile mode3Active = false; /**< Controller must not sleep */
|
bool volatile mode3Active = false; /**< Controller must not sleep */
|
||||||
bool volatile mDeepsleep = false;
|
bool volatile mDeepsleep = false;
|
||||||
|
|
||||||
int plantSensor1 = 0;
|
|
||||||
|
|
||||||
int readCounter = 0;
|
int readCounter = 0;
|
||||||
bool mConfigured = false;
|
bool mConfigured = false;
|
||||||
|
long nextBlink = 0; /**< Time needed in main loop to support expected blink code */
|
||||||
|
|
||||||
RunningMedian lipoRawSensor = RunningMedian(5);
|
RunningMedian lipoRawSensor = RunningMedian(5);
|
||||||
RunningMedian solarRawSensor = RunningMedian(5);
|
RunningMedian solarRawSensor = RunningMedian(5);
|
||||||
@ -81,6 +103,10 @@ Plant mPlants[MAX_PLANTS] = {
|
|||||||
Plant(SENSOR_PLANT5, OUTPUT_PUMP5, 5, &plant5, &mSetting5),
|
Plant(SENSOR_PLANT5, OUTPUT_PUMP5, 5, &plant5, &mSetting5),
|
||||||
Plant(SENSOR_PLANT6, OUTPUT_PUMP6, 6, &plant6, &mSetting6)};
|
Plant(SENSOR_PLANT6, OUTPUT_PUMP6, 6, &plant6, &mSetting6)};
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* LOCAL FUNCTIONS
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
float getBatteryVoltage()
|
float getBatteryVoltage()
|
||||||
{
|
{
|
||||||
return ADC_5V_TO_3V3(lipoRawSensor.getAverage());
|
return ADC_5V_TO_3V3(lipoRawSensor.getAverage());
|
||||||
@ -148,6 +174,10 @@ long getDistance()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read Voltage
|
||||||
|
* Read the battery voltage and the current voltage, provided by the solar panel
|
||||||
|
*/
|
||||||
void readSystemSensors()
|
void readSystemSensors()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
@ -158,9 +188,6 @@ void readSystemSensors()
|
|||||||
Serial << "Lipo " << lipoRawSensor.getAverage() << " -> " << getBatteryVoltage() << endl;
|
Serial << "Lipo " << lipoRawSensor.getAverage() << " -> " << getBatteryVoltage() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int determineNextPump();
|
|
||||||
void setLastActivationForPump(int pumpId, long time);
|
|
||||||
|
|
||||||
long getCurrentTime()
|
long getCurrentTime()
|
||||||
{
|
{
|
||||||
struct timeval tv_now;
|
struct timeval tv_now;
|
||||||
@ -537,8 +564,6 @@ bool readSensors()
|
|||||||
return leaveMode1;
|
return leaveMode1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Homie.getMqttClient().disconnect();
|
|
||||||
|
|
||||||
void onHomieEvent(const HomieEvent &event)
|
void onHomieEvent(const HomieEvent &event)
|
||||||
{
|
{
|
||||||
switch (event.type)
|
switch (event.type)
|
||||||
@ -873,7 +898,6 @@ void setup()
|
|||||||
* @brief Cyclic call
|
* @brief Cyclic call
|
||||||
* Executs the Homie base functionallity or triggers sleeping, if requested.
|
* Executs the Homie base functionallity or triggers sleeping, if requested.
|
||||||
*/
|
*/
|
||||||
long nextBlink = 0;
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
if (!mDeepsleep || mode3Active)
|
if (!mDeepsleep || mode3Active)
|
||||||
|
Loading…
Reference in New Issue
Block a user