소스 검색

Overhaul and simplify program usage and documentation in README

- Use version from configure script
- Simplify usage text for accessibility, only one command at a time
- Simplify terminology, we have commands and options to commands

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
Joachim Nilsson 6 년 전
부모
커밋
99950f7c51
3개의 변경된 파일89개의 추가작업 그리고 119개의 파일을 삭제
  1. 42
    66
      README.md
  2. 36
    39
      src/light.c
  3. 11
    14
      src/light.h

+ 42
- 66
README.md 파일 보기

@@ -27,8 +27,8 @@ Introduction
27 27
 * Possibility to set a minimum brightness value
28 28
 
29 29
 Let's get started with a few examples, for details, see below for the
30
-full description of the different operating modes, value conversion and
31
-how to operate different controllers.
30
+full description of the different commands, options and how to access
31
+different controllers.
32 32
 
33 33
 
34 34
 Examples
@@ -77,85 +77,61 @@ Verify by reading back the max brightness, you should get a value of 1:
77 77
 Usage
78 78
 -----
79 79
 
80
-Light has 5 different criteria on flags to use: operation modes, value
81
-mode, target, field and controller mode.  Flags from these different
82
-modes can never be used in conjunction, i.e. you cannot get and set a
83
-value at the same time, that requires different invocations.
80
+### Commands
84 81
 
85
-**Note:** like most UNIX applications, light only print errors if you
86
-  are using it incorrectly. If something goes wrong, and you can't
87
-  figure out why, try setting the verbosity flag with -v:
82
+* `-G`: Get (read) brightness/data from controllers/files
83
+* `-S VAL`: Set (write)brightness/data to controllers/files
84
+* `-A VAL`: Like `-S`, but adds the given value
85
+* `-U VAL`: Like `-S`, but subtracts the given value
86
+* `-O`: Save the current brightness for later use (usually used on shutdown)
87
+* `-I`: Restore the previously saved brightness (usually used on boot)
88
+* `-L`: List available controllers, see below `-k` option as well
89
+
90
+Without any options (below) the commands operate on the brightness of an
91
+automatically selected controller.  Values are given in percent, unless
92
+the below `r` option is also given.
93
+
94
+**Note:** like most UNIX applications, light only gives output on
95
+  errors.  If something goes wrong try the verbosity option `-v VAL`:
88 96
 
89 97
 * 0: No debug output
90 98
 * 1: Errors
91 99
 * 2: Errors, warnings
92 100
 * 3: Errors, warnings, notices
93 101
 
102
+### Options
94 103
 
95
-### Operation modes
96
-
97
-The operation modes describe **what** you want to do.
98
-
99
-* -G: Which **reads/gets** brightness/data from controllers/files
100
-* -S: Which **writes/sets** brightness/data to controllers/files
101
-* -A: Which does like -S but instead **adds** the value
102
-* -U: Which does like -S but instead '**subtracts** the value
103
-* -O: Save the current brightness for later use (usually used on shutdown)
104
-* -I: Restore the previously saved brightness (usually used on boot)
105
-* -L: List the available controllers
106
-
107
-When used by themselves operate on the brightness of a controller that
108
-is selected automatically. S, A and U needs another argument -- except
109
-for the main 4 criteria -- which is the value to set/add/subtract.  This
110
-can be specified either in percent or in raw values, but remember to
111
-specify the value mode (read below) if you want to write raw values.
112
-
113
-
114
-### Value modes
115
-
116
-The value mode specify in what unit you want to read or write values
117
-in. The default one (if not specified) is in percent, the other one is
118
-raw mode and should always be used when you need very precise values (or
119
-only have a controller with a very small amount of brightness levels).
120
-
121
-* -p: Percent
122
-* -r: Raw mode
123
-
124
-Remember, this is the unit that will be used when you set, get, add or
125
-subtract brightness values.
126
-
127
-
128
-### Target
129
-
130
-You can choose which target to act on:
131
-
132
-* -l: Act on screen backlight
133
-* -k: Act on keyboard backlight and LEDs
134
-
104
+Values may be given, or presented, in percent or raw mode.  Raw mode is
105
+the format specific to the controller.  The default is in percent, but
106
+raw mode may be required for precise control, or when the steps are very
107
+few, e.g. for most keyboard backlight controllers.
135 108
 
136
-### Field
109
+* `-p`: Percent, default
110
+* `-r`: Raw mode
137 111
 
