* Code refactoring for GPS to RTC clock

* Enabled GPS adjust RTC option for Horus
* Moved sensor ID to the right to allow display of GPS date/time in Telemetry screen
This commit is contained in:
Damjan Adamic
2016-09-02 20:47:56 +02:00
parent 07c4563764
commit d8a00c3f3d
9 changed files with 77 additions and 53 deletions
+2 -21
View File
@@ -76,22 +76,12 @@ void TelemetryItem::setValue(const TelemetrySensor & sensor, int32_t val, uint32
else if (unit == UNIT_DATETIME) {
uint32_t data = uint32_t(newVal);
if (data & 0x000000ff) {
datetime.year = (uint16_t) ((data & 0xff000000) >> 24);
datetime.year = (uint16_t) ((data & 0xff000000) >> 24) + 2000;
datetime.month = (uint8_t) ((data & 0x00ff0000) >> 16);
datetime.day = (uint8_t) ((data & 0x0000ff00) >> 8);
if (datetime.year != 0) {
datetime.datestate = 1;
}
#if defined(RTCLOCK)
if (g_eeGeneral.adjustRTC && (datetime.datestate == 1)) {
struct gtm t;
gettime(&t);
t.tm_year = datetime.year+4;
t.tm_mon = datetime.month-1;
t.tm_mday = datetime.day;
rtcSetTime(&t);
}
#endif
}
else {
datetime.hour = ((uint8_t) ((data & 0xff000000) >> 24) + g_eeGeneral.timezone + 24) % 24;
@@ -102,16 +92,7 @@ void TelemetryItem::setValue(const TelemetrySensor & sensor, int32_t val, uint32
}
#if defined(RTCLOCK)
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) {
// we adjust RTC only if difference is > 20 seconds
t.tm_hour = datetime.hour;
t.tm_min = datetime.min;
t.tm_sec = datetime.sec;
g_rtcTime = gmktime(&t); // update local timestamp and get wday calculated
rtcSetTime(&t);
}
rtcAdjust(datetime.year, datetime.month, datetime.day, datetime.hour, datetime.min, datetime.sec);
}
#endif
}