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

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

Issue 2447273002: [sensors] [mac] Fix ambient light sensor not updating its value when closing the lid with a monitor… (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « device/generic_sensor/platform_sensor_ambient_light_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/generic_sensor/platform_sensor_ambient_light_mac.h" 5 #include "device/generic_sensor/platform_sensor_ambient_light_mac.h"
6 6
7 #include <IOKit/IOMessage.h> 7 #include <IOKit/IOMessage.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "device/base/synchronization/shared_memory_seqlock_buffer.h" 10 #include "device/base/synchronization/shared_memory_seqlock_buffer.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 IONotificationPortSetDispatchQueue( 87 IONotificationPortSetDispatchQueue(
88 light_sensor_port_.get(), 88 light_sensor_port_.get(),
89 dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)); 89 dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0));
90 90
91 kern_return_t kr = IOServiceAddInterestNotification( 91 kern_return_t kr = IOServiceAddInterestNotification(
92 light_sensor_port_.get(), light_sensor_service_, kIOGeneralInterest, 92 light_sensor_port_.get(), light_sensor_service_, kIOGeneralInterest,
93 IOServiceCallback, this, light_sensor_notification_.InitializeInto()); 93 IOServiceCallback, this, light_sensor_notification_.InitializeInto());
94 if (kr != KERN_SUCCESS) 94 if (kr != KERN_SUCCESS)
95 return false; 95 return false;
96 96
97 kr = IOServiceAddInterestNotification(
98 light_sensor_port_.get(), light_sensor_service_, kIOBusyInterest,
99 IOServiceCallback, this,
100 light_sensor_busy_notification_.InitializeInto());
101 if (kr != KERN_SUCCESS)
102 return false;
103
97 kr = IOServiceOpen(light_sensor_service_, mach_task_self(), 0, 104 kr = IOServiceOpen(light_sensor_service_, mach_task_self(), 0,
98 light_sensor_object_.InitializeInto()); 105 light_sensor_object_.InitializeInto());
99 if (kr != KERN_SUCCESS) 106 if (kr != KERN_SUCCESS)
100 return false; 107 return false;
101 108
102 bool success = ReadAndUpdate(); 109 bool success = ReadAndUpdate();
103 if (!success) 110 if (!success)
104 StopSensor(); 111 StopSensor();
105 112
106 return success; 113 return success;
107 } 114 }
108 115
109 void PlatformSensorAmbientLightMac::StopSensor() { 116 void PlatformSensorAmbientLightMac::StopSensor() {
110 light_sensor_port_.reset(); 117 light_sensor_port_.reset();
111 light_sensor_notification_.reset(); 118 light_sensor_notification_.reset();
119 light_sensor_busy_notification_.reset();
112 light_sensor_object_.reset(); 120 light_sensor_object_.reset();
113 light_sensor_service_.reset(); 121 light_sensor_service_.reset();
114 current_lux_ = 0.0; 122 current_lux_ = 0.0;
115 } 123 }
116 124
117 bool PlatformSensorAmbientLightMac::ReadAndUpdate() { 125 bool PlatformSensorAmbientLightMac::ReadAndUpdate() {
118 uint32_t scalar_output_count = 2; 126 uint32_t scalar_output_count = 2;
119 uint64_t lux_values[2]; 127 uint64_t lux_values[2];
120 kern_return_t kr = IOConnectCallMethod( 128 kern_return_t kr = IOConnectCallMethod(
121 light_sensor_object_, LmuFunctionIndex::kGetSensorReadingID, nullptr, 0, 129 light_sensor_object_, LmuFunctionIndex::kGetSensorReadingID, nullptr, 0,
122 nullptr, 0, lux_values, &scalar_output_count, nullptr, 0); 130 nullptr, 0, lux_values, &scalar_output_count, nullptr, 0);
123 131
124 if (kr != KERN_SUCCESS) 132 if (kr != KERN_SUCCESS)
125 return false; 133 return false;
126 134
127 uint64_t mean = (lux_values[0] + lux_values[1]) / 2; 135 uint64_t mean = (lux_values[0] + lux_values[1]) / 2;
128 double lux = LMUvalueToLux(mean); 136 double lux = LMUvalueToLux(mean);
129 if (lux == current_lux_) 137 if (lux == current_lux_)
130 return true; 138 return true;
131 current_lux_ = lux; 139 current_lux_ = lux;
132 140
133 SensorReading reading; 141 SensorReading reading;
134 reading.timestamp = (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); 142 reading.timestamp = (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
135 reading.values[0] = current_lux_; 143 reading.values[0] = current_lux_;
136 UpdateSensorReading(reading, true); 144 UpdateSensorReading(reading, true);
137 return true; 145 return true;
138 } 146 }
139 147
140 } // namespace device 148 } // namespace device
OLDNEW
« no previous file with comments | « device/generic_sensor/platform_sensor_ambient_light_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698