Ver código fonte

Specify exponential base in the args and modify README

Alexander Lutsai 4 anos atrás
pai
commit
79c2dea7e6
3 arquivos alterados com 39 adições e 6 exclusões
  1. 4
    0
      README.md
  2. 34
    6
      src/light.c
  3. 1
    0
      src/light.h

+ 4
- 0
README.md Ver arquivo

@@ -58,6 +58,10 @@ Decrease backlight brightness by 5 percent in exponential mode (natural way)
58 58
 
59 59
     light -e -U 5
60 60
 
61
+Increase backlight brightness by 2 percent in exponential mode and specify exponential base K, it must be more then 1.0 and less then 20.0
62
+
63
+    light -e2.8 -U 2
64
+
61 65
 Set the minimum cap to 2 in raw value on the sysfs/backlight/acpi_video0 device:
62 66
 
63 67
     light -Nrs "sysfs/backlight/acpi_video0" 2

+ 34
- 6
src/light.c Ver arquivo

@@ -159,7 +159,7 @@ static bool _light_raw_to_percent(light_context_t *ctx, uint64_t inraw, double *
159 159
         double max_value_d = (double)max_value;
160 160
         double percent = 0;
161 161
         if(ctx->run_params.mode == LC_MODE_EXPONENTIAL)
162
-            percent = pow((inraw_d / max_value_d), 1.0 / LIGHT_EXPONENT) * 100.0;
162
+            percent = pow((inraw_d / max_value_d), 1.0 / ctx->run_params.exponent) * 100.0;
163 163
         else
164 164
             percent = (inraw_d / max_value_d) * 100.0;
165 165
         
@@ -181,7 +181,7 @@ static bool _light_percent_to_raw(light_context_t *ctx, double inpercent, uint64
181 181
     double max_value_d = (double)max_value;
182 182
     double target_value_d = 0;
183 183
     if(ctx->run_params.mode == LC_MODE_EXPONENTIAL)
184
-        target_value_d = max_value_d * pow(light_percent_clamp(inpercent) / 100.0, LIGHT_EXPONENT);
184
+        target_value_d = max_value_d * pow(light_percent_clamp(inpercent) / 100.0, ctx->run_params.exponent);
185 185
     else
186 186
         target_value_d = max_value_d * (light_percent_clamp(inpercent) / 100.0);
187 187
     uint64_t target_value = LIGHT_CLAMP((uint64_t)target_value_d, 0, max_value);
@@ -214,7 +214,9 @@ static void _light_print_usage()
214 214
         "\n"
215 215
         "Options:\n"
216 216
         "  -r          Interpret input and output values in raw mode (ignored for -T)\n"
217
-        "  -e          Interpret input and output values in exponential mode (ignored for -r and -T)\n"
217
+        "  -e[K]       Interpret input and output values in exponential mode (ignored for -r)\n"
218
+        "                 Optional K value specifies base of the exponential mode. Default is 4.0\n"
219
+        "                 K must be more then 1.0 and less then 20.0 \n"
218 220
         "  -s          Specify device target path to use, use -L to list available\n"
219 221
         "  -v          Specify the verbosity level (default 0)\n"
220 222
         "                 0: Values only\n"
@@ -253,7 +255,7 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
253 255
     bool specified_target = false;
254 256
     snprintf(ctrl_name, sizeof(ctrl_name), "%s", "sysfs/backlight/auto");
255 257
 
256
-    while((curr_arg = getopt(argc, argv, "HhVGSLMNPAUTOIv:s:re")) != -1)
258
+    while((curr_arg = getopt(argc, argv, "HhVGSLMNPAUTOIv:s:re?")) != -1)
257 259
     {
258 260
         switch(curr_arg)
259 261
         {
@@ -284,7 +286,27 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
284 286
                 ctx->run_params.mode = LC_MODE_RAW;
285 287
                 break;
286 288
             case 'e':
287
-                ctx->run_params.mode = LC_MODE_EXPONENTIAL;
289
+                if(ctx->run_params.mode != LC_MODE_RAW)
290
+                    ctx->run_params.mode = LC_MODE_EXPONENTIAL;
291
+                if(optarg)
292
+                {
293
+                    if(sscanf(optarg, "%lf", &ctx->run_params.exponent) != 1)
294
+                    {
295
+                        fprintf(stderr, "-e argument is not an double.\n\n");
296
+                        _light_print_usage();
297
+                        return false;
298
+                    }
299
+                    else if(ctx->run_params.exponent <= 1 || ctx->run_params.exponent > 20)
300
+                    {
301
+                        fprintf(stderr, "-e argument must be more then 1 and less then 20.\n\n");
302
+                        _light_print_usage();
303
+                        return false;
304
+                    }
305
+                }
306
+                else
307
+                {
308
+                    ctx->run_params.exponent = LIGHT_EXPONENT;
309
+                }
288 310
                 break;
289 311
             
290 312
             // Commands
@@ -332,7 +354,8 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
332 354
                 break;
333 355
             case 'T':
334 356
                 _light_set_context_command(ctx, light_cmd_mul_brightness);
335
-                ctx->run_params.mode = LC_MODE_PERCENTAGE;
357
+                if(ctx->run_params.mode != LC_MODE_RAW)
358
+                    ctx->run_params.mode = LC_MODE_PERCENTAGE;
336 359
                 need_target = true;
337 360
                 need_float_value = true;
338 361
                 break;
@@ -967,6 +990,11 @@ bool light_cmd_sub_brightness(light_context_t *ctx)
967 990
         break;
968 991
     case LC_MODE_PERCENTAGE:
969 992
     case LC_MODE_EXPONENTIAL:
993
+        if(value < 5 && value > 0)
994
+        { // on small values adequate behaviour
995
+            value --;
996
+            break;
997
+        }   
970 998
         if(!_light_raw_to_percent(ctx, value, &percent))
971 999
         {
972 1000
             LIGHT_ERR("failed to convert value from raw to percent for device target");

+ 1
- 0
src/light.h Ver arquivo

@@ -85,6 +85,7 @@ struct _light_context_t
85 85
         // Only one of value and raw_value is populated; which one depends on the command
86 86
         uint64_t                value; // The input value, in raw mode
87 87
         float                   float_value; // The input value as a float
88
+        double                  exponent; // Exponent value for the exponential mode
88 89
         light_context_mode      mode; // Whether or not we use raw, exponential or percentage mode
89 90
         light_device_target_t   *device_target; // The device target to act on
90 91
     } run_params;