Implemented NTP
This commit is contained in:
Submodule components/TFT_eSPI updated: b6f9d19349...5b450e3992
Submodule components/arduino-esp32 updated: a84e0538ff...8e447f5cd5
Submodule components/cpputils updated: faeacdcfbf...b60122ff4a
Submodule components/espcpputils updated: 1ef4a9ea56...a6ed293eab
Submodule components/esphttpdutils updated: a78711317b...4ebd651a70
Submodule components/espwifistack updated: 717d877a44...9d134d9f6c
@ -79,4 +79,5 @@ add_definitions(
|
|||||||
-DPINS_LEDBACKLIGHT=23
|
-DPINS_LEDBACKLIGHT=23
|
||||||
-DLEDBACKLIGHT_INVERTED
|
-DLEDBACKLIGHT_INVERTED
|
||||||
-DFEATURE_GARAGE
|
-DFEATURE_GARAGE
|
||||||
|
-DFEATURE_NTP
|
||||||
)
|
)
|
||||||
|
@ -35,6 +35,7 @@ set(headers
|
|||||||
bmsutils.h
|
bmsutils.h
|
||||||
changevaluedisplay_bluetoothmode.h
|
changevaluedisplay_bluetoothmode.h
|
||||||
changevaluedisplay_bool.h
|
changevaluedisplay_bool.h
|
||||||
|
changevaluedisplay_sntp_sync_mode_t.h
|
||||||
changevaluedisplay_daylightsavingmode.h
|
changevaluedisplay_daylightsavingmode.h
|
||||||
changevaluedisplay_larsmmode_mode.h
|
changevaluedisplay_larsmmode_mode.h
|
||||||
changevaluedisplay_unifiedmodelmode.h
|
changevaluedisplay_unifiedmodelmode.h
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// local includes
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "accessorinterface.h"
|
#include "accessorinterface.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@ -47,8 +48,21 @@ struct CloudEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRe
|
|||||||
struct CloudTransmitTimeoutAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.cloudSettings.cloudTransmitTimeout; } };
|
struct CloudTransmitTimeoutAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.cloudSettings.cloudTransmitTimeout; } };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct TimezoneOffsetAccessor : public RefAccessorSaveSettings<int16_t> { int16_t &getRef() const override { return settings.timeSettings.timezoneOffset; } };
|
struct TimezoneOffsetAccessor : public virtual AccessorInterface<int32_t>
|
||||||
|
{
|
||||||
|
int32_t getValue() const override { return settings.timeSettings.timezoneOffset.count(); }
|
||||||
|
void setValue(int32_t value) override { settings.timeSettings.timezoneOffset = espchrono::minutes32{value}; saveSettings(); }
|
||||||
|
};
|
||||||
struct DaylightSavingModeAccessor : public RefAccessorSaveSettings<espchrono::DayLightSavingMode> { espchrono::DayLightSavingMode &getRef() const override { return settings.timeSettings.daylightSavingMode; } };
|
struct DaylightSavingModeAccessor : public RefAccessorSaveSettings<espchrono::DayLightSavingMode> { espchrono::DayLightSavingMode &getRef() const override { return settings.timeSettings.daylightSavingMode; } };
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
struct TimeServerEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.timeSettings.timeServerEnabled; } };
|
||||||
|
struct TimeSyncModeAccessor : public RefAccessorSaveSettings<sntp_sync_mode_t> { sntp_sync_mode_t &getRef() const override { return settings.timeSettings.timeSyncMode; } };
|
||||||
|
struct TimeSyncIntervalAccessor : public virtual AccessorInterface<int32_t>
|
||||||
|
{
|
||||||
|
int32_t getValue() const override { return settings.timeSettings.timeSyncInterval.count(); }
|
||||||
|
void setValue(int32_t value) override { settings.timeSettings.timeSyncInterval = espchrono::milliseconds32{value}; saveSettings(); }
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
struct FrontLeftEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.enableFrontLeft; } };
|
struct FrontLeftEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.enableFrontLeft; } };
|
||||||
struct FrontRightEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.enableFrontRight; } };
|
struct FrontRightEnabledAccessor : public RefAccessorSaveSettings<bool> { bool &getRef() const override { return settings.controllerHardware.enableFrontRight; } };
|
||||||
|
@ -155,6 +155,9 @@ void ChangeValueDisplay<Tvalue>::confirm()
|
|||||||
#ifdef FEATURE_BLUETOOTH
|
#ifdef FEATURE_BLUETOOTH
|
||||||
#include "changevaluedisplay_bluetoothmode.h"
|
#include "changevaluedisplay_bluetoothmode.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
#include "changevaluedisplay_sntp_sync_mode_t.h"
|
||||||
|
#endif
|
||||||
#include "changevaluedisplay_controlmode.h"
|
#include "changevaluedisplay_controlmode.h"
|
||||||
#include "changevaluedisplay_controltype.h"
|
#include "changevaluedisplay_controltype.h"
|
||||||
#include "changevaluedisplay_daylightsavingmode.h"
|
#include "changevaluedisplay_daylightsavingmode.h"
|
||||||
|
50
main/changevaluedisplay_sntp_sync_mode_t.h
Normal file
50
main/changevaluedisplay_sntp_sync_mode_t.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// esp-idf includes
|
||||||
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
|
#include "changevaluedisplay.h"
|
||||||
|
#include "menudisplay.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "actions/setvalueaction.h"
|
||||||
|
#include "actions/backproxyaction.h"
|
||||||
|
#include "icons/back.h"
|
||||||
|
#include "texts.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
template<>
|
||||||
|
class ChangeValueDisplay<sntp_sync_mode_t> :
|
||||||
|
public MenuDisplay,
|
||||||
|
public virtual AccessorInterface<sntp_sync_mode_t>,
|
||||||
|
public virtual ActionInterface
|
||||||
|
{
|
||||||
|
using Base = MenuDisplay;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ChangeValueDisplay();
|
||||||
|
|
||||||
|
void start() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
ChangeValueDisplay<sntp_sync_mode_t>::ChangeValueDisplay()
|
||||||
|
{
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<sntp_sync_mode_t>, StaticText<TEXT_IMMED>>>(SNTP_SYNC_MODE_IMMED, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, SetValueAction<sntp_sync_mode_t>, StaticText<TEXT_SMOOTH>>>(SNTP_SYNC_MODE_SMOOTH, *this, *this);
|
||||||
|
constructMenuItem<makeComponentArgs<MenuItem, BackProxyAction, StaticText<TEXT_BACK>, StaticMenuItemIcon<&icons::back>>>(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChangeValueDisplay<sntp_sync_mode_t>::start()
|
||||||
|
{
|
||||||
|
Base::start();
|
||||||
|
|
||||||
|
switch (const auto value = getValue())
|
||||||
|
{
|
||||||
|
case SNTP_SYNC_MODE_IMMED: setSelectedIndex(0); break;
|
||||||
|
case SNTP_SYNC_MODE_SMOOTH: setSelectedIndex(1); break;
|
||||||
|
default:
|
||||||
|
ESP_LOGW("BOBBY", "Unknown sntp_sync_mode_t: %i", int(value));
|
||||||
|
setSelectedIndex(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,10 +7,13 @@
|
|||||||
// local includes
|
// local includes
|
||||||
#include "menudisplay.h"
|
#include "menudisplay.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "actions/toggleboolaction.h"
|
||||||
#include "actions/switchscreenaction.h"
|
#include "actions/switchscreenaction.h"
|
||||||
|
#include "checkboxicon.h"
|
||||||
#include "icons/back.h"
|
#include "icons/back.h"
|
||||||
#include "texts.h"
|
#include "texts.h"
|
||||||
#include "accessors/settingsaccessors.h"
|
#include "accessors/settingsaccessors.h"
|
||||||
|
#include "espstrutils.h"
|
||||||
|
|
||||||
// forward declares
|
// forward declares
|
||||||
namespace {
|
namespace {
|
||||||
@ -19,20 +22,14 @@ class TimeSettingsMenu;
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class CurrentUtcDateTime : public virtual TextInterface
|
class CurrentUtcDateTimeText : public virtual TextInterface { public:
|
||||||
{
|
std::string text() const override { return fmt::format("utc: {}", espchrono::toString(espchrono::toDateTime(espchrono::utc_clock::now()))); }};
|
||||||
public:
|
|
||||||
std::string text() const override { return fmt::format("utc: {}", espchrono::toString(espchrono::toDateTime(espchrono::utc_clock::now()))); }
|
|
||||||
};
|
|
||||||
|
|
||||||
class CurrentLocalDateTime : public virtual TextInterface
|
class CurrentLocalDateTimeText : public virtual TextInterface { public:
|
||||||
{
|
std::string text() const override { return fmt::format("local: {}", espchrono::toString(espchrono::toDateTime(espchrono::local_clock::now()))); }};
|
||||||
public:
|
|
||||||
std::string text() const override { return fmt::format("local: {}", espchrono::toString(espchrono::toDateTime(espchrono::local_clock::now()))); }
|
|
||||||
};
|
|
||||||
|
|
||||||
using TimezoneOffsetChangeDisplay = makeComponent<
|
using TimezoneOffsetChangeDisplay = makeComponent<
|
||||||
ChangeValueDisplay<int16_t>,
|
ChangeValueDisplay<int32_t>,
|
||||||
StaticText<TEXT_OFFSET>,
|
StaticText<TEXT_OFFSET>,
|
||||||
TimezoneOffsetAccessor,
|
TimezoneOffsetAccessor,
|
||||||
BackActionInterface<SwitchScreenAction<TimeSettingsMenu>>,
|
BackActionInterface<SwitchScreenAction<TimeSettingsMenu>>,
|
||||||
@ -47,6 +44,27 @@ using DaylightSavingModeChangeDisplay = makeComponent<
|
|||||||
SwitchScreenAction<TimeSettingsMenu>
|
SwitchScreenAction<TimeSettingsMenu>
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
using TimeSyncModeChangeDisplay = makeComponent<
|
||||||
|
ChangeValueDisplay<sntp_sync_mode_t>,
|
||||||
|
StaticText<TEXT_NTPMODE>,
|
||||||
|
TimeSyncModeAccessor,
|
||||||
|
BackActionInterface<SwitchScreenAction<TimeSettingsMenu>>,
|
||||||
|
SwitchScreenAction<TimeSettingsMenu>
|
||||||
|
>;
|
||||||
|
|
||||||
|
using TimeSyncIntervalChangeDisplay = makeComponent<
|
||||||
|
ChangeValueDisplay<int32_t>,
|
||||||
|
StaticText<TEXT_NTPINTERVAL>,
|
||||||
|
TimeSyncIntervalAccessor,
|
||||||
|
BackActionInterface<SwitchScreenAction<TimeSettingsMenu>>,
|
||||||
|
SwitchScreenAction<TimeSettingsMenu>
|
||||||
|
>;
|
||||||
|
|
||||||
|
class NtpSyncStatusText : public virtual TextInterface { public:
|
||||||
|
std::string text() const override { return fmt::format("Status: {}", espcpputils::toString(sntp_get_sync_status())); }};
|
||||||
|
#endif
|
||||||
|
|
||||||
class TimeSettingsMenu :
|
class TimeSettingsMenu :
|
||||||
public MenuDisplay,
|
public MenuDisplay,
|
||||||
public StaticText<TEXT_TIME>,
|
public StaticText<TEXT_TIME>,
|
||||||
@ -55,10 +73,17 @@ class TimeSettingsMenu :
|
|||||||
public:
|
public:
|
||||||
TimeSettingsMenu()
|
TimeSettingsMenu()
|
||||||
{
|
{
|
||||||
constructMenuItem<makeComponent<MenuItem, CurrentUtcDateTime, StaticFont<2>, DummyAction>>();
|
constructMenuItem<makeComponent<MenuItem, CurrentUtcDateTimeText, StaticFont<2>, DummyAction>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, CurrentLocalDateTime, StaticFont<2>, DummyAction>>();
|
constructMenuItem<makeComponent<MenuItem, CurrentLocalDateTimeText, StaticFont<2>, DummyAction>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_OFFSET>, SwitchScreenAction<TimezoneOffsetChangeDisplay>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_OFFSET>, SwitchScreenAction<TimezoneOffsetChangeDisplay>>>();
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DAYLIGHTSAVINGMODE>, SwitchScreenAction<DaylightSavingModeChangeDisplay>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_DAYLIGHTSAVINGMODE>, SwitchScreenAction<DaylightSavingModeChangeDisplay>>>();
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_NTPENABLED>, ToggleBoolAction, CheckboxIcon, TimeServerEnabledAccessor>>();
|
||||||
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_NTPSERVER>, DummyAction>>();
|
||||||
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_NTPMODE>, SwitchScreenAction<TimeSyncModeChangeDisplay>>>();
|
||||||
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_NTPINTERVAL>, SwitchScreenAction<TimeSyncIntervalChangeDisplay>>>();
|
||||||
|
constructMenuItem<makeComponent<MenuItem, NtpSyncStatusText, DummyAction>>();
|
||||||
|
#endif
|
||||||
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<SettingsMenu>, StaticMenuItemIcon<&icons::back>>>();
|
constructMenuItem<makeComponent<MenuItem, StaticText<TEXT_BACK>, SwitchScreenAction<SettingsMenu>, StaticMenuItemIcon<&icons::back>>>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// Arduino includes
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
#include <espchrono.h>
|
#include <espchrono.h>
|
||||||
|
#include <tickchrono.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
#include "dpad.h"
|
#include "dpad.h"
|
||||||
#include "buttons.h"
|
#include "buttons.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
@ -38,7 +42,7 @@ dpad::State Helper<OUT, IN1, IN2>::read()
|
|||||||
pinMode(IN1, INPUT_PULLUP);
|
pinMode(IN1, INPUT_PULLUP);
|
||||||
pinMode(IN2, INPUT_PULLUP);
|
pinMode(IN2, INPUT_PULLUP);
|
||||||
|
|
||||||
delay(1);
|
vPortYield();
|
||||||
|
|
||||||
const bool result0 = digitalRead(IN1)==LOW;
|
const bool result0 = digitalRead(IN1)==LOW;
|
||||||
const bool result1 = digitalRead(IN2)==LOW;
|
const bool result1 = digitalRead(IN2)==LOW;
|
||||||
@ -48,7 +52,7 @@ dpad::State Helper<OUT, IN1, IN2>::read()
|
|||||||
pinMode(IN1, INPUT_PULLDOWN);
|
pinMode(IN1, INPUT_PULLDOWN);
|
||||||
pinMode(IN2, INPUT_PULLDOWN);
|
pinMode(IN2, INPUT_PULLDOWN);
|
||||||
|
|
||||||
delay(1);
|
vPortYield();
|
||||||
|
|
||||||
const bool result2 = digitalRead(IN1);
|
const bool result2 = digitalRead(IN1);
|
||||||
const bool result3 = digitalRead(IN2);
|
const bool result3 = digitalRead(IN2);
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// system includes
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
// Arduino includes
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
#include <espchrono.h>
|
#include <espchrono.h>
|
||||||
|
#include <tickchrono.h>
|
||||||
|
|
||||||
|
// local includes
|
||||||
#include "buttons.h"
|
#include "buttons.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
@ -73,7 +78,7 @@ State Helper<OUT, IN1, IN2, IN3, IN4>::read()
|
|||||||
pinMode(IN3, INPUT_PULLUP);
|
pinMode(IN3, INPUT_PULLUP);
|
||||||
pinMode(IN4, INPUT_PULLUP);
|
pinMode(IN4, INPUT_PULLUP);
|
||||||
|
|
||||||
delay(1);
|
vPortYield();
|
||||||
|
|
||||||
result[0] = digitalRead(IN1)==LOW;
|
result[0] = digitalRead(IN1)==LOW;
|
||||||
result[1] = digitalRead(IN2)==LOW;
|
result[1] = digitalRead(IN2)==LOW;
|
||||||
@ -87,7 +92,7 @@ State Helper<OUT, IN1, IN2, IN3, IN4>::read()
|
|||||||
pinMode(IN3, INPUT_PULLDOWN);
|
pinMode(IN3, INPUT_PULLDOWN);
|
||||||
pinMode(IN4, INPUT_PULLDOWN);
|
pinMode(IN4, INPUT_PULLDOWN);
|
||||||
|
|
||||||
delay(1);
|
vPortYield();
|
||||||
|
|
||||||
result[4] = digitalRead(IN1);
|
result[4] = digitalRead(IN1);
|
||||||
result[5] = digitalRead(IN2);
|
result[5] = digitalRead(IN2);
|
||||||
|
@ -151,6 +151,9 @@ std::optional<espchrono::millis_clock::time_point> lastBleUpdate;
|
|||||||
#ifdef FEATURE_CLOUD
|
#ifdef FEATURE_CLOUD
|
||||||
std::optional<espchrono::millis_clock::time_point> lastCloudUpdate;
|
std::optional<espchrono::millis_clock::time_point> lastCloudUpdate;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
std::optional<espchrono::millis_clock::time_point> lastNtpUpdate;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void app_main()
|
extern "C" void app_main()
|
||||||
@ -297,6 +300,11 @@ extern "C" void app_main()
|
|||||||
initCloud();
|
initCloud();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
bootLabel.redraw("time");
|
||||||
|
initTime();
|
||||||
|
#endif
|
||||||
|
|
||||||
bootLabel.redraw("switchScreen");
|
bootLabel.redraw("switchScreen");
|
||||||
|
|
||||||
#if defined(FEATURE_DPAD_5WIRESW) && defined(DPAD_5WIRESW_DEBUG)
|
#if defined(FEATURE_DPAD_5WIRESW) && defined(DPAD_5WIRESW_DEBUG)
|
||||||
@ -427,6 +435,15 @@ extern "C" void app_main()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
if (!lastNtpUpdate || now - *lastNtpUpdate >= 100ms)
|
||||||
|
{
|
||||||
|
updateTime();
|
||||||
|
|
||||||
|
lastNtpUpdate = now;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef FEATURE_WEBSERVER
|
#ifdef FEATURE_WEBSERVER
|
||||||
handleWebserver();
|
handleWebserver();
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// esp-idf includes
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
#include <lwip/apps/snmp.h>
|
||||||
|
#include <esp_sntp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
#include <espchrono.h>
|
#include <espchrono.h>
|
||||||
|
|
||||||
@ -7,6 +13,8 @@
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "stringsettings.h"
|
#include "stringsettings.h"
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
namespace presets {
|
namespace presets {
|
||||||
constexpr Settings::Limits defaultLimits {
|
constexpr Settings::Limits defaultLimits {
|
||||||
.iMotMax = DEFAULT_IMOTMAX,
|
.iMotMax = DEFAULT_IMOTMAX,
|
||||||
@ -25,8 +33,13 @@ constexpr Settings::Limits kidsLimits {
|
|||||||
};
|
};
|
||||||
|
|
||||||
constexpr Settings::TimeSettings defaultTimeSettings {
|
constexpr Settings::TimeSettings defaultTimeSettings {
|
||||||
.timezoneOffset = 60,
|
.timezoneOffset = 60min,
|
||||||
.daylightSavingMode = espchrono::DayLightSavingMode::EuropeanSummerTime
|
.daylightSavingMode = espchrono::DayLightSavingMode::EuropeanSummerTime,
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
.timeServerEnabled = true,
|
||||||
|
.timeSyncMode = SNTP_SYNC_MODE_IMMED,
|
||||||
|
.timeSyncInterval = espchrono::milliseconds32{CONFIG_LWIP_SNTP_UPDATE_DELAY},
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr Settings::ControllerHardware defaultControllerHardware {
|
constexpr Settings::ControllerHardware defaultControllerHardware {
|
||||||
@ -245,7 +258,10 @@ StringSettings makeDefaultStringSettings()
|
|||||||
.otaUrl = {},
|
.otaUrl = {},
|
||||||
#endif
|
#endif
|
||||||
#ifdef FEATURE_GARAGE
|
#ifdef FEATURE_GARAGE
|
||||||
.garageUrl = "http://insecure.brunner.ninja/tor.php",
|
.garageUrl = {},
|
||||||
|
#endif
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
.timeServer = "europe.pool.ntp.org",
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,13 @@
|
|||||||
|
|
||||||
// esp-idf includes
|
// esp-idf includes
|
||||||
#include <esp_wifi_types.h>
|
#include <esp_wifi_types.h>
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
#include <lwip/apps/snmp.h>
|
||||||
|
#include <esp_sntp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// 3rdparty lib includes
|
||||||
|
#include <espchrono.h>
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "bobbycar-common.h"
|
#include "bobbycar-common.h"
|
||||||
@ -54,8 +61,14 @@ struct Settings
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct TimeSettings {
|
struct TimeSettings {
|
||||||
int16_t timezoneOffset;
|
espchrono::minutes32 timezoneOffset;
|
||||||
espchrono::DayLightSavingMode daylightSavingMode;
|
espchrono::DayLightSavingMode daylightSavingMode;
|
||||||
|
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
bool timeServerEnabled;
|
||||||
|
sntp_sync_mode_t timeSyncMode;
|
||||||
|
espchrono::milliseconds32 timeSyncInterval;
|
||||||
|
#endif
|
||||||
} timeSettings;
|
} timeSettings;
|
||||||
|
|
||||||
struct ControllerHardware {
|
struct ControllerHardware {
|
||||||
@ -160,6 +173,11 @@ void Settings::executeForEveryCommonSetting(T &&callable)
|
|||||||
|
|
||||||
callable("timezoneOffset", timeSettings.timezoneOffset);
|
callable("timezoneOffset", timeSettings.timezoneOffset);
|
||||||
callable("daylightSaving", timeSettings.daylightSavingMode);
|
callable("daylightSaving", timeSettings.daylightSavingMode);
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
callable("timeServerEnab", timeSettings.timeServerEnabled);
|
||||||
|
callable("timeSyncMode", timeSettings.timeSyncMode);
|
||||||
|
callable("timeSyncInterv", timeSettings.timeSyncInterval);
|
||||||
|
#endif
|
||||||
|
|
||||||
callable("wheelDiameter", controllerHardware.wheelDiameter);
|
callable("wheelDiameter", controllerHardware.wheelDiameter);
|
||||||
callable("numMagnetPoles", controllerHardware.numMagnetPoles);
|
callable("numMagnetPoles", controllerHardware.numMagnetPoles);
|
||||||
|
@ -5,9 +5,13 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
// esp-idf includes
|
// esp-idf includes
|
||||||
|
#include <esp_log.h>
|
||||||
#include <nvs_flash.h>
|
#include <nvs_flash.h>
|
||||||
#include <nvs.h>
|
#include <nvs.h>
|
||||||
#include <esp_log.h>
|
#ifdef FEATURE_NTP
|
||||||
|
#include <lwip/apps/snmp.h>
|
||||||
|
#include <esp_sntp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
@ -230,6 +234,48 @@ template<> struct nvsGetterHelper<espchrono::DayLightSavingMode> { static esp_er
|
|||||||
*out_value = espchrono::DayLightSavingMode(tempValue);
|
*out_value = espchrono::DayLightSavingMode(tempValue);
|
||||||
return err;
|
return err;
|
||||||
}};
|
}};
|
||||||
|
template<> struct nvsGetterHelper<espchrono::milliseconds32> { static esp_err_t nvs_get(nvs_handle handle, const char* key, espchrono::milliseconds32* out_value)
|
||||||
|
{
|
||||||
|
int32_t tempValue;
|
||||||
|
esp_err_t err = nvs_get_i32(handle, key, &tempValue);
|
||||||
|
if (err == ESP_OK)
|
||||||
|
*out_value = espchrono::milliseconds32(tempValue);
|
||||||
|
return err;
|
||||||
|
}};
|
||||||
|
template<> struct nvsGetterHelper<espchrono::seconds32> { static esp_err_t nvs_get(nvs_handle handle, const char* key, espchrono::seconds32* out_value)
|
||||||
|
{
|
||||||
|
int32_t tempValue;
|
||||||
|
esp_err_t err = nvs_get_i32(handle, key, &tempValue);
|
||||||
|
if (err == ESP_OK)
|
||||||
|
*out_value = espchrono::seconds32(tempValue);
|
||||||
|
return err;
|
||||||
|
}};
|
||||||
|
template<> struct nvsGetterHelper<espchrono::minutes32> { static esp_err_t nvs_get(nvs_handle handle, const char* key, espchrono::minutes32* out_value)
|
||||||
|
{
|
||||||
|
int32_t tempValue;
|
||||||
|
esp_err_t err = nvs_get_i32(handle, key, &tempValue);
|
||||||
|
if (err == ESP_OK)
|
||||||
|
*out_value = espchrono::minutes32(tempValue);
|
||||||
|
return err;
|
||||||
|
}};
|
||||||
|
template<> struct nvsGetterHelper<espchrono::hours32> { static esp_err_t nvs_get(nvs_handle handle, const char* key, espchrono::hours32* out_value)
|
||||||
|
{
|
||||||
|
int32_t tempValue;
|
||||||
|
esp_err_t err = nvs_get_i32(handle, key, &tempValue);
|
||||||
|
if (err == ESP_OK)
|
||||||
|
*out_value = espchrono::hours32(tempValue);
|
||||||
|
return err;
|
||||||
|
}};
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
template<> struct nvsGetterHelper<sntp_sync_mode_t> { static esp_err_t nvs_get(nvs_handle handle, const char* key, sntp_sync_mode_t* out_value)
|
||||||
|
{
|
||||||
|
uint8_t tempValue;
|
||||||
|
esp_err_t err = nvs_get_u8(handle, key, &tempValue);
|
||||||
|
if (err == ESP_OK)
|
||||||
|
*out_value = sntp_sync_mode_t(tempValue);
|
||||||
|
return err;
|
||||||
|
}};
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool SettingsPersister::load(T &settings)
|
bool SettingsPersister::load(T &settings)
|
||||||
@ -317,6 +363,28 @@ template<> struct nvsSetterHelper<espchrono::DayLightSavingMode> { static esp_er
|
|||||||
{
|
{
|
||||||
return nvs_set_u8(handle, key, uint8_t(value));
|
return nvs_set_u8(handle, key, uint8_t(value));
|
||||||
}};
|
}};
|
||||||
|
template<> struct nvsSetterHelper<espchrono::milliseconds32> { static esp_err_t nvs_set(nvs_handle handle, const char* key, espchrono::milliseconds32 value)
|
||||||
|
{
|
||||||
|
return nvs_set_i32(handle, key, value.count());
|
||||||
|
}};
|
||||||
|
template<> struct nvsSetterHelper<espchrono::seconds32> { static esp_err_t nvs_set(nvs_handle handle, const char* key, espchrono::seconds32 value)
|
||||||
|
{
|
||||||
|
return nvs_set_i32(handle, key, value.count());
|
||||||
|
}};
|
||||||
|
template<> struct nvsSetterHelper<espchrono::minutes32> { static esp_err_t nvs_set(nvs_handle handle, const char* key, espchrono::minutes32 value)
|
||||||
|
{
|
||||||
|
return nvs_set_i32(handle, key, value.count());
|
||||||
|
}};
|
||||||
|
template<> struct nvsSetterHelper<espchrono::hours32> { static esp_err_t nvs_set(nvs_handle handle, const char* key, espchrono::hours32 value)
|
||||||
|
{
|
||||||
|
return nvs_set_i32(handle, key, value.count());
|
||||||
|
}};
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
template<> struct nvsSetterHelper<sntp_sync_mode_t> { static esp_err_t nvs_set(nvs_handle handle, const char* key, sntp_sync_mode_t value)
|
||||||
|
{
|
||||||
|
return nvs_set_u8(handle, key, uint8_t(value));
|
||||||
|
}};
|
||||||
|
#endif
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool SettingsPersister::save(T &settings)
|
bool SettingsPersister::save(T &settings)
|
||||||
|
@ -26,6 +26,10 @@ struct StringSettings
|
|||||||
std::string garageUrl;
|
std::string garageUrl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
std::string timeServer;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
void executeForEveryCommonSetting(T &&callable);
|
void executeForEveryCommonSetting(T &&callable);
|
||||||
@ -69,6 +73,9 @@ void StringSettings::executeForEveryCommonSetting(T &&callable)
|
|||||||
#ifdef FEATURE_GARAGE
|
#ifdef FEATURE_GARAGE
|
||||||
callable("garageUrl", garageUrl);
|
callable("garageUrl", garageUrl);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
callable("timeServer", timeServer);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
11
main/texts.h
11
main/texts.h
@ -332,7 +332,11 @@ constexpr char TEXT_CLOUDSENDRATE[] = "Cloud send rate";
|
|||||||
//TimeSettingsMenu
|
//TimeSettingsMenu
|
||||||
//constexpr char TEXT_TIME[] = "Time";
|
//constexpr char TEXT_TIME[] = "Time";
|
||||||
constexpr char TEXT_OFFSET[] = "Offset";
|
constexpr char TEXT_OFFSET[] = "Offset";
|
||||||
constexpr char TEXT_DAYLIGHTSAVINGMODE[] = "Daylight Saving Mode";
|
constexpr char TEXT_DAYLIGHTSAVINGMODE[] = "Daylight Saving";
|
||||||
|
constexpr char TEXT_NTPENABLED[] = "NTP Enabled";
|
||||||
|
constexpr char TEXT_NTPSERVER[] = "NTP Server";
|
||||||
|
constexpr char TEXT_NTPMODE[] = "NTP Mode";
|
||||||
|
constexpr char TEXT_NTPINTERVAL[] = "NTP Interval";
|
||||||
//constexpr char TEXT_BACK[] = "Back";
|
//constexpr char TEXT_BACK[] = "Back";
|
||||||
|
|
||||||
//ChangeValueDisplay<BluetoothMode>
|
//ChangeValueDisplay<BluetoothMode>
|
||||||
@ -345,6 +349,11 @@ constexpr char TEXT_TRUE[] = "true";
|
|||||||
constexpr char TEXT_FALSE[] = "false";
|
constexpr char TEXT_FALSE[] = "false";
|
||||||
//constexpr char TEXT_BACK[] = "Back";
|
//constexpr char TEXT_BACK[] = "Back";
|
||||||
|
|
||||||
|
//ChangeValueDisplay<sntp_sync_mode_t>
|
||||||
|
constexpr char TEXT_IMMED[] = "IMMED";
|
||||||
|
constexpr char TEXT_SMOOTH[] = "SMOOTH";
|
||||||
|
//constexpr char TEXT_BACK[] = "Back";
|
||||||
|
|
||||||
//ChangeValueDisplay<ControlMode>
|
//ChangeValueDisplay<ControlMode>
|
||||||
constexpr char TEXT_OPENMODE[] = "Open mode";
|
constexpr char TEXT_OPENMODE[] = "Open mode";
|
||||||
constexpr char TEXT_VOLTAGE[] = "Voltage";
|
constexpr char TEXT_VOLTAGE[] = "Voltage";
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
// esp-idf includes
|
||||||
|
#include <esp_log.h>
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
#include <lwip/apps/snmp.h>
|
||||||
|
#include <esp_sntp.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// 3rdparty lib includes
|
// 3rdparty lib includes
|
||||||
#include <espchrono.h>
|
#include <espchrono.h>
|
||||||
|
#include <espstrutils.h>
|
||||||
|
|
||||||
// local includes
|
// local includes
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
@ -10,3 +18,84 @@ auto espchrono::local_clock::timezone() noexcept -> time_zone
|
|||||||
{
|
{
|
||||||
return time_zone{minutes32{settings.timeSettings.timezoneOffset}, settings.timeSettings.daylightSavingMode};
|
return time_zone{minutes32{settings.timeSettings.timezoneOffset}, settings.timeSettings.daylightSavingMode};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
#ifdef FEATURE_NTP
|
||||||
|
void time_sync_notification_cb(struct timeval *tv);
|
||||||
|
|
||||||
|
void initTime()
|
||||||
|
{
|
||||||
|
sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
||||||
|
static_assert(SNTP_MAX_SERVERS >= 1);
|
||||||
|
sntp_setservername(0, stringSettings.timeServer.c_str());
|
||||||
|
sntp_set_time_sync_notification_cb(time_sync_notification_cb);
|
||||||
|
sntp_set_sync_mode(settings.timeSettings.timeSyncMode);
|
||||||
|
sntp_set_sync_interval(espchrono::milliseconds32{settings.timeSettings.timeSyncInterval}.count());
|
||||||
|
if (settings.timeSettings.timeServerEnabled)
|
||||||
|
{
|
||||||
|
ESP_LOGI("BOBBY", "sntp_init() ...");
|
||||||
|
sntp_init();
|
||||||
|
if (!sntp_enabled())
|
||||||
|
{
|
||||||
|
ESP_LOGE("BOBBY", "sntp_init() failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateTime()
|
||||||
|
{
|
||||||
|
if (bool(sntp_enabled()) != settings.timeSettings.timeServerEnabled)
|
||||||
|
{
|
||||||
|
if (settings.timeSettings.timeServerEnabled)
|
||||||
|
{
|
||||||
|
ESP_LOGD("BOBBY", "calling sntp_init()...");
|
||||||
|
sntp_init();
|
||||||
|
ESP_LOGI("BOBBY", "sntp_init() finished");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGD("BOBBY", "calling sntp_stop()...");
|
||||||
|
sntp_stop();
|
||||||
|
ESP_LOGI("BOBBY", "sntp_stop() finished");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stringSettings.timeServer != sntp_getservername(0))
|
||||||
|
{
|
||||||
|
ESP_LOGD("BOBBY", "calling sntp_getservername() with %s...", stringSettings.timeServer.c_str());
|
||||||
|
sntp_setservername(0, stringSettings.timeServer.c_str());
|
||||||
|
ESP_LOGI("BOBBY", "sntp_getservername() finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.timeSettings.timeSyncMode != sntp_get_sync_mode())
|
||||||
|
{
|
||||||
|
ESP_LOGD("BOBBY", "calling sntp_set_sync_mode() with %s...", espcpputils::toString(settings.timeSettings.timeSyncMode).c_str());
|
||||||
|
sntp_set_sync_mode(settings.timeSettings.timeSyncMode);
|
||||||
|
ESP_LOGI("BOBBY", "sntp_set_sync_mode() finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.timeSettings.timeSyncInterval != espchrono::milliseconds32{sntp_get_sync_interval()})
|
||||||
|
{
|
||||||
|
ESP_LOGD("BOBBY", "calling sntp_set_sync_interval() with %s...", espchrono::toString(settings.timeSettings.timeSyncInterval).c_str());
|
||||||
|
sntp_set_sync_interval(espchrono::milliseconds32{settings.timeSettings.timeSyncInterval}.count());
|
||||||
|
ESP_LOGI("BOBBY", "sntp_set_sync_interval() finished");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tl::expected<void, std::string> time_requestSync()
|
||||||
|
{
|
||||||
|
ESP_LOGI("BOBBY", "called");
|
||||||
|
if (!sntp_restart())
|
||||||
|
return tl::make_unexpected("sntp_restart() failed");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
void time_sync_notification_cb(struct timeval *tv)
|
||||||
|
{
|
||||||
|
if (tv)
|
||||||
|
ESP_LOGI("BOBBY", "%ld", tv->tv_sec);
|
||||||
|
else
|
||||||
|
ESP_LOGI("BOBBY", "nullptr");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
@ -167,6 +167,18 @@ CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP_INFO=y
|
|||||||
CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP=3
|
CONFIG_LOG_LOCAL_LEVEL_ASYNC_HTTP=3
|
||||||
# end of Simple Async HTTP Request
|
# end of Simple Async HTTP Request
|
||||||
|
|
||||||
|
#
|
||||||
|
# espcpputils settings
|
||||||
|
#
|
||||||
|
# CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL_NONE is not set
|
||||||
|
# CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL_ERROR is not set
|
||||||
|
# CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL_WARN is not set
|
||||||
|
CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL_INFO=y
|
||||||
|
# CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL_DEBUG is not set
|
||||||
|
# CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL_VERBOSE is not set
|
||||||
|
CONFIG_ESPCPPUTILS_LOG_LOCAL_LEVEL=3
|
||||||
|
# end of espcpputils settings
|
||||||
|
|
||||||
#
|
#
|
||||||
# Simple WiFi Stack settings
|
# Simple WiFi Stack settings
|
||||||
#
|
#
|
||||||
|
Reference in New Issue
Block a user