-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSensorTask.h
140 lines (103 loc) · 4.36 KB
/
SensorTask.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* IIRR -- Intelligent Irrigator Based on ESP8266
Copyright (C) 2016--2018 Sergio Queiroz <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef _SENSOR_TASK_H_
#define _SENSOR_TASK_H_
#include "sensor_calibration.h"
#include <Scheduler.h>
#include "TimeKeeper.h"
#include "FS.h"
#include <ArduinoJson.h>
#include "ConfParams.h"
#include "WaterController.h"
#include "global_funcs.h"
#define MIN_IRRIG_TS 300
enum StopIrrigReason {
STOPIRRIG_SLOTEND,
STOPIRRIG_SURFACESAT,
STOPIRRIG_MIDDLESAT,
STOPIRRIG_DEEPINCREASE,
STOPIRRIG_MAXTIMEDAY,
STOPIRRIG_WATEREMPTY
};
enum MessageTypes {
MSG_DEBUG,
MSG_INFO,
MSG_WARN,
MSG_ERR
};
enum MessageCodes {
MSG_INCONSIST_WATER_CURRSTATUS, //this means that we were expecting a certain water
// current status, but another was found. First it
// is logged the status found and after the one expected
MSG_STOPPED_IRRIG, // this means that we stopped irrigating. It may be just informational.
MSG_STARTED_IRRIG
};
enum AsyncLearnFlowStatus {
LFLOW_NOTREQUESTED,
LFLOW_INPROGRESS,
LFLOW_DONE,
LFLOW_ERROR
};
class SensorTask : public Task {
private:
float readMoisture(SensorType sType);
// the loop function runs over and over again forever
void loopSensorMode();
void selectSensor(SensorInput sensor);
SensorDirection switchSensorDirection();
//bool isWithWater();
void enableSensorVoltage(SensorType sType, SensorDirection sDir);
int readReferenceVoltage(SensorType sType, SensorDirection sDir);
int readAfterSensorVoltage(SensorType sType, SensorDirection sDir);
int readVoltage(SensorType sType, SensorDirection sDirection, SensorInput sensorInput);
static void multiTaskDelay(SensorTask *taskServer, unsigned long ms);
File getCurrLogFile(time_t nowTime);
File getCurrMsgFile(time_t nowTime);
static File getFSFileWithDate(time_t nowTime, PGM_P fmtStr, const int bufSize);
static bool doFSMaintenance(int keepDays);
static bool doFSMaintenance(int keepDays, const String& dirName, const String& commonName);
ConfParams *readMainConfParams();
static time_t toConfTimet(time_t aTime_t);
static time_t confParamTime2Timet(const char* timeStr);
static bool isInNoIrrigTime(time_t aTime);
static bool isInHHMMConfInterval(time_t aTimeInConfTimet, time_t initHHMM, time_t endHHMM);
static unsigned int irrigTodayRemainingSecs();
bool fulfillMinIrrigInterval(time_t aTime);
TimeKeeper timeKeeper;
WellPumpWaterController waterControl;
inline static bool isValidMoisture(float percent) { return (percent >= 0) && (percent <= 100); }
bool stopIrrigationAndLog(time_t aTime, enum StopIrrigReason);
bool startIrrigationAndLog(time_t aTime, const SoilMoisture& moist);
static File getFSFileWithDateForRead(time_t aTime, PGM_P fmtStr, const int bufSize);
protected:
void loop();
public:
SensorTask();
static JsonObject& createJsonFromConfParams(DynamicJsonBuffer& jsonBuffer);
static void updateConfParamsFromJson(ConfParams& confStruct, JsonObject& jsonConfParamsRoot);
static bool updateConfParams(const ConfParams &newParams);
static void asyncLearnNormalFlow();
static AsyncLearnFlowStatus getLastLearnFlowStatus();
static void resetLearnFlowStatus();
static File getLogFileWithDate(time_t theDate);
static File getMsgFileWithDate(time_t theDate);
static bool isLogFileName(const String& str);
static bool isMsgFileName(const String& str);
static bool getLogfileDMY(const String& logStr, int& day, int& month, int&year);
static bool getMsgfileDMY(const String& msgStr, int& day, int& month, int&year);
static File getMsgFileWithDateForRead(time_t theDate);
static File getLogFileWithDateForRead(time_t theDate);
};
#endif