138
-As you can not only handle the **brightness** of controllers, you may
139
-also specify a field to read/write from/to:
112
+By default the screen is the active target for all commands, use `-k` to
113
+select the keyboard instead.  In either case you may need to select a
114
+different controller, see below.
140 115
 
141
-* -b: Current brightness of selected controller
142
-* -m: Maximum brightness of selected controller
143
-* -c: Minimum brightness (cap) of selected controller
116
+* `-l`: Act on screen backlight, default
117
+* `-k`: Act on keyboard backlight and LEDs
144 118
 
145
-The minimum brightness is a feature implemented as some controllers make
146
-the screen go pitch black at 0%, if you have a controller like that, it
147
-is recommended to set this value (in percent or raw mode).  These values
148
-are saved in raw mode though, so if you specify it in percent it might
149
-not be too accurate depending on your controller.
119
+By default commands act on the brightness property, which is read+write.
120
+The maximum brightness is a read-only property.  The minimum brightness
121
+cap is a feature implemented to protect against setting brightness too
122
+low, since some controllers make the screen go pitch black at 0%.  For
123
+controllers like that it is recommended to set this value.
150 124
 
125
+* `-b`: Current brightness of selected controller, default
126
+* `-m`: Max. brightness of selected controller
127
+* `-c`: Min. brightness (cap) of selected controller (recommend raw mode)
151 128
 
152
-### Controller modes
129
+Controller is automatically done to select the controller with maximum
130
+precision.  It can however also be done manually and we recommend the
131
+`-L` and `-Lk` commands to list available controllers:
153 132
 
154
-Finally, you can either use the built-in controller selection to get the
155
-controller with the maximum precision, or you can specify one manually
156
-with the -s flag. The -a flag will force automatic mode and is
157
-default. Use -L to get a list of controllers to use with the -s flag (to
158
-specify which controller to use).
133
+* `-a`: Automatic controller selection
134
+* `-s ARG`: Manual controller selection
159 135
 
160 136
 **Note:** Without the `-s` flag on _every_ command light will default
161 137
   to automatic controller selection.

+ 36
- 39
src/light.c 파일 보기

@@ -239,48 +239,45 @@ LIGHT_BOOL light_parseArguments(int argc, char** argv)
239 239
 }
240 240
 
241 241
 void light_printVersion(){
242
-  printf("Light %u.%u (%s)\n", LIGHT_VER_MAJOR, LIGHT_VER_MINOR, LIGHT_VER_TYPE);
243
-  printf("Copyright (C) %u %s\n", LIGHT_YEAR, LIGHT_AUTHOR);
244
-  printf("This is free software, see the source for copying conditions.  There is NO\n");
245
-  printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\n\n");
242
+  printf("v%s\n", VERSION);
246 243
 }
247 244
 
