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
=== modified file 'src/backlight.c'
--- src/backlight.c 2014-08-12 08:52:23 +0000
+++ src/backlight.c 2015-01-15 23:02:08 +0000
@@ -26,6 +26,7 @@
26#include <glib-object.h>26#include <glib-object.h>
27#include <android/hardware/hardware.h>27#include <android/hardware/hardware.h>
28#include <android/hardware/lights.h>28#include <android/hardware/lights.h>
29#include <unistd.h>
2930
30#include "powerd-internal.h"31#include "powerd-internal.h"
31#include "device-config.h"32#include "device-config.h"
@@ -52,6 +53,10 @@
52int dim_brightness = 10;53int dim_brightness = 10;
53int current_brightness = -1;54int current_brightness = -1;
5455
56/* Used when setting up brightness */
57const int set_brightness_usleep = 5000;
58const int set_brightness_step = 2;
59
55static int user_brightness;60static int user_brightness;
5661
57int powerd_get_brightness(void)62int powerd_get_brightness(void)
@@ -64,11 +69,26 @@
64 return max_brightness;69 return max_brightness;
65}70}
6671
72static int set_brightness_hal(int brightness)
73{
74 struct light_state_t state = { .flashMode = LIGHT_FLASH_NONE,
75 .brightnessMode = BRIGHTNESS_MODE_USER };
76 int ret;
77
78 /* color is ARGB, docs specifiy that alpha should be 0xff,
79 * although it also instructs callers to ignore it. */
80 state.color = (int)((0xffU << 24) | (brightness << 16) |
81 (brightness << 8) | brightness);
82 ret = light_dev->set_light(light_dev, &state);
83 if (ret != 0)
84 powerd_error("light_dev: failed to set brightness to %i", brightness);
85
86 return ret;
87}
88
67int powerd_set_brightness(int brightness)89int powerd_set_brightness(int brightness)
68{90{
69 struct light_state_t state;91 int ret, i;
70 int scaled_brightness;
71 int ret;
7292
73 if (!light_dev)93 if (!light_dev)
74 return -ENODEV;94 return -ENODEV;
@@ -77,25 +97,33 @@
77 if (brightness == current_brightness)97 if (brightness == current_brightness)
78 return 0;98 return 0;
7999
80 /* Scale brightness to range of 0 to 255 */100 powerd_debug("light_dev: setting brightness to %i", brightness);
81 scaled_brightness = (brightness * 255) / max_brightness;101
82 if (scaled_brightness > 255)102 /* If current < min, it means we're comming from a resume */
83 scaled_brightness = 255;103 if (current_brightness >= min_user_brightness) {
84104 /* Set brightness in a progressive way, per step */
85 state.flashMode = LIGHT_FLASH_NONE; 105 if (brightness > current_brightness) {
86 state.brightnessMode = BRIGHTNESS_MODE_USER;106 for (i = current_brightness; i < brightness;
87 /* color is ARGB, docs specifiy that alpha should be 0xff,107 i = i + set_brightness_step) {
88 * although it also instructs callers to ignore it. */108 set_brightness_hal(i);
89 state.color = (int)((0xffU << 24) | (scaled_brightness << 16) |109 usleep(set_brightness_usleep);
90 (scaled_brightness << 8) | scaled_brightness);110 }
91111 } else {
92 ret = light_dev->set_light(light_dev, &state);112 for (i = current_brightness; i > brightness;
93 if (!ret) {113 i = i - set_brightness_step) {
94 powerd_debug("light_dev: set_light to brightness %i succ", brightness);114 set_brightness_hal(i);
115 usleep(set_brightness_usleep);
116 }
117 }
118 }
119
120 /* Now set the final value (only care about error here as if
121 * the last set works, we're good) */
122 ret = set_brightness_hal(brightness);
123 if (!ret)
95 current_brightness = brightness;124 current_brightness = brightness;
96 } else {125 else
97 powerd_debug("light_dev: set_light to brightness %i failed", brightness);126 powerd_error("light_dev: failed to set brightness to %i", brightness);
98 }
99127
100 return ret;128 return ret;
101}129}

Subscribers

People subscribed via source and target branches