M harmony_changelog.md => harmony_changelog.md +1 -0
@@ 10,6 10,7 @@
### Added
* Added shortcuts instruction to settings
+* Added brightness fade in functionality
### Changed / Improved
* Optimize the way Relaxation is loading music files
M module-apps/apps-common/widgets/ProgressTimer.cpp => module-apps/apps-common/widgets/ProgressTimer.cpp +5 -3
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "ProgressTimer.hpp"
@@ 10,7 10,6 @@
namespace app
{
-
ProgressTimer::ProgressTimer(app::ApplicationCommon *app,
gui::Item &parent,
std::string timerName,
@@ 47,7 46,9 @@ namespace app
void ProgressTimer::startTimer()
{
Expects(app != nullptr);
- parent.timerCallback = [this](gui::Item &it, sys::Timer &task) { return onTimerTimeout(task); };
+ parent.timerCallback = [this]([[maybe_unused]] gui::Item &it, sys::Timer &task) {
+ return onTimerTimeout(task);
+ };
timerTask = app::GuiTimerFactory::createPeriodicTimer(app, &parent, name, baseTickInterval);
timerTask.start();
}
@@ 94,6 95,7 @@ namespace app
{
isRunning = false;
}
+
std::chrono::milliseconds ProgressTimer::getElapsed()
{
return elapsed;
M module-apps/apps-common/widgets/ProgressTimer.hpp => module-apps/apps-common/widgets/ProgressTimer.hpp +2 -6
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 8,10 8,7 @@
#include <atomic>
#include <chrono>
#include <string>
-namespace
-{
- constexpr auto baseTickDefault = std::chrono::milliseconds{1000};
-} // namespace
+
namespace gui
{
class Item;
@@ 81,5 78,4 @@ namespace app
void registerOnIntervalCallback(std::function<void()> cb) override;
[[nodiscard]] auto isStopped() const noexcept -> bool override;
};
-
} // namespace app
M module-services/service-evtmgr/screen-light-control/ScreenLightControlParameters.hpp => module-services/service-evtmgr/screen-light-control/ScreenLightControlParameters.hpp +3 -2
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 13,7 13,8 @@ namespace screen_light_control
{
Other,
AlarmPrewakeup,
- Alarm
+ Alarm,
+ PowerNap
};
/// Modes in which front light can operate
M module-services/service-time/AlarmHandlerFactory.cpp => module-services/service-time/AlarmHandlerFactory.cpp +0 -1
@@ 1,7 1,6 @@
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-#include <map>
#include <memory>
#include <service-time/AlarmHandler.hpp>
M products/BellHybrid/alarms/BellAlarmHandler.cpp => products/BellHybrid/alarms/BellAlarmHandler.cpp +2 -2
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "BellAlarmHandler.hpp"
@@ 41,7 41,7 @@ namespace alarms
actions.emplace_back(factory::createAlarmToneAction(*service));
actions.emplace_back(std::make_unique<NotifyGUIAction>(*service));
actions.emplace_back(std::make_unique<FrontlightAction>(
- *service, FrontlightAction::Mode::Manual, FrontlightAction::SettingsDependency::AlarmClock));
+ *service, FrontlightAction::Mode::LinearProgress, FrontlightAction::SettingsDependency::AlarmClock));
return actions;
}
M products/BellHybrid/alarms/CMakeLists.txt => products/BellHybrid/alarms/CMakeLists.txt +1 -0
@@ 11,6 11,7 @@ target_sources(alarms
include/AbstractAlarmAction.hpp
include/BellAlarmHandler.hpp
+ include/BellAlarmConstants.hpp
src/actions/PlayAudioActions.hpp
src/actions/FrontlightAction.hpp
src/actions/NotifyGUIAction.hpp
A products/BellHybrid/alarms/include/BellAlarmConstants.hpp => products/BellHybrid/alarms/include/BellAlarmConstants.hpp +11 -0
@@ 0,0 1,11 @@
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#pragma once
+
+#include <chrono>
+
+namespace alarms
+{
+ inline constexpr auto defaultAlarmRingingTime = std::chrono::minutes{5};
+}
M products/BellHybrid/alarms/include/BellAlarmHandler.hpp => products/BellHybrid/alarms/include/BellAlarmHandler.hpp +2 -1
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 57,6 57,7 @@ namespace alarms
private:
static auto getActions(sys::Service *service) -> Actions;
};
+
class BedtimeReminderHandler : public BellAlarmHandler
{
public:
M products/BellHybrid/alarms/src/actions/FrontlightAction.cpp => products/BellHybrid/alarms/src/actions/FrontlightAction.cpp +76 -35
@@ 2,6 2,7 @@
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "FrontlightAction.hpp"
+#include "BellAlarmConstants.hpp"
#include <service-evtmgr/ScreenLightControlMessage.hpp>
#include <service-evtmgr/ServiceEventManagerName.hpp>
@@ 9,24 10,29 @@
#include <service-db/Settings.hpp>
#include <db/SystemSettings.hpp>
#include <module-utils/utility/Utils.hpp>
-#include <common/data/FrontlightUtils.hpp>
namespace alarms
{
namespace
{
+ constexpr std::string_view alarmFrontlightOff = "0";
+ constexpr std::string_view prewakeupFrontlightOff = "0";
+
+ /* Reach and maintain target brightness 1 minute faster than
+ * the duration of the action. */
+ constexpr auto frontlightRampDurationOffset = std::chrono::minutes{1};
+ constexpr auto initialTargetDuration = std::chrono::seconds{5};
+ constexpr auto initialZeroBrightnessValue = 10;
+
void validateBrightness(std::string &brightness)
{
- constexpr std::string_view DefaultBrightness{"50.0"};
+ constexpr auto defaultBrightness = std::string_view{"50.0"};
if (brightness.empty()) {
- brightness = DefaultBrightness;
+ brightness = defaultBrightness;
}
}
- } // namespace
- namespace
- {
screen_light_control::Sender translateDependency(FrontlightAction::SettingsDependency dependency)
{
screen_light_control::Sender sender;
@@ 71,6 77,8 @@ namespace alarms
private:
screen_light_control::LinearProgressModeParameters prepareParameters();
+ screen_light_control::LinearProgressModeParameters prepareAlarmClockParameters();
+ screen_light_control::LinearProgressModeParameters preparePrewakeupParameters();
sys::Service &service;
settings::Settings settings;
@@ 103,7 111,7 @@ namespace alarms
switch (settingsDependency) {
case SettingsDependency::AlarmClock:
settingString = settings.getValue(bell::settings::Alarm::lightActive, settings::SettingsScope::Global);
- if (settingString == std::string(alarmFrontlightOFF)) {
+ if (settingString == alarmFrontlightOff) {
service.bus.sendUnicast(
std::make_shared<sevm::ScreenLightControlMessage>(screen_light_control::Action::ignoreKeypress),
service::name::evt_manager);
@@ 113,7 121,7 @@ namespace alarms
case SettingsDependency::Prewakeup:
settingString =
settings.getValue(bell::settings::PrewakeUp::lightDuration, settings::SettingsScope::Global);
- if (settingString == std::string(prewakeupFrontlightOFF)) {
+ if (settingString == prewakeupFrontlightOff) {
return true;
}
break;
@@ 131,7 139,7 @@ namespace alarms
switch (settingsDependency) {
case SettingsDependency::AlarmClock:
settingString = settings.getValue(bell::settings::Alarm::lightActive, settings::SettingsScope::Global);
- if (settingString == std::string(alarmFrontlightOFF)) {
+ if (settingString == alarmFrontlightOff) {
service.bus.sendUnicast(std::make_shared<sevm::ScreenLightControlMessage>(
screen_light_control::Action::stopIgnoringKeypress),
service::name::evt_manager);
@@ 146,11 154,12 @@ namespace alarms
screen_light_control::ManualModeParameters ManualFrontlightAction::prepareParameters()
{
- std::string brightnessString =
- settings.getValue(bell::settings::Alarm::brightness, settings::SettingsScope::Global);
+ using bsp::eink_frontlight::BrightnessPercentage;
+
+ auto brightnessString = settings.getValue(bell::settings::Alarm::brightness, settings::SettingsScope::Global);
validateBrightness(brightnessString);
screen_light_control::ManualModeParameters params{};
- params.manualModeBrightness = utils::toNumeric(brightnessString);
+ params.manualModeBrightness = static_cast<BrightnessPercentage>(utils::toNumeric(brightnessString));
return params;
}
@@ 164,8 173,8 @@ namespace alarms
bool ManualFrontlightAction::execute()
{
- auto params = prepareParameters();
- auto sender = translateDependency(settingsDependency);
+ const auto params = prepareParameters();
+ const auto sender = translateDependency(settingsDependency);
service.bus.sendUnicast(
std::make_shared<sevm::ScreenLightControlMessage>(
screen_light_control::Action::turnOn, screen_light_control::Parameters{params}, sender),
@@ 175,7 184,7 @@ namespace alarms
bool ManualFrontlightAction::turnOff()
{
- auto sender = translateDependency(settingsDependency);
+ const auto sender = translateDependency(settingsDependency);
service.bus.sendUnicast(std::make_shared<sevm::ScreenLightControlMessage>(
screen_light_control::Action::turnOff, std::nullopt, sender),
service::name::evt_manager);
@@ 192,7 201,7 @@ namespace alarms
bool LinearProgressFrontlightAction::execute()
{
const auto params = prepareParameters();
- auto sender = translateDependency(settingsDependency);
+ const auto sender = translateDependency(settingsDependency);
service.bus.sendUnicast(std::make_shared<sevm::ScreenLightSetAutoProgressiveModeParams>(params),
service::name::evt_manager);
service.bus.sendUnicast(std::make_shared<sevm::ScreenLightControlMessage>(
@@ 203,38 212,70 @@ namespace alarms
screen_light_control::LinearProgressModeParameters LinearProgressFrontlightAction::prepareParameters()
{
- constexpr auto firstTargetDuration = std::chrono::seconds{5};
+ switch (settingsDependency) {
+ case FrontlightAction::SettingsDependency::AlarmClock:
+ return prepareAlarmClockParameters();
+ case FrontlightAction::SettingsDependency::Prewakeup:
+ return preparePrewakeupParameters();
+ default:
+ return {};
+ }
+ }
- std::string brightnessString =
- settings.getValue(bell::settings::PrewakeUp::brightness, settings::SettingsScope::Global);
- validateBrightness(brightnessString);
- const auto value = settings.getValue(bell::settings::PrewakeUp::lightDuration, settings::SettingsScope::Global);
- const auto lightDuration = std::chrono::minutes{utils::toNumeric(value)};
- const auto secondTargetDuration = lightDuration - std::chrono::minutes{1} - firstTargetDuration;
+ screen_light_control::LinearProgressModeParameters LinearProgressFrontlightAction::prepareAlarmClockParameters()
+ {
+ constexpr auto mainTargetDuration =
+ defaultAlarmRingingTime - frontlightRampDurationOffset - initialTargetDuration;
+
+ auto initialBrightness = initialZeroBrightnessValue;
+ const auto isPrewakeUpEnabled = (settings.getValue(bell::settings::PrewakeUp::lightDuration,
+ settings::SettingsScope::Global) != prewakeupFrontlightOff);
+ if (isPrewakeUpEnabled) {
+ auto initialBrightnessString =
+ settings.getValue(bell::settings::PrewakeUp::brightness, settings::SettingsScope::Global);
+ validateBrightness(initialBrightnessString);
+ initialBrightness = utils::toNumeric(initialBrightnessString);
+ }
- screen_light_control::LinearProgressModeParameters params{};
- screen_light_control::functions::LinearProgressFunction startFunction{}, endFunction{};
+ auto targetBrightnessString =
+ settings.getValue(bell::settings::Alarm::brightness, settings::SettingsScope::Global);
+ validateBrightness(targetBrightnessString);
- startFunction.duration = firstTargetDuration;
- startFunction.target = 10.0f;
+ const screen_light_control::functions::LinearProgressFunction startFunction{
+ .target = static_cast<float>(initialBrightness), .duration = initialTargetDuration};
+ const screen_light_control::functions::LinearProgressFunction endFunction{
+ .target = static_cast<float>(utils::toNumeric(targetBrightnessString)), .duration = mainTargetDuration};
- endFunction.duration = secondTargetDuration;
- endFunction.target = utils::toNumeric(brightnessString);
+ return screen_light_control::LinearProgressModeParameters{.startBrightnessValue =
+ static_cast<float>(initialBrightness),
+ .functions = {startFunction, endFunction},
+ .brightnessHysteresis = 0.0f};
+ }
- params.startBrightnessValue = 0.0f;
- params.brightnessHysteresis = 0.0f;
- params.functions = {startFunction, endFunction};
+ screen_light_control::LinearProgressModeParameters LinearProgressFrontlightAction::preparePrewakeupParameters()
+ {
+ auto brightnessString =
+ settings.getValue(bell::settings::PrewakeUp::brightness, settings::SettingsScope::Global);
+ validateBrightness(brightnessString);
+ const auto value = settings.getValue(bell::settings::PrewakeUp::lightDuration, settings::SettingsScope::Global);
+ const auto lightDuration = std::chrono::minutes{utils::toNumeric(value)};
+ const auto mainTargetDuration = lightDuration - frontlightRampDurationOffset - initialTargetDuration;
- return params;
+ const screen_light_control::functions::LinearProgressFunction startFunction{
+ .target = initialZeroBrightnessValue, .duration = initialTargetDuration};
+ const screen_light_control::functions::LinearProgressFunction endFunction{
+ .target = static_cast<float>(utils::toNumeric(brightnessString)), .duration = mainTargetDuration};
+
+ return screen_light_control::LinearProgressModeParameters{
+ .startBrightnessValue = 0.0f, .functions = {startFunction, endFunction}, .brightnessHysteresis = 0.0f};
}
bool LinearProgressFrontlightAction::turnOff()
{
- auto sender = translateDependency(settingsDependency);
+ const auto sender = translateDependency(settingsDependency);
service.bus.sendUnicast(std::make_shared<sevm::ScreenLightControlMessage>(
screen_light_control::Action::turnOff, std::nullopt, sender),
service::name::evt_manager);
return true;
}
-
} // namespace alarms
M products/BellHybrid/alarms/src/actions/FrontlightAction.hpp => products/BellHybrid/alarms/src/actions/FrontlightAction.hpp +1 -4
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 34,9 34,6 @@ namespace alarms
bool turnOff() override;
private:
- static constexpr std::string_view alarmFrontlightOFF = "0";
- static constexpr std::string_view prewakeupFrontlightOFF = "0";
-
sys::Service &service;
SettingsDependency settingsDependency;
std::unique_ptr<AbstractAlarmAction> pimpl;
M products/BellHybrid/apps/application-bell-main/CMakeLists.txt => products/BellHybrid/apps/application-bell-main/CMakeLists.txt +1 -0
@@ 38,6 38,7 @@ target_include_directories(application-bell-main
target_link_libraries(application-bell-main
PRIVATE
+ alarms
app
apps-common
i18n
M products/BellHybrid/apps/application-bell-main/presenters/StateController.cpp => products/BellHybrid/apps/application-bell-main/presenters/StateController.cpp +4 -4
@@ 1,9 1,10 @@
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-#include "application-bell-main/presenters/HomeScreenPresenter.hpp"
-#include "models/TemperatureModel.hpp"
#include "StateController.hpp"
+#include "BellAlarmConstants.hpp"
+#include "models/TemperatureModel.hpp"
+#include "application-bell-main/presenters/HomeScreenPresenter.hpp"
#include <common/TimeUtils.hpp>
#include <common/models/TimeModel.hpp>
@@ 16,7 17,6 @@
#include <time/time_conversion.hpp>
#include <chrono>
-#include <random>
/// Uncomment to print state machine debug logs
/// #define DEBUG_STATE_MACHINE 1U
@@ 225,7 225,7 @@ namespace app::home_screen
{
auto entry =
[](AbstractView &view, AbstractTemperatureModel &temperatureModel, AbstractPresenter &presenter) {
- presenter.spawnTimer(defaultAlarmRingingTime);
+ presenter.spawnTimer(alarms::defaultAlarmRingingTime);
view.setViewState(ViewState::AlarmRinging);
view.setTemperature(temperatureModel.getTemperature());
};
M products/BellHybrid/apps/application-bell-main/presenters/StateController.hpp => products/BellHybrid/apps/application-bell-main/presenters/StateController.hpp +1 -3
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 17,8 17,6 @@ namespace app
namespace app::home_screen
{
-
- inline constexpr auto defaultAlarmRingingTime = std::chrono::minutes(5);
inline constexpr auto defaultAlarmSetTime = std::chrono::seconds{10};
class AbstractView;
M products/BellHybrid/apps/application-bell-powernap/ApplicationBellPowerNap.cpp => products/BellHybrid/apps/application-bell-powernap/ApplicationBellPowerNap.cpp +16 -17
@@ 2,9 2,7 @@
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "ApplicationBellPowerNap.hpp"
-#include "presenter/PowerNapMainWindowPresenter.hpp"
-#include "presenter/PowerNapProgressPresenter.hpp"
-#include "presenter/PowerNapSessionEndedPresenter.hpp"
+#include "models/PowerNapFrontlightModel.hpp"
#include "windows/PowerNapMainWindow.hpp"
#include "windows/PowerNapProgressWindow.hpp"
#include "windows/PowerNapSessionEndedWindow.hpp"
@@ 18,10 16,9 @@ namespace app
std::string parent,
StatusIndicators statusIndicators,
StartInBackground startInBackground,
- uint32_t stackDepth)
+ std::uint32_t stackDepth)
: Application(std::move(name), std::move(parent), statusIndicators, startInBackground, stackDepth),
- audioModel{std::make_unique<AudioModel>(this)},
- frontLightModel{std::make_unique<app::bell_settings::FrontlightModel>(this)}
+ audioModel{std::make_unique<AudioModel>(this)}
{
bus.channels.push_back(sys::BusChannel::ServiceAudioNotifications);
}
@@ 40,31 37,33 @@ namespace app
void ApplicationBellPowerNap::createUserInterface()
{
- windowsFactory.attach(gui::name::window::main_window, [this](ApplicationCommon *app, const std::string &name) {
- auto presenter = std::make_unique<powernap::PowerNapMainWindowPresenter>(app, settings.get());
- return std::make_unique<gui::PowerNapMainWindow>(app, std::move(presenter));
- });
windowsFactory.attach(
- gui::window::name::powernapProgress, [this](ApplicationCommon *app, const std::string &name) {
+ gui::name::window::main_window, [this](ApplicationCommon *app, [[maybe_unused]] const std::string &name) {
+ auto presenter = std::make_unique<powernap::PowerNapMainWindowPresenter>(app, settings.get());
+ return std::make_unique<gui::PowerNapMainWindow>(app, std::move(presenter));
+ });
+ windowsFactory.attach(
+ gui::window::name::powerNapProgress,
+ [this](ApplicationCommon *app, [[maybe_unused]] const std::string &name) {
auto timeModel = std::make_unique<app::TimeModel>();
- auto alarmLightOnOff = std::make_unique<bell_settings::AlarmLightOnOffModel>(this);
+ auto frontlightModel = std::make_unique<powernap::PowerNapFrontlightModel>(this, powerNapAlarmDuration);
auto soundsRepository =
std::make_unique<SoundsRepository>(paths::audio::proprietary() / paths::audio::alarm());
auto presenter = std::make_unique<powernap::PowerNapProgressPresenter>(app,
settings.get(),
std::move(soundsRepository),
*audioModel,
- *frontLightModel,
std::move(timeModel),
- std::move(alarmLightOnOff));
+ std::move(frontlightModel),
+ powerNapAlarmDuration);
return std::make_unique<gui::PowerNapProgressWindow>(app, std::move(presenter));
});
windowsFactory.attach(gui::window::session_paused::sessionPaused,
- [](ApplicationCommon *app, const std::string &name) {
+ [](ApplicationCommon *app, [[maybe_unused]] const std::string &name) {
return std::make_unique<gui::SessionPausedWindow>(app);
});
- windowsFactory.attach(gui::window::name::powernapSessionEnded,
- [](ApplicationCommon *app, const std::string &name) {
+ windowsFactory.attach(gui::window::name::powerNapSessionEnded,
+ [](ApplicationCommon *app, [[maybe_unused]] const std::string &name) {
auto presenter = std::make_unique<powernap::PowerNapSessionEndPresenter>(app);
return std::make_unique<gui::PowerNapSessionEndedWindow>(app, std::move(presenter));
});
M products/BellHybrid/apps/application-bell-powernap/CMakeLists.txt => products/BellHybrid/apps/application-bell-powernap/CMakeLists.txt +2 -0
@@ 24,6 24,7 @@ target_sources(application-bell-powernap
windows/PowerNapSessionEndedWindow.cpp
data/PowerNapListItem.cpp
models/PowerNapModel.cpp
+ models/PowerNapFrontlightModel.cpp
presenter/PowerNapMainWindowPresenter.hpp
presenter/PowerNapProgressPresenter.hpp
@@ 35,6 36,7 @@ target_sources(application-bell-powernap
data/PowerNapStyle.hpp
data/PowerNapCommon.hpp
models/PowerNapModel.hpp
+ models/PowerNapFrontlightModel.hpp
PUBLIC
include/application-bell-powernap/ApplicationBellPowerNap.hpp
M products/BellHybrid/apps/application-bell-powernap/include/application-bell-powernap/ApplicationBellPowerNap.hpp => products/BellHybrid/apps/application-bell-powernap/include/application-bell-powernap/ApplicationBellPowerNap.hpp +13 -18
@@ 1,40 1,35 @@
-// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
-#include <Application.hpp>
#include <common/models/AbstractAudioModel.hpp>
-#include <common/models/FrontlightModel.hpp>
-#include <common/models/AlarmSettingsModel.hpp>
+#include <Application.hpp>
namespace gui::window::name
{
- inline constexpr auto powernapProgress = "PowerNapProgressWindow";
- inline constexpr auto powernapSessionEnded = "PowerNapSessionEndedWindow";
+ inline constexpr auto powerNapProgress = "PowerNapProgressWindow";
+ inline constexpr auto powerNapSessionEnded = "PowerNapSessionEndedWindow";
} // namespace gui::window::name
+
namespace app
{
- namespace powernap
- {
- class PowerNapAlarmImpl;
- }
-
inline constexpr auto applicationBellPowerNapName = "ApplicationBellPowerNap";
+ inline constexpr auto applicationBellPowerNapStackSize = 1024 * 8;
+ inline constexpr std::chrono::minutes powerNapAlarmDuration{5};
class ApplicationBellPowerNap : public Application
{
private:
std::unique_ptr<AbstractAudioModel> audioModel;
- std::unique_ptr<app::bell_settings::AbstractFrontlightModel> frontLightModel;
void onStop() override;
public:
- ApplicationBellPowerNap(std::string name = applicationBellPowerNapName,
- std::string parent = "",
- StatusIndicators statusIndicators = StatusIndicators{},
- StartInBackground startInBackground = {false},
- uint32_t stackDepth = 4096 * 2);
+ explicit ApplicationBellPowerNap(std::string name = applicationBellPowerNapName,
+ std::string parent = "",
+ StatusIndicators statusIndicators = StatusIndicators{},
+ StartInBackground startInBackground = {false},
+ std::uint32_t stackDepth = applicationBellPowerNapStackSize);
~ApplicationBellPowerNap();
sys::ReturnCodes InitHandler() override;
@@ 44,7 39,7 @@ namespace app
sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override;
- sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) override final
+ sys::ReturnCodes SwitchPowerModeHandler([[maybe_unused]] const sys::ServicePowerMode mode) override final
{
return sys::ReturnCodes::Success;
}
A products/BellHybrid/apps/application-bell-powernap/models/PowerNapFrontlightModel.cpp => products/BellHybrid/apps/application-bell-powernap/models/PowerNapFrontlightModel.cpp +85 -0
@@ 0,0 1,85 @@
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#include "PowerNapFrontlightModel.hpp"
+
+#include <db/SystemSettings.hpp>
+#include <apps-common/ApplicationCommon.hpp>
+#include <service-evtmgr/ScreenLightControlMessage.hpp>
+#include <service-evtmgr/ServiceEventManagerName.hpp>
+
+namespace app::powernap
+{
+ PowerNapFrontlightModel::PowerNapFrontlightModel(ApplicationCommon *app, const std::chrono::seconds &alarmDuration)
+ : app{app}, alarmDuration{alarmDuration}
+ {
+ settings.init(service::ServiceProxy{app->weak_from_this()});
+ }
+
+ auto PowerNapFrontlightModel::isAlarmLightEnabled() const -> bool
+ {
+ const auto alarmLightEnabled =
+ settings.getValue(bell::settings::Alarm::lightActive, settings::SettingsScope::Global);
+ return (utils::toNumeric(alarmLightEnabled) != 0);
+ }
+
+ auto PowerNapFrontlightModel::lockKeypressTrigger() -> void
+ {
+ app->bus.sendUnicast(
+ std::make_shared<sevm::ScreenLightControlMessage>(
+ screen_light_control::Action::ignoreKeypress, std::nullopt, screen_light_control::Sender::PowerNap),
+ service::name::evt_manager);
+ }
+
+ auto PowerNapFrontlightModel::unlockKeypressTrigger() -> void
+ {
+ app->bus.sendUnicast(
+ std::make_shared<sevm::ScreenLightControlMessage>(screen_light_control::Action::stopIgnoringKeypress,
+ std::nullopt,
+ screen_light_control::Sender::PowerNap),
+ service::name::evt_manager);
+ }
+
+ auto PowerNapFrontlightModel::startBrightnessFadeIn() -> void
+ {
+ const auto &fadeInParams = prepareFadeInParameters();
+ app->bus.sendUnicast(std::make_shared<sevm::ScreenLightSetAutoProgressiveModeParams>(fadeInParams),
+ service::name::evt_manager);
+ app->bus.sendUnicast(std::make_shared<sevm::ScreenLightControlMessage>(screen_light_control::Action::turnOn,
+ std::nullopt,
+ screen_light_control::Sender::PowerNap),
+ service::name::evt_manager);
+ }
+
+ auto PowerNapFrontlightModel::turnOff() -> void
+ {
+ app->bus.sendUnicast(std::make_shared<sevm::ScreenLightControlMessage>(screen_light_control::Action::turnOff,
+ std::nullopt,
+ screen_light_control::Sender::PowerNap),
+ service::name::evt_manager);
+ }
+
+ auto PowerNapFrontlightModel::getAlarmBrightness() const -> int
+ {
+ const auto brightness = settings.getValue(bell::settings::Alarm::brightness, settings::SettingsScope::Global);
+ return utils::toNumeric(brightness);
+ }
+
+ auto PowerNapFrontlightModel::prepareFadeInParameters() const -> screen_light_control::LinearProgressModeParameters
+ {
+ constexpr auto targetReachTimeOffset = std::chrono::minutes{1};
+ constexpr auto startFunctionDuration = std::chrono::seconds{5};
+ constexpr auto startFunctionTarget = 10.0f;
+
+ const auto brightness = getAlarmBrightness();
+ const auto endFunctionDuration = alarmDuration - targetReachTimeOffset - startFunctionDuration;
+
+ const screen_light_control::functions::LinearProgressFunction startFunction{.target = startFunctionTarget,
+ .duration = startFunctionDuration};
+ const screen_light_control::functions::LinearProgressFunction endFunction{
+ .target = static_cast<float>(brightness), .duration = endFunctionDuration};
+
+ return screen_light_control::LinearProgressModeParameters{
+ .startBrightnessValue = 0.0f, .functions = {startFunction, endFunction}, .brightnessHysteresis = 0.0f};
+ }
+} // namespace app::powernap
A products/BellHybrid/apps/application-bell-powernap/models/PowerNapFrontlightModel.hpp => products/BellHybrid/apps/application-bell-powernap/models/PowerNapFrontlightModel.hpp +36 -0
@@ 0,0 1,36 @@
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#pragma once
+
+#include <chrono>
+#include <service-db/Settings.hpp>
+#include <service-evtmgr/screen-light-control/ScreenLightControlParameters.hpp>
+
+namespace app
+{
+ class ApplicationCommon;
+}
+
+namespace app::powernap
+{
+ class PowerNapFrontlightModel
+ {
+ public:
+ explicit PowerNapFrontlightModel(ApplicationCommon *app, const std::chrono::seconds &alarmDuration);
+
+ auto isAlarmLightEnabled() const -> bool;
+ auto lockKeypressTrigger() -> void;
+ auto unlockKeypressTrigger() -> void;
+ auto startBrightnessFadeIn() -> void;
+ auto turnOff() -> void;
+
+ private:
+ ApplicationCommon *app = nullptr;
+ const std::chrono::seconds alarmDuration;
+ mutable settings::Settings settings;
+
+ auto getAlarmBrightness() const -> int;
+ auto prepareFadeInParameters() const -> screen_light_control::LinearProgressModeParameters;
+ };
+} // namespace app::powernap
M products/BellHybrid/apps/application-bell-powernap/models/PowerNapModel.cpp => products/BellHybrid/apps/application-bell-powernap/models/PowerNapModel.cpp +5 -1
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "PowerNapModel.hpp"
@@ 18,14 18,17 @@ namespace app::powernap
{
return getRecord(order);
}
+
auto PowerNapModel::requestRecordsCount() -> unsigned int
{
return internalData.size();
}
+
auto PowerNapModel::getMinimalItemSpaceRequired() const -> unsigned int
{
return style::sidelistview::list_item::w;
}
+
void PowerNapModel::requestRecords(uint32_t offset, uint32_t limit)
{
setupModel(offset, limit);
@@ 39,6 42,7 @@ namespace app::powernap
}
return std::chrono::minutes{powerNapItem->getSpinnerValue()};
}
+
void PowerNapModel::setValue(std::chrono::minutes napTimeValue)
{
if (powerNapItem == nullptr) {
M products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapMainWindowPresenter.cpp => products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapMainWindowPresenter.cpp +3 -6
@@ 1,13 1,10 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "PowerNapMainWindowPresenter.hpp"
#include "models/PowerNapModel.hpp"
#include "data/PowerNapCommon.hpp"
#include <ApplicationBellPowerNap.hpp>
-#include <apps-common/ApplicationCommon.hpp>
-#include <service-db/agents/settings/SystemSettings.hpp>
-#include <service-db/Settings.hpp>
namespace app::powernap
{
@@ 32,7 29,7 @@ namespace app::powernap
const auto currentValue = model->getCurrentValue();
settings->setValue(
powernapDBRecordName, utils::to_string(currentValue.count()), settings::SettingsScope::AppLocal);
- reinterpret_cast<app::Application *>(app)->suspendIdleTimer();
- app->switchWindow(gui::window::name::powernapProgress);
+ static_cast<app::Application *>(app)->suspendIdleTimer();
+ app->switchWindow(gui::window::name::powerNapProgress);
}
} // namespace app::powernap
M products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapMainWindowPresenter.hpp => products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapMainWindowPresenter.hpp +1 -2
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 56,5 56,4 @@ namespace app::powernap
void loadNapTimeList() override;
void activate() override;
};
-
} // namespace app::powernap
M products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapProgressPresenter.cpp => products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapProgressPresenter.cpp +28 -31
@@ 2,40 2,33 @@
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "PowerNapProgressPresenter.hpp"
-#include "application-bell-powernap/ApplicationBellPowerNap.hpp"
#include "data/PowerNapCommon.hpp"
+#include "models/PowerNapFrontlightModel.hpp"
-#include <apps-common/widgets/ProgressTimerWithBarGraphAndCounter.hpp>
#include <common/models/TimeModel.hpp>
#include <db/SystemSettings.hpp>
-#include <service-db/Settings.hpp>
-#include <Timers/TimerFactory.hpp>
#include <common/windows/BellFinishedWindow.hpp>
-#include <common/windows/SessionPausedWindow.hpp>
-#include <Utils.hpp>
#include <gsl/assert>
+#include <Application.hpp>
namespace
{
- inline constexpr auto powernapAlarmTimerName = "PowerNapAlarmTimer";
- inline constexpr std::chrono::minutes powernapAlarmTimeout{5};
+ constexpr auto powerNapAlarmTimerName = "PowerNapAlarmTimer";
} // namespace
namespace app::powernap
{
- PowerNapProgressPresenter::PowerNapProgressPresenter(
- app::ApplicationCommon *app,
- settings::Settings *settings,
- std::unique_ptr<AbstractSoundsRepository> soundsRepository,
- AbstractAudioModel &audioModel,
- app::bell_settings::AbstractFrontlightModel &frontLightModel,
- std::unique_ptr<AbstractTimeModel> timeModel,
- std::unique_ptr<app::bell_settings::AlarmLightOnOffModel> alarmLightOnOffModel)
- : app{app}, settings{settings}, soundsRepository{std::move(soundsRepository)}, audioModel{audioModel},
- frontLightModel{frontLightModel}, timeModel{std::move(timeModel)}, alarmLightOnOffModel{std::move(
- alarmLightOnOffModel)},
+ PowerNapProgressPresenter::PowerNapProgressPresenter(app::ApplicationCommon *app,
+ settings::Settings *settings,
+ std::unique_ptr<AbstractSoundsRepository> soundsRepository,
+ AbstractAudioModel &audioModel,
+ std::unique_ptr<AbstractTimeModel> timeModel,
+ std::unique_ptr<PowerNapFrontlightModel> frontlightModel,
+ const std::chrono::seconds &powerNapAlarmDuration)
+ : app{app}, settings{settings}, soundsRepository{std::move(soundsRepository)},
+ audioModel{audioModel}, timeModel{std::move(timeModel)}, frontlightModel{std::move(frontlightModel)},
napAlarmTimer{sys::TimerFactory::createSingleShotTimer(
- app, powernapAlarmTimerName, powernapAlarmTimeout, [this](sys::Timer &) { onNapAlarmFinished(); })}
+ app, powerNapAlarmTimerName, powerNapAlarmDuration, [this](sys::Timer &) { onNapAlarmFinished(); })}
{}
@@ 52,17 45,22 @@ namespace app::powernap
{
Expects(timer != nullptr);
const auto value = settings->getValue(powernapDBRecordName);
- reinterpret_cast<app::Application *>(app)->suspendIdleTimer();
+ static_cast<app::Application *>(app)->suspendIdleTimer();
timer->reset(std::chrono::minutes{utils::getNumericValue<int>(value)});
timer->start();
napFinished = false;
}
- void PowerNapProgressPresenter::endNap()
+ void PowerNapProgressPresenter::abortNap()
{
napFinished = false;
timer->stop();
napAlarmTimer.stop();
+ }
+
+ void PowerNapProgressPresenter::endNap()
+ {
+ abortNap();
onNapAlarmFinished();
}
@@ 83,16 81,13 @@ namespace app::powernap
if (napFinished) {
return;
}
- if (alarmLightOnOffModel->getValue()) {
- const auto modeAutoStr = utils::translate("app_bell_settings_frontlight_mode_auto");
- frontLightModel.setMode(frontLightModel.getModeModel().getValue() == modeAutoStr
- ? screen_light_control::ScreenLightMode::Automatic
- : screen_light_control::ScreenLightMode::Manual);
- frontLightModel.setBrightness(frontLightModel.getBrightnessModel().getValue());
- frontLightModel.setBacklight(bell_settings::BacklightState::On);
+
+ if (frontlightModel->isAlarmLightEnabled()) {
+ frontlightModel->lockKeypressTrigger();
+ frontlightModel->startBrightnessFadeIn();
}
- const auto filePath = soundsRepository->titleToPath(
+ const auto &filePath = soundsRepository->titleToPath(
settings->getValue(bell::settings::Alarm::tone, settings::SettingsScope::Global));
audioModel.play(filePath.value_or(""), AbstractAudioModel::PlaybackType::Alarm, {});
@@ 102,6 97,8 @@ namespace app::powernap
void PowerNapProgressPresenter::onNapAlarmFinished()
{
+ frontlightModel->unlockKeypressTrigger();
+ frontlightModel->turnOff();
audioModel.stopPlayedByThis({});
getView()->napEnded();
}
@@ 110,6 107,7 @@ namespace app::powernap
{
getView()->setTime(timeModel->getCurrentTime());
}
+
bool PowerNapProgressPresenter::isNapFinished()
{
return napFinished;
@@ 124,5 122,4 @@ namespace app::powernap
{
return timer->isStopped();
}
-
} // namespace app::powernap
M products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapProgressPresenter.hpp => products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapProgressPresenter.hpp +9 -12
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 10,8 10,6 @@
#include <time/time_locale.hpp>
#include <Timers/TimerHandle.hpp>
#include <memory>
-#include <common/models/FrontlightModel.hpp>
-#include <common/models/AlarmSettingsModel.hpp>
namespace app
{
@@ 19,15 17,11 @@ namespace app
class ApplicationCommon;
} // namespace app
-namespace app::bell_settings
-{
- class AbstractFrontlightModel;
- class AlarmLightOnOffModel;
-} // namespace app::bell_settings
namespace gui
{
class Item;
} // namespace gui
+
namespace settings
{
class Settings;
@@ 35,6 29,8 @@ namespace settings
namespace app::powernap
{
+ class PowerNapFrontlightModel;
+
class PowerNapProgressContract
{
public:
@@ 55,6 51,7 @@ namespace app::powernap
public:
virtual void activate() = 0;
virtual void endNap() = 0;
+ virtual void abortNap() = 0;
virtual bool isTimerStopped() = 0;
virtual void pause() = 0;
virtual void resume() = 0;
@@ 71,10 68,9 @@ namespace app::powernap
settings::Settings *settings{};
std::unique_ptr<AbstractSoundsRepository> soundsRepository;
AbstractAudioModel &audioModel;
- app::bell_settings::AbstractFrontlightModel &frontLightModel;
std::unique_ptr<app::TimerWithCallbacks> timer;
std::unique_ptr<AbstractTimeModel> timeModel;
- std::unique_ptr<app::bell_settings::AlarmLightOnOffModel> alarmLightOnOffModel;
+ std::unique_ptr<PowerNapFrontlightModel> frontlightModel;
sys::TimerHandle napAlarmTimer;
bool napFinished{false};
@@ 85,12 81,13 @@ namespace app::powernap
settings::Settings *settings,
std::unique_ptr<AbstractSoundsRepository> soundsRepository,
AbstractAudioModel &audioModel,
- app::bell_settings::AbstractFrontlightModel &frontLightModel,
std::unique_ptr<AbstractTimeModel> timeModel,
- std::unique_ptr<app::bell_settings::AlarmLightOnOffModel> alarmLightOnOffModel);
+ std::unique_ptr<PowerNapFrontlightModel> frontlightModel,
+ const std::chrono::seconds &powerNapAlarmDuration);
void activate() override;
void endNap() override;
+ void abortNap() override;
void pause() override;
void resume() override;
void setTimer(std::unique_ptr<app::TimerWithCallbacks> &&_timer) override;
M products/BellHybrid/apps/application-bell-powernap/windows/PowerNapMainWindow.cpp => products/BellHybrid/apps/application-bell-powernap/windows/PowerNapMainWindow.cpp +2 -2
@@ 1,10 1,11 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "PowerNapMainWindow.hpp"
#include <Style.hpp>
#include <SideListView.hpp>
#include <gui/input/InputEvent.hpp>
+
namespace gui
{
PowerNapMainWindow::PowerNapMainWindow(
@@ 40,5 41,4 @@ namespace gui
return AppWindow::onInput(inputEvent);
}
-
} // namespace gui
M products/BellHybrid/apps/application-bell-powernap/windows/PowerNapProgressWindow.cpp => products/BellHybrid/apps/application-bell-powernap/windows/PowerNapProgressWindow.cpp +19 -12
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "PowerNapProgressWindow.hpp"
@@ 10,8 10,8 @@
namespace
{
- inline constexpr auto powernapTimerName = "PowerNapTimer";
- inline constexpr std::chrono::seconds timerTick{1};
+ constexpr auto powerNapTimerName = "PowerNapTimer";
+ constexpr auto powerNapTimerPeriod = std::chrono::seconds{1};
} // namespace
namespace gui
@@ 19,7 19,7 @@ namespace gui
PowerNapProgressWindow::PowerNapProgressWindow(
app::ApplicationCommon *app,
std::shared_ptr<app::powernap::PowerNapProgressContract::Presenter> &&windowPresenter)
- : AppWindow(app, gui::window::name::powernapProgress), presenter{std::move(windowPresenter)}
+ : AppWindow(app, gui::window::name::powerNapProgress), presenter{std::move(windowPresenter)}
{
presenter->attach(this);
buildInterface();
@@ 90,7 90,7 @@ namespace gui
void PowerNapProgressWindow::configureTimer()
{
auto progressTimer = std::make_unique<app::ProgressTimerWithBarGraphAndCounter>(
- application, *this, powernapTimerName, timerTick, app::ProgressCountdownMode::Increasing);
+ application, *this, powerNapTimerName, powerNapTimerPeriod, app::ProgressCountdownMode::Increasing);
progressTimer->attach(progress);
progressTimer->attach(timer);
presenter->setTimer(std::move(progressTimer));
@@ 98,13 98,19 @@ namespace gui
bool PowerNapProgressWindow::onInput(const InputEvent &inputEvent)
{
+ const auto key = mapKey(inputEvent.getKeyCode());
+
+ /* Prevent leaving by back long press */
+ if (inputEvent.isLongRelease() && (key == KeyMap::Back)) {
+ return true;
+ }
+
if (inputEvent.isShortRelease()) {
- const auto key = mapKey(inputEvent.getKeyCode());
- if (presenter->isNapFinished() && key == KeyMap::LightPress) {
+ if (presenter->isNapFinished() && (key == KeyMap::LightPress)) {
presenter->endNap();
return true;
}
- else if (not presenter->isNapFinished() && key == KeyMap::LightPress) {
+ else if (!presenter->isNapFinished() && (key == KeyMap::LightPress)) {
if (presenter->isTimerStopped()) {
presenter->resume();
}
@@ 113,9 119,9 @@ namespace gui
}
return true;
}
- else if (not presenter->isNapFinished() && key == KeyMap::Back) {
- reinterpret_cast<app::Application *>(application)->resumeIdleTimer();
- presenter->endNap();
+ else if (!presenter->isNapFinished() && (key == KeyMap::Back)) {
+ static_cast<app::Application *>(application)->resumeIdleTimer();
+ presenter->abortNap();
application->returnToPreviousWindow();
return true;
}
@@ 123,9 129,10 @@ namespace gui
}
return AppWindow::onInput(inputEvent);
}
+
void PowerNapProgressWindow::napEnded()
{
- application->switchWindow(gui::window::name::powernapSessionEnded, std::make_unique<gui::PowerNapSwitchData>());
+ application->switchWindow(gui::window::name::powerNapSessionEnded, std::make_unique<gui::PowerNapSwitchData>());
}
void PowerNapProgressWindow::setTime(std::time_t newTime)
M products/BellHybrid/apps/application-bell-powernap/windows/PowerNapSessionEndedWindow.cpp => products/BellHybrid/apps/application-bell-powernap/windows/PowerNapSessionEndedWindow.cpp +2 -3
@@ 1,8 1,7 @@
-// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "PowerNapSessionEndedWindow.hpp"
-#include "data/PowerNapStyle.hpp"
#include <application-bell-powernap/ApplicationBellPowerNap.hpp>
#include <gui/widgets/Icon.hpp>
@@ 10,7 9,7 @@ namespace gui
{
PowerNapSessionEndedWindow::PowerNapSessionEndedWindow(
app::ApplicationCommon *app, std::shared_ptr<app::powernap::PowerNapSessionEndedContract::Presenter> presenter)
- : WindowWithTimer(app, window::name::powernapSessionEnded), presenter{std::move(presenter)}
+ : WindowWithTimer(app, window::name::powerNapSessionEnded), presenter{std::move(presenter)}
{
buildInterface();
}
M products/BellHybrid/apps/application-bell-settings/models/FrontlightModel.cpp => products/BellHybrid/apps/application-bell-settings/models/FrontlightModel.cpp +6 -1
@@ 35,6 35,7 @@ namespace app::bell_settings
service::name::evt_manager);
request->execute(app, this, responseCallback);
}
+
void FrontlightModel::setBacklight(BacklightState state)
{
app->bus.sendUnicast(std::make_shared<sevm::ScreenLightControlMessage>(
@@ 42,6 43,7 @@ namespace app::bell_settings
: screen_light_control::Action::turnOff),
service::name::evt_manager);
}
+
void FrontlightModel::setMode(screen_light_control::ScreenLightMode mode)
{
app->bus.sendUnicast(
@@ 50,17 52,20 @@ namespace app::bell_settings
: screen_light_control::Action::disableAutomaticMode),
service::name::evt_manager);
}
+
void FrontlightModel::setBrightness(frontlight_utils::Brightness value)
{
- screen_light_control::ConstLinearProgressModeParameters parameters{
+ const screen_light_control::ConstLinearProgressModeParameters parameters{
frontlight_utils::fixedValToPercentage(value)};
app->bus.sendUnicast(std::make_shared<sevm::ScreenLightSetConstLinearModeParams>(parameters),
service::name::evt_manager);
}
+
gui::AbstractSettingsModel<std::uint8_t> &FrontlightModel::getBrightnessModel()
{
return *brightnessAdapter;
}
+
gui::AbstractSettingsModel<UTF8> &FrontlightModel::getModeModel()
{
return *modeAdapter;
M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsModel.cpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsModel.cpp +15 -10
@@ 1,16 1,21 @@
-// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include <common/models/AlarmSettingsModel.hpp>
-
-#include <apps-common/ApplicationCommon.hpp>
#include <db/SystemSettings.hpp>
namespace app::bell_settings
{
namespace
{
- static constexpr std::string_view DefaultBrightness{"50.0"};
+ inline void validateBrightness(std::string &brightness)
+ {
+ constexpr auto defaultBrightness = std::string_view{"50.0"};
+
+ if (brightness.empty()) {
+ brightness = defaultBrightness;
+ }
+ }
}
void AlarmToneModel::setValue(UTF8 value)
@@ 32,10 37,12 @@ namespace app::bell_settings
{
return defaultValue;
}
+
void AlarmVolumeModel::restoreDefault()
{
setValue(defaultValue);
}
+
AlarmVolumeModel::AlarmVolumeModel(AbstractAudioModel &audioModel) : audioModel{audioModel}
{
defaultValue = audioModel.getVolume(AbstractAudioModel::PlaybackType::Alarm).value_or(0);
@@ 43,14 50,14 @@ namespace app::bell_settings
void AlarmLightOnOffModel::setValue(bool value)
{
- const auto valStr = std::to_string(value);
+ const auto valStr = std::to_string(static_cast<int>(value));
settings.setValue(bell::settings::Alarm::lightActive, valStr, settings::SettingsScope::Global);
}
bool AlarmLightOnOffModel::getValue() const
{
const auto str = settings.getValue(bell::settings::Alarm::lightActive, settings::SettingsScope::Global);
- return std::stoi(str);
+ return (utils::toNumeric(str) != 0);
}
void AlarmFrontlightModel::setValue(frontlight_utils::Brightness value)
@@ 62,9 69,7 @@ namespace app::bell_settings
frontlight_utils::Brightness AlarmFrontlightModel::getValue() const
{
auto str = settings.getValue(bell::settings::Alarm::brightness, settings::SettingsScope::Global);
- if (str.empty()) {
- str = DefaultBrightness;
- }
- return frontlight_utils::percentageToFixedVal(std::stoi(str));
+ validateBrightness(str);
+ return frontlight_utils::percentageToFixedVal(static_cast<float>(utils::toNumeric(str)));
}
} // namespace app::bell_settings
M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpListItemProvider.hpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpListItemProvider.hpp +1 -2
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 20,5 20,4 @@ namespace app::bell_settings
AbstractPrewakeUpSettingsModel &settingsModel;
};
-
} // namespace app::bell_settings
M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpSettingsModel.cpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpSettingsModel.cpp +7 -7
@@ 1,16 1,14 @@
-// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include <models/alarm_settings/PrewakeUpSettingsModel.hpp>
-
-#include <apps-common/ApplicationCommon.hpp>
#include <db/SystemSettings.hpp>
namespace app::bell_settings
{
namespace
{
- static constexpr std::string_view DefaultBrightness{"50.0"};
+ constexpr std::string_view DefaultBrightness{"50.0"};
}
void PrewakeUpChimeDurationModel::setValue(std::uint8_t value)
@@ 22,7 20,7 @@ namespace app::bell_settings
std::uint8_t PrewakeUpChimeDurationModel::getValue() const
{
const auto str = settings.getValue(bell::settings::PrewakeUp::duration, settings::SettingsScope::Global);
- return std::stoi(str);
+ return utils::toNumeric(str);
}
void PrewakeUpChimeToneModel::setValue(UTF8 value)
@@ 44,10 42,12 @@ namespace app::bell_settings
{
return defaultValue;
}
+
PrewakeUpChimeVolumeModel::PrewakeUpChimeVolumeModel(AbstractAudioModel &audioModel) : audioModel{audioModel}
{
defaultValue = audioModel.getVolume(AbstractAudioModel::PlaybackType::PreWakeup).value_or(0);
}
+
void PrewakeUpChimeVolumeModel::restoreDefault()
{
setValue(defaultValue);
@@ 62,7 62,7 @@ namespace app::bell_settings
std::uint8_t PrewakeUpLightDurationModel::getValue() const
{
const auto str = settings.getValue(bell::settings::PrewakeUp::lightDuration, settings::SettingsScope::Global);
- return std::stoi(str);
+ return utils::toNumeric(str);
}
void PrewakeUpFrontlightModel::setValue(frontlight_utils::Brightness value)
@@ 77,6 77,6 @@ namespace app::bell_settings
if (str.empty()) {
str = DefaultBrightness;
}
- return frontlight_utils::percentageToFixedVal(std::stoi(str));
+ return frontlight_utils::percentageToFixedVal(static_cast<float>(utils::toNumeric(str)));
}
} // namespace app::bell_settings
M products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/PrewakeUpPresenter.cpp => products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/PrewakeUpPresenter.cpp +2 -1
@@ 52,7 52,6 @@ namespace app::bell_settings
auto PrewakeUpWindowPresenter::saveData() -> void
{
for (const auto &item : provider->getListItems()) {
-
item->getValue();
}
}
@@ 73,10 72,12 @@ namespace app::bell_settings
{
provider->clearData();
}
+
void PrewakeUpWindowPresenter::stopSound()
{
this->audioModel.stopPlayedByThis({});
}
+
void PrewakeUpWindowPresenter::exitWithoutSave()
{
model->getChimeVolume().restoreDefault();
M products/BellHybrid/apps/common/include/common/models/AbstractAlarmModel.hpp => products/BellHybrid/apps/common/include/common/models/AbstractAlarmModel.hpp +2 -3
@@ 22,8 22,8 @@ namespace app
virtual bool isActive() const = 0;
virtual void setDefaultAlarmTime() = 0;
- virtual void setAlarmTime(time_t time) = 0;
- virtual time_t getAlarmTime() const = 0;
+ virtual void setAlarmTime(std::time_t time) = 0;
+ virtual std::time_t getAlarmTime() const = 0;
virtual void activate(bool value) = 0;
virtual std::chrono::seconds getSnoozeDuration() const = 0;
virtual bool isSnoozeAllowed() = 0;
@@ 37,5 37,4 @@ namespace app
/// Command model to update its internal data
virtual void update(AlarmModelReadyHandler callback = AlarmModelReadyHandler()) = 0;
};
-
} // namespace app
M products/BellHybrid/apps/common/include/common/models/AlarmModel.hpp => products/BellHybrid/apps/common/include/common/models/AlarmModel.hpp +2 -4
@@ 19,8 19,6 @@ namespace app
namespace app
{
- constexpr std::uint32_t maxSnoozeCount = 3;
-
class AlarmModel : public AbstractAlarmModel, public AsyncCallbackReceiver
{
public:
@@ 28,8 26,8 @@ namespace app
bool isActive() const override;
void setDefaultAlarmTime() override;
- void setAlarmTime(time_t time) override;
- time_t getAlarmTime() const override;
+ void setAlarmTime(std::time_t time) override;
+ std::time_t getAlarmTime() const override;
void activate(bool value) override;
void update(AlarmModelReadyHandler callback) override;
std::chrono::seconds getSnoozeDuration() const override;
M products/BellHybrid/apps/common/include/common/models/FrontlightModel.hpp => products/BellHybrid/apps/common/include/common/models/FrontlightModel.hpp +0 -1
@@ 82,5 82,4 @@ namespace app::bell_settings
const std::string autoStr;
const std::string onDemandStr;
};
-
} // namespace app::bell_settings
M products/BellHybrid/apps/common/src/AlarmModel.cpp => products/BellHybrid/apps/common/src/AlarmModel.cpp +7 -2
@@ 50,7 50,7 @@ namespace app
service::name::service_time);
request->execute(app, this, responseCallback);
}
- void AlarmModel::setAlarmTime(time_t time)
+ void AlarmModel::setAlarmTime(std::time_t time)
{
auto alarmEventPtr = getAlarmPtr();
if (!alarmEventPtr) {
@@ 69,7 69,7 @@ namespace app
updateAlarm(*alarmEventPtr);
}
- time_t AlarmModel::getAlarmTime() const
+ std::time_t AlarmModel::getAlarmTime() const
{
return Clock::to_time_t(cachedRecord.startDate);
}
@@ 146,6 146,7 @@ namespace app
const auto snoozeActive = utils::getNumericValue<bool>(snoozeActiveStr);
return snoozeActive;
}
+
void AlarmModel::turnOff()
{
snoozeCount = 0;
@@ 195,10 196,12 @@ namespace app
}
return alarmEventPtr;
}
+
bool AlarmModel::isSnoozeActive()
{
return snoozeCount > 0;
}
+
void AlarmModel::updateCache(const SingleEventRecord &record, alarms::AlarmStatus status)
{
if (record.startDate != cachedRecord.startDate) {
@@ 208,6 211,7 @@ namespace app
alarmStatus = status;
state = State::Valid;
}
+
void AlarmModel::setDefaultAlarmTime()
{
auto alarmEventPtr = getAlarmPtr();
@@ 229,6 233,7 @@ namespace app
{
return alarmStatus;
}
+
TimePoint AlarmModel::getTimeOfNextSnooze()
{
return nextSnoozeTime;
M products/BellHybrid/services/evtmgr/EventManager.cpp => products/BellHybrid/services/evtmgr/EventManager.cpp +1 -1
@@ 127,7 127,7 @@ void EventManager::initProductEvents()
return sys::msgHandled();
});
- connect(sevm::ScreenLightControlRequestParameters(), [&](sys::Message *msgl) {
+ connect(sevm::ScreenLightControlRequestParameters(), [&]([[maybe_unused]] sys::Message *msgl) {
const screen_light_control::ManualModeParameters params = {backlightHandler.getScreenBrightnessValue()};
auto msg = std::make_shared<sevm::ScreenLightControlParametersResponse>(
backlightHandler.getScreenLightState(), backlightHandler.getScreenAutoModeState(), params);
M products/BellHybrid/services/evtmgr/backlight-handler/BacklightHandler.cpp => products/BellHybrid/services/evtmgr/backlight-handler/BacklightHandler.cpp +15 -12
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include <evtmgr/backlight-handler/BacklightHandler.hpp>
@@ 15,19 15,19 @@ namespace backlight
{
namespace timers
{
- constexpr auto screenLightTimerTimeout = std::chrono::seconds(5);
- constexpr auto screenLightTimerHoldTimeout = std::chrono::seconds(10);
- constexpr auto screenLightBedsideLampTimeout = std::chrono::minutes(10);
+ constexpr auto screenLightTimerTimeout = std::chrono::seconds{5};
+ constexpr auto screenLightTimerHoldTimeout = std::chrono::seconds{10};
+ constexpr auto screenLightBedsideLampTimeout = std::chrono::minutes{10};
} // namespace timers
Handler::Handler(std::shared_ptr<settings::Settings> settings, sys::Service *parent)
: HandlerCommon(std::move(settings),
std::make_shared<bell::screen_light_control::ScreenLightController>(parent),
parent,
- [this](sys::Timer &t) {
- if (this->screenLightController->isLightOn()) {
+ [this]([[maybe_unused]] sys::Timer &t) {
+ if (screenLightController->isLightOn()) {
backlightType = Type::Frontlight;
- this->screenLightController->processRequest(screen_light_control::Action::turnOff);
+ screenLightController->processRequest(screen_light_control::Action::turnOff);
}
})
{}
@@ 36,7 36,7 @@ namespace backlight
{
using namespace screen_light_control;
settings->registerValueChange(settings::Brightness::brightnessLevel, [&](const std::string &value) {
- ConstLinearProgressModeParameters params{utils::getNumericValue<float>(value)};
+ const ConstLinearProgressModeParameters params{utils::getNumericValue<float>(value)};
screenLightController->processRequest(Action::setAutomaticModeParameters, Parameters(params));
});
@@ 47,7 47,9 @@ namespace backlight
void Handler::handleKeyPressed([[maybe_unused]] int key)
{
- handleScreenLightRefresh(key);
+ if (!ignoreKeypress) {
+ handleScreenLightRefresh(key);
+ }
}
void Handler::handleScreenLightRefresh([[maybe_unused]] int key)
@@ 59,7 61,7 @@ namespace backlight
if (controller->isLightOn()) {
timer->restart(timers::screenLightTimerHoldTimeout);
}
- else if (!onDemandModeOn && !ignoreKeypress) {
+ else if (!onDemandModeOn) {
setKeyPressedModeFrontlightOn();
controller->processRequest(screen_light_control::Action::turnOn);
timer->restart(timers::screenLightTimerHoldTimeout);
@@ 108,9 110,10 @@ namespace backlight
switch (sender) {
case screen_light_control::Sender::AlarmPrewakeup:
case screen_light_control::Sender::Alarm:
+ case screen_light_control::Sender::PowerNap:
switch (action) {
case screen_light_control::Action::turnOff:
- backlightType = Type::Frontlight;
+ backlightType = Type::Frontlight; // Override bedside lamp for events with higher priority
break;
default:
break;
@@ 181,7 184,7 @@ namespace backlight
{
using namespace screen_light_control;
auto brightnessLevel = utils::getNumericValue<float>(getValue(settings::Brightness::brightnessLevel));
- screen_light_control::ConstLinearProgressModeParameters params{brightnessLevel};
+ const ConstLinearProgressModeParameters params{brightnessLevel};
screenLightController->processRequest(Action::setAutomaticModeParameters, Parameters(params));
}
M products/BellHybrid/services/evtmgr/screen-light-control/ScreenLightControl.cpp => products/BellHybrid/services/evtmgr/screen-light-control/ScreenLightControl.cpp +0 -2
@@ 5,7 5,6 @@
#include <Service/Service.hpp>
#include <Timers/TimerFactory.hpp>
-#include <Utils.hpp>
#include <system/Constants.hpp>
#include <system/messages/SentinelRegistrationMessage.hpp>
@@ 201,5 200,4 @@ namespace bell::screen_light_control
{
return false;
}
-
} // namespace bell::screen_light_control
M products/BellHybrid/services/time/AlarmOperations.cpp => products/BellHybrid/services/time/AlarmOperations.cpp +10 -7
@@ 59,6 59,7 @@ namespace alarms
{
settings.init(service::ServiceProxy{service->weak_from_this()});
}
+
auto isBedtimeEnabled() -> bool override
{
bool enabled = false;
@@ 71,7 72,8 @@ namespace alarms
}
return enabled;
}
- auto getBedtimeTime() -> time_t override
+
+ auto getBedtimeTime() -> std::time_t override
{
return bedtimeTimeModel->getValue();
}
@@ 223,7 225,7 @@ namespace alarms
{
if (bedtime.decide(now)) {
auto bedtimeEvent = std::make_shared<AlarmEventRecord>();
- bedtimeEvent.get()->enabled = true;
+ bedtimeEvent->enabled = true;
handleAlarmEvent(bedtimeEvent, alarms::AlarmType::BedtimeReminder, true);
}
}
@@ 249,7 251,7 @@ namespace alarms
return event;
}
- void AlarmOperations::turnOffRingingAlarm(const std::uint32_t id, OnTurnOffRingingAlarm callback)
+ void AlarmOperations::turnOffRingingAlarm(std::uint32_t id, OnTurnOffRingingAlarm callback)
{
auto nextEvent = getNextPreWakeUpEvent();
if (nextEvent.isValid()) {
@@ 365,6 367,7 @@ namespace alarms
const auto expectedAlarmStart = std::chrono::floor<std::chrono::minutes>(now) + settings.timeBeforeAlarm;
return settings.enabled && std::chrono::floor<std::chrono::minutes>(event.startDate) == expectedAlarmStart;
}
+
auto PreWakeUp::isActive() const -> bool
{
return active;
@@ 386,11 389,11 @@ namespace alarms
return activated && isTimeForBed(now, time);
}
- auto Bedtime::isTimeForBed(const TimePoint &now, const time_t &bedtime) -> bool
+ auto Bedtime::isTimeForBed(const TimePoint &now, const std::time_t &bedtime) -> bool
{
- auto time_tNow = TimePointToTimeT(now);
- std::tm bedtimeTm = *std::localtime(&bedtime);
- std::tm checkTm = *std::localtime(&time_tNow);
+ const auto timeNow = TimePointToTimeT(now);
+ const auto bedtimeTm = *std::localtime(&bedtime);
+ const auto checkTm = *std::localtime(&timeNow);
return (bedtimeTm.tm_hour == checkTm.tm_hour && bedtimeTm.tm_min == checkTm.tm_min);
}
} // namespace alarms
M products/BellHybrid/services/time/include/time/AlarmOperations.hpp => products/BellHybrid/services/time/include/time/AlarmOperations.hpp +4 -4
@@ 7,6 7,7 @@
#include <db/SystemSettings.hpp>
#include <common/models/BedtimeModel.hpp>
#include <service-db/Settings.hpp>
+
namespace alarms
{
class AlarmOperationsFactory : public IAlarmOperationsFactory
@@ 57,7 58,7 @@ namespace alarms
public:
virtual ~AbstractBedtimeSettingsProvider() noexcept = default;
virtual auto isBedtimeEnabled() -> bool = 0;
- virtual auto getBedtimeTime() -> time_t = 0;
+ virtual auto getBedtimeTime() -> std::time_t = 0;
};
class PreWakeUp
@@ 90,7 91,7 @@ namespace alarms
auto decide(TimePoint now) -> bool;
private:
- auto isTimeForBed(const TimePoint &now, const time_t &bedtime) -> bool;
+ auto isTimeForBed(const TimePoint &now, const std::time_t &bedtime) -> bool;
const std::unique_ptr<AbstractBedtimeSettingsProvider> settingsProvider;
};
@@ 116,9 117,8 @@ namespace alarms
void handlePreWakeUp(const SingleEventRecord &event, PreWakeUp::Decision decision);
void disablePreWakeUp(const std::shared_ptr<AlarmEventRecord> &event);
void handleSnoozeChime(const SingleEventRecord &event, bool newStateOn);
- void handleBedtime(const SingleEventRecord &event, bool decision);
void processBedtime(TimePoint now);
- void turnOffRingingAlarm(const std::uint32_t id, OnTurnOffRingingAlarm callback) override;
+ void turnOffRingingAlarm(std::uint32_t id, OnTurnOffRingingAlarm callback) override;
void onAlarmTurnedOff(const std::shared_ptr<AlarmEventRecord> &event, alarms::AlarmType alarmType) override;
void handleAlarmEvent(const std::shared_ptr<AlarmEventRecord> &event,
alarms::AlarmType alarmType,
M products/PurePhone/services/evtmgr/screen-light-control/ScreenLightControl.cpp => products/PurePhone/services/evtmgr/screen-light-control/ScreenLightControl.cpp +4 -5
@@ 10,7 10,7 @@ namespace pure::screen_light_control
{
namespace
{
- constexpr bsp::eink_frontlight::BrightnessPercentage fadeOutBrigthnessMax = 35.0f;
+ constexpr bsp::eink_frontlight::BrightnessPercentage fadeOutBrightnessMax = 35.0f;
}
ScreenLightController::ScreenLightController(sys::Service *parent)
@@ 187,10 187,10 @@ namespace pure::screen_light_control
{
if (automaticMode == ScreenLightMode::Automatic) {
fadeOut = true;
- // Set fadeout brightess as maximum or current ramp state if lower
+ // Set fadeout brightness as maximum or current ramp state if lower
auto rampState = ::screen_light_control::functions::getRampState();
- auto fadeOutBrigthness = std::clamp(rampState, 0.0f, fadeOutBrigthnessMax);
- ::screen_light_control::functions::setRampTarget(fadeOutBrigthness);
+ auto fadeOutBrightness = std::clamp(rampState, 0.0f, fadeOutBrightnessMax);
+ ::screen_light_control::functions::setRampTarget(fadeOutBrightness);
}
}
@@ 198,5 198,4 @@ namespace pure::screen_light_control
{
return fadeOut;
}
-
} // namespace pure::screen_light_control