Merge lp:~rsalveti/powerd/progressive-brightness into lp:powerd

Proposed by Ricardo Salveti
Status: Merged
Approved by: Jim Hodapp
Approved revision: 150
Merged at revision: 149
Proposed branch: lp:~rsalveti/powerd/progressive-brightness
Merge into: lp:powerd
Diff against target: 104 lines (+49/-21)
1 file modified
src/backlight.c (+49/-21)
To merge this branch: bzr merge lp:~rsalveti/powerd/progressive-brightness
Reviewer Review Type Date Requested Status
Jim Hodapp (community) code Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+246651@code.launchpad.net

Commit message

backlight: setting brightness in a progressive way (LP: #1411417)

Description of the change

backlight: setting brightness in a progressive way (LP: #1411417)

Also don't need the old scale code as that could lead in a higher value than supported by the hardware.

To post a comment you must log in.
Revision history for this message
Jim Hodapp (jhodapp) wrote :

Minor tweak below.

review: Needs Fixing (code)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
150. By Ricardo Salveti

backlight: using const for the set_brightness vars

Revision history for this message
Jim Hodapp (jhodapp) wrote :

Looks good, can't wait to see this fix land.

review: Approve (code)
151. By Ricardo Salveti

backlight: don't need progressive set when resuming

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/backlight.c'
2--- src/backlight.c 2014-08-12 08:52:23 +0000
3+++ src/backlight.c 2015-01-15 23:02:08 +0000
4@@ -26,6 +26,7 @@
5 #include <glib-object.h>
6 #include <android/hardware/hardware.h>
7 #include <android/hardware/lights.h>
8+#include <unistd.h>
9
10 #include "powerd-internal.h"
11 #include "device-config.h"
12@@ -52,6 +53,10 @@
13 int dim_brightness = 10;
14 int current_brightness = -1;
15
16+/* Used when setting up brightness */
17+const int set_brightness_usleep = 5000;
18+const int set_brightness_step = 2;
19+
20 static int user_brightness;
21
22 int powerd_get_brightness(void)
23@@ -64,11 +69,26 @@
24 return max_brightness;
25 }
26
27+static int set_brightness_hal(int brightness)
28+{
29+ struct light_state_t state = { .flashMode = LIGHT_FLASH_NONE,
30+ .brightnessMode = BRIGHTNESS_MODE_USER };
31+ int ret;
32+
33+ /* color is ARGB, docs specifiy that alpha should be 0xff,
34+ * although it also instructs callers to ignore it. */
35+ state.color = (int)((0xffU << 24) | (brightness << 16) |
36+ (brightness << 8) | brightness);
37+ ret = light_dev->set_light(light_dev, &state);
38+ if (ret != 0)
39+ powerd_error("light_dev: failed to set brightness to %i", brightness);
40+
41+ return ret;
42+}
43+
44 int powerd_set_brightness(int brightness)
45 {
46- struct light_state_t state;
47- int scaled_brightness;
48- int ret;
49+ int ret, i;
50
51 if (!light_dev)
52 return -ENODEV;
53@@ -77,25 +97,33 @@
54 if (brightness == current_brightness)
55 return 0;
56
57- /* Scale brightness to range of 0 to 255 */
58- scaled_brightness = (brightness * 255) / max_brightness;
59- if (scaled_brightness > 255)
60- scaled_brightness = 255;
61-
62- state.flashMode = LIGHT_FLASH_NONE;
63- state.brightnessMode = BRIGHTNESS_MODE_USER;
64- /* color is ARGB, docs specifiy that alpha should be 0xff,
65- * although it also instructs callers to ignore it. */
66- state.color = (int)((0xffU << 24) | (scaled_brightness << 16) |
67- (scaled_brightness << 8) | scaled_brightness);
68-
69- ret = light_dev->set_light(light_dev, &state);
70- if (!ret) {
71- powerd_debug("light_dev: set_light to brightness %i succ", brightness);
72+ powerd_debug("light_dev: setting brightness to %i", brightness);
73+
74+ /* If current < min, it means we're comming from a resume */
75+ if (current_brightness >= min_user_brightness) {
76+ /* Set brightness in a progressive way, per step */
77+ if (brightness > current_brightness) {
78+ for (i = current_brightness; i < brightness;
79+ i = i + set_brightness_step) {
80+ set_brightness_hal(i);
81+ usleep(set_brightness_usleep);
82+ }
83+ } else {
84+ for (i = current_brightness; i > brightness;
85+ i = i - set_brightness_step) {
86+ set_brightness_hal(i);
87+ usleep(set_brightness_usleep);
88+ }
89+ }
90+ }
91+
92+ /* Now set the final value (only care about error here as if
93+ * the last set works, we're good) */
94+ ret = set_brightness_hal(brightness);
95+ if (!ret)
96 current_brightness = brightness;
97- } else {
98- powerd_debug("light_dev: set_light to brightness %i failed", brightness);
99- }
100+ else
101+ powerd_error("light_dev: failed to set brightness to %i", brightness);
102
103 return ret;
104 }

Subscribers

People subscribed via source and target branches