Chromium Code Reviews| 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..b6f162b89d4e262e2cce5931a4096b49d1a94515 100644 |
| --- a/device/generic_sensor/platform_sensor_ambient_light_mac.cc |
| +++ b/device/generic_sensor/platform_sensor_ambient_light_mac.cc |
| @@ -54,14 +54,7 @@ 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); |
| + sensor->ReadSensorValue(); |
|
timvolodine
2016/10/18 19:26:13
would it make sense to make ReadSensorValue return
darktears
2016/10/18 19:56:58
The idea here was that at some point we will need
|
| } |
| bool PlatformSensorAmbientLightMac::StartSensor( |
| @@ -100,8 +93,10 @@ bool PlatformSensorAmbientLightMac::StartSensor( |
| kr = IOServiceOpen(light_sensor_service_, mach_task_self(), 0, |
| light_sensor_object_.InitializeInto()); |
| + if (kr != KERN_SUCCESS) |
| + return false; |
| - return kr == KERN_SUCCESS; |
| + return ReadSensorValue(); |
|
timvolodine
2016/10/18 19:26:13
is it possible that ReadSensorValue returns false
darktears
2016/10/18 19:56:58
Yes then we can clean it up.
|
| } |
| void PlatformSensorAmbientLightMac::StopSensor() { |
| @@ -111,17 +106,27 @@ void PlatformSensorAmbientLightMac::StopSensor() { |
| current_lux_ = 0.0; |
| } |
| -void PlatformSensorAmbientLightMac::UpdateReading(uint64_t lux_values[2]) { |
| +bool PlatformSensorAmbientLightMac::ReadSensorValue() { |
|
timvolodine
2016/10/18 19:26:13
maybe better name something like: ReadAndUpdate..
darktears
2016/10/18 19:56:58
I will change.
|
| + 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 |