Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
|
Simon Que
2011/01/21 20:51:14
2011
Benson Leung
2011/01/21 20:55:57
Done.
| |
| 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 #ifndef POWER_MANAGER_AMBIENT_LIGHT_SENSOR_H_ | 5 #ifndef POWER_MANAGER_AMBIENT_LIGHT_SENSOR_H_ |
| 6 #define POWER_MANAGER_AMBIENT_LIGHT_SENSOR_H_ | 6 #define POWER_MANAGER_AMBIENT_LIGHT_SENSOR_H_ |
| 7 | 7 |
| 8 #include <glib.h> | 8 #include <glib.h> |
| 9 | 9 |
| 10 #include "power_manager/backlight_controller.h" | 10 #include "power_manager/backlight_controller.h" |
| 11 #include "power_manager/signal_callback.h" | |
| 11 | 12 |
| 12 namespace power_manager { | 13 namespace power_manager { |
| 13 | 14 |
| 14 // Get ambient light sensor data and feed it into the backlight interface. | 15 // Get ambient light sensor data and feed it into the backlight interface. |
| 15 // | 16 // |
| 16 // Example usage: | 17 // Example usage: |
| 17 // // Initialization: | 18 // // Initialization: |
| 18 // power_manager::BacklightController backlight_ctl(&backlight, &prefs); | 19 // power_manager::BacklightController backlight_ctl(&backlight, &prefs); |
| 19 // CHECK(backlight_ctl.Init()) << "fatal"; | 20 // CHECK(backlight_ctl.Init()) << "fatal"; |
| 20 // power_manager::AmbientLightSensor als(&backlight_ctl); | 21 // power_manager::AmbientLightSensor als(&backlight_ctl); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 40 // Initialize the AmbientLightSensor object. | 41 // Initialize the AmbientLightSensor object. |
| 41 // Open the lux file so we can read ambient light data. | 42 // Open the lux file so we can read ambient light data. |
| 42 // On success, return true; otherwise return false. | 43 // On success, return true; otherwise return false. |
| 43 bool Init(); | 44 bool Init(); |
| 44 | 45 |
| 45 // The backlight controller sends us power state events so we can | 46 // The backlight controller sends us power state events so we can |
| 46 // enable and disable polling. | 47 // enable and disable polling. |
| 47 void EnableOrDisableSensor(PowerState power, DimState dim); | 48 void EnableOrDisableSensor(PowerState power, DimState dim); |
| 48 | 49 |
| 49 private: | 50 private: |
| 50 static gboolean ReadAls(gpointer data); | 51 SIGNAL_CALLBACK_0(AmbientLightSensor, gboolean, ReadAls); |
| 51 static bool DeferredInit(AmbientLightSensor* self); | 52 bool DeferredInit(); |
| 52 | 53 |
| 53 // Return a luma level normalized to 100 based on the tsl2563 lux value. | 54 // Return a luma level normalized to 100 based on the tsl2563 lux value. |
| 54 // The luma level will modify the controller's brightness calculation. | 55 // The luma level will modify the controller's brightness calculation. |
| 55 static int64 Tsl2563LuxToLevel(int luxval); | 56 static int64 Tsl2563LuxToLevel(int luxval); |
| 56 | 57 |
| 57 // Use this to send AmbientLightSensor events to BacklightController. | 58 // Use this to send AmbientLightSensor events to BacklightController. |
| 58 BacklightController* controller_; | 59 BacklightController* controller_; |
| 59 | 60 |
| 60 // This is the ambient light sensor file descriptor. | 61 // This is the ambient light sensor file descriptor. |
| 61 int als_fd_; | 62 int als_fd_; |
| 62 | 63 |
| 63 // Record the last read ambient light level to reduce unnecessary events. | 64 // Record the last read ambient light level to reduce unnecessary events. |
| 64 int64 last_level_; | 65 int64 last_level_; |
| 65 | 66 |
| 66 // These flags are used to turn on and off polling. | 67 // These flags are used to turn on and off polling. |
| 67 bool is_polling_; | 68 bool is_polling_; |
| 68 bool disable_polling_; | 69 bool disable_polling_; |
| 69 | 70 |
| 70 // Issue reasonable diagnostics about the deferred lux file open. | 71 // Issue reasonable diagnostics about the deferred lux file open. |
| 71 bool still_deferring_; | 72 bool still_deferring_; |
| 72 | 73 |
| 73 DISALLOW_COPY_AND_ASSIGN(AmbientLightSensor); | 74 DISALLOW_COPY_AND_ASSIGN(AmbientLightSensor); |
| 74 }; | 75 }; |
| 75 | 76 |
| 76 } // namespace power_manager | 77 } // namespace power_manager |
| 77 | 78 |
| 78 #endif // POWER_MANAGER_AMBIENT_LIGHT_SENSOR_H_ | 79 #endif // POWER_MANAGER_AMBIENT_LIGHT_SENSOR_H_ |
| OLD | NEW |