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 "base/message_loop/message_loop.h" | |
9 #include "content/browser/device_sensors/ambient_light_mac.h" | |
10 #include "content/common/shared_memory_seqlock_buffer.h" | |
11 #include "device/generic_sensor/platform_sensor_provider_mac.h" | |
12 #include "device/generic_sensor/platform_sensor_util_mac.h" | |
13 | |
14 namespace device { | |
15 | |
16 struct DeviceLightData { | |
17 DeviceLightData() : illuminance(-1) {} | |
shalamov
2016/09/13 09:52:34
Should it be 0?
| |
18 double illuminance; | |
19 }; | |
20 | |
21 typedef content::SharedMemorySeqLockBuffer<DeviceLightData> | |
22 DeviceLightHardwareBuffer; | |
23 | |
24 PlatformSensorAmbientLightMac::PlatformSensorAmbientLightMac( | |
25 mojom::SensorType type, | |
26 mojo::ScopedSharedBufferMapping mapping, | |
27 uint64_t buffer_size, | |
28 PlatformSensorProvider* provider) | |
29 : PlatformSensorMac(type, std::move(mapping), provider), | |
30 task_runner_(base::MessageLoop::current()->task_runner()) { | |
31 platformSensor_ = content::AmbientLightSensor::Create(); | |
32 } | |
33 | |
34 PlatformSensorAmbientLightMac::~PlatformSensorAmbientLightMac() = default; | |
35 | |
36 mojom::ReportingMode PlatformSensorAmbientLightMac::GetReportingMode() { | |
37 return mojom::ReportingMode::CONTINUOUS; | |
shalamov
2016/09/13 09:52:34
Should it be mojom::ReportingMode::ON_CHANGE, sinc
| |
38 } | |
39 | |
40 bool PlatformSensorAmbientLightMac::StartSensor( | |
41 const PlatformSensorConfiguration& configuration) { | |
42 PlatformSensorProviderMac::GetInstance()->BeginPollingSensor(this, | |
43 configuration); | |
44 return true; | |
45 } | |
46 | |
47 void PlatformSensorAmbientLightMac::StopSensor() { | |
48 PlatformSensorProviderMac::GetInstance()->StopPollingSensor(this); | |
49 } | |
50 | |
51 bool PlatformSensorAmbientLightMac::CheckSensorConfiguration( | |
52 const PlatformSensorConfiguration& configuration) { | |
53 return true; | |
54 } | |
55 | |
56 PlatformSensorConfiguration | |
57 PlatformSensorAmbientLightMac::GetDefaultConfiguration() { | |
58 PlatformSensorConfiguration default_configuration; | |
59 // Default configuration inherited from content/browser/device_sensors. | |
60 default_configuration.set_frequency(5); | |
61 return default_configuration; | |
62 } | |
63 | |
64 void PlatformSensorAmbientLightMac::UpdateReading() { | |
65 uint64_t lux_value[2]; | |
shalamov
2016/09/13 09:52:34
Is it possible to store previous value and fire No
| |
66 platformSensor_->ReadSensorValue(lux_value); | |
67 uint64_t mean = (lux_value[0] + lux_value[1]) / 2; | |
68 double lux = device::LMUvalueToLux(mean); | |
69 DeviceLightHardwareBuffer* light_buffer = | |
70 static_cast<DeviceLightHardwareBuffer*>(shared_buffer_mapping_.get()); | |
71 light_buffer->seqlock.WriteBegin(); | |
72 light_buffer->data.illuminance = lux; | |
73 light_buffer->seqlock.WriteEnd(); | |
74 task_runner_->PostTask( | |
75 FROM_HERE, | |
76 base::Bind(&PlatformSensorAmbientLightMac::NotifySensorReadingChanged, | |
77 base::Unretained(this))); | |
78 } | |
79 | |
80 } // namespace device | |
OLD | NEW |