1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-26 01:35:16 +03:00

Fix date adjustment, avoid setting time/date before GPS reception is good (GPS sends 0:0:0 0-0-0). Doesn't handle disconnection/reconnection of GPS module while radio is on, datetime.datestate and datetime.timestate should be reset when sensor is considered old

This commit is contained in:
Andre Bernet 2015-03-21 11:12:19 +04:00
parent c44a355573
commit 4318d04707

View file

@ -52,12 +52,14 @@ void TelemetryItem::setValue(const TelemetrySensor & sensor, int32_t newVal, uin
datetime.year = (uint16_t) ((data & 0xff000000) >> 24);
datetime.month = (uint8_t) ((data & 0x00ff0000) >> 16);
datetime.day = (uint8_t) ((data & 0x0000ff00) >> 8);
datetime.datestate = 1;
if (g_eeGeneral.adjustRTC) {
if (datetime.year != 0) {
datetime.datestate = 1;
}
if (g_eeGeneral.adjustRTC && (datetime.datestate == 1)) {
struct gtm t;
gettime(&t);
t.tm_year = datetime.year-1900;
t.tm_mon = datetime.month;
t.tm_year = datetime.year+4;
t.tm_mon = datetime.month-1;
t.tm_mday = datetime.day;
rtcSetTime(&t);
}
@ -66,8 +68,10 @@ void TelemetryItem::setValue(const TelemetrySensor & sensor, int32_t newVal, uin
datetime.hour = ((uint8_t) ((data & 0xff000000) >> 24) + g_eeGeneral.timezone + 24) % 24;
datetime.min = (uint8_t) ((data & 0x00ff0000) >> 16);
datetime.sec = (uint16_t) ((data & 0x0000ff00) >> 8);
datetime.timestate = 1;
if (g_eeGeneral.adjustRTC) {
if (datetime.datestate == 1) {
datetime.timestate = 1;
}
if (g_eeGeneral.adjustRTC && (datetime.datestate == 1)) {
struct gtm t;
gettime(&t);
if (abs((t.tm_hour-datetime.hour)*3600 + (t.tm_min-datetime.min)*60 + (t.tm_sec-datetime.sec)) > 20) {