Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "device/generic_sensor/platform_sensor_ambient_light_mac.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "device/generic_sensor/ambient_light_mac.h" | |
| 9 #include "device/generic_sensor/platform_sensor_provider_mac.h" | |
| 10 #include "device/generic_sensor/platform_sensor_util_mac.h" | |
| 11 #include "device/generic_sensor/shared_memory_seqlock_buffer.h" | |
| 12 | |
| 13 namespace device { | |
| 14 | |
| 15 struct DeviceLightData { | |
|
Mikhail
2016/09/16 16:23:54
why is that needed?
| |
| 16 DeviceLightData() : illuminance(0) {} | |
| 17 double illuminance; | |
| 18 }; | |
| 19 | |
| 20 typedef SharedMemorySeqLockBuffer<DeviceLightData> DeviceLightHardwareBuffer; | |
|
Mikhail
2016/09/16 16:23:54
nit: using DeviceLightHardwareBuffer = ..
| |
| 21 | |
| 22 PlatformSensorAmbientLightMac::PlatformSensorAmbientLightMac( | |
| 23 mojom::SensorType type, | |
| 24 mojo::ScopedSharedBufferMapping mapping, | |
| 25 uint64_t buffer_size, | |
| 26 PlatformSensorProvider* provider, | |
| 27 const scoped_refptr<base::SingleThreadTaskRunner>& | |
| 28 polling_thread_task_runner) | |
| 29 : PlatformSensorMac(type, | |
| 30 std::move(mapping), | |
| 31 provider, | |
| 32 polling_thread_task_runner), | |
| 33 current_lux(0) { | |
| 34 platformSensor_ = AmbientLightSensor::Create(); | |
| 35 } | |
| 36 | |
| 37 mojom::ReportingMode PlatformSensorAmbientLightMac::GetReportingMode() { | |
| 38 return mojom::ReportingMode::ON_CHANGE; | |
| 39 } | |
| 40 | |
| 41 bool PlatformSensorAmbientLightMac::CheckSensorConfiguration( | |
| 42 const PlatformSensorConfiguration& configuration) { | |
| 43 return configuration.frequency() > 0 && configuration.frequency() <= 60; | |
|
Mikhail
2016/09/16 16:23:54
PlatformSensorConfiguration::kMaxAllowedFrequency
| |
| 44 } | |
| 45 | |
| 46 PlatformSensorConfiguration | |
| 47 PlatformSensorAmbientLightMac::GetDefaultConfiguration() { | |
| 48 PlatformSensorConfiguration default_configuration; | |
| 49 // Default configuration inherited from content/browser/device_sensors. | |
| 50 default_configuration.set_frequency(5); | |
| 51 return default_configuration; | |
| 52 } | |
| 53 | |
| 54 void PlatformSensorAmbientLightMac::UpdateReading() { | |
| 55 uint64_t lux_value[2]; | |
| 56 platformSensor_->ReadSensorValue(lux_value); | |
| 57 uint64_t mean = (lux_value[0] + lux_value[1]) / 2; | |
| 58 double lux = device::LMUvalueToLux(mean); | |
| 59 if (lux == current_lux) | |
| 60 return; | |
| 61 current_lux = lux; | |
| 62 DeviceLightHardwareBuffer* light_buffer = | |
| 63 static_cast<DeviceLightHardwareBuffer*>(shared_buffer_mapping_.get()); | |
| 64 light_buffer->seqlock.WriteBegin(); | |
| 65 light_buffer->data.illuminance = lux; | |
| 66 light_buffer->seqlock.WriteEnd(); | |
| 67 ui_task_runner_->PostTask( | |
| 68 FROM_HERE, | |
| 69 base::Bind(&PlatformSensorAmbientLightMac::NotifySensorReadingChanged, | |
| 70 base::Unretained(this))); | |
| 71 } | |
| 72 | |
| 73 } // namespace device | |
| OLD | NEW |