diff --git a/NEWS.md b/NEWS.md index 278c23d..da0427c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,9 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Added +- Enable dark mode depending on device state (expects firmware >= + 6.8.x) [#98](https://github.com/orontee/taranis/issues/98) + - Add icons to sunrise and sunset lines [#95](https://github.com/orontee/taranis/issues/95) diff --git a/src/app.cc b/src/app.cc index a600bcc..a281bec 100644 --- a/src/app.cc +++ b/src/app.cc @@ -86,20 +86,8 @@ void App::setup() { BOOST_LOG_TRIVIAL(info) << "Application setup"; this->l10n->initialize_translations(); - - const auto firmware_version = GetSoftwareVersion(); - try { - check_firmware_version(firmware_version); - } catch (const UnsupportedFirmwareVersion &error) { - BOOST_LOG_TRIVIAL(warning) - << "Unsupported firmware version " << firmware_version; - Message(ICON_WARNING, GetLangText("Unsupported software version"), - GetLangText("The application isn't compatible with the software " - "version of this reader."), - error_dialog_delay); - this->exit(); - return; - } + this->check_minimum_supported_firmware(); + this->set_app_capabilities(); this->set_task_parameters(); this->application_state->restore(); @@ -564,6 +552,34 @@ void App::update_configured_unit_system(UnitSystem unit_system) { Config::config_changed(); } +void App::check_minimum_supported_firmware() { + const auto firmware_version = GetSoftwareVersion(); + try { + firmware_version_greater_than(firmware_version, 6); + } catch (const UnsupportedFirmwareVersion &error) { + BOOST_LOG_TRIVIAL(warning) + << "Unsupported firmware version, " << firmware_version; + Message(ICON_WARNING, GetLangText("Unsupported software version"), + GetLangText("The application isn't compatible with the software " + "version of this reader."), + error_dialog_delay); + this->exit(); + return; + } +} + +void App::set_app_capabilities() { + const auto firmware_version = GetSoftwareVersion(); + try { + firmware_version_greater_than(firmware_version, 6, 8); + } catch (const UnsupportedFirmwareVersion &error) { + BOOST_LOG_TRIVIAL(warning) + << "Firmware version not supporting dark mode, " << firmware_version; + return; + } + IvSetAppCapability(APP_CAPABILITY_SUPPORT_SCREEN_INVERSION); +} + void App::set_task_parameters() { const auto task_identifier = GetCurrentTask(); const auto task_info = GetTaskInfo(task_identifier); diff --git a/src/app.h b/src/app.h index 08ac94b..cff75d9 100644 --- a/src/app.h +++ b/src/app.h @@ -85,6 +85,10 @@ class App { void update_configured_unit_system(UnitSystem unit_system); + void check_minimum_supported_firmware(); + + void set_app_capabilities(); + void set_task_parameters(); void start_refresh_timer() const; diff --git a/src/events.cc b/src/events.cc index 5ef7bda..cc01bd9 100644 --- a/src/events.cc +++ b/src/events.cc @@ -344,6 +344,9 @@ std::string taranis::format_event_type(int event_type) { if (event_type == EVT_PACKAGE_JOB_CHANGED) { return "EVT_PACKAGE_JOB_CHANGED"; } + if (event_type == EVT_SCREEN_INVERSION_MODE_CHANGED) { + return "EVT_SCREEN_INVERSION_MODE_CHANGED"; + } if (event_type == EVT_CUSTOM) { return "EVT_CUSTOM"; } diff --git a/src/util.h b/src/util.h index ead9f6d..15fe5b9 100644 --- a/src/util.h +++ b/src/util.h @@ -24,15 +24,23 @@ normalize_precipitations(const std::vector &conditions, double max_number(double value_one, double value_two); -inline void check_firmware_version(const std::string &version) { +inline void firmware_version_greater_than(const std::string &version, + int major_version, + int minor_version = 0) { // expected form V632.6.7.1405 std::stringstream to_parse{version}; std::string token; if (std::getline(to_parse, token, '.')) { std::getline(to_parse, token, '.'); try { - if (std::stoi(token) >= 6) { - return; + if (std::stoi(token) >= major_version) { + if (minor_version == 0) { + return; + } + std::getline(to_parse, token, '.'); + if (std::stoi(token) >= minor_version) { + return; + } } } catch (const std::invalid_argument &error) { }