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/shared_memory_seqlock_buffer.h" | |
11 | |
12 namespace device { | |
13 | |
14 using DeviceLightHardwareBuffer = SharedMemorySeqLockBuffer<double>; | |
15 | |
16 PlatformSensorAmbientLightMac::PlatformSensorAmbientLightMac( | |
17 mojom::SensorType type, | |
18 mojo::ScopedSharedBufferMapping mapping, | |
19 uint64_t buffer_size, | |
20 PlatformSensorProvider* provider, | |
21 scoped_refptr<base::SingleThreadTaskRunner> polling_thread_task_runner) | |
22 : PollingPlatformSensor(type, | |
23 std::move(mapping), | |
24 provider, | |
25 polling_thread_task_runner), | |
26 current_lux(0) { | |
maksims (do not use this acc)
2016/09/20 11:41:15
I think it should be still -1, because 0 is valid
| |
27 platformSensor_ = AmbientLightSensor::Create(); | |
28 } | |
29 | |
30 PlatformSensorAmbientLightMac::~PlatformSensorAmbientLightMac() = default; | |
31 | |
32 mojom::ReportingMode PlatformSensorAmbientLightMac::GetReportingMode() { | |
33 return mojom::ReportingMode::ON_CHANGE; | |
34 } | |
35 | |
36 bool PlatformSensorAmbientLightMac::CheckSensorConfiguration( | |
37 const PlatformSensorConfiguration& configuration) { | |
38 return configuration.frequency() > 0 && | |
39 configuration.frequency() <= | |
40 PlatformSensorConfiguration::kMaxAllowedFrequency; | |
41 } | |
42 | |
43 PlatformSensorConfiguration | |
44 PlatformSensorAmbientLightMac::GetDefaultConfiguration() { | |
45 PlatformSensorConfiguration default_configuration; | |
46 // Default configuration inherited from content/browser/device_sensors. | |
47 default_configuration.set_frequency(5); | |
48 return default_configuration; | |
49 } | |
50 | |
51 void PlatformSensorAmbientLightMac::UpdateReading() { | |
52 uint64_t lux_value[2]; | |
53 platformSensor_->ReadSensorValue(lux_value); | |
54 uint64_t mean = (lux_value[0] + lux_value[1]) / 2; | |
55 double lux = AmbientLightSensor::LMUvalueToLux(mean); | |
56 if (lux == current_lux) | |
57 return; | |
58 current_lux = lux; | |
maksims (do not use this acc)
2016/09/20 11:41:15
nit: current_lux -> current_lux_
| |
59 DeviceLightHardwareBuffer* light_buffer = | |
60 static_cast<DeviceLightHardwareBuffer*>(shared_buffer_mapping_.get()); | |
61 light_buffer->seqlock.WriteBegin(); | |
62 light_buffer->data = lux; | |
63 light_buffer->seqlock.WriteEnd(); | |
64 ui_task_runner_->PostTask( | |
65 FROM_HERE, | |
66 base::Bind(&PlatformSensorAmbientLightMac::NotifySensorReadingChanged, | |
67 this)); | |
68 } | |
69 | |
70 } // namespace device | |
OLD | NEW |