Browse Source

Specify exponential base in the args and modify README

Alexander Lutsai 4 years ago
parent
commit
79c2dea7e6
3 changed files with 39 additions and 6 deletions
  1. 4
    0
      README.md
  2. 34
    6
      src/light.c
  3. 1
    0
      src/light.h

+ 4
- 0
README.md View File

58
 
58
 
59
     light -e -U 5
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
 Set the minimum cap to 2 in raw value on the sysfs/backlight/acpi_video0 device:
65
 Set the minimum cap to 2 in raw value on the sysfs/backlight/acpi_video0 device:
62
 
66
 
63
     light -Nrs "sysfs/backlight/acpi_video0" 2
67
     light -Nrs "sysfs/backlight/acpi_video0" 2

+ 34
- 6
src/light.c View File

159
         double max_value_d = (double)max_value;
159
         double max_value_d = (double)max_value;
160
         double percent = 0;
160
         double percent = 0;
161
         if(ctx->run_params.mode == LC_MODE_EXPONENTIAL)
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
         else
163
         else
164
             percent = (inraw_d / max_value_d) * 100.0;
164
             percent = (inraw_d / max_value_d) * 100.0;
165
         
165
         
181
     double max_value_d = (double)max_value;
181
     double max_value_d = (double)max_value;
182
     double target_value_d = 0;
182
     double target_value_d = 0;
183
     if(ctx->run_params.mode == LC_MODE_EXPONENTIAL)
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
     else
185
     else
186
         target_value_d = max_value_d * (light_percent_clamp(inpercent) / 100.0);
186
         target_value_d = max_value_d * (light_percent_clamp(inpercent) / 100.0);
187
     uint64_t target_value = LIGHT_CLAMP((uint64_t)target_value_d, 0, max_value);
187
     uint64_t target_value = LIGHT_CLAMP((uint64_t)target_value_d, 0, max_value);
214
         "\n"
214
         "\n"
215
         "Options:\n"
215
         "Options:\n"
216
         "  -r          Interpret input and output values in raw mode (ignored for -T)\n"
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
         "  -s          Specify device target path to use, use -L to list available\n"
220
         "  -s          Specify device target path to use, use -L to list available\n"
219
         "  -v          Specify the verbosity level (default 0)\n"
221
         "  -v          Specify the verbosity level (default 0)\n"
220
         "                 0: Values only\n"
222
         "                 0: Values only\n"
253
     bool specified_target = false;
255
     bool specified_target = false;
254
     snprintf(ctrl_name, sizeof(ctrl_name), "%s", "sysfs/backlight/auto");
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
         switch(curr_arg)
260
         switch(curr_arg)
259
         {
261
         {
284
                 ctx->run_params.mode = LC_MODE_RAW;
286
                 ctx->run_params.mode = LC_MODE_RAW;
285
                 break;
287
                 break;
286
             case 'e':
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
                 break;
310
                 break;
289
             
311
             
290
             // Commands
312
             // Commands
332
                 break;
354
                 break;
333
             case 'T':
355
             case 'T':
334
                 _light_set_context_command(ctx, light_cmd_mul_brightness);
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
                 need_target = true;
359
                 need_target = true;
337
                 need_float_value = true;
360
                 need_float_value = true;
338
                 break;
361
                 break;
967
         break;
990
         break;
968
     case LC_MODE_PERCENTAGE:
991
     case LC_MODE_PERCENTAGE:
969
     case LC_MODE_EXPONENTIAL:
992
     case LC_MODE_EXPONENTIAL:
993
+        if(value < 5 && value > 0)
994
+        { // on small values adequate behaviour
995
+            value --;
996
+            break;
997
+        }   
970
         if(!_light_raw_to_percent(ctx, value, &percent))
998
         if(!_light_raw_to_percent(ctx, value, &percent))
971
         {
999
         {
972
             LIGHT_ERR("failed to convert value from raw to percent for device target");
1000
             LIGHT_ERR("failed to convert value from raw to percent for device target");

+ 1
- 0
src/light.h View File

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