Index: device/generic_sensor/ambient_light_mac.cc |
diff --git a/content/browser/device_sensors/ambient_light_mac.cc b/device/generic_sensor/ambient_light_mac.cc |
similarity index 74% |
rename from content/browser/device_sensors/ambient_light_mac.cc |
rename to device/generic_sensor/ambient_light_mac.cc |
index c6606791bd35ef399d186bc46e84c336f61f51a4..68bc459ec9c7da69f684bb0c5b373acd9b5f8882 100644 |
--- a/content/browser/device_sensors/ambient_light_mac.cc |
+++ b/device/generic_sensor/ambient_light_mac.cc |
@@ -4,14 +4,14 @@ |
// This file is based on http://osxbook.com/book/bonus/chapter10/light/ |
-#include "content/browser/device_sensors/ambient_light_mac.h" |
+#include "device/generic_sensor/ambient_light_mac.h" |
#include <utility> |
#include "base/mac/scoped_cftyperef.h" |
#include "base/mac/scoped_ioobject.h" |
-namespace content { |
+namespace device { |
namespace { |
enum LmuFunctionIndex { |
@@ -28,13 +28,33 @@ std::unique_ptr<AmbientLightSensor> AmbientLightSensor::Create() { |
return light_sensor->Init() ? std::move(light_sensor) : nullptr; |
} |
+double AmbientLightSensor::LMUvalueToLux(uint64_t raw_value) { |
+ // Conversion formula from regression. |
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=793728 |
+ // Let x = raw_value, then |
+ // lux = -2.978303814*(10^-27)*x^4 + 2.635687683*(10^-19)*x^3 - |
+ // 3.459747434*(10^-12)*x^2 + 3.905829689*(10^-5)*x - 0.1932594532 |
+ |
+ static const long double k4 = pow(10.L, -7); |
+ static const long double k3 = pow(10.L, -4); |
+ static const long double k2 = pow(10.L, -2); |
+ static const long double k1 = pow(10.L, 5); |
+ long double scaled_value = raw_value / k1; |
+ |
+ long double lux_value = |
+ (-3 * k4 * pow(scaled_value, 4)) + (2.6 * k3 * pow(scaled_value, 3)) + |
+ (-3.4 * k2 * pow(scaled_value, 2)) + (3.9 * scaled_value) - 0.19; |
+ |
+ double lux = ceil(static_cast<double>(lux_value)); |
+ return lux > 0 ? lux : 0; |
+} |
+ |
AmbientLightSensor::~AmbientLightSensor() { |
if (!io_connection_) |
IOServiceClose(io_connection_); |
} |
-AmbientLightSensor::AmbientLightSensor() : io_connection_(IO_OBJECT_NULL) { |
-} |
+AmbientLightSensor::AmbientLightSensor() : io_connection_(IO_OBJECT_NULL) {} |
bool AmbientLightSensor::Init() { |
// Tested and verified by riju that the following call works on |
@@ -77,4 +97,4 @@ bool AmbientLightSensor::ReadSensorValue(uint64_t lux_values[2]) { |
return kr == KERN_SUCCESS; |
} |
-} // namespace content |
+} // namespace device |