Skip to content

Commit 17a7c2b

Browse files
committed
[BH-2085] Set lower minimum brightness for Pro version
* Added ENABLE_VERSION_PRO build flag that selects different config for 2 Pro device. * Reduced lowest brightness level for Pro 2 device. * Changed the format in which brightness values are stored in database - previously it was stored as PWM percentage, now 1-10 scale system level is used.
1 parent 5aab08b commit 17a7c2b

File tree

26 files changed

+245
-142
lines changed

26 files changed

+245
-142
lines changed

CMakeLists.txt

+10-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,16 @@ include(AddDatabases)
3636
include(FetchContent)
3737
include(AddScripts)
3838

39+
option(ENABLE_VERSION_PRO "Enable configuration for Pro version" OFF)
40+
if (ENABLE_VERSION_PRO)
41+
add_compile_definitions(CONFIG_VERSION_PRO=1)
42+
endif()
43+
3944
message("Selected product: ${PRODUCT}")
4045
message("Selected board: ${BOARD}")
46+
if (${PRODUCT} STREQUAL "BellHybrid")
47+
message("Pro config: ${ENABLE_VERSION_PRO}")
48+
endif()
4149
message("Board revision: ${BOARD_REVISION}")
4250
message("PROJECT_TARGET: ${PROJECT_TARGET}")
4351
message("Assets version: ${ASSETS_TYPE}")
@@ -112,12 +120,12 @@ add_compile_options(
112120

113121
include_directories(${CMAKE_SOURCE_DIR})
114122

115-
option (GENERATE_STACK_USAGE "Generate stack usage report" OFF)
123+
option(GENERATE_STACK_USAGE "Generate stack usage report" OFF)
116124
if (GENERATE_STACK_USAGE)
117125
add_compile_options (-fstack-usage)
118126
endif ()
119127

120-
option (ENABLE_SECURE_BOOT "Build signed binary for Secure Boot" OFF)
128+
option(ENABLE_SECURE_BOOT "Build signed binary for Secure Boot" OFF)
121129
set(SIGN_CLIENT_PATH "${CMAKE_SOURCE_DIR}/../sign_server/key_client" CACHE PATH "signclient.py path")
122130
set(SERVER "https://10.20.50.10:4430" CACHE STRING "sign server address")
123131

module-services/service-evtmgr/backlight-handler/BacklightHandlerCommon.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <service-db/agents/settings/SystemSettings.hpp>
66
#include <service-db/Settings.hpp>
77
#include <Timers/TimerFactory.hpp>
8+
#include <FrontlightUtils.hpp>
89
#include <Utils.hpp>
910

1011
namespace backlight
@@ -55,7 +56,8 @@ namespace backlight
5556

5657
auto HandlerCommon::getScreenBrightnessValue() const noexcept -> bsp::eink_frontlight::BrightnessPercentage
5758
{
58-
return utils::getNumericValue<float>(getValue(settings::Brightness::brightnessLevel));
59+
const auto brightnessValue = utils::toNumeric(getValue(settings::Brightness::brightnessLevel));
60+
return utils::frontlight::fixedValToPercentage(brightnessValue);
5961
}
6062

6163
void HandlerCommon::handleScreenLightRefresh()
@@ -89,8 +91,9 @@ namespace backlight
8991
break;
9092
case screen_light_control::Action::setManualModeBrightness:
9193
if (params.hasManualModeParams()) {
92-
setValue(settings::Brightness::brightnessLevel,
93-
utils::to_string(params.getManualModeParams().manualModeBrightness));
94+
const auto brightnessValue =
95+
utils::frontlight::percentageToFixedVal(params.getManualModeParams().manualModeBrightness);
96+
setValue(settings::Brightness::brightnessLevel, utils::to_string(brightnessValue));
9497
}
9598
else {
9699
LOG_ERROR("Missing ManualModeBrightness value, change request ignored");

module-utils/utility/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ target_sources(utility
1616
Units.hpp
1717
Anonymize.hpp
1818
Version.hpp
19+
FrontlightUtils.hpp
1920
)
2021

2122
target_include_directories(utility
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
2+
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md
3+
4+
#pragma once
5+
6+
#include <cmath>
7+
#include <cstdint>
8+
#include <algorithm>
9+
10+
namespace utils::frontlight
11+
{
12+
#if defined(CONFIG_VERSION_PRO) && (CONFIG_VERSION_PRO == 1)
13+
inline constexpr auto minimumLightOnPercentOffsetValue = 8.0f;
14+
#else
15+
inline constexpr auto minimumLightOnPercentOffsetValue = 16.0f;
16+
#endif
17+
inline constexpr auto minPercent = 0.0f;
18+
inline constexpr auto maxPercent = 100.0f;
19+
inline constexpr auto minBrightness = 1U;
20+
inline constexpr auto maxBrightness = 10U;
21+
inline constexpr float multiplier = (maxPercent - minimumLightOnPercentOffsetValue) / maxBrightness;
22+
23+
static inline float fixedValToPercentage(std::uint8_t value)
24+
{
25+
const float valueScaled =
26+
(static_cast<float>(value) - minBrightness) * multiplier + minimumLightOnPercentOffsetValue;
27+
return std::clamp(valueScaled, minPercent, maxPercent);
28+
}
29+
30+
static inline std::uint8_t percentageToFixedVal(float percent)
31+
{
32+
const float value = (percent - minimumLightOnPercentOffsetValue) / multiplier;
33+
return static_cast<std::uint8_t>(std::round(value + minBrightness));
34+
}
35+
} // namespace utils::frontlight

products/BellHybrid/alarms/src/actions/FrontlightAction.cpp

+24-18
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,33 @@
33

44
#include "FrontlightAction.hpp"
55
#include "BellAlarmConstants.hpp"
6-
76
#include <service-evtmgr/ScreenLightControlMessage.hpp>
87
#include <service-evtmgr/ServiceEventManagerName.hpp>
9-
108
#include <service-db/Settings.hpp>
119
#include <db/SystemSettings.hpp>
10+
#include <module-utils/utility/FrontlightUtils.hpp>
1211
#include <module-utils/utility/Utils.hpp>
1312

1413
namespace alarms
1514
{
1615
namespace
1716
{
18-
constexpr std::string_view alarmFrontlightOff = "0";
19-
constexpr std::string_view prewakeupFrontlightOff = "0";
17+
constexpr auto alarmFrontlightOff = std::string_view{"0"};
18+
constexpr auto prewakeupFrontlightOff = std::string_view{"0"};
2019

2120
/* Reach and maintain target brightness 1 minute faster than
2221
* the duration of the action. */
2322
constexpr auto frontlightRampDurationOffset = std::chrono::minutes{1};
2423
constexpr auto initialTargetDuration = std::chrono::seconds{5};
25-
constexpr auto initialZeroBrightnessValue = 10;
24+
#if defined(CONFIG_VERSION_PRO) && (CONFIG_VERSION_PRO == 1)
25+
constexpr auto initialZeroBrightnessValue = 5.0f;
26+
#else
27+
constexpr auto initialZeroBrightnessValue = 10.0f;
28+
#endif
2629

27-
void validateBrightness(std::string &brightness)
30+
inline void validateBrightness(std::string &brightness)
2831
{
29-
constexpr auto defaultBrightness = std::string_view{"50.0"};
32+
constexpr auto defaultBrightness = std::string_view{"5"};
3033

3134
if (brightness.empty()) {
3235
brightness = defaultBrightness;
@@ -163,9 +166,9 @@ namespace alarms
163166

164167
auto brightnessString = settings.getValue(bell::settings::Alarm::brightness, settings::SettingsScope::Global);
165168
validateBrightness(brightnessString);
166-
screen_light_control::ManualModeParameters params{};
167-
params.manualModeBrightness = static_cast<BrightnessPercentage>(utils::toNumeric(brightnessString));
168169

170+
screen_light_control::ManualModeParameters params{
171+
.manualModeBrightness = utils::frontlight::fixedValToPercentage(utils::toNumeric(brightnessString))};
169172
return params;
170173
}
171174

@@ -239,17 +242,18 @@ namespace alarms
239242
auto initialBrightnessString =
240243
settings.getValue(bell::settings::PrewakeUp::brightness, settings::SettingsScope::Global);
241244
validateBrightness(initialBrightnessString);
242-
initialBrightness = utils::toNumeric(initialBrightnessString);
245+
initialBrightness = utils::frontlight::fixedValToPercentage(utils::toNumeric(initialBrightnessString));
243246
}
244247

245248
auto targetBrightnessString =
246249
settings.getValue(bell::settings::Alarm::brightness, settings::SettingsScope::Global);
247250
validateBrightness(targetBrightnessString);
251+
const auto targetBrightness = utils::frontlight::fixedValToPercentage(utils::toNumeric(targetBrightnessString));
248252

249-
const screen_light_control::functions::LinearProgressFunction startFunction{
250-
.target = static_cast<float>(initialBrightness), .duration = initialTargetDuration};
251-
const screen_light_control::functions::LinearProgressFunction endFunction{
252-
.target = static_cast<float>(utils::toNumeric(targetBrightnessString)), .duration = mainTargetDuration};
253+
const screen_light_control::functions::LinearProgressFunction startFunction{.target = initialBrightness,
254+
.duration = initialTargetDuration};
255+
const screen_light_control::functions::LinearProgressFunction endFunction{.target = targetBrightness,
256+
.duration = mainTargetDuration};
253257

254258
return screen_light_control::LinearProgressModeParameters{.startBrightnessValue =
255259
static_cast<float>(initialBrightness),
@@ -262,14 +266,16 @@ namespace alarms
262266
auto brightnessString =
263267
settings.getValue(bell::settings::PrewakeUp::brightness, settings::SettingsScope::Global);
264268
validateBrightness(brightnessString);
265-
const auto value = settings.getValue(bell::settings::PrewakeUp::lightDuration, settings::SettingsScope::Global);
266-
const auto lightDuration = std::chrono::minutes{utils::toNumeric(value)};
269+
const auto brightnessValue = utils::frontlight::fixedValToPercentage(utils::toNumeric(brightnessString));
270+
const auto durationString =
271+
settings.getValue(bell::settings::PrewakeUp::lightDuration, settings::SettingsScope::Global);
272+
const auto lightDuration = std::chrono::minutes{utils::toNumeric(durationString)};
267273
const auto mainTargetDuration = lightDuration - frontlightRampDurationOffset - initialTargetDuration;
268274

269275
const screen_light_control::functions::LinearProgressFunction startFunction{
270276
.target = initialZeroBrightnessValue, .duration = initialTargetDuration};
271-
const screen_light_control::functions::LinearProgressFunction endFunction{
272-
.target = static_cast<float>(utils::toNumeric(brightnessString)), .duration = mainTargetDuration};
277+
const screen_light_control::functions::LinearProgressFunction endFunction{.target = brightnessValue,
278+
.duration = mainTargetDuration};
273279

274280
return screen_light_control::LinearProgressModeParameters{
275281
.startBrightnessValue = 0.0f, .functions = {startFunction, endFunction}, .brightnessHysteresis = 0.0f};

products/BellHybrid/apps/application-bell-powernap/models/PowerNapFrontlightModel.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <apps-common/ApplicationCommon.hpp>
88
#include <service-evtmgr/ScreenLightControlMessage.hpp>
99
#include <service-evtmgr/ServiceEventManagerName.hpp>
10+
#include <FrontlightUtils.hpp>
11+
#include <Utils.hpp>
1012

1113
namespace app::powernap
1214
{
@@ -59,25 +61,30 @@ namespace app::powernap
5961
service::name::evt_manager);
6062
}
6163

62-
auto PowerNapFrontlightModel::getAlarmBrightness() const -> int
64+
auto PowerNapFrontlightModel::getAlarmBrightness() const -> float
6365
{
64-
const auto brightness = settings.getValue(bell::settings::Alarm::brightness, settings::SettingsScope::Global);
65-
return utils::toNumeric(brightness);
66+
const auto &brightnessString =
67+
settings.getValue(bell::settings::Alarm::brightness, settings::SettingsScope::Global);
68+
return utils::frontlight::fixedValToPercentage(utils::toNumeric(brightnessString));
6669
}
6770

6871
auto PowerNapFrontlightModel::prepareFadeInParameters() const -> screen_light_control::LinearProgressModeParameters
6972
{
7073
constexpr auto targetReachTimeOffset = std::chrono::minutes{1};
7174
constexpr auto startFunctionDuration = std::chrono::seconds{5};
72-
constexpr auto startFunctionTarget = 10.0f;
7375

76+
#if defined(CONFIG_VERSION_PRO) && (CONFIG_VERSION_PRO == 1)
77+
constexpr auto startFunctionTarget = 5.0f;
78+
#else
79+
constexpr auto startFunctionTarget = 10.0f;
80+
#endif
7481
const auto brightness = getAlarmBrightness();
7582
const auto endFunctionDuration = alarmDuration - targetReachTimeOffset - startFunctionDuration;
7683

7784
const screen_light_control::functions::LinearProgressFunction startFunction{.target = startFunctionTarget,
7885
.duration = startFunctionDuration};
79-
const screen_light_control::functions::LinearProgressFunction endFunction{
80-
.target = static_cast<float>(brightness), .duration = endFunctionDuration};
86+
const screen_light_control::functions::LinearProgressFunction endFunction{.target = brightness,
87+
.duration = endFunctionDuration};
8188

8289
return screen_light_control::LinearProgressModeParameters{
8390
.startBrightnessValue = 0.0f, .functions = {startFunction, endFunction}, .brightnessHysteresis = 0.0f};

products/BellHybrid/apps/application-bell-powernap/models/PowerNapFrontlightModel.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace app::powernap
3030
const std::chrono::seconds alarmDuration;
3131
mutable settings::Settings settings;
3232

33-
auto getAlarmBrightness() const -> int;
33+
auto getAlarmBrightness() const -> float;
3434
auto prepareFadeInParameters() const -> screen_light_control::LinearProgressModeParameters;
3535
};
3636
} // namespace app::powernap

products/BellHybrid/apps/application-bell-settings/models/BedsideModel.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

88
namespace app::bell_settings
99
{
10-
auto BedsideBrightnessModel::setValue(frontlight_utils::Brightness value) -> void
10+
auto BedsideBrightnessModel::setValue(std::uint8_t value) -> void
1111
{
12-
const auto str = std::to_string(frontlight_utils::fixedValToPercentage(value));
12+
const auto str = std::to_string(value);
1313
settings.setValue(settings::Brightness::bedsideBrightnessLevel, str, settings::SettingsScope::Global);
1414
}
1515

16-
auto BedsideBrightnessModel::getValue() const -> frontlight_utils::Brightness
16+
auto BedsideBrightnessModel::getValue() const -> std::uint8_t
1717
{
1818
const auto str =
1919
settings.getValue(settings::Brightness::bedsideBrightnessLevel, settings::SettingsScope::Global);
20-
return frontlight_utils::percentageToFixedVal(static_cast<float>(utils::toNumeric(str)));
20+
return utils::toNumeric(str);
2121
}
2222

2323
auto BedsideTimeModel::setValue(std::uint8_t value) -> void

products/BellHybrid/apps/application-bell-settings/models/FrontlightModel.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md
33

44
#include <common/models/FrontlightModel.hpp>
5-
65
#include <apps-common/ApplicationCommon.hpp>
76
#include <service-evtmgr/screen-light-control/ScreenLightControl.hpp>
87
#include <service-evtmgr/ServiceEventManagerName.hpp>
98
#include <service-evtmgr/ScreenLightControlMessage.hpp>
9+
#include <FrontlightUtils.hpp>
1010

1111
namespace app::bell_settings
1212
{
@@ -18,8 +18,8 @@ namespace app::bell_settings
1818
{
1919
const auto responseCallback = [this](const auto response) -> bool {
2020
const auto resp = dynamic_cast<sevm::ScreenLightControlParametersResponse *>(response);
21-
if (resp) {
22-
const auto brightness = frontlight_utils::percentageToFixedVal(resp->getParams().manualModeBrightness);
21+
if (resp != nullptr) {
22+
const auto brightness = utils::frontlight::percentageToFixedVal(resp->getParams().manualModeBrightness);
2323
this->brightnessAdapter->update(brightness);
2424
this->modeAdapter->update(
2525
resp->getMode() == screen_light_control::ScreenLightMode::Automatic ? autoStr : onDemandStr);
@@ -53,10 +53,10 @@ namespace app::bell_settings
5353
service::name::evt_manager);
5454
}
5555

56-
void FrontlightModel::setBrightness(frontlight_utils::Brightness value)
56+
void FrontlightModel::setBrightness(std::uint8_t value)
5757
{
5858
const screen_light_control::ConstLinearProgressModeParameters parameters{
59-
frontlight_utils::fixedValToPercentage(value)};
59+
utils::frontlight::fixedValToPercentage(value)};
6060
app->bus.sendUnicast(std::make_shared<sevm::ScreenLightSetConstLinearModeParams>(parameters),
6161
service::name::evt_manager);
6262
}

products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AbstractAlarmSettingsModel.hpp

+8-11
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@
44
#pragma once
55

66
#include <common/models/AbstractSettingsModel.hpp>
7-
#include <common/data/FrontlightUtils.hpp>
8-
9-
#include <cstdint>
107
#include <utf8/UTF8.hpp>
8+
#include <cstdint>
119

1210
namespace app::bell_settings
1311
{
1412
class AbstractAlarmSettingsModel
1513
{
1614
public:
17-
AbstractAlarmSettingsModel(
18-
std::unique_ptr<gui::AbstractSettingsModel<UTF8>> alarmTone,
19-
std::unique_ptr<gui::AbstractSettingsModel<std::uint8_t>> alarmVolume,
20-
std::unique_ptr<gui::AbstractSettingsModel<bool>> alarmFadeOnOff,
21-
std::unique_ptr<gui::AbstractSettingsModel<bool>> alarmLightOnOff,
22-
std::unique_ptr<gui::AbstractSettingsModel<frontlight_utils::Brightness>> alarmFrontlight)
15+
AbstractAlarmSettingsModel(std::unique_ptr<gui::AbstractSettingsModel<UTF8>> alarmTone,
16+
std::unique_ptr<gui::AbstractSettingsModel<std::uint8_t>> alarmVolume,
17+
std::unique_ptr<gui::AbstractSettingsModel<bool>> alarmFadeOnOff,
18+
std::unique_ptr<gui::AbstractSettingsModel<bool>> alarmLightOnOff,
19+
std::unique_ptr<gui::AbstractSettingsModel<std::uint8_t>> alarmFrontlight)
2320
: alarmTone(std::move(alarmTone)), alarmVolume(std::move(alarmVolume)),
2421
alarmFadeOnOff(std::move(alarmFadeOnOff)), alarmLightOnOff(std::move(alarmLightOnOff)),
2522
alarmFrontlight(std::move(alarmFrontlight))
@@ -47,7 +44,7 @@ namespace app::bell_settings
4744
return *alarmLightOnOff;
4845
}
4946

50-
gui::AbstractSettingsModel<frontlight_utils::Brightness> &getBrightness()
47+
gui::AbstractSettingsModel<std::uint8_t> &getBrightness()
5148
{
5249
return *alarmFrontlight;
5350
}
@@ -57,6 +54,6 @@ namespace app::bell_settings
5754
std::unique_ptr<gui::AbstractSettingsModel<std::uint8_t>> alarmVolume;
5855
std::unique_ptr<gui::AbstractSettingsModel<bool>> alarmFadeOnOff;
5956
std::unique_ptr<gui::AbstractSettingsModel<bool>> alarmLightOnOff;
60-
std::unique_ptr<gui::AbstractSettingsModel<frontlight_utils::Brightness>> alarmFrontlight;
57+
std::unique_ptr<gui::AbstractSettingsModel<std::uint8_t>> alarmFrontlight;
6158
};
6259
} // namespace app::bell_settings

0 commit comments

Comments
 (0)