Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(467)

Side by Side Diff: device/generic_sensor/platform_sensor_ambient_light_mac.cc

Issue 2332903002: [sensors] [mac] Implement ambient light sensor for macOS (Closed)
Patch Set: More style fixes and build fixes Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 : PlatformSensorMac(type,
23 std::move(mapping),
24 provider,
25 polling_thread_task_runner),
26 current_lux(0) {
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;
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 base::Unretained(this)));
Mikhail 2016/09/19 06:25:18 GetWeakPtr() to solve the potential raise conditio
68 }
69
70 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698