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

Unified Diff: ambient_light_sensor.cc

Issue 6307010: Use Signal Callback in Ambient Light Sensor (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/power_manager.git@master
Patch Set: Created 9 years, 11 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
« ambient_light_sensor.h ('K') | « ambient_light_sensor.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ambient_light_sensor.cc
diff --git a/ambient_light_sensor.cc b/ambient_light_sensor.cc
index ba56f7616bafde6f1d2f80e6ccf0a706830535b1..b7b89ce162f8a23381af014d21895f0816466b87 100644
--- a/ambient_light_sensor.cc
+++ b/ambient_light_sensor.cc
@@ -28,19 +28,19 @@ AmbientLightSensor::~AmbientLightSensor() {
close(als_fd_);
}
-bool AmbientLightSensor::DeferredInit(AmbientLightSensor* self) {
+bool AmbientLightSensor::DeferredInit() {
// tsl2561 is currently the only supported light sensor.
// If the lux file is not immediately found, issue a deferral
// message and try again later.
- self->als_fd_ = open("/sys/class/iio/device0/lux", O_RDONLY);
- if (self->als_fd_ == -1) {
- if (self->still_deferring_)
+ als_fd_ = open("/sys/class/iio/device0/lux", O_RDONLY);
+ if (als_fd_ == -1) {
+ if (still_deferring_)
return false;
LOG(WARNING) << "Deferring lux: " << strerror(errno);
- self->still_deferring_ = true;
+ still_deferring_ = true;
return false;
}
- if (self->still_deferring_)
+ if (still_deferring_)
LOG(INFO) << "Finally found the lux file";
return true;
}
@@ -72,36 +72,35 @@ void AmbientLightSensor::EnableOrDisableSensor(PowerState power, DimState dim) {
// Start polling.
LOG(INFO) << "Enabling light sensor poll";
is_polling_ = true;
- g_timeout_add(kSensorPollPeriodMs, ReadAls, this);
+ g_timeout_add(kSensorPollPeriodMs, AmbientLightSensor::ReadAlsThunk, this);
Simon Que 2011/01/21 20:51:14 Is "AmbientLightSensor::" necessary?
Benson Leung 2011/01/21 20:55:57 Nope. Removed.
}
-gboolean AmbientLightSensor::ReadAls(gpointer data) {
- AmbientLightSensor* self = static_cast<AmbientLightSensor*>(data);
- if (self->disable_polling_) {
- self->is_polling_ = false;
+gboolean AmbientLightSensor::ReadAls() {
+ if (disable_polling_) {
+ is_polling_ = false;
return false; // Returning false removes the timeout.
}
// We really want to read the ambient light level.
// Complete the deferred lux file open if necessary.
- if (self->als_fd_ < 0) {
- if (!DeferredInit(self))
+ if (als_fd_ < 0) {
+ if (!DeferredInit())
return true; // Return true to try again later.
}
char buffer[10];
int n;
- if (lseek(self->als_fd_, 0, SEEK_SET) != 0 ||
- (n = read(self->als_fd_, buffer, sizeof(buffer) - 1)) == -1) {
+ if (lseek(als_fd_, 0, SEEK_SET) != 0 ||
+ (n = read(als_fd_, buffer, sizeof(buffer) - 1)) == -1) {
LOG(WARNING) << "Unable to read light sensor file";
}
if (n > 0 && n < static_cast<int>(sizeof(buffer))) {
buffer[n] = '\0';
int luxval = atoi(buffer);
int64 level = Tsl2563LuxToLevel(luxval);
- if (level != self->last_level_ && self->controller_)
- self->controller_->SetAlsBrightnessLevel(level);
- self->last_level_ = level;
+ if (level != last_level_ && controller_)
+ controller_->SetAlsBrightnessLevel(level);
+ last_level_ = level;
}
return true;
}
« ambient_light_sensor.h ('K') | « ambient_light_sensor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698