|
@@ -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");
|