OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "device/generic_sensor/platform_sensor_ambient_light_mac.h" | 5 #include "device/generic_sensor/platform_sensor_ambient_light_mac.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <IOKit/IOMessage.h> | 9 #include <IOKit/IOMessage.h> |
8 | 10 |
9 #include "base/bind.h" | 11 #include "base/bind.h" |
10 #include "device/base/synchronization/shared_memory_seqlock_buffer.h" | 12 #include "device/base/synchronization/shared_memory_seqlock_buffer.h" |
| 13 #include "device/generic_sensor/generic_sensor_consts.h" |
11 #include "device/generic_sensor/platform_sensor_provider_mac.h" | 14 #include "device/generic_sensor/platform_sensor_provider_mac.h" |
12 #include "device/sensors/public/cpp/device_sensors_consts.h" | 15 |
13 #include "device/sensors/public/cpp/device_util_mac.h" | 16 namespace { |
| 17 |
| 18 // Convert the value returned by the ambient light LMU sensor on Mac |
| 19 // hardware to a lux value. |
| 20 double LMUvalueToLux(uint64_t raw_value) { |
| 21 // Conversion formula from regression. |
| 22 // https://bugzilla.mozilla.org/show_bug.cgi?id=793728 |
| 23 // Let x = raw_value, then |
| 24 // lux = -2.978303814*(10^-27)*x^4 + 2.635687683*(10^-19)*x^3 - |
| 25 // 3.459747434*(10^-12)*x^2 + 3.905829689*(10^-5)*x - 0.1932594532 |
| 26 |
| 27 static const long double k4 = pow(10.L, -7); |
| 28 static const long double k3 = pow(10.L, -4); |
| 29 static const long double k2 = pow(10.L, -2); |
| 30 static const long double k1 = pow(10.L, 5); |
| 31 long double scaled_value = raw_value / k1; |
| 32 |
| 33 long double lux_value = |
| 34 (-3 * k4 * pow(scaled_value, 4)) + (2.6 * k3 * pow(scaled_value, 3)) + |
| 35 (-3.4 * k2 * pow(scaled_value, 2)) + (3.9 * scaled_value) - 0.19; |
| 36 |
| 37 double lux = ceil(static_cast<double>(lux_value)); |
| 38 return lux > 0 ? lux : 0; |
| 39 } |
| 40 |
| 41 } // namespace |
14 | 42 |
15 namespace device { | 43 namespace device { |
16 | 44 |
17 enum LmuFunctionIndex { | 45 enum LmuFunctionIndex { |
18 kGetSensorReadingID = 0, // getSensorReading(int *, int *) | 46 kGetSensorReadingID = 0, // getSensorReading(int *, int *) |
19 }; | 47 }; |
20 | 48 |
21 PlatformSensorAmbientLightMac::PlatformSensorAmbientLightMac( | 49 PlatformSensorAmbientLightMac::PlatformSensorAmbientLightMac( |
22 mojom::SensorType type, | 50 mojom::SensorType type, |
23 mojo::ScopedSharedBufferMapping mapping, | 51 mojo::ScopedSharedBufferMapping mapping, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 current_lux_ = lux; | 167 current_lux_ = lux; |
140 | 168 |
141 SensorReading reading; | 169 SensorReading reading; |
142 reading.timestamp = (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); | 170 reading.timestamp = (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); |
143 reading.values[0] = current_lux_; | 171 reading.values[0] = current_lux_; |
144 UpdateSensorReading(reading, true); | 172 UpdateSensorReading(reading, true); |
145 return true; | 173 return true; |
146 } | 174 } |
147 | 175 |
148 } // namespace device | 176 } // namespace device |
OLD | NEW |