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

Unified Diff: device/generic_sensor/platform_sensor_ambient_light_mac.cc

Issue 2417643006: [sensors][mac] Make sure to update the sensor value when initializing the sensor. (Closed)
Patch Set: Last comments from Tim Created 4 years, 2 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/generic_sensor/platform_sensor_ambient_light_mac.cc
diff --git a/device/generic_sensor/platform_sensor_ambient_light_mac.cc b/device/generic_sensor/platform_sensor_ambient_light_mac.cc
index 7256cfb4bb72491b2f84823a0a38f1399fdfc6bf..d83114c3ac3d3dbb8b174ccd66d6619b604c1335 100644
--- a/device/generic_sensor/platform_sensor_ambient_light_mac.cc
+++ b/device/generic_sensor/platform_sensor_ambient_light_mac.cc
@@ -54,14 +54,10 @@ void PlatformSensorAmbientLightMac::IOServiceCallback(void* context,
void* message_argument) {
PlatformSensorAmbientLightMac* sensor =
static_cast<PlatformSensorAmbientLightMac*>(context);
- uint32_t scalar_output_count = 2;
- uint64_t lux_values[2];
- kern_return_t kr = IOConnectCallMethod(
- sensor->light_sensor_object_, LmuFunctionIndex::kGetSensorReadingID,
- nullptr, 0, nullptr, 0, lux_values, &scalar_output_count, nullptr, 0);
-
- if (kr == KERN_SUCCESS)
- sensor->UpdateReading(lux_values);
+ if (!sensor->ReadAndUpdate()) {
+ sensor->NotifySensorError();
+ sensor->StopSensor();
+ }
}
bool PlatformSensorAmbientLightMac::StartSensor(
@@ -100,28 +96,45 @@ bool PlatformSensorAmbientLightMac::StartSensor(
kr = IOServiceOpen(light_sensor_service_, mach_task_self(), 0,
light_sensor_object_.InitializeInto());
+ if (kr != KERN_SUCCESS)
+ return false;
+
+ bool success = ReadAndUpdate();
+ if (!success)
+ StopSensor();
- return kr == KERN_SUCCESS;
+ return success;
}
void PlatformSensorAmbientLightMac::StopSensor() {
light_sensor_port_.reset();
light_sensor_notification_.reset();
light_sensor_object_.reset();
+ light_sensor_service_.reset();
current_lux_ = 0.0;
}
-void PlatformSensorAmbientLightMac::UpdateReading(uint64_t lux_values[2]) {
+bool PlatformSensorAmbientLightMac::ReadAndUpdate() {
+ uint32_t scalar_output_count = 2;
+ uint64_t lux_values[2];
+ kern_return_t kr = IOConnectCallMethod(
+ light_sensor_object_, LmuFunctionIndex::kGetSensorReadingID, nullptr, 0,
+ nullptr, 0, lux_values, &scalar_output_count, nullptr, 0);
+
+ if (kr != KERN_SUCCESS)
+ return false;
+
uint64_t mean = (lux_values[0] + lux_values[1]) / 2;
double lux = LMUvalueToLux(mean);
if (lux == current_lux_)
- return;
+ return true;
current_lux_ = lux;
SensorReading reading;
reading.timestamp = (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
reading.values[0] = current_lux_;
UpdateSensorReading(reading, true);
+ return true;
}
} // namespace device
« 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