248 245
 void light_printHelp(){
249
-  printf("Usage: light <options> <value>\n");
250
-  printf("<value> has to be either integral(raw mode) or decimal(percent mode) depending on the specified value mode.\n");
251
-  printf("<options> can be any of the following:\n\n");
252
-
253
-  printf("Operations (can not be used in conjunction):\n");
254
-  printf("  -H -h:\tPrints this help and exits\n");
255
-  printf("  -V:\t\tPrints version info and exits\n");
256
-  printf("  -G:\t\tGet value (default)\n");
257
-  printf("  -S:\t\tSet value\n");
258
-  printf("  -A:\t\tAdd value\n");
259
-  printf("  -U:\t\tSubtract value\n");
260
-  printf("  -L:\t\tList controllers\n");
261
-  printf("  -I:\t\tRestore brightness\n");
262
-  printf("  -O:\t\tSave brightness\n\n");
263
-
264
-  printf("Targets (can not be used in conjunction):\n");
265
-  printf("  -l:\t\tAct on screen backlight (default)\n");
266
-  printf("  -k:\t\tAct on keyboard backlight\n\n");
267
-
268
-  printf("Fields (can not be used in conjunction):\n");
269
-  printf("  -b:\t\tBrightness (default)\n  \t\tUsed with [GSAU]\n\n");
270
-  printf("  -m:\t\tMaximum brightness\n  \t\tUsed with [G]\n\n");
271
-  printf("  -c:\t\tMinimum cap\n  \t\tUsed with [GS]\n");
272
-  printf("  \t\tG returns null if no minimum cap is set.\n\n");
273
-
274
-  printf("Controller selection (can not be used in conjunction):\n");
275
-  printf("  -a:\t\tSelects controller automatically (default).\n");
276
-  printf("  -s:\t\tSpecify controller to use. (needs argument)\n\n");
277
-
278
-  printf("Value modes (can not be used in conjunction):\n");
279
-  printf("  -p:\t\tInterpret <value> as, and output values in, percent. (default)\n");
280
-  printf("  -r:\t\tInterpret <value> as, and output values in, raw mode.\n\n");
281
-
282
-  printf("Other:\n");
283
-  printf("  -v:\t\tSets the verbosity level, (needs argument).\n  \t\t0: Only outputs read values.\n  \t\t1: Read values, Errors.\n  \t\t2: Read values, Errors, Warnings.\n  \t\t3: Read values, Errors, Warnings, Notices.\n\n");
246
+	printf("Usage:\n"
247
+	       "  light [OPTIONS] <COMMAND> [VALUE]\n"
248
+	       "\n"
249
+	       "Commands:\n"
250
+	       "  -A VAL  Add value\n"
251
+	       "  -G      Get (read) value, default command\n"
252
+	       "  -H, -h  Show this help and exit\n"
253
+	       "  -I      Restore brightness\n"
254
+	       "  -L      List available controllers\n"
255
+	       "  -O      Save brightness\n"
256
+	       "  -S VAL  Set (write) value\n"
257
+	       "  -U VAL  Subtract value\n"
258
+	       "  -V      Show program version and exit\n"
259
+	       "\n"
260
+	       "Options:\n"
261
+	       "  -a      Automatic controller selection, default\n"
262
+	       "  -b      Brightness, default\n"
263
+	       "  -c      Act on minimum cap, only possible to read and set\n"
264
+	       "  -k      Act on keyboard backlight\n"
265
+	       "  -l      Act on screen backlight, default\n"
266
+	       "  -m      Maximum brightness, only possible to read\n"
267
+	       "  -p      Interpret input, and output, values in percent, default\n"
268
+	       "  -r      Interpret input, and outpot, values in raw mode\n"
269
+	       "  -s ARG  Specify controller to use, use -L and -Lk to list available\n"
270
+	       "  -v ARG  Verbosity level:\n"
271
+	       "            0: Values only, default\n"
272
+	       "            1: Values, Errors.\n"
273
+	       "            2: Values, Errors, Warnings.\n"
274
+	       "            3: Values, Errors, Warnings, Notices.\n"
275
+	       "\n");
276
+
277
+	printf("Copyright (C) %s  %s\n", LIGHT_YEAR, LIGHT_AUTHOR);
278
+	printf("This is free software, see the source for copying conditions.  There is NO\n"
279
+	       "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\n"
280
+	       "\n");
284 281
 }
285 282
 
286 283
 LIGHT_BOOL light_initialize(int argc, char** argv)

+ 11
- 14
src/light.h 파일 보기

@@ -1,25 +1,22 @@
1
-#ifndef LIGHT_H
2
-#define LIGHT_H
1
+#ifndef LIGHT_H_
2
+#define LIGHT_H_
3 3
 
4
+#include "config.h"
4 5
 #include "helpers.h"
5 6
 
6 7
 #include <sys/types.h>
7 8
 #include <dirent.h>
8 9
 #include <linux/limits.h>
9 10
 
10
-#define LIGHT_VER_MAJOR 0
11
-#define LIGHT_VER_MINOR 10
12
-#define LIGHT_VER_TYPE "beta"
13
-#define LIGHT_YEAR 2014
11
+#define LIGHT_YEAR   "2012-2018"
14 12
 #define LIGHT_AUTHOR "Fredrik Haikarainen"
15 13
 
16
-#define ASSERT_SET(t,v) \
17
-  if(v)\
18
-  {\
19
-    fprintf(stderr, t" arguments can not be used in conjunction.\n");\
20
-    return FALSE;\
21
-  }\
22
-  v = TRUE;
14
+#define ASSERT_SET(t,v)							\
15
+	if (v) {							\
16
+		fprintf(stderr, t" arguments cannot be used in conjunction.\n"); \
17
+		return FALSE;						\
18
+	}								\
19
+	v = TRUE;
23 20
 
24 21
 #define ASSERT_OPSET() ASSERT_SET("Operation", opSet)
25 22
 #define ASSERT_TARGETSET() ASSERT_SET("Target", targetSet)
@@ -138,4 +135,4 @@ LIGHT_BOOL light_saveBrightness(char const *controller, unsigned long v);
138 135
 
139 136
 LIGHT_BOOL light_restoreBrightness(char const *controller);
140 137
 
141
-#endif /* LIGHT_H */
138
+#endif /* LIGHT_H_ */