Skip to content

Commit 796306b

Browse files
authored
Merge pull request #5 from wyatt8740/no-offset
Cleaner patch to allow setting backlight to 0.
2 parents 15fff57 + 0420683 commit 796306b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

intel_backlight.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void print_usage() {
7575

7676
int main(int argc, char** argv)
7777
{
78-
uint32_t current, max, min;
78+
uint32_t current, max;
7979
uint32_t currentReg, maxReg;
8080
int result;
8181

@@ -104,11 +104,6 @@ int main(int argc, char** argv)
104104
current = reg_read(currentReg) & BACKLIGHT_DUTY_CYCLE_MASK;
105105
max = reg_read(maxReg) >> 16;
106106

107-
min = 0.5 + 0.5 * max / 100.0; // 0.5%
108-
/*
109-
printf ("min: %d, NUM_ELEMENTS(brightness_levels): %d\n", min,
110-
NUM_ELEMENTS(brightness_levels));
111-
*/
112107
result = 0.5 + current * 100.0 / max;
113108
printf ("Current backlight value: %d%% (%d/%d)\n", result, current, max);
114109

@@ -117,6 +112,9 @@ int main(int argc, char** argv)
117112
if (0 == strcmp(argv[1], "incr"))
118113
v = 0.5 + brightness_incr(result) * max / 100.0;
119114
else if (0 == strcmp(argv[1], "decr"))
115+
/* allowing decr to turn the backlight off might be a
116+
problem, since it could be done inadvertently and we don't
117+
know if any hw has problems with it. */
120118
v = 0.5 + brightness_decr(result) * max / 100.0;
121119
else {
122120
errno = 0;
@@ -129,13 +127,13 @@ int main(int argc, char** argv)
129127
return result;
130128
}
131129

132-
v = 0.5 + val * max / 100.0;
130+
v = val * max / 100.0;
133131
}
134132
/*
135133
printf("v: %d\n", v);
136134
*/
137-
if (v < min)
138-
v = min;
135+
if (v < 0)
136+
v = 0;
139137
else if (v > max)
140138
v = max;
141139
reg_write(BLC_PWM_CPU_CTL,
@@ -145,7 +143,7 @@ int main(int argc, char** argv)
145143
reg_write(currentReg,
146144
(reg_read(currentReg) &~ BACKLIGHT_DUTY_CYCLE_MASK) | v);
147145
(void) reg_read(currentReg);
148-
result = 0.5 + v * 100.0 / max;
146+
result = v * 100.0 / max;
149147
printf ("set backlight to %d%% (%d/%d)\n", result, v, max);
150148
}
151149
return result;

0 commit comments

Comments
 (0)