Compare commits

...

14 Commits
v1.5 ... master

Author SHA1 Message Date
43542d84dc Merge branch 'master' of ssh://rexy712-server:1995/var/git/repos/rexy712/thinkpad_backlight 2022-01-30 20:43:09 -08:00
398146a0d8 Fix parsing of restore file 2022-01-30 20:42:12 -08:00
rexy712
b944ee8dec Version bump 2021-01-17 09:35:35 -08:00
rexy712
927160ba01 Fix restore file not working 2021-01-17 09:34:21 -08:00
rexy712
42dee2de78 Update to version 1.5.2 2021-01-03 10:01:25 -08:00
rexy712
61e36bed19 Fix error output on invalid permissions to write to brightness file 2021-01-03 09:54:49 -08:00
rexy712
50412e0006 Fix CMakeLists.txt 2020-04-09 15:22:05 -07:00
rexy712
19d736bc84 Fix usage of older rjp parse flag 2020-04-09 14:56:02 -07:00
rexy712
db3036e85b Merge branch 'master' of ssh://rexy712-server:1995/var/git/repos/rexy712/thinkpad_backlight 2020-04-09 14:39:01 -07:00
rexy712
26bd685296 Update to new rjp api 2020-04-09 14:38:52 -07:00
rexy712
fa187be8b0 Update CMakeLists to use rjp's pkg-config files 2020-03-07 13:19:34 -08:00
rexy712
bbce4dc8fe Updated version 2020-02-23 10:27:13 -08:00
rexy712
9c4425ff54 Update to new rjp api 2020-02-23 10:24:10 -08:00
rexy712
2e0ee84ca7 Add support for new rjp api 2019-11-09 21:18:00 -08:00
12 changed files with 71 additions and 41 deletions

View File

