sdk: Stop using lerp for night/day mode transitions

* This makes it clear what the desired behavior is
* In order to make the logic more clear, also start
  scaling into night mode before civil sunset so that
  we finish by civil sunset -- this makes sure that
  by the time there's no light out for practical
  purposes, we are in night mode
* While we're at it, add a few comments about what
  each return is supposed to do, for the future

Change-Id: I4ec0f8eec6b0129a37e99f9e3a2b3f124aeeb4f2
This commit is contained in:
Paul Keith
2018-10-01 03:10:04 +02:00
parent 0b12914dbf
commit bd9f127ef8

View File

@@ -293,20 +293,23 @@ public class ColorTemperatureController extends LiveDisplayFeature {
*/
private static float adj(long now, long sunset, long sunrise) {
if (sunset < 0 || sunrise < 0
|| now < sunset || now > (sunrise + TWILIGHT_ADJUSTMENT_TIME)) {
|| now < (sunset - TWILIGHT_ADJUSTMENT_TIME)
|| now > (sunrise + TWILIGHT_ADJUSTMENT_TIME)) {
// More than 1hr after civil sunrise or before civil sunset
return 1.0f;
}
if (now <= (sunset + TWILIGHT_ADJUSTMENT_TIME)) {
return MathUtils.lerp(1.0f, 0.0f,
(float) (now - sunset) / TWILIGHT_ADJUSTMENT_TIME);
// Scale the transition into night mode in 1hr before civil sunset
if (now <= sunset) {
return (float) (sunset - now) / TWILIGHT_ADJUSTMENT_TIME;
}
// Scale the transition into day mode in 1hr after civil sunrise
if (now >= sunrise) {
return MathUtils.lerp(1.0f, 0.0f,
(float) ((sunrise + TWILIGHT_ADJUSTMENT_TIME) - now) / TWILIGHT_ADJUSTMENT_TIME);
return (float) (now - sunrise) / TWILIGHT_ADJUSTMENT_TIME;
}
// More than 1hr past civil sunset
return 0.0f;
}