@@ -35,8 +35,14 @@ | |||||
#pragma endregion | #pragma endregion | ||||
#define SLEEP_TIMING_TIME(hours, minutes) hours * 60 + minutes | |||||
#define SLEEP_TIMING_MIN SLEEP_TIMING_TIME(0, 0) | |||||
#define SLEEP_TIMING_MAX SLEEP_TIMING_TIME(23, 59) | |||||
struct sleepTimings_t { | struct sleepTimings_t { | ||||
uint8_t speed; | uint8_t speed; | ||||
uint16_t timeMin; | |||||
uint16_t timeMax; | |||||
uint16_t seconds; | uint16_t seconds; | ||||
}; | }; | ||||
@@ -53,25 +59,19 @@ struct config_t { | |||||
namespace config { | namespace config { | ||||
static const sleepTimings_t defaultSleepTimings[] PROGMEM = { | static const sleepTimings_t defaultSleepTimings[] PROGMEM = { | ||||
/*{ 5, SLEEP_DEFAULT_TIME_SECONDS }, | |||||
{ 10, 1200 }, | |||||
{ 20, 600 }, | |||||
{ 30, 540 }, | |||||
{ 50, 480 }, | |||||
{ 80, 240 }, | |||||
{ 100, 210 }, | |||||
{ 180, 180 }, | |||||
};*/ | |||||
{ 3, 1800 }, | |||||
{ 5, 900 }, | |||||
{ 10, 600 }, | |||||
{ 20, 600 }, | |||||
{ 30, 540 }, | |||||
{ 50, 480 }, | |||||
{ 80, 240 }, | |||||
{ 100, 210 }, | |||||
{ 180, 180 }, | |||||
{ 3, SLEEP_TIMING_TIME(16, 00), SLEEP_TIMING_TIME(8, 30), SLEEP_DEFAULT_TIME_SECONDS }, | |||||
{ 3, SLEEP_TIMING_MIN, SLEEP_TIMING_TIME(15, 59), 10800 }, | |||||
{ 3, SLEEP_TIMING_TIME(8, 29), SLEEP_TIMING_MAX, 10800 }, | |||||
{ 5, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 900 }, | |||||
{ 20, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 600 }, | |||||
{ 30, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 540 }, | |||||
{ 50, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 480 }, | |||||
{ 80, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 240 }, | |||||
{ 100, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 210 }, | |||||
{ 180, SLEEP_TIMING_MIN, SLEEP_TIMING_MAX, 180 }, | |||||
}; | }; | ||||
namespace main { | namespace main { | ||||
extern config_t value; | extern config_t value; | ||||
@@ -39,13 +39,22 @@ namespace core { | |||||
uint16_t computeSleepTime(uint8_t velocity) { | uint16_t computeSleepTime(uint8_t velocity) { | ||||
uint16_t result; | uint16_t result; | ||||
uint16_t currentTime = 0xFFFF; | |||||
if (rtc::isAccurate()) { | |||||
tmElements_t time; | |||||
rtc::getTime(time); | |||||
currentTime = SLEEP_TIMING_TIME(time.Hour, time.Minute); | |||||
} | |||||
for (uint8_t i = 0; i < flash::getArraySize(config::defaultSleepTimings); i++) { | for (uint8_t i = 0; i < flash::getArraySize(config::defaultSleepTimings); i++) { | ||||
sleepTimings_t timing; | sleepTimings_t timing; | ||||
flash::read(&config::defaultSleepTimings[i], timing); | flash::read(&config::defaultSleepTimings[i], timing); | ||||
if (velocity > timing.speed) continue; | if (velocity > timing.speed) continue; | ||||
if (currentTime != 0xFFFF && (currentTime < timing.timeMin || currentTime > timing.timeMax)) continue; | |||||
result = timing.seconds; | result = timing.seconds; | ||||
break; | break; | ||||
} | } | ||||
@@ -7,7 +7,7 @@ | |||||
#define MENU_ENTRY(name, text) const char MENU_##name[] PROGMEM = text | #define MENU_ENTRY(name, text) const char MENU_##name[] PROGMEM = text | ||||
const char FAKE_GPS_ENTRY[] PROGMEM = "1,1,20170924184842.000,49.454862,1.144537,71.900,67.99,172.6,1,,1.3,2.2,1.8,,11,7,,,37,,"; | |||||
const char FAKE_GPS_ENTRY[] PROGMEM = "1,1,20170924184842.000,49.454862,1.144537,71.900,2.70,172.6,1,,1.3,2.2,1.8,,11,7,,,37,,"; | |||||
MENU_ENTRY(HEADER, "========================\n-- Menu --"); | MENU_ENTRY(HEADER, "========================\n-- Menu --"); | ||||
MENU_ENTRY(SEPARATOR, "----"); | MENU_ENTRY(SEPARATOR, "----"); | ||||
@@ -4,7 +4,7 @@ | |||||
#if _DEBUG | #if _DEBUG | ||||
#define MENU_DEFAULT_TIMEOUT 0 | #define MENU_DEFAULT_TIMEOUT 0 | ||||
#else | #else | ||||
#define MENU_DEFAULT_TIMEOUT 5000 | |||||
#define MENU_DEFAULT_TIMEOUT 10000 | |||||
#endif | #endif | ||||
bool bypassMenu = false; | bool bypassMenu = false; | ||||
@@ -31,6 +31,14 @@ namespace rtc { | |||||
return temperature; | return temperature; | ||||
} | } | ||||
bool isAccurate() { | |||||
hardware::i2c::powerOn(); | |||||
bool accurate = RTC.status(DS3231_HALTED_FLAG) == DS3231_OFF; | |||||
hardware::i2c::powerOff(); | |||||
return accurate; | |||||
} | |||||
timestamp_t getTime() { | timestamp_t getTime() { | ||||
tmElements_t time; | tmElements_t time; | ||||
getTime(time); | getTime(time); | ||||
@@ -50,6 +58,7 @@ namespace rtc { | |||||
hardware::i2c::powerOn(); | hardware::i2c::powerOn(); | ||||
RTC.writeTime(time); | RTC.writeTime(time); | ||||
RTC.control(DS3231_HALTED_FLAG, DS3231_OFF); | |||||
hardware::i2c::powerOff(); | hardware::i2c::powerOff(); | ||||
} | } | ||||
@@ -7,6 +7,7 @@ namespace rtc { | |||||
float getTemperature(); | float getTemperature(); | ||||
bool isAccurate(); | |||||
timestamp_t getTime(); | timestamp_t getTime(); | ||||
void getTime(tmElements_t &time); | void getTime(tmElements_t &time); | ||||
void setTime(const tmElements_t &time); | void setTime(const tmElements_t &time); | ||||