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

Side by Side Diff: ambient_light_sensor.h

Issue 6307010: Use Signal Callback in Ambient Light Sensor (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/power_manager.git@master
Patch Set: Added comments for ReadAls and Deffered Init. 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ambient_light_sensor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium OS 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 #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
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 // Handler for a periodic event that reads the ambient light sensor.
51 static bool DeferredInit(AmbientLightSensor* self); 52 SIGNAL_CALLBACK_0(AmbientLightSensor, gboolean, ReadAls);
53
54 // Deferred init for the als in case the light sensor starts late.
55 bool DeferredInit();
52 56
53 // Return a luma level normalized to 100 based on the tsl2563 lux value. 57 // Return a luma level normalized to 100 based on the tsl2563 lux value.
54 // The luma level will modify the controller's brightness calculation. 58 // The luma level will modify the controller's brightness calculation.
55 static int64 Tsl2563LuxToLevel(int luxval); 59 static int64 Tsl2563LuxToLevel(int luxval);
56 60
57 // Use this to send AmbientLightSensor events to BacklightController. 61 // Use this to send AmbientLightSensor events to BacklightController.
58 BacklightController* controller_; 62 BacklightController* controller_;
59 63
60 // This is the ambient light sensor file descriptor. 64 // This is the ambient light sensor file descriptor.
61 int als_fd_; 65 int als_fd_;
62 66
63 // Record the last read ambient light level to reduce unnecessary events. 67 // Record the last read ambient light level to reduce unnecessary events.
64 int64 last_level_; 68 int64 last_level_;
65 69
66 // These flags are used to turn on and off polling. 70 // These flags are used to turn on and off polling.
67 bool is_polling_; 71 bool is_polling_;
68 bool disable_polling_; 72 bool disable_polling_;
69 73
70 // Issue reasonable diagnostics about the deferred lux file open. 74 // Issue reasonable diagnostics about the deferred lux file open.
71 bool still_deferring_; 75 bool still_deferring_;
72 76
73 DISALLOW_COPY_AND_ASSIGN(AmbientLightSensor); 77 DISALLOW_COPY_AND_ASSIGN(AmbientLightSensor);
74 }; 78 };
75 79
76 } // namespace power_manager 80 } // namespace power_manager
77 81
78 #endif // POWER_MANAGER_AMBIENT_LIGHT_SENSOR_H_ 82 #endif // POWER_MANAGER_AMBIENT_LIGHT_SENSOR_H_
OLDNEW
« no previous file with comments | « no previous file | ambient_light_sensor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698