mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
Add natural dimer (#106)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "backlight_dimming_timer.h"
|
||||
#include "global_preferences.h"
|
||||
|
||||
BacklightDimmingTimer::BacklightDimmingTimer() :
|
||||
Timer(k_idleBeforeDimmingDuration/Timer::TickDuration)
|
||||
@@ -6,6 +7,33 @@ BacklightDimmingTimer::BacklightDimmingTimer() :
|
||||
}
|
||||
|
||||
bool BacklightDimmingTimer::fire() {
|
||||
Ion::Backlight::setBrightness(k_dimBacklightBrightness);
|
||||
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;
|
||||
}
|
||||
resetTimer();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -6,10 +6,19 @@
|
||||
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
|
||||
|
||||
@@ -18,11 +18,10 @@ public:
|
||||
Timer(uint32_t period); // Period is in ticks
|
||||
bool tick();
|
||||
void reset();
|
||||
protected:
|
||||
virtual bool fire() = 0;
|
||||
private:
|
||||
uint32_t m_period;
|
||||
uint32_t m_numberOfTicksBeforeFire;
|
||||
protected:
|
||||
virtual bool fire() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user