Index: device/generic_sensor/platform_sensor_ambient_light_mac.cc |
diff --git a/device/generic_sensor/platform_sensor_ambient_light_mac.cc b/device/generic_sensor/platform_sensor_ambient_light_mac.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a2889edab7bf196ed9ec0fe2f220bed30b30626b |
--- /dev/null |
+++ b/device/generic_sensor/platform_sensor_ambient_light_mac.cc |
@@ -0,0 +1,80 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "device/generic_sensor/platform_sensor_ambient_light_mac.h" |
+ |
+#include "base/bind.h" |
+#include "base/message_loop/message_loop.h" |
+#include "content/browser/device_sensors/ambient_light_mac.h" |
+#include "content/common/shared_memory_seqlock_buffer.h" |
+#include "device/generic_sensor/platform_sensor_provider_mac.h" |
+#include "device/generic_sensor/platform_sensor_util_mac.h" |
+ |
+namespace device { |
+ |
+struct DeviceLightData { |
+ DeviceLightData() : illuminance(-1) {} |
shalamov
2016/09/13 09:52:34
Should it be 0?
|
+ double illuminance; |
+}; |
+ |
+typedef content::SharedMemorySeqLockBuffer<DeviceLightData> |
+ DeviceLightHardwareBuffer; |
+ |
+PlatformSensorAmbientLightMac::PlatformSensorAmbientLightMac( |
+ mojom::SensorType type, |
+ mojo::ScopedSharedBufferMapping mapping, |
+ uint64_t buffer_size, |
+ PlatformSensorProvider* provider) |
+ : PlatformSensorMac(type, std::move(mapping), provider), |
+ task_runner_(base::MessageLoop::current()->task_runner()) { |
+ platformSensor_ = content::AmbientLightSensor::Create(); |
+} |
+ |
+PlatformSensorAmbientLightMac::~PlatformSensorAmbientLightMac() = default; |
+ |
+mojom::ReportingMode PlatformSensorAmbientLightMac::GetReportingMode() { |
+ return mojom::ReportingMode::CONTINUOUS; |
shalamov
2016/09/13 09:52:34
Should it be mojom::ReportingMode::ON_CHANGE, sinc
|
+} |
+ |
+bool PlatformSensorAmbientLightMac::StartSensor( |
+ const PlatformSensorConfiguration& configuration) { |
+ PlatformSensorProviderMac::GetInstance()->BeginPollingSensor(this, |
+ configuration); |
+ return true; |
+} |
+ |
+void PlatformSensorAmbientLightMac::StopSensor() { |
+ PlatformSensorProviderMac::GetInstance()->StopPollingSensor(this); |
+} |
+ |
+bool PlatformSensorAmbientLightMac::CheckSensorConfiguration( |
+ const PlatformSensorConfiguration& configuration) { |
+ return true; |
+} |
+ |
+PlatformSensorConfiguration |
+PlatformSensorAmbientLightMac::GetDefaultConfiguration() { |
+ PlatformSensorConfiguration default_configuration; |
+ // Default configuration inherited from content/browser/device_sensors. |
+ default_configuration.set_frequency(5); |
+ return default_configuration; |
+} |
+ |
+void PlatformSensorAmbientLightMac::UpdateReading() { |
+ uint64_t lux_value[2]; |
shalamov
2016/09/13 09:52:34
Is it possible to store previous value and fire No
|
+ platformSensor_->ReadSensorValue(lux_value); |
+ uint64_t mean = (lux_value[0] + lux_value[1]) / 2; |
+ double lux = device::LMUvalueToLux(mean); |
+ DeviceLightHardwareBuffer* light_buffer = |
+ static_cast<DeviceLightHardwareBuffer*>(shared_buffer_mapping_.get()); |
+ light_buffer->seqlock.WriteBegin(); |
+ light_buffer->data.illuminance = lux; |
+ light_buffer->seqlock.WriteEnd(); |
+ task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&PlatformSensorAmbientLightMac::NotifySensorReadingChanged, |
+ base::Unretained(this))); |
+} |
+ |
+} // namespace device |