[Feature] Backlight settings (#137)

* Added backlight settings

* Changed location of the brightness setting

* Fix row size of brightness settings

* [apps/settings/brightness] Update translations

* Fix dimmer

* Update translations

* [apps/settings] Add dimmer duration setting

* [apps/settings] Ensure of the brightness level is greater than the dimmed brightness level

* Make transition smooth

* Removed transition time setting
I personally think that this setting is completely useless except if you absolutely want a transition that is not smooth, which is weird.

* Moved everything related to brightness in one submenu

* Some refactoring

* Update defaults

* Removed unnecessary translation

* [apps/settings] Fix Shift + Minus/Plus in settings

* Apply suggestions from code review

* [apps/shared] Remove a think that I don't know what it is

* Apply review suggestions

Co-authored-by: Joachim LF <joachimlf@pm.me>
Co-authored-by: lolocomotive <lolocomotive181@gmail.com>
This commit is contained in:
Yaya-Cout
2022-03-22 17:59:52 +01:00
committed by GitHub
parent 865bacf89a
commit 8ac969d772
26 changed files with 288 additions and 80 deletions

View File

@@ -266,7 +266,8 @@ bool AppsContainer::processEvent(Ion::Events::Event event) {
}
if (event == Ion::Events::BrightnessPlus || event == Ion::Events::BrightnessMinus) {
int delta = Ion::Backlight::MaxBrightness/GlobalPreferences::NumberOfBrightnessStates;
int direction = (event == Ion::Events::BrightnessPlus) ? Ion::Backlight::NumberOfStepsPerShortcut*delta : -delta*Ion::Backlight::NumberOfStepsPerShortcut;
int NumberOfStepsPerShortcut = GlobalPreferences::sharedGlobalPreferences()->brightnessShortcut();
int direction = (event == Ion::Events::BrightnessPlus) ? NumberOfStepsPerShortcut*delta : -delta*NumberOfStepsPerShortcut;
GlobalPreferences::sharedGlobalPreferences()->setBrightnessLevel(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel()+direction);
}
return false;
@@ -353,6 +354,8 @@ bool AppsContainer::updateBatteryState() {
}
void AppsContainer::refreshPreferences() {
m_suspendTimer.reset(GlobalPreferences::sharedGlobalPreferences()->idleBeforeSuspendSeconds()*1000/Timer::TickDuration);
m_backlightDimmingTimer.reset(GlobalPreferences::sharedGlobalPreferences()->idleBeforeDimmingSeconds()*1000/Timer::TickDuration);
m_window.refreshPreferences();
}

View File

@@ -1,39 +1,26 @@
#include "backlight_dimming_timer.h"
#include "global_preferences.h"
#include <ion/backlight.h>
#include <ion/events.h>
#include <apps/apps_container.h>
BacklightDimmingTimer::BacklightDimmingTimer() :
Timer(k_idleBeforeDimmingDuration/Timer::TickDuration)
Timer(GlobalPreferences::sharedGlobalPreferences()->idleBeforeDimmingSeconds()*1000/Timer::TickDuration)
{
}
bool BacklightDimmingTimer::fire() {
if (m_dimerExecutions == 0) {
m_brightnessLevel = GlobalPreferences::sharedGlobalPreferences()->brightnessLevel();
m_dimerSteps = m_brightnessLevel / decreaseBy;
m_timeToSleep = decreasetime / m_dimerSteps;
m_period = m_timeToSleep / Timer::TickDuration;
if (m_period == 0) {
m_period = 1;
bool BacklightDimmingTimer::fire(){
int i = Ion::Backlight::brightness();
while (i > 0){
int t = 20;
Ion::Events::Event e = Ion::Events::getEvent(&t);
AppsContainer::sharedAppsContainer()->dispatchEvent(e);
if (e.isKeyboardEvent()){
return false;
}
resetTimer();
Ion::Backlight::setBrightness(i);
i -= 15;
}
if (m_dimerExecutions < m_dimerSteps) {
m_nextbrightness = (m_brightnessLevel-k_dimBacklightBrightness)/m_dimerSteps * (m_dimerSteps-m_dimerExecutions);
Ion::Backlight::setBrightness(m_nextbrightness);
resetTimer();
} else if (m_dimerExecutions == m_dimerSteps) {
Ion::Backlight::setBrightness(k_dimBacklightBrightness);
}
m_dimerExecutions++;
return false;
}
void BacklightDimmingTimer::reset() {
m_dimerExecutions = 0;
m_period = k_idleBeforeDimmingDuration / Timer::TickDuration;
resetTimer();
}
void BacklightDimmingTimer::resetTimer() {
BacklightDimmingTimer::m_numberOfTicksBeforeFire = BacklightDimmingTimer::m_period;
}

View File

@@ -6,19 +6,8 @@
class BacklightDimmingTimer : public Timer {
public:
BacklightDimmingTimer();
void reset();
private:
constexpr static int k_idleBeforeDimmingDuration = 30*1000; // In miliseconds
constexpr static int k_dimBacklightBrightness = 0;
constexpr static int decreaseBy = 15;
constexpr static int decreasetime = 1*1000; // In miliseconds
int m_dimerExecutions = 0;
int m_brightnessLevel;
int m_dimerSteps;
int m_nextbrightness;
float m_timeToSleep; // In miliseconds
bool fire() override;
void resetTimer();
};
#endif

View File

@@ -41,6 +41,25 @@ void GlobalPreferences::setBrightnessLevel(int brightnessLevel) {
brightnessLevel = brightnessLevel < 0 ? 0 : brightnessLevel;
brightnessLevel = brightnessLevel > Ion::Backlight::MaxBrightness ? Ion::Backlight::MaxBrightness : brightnessLevel;
m_brightnessLevel = brightnessLevel;
Ion::Backlight::setBrightness(m_brightnessLevel);
}
}
void GlobalPreferences::setIdleBeforeSuspendSeconds(int idleBeforeSuspendSeconds) {
if (m_idleBeforeSuspendSeconds != idleBeforeSuspendSeconds) {
idleBeforeSuspendSeconds = idleBeforeSuspendSeconds < 5 ? 5 : idleBeforeSuspendSeconds;
idleBeforeSuspendSeconds = idleBeforeSuspendSeconds > 7200 ? 7200 : idleBeforeSuspendSeconds;
m_idleBeforeSuspendSeconds = idleBeforeSuspendSeconds;
}
}
void GlobalPreferences::setIdleBeforeDimmingSeconds(int idleBeforeDimmingSeconds) {
if (m_idleBeforeDimmingSeconds != idleBeforeDimmingSeconds) {
idleBeforeDimmingSeconds = idleBeforeDimmingSeconds < 3 ? 3 : idleBeforeDimmingSeconds;
idleBeforeDimmingSeconds = idleBeforeDimmingSeconds > 1200 ? 1200 : idleBeforeDimmingSeconds;
m_idleBeforeDimmingSeconds = idleBeforeDimmingSeconds;
}
}
void GlobalPreferences::setBrightnessShortcut(int brightnessShortcut){
m_brightnessShortcut = brightnessShortcut;
}

View File

@@ -45,6 +45,12 @@ public:
const KDFont * font() const { return m_font; }
void setFont(const KDFont * font) { m_font = font; }
constexpr static int NumberOfBrightnessStates = 15;
int idleBeforeSuspendSeconds() const { return m_idleBeforeSuspendSeconds; }
void setIdleBeforeSuspendSeconds(int m_idleBeforeSuspendSeconds);
int idleBeforeDimmingSeconds() const { return m_idleBeforeDimmingSeconds; }
void setIdleBeforeDimmingSeconds(int m_idleBeforeDimmingSeconds);
int brightnessShortcut() const { return m_brightnessShortcut; }
void setBrightnessShortcut(int m_BrightnessShortcut);
private:
static_assert(I18n::NumberOfLanguages > 0, "I18n::NumberOfLanguages is not superior to 0"); // There should already have been an error when processing an empty EPSILON_I18N flag
static_assert(I18n::NumberOfCountries > 0, "I18n::NumberOfCountries is not superior to 0"); // There should already have been an error when processing an empty EPSILON_COUNTRIES flag
@@ -60,6 +66,9 @@ private:
m_syntaxhighlighting(true),
m_cursorSaving(true),
m_brightnessLevel(Ion::Backlight::MaxBrightness),
m_idleBeforeSuspendSeconds(55),
m_idleBeforeDimmingSeconds(45),
m_brightnessShortcut(4),
m_font(KDFont::LargeFont) {}
I18n::Language m_language;
I18n::Country m_country;
@@ -74,6 +83,9 @@ private:
bool m_syntaxhighlighting;
bool m_cursorSaving;
int m_brightnessLevel;
int m_idleBeforeSuspendSeconds;
int m_idleBeforeDimmingSeconds;
int m_brightnessShortcut;
const KDFont * m_font;
};

View File

@@ -26,6 +26,7 @@ app_settings_src = $(addprefix apps/settings/,\
sub_menu/math_options_controller.cpp \
sub_menu/selectable_view_with_messages.cpp \
sub_menu/usb_protection_controller.cpp \
sub_menu/brightness_controller.cpp\
)
SFLAGS += -DOMEGA_STATE="$(OMEGA_STATE)"

View File

@@ -32,6 +32,7 @@ Real = "Reell "
Cartesian = "Kartesisch "
Polar = "Polar "
Brightness = "Helligkeit"
BrightnessSettings = "Helligkeitseinstellungen"
SoftwareVersion = "Epsilon version"
UpsilonVersion = "Upsilon version"
OmegaVersion = "Omega version"
@@ -79,3 +80,7 @@ USBProtectionLevel = "Akzeptierte Updates"
USBDefaultLevel = "Basierend auf Upsilon"
USBLowLevel = "Basierend auf Omega"
USBParanoidLevel = "Nichts"
Normal = "Normal"
IdleTimeBeforeDimming = "Abdunkeln nach (s)"
IdleTimeBeforeSuspend = "Anhalten nach (s)"
BrightnessShortcut = "Tastenkombinationsschritte"

View File

@@ -32,6 +32,7 @@ Real = "Real "
Cartesian = "Cartesian "
Polar = "Polar "
Brightness = "Brightness"
BrightnessSettings = "Brightness settings"
SoftwareVersion = "Epsilon version"
UpsilonVersion = "Upsilon version"
OmegaVersion = "Omega version"
@@ -79,3 +80,7 @@ USBProtectionLevel = "Updates accepted"
USBDefaultLevel = "Based on Upsilon"
USBLowLevel = "Based on Omega"
USBParanoidLevel = "None"
Normal = "Normal"
IdleTimeBeforeDimming = "Dim after (s)"
IdleTimeBeforeSuspend = "Suspend after (s)"
BrightnessShortcut = "Shortcut steps"

View File

@@ -32,6 +32,7 @@ Real = "Real "
Cartesian = "Binómica "
Polar = "Polar "
Brightness = "Brillo"
BrightnessSettings = "Configuración de brillo"
SoftwareVersion = "Versión de Epsilon"
UpsilonVersion = "Versión de Upsilon"
OmegaVersion = "Versión de Omega"
@@ -79,3 +80,7 @@ USBProtectionLevel = "Actualizaciones aceptadas"
USBDefaultLevel = "Basado en Upsilon"
USBLowLevel = "Basado en Omega"
USBParanoidLevel = "Ninguno"
Normal = "Normal"
IdleTimeBeforeDimming = "Oscurecer después de (s)"
IdleTimeBeforeSuspend = "Suspender después de (s)"
BrightnessShortcut = "Pasos de acceso directo"

View File

@@ -32,6 +32,7 @@ Real = "Réel "
Cartesian = "Algébrique "
Polar = "Exponentielle "
Brightness = "Luminosité"
BrightnessSettings = "Paramètres de luminosité"
SoftwareVersion = "Version d'Epsilon"
UpsilonVersion = "Version d'Upsilon"
OmegaVersion = "Version d'Omega"
@@ -79,3 +80,7 @@ USBProtectionLevel = "Mise à jour acceptées"
USBDefaultLevel = "Basées sur Upsilon"
USBLowLevel = "Basées sur Omega"
USBParanoidLevel = "Aucune"
Normal = "Normale"
IdleTimeBeforeDimming = "Assombrir après (s)"
IdleTimeBeforeSuspend = "Éteindre après (s)"
BrightnessShortcut = "Étapes du raccourci"

View File

@@ -32,6 +32,7 @@ Real = "Valódi "
Cartesian = "Kartéziánus "
Polar = "Poláris "
Brightness = "Fényerö"
BrightnessSettings = "Fényerő beállításai"
SoftwareVersion = "Epsilon verzió"
UpsilonVersion = "Upsilon verzió"
OmegaVersion = "Omega verzió"
@@ -79,3 +80,7 @@ USBProtectionLevel = "Elfogadott frissítések"
USBDefaultLevel = "Upsilon alapján"
USBLowLevel = "Omega alapján"
USBParanoidLevel = "Egyik sem"
Normal = "Normale"
IdleTimeBeforeDimming = "Assombrir après (s)"
IdleTimeBeforeSuspend = "Éteindre après (s)"
BrightnessShortcut = "Parancsikon lépések"

View File

@@ -32,6 +32,7 @@ Real = "Reale "
Cartesian = "Algebrico "
Polar = "Esponenziale "
Brightness = "Luminosità"
BrightnessSettings = "Impostazioni di luminosità"
SoftwareVersion = "Epsilon version"
UpsilonVersion = "Upsilon version"
OmegaVersion = "Omega version"
@@ -79,3 +80,7 @@ USBProtectionLevel = "Aggiornamenti accettati"
USBDefaultLevel = "Basato su Upsilon"
USBLowLevel = "A base di Omega"
USBParanoidLevel = "Nessuno"
Normal = "Normale"
IdleTimeBeforeDimming = "Scurisci dopo (s)"
IdleTimeBeforeSuspend = "Sospendi dopo (s)"
BrightnessShortcut = "Passaggi di scelta rapida"

View File

@@ -32,6 +32,7 @@ Real = "Reëel "
Cartesian = "Cartesisch "
Polar = "Polair "
Brightness = "Helderheid"
BrightnessSettings = "Helderheidsinstellingen"
SoftwareVersion = "Epsilon version"
UpsilonVersion = "Upsilon version"
OmegaVersion = "Omega version"
@@ -79,3 +80,7 @@ USBProtectionLevel = "Updates geaccepteerd"
USBDefaultLevel = "Gebaseerd op Upsilon"
USBLowLevel = "Op basis van Omega"
USBParanoidLevel = "Geen"
Normal = "Normaal"
IdleTimeBeforeDimming = "Donkerder maken na (s)"
IdleTimeBeforeSuspend = "Suspend after (s)"
BrightnessShortcut = "Snelkoppelingsstappen"

View File

@@ -32,6 +32,7 @@ Real = "Real "
Cartesian = "Cartesiana "
Polar = "Polar "
Brightness = "Brilho"
BrightnessSettings = "Configurações de brilho"
SoftwareVersion = "Versão do Epsilon"
UpsilonVersion = "Versão do Upsilon"
OmegaVersion = "Versão do Omega"
@@ -79,3 +80,7 @@ USBProtectionLevel = "Atualizações aceitas"
USBDefaultLevel = "Baseado em Upsilon"
USBLowLevel = "Baseado em Ômega"
USBParanoidLevel = "Nenhum"
Normal = "Normal"
IdleTimeBeforeDimming = "Diminuir depois (s)"
IdleTimeBeforeSuspend = "Suspender depois (s)"
BrightnessShortcut = "Passos de atalho"

View File

@@ -19,6 +19,7 @@ constexpr SettingsMessageTree s_usbProtectionChildren[2] = {SettingsMessageTree(
constexpr SettingsMessageTree s_usbProtectionLevelChildren[3] = {SettingsMessageTree(I18n::Message::USBDefaultLevel), SettingsMessageTree(I18n::Message::USBLowLevel), SettingsMessageTree(I18n::Message::USBParanoidLevel)};
constexpr SettingsMessageTree s_symbolFunctionChildren[3] = {SettingsMessageTree(I18n::Message::SymbolDefaultFunction), SettingsMessageTree(I18n::Message::SymbolArgDefaultFunction), SettingsMessageTree(I18n::Message::SymbolArgFunction)};
constexpr SettingsMessageTree s_modelMathOptionsChildren[6] = {SettingsMessageTree(I18n::Message::AngleUnit, s_modelAngleChildren), SettingsMessageTree(I18n::Message::DisplayMode, s_modelFloatDisplayModeChildren), SettingsMessageTree(I18n::Message::EditionMode, s_modelEditionModeChildren), SettingsMessageTree(I18n::Message::SymbolFunction, s_symbolFunctionChildren), SettingsMessageTree(I18n::Message::ComplexFormat, s_modelComplexFormatChildren), SettingsMessageTree(I18n::Message::SymbolMultiplication, s_symbolChildren)};
constexpr SettingsMessageTree s_brightnessChildren[4] = {SettingsMessageTree(I18n::Message::Brightness), SettingsMessageTree(I18n::Message::IdleTimeBeforeDimming), SettingsMessageTree(I18n::Message::IdleTimeBeforeSuspend), SettingsMessageTree(I18n::Message::BrightnessShortcut)};
constexpr SettingsMessageTree s_accessibilityChildren[6] = {SettingsMessageTree(I18n::Message::AccessibilityInvertColors), SettingsMessageTree(I18n::Message::AccessibilityMagnify),SettingsMessageTree(I18n::Message::AccessibilityGamma),SettingsMessageTree(I18n::Message::AccessibilityGammaRed),SettingsMessageTree(I18n::Message::AccessibilityGammaGreen),SettingsMessageTree(I18n::Message::AccessibilityGammaBlue)};
constexpr SettingsMessageTree s_contributorsChildren[18] = {SettingsMessageTree(I18n::Message::LaurianFournier), SettingsMessageTree(I18n::Message::YannCouturier), SettingsMessageTree(I18n::Message::DavidLuca), SettingsMessageTree(I18n::Message::LoicE), SettingsMessageTree(I18n::Message::VictorKretz), SettingsMessageTree(I18n::Message::QuentinGuidee), SettingsMessageTree(I18n::Message::JoachimLeFournis), SettingsMessageTree(I18n::Message::MaximeFriess), SettingsMessageTree(I18n::Message::JeanBaptisteBoric), SettingsMessageTree(I18n::Message::SandraSimmons), SettingsMessageTree(I18n::Message::David), SettingsMessageTree(I18n::Message::DamienNicolet), SettingsMessageTree(I18n::Message::EvannDreumont), SettingsMessageTree(I18n::Message::SzaboLevente), SettingsMessageTree(I18n::Message::VenceslasDuet), SettingsMessageTree(I18n::Message::CharlotteThomas), SettingsMessageTree(I18n::Message::AntoninLoubiere), SettingsMessageTree(I18n::Message::CyprienMejat)};
@@ -32,10 +33,10 @@ constexpr SettingsMessageTree s_modelAboutChildren[10] = {SettingsMessageTree(I1
MainController::MainController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate) :
ViewController(parentResponder),
m_brightnessCell(I18n::Message::Default, KDFont::LargeFont),
m_popUpCell(I18n::Message::Default, KDFont::LargeFont),
m_selectableTableView(this),
m_mathOptionsController(this, inputEventHandlerDelegate),
m_brightnessController(this, inputEventHandlerDelegate),
m_localizationController(this, Metric::CommonTopMargin, LocalizationController::Mode::Language),
m_accessibilityController(this),
m_dateTimeController(this),
@@ -63,13 +64,6 @@ void MainController::didBecomeFirstResponder() {
bool MainController::handleEvent(Ion::Events::Event event) {
GlobalPreferences * globalPreferences = GlobalPreferences::sharedGlobalPreferences();
if (event == Ion::Events::BrightnessPlus || event == Ion::Events::BrightnessMinus){
int delta = Ion::Backlight::MaxBrightness/GlobalPreferences::NumberOfBrightnessStates;
int direction = (event == Ion::Events::BrightnessPlus) ? Ion::Backlight::NumberOfStepsPerShortcut*delta : -delta*Ion::Backlight::NumberOfStepsPerShortcut;
GlobalPreferences::sharedGlobalPreferences()->setBrightnessLevel(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel()+direction);
m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), 1);
return true;
}
if (model()->childAtIndex(selectedRow())->numberOfChildren() == 0) {
if (model()->childAtIndex(selectedRow())->label() == promptMessage()) {
if (event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) {
@@ -79,16 +73,6 @@ bool MainController::handleEvent(Ion::Events::Event event) {
}
return false;
}
if (model()->childAtIndex(selectedRow())->label() == I18n::Message::Brightness) {
if (event == Ion::Events::Right || event == Ion::Events::Left || event == Ion::Events::Plus || event == Ion::Events::Minus) {
int delta = Ion::Backlight::MaxBrightness/GlobalPreferences::NumberOfBrightnessStates;
int direction = (event == Ion::Events::Right || event == Ion::Events::Plus) ? delta : -delta;
globalPreferences->setBrightnessLevel(globalPreferences->brightnessLevel()+direction);
m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow());
return true;
}
return false;
}
if (model()->childAtIndex(selectedRow())->label() == I18n::Message::Language || model()->childAtIndex(selectedRow())->label() == I18n::Message::Country) {
if (event == Ion::Events::OK || event == Ion::Events::EXE || event == Ion::Events::Right) {
m_localizationController.setMode(model()->childAtIndex(selectedRow())->label() == I18n::Message::Language ? LocalizationController::Mode::Language : LocalizationController::Mode::Country);
@@ -107,6 +91,8 @@ bool MainController::handleEvent(Ion::Events::Event event) {
subController = &m_examModeController;
} else if (title == I18n::Message::About) {
subController = &m_aboutController;
} else if (title == I18n::Message::BrightnessSettings) {
subController = &m_brightnessController;
} else if (title == I18n::Message::Accessibility) {
subController = &m_accessibilityController;
} else if (title == I18n::Message::DateTime) {
@@ -140,11 +126,7 @@ KDCoordinate MainController::rowHeight(int j) {
}
KDCoordinate MainController::cumulatedHeightFromIndex(int j) {
KDCoordinate height = j * rowHeight(0);
if (j > k_indexOfBrightnessCell) {
height += CellWithSeparator::k_margin;
}
return height;
return j * rowHeight(0);
}
int MainController::indexFromCumulatedHeight(KDCoordinate offsetY) {
@@ -161,11 +143,8 @@ HighlightCell * MainController::reusableCell(int index, int type) {
return &m_cells[index];
}
assert(index == 0);
if (type == 2) {
return &m_popUpCell;
}
assert(type == 1);
return &m_brightnessCell;
assert(type == 2);
return &m_popUpCell;
}
int MainController::reusableCellCount(int type) {

View File

@@ -13,6 +13,7 @@
#include "sub_menu/math_options_controller.h"
#include "sub_menu/preferences_controller.h"
#include "sub_menu/usb_protection_controller.h"
#include "sub_menu/brightness_controller.h"
namespace Settings {
@@ -31,6 +32,7 @@ extern const Shared::SettingsMessageTree s_contributorsChildren[18];
extern const Shared::SettingsMessageTree s_modelAboutChildren[10];
extern const Shared::SettingsMessageTree s_usbProtectionChildren[2];
extern const Shared::SettingsMessageTree s_usbProtectionLevelChildren[3];
extern const Shared::SettingsMessageTree s_brightnessChildren[4];
extern const Shared::SettingsMessageTree s_model;
class MainController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource {
@@ -66,12 +68,12 @@ private:
StackViewController * stackController() const;
I18n::Message promptMessage() const;
bool hasPrompt() const { return promptMessage() != I18n::Message::Default; }
constexpr static int k_numberOfSimpleChevronCells = 9;
constexpr static int k_numberOfSimpleChevronCells = 10;
MessageTableCellWithChevronAndMessage m_cells[k_numberOfSimpleChevronCells];
MessageTableCellWithGaugeWithSeparator m_brightnessCell;
MessageTableCellWithSwitch m_popUpCell;
SelectableTableView m_selectableTableView;
MathOptionsController m_mathOptionsController;
BrightnessController m_brightnessController;
LocalizationController m_localizationController;
AccessibilityController m_accessibilityController;
DateTimeController m_dateTimeController;

View File

@@ -8,7 +8,7 @@ namespace Settings {
constexpr SettingsMessageTree s_modelMenu[] =
{SettingsMessageTree(I18n::Message::MathOptions, s_modelMathOptionsChildren),
SettingsMessageTree(I18n::Message::Brightness),
SettingsMessageTree(I18n::Message::BrightnessSettings, s_brightnessChildren),
SettingsMessageTree(I18n::Message::DateTime, s_modelDateTimeChildren),
SettingsMessageTree(I18n::Message::Language),
SettingsMessageTree(I18n::Message::Country),

View File

@@ -9,7 +9,7 @@ namespace Settings {
constexpr SettingsMessageTree s_modelMenu[] =
{SettingsMessageTree(I18n::Message::MathOptions, s_modelMathOptionsChildren),
SettingsMessageTree(I18n::Message::Brightness),
SettingsMessageTree(I18n::Message::BrightnessSettings, s_brightnessChildren),
SettingsMessageTree(I18n::Message::DateTime, s_modelDateTimeChildren),
SettingsMessageTree(I18n::Message::Language),
SettingsMessageTree(I18n::Message::Country),

View File

@@ -8,14 +8,14 @@ using namespace Shared;
constexpr SettingsMessageTree s_modelMenu[] =
{SettingsMessageTree(I18n::Message::MathOptions, s_modelMathOptionsChildren),
SettingsMessageTree(I18n::Message::Brightness),
SettingsMessageTree(I18n::Message::BrightnessSettings, s_brightnessChildren),
SettingsMessageTree(I18n::Message::DateTime, s_modelDateTimeChildren),
SettingsMessageTree(I18n::Message::Language),
SettingsMessageTree(I18n::Message::Country),
SettingsMessageTree(I18n::Message::ExamMode, ExamModeConfiguration::s_modelExamChildren),
#ifdef HAS_CODE
SettingsMessageTree(I18n::Message::CodeApp, s_codeChildren),
#endif
#endif
SettingsMessageTree(I18n::Message::UpdatePopUp),
SettingsMessageTree(I18n::Message::Accessibility, s_accessibilityChildren),
SettingsMessageTree(I18n::Message::UsbSetting, s_usbProtectionChildren),

View File

@@ -0,0 +1,142 @@
#include "brightness_controller.h"
#include "../../global_preferences.h"
#include "../../apps_container.h"
#include "../../shared/poincare_helpers.h"
#include <assert.h>
#include <cmath>
#include "../app.h"
#include <apps/shared/text_field_delegate_app.h>
#include <poincare/integer.h>
using namespace Poincare;
using namespace Shared;
namespace Settings {
BrightnessController::BrightnessController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate) :
GenericSubController(parentResponder),
m_brightnessCell(I18n::Message::Brightness, KDFont::LargeFont),
m_editableCellIdleBeforeDimmingSeconds(&m_selectableTableView, inputEventHandlerDelegate, this),
m_editableCellIdleBeforeSuspendSeconds(&m_selectableTableView, inputEventHandlerDelegate, this),
m_BrightnessShortcutCell(&m_selectableTableView, inputEventHandlerDelegate, this)
{
m_editableCellIdleBeforeDimmingSeconds.setMessage(I18n::Message::IdleTimeBeforeDimming);
m_editableCellIdleBeforeDimmingSeconds.setMessageFont(KDFont::LargeFont);
m_editableCellIdleBeforeSuspendSeconds.setMessage(I18n::Message::IdleTimeBeforeSuspend);
m_editableCellIdleBeforeSuspendSeconds.setMessageFont(KDFont::LargeFont);
m_BrightnessShortcutCell.setMessage(I18n::Message::BrightnessShortcut);
m_BrightnessShortcutCell.setMessageFont(KDFont::LargeFont);
}
HighlightCell * BrightnessController::reusableCell(int index, int type) {
HighlightCell * editableCell[] = {
&m_brightnessCell,
&m_editableCellIdleBeforeDimmingSeconds,
&m_editableCellIdleBeforeSuspendSeconds,
&m_BrightnessShortcutCell
};
return editableCell[index];
}
int BrightnessController::reusableCellCount(int type) {
switch(type) {
case 0:
case 1:
return k_totalNumberOfCell;
default:
assert(false);
return 0;
}
}
void BrightnessController::willDisplayCellForIndex(HighlightCell * cell, int index) {
if(index == 0){
MessageTableCellWithGauge * myGaugeCell = (MessageTableCellWithGauge *)cell;
GaugeView * myGauge = (GaugeView *)myGaugeCell->accessoryView();
myGauge->setLevel((float)GlobalPreferences::sharedGlobalPreferences()->brightnessLevel()/(float)Ion::Backlight::MaxBrightness);
return;
} else {
MessageTableCellWithEditableText * myCell = (MessageTableCellWithEditableText *)cell;
GenericSubController::willDisplayCellForIndex(myCell, index);
char buffer[5];
int val;
switch(index){
case 1:{
val = GlobalPreferences::sharedGlobalPreferences()->idleBeforeDimmingSeconds();
break;
}
case 2:{
val = GlobalPreferences::sharedGlobalPreferences()->idleBeforeSuspendSeconds();
break;
}
case 3:{
val = GlobalPreferences::sharedGlobalPreferences()->brightnessShortcut();
break;
}
default:
assert(false);
}
Poincare::Integer(val).serialize(buffer, 5);
myCell->setAccessoryText(buffer);
}
}
bool BrightnessController::handleEvent(Ion::Events::Event event) {
if ((selectedRow() == 0) && (event == Ion::Events::Right || event == Ion::Events::Left || event == Ion::Events::Plus || event == Ion::Events::Minus)) {
int delta = Ion::Backlight::MaxBrightness/GlobalPreferences::NumberOfBrightnessStates;
int direction = (event == Ion::Events::Right || event == Ion::Events::Plus) ? delta : -delta;
GlobalPreferences::sharedGlobalPreferences()->setBrightnessLevel(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel()+direction);
m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow());
return true;
}
if (event == Ion::Events::BrightnessPlus || event == Ion::Events::BrightnessMinus){
int delta = Ion::Backlight::MaxBrightness/GlobalPreferences::NumberOfBrightnessStates;
int NumberOfStepsPerShortcut = GlobalPreferences::sharedGlobalPreferences()->brightnessShortcut();
int direction = (event == Ion::Events::BrightnessPlus) ? NumberOfStepsPerShortcut*delta : -delta*NumberOfStepsPerShortcut;
GlobalPreferences::sharedGlobalPreferences()->setBrightnessLevel(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel()+direction);
m_selectableTableView.reloadCellAtLocation(m_selectableTableView.selectedColumn(), 0);
return true;
}
return false;
}
bool BrightnessController::textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) {
return ((event == Ion::Events::Up && selectedRow() > 0) || (event == Ion::Events::Down && selectedRow() < k_totalNumberOfCell - 1))
|| TextFieldDelegate::textFieldShouldFinishEditing(textField, event);
}
bool BrightnessController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) {
double floatBody;
if (textFieldDelegateApp()->hasUndefinedValue(text, floatBody)) {
return false;
}
int val = std::round(floatBody);
switch (selectedRow()) {
case 1:
GlobalPreferences::sharedGlobalPreferences()->setIdleBeforeDimmingSeconds(val);
m_editableCellIdleBeforeDimmingSeconds.setAccessoryText(text);
break;
case 2:
GlobalPreferences::sharedGlobalPreferences()->setIdleBeforeSuspendSeconds(val);
m_editableCellIdleBeforeSuspendSeconds.setAccessoryText(text);
break;
case 3:{
if(val > GlobalPreferences::NumberOfBrightnessStates){ val = GlobalPreferences::NumberOfBrightnessStates;
} else if (val < 0){val = 0;}
GlobalPreferences::sharedGlobalPreferences()->setBrightnessShortcut(val);
m_BrightnessShortcutCell.setAccessoryText(text);
break;
}
default:
assert(false);
}
AppsContainer * myContainer = AppsContainer::sharedAppsContainer();
myContainer->refreshPreferences();
m_selectableTableView.reloadCellAtLocation(0, selectedRow());
if (event == Ion::Events::Up || event == Ion::Events::Down || event == Ion::Events::OK) {
m_selectableTableView.handleEvent(event);
}
return true;
}
}

View File

@@ -0,0 +1,33 @@
#ifndef SETTINGS_BRIGHTNESS_CONTROLLER_H
#define SETTINGS_BRIGHTNESS_CONTROLLER_H
#include "generic_sub_controller.h"
#include "preferences_controller.h"
#include "../message_table_cell_with_editable_text_with_separator.h"
#include "../../shared/parameter_text_field_delegate.h"
#include "../message_table_cell_with_gauge_with_separator.h"
namespace Settings {
class BrightnessController : public GenericSubController, public Shared::ParameterTextFieldDelegate {
public:
BrightnessController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate);
TELEMETRY_ID("BrightnessSettings");
HighlightCell * reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
bool handleEvent(Ion::Events::Event event) override;
bool textFieldShouldFinishEditing(TextField * textField, Ion::Events::Event event) override;
bool textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) override;
protected:
constexpr static int k_totalNumberOfCell = 4;
private:
MessageTableCellWithGauge m_brightnessCell;
MessageTableCellWithEditableText m_editableCellIdleBeforeDimmingSeconds;
MessageTableCellWithEditableText m_editableCellIdleBeforeSuspendSeconds;
MessageTableCellWithEditableText m_BrightnessShortcutCell;
};
}
#endif

View File

@@ -2,7 +2,7 @@
#include "apps_container.h"
SuspendTimer::SuspendTimer() :
Timer(k_idleBeforeSuspendDuration/Timer::TickDuration)
Timer(GlobalPreferences::sharedGlobalPreferences()->idleBeforeSuspendSeconds()*1000/Timer::TickDuration)
{
}

View File

@@ -7,7 +7,6 @@ class SuspendTimer : public Timer {
public:
SuspendTimer();
private:
constexpr static int k_idleBeforeSuspendDuration = 5*60*1000; // In miliseconds
bool fire() override;
};

View File

@@ -17,7 +17,7 @@ public:
static constexpr int TickDuration = 300; // In Miliseconds
Timer(uint32_t period); // Period is in ticks
bool tick();
void reset();
void reset(uint32_t NewPeriod = -1);
protected:
virtual bool fire() = 0;
uint32_t m_period;

View File

@@ -16,6 +16,9 @@ bool Timer::tick() {
return false;
}
void Timer::reset() {
void Timer::reset(uint32_t NewPeriod) {
if(NewPeriod != -1){
m_period = NewPeriod;
}
m_numberOfTicksBeforeFire = m_period;
}

View File

@@ -12,7 +12,6 @@ bool isInitialized();
void shutdown();
void setBrightness(uint8_t b);
uint8_t brightness();
const int NumberOfStepsPerShortcut = 4;
}
}