From 2c197fa4630201ad9595e550cb0c250c539cfa15 Mon Sep 17 00:00:00 2001 From: Jeremy Beker Date: Fri, 24 May 2019 14:28:50 -0400 Subject: [PATCH 1/2] When lid is closed, light sensor returns max value If the lid is closed (on a Macbook Pro late 2013), the light sensors both report the max value. In that case, we really want to say the value is 0, so return that. --- Source/LightEvidenceSource.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Source/LightEvidenceSource.m b/Source/LightEvidenceSource.m index de7db7f5a..ad66491cb 100644 --- a/Source/LightEvidenceSource.m +++ b/Source/LightEvidenceSource.m @@ -83,13 +83,18 @@ - (NSString *)description { // Returns value in [0.0, 1.0] - (double)levelFromRawLeft:(uint64_t)left andRight:(uint64_t)right { // FIXME(rdamazio): This value is probably incorrect - // COMMENTS(dustinrue) below is the observed max value on a 13" unibody MacBook (Late 2008) + // COMMENTS(jbeker) below is the observed max value on a 15" Late 2013 Macbook Pro // This value is ridiculous and results in a much smaller // useful value range. - const double kMaxLightValue = 67092480.0; + const double kMaxLightValue = 4294967295.0; const double avg = (left + right) / 2; // determine average value from the two sensors - return (avg / kMaxLightValue); // normalize + + if (avg == kMaxLightValue) { + return 0; // COMMENTS(jbeker) on a 15" Late 2013 Macbook Pro it returns max value when the laptop is shut + } else { + return (avg / kMaxLightValue); // normalize + } } - (void)doUpdate { From beabdd6dc8fb2f0812c0375ab8a6373b7f72ef27 Mon Sep 17 00:00:00 2001 From: Jeremy Beker Date: Tue, 11 Jun 2019 12:22:58 -0400 Subject: [PATCH 2/2] The value when closed was too high when light was present for percentage --- Source/LightEvidenceSource.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/LightEvidenceSource.m b/Source/LightEvidenceSource.m index ad66491cb..5c785c103 100644 --- a/Source/LightEvidenceSource.m +++ b/Source/LightEvidenceSource.m @@ -86,11 +86,12 @@ - (double)levelFromRawLeft:(uint64_t)left andRight:(uint64_t)right { // COMMENTS(jbeker) below is the observed max value on a 15" Late 2013 Macbook Pro // This value is ridiculous and results in a much smaller // useful value range. - const double kMaxLightValue = 4294967295.0; + const double kClosedLightValue = 4294967295.0; + const double kMaxLightValue = 67092480.0;; const double avg = (left + right) / 2; // determine average value from the two sensors - if (avg == kMaxLightValue) { + if (avg == kClosedLightValue) { return 0; // COMMENTS(jbeker) on a 15" Late 2013 Macbook Pro it returns max value when the laptop is shut } else { return (avg / kMaxLightValue); // normalize