2018-12-19 08:39:07 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the "bluetoothheater" distribution
|
|
|
|
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Ray Jones <ray@mrjones.id.au>
|
|
|
|
*
|
|
|
|
* 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 __BTC_TIMERS_H__
|
|
|
|
#define __BTC_TIMERS_H__
|
|
|
|
|
2019-05-16 11:12:29 +00:00
|
|
|
#include "../Utility/NVCore.h"
|
2019-06-15 23:09:29 +00:00
|
|
|
#include "../Utility/macros.h"
|
2019-05-16 11:12:29 +00:00
|
|
|
|
|
|
|
|
2019-03-03 08:48:52 +00:00
|
|
|
struct sHourMin {
|
|
|
|
int8_t hour;
|
|
|
|
int8_t min;
|
|
|
|
sHourMin() {
|
|
|
|
hour = 0;
|
|
|
|
min = 0;
|
|
|
|
}
|
|
|
|
sHourMin& operator=(const sHourMin& rhs) {
|
|
|
|
hour = rhs.hour;
|
|
|
|
min = rhs.min;
|
|
|
|
}
|
|
|
|
bool operator!=(const sHourMin& rhs) {
|
|
|
|
return (hour != rhs.hour) || (min != rhs.min);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-16 11:12:29 +00:00
|
|
|
struct sTimer : public CESP32_NVStorage {
|
2019-03-03 08:48:52 +00:00
|
|
|
sHourMin start; // start time
|
|
|
|
sHourMin stop; // stop time
|
|
|
|
uint8_t enabled; // timer enabled - each bit is a day of week flag
|
|
|
|
uint8_t repeat; // repeating timer
|
|
|
|
uint8_t temperature;
|
|
|
|
uint8_t timerID; // numeric ID
|
|
|
|
sTimer() {
|
|
|
|
enabled = 0;
|
|
|
|
repeat = false;
|
|
|
|
temperature = 22;
|
|
|
|
timerID = 0;
|
|
|
|
}
|
|
|
|
sTimer& operator=(const sTimer& rhs) {
|
|
|
|
start = rhs.start;
|
|
|
|
stop = rhs.stop;
|
|
|
|
enabled = rhs.enabled;
|
|
|
|
repeat = rhs.repeat;
|
|
|
|
temperature = rhs.temperature;
|
|
|
|
timerID = rhs.timerID;
|
|
|
|
}
|
2019-06-16 10:37:25 +00:00
|
|
|
void init(int idx) {
|
2019-03-03 08:48:52 +00:00
|
|
|
start.hour = 0;
|
|
|
|
start.min = 0;
|
|
|
|
stop.hour = 0;
|
|
|
|
stop.min = 0;
|
|
|
|
enabled = 0;
|
|
|
|
repeat = 0;
|
|
|
|
temperature = 22;
|
2019-06-16 10:37:25 +00:00
|
|
|
timerID = idx;
|
2019-03-03 08:48:52 +00:00
|
|
|
}
|
|
|
|
bool valid() {
|
|
|
|
bool retval = true;
|
2019-06-15 23:09:29 +00:00
|
|
|
retval &= INBOUNDS(start.hour, 0, 23);
|
|
|
|
retval &= INBOUNDS(start.min, 0, 59);
|
|
|
|
retval &= INBOUNDS(stop.hour, 0, 23);
|
|
|
|
retval &= INBOUNDS(stop.min, 0, 59);
|
2019-03-03 08:48:52 +00:00
|
|
|
retval &= repeat <= 2;
|
2019-06-15 23:09:29 +00:00
|
|
|
retval &= INBOUNDS(temperature, 8, 35);
|
2019-03-03 08:48:52 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2019-05-16 11:12:29 +00:00
|
|
|
void load();
|
|
|
|
void save();
|
2019-03-03 08:48:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const char* getTimerJSONStr(int timer, int param);
|
2019-03-14 10:52:59 +00:00
|
|
|
void decodeJSONTimerDays(const char* str);
|
|
|
|
void decodeJSONTimerTime(int stop, const char*);
|
|
|
|
void decodeJSONTimerNumeric(int repeat, const char*);
|
2018-12-19 08:39:07 +00:00
|
|
|
|
|
|
|
#endif
|