Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ sudo make uninstall

## Usage
```sh
$ backlight_control
Usage: backlight_control [+|-]<value>
$ backlight_control -h
Usage: backlight_control [-h] [[+|-]<value>]

Examples:
backlight_control
backlight_control +10
backlight_control -10
backlight_control 50

```

`backlight_control` prints the current brightness

`backlight_control +n` increases brightness by n%

`backlight_control -n` decreases brightness by n%
Expand Down
16 changes: 12 additions & 4 deletions backlight_control.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/**
* A program to control the backlight brightness.
Expand All @@ -14,9 +15,10 @@

void print_usage(char *name) {
printf(
"Usage: %1$s [+|-]<value>\n"
"Usage: %1$s [-h] [[+|-]<value>]\n"
"\n"
"Examples:\n"
"\t%1$s\n"
"\t%1$s +10\n"
"\t%1$s -10\n"
"\t%1$s 50\n",
Expand All @@ -34,13 +36,19 @@ FILE *open_file(char *name) {
}

int main(int argc, char **argv) {
if (argc != 2) {
if (argc >= 2 && strcmp(argv[1], "-h") == 0) {
print_usage(argv[0]);
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
int value = strtol(argv[1], NULL, 10);
int value = (argc == 2) ? strtol(argv[1], NULL, 10) : 0;
FILE *brightness = open_file(BRIGHTNESS_FILE);
int brightness_value = MIN_BRIGHTNESS;
if (argc == 1) {
fscanf(brightness, "%d", &brightness_value);
printf("%.1f\n", 100.0 * brightness_value / MAX_BRIGHTNESS);
fclose(brightness);
return EXIT_SUCCESS;
}
switch (argv[1][0]) {
case '+':
case '-':
Expand Down