M module-services/service-evtmgr/backlight-handler/BacklightHandlerCommon.cpp => module-services/service-evtmgr/backlight-handler/BacklightHandlerCommon.cpp +7 -31
@@ 17,40 17,16 @@ namespace backlight
HandlerCommon::HandlerCommon(std::shared_ptr<settings::Settings> settings,
std::shared_ptr<screen_light_control::ScreenLightController> screenLightController,
- sys::Service *parent)
+ sys::Service *parent,
+ sys::timer::TimerCallback &&screenLightTimerCallback)
: settings{std::move(settings)}, screenLightController{std::move(screenLightController)},
- screenLightTimer{std::make_shared<sys::TimerHandle>(sys::TimerFactory::createSingleShotTimer(
- parent, timers::screenLightTimerName, timers::screenLightTimerTimeout, [this](sys::Timer &t) {
- if (getScreenAutoModeState() == screen_light_control::ScreenLightMode::Automatic &&
- this->screenLightController->isLightOn()) {
- this->screenLightController->processRequest(screen_light_control::Action::turnOff);
- }
- }))}
+ screenLightTimer{std::make_shared<sys::TimerHandle>(
+ sys::TimerFactory::createSingleShotTimer(parent,
+ timers::screenLightTimerName,
+ timers::screenLightTimerTimeout,
+ std::move(screenLightTimerCallback)))}
{}
- void HandlerCommon::init()
- {
- using namespace screen_light_control;
- settings->registerValueChange(settings::Brightness::brightnessLevel, [&](const std::string &value) {
- ManualModeParameters params{utils::getNumericValue<float>(value)};
- screenLightController->processRequest(Action::setManualModeBrightness, Parameters(params));
- });
-
- settings->registerValueChange(settings::Brightness::autoMode, [&]([[maybe_unused]] const std::string &value) {
- const auto action = getScreenAutoModeState() == ScreenLightMode::Automatic ? Action::enableAutomaticMode
- : Action::disableAutomaticMode;
- screenLightController->processRequest(action);
- });
-
- settings->registerValueChange(settings::Brightness::state, [&]([[maybe_unused]] const std::string &value) {
- const auto action = getScreenLightState() ? Action::turnOn : Action::turnOff;
- if (action == Action::turnOn) {
- onScreenLightTurnedOn();
- }
- screenLightController->processRequest(action);
- });
- }
-
auto HandlerCommon::getValue(const std::string &path) const -> std::string
{
return settings->getValue(path);
M module-services/service-evtmgr/backlight-handler/BacklightHandlerCommon.hpp => module-services/service-evtmgr/backlight-handler/BacklightHandlerCommon.hpp +6 -4
@@ 21,10 21,11 @@ namespace backlight
public:
HandlerCommon(std::shared_ptr<settings::Settings> settings,
std::shared_ptr<screen_light_control::ScreenLightController> screenLightController,
- sys::Service *parent);
+ sys::Service *parent,
+ sys::timer::TimerCallback &&screenLightTimerCallback);
/// initialise in InitHandler when Service is ready
- void init();
+ virtual void init() = 0;
/// Process request of the screen light control
/// @screen_light_control::Action an action to perform
@@ 39,6 40,7 @@ namespace backlight
private:
virtual void onScreenLightTurnedOn() = 0;
+ protected:
std::shared_ptr<settings::Settings> settings;
std::shared_ptr<screen_light_control::ScreenLightController> screenLightController;
@@ 51,8 53,8 @@ namespace backlight
{
return screenLightController;
}
- void handleScreenLightSettings(screen_light_control::Action action,
- const screen_light_control::Parameters ¶ms);
+ virtual void handleScreenLightSettings(screen_light_control::Action action,
+ const screen_light_control::Parameters ¶ms);
void handleScreenLightRefresh();
protected:
M module-services/service-evtmgr/screen-light-control/ControlFunctions.cpp => module-services/service-evtmgr/screen-light-control/ControlFunctions.cpp +3 -0
@@ 60,6 60,9 @@ namespace screen_light_control::functions
rampTargetReached = true;
}
}
+ else {
+ rampTargetReached = true;
+ }
}
return rampState;
M module-services/service-evtmgr/screen-light-control/ScreenLightControlParameters.cpp => module-services/service-evtmgr/screen-light-control/ScreenLightControlParameters.cpp +6 -0
@@ 24,4 24,10 @@ namespace screen_light_control
Expects(hasLinearProgressModeParams());
return linearProgressModeParams.value();
}
+
+ auto Parameters::getConstLinearProgressModeParams() const noexcept -> const ConstLinearProgressModeParameters &
+ {
+ Expects(hasConstLinearProgressModeParams());
+ return constLinearProgressModeParams.value();
+ }
} // namespace screen_light_control
M module-services/service-evtmgr/screen-light-control/ScreenLightControlParameters.hpp => module-services/service-evtmgr/screen-light-control/ScreenLightControlParameters.hpp +17 -0
@@ 60,11 60,17 @@ namespace screen_light_control
float brightnessHysteresis = 0.0f;
};
+ struct ConstLinearProgressModeParameters
+ {
+ float targetBrightness = 0.0f;
+ };
+
class Parameters
{
std::optional<ManualModeParameters> manualModeParams;
std::optional<AutomaticModeParameters> autoModeParams;
std::optional<LinearProgressModeParameters> linearProgressModeParams;
+ std::optional<ConstLinearProgressModeParameters> constLinearProgressModeParams;
public:
Parameters() = default;
@@ 77,6 83,9 @@ namespace screen_light_control
explicit Parameters(const LinearProgressModeParameters &autoModeParams)
: linearProgressModeParams{autoModeParams}
{}
+ explicit Parameters(const ConstLinearProgressModeParameters &autoModeParams)
+ : constLinearProgressModeParams{autoModeParams}
+ {}
[[nodiscard]] bool hasManualModeParams() const noexcept
{
@@ 98,5 107,13 @@ namespace screen_light_control
}
[[nodiscard]] auto getLinearProgressModeParams() const noexcept -> const LinearProgressModeParameters &;
+
+ [[nodiscard]] bool hasConstLinearProgressModeParams() const noexcept
+ {
+ return constLinearProgressModeParams.has_value();
+ }
+
+ [[nodiscard]] auto getConstLinearProgressModeParams() const noexcept
+ -> const ConstLinearProgressModeParameters &;
};
} // namespace screen_light_control
M module-services/service-evtmgr/service-evtmgr/ScreenLightControlMessage.hpp => module-services/service-evtmgr/service-evtmgr/ScreenLightControlMessage.hpp +15 -0
@@ 80,6 80,21 @@ namespace sevm
}
};
+ class ScreenLightSetConstLinearModeParams : public ScreenLightControlMessage
+ {
+ screen_light_control::ConstLinearProgressModeParameters params;
+
+ public:
+ explicit ScreenLightSetConstLinearModeParams(screen_light_control::ConstLinearProgressModeParameters params)
+ : ScreenLightControlMessage(screen_light_control::Action::setAutomaticModeParameters), params{params}
+ {}
+
+ [[nodiscard]] auto getParams() const noexcept -> screen_light_control::ConstLinearProgressModeParameters
+ {
+ return params;
+ }
+ };
+
class ScreenLightControlRequestParameters : public sys::DataMessage
{
public:
M products/BellHybrid/alarms/src/actions/FrontlightAction.cpp => products/BellHybrid/alarms/src/actions/FrontlightAction.cpp +0 -7
@@ 73,10 73,6 @@ namespace alarms
bool ManualFrontlightAction::execute()
{
- service.bus.sendUnicast(
- std::make_shared<sevm::ScreenLightControlMessage>(screen_light_control::Action::disableAutomaticMode),
- service::name::evt_manager);
-
auto params = prepareParameters();
service.bus.sendUnicast(std::make_shared<sevm::ScreenLightControlMessage>(
screen_light_control::Action::turnOn, screen_light_control::Parameters{params}),
@@ 107,9 103,6 @@ namespace alarms
const auto params = prepareParameters();
service.bus.sendUnicast(std::make_shared<sevm::ScreenLightSetAutoProgressiveModeParams>(params),
service::name::evt_manager);
- service.bus.sendUnicast(
- std::make_shared<sevm::ScreenLightControlMessage>(screen_light_control::Action::enableAutomaticMode),
- service::name::evt_manager);
service.bus.sendUnicast(std::make_shared<sevm::ScreenLightControlMessage>(screen_light_control::Action::turnOn),
service::name::evt_manager);
return true;
M products/BellHybrid/apps/application-bell-settings/models/advanced/FrontlightListItemProvider.cpp => products/BellHybrid/apps/application-bell-settings/models/advanced/FrontlightListItemProvider.cpp +4 -4
@@ 34,10 34,10 @@ namespace app::bell_settings
auto mode = new gui::UTF8ListItem(model.getModeModel(),
gui::UTF8Spinner::Range{modeOnDemandsStr, modeAutoStr},
utils::translate("app_bell_settings_frontlight_mode_top_message"));
- mode->setOnValueChanged([this, modeAutoStr](const auto &val) {
- model.setMode(val == modeAutoStr ? screen_light_control::ScreenLightMode::Automatic
- : screen_light_control::ScreenLightMode::Manual);
- });
+ mode->onExit = [this, mode, modeAutoStr]() {
+ model.setMode(mode->getCurrentValue() == modeAutoStr ? screen_light_control::ScreenLightMode::Automatic
+ : screen_light_control::ScreenLightMode::Manual);
+ };
internalData.emplace_back(mode);
}
FrontlightListItemProvider::FrontlightListItemProvider(AbstractFrontlightModel &model) : model{model}
M products/BellHybrid/apps/application-bell-settings/models/advanced/FrontlightModel.cpp => products/BellHybrid/apps/application-bell-settings/models/advanced/FrontlightModel.cpp +2 -2
@@ 68,8 68,8 @@ namespace app::bell_settings
}
void FrontlightModel::setBrightness(Brightness value)
{
- screen_light_control::ManualModeParameters parameters{fixedValToPercentage(value)};
- app->bus.sendUnicast(std::make_shared<sevm::ScreenLightSetManualModeParams>(parameters),
+ screen_light_control::ConstLinearProgressModeParameters parameters{fixedValToPercentage(value)};
+ app->bus.sendUnicast(std::make_shared<sevm::ScreenLightSetConstLinearModeParams>(parameters),
service::name::evt_manager);
}
gui::AbstractSettingsModel<std::uint8_t> &FrontlightModel::getBrightnessModel()
M products/BellHybrid/services/evtmgr/CMakeLists.txt => products/BellHybrid/services/evtmgr/CMakeLists.txt +1 -0
@@ 42,6 42,7 @@ target_link_libraries(evtmgr
keymap
module-bsp
module-utils
+ module-sys
service-evtmgr
bell::appmgr
sys
M products/BellHybrid/services/evtmgr/EventManager.cpp => products/BellHybrid/services/evtmgr/EventManager.cpp +6 -0
@@ 98,6 98,12 @@ void EventManager::initProductEvents()
return sys::msgHandled();
});
+ connect(typeid(sevm::ScreenLightSetConstLinearModeParams), [&](sys::Message *msgl) {
+ auto *m = static_cast<sevm::ScreenLightSetConstLinearModeParams *>(msgl);
+ backlightHandler.processScreenRequest(m->getAction(), screen_light_control::Parameters(m->getParams()));
+ return sys::msgHandled();
+ });
+
connect(sevm::ScreenLightControlRequestParameters(), [&](sys::Message *msgl) {
screen_light_control::ManualModeParameters params = {backlightHandler.getScreenBrightnessValue()};
auto msg = std::make_shared<sevm::ScreenLightControlParametersResponse>(
M products/BellHybrid/services/evtmgr/backlight-handler/BacklightHandler.cpp => products/BellHybrid/services/evtmgr/backlight-handler/BacklightHandler.cpp +89 -10
@@ 4,11 4,12 @@
#include <evtmgr/backlight-handler/BacklightHandler.hpp>
#include <screen-light-control/ScreenLightControl.hpp>
-
+#include <service-db/agents/settings/SystemSettings.hpp>
#include <service-db/Settings.hpp>
#include <Timers/TimerFactory.hpp>
#include <keymap/KeyMap.hpp>
+#include <Utils.hpp>
namespace backlight
{
@@ 19,10 20,29 @@ namespace backlight
} // 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)
+ : HandlerCommon(std::move(settings),
+ std::make_shared<bell::screen_light_control::ScreenLightController>(parent),
+ parent,
+ [this](sys::Timer &t) {
+ if (this->screenLightController->isLightOn()) {
+ this->screenLightController->processRequest(screen_light_control::Action::turnOff);
+ }
+ })
{}
+ void Handler::init()
+ {
+ using namespace screen_light_control;
+ settings->registerValueChange(settings::Brightness::brightnessLevel, [&](const std::string &value) {
+ ConstLinearProgressModeParameters params{utils::getNumericValue<float>(value)};
+ screenLightController->processRequest(Action::setAutomaticModeParameters, Parameters(params));
+ });
+
+ settings->registerValueChange(settings::Brightness::autoMode, [&](const std::string &value) {
+ onDemandModeOn = utils::getNumericValue<bool>(value);
+ });
+ }
+
void Handler::handleKeyPressed([[maybe_unused]] int key)
{
handleScreenLightRefresh(key);
@@ 32,16 52,26 @@ namespace backlight
{
auto controller = getScreenLightControl();
auto timer = getScreenLightTimer();
- if (!controller->isLightOn() && (key == static_cast<int>(KeyMap::Frontlight))) {
- controller->processRequest(screen_light_control::Action::turnOn);
- timer->restart(timers::screenLightTimerTimeout);
- }
- else if (controller->isLightOn()) {
- if (controller->isAutoModeOn() || key == static_cast<int>(KeyMap::Frontlight)) {
+
+ if (key == static_cast<int>(KeyMap::Frontlight)) {
+ if (controller->isLightOn()) {
+ setKeyPressedModeFrontlightOff();
controller->processRequest(screen_light_control::Action::turnOff);
timer->stop();
}
else {
+ setKeyPressedModeFrontlightOn();
+ controller->processRequest(screen_light_control::Action::turnOn);
+ timer->restart(onDemandModeOn ? timers::screenLightTimerTimeout : timers::screenLightTimerHoldTimeout);
+ }
+ }
+ else {
+ if (controller->isLightOn()) {
+ timer->restart(timers::screenLightTimerHoldTimeout);
+ }
+ else if (!onDemandModeOn) {
+ setKeyPressedModeFrontlightOn();
+ controller->processRequest(screen_light_control::Action::turnOn);
timer->restart(timers::screenLightTimerHoldTimeout);
}
}
@@ 54,10 84,59 @@ namespace backlight
getScreenLightControl()->processRequest(action, params);
}
+ void Handler::handleScreenLightSettings(screen_light_control::Action action,
+ const screen_light_control::Parameters ¶ms)
+ {
+ switch (action) {
+ case screen_light_control::Action::turnOn:
+ if (params.hasManualModeParams()) {
+ auto timer = getScreenLightTimer();
+ timer->stop();
+ backlightMode = BacklightMode::WithoutTimer;
+ }
+ break;
+ case screen_light_control::Action::setAutomaticModeParameters:
+ if (params.hasConstLinearProgressModeParams()) {
+ backlightMode = BacklightMode::WithTimer;
+ setValue(settings::Brightness::brightnessLevel,
+ utils::to_string(params.getConstLinearProgressModeParams().targetBrightness));
+ }
+ else if (params.hasLinearProgressModeParams()) {
+ backlightMode = BacklightMode::WithoutTimer;
+ }
+ break;
+ case screen_light_control::Action::enableAutomaticMode:
+ onDemandModeOn = false;
+ break;
+ case screen_light_control::Action::disableAutomaticMode:
+ onDemandModeOn = true;
+ break;
+ default:
+ break;
+ }
+
+ HandlerCommon::handleScreenLightSettings(action, params);
+ }
+
void Handler::onScreenLightTurnedOn()
{
- if (!getScreenLightControl()->isAutoModeOn()) {
+ if (backlightMode == BacklightMode::WithTimer) {
startScreenLightTimer();
}
}
+
+ void Handler::setKeyPressedModeFrontlightOn()
+ {
+ using namespace screen_light_control;
+ auto brightnessLevel = utils::getNumericValue<float>(getValue(settings::Brightness::brightnessLevel));
+ screen_light_control::ConstLinearProgressModeParameters params{brightnessLevel};
+ screenLightController->processRequest(Action::setAutomaticModeParameters, Parameters(params));
+ }
+
+ void Handler::setKeyPressedModeFrontlightOff()
+ {
+ using namespace screen_light_control;
+ screenLightController->processRequest(Action::setAutomaticModeParameters,
+ Parameters(screen_light_control::ConstLinearProgressModeParameters{0}));
+ }
} // namespace backlight
M products/BellHybrid/services/evtmgr/include/evtmgr/backlight-handler/BacklightHandler.hpp => products/BellHybrid/services/evtmgr/include/evtmgr/backlight-handler/BacklightHandler.hpp +16 -0
@@ 16,20 16,36 @@ namespace settings
namespace backlight
{
+ enum class BacklightMode
+ {
+ WithTimer,
+ WithoutTimer
+ };
/// @brief Backlight events handler
class Handler : public HandlerCommon
{
public:
Handler(std::shared_ptr<settings::Settings> settings, sys::Service *parent);
+ void init() override;
+
void handleKeyPressed(int key = 0);
void processScreenRequest(screen_light_control::Action action,
const screen_light_control::Parameters ¶ms) override;
+ void handleScreenLightSettings(screen_light_control::Action action,
+ const screen_light_control::Parameters ¶ms) override;
+
private:
void handleScreenLightRefresh(int key = 0);
void onScreenLightTurnedOn() override;
+
+ void setKeyPressedModeFrontlightOn();
+ void setKeyPressedModeFrontlightOff();
+
+ bool onDemandModeOn = true;
+ BacklightMode backlightMode = BacklightMode::WithTimer;
};
} // namespace backlight
M products/BellHybrid/services/evtmgr/screen-light-control/ScreenLightControl.cpp => products/BellHybrid/services/evtmgr/screen-light-control/ScreenLightControl.cpp +58 -56
@@ 5,17 5,24 @@
#include <Service/Service.hpp>
#include <Timers/TimerFactory.hpp>
+#include <Utils.hpp>
+
+#include <system/Constants.hpp>
+#include <system/messages/SentinelRegistrationMessage.hpp>
namespace bell::screen_light_control
{
ScreenLightController::ScreenLightController(sys::Service *parent)
+ : cpuSentinel(std::make_shared<sys::CpuSentinel>(screenLightControlName, parent))
{
- controlTimer = sys::TimerFactory::createPeriodicTimer(parent,
+ auto sentinelRegistrationMsg = std::make_shared<sys::SentinelRegistrationMessage>(cpuSentinel);
+ parent->bus.sendUnicast(std::move(sentinelRegistrationMsg), service::name::system_manager);
+
+ controlTimer = sys::TimerFactory::createPeriodicTimer(parent,
"LightControlTimer",
std::chrono::milliseconds{CONTROL_TIMER_MS},
[this](sys::Timer &) { controlTimerCallback(); });
-
- setParameters(ManualModeParameters{});
+ automaticMode = ScreenLightMode::Automatic;
}
ScreenLightController::~ScreenLightController()
@@ 38,37 45,35 @@ namespace bell::screen_light_control
turnOn(params.hasManualModeParams() ? std::optional<ManualModeParameters>(params.getManualModeParams())
: std::nullopt);
break;
- case Action::enableAutomaticMode:
- enableAutomaticMode();
- break;
- case Action::disableAutomaticMode:
- disableAutomaticMode();
- setManualBrightnessLevel(brightnessValue);
- break;
- case Action::setManualModeBrightness:
- if (params.hasManualModeParams()) {
- setParameters(params.getManualModeParams());
- }
- break;
case Action::setAutomaticModeParameters:
if (params.hasLinearProgressModeParams()) {
setParameters(params.getLinearProgressModeParams());
}
+ else if (params.hasConstLinearProgressModeParams()) {
+ setParameters(params.getConstLinearProgressModeParams());
+ }
+ break;
+ default:
break;
}
}
void ScreenLightController::controlTimerCallback()
{
- auto currentBrightness = ::screen_light_control::functions::brightnessRampOut();
+ auto newBrightness = ::screen_light_control::functions::brightnessRampOut();
+ bsp::eink_frontlight::setBrightness(newBrightness);
- bsp::eink_frontlight::setBrightness(currentBrightness);
if (::screen_light_control::functions::isRampTargetReached()) {
if (!automaticModeFunctions.empty()) {
- setUpAutomaticFunction(getNextAutomaticFunction(), currentBrightness);
+ setUpAutomaticFunction(getNextAutomaticFunction(), newBrightness);
}
else {
- disableAutomaticMode();
+ if (newBrightness == MINIMAL_TARGET) {
+ turnOff();
+ bsp::eink_frontlight::turnOff();
+ }
+ setBrightnessInstant(MINIMAL_TARGET);
+ disableTimers();
}
}
}
@@ 85,7 90,7 @@ namespace bell::screen_light_control
auto ScreenLightController::getBrightnessValue() const noexcept -> bsp::eink_frontlight::BrightnessPercentage
{
- return brightnessValue;
+ return brightnessWhenOn;
}
void ScreenLightController::enableTimers()
@@ 101,7 106,6 @@ namespace bell::screen_light_control
void ScreenLightController::setParameters(const LinearProgressModeParameters ¶ms)
{
if (params.functions.empty()) {
- LOG_ERROR("Functions are not defined. Cannot proceed with automatic mode.");
disableTimers();
return;
}
@@ 113,7 117,7 @@ namespace bell::screen_light_control
::screen_light_control::functions::setHysteresis(params.brightnessHysteresis);
setUpAutomaticFunction(getNextAutomaticFunction(), ::screen_light_control::functions::getRampState());
- setManualBrightnessLevel(params.startBrightnessValue);
+ setBrightnessInstant(getStandarizedRampTarget(params.startBrightnessValue));
if (lightOn && automaticMode == ScreenLightMode::Automatic) {
enableTimers();
@@ 137,61 141,59 @@ namespace bell::screen_light_control
::screen_light_control::functions::LinearProgressFunction function,
bsp::eink_frontlight::BrightnessPercentage currentBrightness)
{
+ const auto rampTarget = getStandarizedRampTarget(function.target);
::screen_light_control::functions::setRampStep(
- std::abs(function.target - currentBrightness) /
+ std::abs(rampTarget - currentBrightness) /
(static_cast<float>(function.duration.count()) / CONTROL_TIMER_MS));
- ::screen_light_control::functions::setRampTarget(function.target);
- }
-
- void ScreenLightController::setParameters(ManualModeParameters params)
- {
- brightnessValue = params.manualModeBrightness;
- ::screen_light_control::functions::setRampTarget(brightnessValue);
- setManualBrightnessLevel(brightnessValue);
- }
-
- void ScreenLightController::enableAutomaticMode()
- {
- if (lightOn) {
- enableTimers();
- }
- automaticMode = ScreenLightMode::Automatic;
+ ::screen_light_control::functions::setRampTarget(rampTarget);
}
- void ScreenLightController::disableAutomaticMode()
+ void ScreenLightController::setParameters(const ConstLinearProgressModeParameters ¶ms)
{
- disableTimers();
- automaticMode = ScreenLightMode::Manual;
- automaticModeFunctions.clear();
+ setBrightnessInstant(getStandarizedRampTarget(params.targetBrightness));
}
void ScreenLightController::turnOn(const std::optional<ManualModeParameters> ¶ms)
{
if (params.has_value()) {
- const auto brightness = params->manualModeBrightness;
- ::screen_light_control::functions::setRampTarget(brightness);
- setManualBrightnessLevel(brightness);
+ brightnessWhenOn = getStandarizedRampTarget(params->manualModeBrightness);
}
+ ::screen_light_control::functions::setRampTarget(brightnessWhenOn);
bsp::eink_frontlight::turnOn();
- if (automaticMode == ScreenLightMode::Automatic) {
- enableTimers();
- }
+ cpuSentinelKeepOn();
+ enableTimers();
lightOn = true;
}
- void ScreenLightController::setManualBrightnessLevel(bsp::eink_frontlight::BrightnessPercentage brightness)
+ void ScreenLightController::setBrightnessInstant(bsp::eink_frontlight::BrightnessPercentage brightness)
{
- bsp::eink_frontlight::setBrightness(brightness);
- ::screen_light_control::functions::setRampState(brightness);
+ brightnessWhenOn = getStandarizedRampTarget(brightness);
+ ::screen_light_control::functions::setRampTarget(brightnessWhenOn);
+ ::screen_light_control::functions::setRampStep(RAMP_STEP_PER_MS * CONTROL_TIMER_MS);
}
void ScreenLightController::turnOff()
{
- bsp::eink_frontlight::turnOff();
- disableAutomaticMode();
lightOn = false;
+ ::screen_light_control::functions::setRampTarget(MINIMAL_TARGET);
+ cpuSentinelRelease();
+ enableTimers();
+ }
- setManualBrightnessLevel(brightnessValue);
+ void ScreenLightController::cpuSentinelKeepOn()
+ {
+ cpuSentinel->HoldMinimumFrequency(bsp::CpuFrequencyHz::Level_6);
+ }
+
+ void ScreenLightController::cpuSentinelRelease()
+ {
+ cpuSentinel->ReleaseMinimumFrequency();
+ }
+
+ bsp::eink_frontlight::BrightnessPercentage ScreenLightController::getStandarizedRampTarget(
+ bsp::eink_frontlight::BrightnessPercentage target)
+ {
+ return std::max<bsp::eink_frontlight::BrightnessPercentage>(target, MINIMAL_TARGET);
}
-} // namespace screen_light_control
+} // namespace bell::screen_light_control
M products/BellHybrid/services/evtmgr/screen-light-control/ScreenLightControl.hpp => products/BellHybrid/services/evtmgr/screen-light-control/ScreenLightControl.hpp +22 -12
@@ 6,6 6,7 @@
#include <service-evtmgr/screen-light-control/ScreenLightControl.hpp>
#include <service-evtmgr/screen-light-control/ScreenLightControlParameters.hpp>
+#include <SystemManager/CpuSentinel.hpp>
#include <Timers/TimerHandle.hpp>
#include <memory>
@@ 19,15 20,18 @@ namespace sys
/// Processing of ambient light sensor input to screen brightness output.
namespace bell::screen_light_control
{
+ constexpr auto screenLightControlName = "ScreenLightControl";
+
/// Control screen light and keeps it's current state
class ScreenLightController : public ::screen_light_control::ScreenLightController
{
public:
- using Action = ::screen_light_control::Action;
- using Parameters = ::screen_light_control::Parameters;
- using ScreenLightMode = ::screen_light_control::ScreenLightMode;
- using ManualModeParameters = ::screen_light_control::ManualModeParameters;
- using LinearProgressModeParameters = ::screen_light_control::LinearProgressModeParameters;
+ using Action = ::screen_light_control::Action;
+ using Parameters = ::screen_light_control::Parameters;
+ using ScreenLightMode = ::screen_light_control::ScreenLightMode;
+ using ManualModeParameters = ::screen_light_control::ManualModeParameters;
+ using LinearProgressModeParameters = ::screen_light_control::LinearProgressModeParameters;
+ using ConstLinearProgressModeParameters = ::screen_light_control::ConstLinearProgressModeParameters;
explicit ScreenLightController(sys::Service *parent);
~ScreenLightController() override;
@@ 46,8 50,8 @@ namespace bell::screen_light_control
void disableTimers();
void setParameters(const LinearProgressModeParameters ¶ms);
- void setParameters(ManualModeParameters params);
- void setManualBrightnessLevel(bsp::eink_frontlight::BrightnessPercentage brightness);
+ void setParameters(const ConstLinearProgressModeParameters ¶ms);
+ void setBrightnessInstant(bsp::eink_frontlight::BrightnessPercentage brightness);
void setAutomaticModeFunctions(const LinearProgressModeParameters::LinearFunctions &functions);
::screen_light_control::functions::LinearProgressFunction getNextAutomaticFunction();
@@ 57,15 61,21 @@ namespace bell::screen_light_control
void turnOff();
void turnOn(const std::optional<ManualModeParameters> ¶ms = std::nullopt);
- void enableAutomaticMode();
- void disableAutomaticMode();
+ void cpuSentinelKeepOn();
+ void cpuSentinelRelease();
+
+ bsp::eink_frontlight::BrightnessPercentage getStandarizedRampTarget(
+ bsp::eink_frontlight::BrightnessPercentage target);
static constexpr inline auto CONTROL_TIMER_MS = 25;
+ static constexpr inline auto RAMP_STEP_PER_MS = 0.1;
+ static constexpr inline auto MINIMAL_TARGET = 15;
sys::TimerHandle controlTimer;
- bool lightOn = false;
- ScreenLightMode automaticMode = ScreenLightMode::Manual;
- bsp::eink_frontlight::BrightnessPercentage brightnessValue = 0.0;
+ std::shared_ptr<sys::CpuSentinel> cpuSentinel;
+ bool lightOn = false;
+ ScreenLightMode automaticMode = ScreenLightMode::Manual;
+ bsp::eink_frontlight::BrightnessPercentage brightnessWhenOn = MINIMAL_TARGET;
LinearProgressModeParameters::LinearFunctions automaticModeFunctions;
};
} // namespace bell::screen_light_control
M products/PurePhone/services/evtmgr/backlight-handler/BacklightHandler.cpp => products/PurePhone/services/evtmgr/backlight-handler/BacklightHandler.cpp +33 -2
@@ 18,14 18,45 @@ namespace backlight
} // namespace timers
Handler::Handler(std::shared_ptr<settings::Settings> settings, sys::Service *parent)
- : HandlerCommon(
- std::move(settings), std::make_shared<pure::screen_light_control::ScreenLightController>(parent), parent),
+ : HandlerCommon(std::move(settings),
+ std::make_shared<pure::screen_light_control::ScreenLightController>(parent),
+ parent,
+ [this](sys::Timer &t) {
+ if (getScreenAutoModeState() == screen_light_control::ScreenLightMode::Automatic &&
+ this->screenLightController->isLightOn()) {
+ this->screenLightController->processRequest(screen_light_control::Action::turnOff);
+ }
+ }),
keypadLightTimer{sys::TimerFactory::createSingleShotTimer(
parent, timers::keypadLightTimerName, timers::keypadLightTimerTimeout, [this](sys::Timer &) {
bsp::keypad_backlight::shutdown();
})}
{}
+ void Handler::init()
+ {
+ using namespace screen_light_control;
+
+ settings->registerValueChange(settings::Brightness::brightnessLevel, [&](const std::string &value) {
+ ManualModeParameters params{utils::getNumericValue<float>(value)};
+ screenLightController->processRequest(Action::setManualModeBrightness, Parameters(params));
+ });
+
+ settings->registerValueChange(settings::Brightness::autoMode, [&]([[maybe_unused]] const std::string &value) {
+ const auto action = getScreenAutoModeState() == ScreenLightMode::Automatic ? Action::enableAutomaticMode
+ : Action::disableAutomaticMode;
+ screenLightController->processRequest(action);
+ });
+
+ settings->registerValueChange(settings::Brightness::state, [&]([[maybe_unused]] const std::string &value) {
+ const auto action = getScreenLightState() ? Action::turnOn : Action::turnOff;
+ if (action == Action::turnOn) {
+ onScreenLightTurnedOn();
+ }
+ screenLightController->processRequest(action);
+ });
+ }
+
void Handler::handleKeyPressed([[maybe_unused]] int key)
{
handleKeypadLightRefresh();
M products/PurePhone/services/evtmgr/include/evtmgr/BacklightHandler.hpp => products/PurePhone/services/evtmgr/include/evtmgr/BacklightHandler.hpp +1 -1
@@ 22,6 22,7 @@ namespace backlight
public:
Handler(std::shared_ptr<settings::Settings> settings, sys::Service *parent);
+ void init() override;
void handleKeyPressed(int key = 0);
/// Process request of the keypad light control
/// @keypad_backlight::action an action to perform
@@ 32,7 33,6 @@ namespace backlight
const screen_light_control::Parameters ¶ms) override;
private:
- std::shared_ptr<settings::Settings> settings;
/// Timer that keeps key backlight on for a certain time if there was key pressed
sys::TimerHandle keypadLightTimer;
/// Timer that keeps screen backlight on for a certain time if there was key pressed