@ -1,6 +1,7 @@
include(CMakeDependentOption)
cmake_minimum_required(VERSION 3.1)
project(rexbacklight)
cmake_minimum_required(VERSION 3.1)
include(CMakeDependentOption)
include(GNUInstallDirs)
set(SCRIPT_DIR ${CMAKE_SOURCE_DIR}/scripts)
@ -23,7 +24,7 @@ if(PYTHONINTERP_FOUND)
add_custom_command(
OUTPUT ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E echo "//File generated by CMake. Do not edit!" > ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_TAG_NAME \"v1.5\"" > ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_TAG_NAME \"v1.5.3\"" > ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GIT_VERSION_TMP_FILE} ${GIT_VERSION_FILE}
COMMAND ${CMAKE_COMMAND} -E remove ${GIT_VERSION_TMP_FILE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
@ -34,7 +35,7 @@ elseif(UNIX)
add_custom_command(
OUTPUT ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E echo "//File generated by CMake. Do not edit!" > ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_TAG_NAME \"v1.5\"" > ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_TAG_NAME \"v1.5.3\"" > ${GIT_VERSION_TMP_FILE}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GIT_VERSION_TMP_FILE} ${GIT_VERSION_FILE}
COMMAND ${CMAKE_COMMAND} -E remove ${GIT_VERSION_TMP_FILE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
@ -61,8 +62,8 @@ endif()
#locate rjp library requirements
if(ENABLE_RESTORE_FILE)
find_library(RJP_LIB rjp)
find_path(RJP_HEADER_DIR rjp.h)
find_package(PkgConfig REQUIRED)
pkg_check_modules(RJP REQUIRED rjp)
#temporary library (no actual library generated)
add_library(common_srcs OBJECT src/cmd.c src/common.c src/restore.c)
add_definitions("-DENABLE_RESTORE_FILE")
@ -80,8 +81,9 @@ if(BUILD_REXLEDCTL)
target_compile_definitions(rexledctl PRIVATE REXLEDCTL) #define REXLEDCTL in C files
target_link_libraries(rexledctl PRIVATE $<TARGET_OBJECTS:common_srcs>) #link with the common_srcs "library"
if(ENABLE_RESTORE_FILE)
target_link_libraries(rexledctl PRIVATE "${RJP_LIB}") #link with rjp
target_include_directories(rexledctl PUBLIC "${RJP_HEADER_DIR}") #include rjp.h directory
target_link_libraries(rexledctl PRIVATE "${RJP_LIBRARIES}") #link with rjp
target_include_directories(rexledctl PUBLIC "${RJP_INCLUDE_DIRS}") #include rjp.h directory
target_compile_options(rexledctl PUBLIC ${RJP_CFLAGS_OTHER})
endif()
install(TARGETS rexledctl RUNTIME DESTINATION bin)
if(INSTALL_UDEV_LED_RULE)
@ -95,8 +97,9 @@ if(BUILD_REXBACKLIGHT)
target_compile_definitions(rexbacklight PRIVATE REXBACKLIGHT)
target_link_libraries(rexbacklight PRIVATE $<TARGET_OBJECTS:common_srcs>)
if(ENABLE_RESTORE_FILE)
target_link_libraries(rexbacklight PRIVATE "${RJP_LIB}")
target_include_directories(rexbacklight PUBLIC "${RJP_HEADER_DIR}")
target_link_libraries(rexbacklight PRIVATE "${RJP_LIBRARIES}")
target_include_directories(rexbacklight PUBLIC "${RJP_INCLUDE_DIRS}")
target_compile_options(rexbacklight PUBLIC ${RJP_CFLAGS_OTHER})
endif()
install(TARGETS rexbacklight RUNTIME DESTINATION bin)
if(INSTALL_UDEV_BACKLIGHT_RULE)

View File

@ -7,9 +7,11 @@ I've also since added a program to control LED devices, rexledctl (best name I c
Either program can be built alone or both together. This is configured using some cmake magic.
Current version is 1.3.1 as of writing this, so if the version is much newer, remind me to update this readme.
Current version is 1.5.2 as of writing this, so if the version is much newer, remind me to update this readme.
```
rexbacklight version v1.5.2
Usage: rexbacklight [argument] [options] [argument]
Options:
@ -25,6 +27,8 @@ Options:
print device names to stdout and exit
--restore|-R
reassign previously saved device values
--no-save|-N
do not write any data to the restore file
--help|-h
print this help message and exit
--version
@ -38,7 +42,7 @@ Arguments:
max
min
rexbacklight Copyright (C) 2018 rexy712
rexbacklight Copyright (C) 2018-2021 rexy712
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; see the GNU GPLv3 for details.

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018 rexy712
Copyright (C) 2018-2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018 rexy712
Copyright (C) 2018-2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018 rexy712
Copyright (C) 2018-2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018 rexy712
Copyright (C) 2018-2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018 rexy712
Copyright (C) 2018-2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018 rexy712
Copyright (C) 2018-2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018 rexy712
Copyright (C) 2018-2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018 rexy712
Copyright (C) 2018-2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -94,7 +94,7 @@ _Noreturn void usage(int exit_val){
printf(" max\n");
printf(" min\n");
printf("\n%s Copyright (C) 2018 rexy712\n", executable_name());
printf("\n%s Copyright (C) 2018-2021 rexy712\n", executable_name());
printf("This program comes with ABSOLUTELY NO WARRANTY.\n");
printf("This is free software, and you are welcome to redistribute it\n");
printf("under certain conditions; see the GNU GPLv3 for details.\n");

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018 rexy712
Copyright (C) 2018-2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -77,7 +77,7 @@ RJP_value* read_restore_file(const char* file){
i = fread(file_contents, filesize, 1, fp);
fclose(fp);
file_contents[filesize] = 0;
RJP_value* root = rjp_parse(file_contents);
RJP_value* root = rjp_parse(file_contents, RJP_PARSE_ALLOW_COMMENTS, NULL);
free(file_contents);
return root;
}
@ -93,8 +93,10 @@ static RJP_value* restore_file_handle(void){
}
RJP_value* find_matching_json_device(const char* name, RJP_value* root){
for(RJP_value* curr = rjp_get_member(root);curr;curr = rjp_next_member(curr)){
if(!strcmp(rjp_member_name(curr), name)){
RJP_object_iterator it;
rjp_init_object_iterator(&it, root);
for(RJP_value* curr = rjp_object_iterator_current(&it);curr;curr = rjp_object_iterator_next(&it)){
if(!strcmp(rjp_member_key(curr)->value, name)){
return curr;
}
}
@ -114,7 +116,7 @@ int restore_to_delta(struct arg_values* curr){
return 0;
}
curr->operation = OP_SET;
curr->delta = rjp_value_dfloat(match);
curr->delta = rjp_get_float(match);
return 1;
}
void prep_restore(struct arg_values* a){
@ -124,10 +126,12 @@ void prep_restore(struct arg_values* a){
}
void save_restore_file(struct string_array* devices, struct arg_values* args){
RJP_object_iterator it;
RJP_value* rf = restore_file_handle();
if(!rf)
rf = rjp_init_json();
for(RJP_value* mem = rjp_get_member(rf);mem;mem = rjp_next_member(mem)){
rf = rjp_new_object();
rjp_init_object_iterator(&it, rf);
for(RJP_value* mem = rjp_object_iterator_current(&it);mem;mem = rjp_object_iterator_next(&it)){
for(struct arg_values* curr = args->next, *prev = args;curr;prev = curr, curr = curr->next){
if(curr->operation != OP_SET || curr->flags & ARG_FLAG_NO_SAVE){
prev->next = curr->next;
@ -135,8 +139,8 @@ void save_restore_file(struct string_array* devices, struct arg_values* args){
curr = prev;
continue;
}
if(!strcmp(rjp_member_name(mem), curr->device)){
rjp_set_value(mem, rjp_dfloat(curr->delta));
if(!strcmp(rjp_member_key(mem)->value, curr->device)){
rjp_set_float(mem, curr->delta);
prev->next = curr->next;
free(curr);
break;
@ -144,12 +148,14 @@ void save_restore_file(struct string_array* devices, struct arg_values* args){
}
}
for(struct arg_values* curr = args->next;curr;curr = curr->next){
if(curr->operation == OP_SET)
rjp_add_member(rf, curr->device, 0, rjp_dfloat(curr->delta));
if(curr->operation == OP_SET){
RJP_value* newmem = rjp_new_member(rf, curr->device, 0);
rjp_set_float(newmem, curr->delta);
}
}
free_cmd_args(args);
char* tmp = rjp_to_json(rf);
char* tmp = rjp_to_json(rf, RJP_FORMAT_NONE);
char* rfil = restore_file();
FILE* restf = fopen(rfil, "w");
if(!restf){

View File

@ -1,6 +1,6 @@
/**
rexbacklight
Copyright (C) 2018 rexy712
Copyright (C) 2018-2021 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -63,6 +63,15 @@ const char* max_brightness_file(void){return "max_brightness";}
/////////////////////////////////////////////////////////////////////////////////////////////
//create a copy of a string and append a '/' character to the end
char* add_slash_to(const char* name, size_t namelen){
char* newname = malloc(namelen + 2);
memcpy(newname, name, namelen);
newname[namelen++] = '/';
newname[namelen] = 0;
return newname;
}
//Get a list of led/backlight devices in sysfs
struct string_array get_device_sources(void){
DIR* fd;
@ -162,6 +171,12 @@ void sleep_for(double time){
nanosleep(&ts, NULL);
}
void return_to_root_dir(void){
if(chdir(device_dir())){
io_error(IO_ERROR_OPEN, IO_ERROR_DIR, device_dir());
return_value = RETVAL_INVALID_DIR;
}
}
//update brightness incrementally over requested millisecond time interval
void fade_out(struct arg_values* arg){
FILE* fd;
@ -177,8 +192,11 @@ void fade_out(struct arg_values* arg){
start = get_time();
fd = fopen(brightness_file(), "w+");
if(!fd){
io_error_3(IO_ERROR_OPEN, IO_ERROR_FILE, device_dir(), arg->device, brightness_file());
char* devname = add_slash_to(arg->device, strlen(arg->device));
io_error_3(IO_ERROR_OPEN, IO_ERROR_FILE, device_dir(), devname, brightness_file());
return_value = RETVAL_INVALID_FILE;
free(devname);
return_to_root_dir();
return;
}
fprintf(fd, "%d", (int)value);
@ -201,18 +219,17 @@ void fade_out(struct arg_values* arg){
}
fd = fopen(brightness_file(), "w+");
if(!fd){
io_error_3(IO_ERROR_OPEN, IO_ERROR_FILE, device_dir(), arg->device, brightness_file());
char* devname = add_slash_to(arg->device, strlen(arg->device));
io_error_3(IO_ERROR_OPEN, IO_ERROR_FILE, device_dir(), devname, brightness_file());
return_value = RETVAL_INVALID_FILE;
free(devname);
return_to_root_dir();
return;
}
fprintf(fd, "%d", arg->act_delta);
fclose(fd);
if(chdir(device_dir())){
io_error(IO_ERROR_OPEN, IO_ERROR_DIR, device_dir());
return_value = RETVAL_INVALID_DIR;
return;
}
return_to_root_dir();
}
int prep_offset(struct arg_values* args){