diff --git a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp index 439f45aa3..da91b98fa 100644 --- a/companion/src/firmwares/edgetx/yaml_generalsettings.cpp +++ b/companion/src/firmwares/edgetx/yaml_generalsettings.cpp @@ -182,6 +182,7 @@ Node convert::encode(const GeneralSettings& rhs) node["hapticMode"] = rhs.hapticMode; node["stickMode"] = rhs.stickMode; node["timezone"] = rhs.timezone; + node["timezoneMinutes"] = rhs.timezoneMinutes; node["adjustRTC"] = (int)rhs.adjustRTC; node["inactivityTimer"] = rhs.inactivityTimer; @@ -390,6 +391,7 @@ bool convert::decode(const Node& node, GeneralSettings& rhs) node["hapticMode"] >> rhs.hapticMode; node["stickMode"] >> rhs.stickMode; node["timezone"] >> rhs.timezone; + node["timezoneMinutes"] >> rhs.timezoneMinutes; node["adjustRTC"] >> rhs.adjustRTC; node["inactivityTimer"] >> rhs.inactivityTimer; diff --git a/companion/src/firmwares/generalsettings.h b/companion/src/firmwares/generalsettings.h index 0709a67ca..dfaf2a0da 100644 --- a/companion/src/firmwares/generalsettings.h +++ b/companion/src/firmwares/generalsettings.h @@ -212,6 +212,7 @@ class GeneralSettings { BeeperMode hapticMode; unsigned int stickMode; // TODO enum int timezone; + int timezoneMinutes; bool adjustRTC; bool optrexDisplay; unsigned int inactivityTimer; diff --git a/companion/src/generaledit/CMakeLists.txt b/companion/src/generaledit/CMakeLists.txt index a9bbd2ec7..6821321dc 100644 --- a/companion/src/generaledit/CMakeLists.txt +++ b/companion/src/generaledit/CMakeLists.txt @@ -1,4 +1,4 @@ -include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) set(generaledit_NAMES generaledit @@ -10,6 +10,7 @@ set(generaledit_SRCS hardware.cpp trainer.cpp generaloptions.cpp + timezoneedit.cpp ) set(generaledit_HDRS @@ -17,6 +18,7 @@ set(generaledit_HDRS hardware.h trainer.h generaloptions.h + timezoneedit.h ) set(generaledit_UIS diff --git a/companion/src/generaledit/generalsetup.cpp b/companion/src/generaledit/generalsetup.cpp index b2538343a..15ec5e444 100644 --- a/companion/src/generaledit/generalsetup.cpp +++ b/companion/src/generaledit/generalsetup.cpp @@ -150,7 +150,8 @@ ui(new Ui::GeneralSetup) } ui->gpsFormatCB->setCurrentIndex(generalSettings.gpsFormat); - ui->timezoneSB->setValue(generalSettings.timezone); + + ui->timezoneLE->setTime((generalSettings.timezone * 3600) + (generalSettings.timezoneMinutes/*quarter hours*/ * 15 * 60)); if (IS_HORUS_OR_TARANIS(firmware->getBoard())) { ui->adjustRTC->setChecked(generalSettings.adjustRTC); @@ -328,6 +329,16 @@ GeneralSetupPanel::~GeneralSetupPanel() delete ui; } +void GeneralSetupPanel::on_timezoneLE_textEdited(const QString &text) +{ + if (!lock) { + int secs = ui->timezoneLE->timeInSeconds(); + generalSettings.timezone = secs / 3600; + generalSettings.timezoneMinutes = (secs % 3600) / (15 * 60); // timezoneMinutes in quarter hours + emit modified(); + } +} + void GeneralSetupPanel::populateBacklightCB() { QComboBox * b = ui->backlightswCB; @@ -693,12 +704,6 @@ void GeneralSetupPanel::on_switchesDelay_valueChanged(int) emit modified(); } -void GeneralSetupPanel::on_timezoneSB_editingFinished() -{ - generalSettings.timezone = ui->timezoneSB->value(); - emit modified(); -} - void GeneralSetupPanel::on_adjustRTC_stateChanged(int) { generalSettings.adjustRTC = ui->adjustRTC->isChecked(); diff --git a/companion/src/generaledit/generalsetup.h b/companion/src/generaledit/generalsetup.h index 2c8366fd5..0e7354de4 100644 --- a/companion/src/generaledit/generalsetup.h +++ b/companion/src/generaledit/generalsetup.h @@ -50,7 +50,7 @@ class GeneralSetupPanel : public GeneralPanel void on_faimode_CB_stateChanged(int ); void on_rotEncMode_CB_currentIndexChanged(int index); void on_speakerPitchSB_editingFinished(); - void on_timezoneSB_editingFinished(); + void on_timezoneLE_textEdited(const QString &text); void on_adjustRTC_stateChanged(int); void on_hapticStrength_valueChanged(); void on_soundModeCB_currentIndexChanged(int index); diff --git a/companion/src/generaledit/generalsetup.ui b/companion/src/generaledit/generalsetup.ui index 1f096eb0e..9efd263b8 100644 --- a/companion/src/generaledit/generalsetup.ui +++ b/companion/src/generaledit/generalsetup.ui @@ -6,7 +6,7 @@ 0 0 - 810 + 858 880 @@ -927,17 +927,7 @@ - - - -14 - - - 12 - - - 0 - - + @@ -2501,6 +2491,13 @@ p, li { white-space: pre-wrap; } + + + TimezoneEdit + QLineEdit +
timezoneedit.h
+
+
diff --git a/companion/src/generaledit/timezoneedit.cpp b/companion/src/generaledit/timezoneedit.cpp new file mode 100644 index 000000000..8cb97876c --- /dev/null +++ b/companion/src/generaledit/timezoneedit.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + */ + +#include "timezoneedit.h" + +TimezoneEdit::TimezoneEdit(QWidget * parent) : + TimerEdit(parent) +{ + setShowSeconds(false); + setMinimumTime(-12 * 60 * 60); + setMaximumTime(14 * 60 * 60); + setSingleStep(15 * 60); + setPageStep(60 * 60); +} + +void TimezoneEdit::setupFormat() +{ + QString inputRe = "^(?-|\\+|\\s)?(?[0-9]*[0-9]):(?00|15|30|45)"; + m_validator->setRegularExpression(QRegularExpression(inputRe)); + + setInputMask("#99:99"); + setValidator(m_validator); +} diff --git a/companion/src/generaledit/timezoneedit.h b/companion/src/generaledit/timezoneedit.h new file mode 100644 index 000000000..9e327d56e --- /dev/null +++ b/companion/src/generaledit/timezoneedit.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) EdgeTX + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * 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. + */ + +#pragma once + +#include + +class TimezoneEdit : public TimerEdit +{ + Q_OBJECT + + public: + explicit TimezoneEdit(QWidget * parent = Q_NULLPTR); + virtual ~TimezoneEdit() {} + + protected: + void setupFormat() override; +}; diff --git a/companion/src/thirdparty/maxlibqt/src/widgets/TimerEdit.h b/companion/src/thirdparty/maxlibqt/src/widgets/TimerEdit.h index abacaa20a..b4536786b 100644 --- a/companion/src/thirdparty/maxlibqt/src/widgets/TimerEdit.h +++ b/companion/src/thirdparty/maxlibqt/src/widgets/TimerEdit.h @@ -86,7 +86,7 @@ class TimerEdit : public QLineEdit protected: void textEditedHandler(); - void setupFormat(); + virtual void setupFormat(); void emitValueChanged(); void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; void wheelEvent(QWheelEvent *event) Q_DECL_OVERRIDE; diff --git a/radio/src/datastructs_private.h b/radio/src/datastructs_private.h index 8d4009933..059b8bad2 100644 --- a/radio/src/datastructs_private.h +++ b/radio/src/datastructs_private.h @@ -855,7 +855,8 @@ PACK(struct RadioData { // Real attributes NOBACKUP(uint8_t manuallyEdited:1); - NOBACKUP(int8_t spare0:7 SKIP); + int8_t timezoneMinutes:3; // -3 to +3 ==> (-45 to 45 minutes in 15 minute increments) + NOBACKUP(int8_t spare0:4 SKIP); CUST_ATTR(semver,nullptr,w_semver); CUST_ATTR(board,nullptr,w_board); CalibData calib[MAX_CALIB_ANALOG_INPUTS] NO_IDX; diff --git a/radio/src/gui/128x64/radio_setup.cpp b/radio/src/gui/128x64/radio_setup.cpp index a78632b2a..b1dc5383d 100644 --- a/radio/src/gui/128x64/radio_setup.cpp +++ b/radio/src/gui/128x64/radio_setup.cpp @@ -599,9 +599,18 @@ void menuRadioSetup(event_t event) #if defined(GPS) case ITEM_RADIO_SETUP_TIMEZONE: - lcdDrawTextAlignedLeft(y, STR_TIMEZONE); - lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.timezone, attr|LEFT); - if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.timezone, -12, 12); + { + lcdDrawTextAlignedLeft(y, STR_TIMEZONE); + int tzIndex = timezoneIndex(g_eeGeneral.timezone, g_eeGeneral.timezoneMinutes); + lcdDrawText(RADIO_SETUP_2ND_COLUMN, y, timezoneDisplay(tzIndex).c_str(), attr); + if (attr) { + tzIndex = checkIncDec(event, tzIndex, minTimezone(), maxTimezone(), EE_GENERAL); + if (checkIncDec_Ret) { + g_eeGeneral.timezone = timezoneHour(tzIndex); + g_eeGeneral.timezoneMinutes = timezoneMinute(tzIndex); + } + } + } break; case ITEM_RADIO_SETUP_ADJUST_RTC: diff --git a/radio/src/gui/212x64/radio_setup.cpp b/radio/src/gui/212x64/radio_setup.cpp index 2ba2e9415..563c123a5 100644 --- a/radio/src/gui/212x64/radio_setup.cpp +++ b/radio/src/gui/212x64/radio_setup.cpp @@ -547,9 +547,18 @@ void menuRadioSetup(event_t event) break; case ITEM_RADIO_SETUP_TIMEZONE: - lcdDrawText(INDENT_WIDTH, y, STR_TIMEZONE); - lcdDrawNumber(RADIO_SETUP_2ND_COLUMN, y, g_eeGeneral.timezone, attr|LEFT); - if (attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.timezone, -12, 12); + { + lcdDrawText(INDENT_WIDTH, y, STR_TIMEZONE); + int tzIndex = timezoneIndex(g_eeGeneral.timezone, g_eeGeneral.timezoneMinutes); + lcdDrawText(RADIO_SETUP_2ND_COLUMN, y, timezoneDisplay(tzIndex).c_str(), attr); + if (attr) { + tzIndex = checkIncDec(event, tzIndex, minTimezone(), maxTimezone(), EE_GENERAL); + if (checkIncDec_Ret) { + g_eeGeneral.timezone = timezoneHour(tzIndex); + g_eeGeneral.timezoneMinutes = timezoneMinute(tzIndex); + } + } + } break; case ITEM_RADIO_SETUP_ADJUST_RTC: diff --git a/radio/src/gui/colorlcd/radio_setup.cpp b/radio/src/gui/colorlcd/radio_setup.cpp index 43d9412bf..a27c1cd6c 100644 --- a/radio/src/gui/colorlcd/radio_setup.cpp +++ b/radio/src/gui/colorlcd/radio_setup.cpp @@ -556,10 +556,22 @@ class GpsPage : public SubPage { { FlexGridLayout grid(col_two_dsc, row_dsc, 4); + tzIndex = timezoneIndex(g_eeGeneral.timezone, g_eeGeneral.timezoneMinutes); + auto line = body.newLine(&grid); // Timezone new StaticText(line, rect_t{}, STR_TIMEZONE, 0, COLOR_THEME_PRIMARY1); - new NumberEdit(line, rect_t{}, -12, 12, GET_SET_DEFAULT(g_eeGeneral.timezone)); + auto tz = new NumberEdit(line, rect_t{}, minTimezone(), maxTimezone(), + GET_DEFAULT(tzIndex), + [=](int newTz) { + tzIndex = newTz; + g_eeGeneral.timezone = timezoneHour(newTz); + g_eeGeneral.timezoneMinutes = timezoneMinute(newTz); + SET_DIRTY(); + }); + tz->setDisplayHandler([](int32_t tz) { + return timezoneDisplay(tz); + }); line = body.newLine(&grid); // Adjust RTC (from telemetry) @@ -572,6 +584,9 @@ class GpsPage : public SubPage { new Choice(line, rect_t{}, STR_GPSFORMAT, 0, 1, GET_SET_DEFAULT(g_eeGeneral.gpsFormat)); line = body.newLine(&grid); } + + protected: + int tzIndex; }; class ViewOptionsPage : public Page diff --git a/radio/src/rtc.cpp b/radio/src/rtc.cpp index 70b462abf..52f44518f 100644 --- a/radio/src/rtc.cpp +++ b/radio/src/rtc.cpp @@ -471,7 +471,7 @@ uint8_t rtcAdjust(uint16_t year, uint8_t mon, uint8_t day, uint8_t hour, uint8_t t.tm_hour = hour; t.tm_min = min; t.tm_sec = sec; - gtime_t newTime = gmktime(&t) + g_eeGeneral.timezone * 3600; + gtime_t newTime = gmktime(&t) + timezoneOffsetSeconds(g_eeGeneral.timezone, g_eeGeneral.timezoneMinutes); gtime_t diff = (g_rtcTime > newTime) ? (g_rtcTime - newTime) : (newTime - g_rtcTime); #if defined(DEBUG) && defined (PCBTARANIS) diff --git a/radio/src/storage/yaml/yaml_datastructs_128x64.cpp b/radio/src/storage/yaml/yaml_datastructs_128x64.cpp index b8664e5d6..c0615fbcd 100644 --- a/radio/src/storage/yaml/yaml_datastructs_128x64.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_128x64.cpp @@ -263,7 +263,8 @@ static const struct YamlNode struct_CustomFunctionData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "manuallyEdited", 1 ), - YAML_PADDING( 7 ), + YAML_SIGNED( "timezoneMinutes", 3 ), + YAML_PADDING( 4 ), YAML_CUSTOM("semver",nullptr,w_semver), YAML_CUSTOM("board",nullptr,w_board), YAML_ARRAY("calib", 48, 12, struct_CalibData, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp index ab509a595..b4501c50d 100644 --- a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp @@ -293,7 +293,8 @@ static const struct YamlNode struct_OpenTxTheme__PersistentData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "manuallyEdited", 1 ), - YAML_PADDING( 7 ), + YAML_SIGNED( "timezoneMinutes", 3 ), + YAML_PADDING( 4 ), YAML_CUSTOM("semver",nullptr,w_semver), YAML_CUSTOM("board",nullptr,w_board), YAML_ARRAY("calib", 48, 22, struct_CalibData, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_t20.cpp b/radio/src/storage/yaml/yaml_datastructs_t20.cpp index 7e8bace60..16a00f6c8 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t20.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t20.cpp @@ -263,7 +263,8 @@ static const struct YamlNode struct_CustomFunctionData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "manuallyEdited", 1 ), - YAML_PADDING( 7 ), + YAML_SIGNED( "timezoneMinutes", 3 ), + YAML_PADDING( 4 ), YAML_CUSTOM("semver",nullptr,w_semver), YAML_CUSTOM("board",nullptr,w_board), YAML_ARRAY("calib", 48, 12, struct_CalibData, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_tpro.cpp b/radio/src/storage/yaml/yaml_datastructs_tpro.cpp index ce8cfaeaa..71c44c206 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tpro.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tpro.cpp @@ -263,7 +263,8 @@ static const struct YamlNode struct_CustomFunctionData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "manuallyEdited", 1 ), - YAML_PADDING( 7 ), + YAML_SIGNED( "timezoneMinutes", 3 ), + YAML_PADDING( 4 ), YAML_CUSTOM("semver",nullptr,w_semver), YAML_CUSTOM("board",nullptr,w_board), YAML_ARRAY("calib", 48, 12, struct_CalibData, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/yaml/yaml_datastructs_x10.cpp index 2190b7a41..4a88a2660 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x10.cpp @@ -301,7 +301,8 @@ static const struct YamlNode struct_OpenTxTheme__PersistentData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "manuallyEdited", 1 ), - YAML_PADDING( 7 ), + YAML_SIGNED( "timezoneMinutes", 3 ), + YAML_PADDING( 4 ), YAML_CUSTOM("semver",nullptr,w_semver), YAML_CUSTOM("board",nullptr,w_board), YAML_ARRAY("calib", 48, 22, struct_CalibData, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp index 2190b7a41..4a88a2660 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp @@ -301,7 +301,8 @@ static const struct YamlNode struct_OpenTxTheme__PersistentData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "manuallyEdited", 1 ), - YAML_PADDING( 7 ), + YAML_SIGNED( "timezoneMinutes", 3 ), + YAML_PADDING( 4 ), YAML_CUSTOM("semver",nullptr,w_semver), YAML_CUSTOM("board",nullptr,w_board), YAML_ARRAY("calib", 48, 22, struct_CalibData, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp index 9efbaaa04..9886b668c 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp @@ -263,7 +263,8 @@ static const struct YamlNode struct_CustomFunctionData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "manuallyEdited", 1 ), - YAML_PADDING( 7 ), + YAML_SIGNED( "timezoneMinutes", 3 ), + YAML_PADDING( 4 ), YAML_CUSTOM("semver",nullptr,w_semver), YAML_CUSTOM("board",nullptr,w_board), YAML_ARRAY("calib", 48, 12, struct_CalibData, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp index 64195c02e..ea9585f69 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp @@ -263,7 +263,8 @@ static const struct YamlNode struct_CustomFunctionData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "manuallyEdited", 1 ), - YAML_PADDING( 7 ), + YAML_SIGNED( "timezoneMinutes", 3 ), + YAML_PADDING( 4 ), YAML_CUSTOM("semver",nullptr,w_semver), YAML_CUSTOM("board",nullptr,w_board), YAML_ARRAY("calib", 48, 12, struct_CalibData, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp index 70d97e4a8..84ff7d3f2 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp @@ -263,7 +263,8 @@ static const struct YamlNode struct_CustomFunctionData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "manuallyEdited", 1 ), - YAML_PADDING( 7 ), + YAML_SIGNED( "timezoneMinutes", 3 ), + YAML_PADDING( 4 ), YAML_CUSTOM("semver",nullptr,w_semver), YAML_CUSTOM("board",nullptr,w_board), YAML_ARRAY("calib", 48, 12, struct_CalibData, NULL), diff --git a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp index 6536946d1..f4b137df8 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp @@ -265,7 +265,8 @@ static const struct YamlNode struct_CustomFunctionData[] = { }; static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "manuallyEdited", 1 ), - YAML_PADDING( 7 ), + YAML_SIGNED( "timezoneMinutes", 3 ), + YAML_PADDING( 4 ), YAML_CUSTOM("semver",nullptr,w_semver), YAML_CUSTOM("board",nullptr,w_board), YAML_ARRAY("calib", 48, 12, struct_CalibData, NULL), diff --git a/radio/src/strhelpers.cpp b/radio/src/strhelpers.cpp index f909eab11..0f648cc9d 100644 --- a/radio/src/strhelpers.cpp +++ b/radio/src/strhelpers.cpp @@ -1045,3 +1045,47 @@ char *strAppendDate(char *str, bool time) #if !defined(BOOT) #endif + +// Manage timezones +// For backward compatibility timezone is stored as two separate values: +// timezone = hour value +// timezoneMinutes - minute value / 15 + +int8_t minTimezone() +{ + return -12 * 4; +} + +int8_t maxTimezone() +{ + return 14 * 4; +} + +std::string timezoneDisplay(int tz) +{ + char s[16]; + int h = abs(tz / 4); + int m = abs(tz % 4) * 15; + sprintf(s,"%s%d:%02d", (tz < 0) ? "-" : "", h, m); + return std::string(s); +} + +int timezoneIndex(int8_t tzHour, int8_t tzMinute) +{ + return (tzHour * 4) + tzMinute; +} + +int8_t timezoneHour(int tz) +{ + return tz / 4; +} + +int8_t timezoneMinute(int tz) +{ + return tz % 4; +} + +int timezoneOffsetSeconds(int8_t tzHour, int8_t tzMinute) +{ + return (tzHour * 3600) + (tzMinute * 15 * 60); +} diff --git a/radio/src/strhelpers.h b/radio/src/strhelpers.h index ca073e2f0..161da6e5d 100644 --- a/radio/src/strhelpers.h +++ b/radio/src/strhelpers.h @@ -174,4 +174,13 @@ int strncasecmp(char (&s1)[L1], const char *const s2) std::string getValueWithUnit(int val, uint8_t unit, LcdFlags flags); std::string getGVarValue(uint8_t gvar, gvar_t value, LcdFlags flags); +// Timezone handling +extern int8_t minTimezone(); +extern int8_t maxTimezone(); +extern std::string timezoneDisplay(int tz); +extern int timezoneIndex(int8_t tzHour, int8_t tzMinute); +extern int8_t timezoneHour(int tz); +extern int8_t timezoneMinute(int tz); +extern int timezoneOffsetSeconds(int8_t tzHour, int8_t tzMinute); + #endif // _STRHELPERS_H_ diff --git a/radio/src/telemetry/spektrum.cpp b/radio/src/telemetry/spektrum.cpp index ad7d6e083..fd95fc5a8 100644 --- a/radio/src/telemetry/spektrum.cpp +++ b/radio/src/telemetry/spektrum.cpp @@ -934,7 +934,7 @@ static void adjustTimeFromUTC(uint8_t hour, uint8_t min, uint8_t sec, struct gtm *tp) { // Get current UTC date/time - __offtime(&g_rtcTime, -g_eeGeneral.timezone * 3600, tp); + __offtime(&g_rtcTime, -timezoneOffsetSeconds(g_eeGeneral.timezone, g_eeGeneral.timezoneMinutes), tp); tp->tm_hour = hour; tp->tm_min = min;