Made restoration files optional
This commit is contained in:
parent
8244ebb50b
commit
dbfa9b9d12
@ -6,10 +6,6 @@ project(rexbacklight)
|
|||||||
set(rexbacklight_VERSION_MAJOR 1)
|
set(rexbacklight_VERSION_MAJOR 1)
|
||||||
set(rexbacklight_VERSION_MINOR 3)
|
set(rexbacklight_VERSION_MINOR 3)
|
||||||
set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include)
|
set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include)
|
||||||
configure_file(
|
|
||||||
"${INCLUDE_PATH}/config.h.in"
|
|
||||||
"${INCLUDE_PATH}/config.h"
|
|
||||||
)
|
|
||||||
|
|
||||||
#set project include directory
|
#set project include directory
|
||||||
include_directories("${INCLUDE_PATH}")
|
include_directories("${INCLUDE_PATH}")
|
||||||
@ -17,6 +13,7 @@ include_directories("${INCLUDE_PATH}")
|
|||||||
#setup cmake options
|
#setup cmake options
|
||||||
option(BUILD_REXLEDCTL "Build led control program" ON)
|
option(BUILD_REXLEDCTL "Build led control program" ON)
|
||||||
option(BUILD_REXBACKLIGHT "Build backlight control program" ON)
|
option(BUILD_REXBACKLIGHT "Build backlight control program" ON)
|
||||||
|
option(ENABLE_RESTORE_FILE "Enable backlight restoration from generated save file" ON)
|
||||||
option(XBACKLIGHT_COMPAT "Use xbacklight style options (eg -get -inc -dec)" OFF)
|
option(XBACKLIGHT_COMPAT "Use xbacklight style options (eg -get -inc -dec)" OFF)
|
||||||
CMAKE_DEPENDENT_OPTION(INSTALL_UDEV_LED_RULE "Install the udev rule to allow users of video group to control led devices" ON
|
CMAKE_DEPENDENT_OPTION(INSTALL_UDEV_LED_RULE "Install the udev rule to allow users of video group to control led devices" ON
|
||||||
"BUILD_REXLEDCTL" OFF)
|
"BUILD_REXLEDCTL" OFF)
|
||||||
@ -30,19 +27,31 @@ if(XBACKLIGHT_COMPAT)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
#locate rjp library requirements
|
#locate rjp library requirements
|
||||||
find_library(RJP_LIB rjp)
|
if(ENABLE_RESTORE_FILE)
|
||||||
find_path(RJP_HEADER_DIR rjp.h)
|
find_library(RJP_LIB rjp)
|
||||||
|
find_path(RJP_HEADER_DIR rjp.h)
|
||||||
|
#temporary library (no actual library generated)
|
||||||
|
add_library(common_srcs OBJECT src/cmd.c src/common.c src/restore.c)
|
||||||
|
set(enable_RESTORE_FILE "#define ENABLE_RESTORE_FILE")
|
||||||
|
else()
|
||||||
|
add_library(common_srcs OBJECT src/cmd.c src/common.c)
|
||||||
|
set(enable_RESTORE_FILE "")
|
||||||
|
endif()
|
||||||
|
|
||||||
#temporary library (no actual library generated)
|
configure_file(
|
||||||
add_library(common_srcs OBJECT src/cmd.c src/common.c src/restore.c)
|
"${INCLUDE_PATH}/config.h.in"
|
||||||
|
"${INCLUDE_PATH}/config.h"
|
||||||
|
)
|
||||||
|
|
||||||
if(BUILD_REXLEDCTL)
|
if(BUILD_REXLEDCTL)
|
||||||
add_executable (rexledctl src/rexbacklight.c)
|
add_executable (rexledctl src/rexbacklight.c)
|
||||||
add_dependencies(rexledctl common_srcs) #force common_srcs to be built first
|
add_dependencies(rexledctl common_srcs) #force common_srcs to be built first
|
||||||
target_compile_definitions(rexledctl PRIVATE REXLEDCTL) #define REXLEDCTL in C files
|
target_compile_definitions(rexledctl PRIVATE REXLEDCTL) #define REXLEDCTL in C files
|
||||||
target_link_libraries(rexledctl PRIVATE "${RJP_LIB}") #link with rjp
|
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"
|
target_link_libraries(rexledctl PRIVATE $<TARGET_OBJECTS:common_srcs>) #link with the common_srcs "library"
|
||||||
target_include_directories(rexledctl PUBLIC "${RJP_HEADER_DIR}") #include rjp.h directory
|
|
||||||
install(TARGETS rexledctl RUNTIME DESTINATION bin)
|
install(TARGETS rexledctl RUNTIME DESTINATION bin)
|
||||||
if(INSTALL_UDEV_LED_RULE)
|
if(INSTALL_UDEV_LED_RULE)
|
||||||
install(FILES ${CMAKE_SOURCE_DIR}/rules/91-leds.rules DESTINATION ${UDEV_DIR})
|
install(FILES ${CMAKE_SOURCE_DIR}/rules/91-leds.rules DESTINATION ${UDEV_DIR})
|
||||||
@ -52,9 +61,11 @@ if(BUILD_REXBACKLIGHT)
|
|||||||
add_executable (rexbacklight src/rexbacklight.c)
|
add_executable (rexbacklight src/rexbacklight.c)
|
||||||
add_dependencies(rexledctl common_srcs)
|
add_dependencies(rexledctl common_srcs)
|
||||||
target_compile_definitions(rexbacklight PRIVATE REXBACKLIGHT)
|
target_compile_definitions(rexbacklight PRIVATE REXBACKLIGHT)
|
||||||
target_link_libraries(rexbacklight PRIVATE "${RJP_LIB}")
|
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>)
|
target_link_libraries(rexbacklight PRIVATE $<TARGET_OBJECTS:common_srcs>)
|
||||||
target_include_directories(rexbacklight PUBLIC "${RJP_HEADER_DIR}")
|
|
||||||
install(TARGETS rexbacklight RUNTIME DESTINATION bin)
|
install(TARGETS rexbacklight RUNTIME DESTINATION bin)
|
||||||
if(INSTALL_UDEV_BACKLIGHT_RULE)
|
if(INSTALL_UDEV_BACKLIGHT_RULE)
|
||||||
install(FILES ${CMAKE_SOURCE_DIR}/rules/91-backlight.rules DESTINATION ${UDEV_DIR})
|
install(FILES ${CMAKE_SOURCE_DIR}/rules/91-backlight.rules DESTINATION ${UDEV_DIR})
|
||||||
|
|||||||
@ -16,8 +16,6 @@
|
|||||||
along with this program, If not, see <http://www.gnu.org/licenses/>.
|
along with this program, If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#ifndef REXBACKLIGHT_COMMON_H
|
#ifndef REXBACKLIGHT_COMMON_H
|
||||||
#define REXBACKLIGHT_COMMON_H
|
#define REXBACKLIGHT_COMMON_H
|
||||||
|
|
||||||
|
|||||||
@ -22,5 +22,7 @@
|
|||||||
#define REXBACKLIGHT_VERSION_MAJOR @rexbacklight_VERSION_MAJOR@
|
#define REXBACKLIGHT_VERSION_MAJOR @rexbacklight_VERSION_MAJOR@
|
||||||
#define REXBACKLIGHT_VERSION_MINOR @rexbacklight_VERSION_MINOR@
|
#define REXBACKLIGHT_VERSION_MINOR @rexbacklight_VERSION_MINOR@
|
||||||
|
|
||||||
|
@enable_RESTORE_FILE@
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
13
src/cmd.c
13
src/cmd.c
@ -16,12 +16,13 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h> //fprintf
|
||||||
#include <stdlib.h>
|
#include <string.h> //strcmp
|
||||||
#include <string.h>
|
#include <stdlib.h> //malloc, free, strtol, atof
|
||||||
|
|
||||||
#include "cmd.h"
|
#include "cmd.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#define NO_OPT NULL
|
#define NO_OPT NULL
|
||||||
#define GET_LONG_OPT "--get"
|
#define GET_LONG_OPT "--get"
|
||||||
@ -94,7 +95,9 @@ struct cmd_arg rexbacklight_args[] = {
|
|||||||
{STEPS_LONG_OPT, STEPS_SHORT_OPT, STEPS_XBACK_OPT, STEPS_DESC},
|
{STEPS_LONG_OPT, STEPS_SHORT_OPT, STEPS_XBACK_OPT, STEPS_DESC},
|
||||||
{GET_LONG_OPT, GET_SHORT_OPT, GET_XBACK_OPT, GET_DESC},
|
{GET_LONG_OPT, GET_SHORT_OPT, GET_XBACK_OPT, GET_DESC},
|
||||||
{LIST_LONG_OPT, LIST_SHORT_OPT, LIST_XBACK_OPT, LIST_DESC},
|
{LIST_LONG_OPT, LIST_SHORT_OPT, LIST_XBACK_OPT, LIST_DESC},
|
||||||
|
#ifdef ENABLE_RESTORE_FILE
|
||||||
{RESTORE_LONG_OPT, RESTORE_SHORT_OPT, RESTORE_XBACK_OPT, RESTORE_DESC},
|
{RESTORE_LONG_OPT, RESTORE_SHORT_OPT, RESTORE_XBACK_OPT, RESTORE_DESC},
|
||||||
|
#endif
|
||||||
{HELP_LONG_OPT, HELP_SHORT_OPT, HELP_XBACK_OPT, HELP_DESC},
|
{HELP_LONG_OPT, HELP_SHORT_OPT, HELP_XBACK_OPT, HELP_DESC},
|
||||||
{VERSION_LONG_OPT, NO_OPT, VERSION_XBACK_OPT, VERSION_DESC}
|
{VERSION_LONG_OPT, NO_OPT, VERSION_XBACK_OPT, VERSION_DESC}
|
||||||
};
|
};
|
||||||
@ -108,7 +111,9 @@ struct cmd_arg rexbacklight_args[] = {
|
|||||||
{STEPS_LONG_OPT, STEPS_SHORT_OPT, STEPS_DESC},
|
{STEPS_LONG_OPT, STEPS_SHORT_OPT, STEPS_DESC},
|
||||||
{GET_LONG_OPT, GET_SHORT_OPT, GET_DESC},
|
{GET_LONG_OPT, GET_SHORT_OPT, GET_DESC},
|
||||||
{LIST_LONG_OPT, LIST_SHORT_OPT, LIST_DESC},
|
{LIST_LONG_OPT, LIST_SHORT_OPT, LIST_DESC},
|
||||||
|
#ifdef ENABLE_RESTORE_FILE
|
||||||
{RESTORE_LONG_OPT, RESTORE_SHORT_OPT, RESTORE_DESC},
|
{RESTORE_LONG_OPT, RESTORE_SHORT_OPT, RESTORE_DESC},
|
||||||
|
#endif
|
||||||
{HELP_LONG_OPT, HELP_SHORT_OPT, HELP_DESC},
|
{HELP_LONG_OPT, HELP_SHORT_OPT, HELP_DESC},
|
||||||
{VERSION_LONG_OPT, NO_OPT, VERSION_DESC}
|
{VERSION_LONG_OPT, NO_OPT, VERSION_DESC}
|
||||||
};
|
};
|
||||||
@ -202,9 +207,11 @@ struct arg_values process_cmd_args(int argc, char** argv){
|
|||||||
ret.next = NULL;
|
ret.next = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#ifdef ENABLE_RESTORE_FILE
|
||||||
else if(CHECK_OPTION(RESTORE, argv[i])){
|
else if(CHECK_OPTION(RESTORE, argv[i])){
|
||||||
ret.operation = OP_RESTORE;
|
ret.operation = OP_RESTORE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
else if(!strcmp(argv[i], "max")){
|
else if(!strcmp(argv[i], "max")){
|
||||||
curr->operation = OP_SET;
|
curr->operation = OP_SET;
|
||||||
curr->delta = 100;
|
curr->delta = 100;
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
#include <stdio.h> //printf
|
#include <stdio.h> //printf
|
||||||
|
#include <stdlib.h> //exit
|
||||||
|
|
||||||
int return_value = RETVAL_SUCCESS;
|
int return_value = RETVAL_SUCCESS;
|
||||||
|
|
||||||
|
|||||||
@ -16,12 +16,13 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h> //printf
|
||||||
#include <string.h> //strcmp
|
#include <string.h> //strcmp, strlen
|
||||||
#include <rjp.h>
|
#include <rjp.h>
|
||||||
#include <sys/types.h> //struct passwd
|
#include <sys/types.h> //getpwnam
|
||||||
#include <pwd.h> //getpwnam
|
#include <pwd.h> //getpwnam
|
||||||
#include <unistd.h> //chdir
|
#include <unistd.h> //chdir
|
||||||
|
#include <stdlib.h> //malloc, free
|
||||||
|
|
||||||
#include "restore.h"
|
#include "restore.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|||||||
@ -16,22 +16,24 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//Needed for usleep to work
|
#include <stdio.h> //fprintf
|
||||||
#define _DEFAULT_SOURCE
|
#include <stdlib.h> //malloc, free
|
||||||
|
#include <string.h> //strlen, strcpy
|
||||||
#include <stdio.h>
|
#include <unistd.h> //chdir
|
||||||
#include <stdlib.h>
|
#include <sys/types.h> //opendir
|
||||||
#include <string.h>
|
#include <dirent.h> //opendir
|
||||||
#include <unistd.h>
|
#include <sys/time.h> //gettimeofday
|
||||||
#include <dirent.h>
|
#include <time.h> //nanosleep
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <rjp.h>
|
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "cmd.h"
|
#include "cmd.h"
|
||||||
#include "restore.h"
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#ifdef ENABLE_RESTORE_FILE
|
||||||
|
#include <rjp.h>
|
||||||
|
#include "restore.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
//name of the program being run so that we print the correct name in the usage
|
//name of the program being run so that we print the correct name in the usage
|
||||||
|
|
||||||
@ -240,6 +242,7 @@ int individual_device_op(struct arg_values* curr){
|
|||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_RESTORE_FILE
|
||||||
//If devices were specified, this function will run
|
//If devices were specified, this function will run
|
||||||
void individual_device_loop(struct arg_values* a){
|
void individual_device_loop(struct arg_values* a){
|
||||||
struct arg_values* curr;
|
struct arg_values* curr;
|
||||||
@ -258,6 +261,18 @@ void individual_device_loop(struct arg_values* a){
|
|||||||
}
|
}
|
||||||
rjp_free_value(root);
|
rjp_free_value(root);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
//If devices were specified, this function will run
|
||||||
|
void individual_device_loop(struct arg_values* a){
|
||||||
|
struct arg_values* curr;
|
||||||
|
int try_restore = 1;
|
||||||
|
for(curr = a->next;curr;curr = curr->next){
|
||||||
|
return_value = individual_device_op(curr);
|
||||||
|
if(return_value == RETVAL_INTERNAL_ERROR)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//If no devices were specified, this function will run
|
//If no devices were specified, this function will run
|
||||||
@ -280,7 +295,9 @@ void all_device_loop(struct string_array* device_names, struct arg_values* args)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef ENABLE_RESTORE_FILE
|
||||||
save_restore_file(device_names);
|
save_restore_file(device_names);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case OP_LIST:
|
case OP_LIST:
|
||||||
do_list(device_names);
|
do_list(device_names);
|
||||||
@ -300,9 +317,11 @@ void all_device_loop(struct string_array* device_names, struct arg_values* args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#ifdef ENABLE_RESTORE_FILE
|
||||||
case OP_RESTORE:;
|
case OP_RESTORE:;
|
||||||
all_restore();
|
all_restore();
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Internal processing error!\n");
|
fprintf(stderr, "Internal processing error!\n");
|
||||||
break;
|
break;
|
||||||
@ -365,7 +384,9 @@ int main(int argc, char** argv){
|
|||||||
//Run selected operation
|
//Run selected operation
|
||||||
if(args.next){
|
if(args.next){
|
||||||
individual_device_loop(&args);
|
individual_device_loop(&args);
|
||||||
|
#ifdef ENABLE_RESTORE_FILE
|
||||||
save_restore_file(&device_names);
|
save_restore_file(&device_names);
|
||||||
|
#endif
|
||||||
}else{
|
}else{
|
||||||
all_device_loop(&device_names, &args);
|
all_device_loop(&device_names, &args);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user