modified: Makefile

modified:   config.h
	modified:   main.c
This commit is contained in:
Владимир 2024-11-09 12:52:59 +05:00
parent 1d210058ec
commit 7d8ba1a72a
3 changed files with 27 additions and 14 deletions

View File

@ -1,10 +1,13 @@
DESTDIR=/usr/local/bin
DESTDIR=/usr/bin
name=backlight
cc=tcc
all:main.c
gcc $^ -o ${name}
${cc} $^ -o ${name}
debug:
gcc -Wall -std=c99 -pg main.c -o ${name}
install:all
install -m 755 -t ${DESTDIR} ${name}

View File

@ -2,9 +2,20 @@
#ifndef CONFIG_H
#define CONFIG_H
// Maximum brightness
const char max_file[] = "/sys/class/backlight/amdgpu_bl0/max_brightness";
// Current brightness
const char target_file[] = "/sys/class/backlight/amdgpu_bl0/brightness";
// Help
const char help[] = "backlight command [N]\n\n\
command in {set, dec, inc, get, -h}\n\
N in [0 ... 100]\n\n\
get\t\tGet backlight\n\
set N\t\tSet backlight in N%\n\
dec N\t\tDec backlight at N%\n\
inc N\t\tInc backlight at N%\n\
-h\t\tShow help\n\
";
#endif

19
main.c
View File

@ -5,11 +5,6 @@
#include "config.h"
const char help[] = "backlight command N\n\n\
command in {set, dec, inc}\n\
N in [0 ... 100]\n\
";
//
int get_backlight(const char* file)
{
@ -59,7 +54,7 @@ int min_max(int value, int min, int max)
}
//
int change(char* arg, short int direction)
int change(char* arg, char direction)
{
float max = (float)get_backlight(max_file);
float current_value = (float)get_backlight(target_file);
@ -69,10 +64,11 @@ int change(char* arg, short int direction)
int new_value = current_value + direction*proc*one_proc;
set_backlight(target_file, min_max(new_value, 0, max));
return 0;
}
//
int main(int argc, char** argv)
{
if(argc == 3)
@ -89,15 +85,18 @@ int main(int argc, char** argv)
change(argv[2], -1);
if(strcmp(argv[1], "inc") == 0)
change(argv[2], 1);
}
if(argc == 2)
{
if(strcmp(argv[1], "get") == 0)
printf("%d/%d\n", get_backlight(target_file), get_backlight(max_file));
if(strcmp(argv[1], "-h") == 0)
printf("%s\n", help);
if(strcmp(argv[1], "--help") == 0)
printf("%s\n", help);
}
else
printf("%s\n", help);
return 0;
}