|
@@ -5,53 +5,38 @@
|
5
|
5
|
|
6
|
6
|
#include <sys/types.h>
|
7
|
7
|
#include <dirent.h>
|
|
8
|
+#include <linux/limits.h>
|
8
|
9
|
|
9
|
10
|
#define LIGHT_VER_MAJOR 0
|
10
|
|
-#define LIGHT_VER_MINOR 9
|
|
11
|
+#define LIGHT_VER_MINOR 10
|
11
|
12
|
#define LIGHT_VER_TYPE "beta"
|
12
|
13
|
#define LIGHT_YEAR 2014
|
13
|
14
|
#define LIGHT_AUTHOR "Fredrik Haikarainen"
|
14
|
15
|
|
15
|
|
-#define ASSERT_OPSET() \
|
16
|
|
- if(opSet)\
|
|
16
|
+#define ASSERT_SET(t,v) \
|
|
17
|
+ if(v)\
|
17
|
18
|
{\
|
18
|
|
- printf("Operation arguments can not be used in conjunction.\n");\
|
|
19
|
+ fprintf(stderr, t" arguments can not be used in conjunction.\n");\
|
19
|
20
|
return FALSE;\
|
20
|
21
|
}\
|
21
|
|
- opSet = TRUE;
|
22
|
|
-
|
23
|
|
-#define ASSERT_TARGETSET() \
|
24
|
|
- if(targetSet)\
|
25
|
|
- {\
|
26
|
|
- printf("Target arguments can not be used in conjunction.\n");\
|
27
|
|
- return FALSE;\
|
28
|
|
- }\
|
29
|
|
- targetSet = TRUE;
|
30
|
|
-
|
31
|
|
-#define ASSERT_CTRLSET()\
|
32
|
|
- if(ctrlSet)\
|
33
|
|
- {\
|
34
|
|
- printf("Controller arguments can not be used in conjunction.\n");\
|
35
|
|
- return FALSE;\
|
36
|
|
- }\
|
37
|
|
- ctrlSet = TRUE;
|
38
|
|
-
|
39
|
|
-#define ASSERT_VALSET()\
|
40
|
|
- if(valSet)\
|
41
|
|
- {\
|
42
|
|
- printf("Value arguments can not be used in conjunction.\n");\
|
43
|
|
- return FALSE;\
|
44
|
|
- }\
|
45
|
|
- valSet = TRUE;
|
|
22
|
+ v = TRUE;
|
46
|
23
|
|
|
24
|
+#define ASSERT_OPSET() ASSERT_SET("Operation", opSet)
|
|
25
|
+#define ASSERT_TARGETSET() ASSERT_SET("Target", targetSet)
|
|
26
|
+#define ASSERT_FIELDSET() ASSERT_SET("Field", fieldSet)
|
|
27
|
+#define ASSERT_CTRLSET() ASSERT_SET("Controller", ctrlSet)
|
|
28
|
+#define ASSERT_VALSET() ASSERT_SET("Value", valSet)
|
47
|
29
|
|
48
|
|
-typedef enum LIGHT_TARGET {
|
|
30
|
+typedef enum LIGHT_FIELD {
|
49
|
31
|
LIGHT_BRIGHTNESS = 0,
|
50
|
32
|
LIGHT_MAX_BRIGHTNESS,
|
51
|
33
|
LIGHT_MIN_CAP,
|
52
|
|
- LIGHT_SAVERESTORE,
|
53
|
|
- LIGHT_KEYBOARD,
|
54
|
|
- LIGHT_KEYBOARD_MAX_BRIGHTNESS
|
|
34
|
+ LIGHT_SAVERESTORE
|
|
35
|
+} LIGHT_FIELD;
|
|
36
|
+
|
|
37
|
+typedef enum LIGHT_TARGET {
|
|
38
|
+ LIGHT_BACKLIGHT = 0,
|
|
39
|
+ LIGHT_KEYBOARD
|
55
|
40
|
} LIGHT_TARGET;
|
56
|
41
|
|
57
|
42
|
typedef enum LIGHT_CTRL_MODE {
|
|
@@ -80,7 +65,7 @@ typedef enum LIGHT_VAL_MODE {
|
80
|
65
|
typedef struct light_runtimeArguments_s {
|
81
|
66
|
/* Which controller to use */
|
82
|
67
|
LIGHT_CTRL_MODE controllerMode;
|
83
|
|
- char specifiedController[256];
|
|
68
|
+ char specifiedController[NAME_MAX + 1];
|
84
|
69
|
|
85
|
70
|
/* What to do with the controller */
|
86
|
71
|
LIGHT_OP_MODE operationMode;
|
|
@@ -88,13 +73,14 @@ typedef struct light_runtimeArguments_s {
|
88
|
73
|
unsigned long specifiedValueRaw; /* The specified value in raw mode */
|
89
|
74
|
double specifiedValuePercent; /* The specified value in percent */
|
90
|
75
|
|
91
|
|
- LIGHT_TARGET target;
|
92
|
|
-} light_runtimeArguments, *light_runtimeArguments_p;
|
|
76
|
+ LIGHT_TARGET target;
|
|
77
|
+ LIGHT_FIELD field;
|
|
78
|
+
|
|
79
|
+ /* Cache data */
|
|
80
|
+ LIGHT_BOOL hasCachedMaxBrightness;
|
|
81
|
+ unsigned long cachedMaxBrightness;
|
93
|
82
|
|
94
|
|
-/* -- Global variables that handles iterating controllers -- */
|
95
|
|
-struct dirent *light_iterator;
|
96
|
|
-DIR *light_iteratorDir;
|
97
|
|
-char light_currentController[256];
|
|
83
|
+} light_runtimeArguments, *light_runtimeArguments_p;
|
98
|
84
|
|
99
|
85
|
/* -- Global variable holding the settings for the current run -- */
|
100
|
86
|
light_runtimeArguments light_Configuration;
|
|
@@ -126,8 +112,10 @@ void light_free();
|
126
|
112
|
/* SECTION: Controller functionality */
|
127
|
113
|
|
128
|
114
|
/* WARNING: `buffer` HAS to be freed by the user if not null once returned!
|
129
|
|
- * Size is always 256 */
|
130
|
|
-LIGHT_BOOL light_genPath(char const *controller, LIGHT_TARGET type, char **buffer);
|
|
115
|
+ * Size is always NAME_MAX + 1 */
|
|
116
|
+LIGHT_BOOL light_genPath(char const *controller, LIGHT_TARGET target, LIGHT_FIELD type, char **buffer);
|
|
117
|
+
|
|
118
|
+LIGHT_BOOL light_validControllerName(char const *controller);
|
131
|
119
|
|
132
|
120
|
LIGHT_BOOL light_getBrightness(char const *controller, unsigned long *v);
|
133
|
121
|
|
|
@@ -137,9 +125,7 @@ LIGHT_BOOL light_setBrightness(char const *controller, unsigned long v);
|
137
|
125
|
|
138
|
126
|
LIGHT_BOOL light_controllerAccessible(char const *controller);
|
139
|
127
|
|
140
|
|
-LIGHT_BOOL light_iterateControllers(void);
|
141
|
|
-
|
142
|
|
-/* WARNING: `controller` HAS to be at least 256 bytes */
|
|
128
|
+/* WARNING: `controller` HAS to be at most NAME_MAX, otherwise fails */
|
143
|
129
|
LIGHT_BOOL light_getBestController(char *controller);
|
144
|
130
|
|
145
|
131
|
LIGHT_BOOL light_getMinCap(char const *controller, LIGHT_BOOL *hasMinCap, unsigned long *minCap);
|