Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42dee2de78 | ||
|
|
61e36bed19 | ||
|
|
50412e0006 | ||
|
|
19d736bc84 | ||
|
|
db3036e85b | ||
|
|
26bd685296 | ||
|
|
fa187be8b0 | ||
|
|
bbce4dc8fe | ||
|
|
9c4425ff54 | ||
|
|
2e0ee84ca7 | ||
|
|
f868074f0c | ||
|
|
2fdd9fa13b | ||
|
|
40eec1fb23 | ||
|
|
42f93ba026 | ||
|
|
44ddaae28d | ||
|
|
5986fa8133 | ||
|
|
479e7c1f17 | ||
|
|
2dd52c32b7 |
@@ -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,9 +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 ${PYTHON_EXECUTABLE} ${SCRIPT_DIR}/git_branch_name.py >> ${GIT_VERSION_TMP_FILE}
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${SCRIPT_DIR}/git_commit_hash.py >> ${GIT_VERSION_TMP_FILE}
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${SCRIPT_DIR}/git_tag_name.py >> ${GIT_VERSION_TMP_FILE}
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_TAG_NAME \"v1.5.2\"" > ${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}
|
||||
@@ -36,9 +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 ${SCRIPT_DIR}/git_branch_name.sh >> ${GIT_VERSION_TMP_FILE}
|
||||
COMMAND ${SCRIPT_DIR}/git_commit_hash.sh >> ${GIT_VERSION_TMP_FILE}
|
||||
COMMAND ${SCRIPT_DIR}/git_tag_name.sh >> ${GIT_VERSION_TMP_FILE}
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "#define GIT_TAG_NAME \"v1.5.2\"" > ${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}
|
||||
@@ -65,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")
|
||||
@@ -82,11 +79,12 @@ if(BUILD_REXLEDCTL)
|
||||
add_executable (rexledctl src/rexbacklight.c)
|
||||
add_dependencies(rexledctl common_srcs) #force common_srcs to be built first
|
||||
target_compile_definitions(rexledctl PRIVATE REXLEDCTL) #define REXLEDCTL in C files
|
||||
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
|
||||
endif()
|
||||
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_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)
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/rules/91-leds.rules DESTINATION ${UDEV_DIR})
|
||||
@@ -95,13 +93,14 @@ endif()
|
||||
#build backlight control program
|
||||
if(BUILD_REXBACKLIGHT)
|
||||
add_executable (rexbacklight src/rexbacklight.c)
|
||||
add_dependencies(rexledctl common_srcs)
|
||||
add_dependencies(rexbacklight common_srcs)
|
||||
target_compile_definitions(rexbacklight PRIVATE REXBACKLIGHT)
|
||||
if(ENABLE_RESTORE_FILE)
|
||||
target_link_libraries(rexbacklight PRIVATE "${RJP_LIB}")
|
||||
target_include_directories(rexbacklight PUBLIC "${RJP_HEADER_DIR}")
|
||||
endif()
|
||||
target_link_libraries(rexbacklight PRIVATE $<TARGET_OBJECTS:common_srcs>)
|
||||
if(ENABLE_RESTORE_FILE)
|
||||
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)
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/rules/91-backlight.rules DESTINATION ${UDEV_DIR})
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -155,7 +155,7 @@ struct arg_values process_cmd_args(int argc, char** argv){
|
||||
|
||||
//Check for switches
|
||||
if(CHECK_OPTION(GET, argv[i])){
|
||||
curr->operation |= OP_GET;
|
||||
curr->operation = OP_GET;
|
||||
continue;
|
||||
|
||||
}else if(CHECK_OPTION(FADE, argv[i])){
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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_NO_EXT, 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){
|
||||
|
||||
@@ -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){
|
||||
@@ -264,7 +281,8 @@ void do_list(struct arg_values* args){
|
||||
}
|
||||
|
||||
//Run requested operation on a per device basis
|
||||
void run_device_operations(struct arg_values* a){
|
||||
int run_device_operations(struct arg_values* a){
|
||||
int changes = 0;
|
||||
for(a = a->next;a;a = a->next){
|
||||
switch(a->operation){
|
||||
case OP_LIST:
|
||||
@@ -284,10 +302,12 @@ void run_device_operations(struct arg_values* a){
|
||||
case OP_SET:
|
||||
if(prep_offset(a))
|
||||
break;
|
||||
++changes;
|
||||
fade_out(a);
|
||||
break;
|
||||
};
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
//If a global operation is requested, run this to fill arg with all devices, each with the global operation
|
||||
@@ -312,6 +332,7 @@ int main(int argc, char** argv){
|
||||
|
||||
struct arg_values args; //A linked list of devices and the requested settings.
|
||||
struct string_array device_names; //List of all led/backlight devices in sysfs.
|
||||
int should_save = 0;
|
||||
|
||||
args = process_cmd_args(argc, argv);
|
||||
if(args.operation == OP_USAGE){
|
||||
@@ -360,9 +381,14 @@ int main(int argc, char** argv){
|
||||
if(!args.next){
|
||||
populate_args(&args, &device_names);
|
||||
}
|
||||
run_device_operations(&args);
|
||||
should_save = (run_device_operations(&args) > 0);
|
||||
#ifdef ENABLE_RESTORE_FILE
|
||||
save_restore_file(&device_names, &args); //performs cleanup on args
|
||||
if(should_save)
|
||||
save_restore_file(&device_names, &args); //performs cleanup on args
|
||||
else
|
||||
free_cmd_args(&args);
|
||||
#else
|
||||
free_cmd_args(&args);
|
||||
#endif
|
||||
|
||||
free_string_array(&device_names);
|
||||
|
||||
Reference in New Issue
Block a user