aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2016-08-02 09:26:49 +0200
committerSteve Kondik <shade@chemlab.org>2016-08-09 15:14:01 -0700
commitc0dd46d30f10e1da31828b9f67b6e0ea51c2e674 (patch)
tree7ed944a602ff477d0f213d22132fec9fa6c35271
parentd62a53f690a5e636a52e4f064a7cb9d78eec77d7 (diff)
downloadvendor_cmsdk-c0dd46d30f10e1da31828b9f67b6e0ea51c2e674.zip
vendor_cmsdk-c0dd46d30f10e1da31828b9f67b6e0ea51c2e674.tar.gz
vendor_cmsdk-c0dd46d30f10e1da31828b9f67b6e0ea51c2e674.tar.bz2
Introduce a hysteresis for outdoor condition determination.
Avoids flicker when brightness is around the threshold. Change-Id: I8658725450496b89123abb26b6ef8ce333c709e5
-rw-r--r--cm/lib/main/java/org/cyanogenmod/platform/internal/display/AmbientLuxObserver.java8
-rw-r--r--cm/lib/main/java/org/cyanogenmod/platform/internal/display/OutdoorModeController.java6
-rw-r--r--cm/res/res/values/config.xml1
-rw-r--r--cm/res/res/values/symbols.xml1
4 files changed, 13 insertions, 3 deletions
diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/display/AmbientLuxObserver.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/display/AmbientLuxObserver.java
index bf1e85e..f0d67aa 100644
--- a/cm/lib/main/java/org/cyanogenmod/platform/internal/display/AmbientLuxObserver.java
+++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/display/AmbientLuxObserver.java
@@ -38,6 +38,7 @@ public class AmbientLuxObserver {
private final SensorManager mSensorManager;
private final float mThresholdLux;
+ private final float mHysteresisLux;
private final int mThresholdDuration;
private boolean mLightSensorEnabled = false;
@@ -61,9 +62,10 @@ public class AmbientLuxObserver {
}
public AmbientLuxObserver(Context context, Looper looper,
- float thresholdLux, int thresholdDuration) {
+ float thresholdLux, float hysteresisLux, int thresholdDuration) {
mLuxHandler = new AmbientLuxHandler(looper);
mThresholdLux = thresholdLux;
+ mHysteresisLux = hysteresisLux;
mThresholdDuration = thresholdDuration;
mRingBuffer = new TimedMovingAverageRingBuffer(thresholdDuration);
@@ -103,7 +105,9 @@ public class AmbientLuxObserver {
" mAmbientLux=" + mAmbientLux);
}
- direction = mAmbientLux >= mThresholdLux ? HIGH : LOW;
+ final float threshold = mState == HIGH
+ ? mThresholdLux - mHysteresisLux : mThresholdLux;
+ direction = mAmbientLux >= threshold ? HIGH : LOW;
if (mState != direction) {
mState = direction;
if (mCallback != null) {
diff --git a/cm/lib/main/java/org/cyanogenmod/platform/internal/display/OutdoorModeController.java b/cm/lib/main/java/org/cyanogenmod/platform/internal/display/OutdoorModeController.java
index 797a92e..20f047d 100644
--- a/cm/lib/main/java/org/cyanogenmod/platform/internal/display/OutdoorModeController.java
+++ b/cm/lib/main/java/org/cyanogenmod/platform/internal/display/OutdoorModeController.java
@@ -40,6 +40,7 @@ public class OutdoorModeController extends LiveDisplayFeature {
// default values
private final int mDefaultOutdoorLux;
+ private final int mOutdoorLuxHysteresis;
private final boolean mDefaultAutoOutdoorMode;
private final boolean mSelfManaged;
@@ -59,6 +60,8 @@ public class OutdoorModeController extends LiveDisplayFeature {
mDefaultOutdoorLux = mContext.getResources().getInteger(
org.cyanogenmod.platform.internal.R.integer.config_outdoorAmbientLux);
+ mOutdoorLuxHysteresis = mContext.getResources().getInteger(
+ org.cyanogenmod.platform.internal.R.integer.config_outdoorAmbientLuxHysteresis);
mDefaultAutoOutdoorMode = mContext.getResources().getBoolean(
org.cyanogenmod.platform.internal.R.bool.config_defaultAutoOutdoorMode);
}
@@ -71,7 +74,7 @@ public class OutdoorModeController extends LiveDisplayFeature {
if (!mSelfManaged) {
mLuxObserver = new AmbientLuxObserver(mContext, mHandler.getLooper(),
- mDefaultOutdoorLux, SENSOR_WINDOW_MS);
+ mDefaultOutdoorLux, mOutdoorLuxHysteresis, SENSOR_WINDOW_MS);
}
registerSettings(
@@ -128,6 +131,7 @@ public class OutdoorModeController extends LiveDisplayFeature {
pw.println(" mSelfManaged=" + mSelfManaged);
if (!mSelfManaged) {
pw.println(" mDefaultOutdoorLux=" + mDefaultOutdoorLux);
+ pw.println(" mOutdoorLuxHysteresis=" + mOutdoorLuxHysteresis);
pw.println();
pw.println(" OutdoorModeController State:");
pw.println(" mAutoOutdoorMode=" + isAutomaticOutdoorModeEnabled());
diff --git a/cm/res/res/values/config.xml b/cm/res/res/values/config.xml
index c17539c..b9e05d5 100644
--- a/cm/res/res/values/config.xml
+++ b/cm/res/res/values/config.xml
@@ -55,6 +55,7 @@
<integer name="config_dayColorTemperature">6500</integer>
<integer name="config_nightColorTemperature">4800</integer>
<integer name="config_outdoorAmbientLux">12000</integer>
+ <integer name="config_outdoorAmbientLuxHysteresis">1500</integer>
<integer name="config_defaultLiveDisplayMode">2</integer>
<!-- These values should map to the true min and max
diff --git a/cm/res/res/values/symbols.xml b/cm/res/res/values/symbols.xml
index 957e794..7c19dc8 100644
--- a/cm/res/res/values/symbols.xml
+++ b/cm/res/res/values/symbols.xml
@@ -72,6 +72,7 @@
<java-symbol type="integer" name="config_dayColorTemperature" />
<java-symbol type="integer" name="config_nightColorTemperature" />
<java-symbol type="integer" name="config_outdoorAmbientLux" />
+ <java-symbol type="integer" name="config_outdoorAmbientLuxHysteresis" />
<java-symbol type="integer" name="config_defaultLiveDisplayMode" />
<java-symbol type="integer" name="config_minColorTemperature" />
<java-symbol type="integer" name="config_maxColorTemperature" />