a4dc633063
Lots of things "ported" over from the "enhanced" fork. With some adjustments here and there. KeyboardBacklight driver (for T-Deck only currently) Trackball driver (for T-Deck only currently) Keyboard backlight sleep/wake (for T-Deck only currently...also requires keyboard firmware update) Display sleep/wake Files - create file/folder Keyboard settings (for T-Deck only currently) Time & Date settings tweaks Locale settings tweaks Systeminfo additions Espnow wifi coexist initI2cDevices - moved to T-deck init.cpp / initBoot KeyboardInitService - removed, moved to T-deck init.cpp / initBoot Adjusted TIMER_UPDATE_INTERVAL to 2 seconds. Added lock to ActionCreateFolder Maybe missed some things in the list. Display wake could do with some kind of block on wake first touch to prevent UI elements being hit when waking device with touch. Same with encoder/trackball/keyboard press i guess. The original code was written by @cscott0108 at https://github.com/cscott0108/tactility-enhanced-t-deck
82 lines
2.0 KiB
C++
82 lines
2.0 KiB
C++
#include <Tactility/settings/Time.h>
|
|
|
|
#include <Tactility/kernel/SystemEvents.h>
|
|
#include <Tactility/Preferences.h>
|
|
#include <Tactility/settings/SystemSettings.h>
|
|
|
|
#ifdef ESP_PLATFORM
|
|
#include <ctime>
|
|
#endif
|
|
|
|
namespace tt::settings {
|
|
|
|
constexpr auto* TIME_SETTINGS_NAMESPACE = "time";
|
|
|
|
constexpr auto* TIMEZONE_PREFERENCES_KEY_NAME = "tz_name";
|
|
constexpr auto* TIMEZONE_PREFERENCES_KEY_CODE = "tz_code";
|
|
constexpr auto* TIMEZONE_PREFERENCES_KEY_TIME24 = "tz_time24";
|
|
|
|
void initTimeZone() {
|
|
#ifdef ESP_PLATFORM
|
|
auto code= getTimeZoneCode();
|
|
if (!code.empty()) {
|
|
setenv("TZ", code.c_str(), 1);
|
|
tzset();
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void setTimeZone(const std::string& name, const std::string& code) {
|
|
Preferences preferences(TIME_SETTINGS_NAMESPACE);
|
|
preferences.putString(TIMEZONE_PREFERENCES_KEY_NAME, name);
|
|
preferences.putString(TIMEZONE_PREFERENCES_KEY_CODE, code);
|
|
|
|
#ifdef ESP_PLATFORM
|
|
setenv("TZ", code.c_str(), 1);
|
|
tzset();
|
|
#endif
|
|
|
|
kernel::publishSystemEvent(kernel::SystemEvent::Time);
|
|
}
|
|
|
|
std::string getTimeZoneName() {
|
|
Preferences preferences(TIME_SETTINGS_NAMESPACE);
|
|
std::string result;
|
|
if (preferences.optString(TIMEZONE_PREFERENCES_KEY_NAME, result)) {
|
|
return result;
|
|
} else {
|
|
return "America/Los_Angeles"; // Default: Pacific Time (PST/PDT)
|
|
}
|
|
}
|
|
|
|
std::string getTimeZoneCode() {
|
|
Preferences preferences(TIME_SETTINGS_NAMESPACE);
|
|
std::string result;
|
|
if (preferences.optString(TIMEZONE_PREFERENCES_KEY_CODE, result)) {
|
|
return result;
|
|
} else {
|
|
return "PST8PDT,M3.2.0,M11.1.0"; // Default: Pacific Time POSIX string
|
|
}
|
|
}
|
|
|
|
bool isTimeFormat24Hour() {
|
|
SystemSettings properties;
|
|
if (!loadSystemSettings(properties)) {
|
|
return true;
|
|
} else {
|
|
return properties.timeFormat24h;
|
|
}
|
|
}
|
|
|
|
void setTimeFormat24Hour(bool show24Hour) {
|
|
SystemSettings properties;
|
|
if (!loadSystemSettings(properties)) {
|
|
return;
|
|
}
|
|
|
|
properties.timeFormat24h = show24Hour;
|
|
saveSystemSettings(properties);
|
|
}
|
|
|
|
}
|