|
|
@@ -4,6 +4,7 @@
|
|
4
|
4
|
#include "config.h"
|
|
5
|
5
|
#include "helpers.h"
|
|
6
|
6
|
|
|
|
7
|
+#include <stdbool.h>
|
|
7
|
8
|
#include <sys/types.h>
|
|
8
|
9
|
#include <dirent.h>
|
|
9
|
10
|
#include <linux/limits.h>
|
|
|
@@ -11,128 +12,91 @@
|
|
11
|
12
|
#define LIGHT_YEAR "2012-2018"
|
|
12
|
13
|
#define LIGHT_AUTHOR "Fredrik Haikarainen"
|
|
13
|
14
|
|
|
14
|
|
-#define ASSERT_SET(t,v) \
|
|
|
15
|
+#define ASSERT_SET(t, v) \
|
|
15
|
16
|
if (v) { \
|
|
16
|
|
- fprintf(stderr, t" arguments cannot be used in conjunction.\n"); \
|
|
17
|
|
- return FALSE; \
|
|
|
17
|
+ fprintf(stderr, t " cannot be used more than once.\n"); \
|
|
|
18
|
+ return false; \
|
|
18
|
19
|
} \
|
|
19
|
|
- v = TRUE;
|
|
20
|
|
-
|
|
21
|
|
-#define ASSERT_OPSET() ASSERT_SET("Operation", opSet)
|
|
22
|
|
-#define ASSERT_TARGETSET() ASSERT_SET("Target", targetSet)
|
|
23
|
|
-#define ASSERT_FIELDSET() ASSERT_SET("Field", fieldSet)
|
|
24
|
|
-#define ASSERT_CTRLSET() ASSERT_SET("Controller", ctrlSet)
|
|
25
|
|
-#define ASSERT_VALSET() ASSERT_SET("Value", valSet)
|
|
26
|
|
-
|
|
27
|
|
-typedef enum LIGHT_FIELD {
|
|
28
|
|
- LIGHT_BRIGHTNESS = 0,
|
|
29
|
|
- LIGHT_MAX_BRIGHTNESS,
|
|
30
|
|
- LIGHT_MIN_CAP,
|
|
31
|
|
- LIGHT_SAVERESTORE
|
|
32
|
|
-} LIGHT_FIELD;
|
|
33
|
|
-
|
|
34
|
|
-typedef enum LIGHT_TARGET {
|
|
35
|
|
- LIGHT_BACKLIGHT = 0,
|
|
36
|
|
- LIGHT_KEYBOARD
|
|
37
|
|
-} LIGHT_TARGET;
|
|
38
|
|
-
|
|
39
|
|
-typedef enum LIGHT_CTRL_MODE {
|
|
40
|
|
- LIGHT_AUTO = 0,
|
|
41
|
|
- LIGHT_SPECIFY
|
|
42
|
|
-} LIGHT_CTRL_MODE;
|
|
43
|
|
-
|
|
44
|
|
-typedef enum LIGHT_OP_MODE {
|
|
45
|
|
- LIGHT_GET = 0,
|
|
46
|
|
- LIGHT_SET,
|
|
47
|
|
- LIGHT_ADD,
|
|
48
|
|
- LIGHT_SUB,
|
|
49
|
|
- LIGHT_PRINT_HELP, /* Prints help and exits */
|
|
50
|
|
- LIGHT_PRINT_VERSION, /* Prints version info and exits */
|
|
51
|
|
- LIGHT_LIST_CTRL,
|
|
52
|
|
- LIGHT_RESTORE,
|
|
53
|
|
- LIGHT_SAVE
|
|
54
|
|
-
|
|
55
|
|
-} LIGHT_OP_MODE;
|
|
56
|
|
-
|
|
57
|
|
-typedef enum LIGHT_VAL_MODE {
|
|
58
|
|
- LIGHT_RAW = 0,
|
|
59
|
|
- LIGHT_PERCENT
|
|
60
|
|
-} LIGHT_VAL_MODE;
|
|
61
|
|
-
|
|
62
|
|
-typedef struct light_runtimeArguments_s {
|
|
63
|
|
- /* Which controller to use */
|
|
64
|
|
- LIGHT_CTRL_MODE controllerMode;
|
|
65
|
|
- char specifiedController[NAME_MAX + 1];
|
|
66
|
|
-
|
|
67
|
|
- /* What to do with the controller */
|
|
68
|
|
- LIGHT_OP_MODE operationMode;
|
|
69
|
|
- LIGHT_VAL_MODE valueMode;
|
|
70
|
|
- unsigned long specifiedValueRaw; /* The specified value in raw mode */
|
|
71
|
|
- double specifiedValuePercent; /* The specified value in percent */
|
|
72
|
|
-
|
|
73
|
|
- LIGHT_TARGET target;
|
|
74
|
|
- LIGHT_FIELD field;
|
|
75
|
|
-
|
|
76
|
|
- /* Cache data */
|
|
77
|
|
- LIGHT_BOOL hasCachedMaxBrightness;
|
|
78
|
|
- unsigned long cachedMaxBrightness;
|
|
79
|
|
-
|
|
80
|
|
-} light_runtimeArguments, *light_runtimeArguments_p;
|
|
|
20
|
+ v = true;
|
|
|
21
|
+
|
|
|
22
|
+#define ASSERT_CMDSET() ASSERT_SET("Commands", cmd_set)
|
|
|
23
|
+#define ASSERT_TARGETSET() ASSERT_SET("Targets", target_set)
|
|
|
24
|
+#define ASSERT_FIELDSET() ASSERT_SET("Fields", field_set)
|
|
|
25
|
+#define ASSERT_CTRLSET() ASSERT_SET("Controllers", ctrl_set)
|
|
|
26
|
+#define ASSERT_VALSET() ASSERT_SET("Values", val_set)
|
|
|
27
|
+
|
|
|
28
|
+typedef enum {
|
|
|
29
|
+ LIGHT_BRIGHTNESS = 0,
|
|
|
30
|
+ LIGHT_MAX_BRIGHTNESS,
|
|
|
31
|
+ LIGHT_MIN_CAP,
|
|
|
32
|
+ LIGHT_SAVERESTORE
|
|
|
33
|
+} light_field_t;
|
|
|
34
|
+
|
|
|
35
|
+typedef enum {
|
|
|
36
|
+ LIGHT_BACKLIGHT = 0,
|
|
|
37
|
+ LIGHT_KEYBOARD
|
|
|
38
|
+} light_target_t;
|
|
|
39
|
+
|
|
|
40
|
+typedef enum {
|
|
|
41
|
+ LIGHT_AUTO = 0,
|
|
|
42
|
+ LIGHT_SPECIFY
|
|
|
43
|
+} light_ctrl_mode_t;
|
|
|
44
|
+
|
|
|
45
|
+typedef enum {
|
|
|
46
|
+ LIGHT_GET = 0,
|
|
|
47
|
+ LIGHT_SET,
|
|
|
48
|
+ LIGHT_ADD,
|
|
|
49
|
+ LIGHT_SUB,
|
|
|
50
|
+ LIGHT_PRINT_HELP, /* Prints help and exits */
|
|
|
51
|
+ LIGHT_PRINT_VERSION, /* Prints version info and exits */
|
|
|
52
|
+ LIGHT_LIST_CTRL,
|
|
|
53
|
+ LIGHT_RESTORE,
|
|
|
54
|
+ LIGHT_SAVE
|
|
|
55
|
+} light_cmd_t;
|
|
|
56
|
+
|
|
|
57
|
+typedef enum {
|
|
|
58
|
+ LIGHT_RAW = 0,
|
|
|
59
|
+ LIGHT_PERCENT
|
|
|
60
|
+} light_val_mode_t;
|
|
|
61
|
+
|
|
|
62
|
+typedef struct {
|
|
|
63
|
+ /* Which controller to use */
|
|
|
64
|
+ light_ctrl_mode_t ctrl;
|
|
|
65
|
+ char ctrl_name[NAME_MAX + 1];
|
|
|
66
|
+
|
|
|
67
|
+ /* What to do with the controller */
|
|
|
68
|
+ light_cmd_t cmd;
|
|
|
69
|
+ light_val_mode_t val_mode;
|
|
|
70
|
+ unsigned long val_raw; /* The specified value in raw mode */
|
|
|
71
|
+ double val_percent; /* The specified value in percent */
|
|
|
72
|
+
|
|
|
73
|
+ light_target_t target;
|
|
|
74
|
+ light_field_t field;
|
|
|
75
|
+
|
|
|
76
|
+ /* Cache data */
|
|
|
77
|
+ bool has_cached_brightness_max;
|
|
|
78
|
+ unsigned long cached_brightness_max;
|
|
|
79
|
+} light_ctx_t;
|
|
81
|
80
|
|
|
82
|
81
|
/* -- Global variable holding the settings for the current run -- */
|
|
83
|
|
-light_runtimeArguments light_Configuration;
|
|
|
82
|
+light_ctx_t ctx;
|
|
84
|
83
|
|
|
85
|
|
-/* Sets default values for the configuration */
|
|
86
|
|
-void light_defaultConfig();
|
|
|
84
|
+bool light_initialize (int argc, char **argv);
|
|
|
85
|
+bool light_execute (void);
|
|
|
86
|
+void light_free (void);
|
|
87
|
87
|
|
|
|
88
|
+bool light_ctrl_list (void);
|
|
|
89
|
+bool light_ctrl_probe (char *controller);
|
|
|
90
|
+bool light_ctrl_exist (char const *controller);
|
|
88
|
91
|
|
|
89
|
|
-/* Parses the program arguments and sets the configuration accordingly (unsanitized) */
|
|
90
|
|
-LIGHT_BOOL light_parseArguments(int argc, char** argv);
|
|
|
92
|
+bool light_ctrl_get_brightness (char const *controller, unsigned long *v);
|
|
|
93
|
+bool light_ctrl_set_brightness (char const *controller, unsigned long v);
|
|
|
94
|
+bool light_ctrl_get_brightness_max (char const *controller, unsigned long *v);
|
|
91
|
95
|
|
|
92
|
|
-/* Prints a header if verbosity level > 0 */
|
|
93
|
|
-void light_printVersion(void);
|
|
|
96
|
+bool light_ctrl_get_cap_min (char const *controller, bool *hasMinCap, unsigned long *minCap);
|
|
|
97
|
+bool light_ctrl_set_cap_min (char const *controller, unsigned long val);
|
|
94
|
98
|
|
|
95
|
|
-/* Prints help regardless of verbosity level */
|
|
96
|
|
-void light_printHelp(void);
|
|
97
|
|
-
|
|
98
|
|
-/* -- SECTION: Main code -- */
|
|
99
|
|
-
|
|
100
|
|
-/* Initializes the application */
|
|
101
|
|
-LIGHT_BOOL light_initialize(int argc, char** argv);
|
|
102
|
|
-
|
|
103
|
|
-/* Does the work */
|
|
104
|
|
-LIGHT_BOOL light_execute(void);
|
|
105
|
|
-
|
|
106
|
|
-/* Frees up resources */
|
|
107
|
|
-void light_free();
|
|
108
|
|
-
|
|
109
|
|
-/* SECTION: Controller functionality */
|
|
110
|
|
-
|
|
111
|
|
-/* WARNING: `buffer` HAS to be freed by the user if not null once returned!
|
|
112
|
|
- * Size is always NAME_MAX + 1 */
|
|
113
|
|
-LIGHT_BOOL light_genPath(char const *controller, LIGHT_TARGET target, LIGHT_FIELD type, char **buffer);
|
|
114
|
|
-
|
|
115
|
|
-LIGHT_BOOL light_validControllerName(char const *controller);
|
|
116
|
|
-
|
|
117
|
|
-LIGHT_BOOL light_getBrightness(char const *controller, unsigned long *v);
|
|
118
|
|
-
|
|
119
|
|
-LIGHT_BOOL light_getMaxBrightness(char const *controller, unsigned long *v);
|
|
120
|
|
-
|
|
121
|
|
-LIGHT_BOOL light_setBrightness(char const *controller, unsigned long v);
|
|
122
|
|
-
|
|
123
|
|
-LIGHT_BOOL light_controllerAccessible(char const *controller);
|
|
124
|
|
-
|
|
125
|
|
-/* WARNING: `controller` HAS to be at most NAME_MAX, otherwise fails */
|
|
126
|
|
-LIGHT_BOOL light_getBestController(char *controller);
|
|
127
|
|
-
|
|
128
|
|
-LIGHT_BOOL light_getMinCap(char const *controller, LIGHT_BOOL *hasMinCap, unsigned long *minCap);
|
|
129
|
|
-
|
|
130
|
|
-LIGHT_BOOL light_setMinCap(char const *controller, unsigned long v);
|
|
131
|
|
-
|
|
132
|
|
-LIGHT_BOOL light_listControllers();
|
|
133
|
|
-
|
|
134
|
|
-LIGHT_BOOL light_saveBrightness(char const *controller, unsigned long v);
|
|
135
|
|
-
|
|
136
|
|
-LIGHT_BOOL light_restoreBrightness(char const *controller);
|
|
|
99
|
+bool light_ctrl_save_brightness (char const *controller, unsigned long val);
|
|
|
100
|
+bool light_ctrl_restore_brightness (char const *controller);
|
|
137
|
101
|
|
|
138
|
102
|
#endif /* LIGHT_H_ */
|