|
@@ -20,25 +20,25 @@
|
20
|
20
|
|
21
|
21
|
static void _light_add_enumerator_device(light_device_enumerator_t *enumerator, light_device_t *new_device)
|
22
|
22
|
{
|
23
|
|
- // Create a new device array
|
|
23
|
+ // Create a new device array
|
24
|
24
|
uint64_t new_num_devices = enumerator->num_devices + 1;
|
25
|
25
|
light_device_t **new_devices = malloc(new_num_devices * sizeof(light_device_t*));
|
26
|
|
-
|
|
26
|
+
|
27
|
27
|
// Copy old device array to new one
|
28
|
28
|
for(uint64_t i = 0; i < enumerator->num_devices; i++)
|
29
|
29
|
{
|
30
|
30
|
new_devices[i] = enumerator->devices[i];
|
31
|
31
|
}
|
32
|
|
-
|
|
32
|
+
|
33
|
33
|
// Set the new device
|
34
|
34
|
new_devices[enumerator->num_devices] = new_device;
|
35
|
|
-
|
|
35
|
+
|
36
|
36
|
// Free the old devices array, if needed
|
37
|
37
|
if(enumerator->devices != NULL)
|
38
|
38
|
{
|
39
|
39
|
free(enumerator->devices);
|
40
|
40
|
}
|
41
|
|
-
|
|
41
|
+
|
42
|
42
|
// Replace the devices array with the new one
|
43
|
43
|
enumerator->devices = new_devices;
|
44
|
44
|
enumerator->num_devices = new_num_devices;
|
|
@@ -46,25 +46,25 @@ static void _light_add_enumerator_device(light_device_enumerator_t *enumerator,
|
46
|
46
|
|
47
|
47
|
static void _light_add_device_target(light_device_t *device, light_device_target_t *new_target)
|
48
|
48
|
{
|
49
|
|
- // Create a new targets array
|
|
49
|
+ // Create a new targets array
|
50
|
50
|
uint64_t new_num_targets = device->num_targets + 1;
|
51
|
51
|
light_device_target_t **new_targets = malloc(new_num_targets * sizeof(light_device_target_t*));
|
52
|
|
-
|
|
52
|
+
|
53
|
53
|
// Copy old targets array to new one
|
54
|
54
|
for(uint64_t i = 0; i < device->num_targets; i++)
|
55
|
55
|
{
|
56
|
56
|
new_targets[i] = device->targets[i];
|
57
|
57
|
}
|
58
|
|
-
|
|
58
|
+
|
59
|
59
|
// Set the new target
|
60
|
60
|
new_targets[device->num_targets] = new_target;
|
61
|
|
-
|
|
61
|
+
|
62
|
62
|
// Free the old targets array, if needed
|
63
|
63
|
if(device->targets != NULL)
|
64
|
64
|
{
|
65
|
65
|
free(device->targets);
|
66
|
66
|
}
|
67
|
|
-
|
|
67
|
+
|
68
|
68
|
// Replace the targets array with the new one
|
69
|
69
|
device->targets= new_targets;
|
70
|
70
|
device->num_targets = new_num_targets;
|
|
@@ -103,7 +103,7 @@ static uint64_t _light_get_min_cap(light_context_t *ctx)
|
103
|
103
|
{
|
104
|
104
|
return 0;
|
105
|
105
|
}
|
106
|
|
-
|
|
106
|
+
|
107
|
107
|
return minimum_value;
|
108
|
108
|
}
|
109
|
109
|
|
|
@@ -116,7 +116,7 @@ static light_device_enumerator_t* _light_find_enumerator(light_context_t *ctx, c
|
116
|
116
|
return ctx->enumerators[e];
|
117
|
117
|
}
|
118
|
118
|
}
|
119
|
|
-
|
|
119
|
+
|
120
|
120
|
return NULL;
|
121
|
121
|
}
|
122
|
122
|
|
|
@@ -129,7 +129,7 @@ static light_device_t* _light_find_device(light_device_enumerator_t *en, char co
|
129
|
129
|
return en->devices[d];
|
130
|
130
|
}
|
131
|
131
|
}
|
132
|
|
-
|
|
132
|
+
|
133
|
133
|
return NULL;
|
134
|
134
|
}
|
135
|
135
|
|
|
@@ -142,7 +142,7 @@ static light_device_target_t* _light_find_target(light_device_t * dev, char cons
|
142
|
142
|
return dev->targets[t];
|
143
|
143
|
}
|
144
|
144
|
}
|
145
|
|
-
|
|
145
|
+
|
146
|
146
|
return NULL;
|
147
|
147
|
}
|
148
|
148
|
|
|
@@ -158,7 +158,7 @@ static bool _light_raw_to_percent(light_device_target_t *target, uint64_t inraw,
|
158
|
158
|
double max_value_d = (double)max_value;
|
159
|
159
|
double percent = light_percent_clamp((inraw_d / max_value_d) * 100.0);
|
160
|
160
|
*outpercent = percent;
|
161
|
|
-
|
|
161
|
+
|
162
|
162
|
return true;
|
163
|
163
|
}
|
164
|
164
|
|
|
@@ -175,7 +175,7 @@ static bool _light_percent_to_raw(light_device_target_t *target, double inpercen
|
175
|
175
|
double target_value_d = max_value_d * (light_percent_clamp(inpercent) / 100.0);
|
176
|
176
|
uint64_t target_value = LIGHT_CLAMP((uint64_t)target_value_d, 0, max_value);
|
177
|
177
|
*outraw = target_value;
|
178
|
|
-
|
|
178
|
+
|
179
|
179
|
return true;
|
180
|
180
|
}
|
181
|
181
|
|
|
@@ -188,9 +188,9 @@ static void _light_print_usage()
|
188
|
188
|
" -H, -h Show this help and exit\n"
|
189
|
189
|
" -V Show program version and exit\n"
|
190
|
190
|
" -L List available devices\n"
|
191
|
|
-
|
|
191
|
+
|
192
|
192
|
" -A Increase brightness by value\n"
|
193
|
|
- " -U Decrease brightness by value\n"
|
|
193
|
+ " -U Decrease brightness by value\n"
|
194
|
194
|
" -T Multiply brightness by value (can be a non-whole number, ignores raw mode)\n"
|
195
|
195
|
" -S Set brightness to value\n"
|
196
|
196
|
" -G Get brightness\n"
|
|
@@ -224,7 +224,7 @@ static bool _light_set_context_command(light_context_t *ctx, LFUNCCOMMAND new_cm
|
224
|
224
|
LIGHT_WARN("a command was already set. ignoring.");
|
225
|
225
|
return false;
|
226
|
226
|
}
|
227
|
|
-
|
|
227
|
+
|
228
|
228
|
ctx->run_params.command = new_cmd;
|
229
|
229
|
return true;
|
230
|
230
|
}
|
|
@@ -233,20 +233,20 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
|
233
|
233
|
{
|
234
|
234
|
int32_t curr_arg = -1;
|
235
|
235
|
int32_t log_level = 0;
|
236
|
|
-
|
|
236
|
+
|
237
|
237
|
char ctrl_name[NAME_MAX];
|
238
|
238
|
bool need_value = false;
|
239
|
239
|
bool need_float_value = false;
|
240
|
240
|
bool need_target = true; // default cmd is get brightness
|
241
|
241
|
bool specified_target = false;
|
242
|
242
|
snprintf(ctrl_name, sizeof(ctrl_name), "%s", "sysfs/backlight/auto");
|
243
|
|
-
|
|
243
|
+
|
244
|
244
|
while((curr_arg = getopt(argc, argv, "HhVGSLMNPAUTOIv:s:r")) != -1)
|
245
|
245
|
{
|
246
|
246
|
switch(curr_arg)
|
247
|
247
|
{
|
248
|
248
|
// Options
|
249
|
|
-
|
|
249
|
+
|
250
|
250
|
case 'v':
|
251
|
251
|
if (sscanf(optarg, "%i", &log_level) != 1)
|
252
|
252
|
{
|
|
@@ -254,14 +254,14 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
|
254
|
254
|
_light_print_usage();
|
255
|
255
|
return false;
|
256
|
256
|
}
|
257
|
|
-
|
|
257
|
+
|
258
|
258
|
if (log_level < 0 || log_level > 3)
|
259
|
259
|
{
|
260
|
260
|
fprintf(stderr, "-v argument must be between 0 and 3.\n\n");
|
261
|
261
|
_light_print_usage();
|
262
|
262
|
return false;
|
263
|
263
|
}
|
264
|
|
-
|
|
264
|
+
|
265
|
265
|
light_loglevel = (light_loglevel_t)log_level;
|
266
|
266
|
break;
|
267
|
267
|
case 's':
|
|
@@ -271,7 +271,7 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
|
271
|
271
|
case 'r':
|
272
|
272
|
ctx->run_params.raw_mode = true;
|
273
|
273
|
break;
|
274
|
|
-
|
|
274
|
+
|
275
|
275
|
// Commands
|
276
|
276
|
case 'H':
|
277
|
277
|
case 'h':
|
|
@@ -335,7 +335,7 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
|
335
|
335
|
{
|
336
|
336
|
_light_set_context_command(ctx, light_cmd_get_brightness);
|
337
|
337
|
}
|
338
|
|
-
|
|
338
|
+
|
339
|
339
|
if(need_target)
|
340
|
340
|
{
|
341
|
341
|
light_device_target_t *curr_target = light_find_device_target(ctx, ctrl_name);
|
|
@@ -346,13 +346,13 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
|
346
|
346
|
fprintf(stderr, "We couldn't find the specified device target at the path \"%s\". Use -L to find one.\n\n", ctrl_name);
|
347
|
347
|
return false;
|
348
|
348
|
}
|
349
|
|
- else
|
|
349
|
+ else
|
350
|
350
|
{
|
351
|
351
|
fprintf(stderr, "No backlight controller was found, so we could not decide an automatic target. The current command will have no effect. Please use -L to find a target and then specify it with -s.\n\n");
|
352
|
352
|
curr_target = light_find_device_target(ctx, "util/test/dryrun");
|
353
|
353
|
}
|
354
|
354
|
}
|
355
|
|
-
|
|
355
|
+
|
356
|
356
|
ctx->run_params.device_target = curr_target;
|
357
|
357
|
}
|
358
|
358
|
|
|
@@ -386,16 +386,16 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
|
386
|
386
|
_light_print_usage();
|
387
|
387
|
return false;
|
388
|
388
|
}
|
389
|
|
-
|
|
389
|
+
|
390
|
390
|
percent_value = light_percent_clamp(percent_value);
|
391
|
|
-
|
|
391
|
+
|
392
|
392
|
uint64_t raw_value = 0;
|
393
|
393
|
if(!_light_percent_to_raw(ctx->run_params.device_target, percent_value, &raw_value))
|
394
|
394
|
{
|
395
|
395
|
LIGHT_ERR("failed to convert from percent to raw for device target");
|
396
|
396
|
return false;
|
397
|
397
|
}
|
398
|
|
-
|
|
398
|
+
|
399
|
399
|
ctx->run_params.value = raw_value;
|
400
|
400
|
}
|
401
|
401
|
}
|
|
@@ -411,7 +411,7 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
|
411
|
411
|
}
|
412
|
412
|
|
413
|
413
|
return true;
|
414
|
|
-
|
|
414
|
+
|
415
|
415
|
}
|
416
|
416
|
|
417
|
417
|
|
|
@@ -440,7 +440,7 @@ light_context_t* light_initialize(int argc, char **argv)
|
440
|
440
|
else
|
441
|
441
|
{
|
442
|
442
|
char *xdg_conf = getenv("XDG_CONFIG_HOME");
|
443
|
|
-
|
|
443
|
+
|
444
|
444
|
if (xdg_conf != NULL)
|
445
|
445
|
{
|
446
|
446
|
snprintf(new_ctx->sys_params.conf_dir, sizeof(new_ctx->sys_params.conf_dir), "%s/light", xdg_conf);
|
|
@@ -450,7 +450,7 @@ light_context_t* light_initialize(int argc, char **argv)
|
450
|
450
|
snprintf(new_ctx->sys_params.conf_dir, sizeof(new_ctx->sys_params.conf_dir), "%s/.config/light", getenv("HOME"));
|
451
|
451
|
}
|
452
|
452
|
}
|
453
|
|
-
|
|
453
|
+
|
454
|
454
|
// Make sure the configuration folder exists, otherwise attempt to create it
|
455
|
455
|
int32_t rc = light_mkpath(new_ctx->sys_params.conf_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
456
|
456
|
if (rc && errno != EEXIST)
|
|
@@ -458,7 +458,7 @@ light_context_t* light_initialize(int argc, char **argv)
|
458
|
458
|
LIGHT_WARN("couldn't create configuration directory");
|
459
|
459
|
return false;
|
460
|
460
|
}
|
461
|
|
-
|
|
461
|
+
|
462
|
462
|
// Create the built-in enumerators
|
463
|
463
|
light_create_enumerator(new_ctx, "sysfs", &impl_sysfs_init, &impl_sysfs_free);
|
464
|
464
|
light_create_enumerator(new_ctx, "util", &impl_util_init, &impl_util_free);
|
|
@@ -480,7 +480,7 @@ light_context_t* light_initialize(int argc, char **argv)
|
480
|
480
|
LIGHT_ERR("failed to parse arguments");
|
481
|
481
|
return NULL;
|
482
|
482
|
}
|
483
|
|
-
|
|
483
|
+
|
484
|
484
|
return new_ctx;
|
485
|
485
|
}
|
486
|
486
|
|
|
@@ -491,7 +491,7 @@ bool light_execute(light_context_t *ctx)
|
491
|
491
|
LIGHT_ERR("run parameters command was null, can't execute");
|
492
|
492
|
return false;
|
493
|
493
|
}
|
494
|
|
-
|
|
494
|
+
|
495
|
495
|
return ctx->run_params.command(ctx);
|
496
|
496
|
}
|
497
|
497
|
|
|
@@ -501,42 +501,42 @@ void light_free(light_context_t *ctx)
|
501
|
501
|
{
|
502
|
502
|
LIGHT_WARN("failed to free all enumerators");
|
503
|
503
|
}
|
504
|
|
-
|
|
504
|
+
|
505
|
505
|
free(ctx);
|
506
|
506
|
}
|
507
|
507
|
|
508
|
508
|
light_device_enumerator_t * light_create_enumerator(light_context_t *ctx, char const * name, LFUNCENUMINIT init_func, LFUNCENUMFREE free_func)
|
509
|
509
|
{
|
510
|
|
- // Create a new enumerator array
|
|
510
|
+ // Create a new enumerator array
|
511
|
511
|
uint64_t new_num_enumerators = ctx->num_enumerators + 1;
|
512
|
512
|
light_device_enumerator_t **new_enumerators = malloc(new_num_enumerators * sizeof(light_device_enumerator_t*));
|
513
|
|
-
|
|
513
|
+
|
514
|
514
|
// Copy old enumerator array to new one
|
515
|
515
|
for(uint64_t i = 0; i < ctx->num_enumerators; i++)
|
516
|
516
|
{
|
517
|
517
|
new_enumerators[i] = ctx->enumerators[i];
|
518
|
518
|
}
|
519
|
|
-
|
|
519
|
+
|
520
|
520
|
// Allocate the new enumerator
|
521
|
521
|
new_enumerators[ctx->num_enumerators] = malloc(sizeof(light_device_enumerator_t));
|
522
|
522
|
light_device_enumerator_t *returner = new_enumerators[ctx->num_enumerators];
|
523
|
|
-
|
|
523
|
+
|
524
|
524
|
returner->devices = NULL;
|
525
|
525
|
returner->num_devices = 0;
|
526
|
526
|
returner->init = init_func;
|
527
|
527
|
returner->free = free_func;
|
528
|
528
|
snprintf(returner->name, sizeof(returner->name), "%s", name);
|
529
|
|
-
|
|
529
|
+
|
530
|
530
|
// Free the old enumerator array, if needed
|
531
|
531
|
if(ctx->enumerators != NULL)
|
532
|
532
|
{
|
533
|
533
|
free(ctx->enumerators);
|
534
|
534
|
}
|
535
|
|
-
|
|
535
|
+
|
536
|
536
|
// Replace the enumerator array with the new one
|
537
|
537
|
ctx->enumerators = new_enumerators;
|
538
|
538
|
ctx->num_enumerators = new_num_enumerators;
|
539
|
|
-
|
|
539
|
+
|
540
|
540
|
// Return newly created device
|
541
|
541
|
return returner;
|
542
|
542
|
}
|
|
@@ -552,7 +552,7 @@ bool light_init_enumerators(light_context_t *ctx)
|
552
|
552
|
success = false;
|
553
|
553
|
}
|
554
|
554
|
}
|
555
|
|
-
|
|
555
|
+
|
556
|
556
|
return success;
|
557
|
557
|
}
|
558
|
558
|
|
|
@@ -562,30 +562,30 @@ bool light_free_enumerators(light_context_t *ctx)
|
562
|
562
|
for(uint64_t i = 0; i < ctx->num_enumerators; i++)
|
563
|
563
|
{
|
564
|
564
|
light_device_enumerator_t * curr_enumerator = ctx->enumerators[i];
|
565
|
|
-
|
|
565
|
+
|
566
|
566
|
if(!curr_enumerator->free(curr_enumerator))
|
567
|
567
|
{
|
568
|
568
|
success = false;
|
569
|
569
|
}
|
570
|
|
-
|
|
570
|
+
|
571
|
571
|
if(curr_enumerator->devices != NULL)
|
572
|
572
|
{
|
573
|
573
|
for(uint64_t d = 0; d < curr_enumerator->num_devices; d++)
|
574
|
574
|
{
|
575
|
575
|
light_delete_device(curr_enumerator->devices[d]);
|
576
|
576
|
}
|
577
|
|
-
|
|
577
|
+
|
578
|
578
|
free(curr_enumerator->devices);
|
579
|
579
|
curr_enumerator->devices = NULL;
|
580
|
580
|
}
|
581
|
|
-
|
|
581
|
+
|
582
|
582
|
free(curr_enumerator);
|
583
|
583
|
}
|
584
|
|
-
|
|
584
|
+
|
585
|
585
|
free(ctx->enumerators);
|
586
|
586
|
ctx->enumerators = NULL;
|
587
|
587
|
ctx->num_enumerators = 0;
|
588
|
|
-
|
|
588
|
+
|
589
|
589
|
return success;
|
590
|
590
|
}
|
591
|
591
|
|
|
@@ -598,11 +598,11 @@ bool light_split_target_path(char const *in_path, light_target_path_t *out_path)
|
598
|
598
|
LIGHT_WARN("invalid path passed to split_target_path");
|
599
|
599
|
return false;
|
600
|
600
|
}
|
601
|
|
-
|
|
601
|
+
|
602
|
602
|
size_t size = end - begin;
|
603
|
603
|
strncpy(out_path->enumerator, begin, size);
|
604
|
604
|
out_path->enumerator[size] = '\0';
|
605
|
|
-
|
|
605
|
+
|
606
|
606
|
begin = end + 1;
|
607
|
607
|
end = strstr(begin, "/");
|
608
|
608
|
if(end == NULL)
|
|
@@ -610,13 +610,13 @@ bool light_split_target_path(char const *in_path, light_target_path_t *out_path)
|
610
|
610
|
LIGHT_WARN("invalid path passed to split_target_path");
|
611
|
611
|
return false;
|
612
|
612
|
}
|
613
|
|
-
|
|
613
|
+
|
614
|
614
|
size = end - begin;
|
615
|
615
|
strncpy(out_path->device, begin, size);
|
616
|
616
|
out_path->device[size] = '\0';
|
617
|
|
-
|
|
617
|
+
|
618
|
618
|
strcpy(out_path->target, end + 1);
|
619
|
|
-
|
|
619
|
+
|
620
|
620
|
return true;
|
621
|
621
|
}
|
622
|
622
|
|
|
@@ -628,7 +628,7 @@ light_device_target_t* light_find_device_target(light_context_t *ctx, char const
|
628
|
628
|
LIGHT_WARN("light_find_device_target needs a path in the format of \"enumerator/device/target\", the following format is not recognized: \"%s\"", name);
|
629
|
629
|
return NULL;
|
630
|
630
|
}
|
631
|
|
-
|
|
631
|
+
|
632
|
632
|
/*
|
633
|
633
|
Uncomment to debug the split function
|
634
|
634
|
printf("enumerator: %s %u\ndevice: %s %u\ntarget: %s %u\n",
|
|
@@ -636,30 +636,30 @@ light_device_target_t* light_find_device_target(light_context_t *ctx, char const
|
636
|
636
|
new_path.device, strlen(new_path.device),
|
637
|
637
|
new_path.target, strlen(new_path.target));
|
638
|
638
|
*/
|
639
|
|
-
|
640
|
|
- // find a matching enumerator
|
641
|
|
-
|
|
639
|
+
|
|
640
|
+ // find a matching enumerator
|
|
641
|
+
|
642
|
642
|
light_device_enumerator_t *enumerator = _light_find_enumerator(ctx, new_path.enumerator);
|
643
|
643
|
if(enumerator == NULL)
|
644
|
644
|
{
|
645
|
645
|
LIGHT_WARN("no such enumerator, \"%s\"", new_path.enumerator);
|
646
|
646
|
return NULL;
|
647
|
647
|
}
|
648
|
|
-
|
|
648
|
+
|
649
|
649
|
light_device_t *device = _light_find_device(enumerator, new_path.device);
|
650
|
650
|
if(device == NULL)
|
651
|
651
|
{
|
652
|
652
|
LIGHT_WARN("no such device, \"%s\"", new_path.device);
|
653
|
653
|
return NULL;
|
654
|
654
|
}
|
655
|
|
-
|
|
655
|
+
|
656
|
656
|
light_device_target_t *target = _light_find_target(device, new_path.target);
|
657
|
657
|
if(target == NULL)
|
658
|
658
|
{
|
659
|
659
|
LIGHT_WARN("no such target, \"%s\"", new_path.target);
|
660
|
660
|
return NULL;
|
661
|
661
|
}
|
662
|
|
-
|
|
662
|
+
|
663
|
663
|
return target;
|
664
|
664
|
}
|
665
|
665
|
|
|
@@ -687,12 +687,12 @@ bool light_cmd_list_devices(light_context_t *ctx)
|
687
|
687
|
for(uint64_t target = 0; target < curr_device->num_targets; target++)
|
688
|
688
|
{
|
689
|
689
|
light_device_target_t *curr_target = curr_device->targets[target];
|
690
|
|
-
|
|
690
|
+
|
691
|
691
|
printf("\t%s/%s/%s\n", curr_enumerator->name, curr_device->name, curr_target->name);
|
692
|
692
|
}
|
693
|
693
|
}
|
694
|
694
|
}
|
695
|
|
-
|
|
695
|
+
|
696
|
696
|
return true;
|
697
|
697
|
}
|
698
|
698
|
|
|
@@ -704,21 +704,21 @@ bool light_cmd_set_brightness(light_context_t *ctx)
|
704
|
704
|
LIGHT_ERR("didn't have a valid target, programmer mistake");
|
705
|
705
|
return false;
|
706
|
706
|
}
|
707
|
|
-
|
708
|
|
-
|
|
707
|
+
|
|
708
|
+
|
709
|
709
|
uint64_t mincap = _light_get_min_cap(ctx);
|
710
|
710
|
uint64_t value = ctx->run_params.value;
|
711
|
711
|
if(mincap > value)
|
712
|
712
|
{
|
713
|
713
|
value = mincap;
|
714
|
714
|
}
|
715
|
|
-
|
|
715
|
+
|
716
|
716
|
if(!target->set_value(target, value))
|
717
|
717
|
{
|
718
|
718
|
LIGHT_ERR("failed to write to target");
|
719
|
719
|
return false;
|
720
|
720
|
}
|
721
|
|
-
|
|
721
|
+
|
722
|
722
|
return true;
|
723
|
723
|
}
|
724
|
724
|
|
|
@@ -730,19 +730,19 @@ bool light_cmd_get_brightness(light_context_t *ctx)
|
730
|
730
|
LIGHT_ERR("didn't have a valid target, programmer mistake");
|
731
|
731
|
return false;
|
732
|
732
|
}
|
733
|
|
-
|
|
733
|
+
|
734
|
734
|
uint64_t value = 0;
|
735
|
735
|
if(!target->get_value(target, &value))
|
736
|
736
|
{
|
737
|
737
|
LIGHT_ERR("failed to read from target");
|
738
|
738
|
return false;
|
739
|
739
|
}
|
740
|
|
-
|
|
740
|
+
|
741
|
741
|
if(ctx->run_params.raw_mode)
|
742
|
742
|
{
|
743
|
743
|
printf("%" PRIu64 "\n", value);
|
744
|
744
|
}
|
745
|
|
- else
|
|
745
|
+ else
|
746
|
746
|
{
|
747
|
747
|
double percent = 0.0;
|
748
|
748
|
if(!_light_raw_to_percent(target, value, &percent))
|
|
@@ -752,7 +752,7 @@ bool light_cmd_get_brightness(light_context_t *ctx)
|
752
|
752
|
}
|
753
|
753
|
printf("%.2f\n", percent);
|
754
|
754
|
}
|
755
|
|
-
|
|
755
|
+
|
756
|
756
|
return true;
|
757
|
757
|
}
|
758
|
758
|
|
|
@@ -764,20 +764,20 @@ bool light_cmd_get_max_brightness(light_context_t *ctx)
|
764
|
764
|
LIGHT_ERR("didn't have a valid target, programmer mistake");
|
765
|
765
|
return false;
|
766
|
766
|
}
|
767
|
|
-
|
|
767
|
+
|
768
|
768
|
if(!ctx->run_params.raw_mode)
|
769
|
769
|
{
|
770
|
770
|
printf("100.0\n");
|
771
|
771
|
return true;
|
772
|
772
|
}
|
773
|
|
-
|
|
773
|
+
|
774
|
774
|
uint64_t max_value = 0;
|
775
|
775
|
if(!target->get_max_value(target, &max_value))
|
776
|
776
|
{
|
777
|
777
|
LIGHT_ERR("failed to read from device target");
|
778
|
778
|
return false;
|
779
|
779
|
}
|
780
|
|
-
|
|
780
|
+
|
781
|
781
|
printf("%" PRIu64 "\n", max_value);
|
782
|
782
|
return true;
|
783
|
783
|
}
|
|
@@ -786,7 +786,7 @@ bool light_cmd_set_min_brightness(light_context_t *ctx)
|
786
|
786
|
{
|
787
|
787
|
char target_path[NAME_MAX];
|
788
|
788
|
_light_get_target_path(ctx, target_path, sizeof(target_path));
|
789
|
|
-
|
|
789
|
+
|
790
|
790
|
// Make sure the target folder exists, otherwise attempt to create it
|
791
|
791
|
int32_t rc = light_mkpath(target_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
792
|
792
|
if (rc && errno != EEXIST)
|
|
@@ -794,16 +794,16 @@ bool light_cmd_set_min_brightness(light_context_t *ctx)
|
794
|
794
|
LIGHT_ERR("couldn't create target directory for minimum brightness");
|
795
|
795
|
return false;
|
796
|
796
|
}
|
797
|
|
-
|
|
797
|
+
|
798
|
798
|
char target_filepath[NAME_MAX];
|
799
|
799
|
_light_get_target_file(ctx, target_filepath, sizeof(target_filepath), "minimum");
|
800
|
|
-
|
|
800
|
+
|
801
|
801
|
if(!light_file_write_uint64(target_filepath, ctx->run_params.value))
|
802
|
802
|
{
|
803
|
803
|
LIGHT_ERR("couldn't write value to minimum file");
|
804
|
804
|
return false;
|
805
|
805
|
}
|
806
|
|
-
|
|
806
|
+
|
807
|
807
|
return true;
|
808
|
808
|
}
|
809
|
809
|
|
|
@@ -819,19 +819,19 @@ bool light_cmd_get_min_brightness(light_context_t *ctx)
|
819
|
819
|
{
|
820
|
820
|
printf("0\n");
|
821
|
821
|
}
|
822
|
|
- else
|
|
822
|
+ else
|
823
|
823
|
{
|
824
|
824
|
printf("0.00\n");
|
825
|
825
|
}
|
826
|
826
|
|
827
|
827
|
return true;
|
828
|
828
|
}
|
829
|
|
-
|
|
829
|
+
|
830
|
830
|
if(ctx->run_params.raw_mode)
|
831
|
831
|
{
|
832
|
832
|
printf("%" PRIu64 "\n", minimum_value);
|
833
|
833
|
}
|
834
|
|
- else
|
|
834
|
+ else
|
835
|
835
|
{
|
836
|
836
|
double minimum_d = 0.0;
|
837
|
837
|
if(!_light_raw_to_percent(ctx->run_params.device_target, minimum_value, &minimum_d))
|
|
@@ -839,10 +839,10 @@ bool light_cmd_get_min_brightness(light_context_t *ctx)
|
839
|
839
|
LIGHT_ERR("failed to convert value from raw to percent for device target");
|
840
|
840
|
return false;
|
841
|
841
|
}
|
842
|
|
-
|
|
842
|
+
|
843
|
843
|
printf("%.2f\n", minimum_d);
|
844
|
844
|
}
|
845
|
|
-
|
|
845
|
+
|
846
|
846
|
return true;
|
847
|
847
|
}
|
848
|
848
|
|
|
@@ -854,41 +854,41 @@ bool light_cmd_add_brightness(light_context_t *ctx)
|
854
|
854
|
LIGHT_ERR("didn't have a valid target, programmer mistake");
|
855
|
855
|
return false;
|
856
|
856
|
}
|
857
|
|
-
|
|
857
|
+
|
858
|
858
|
uint64_t value = 0;
|
859
|
859
|
if(!target->get_value(target, &value))
|
860
|
860
|
{
|
861
|
861
|
LIGHT_ERR("failed to read from target");
|
862
|
862
|
return false;
|
863
|
863
|
}
|
864
|
|
-
|
|
864
|
+
|
865
|
865
|
uint64_t max_value = 0;
|
866
|
866
|
if(!target->get_max_value(target, &max_value))
|
867
|
867
|
{
|
868
|
868
|
LIGHT_ERR("failed to read from target");
|
869
|
869
|
return false;
|
870
|
870
|
}
|
871
|
|
-
|
|
871
|
+
|
872
|
872
|
value += ctx->run_params.value;
|
873
|
|
-
|
|
873
|
+
|
874
|
874
|
uint64_t mincap = _light_get_min_cap(ctx);
|
875
|
875
|
if(mincap > value)
|
876
|
876
|
{
|
877
|
877
|
value = mincap;
|
878
|
878
|
}
|
879
|
|
-
|
880
|
|
-
|
|
879
|
+
|
|
880
|
+
|
881
|
881
|
if(value > max_value)
|
882
|
882
|
{
|
883
|
883
|
value = max_value;
|
884
|
884
|
}
|
885
|
|
-
|
|
885
|
+
|
886
|
886
|
if(!target->set_value(target, value))
|
887
|
887
|
{
|
888
|
888
|
LIGHT_ERR("failed to write to target");
|
889
|
889
|
return false;
|
890
|
890
|
}
|
891
|
|
-
|
|
891
|
+
|
892
|
892
|
return true;
|
893
|
893
|
}
|
894
|
894
|
|
|
@@ -900,23 +900,23 @@ bool light_cmd_sub_brightness(light_context_t *ctx)
|
900
|
900
|
LIGHT_ERR("didn't have a valid target, programmer mistake");
|
901
|
901
|
return false;
|
902
|
902
|
}
|
903
|
|
-
|
|
903
|
+
|
904
|
904
|
uint64_t value = 0;
|
905
|
905
|
if(!target->get_value(target, &value))
|
906
|
906
|
{
|
907
|
907
|
LIGHT_ERR("failed to read from target");
|
908
|
908
|
return false;
|
909
|
909
|
}
|
910
|
|
-
|
|
910
|
+
|
911
|
911
|
if(value > ctx->run_params.value)
|
912
|
912
|
{
|
913
|
913
|
value -= ctx->run_params.value;
|
914
|
914
|
}
|
915
|
|
- else
|
|
915
|
+ else
|
916
|
916
|
{
|
917
|
917
|
value = 0;
|
918
|
918
|
}
|
919
|
|
-
|
|
919
|
+
|
920
|
920
|
uint64_t mincap = _light_get_min_cap(ctx);
|
921
|
921
|
if(mincap > value)
|
922
|
922
|
{
|
|
@@ -928,7 +928,7 @@ bool light_cmd_sub_brightness(light_context_t *ctx)
|
928
|
928
|
LIGHT_ERR("failed to write to target");
|
929
|
929
|
return false;
|
930
|
930
|
}
|
931
|
|
-
|
|
931
|
+
|
932
|
932
|
return true;
|
933
|
933
|
}
|
934
|
934
|
|
|
@@ -957,7 +957,7 @@ bool light_cmd_mul_brightness(light_context_t *ctx)
|
957
|
957
|
|
958
|
958
|
uint64_t old_value = value;
|
959
|
959
|
value *= ctx->run_params.float_value;
|
960
|
|
-
|
|
960
|
+
|
961
|
961
|
// Check that we actually de/increase value
|
962
|
962
|
if(value == old_value)
|
963
|
963
|
{
|
|
@@ -991,7 +991,7 @@ bool light_cmd_save_brightness(light_context_t *ctx)
|
991
|
991
|
{
|
992
|
992
|
char target_path[NAME_MAX];
|
993
|
993
|
_light_get_target_path(ctx, target_path, sizeof(target_path));
|
994
|
|
-
|
|
994
|
+
|
995
|
995
|
// Make sure the target folder exists, otherwise attempt to create it
|
996
|
996
|
int32_t rc = light_mkpath(target_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
|
997
|
997
|
if (rc && errno != EEXIST)
|
|
@@ -999,7 +999,7 @@ bool light_cmd_save_brightness(light_context_t *ctx)
|
999
|
999
|
LIGHT_ERR("couldn't create target directory for save brightness");
|
1000
|
1000
|
return false;
|
1001
|
1001
|
}
|
1002
|
|
-
|
|
1002
|
+
|
1003
|
1003
|
char target_filepath[NAME_MAX];
|
1004
|
1004
|
_light_get_target_file(ctx, target_filepath, sizeof(target_filepath), "save");
|
1005
|
1005
|
|
|
@@ -1009,13 +1009,13 @@ bool light_cmd_save_brightness(light_context_t *ctx)
|
1009
|
1009
|
LIGHT_ERR("couldn't read from device target");
|
1010
|
1010
|
return false;
|
1011
|
1011
|
}
|
1012
|
|
-
|
|
1012
|
+
|
1013
|
1013
|
if(!light_file_write_uint64(target_filepath, curr_value))
|
1014
|
1014
|
{
|
1015
|
1015
|
LIGHT_ERR("couldn't write value to savefile");
|
1016
|
1016
|
return false;
|
1017
|
1017
|
}
|
1018
|
|
-
|
|
1018
|
+
|
1019
|
1019
|
return true;
|
1020
|
1020
|
}
|
1021
|
1021
|
|
|
@@ -1030,19 +1030,19 @@ bool light_cmd_restore_brightness(light_context_t *ctx)
|
1030
|
1030
|
LIGHT_ERR("couldn't read value from savefile");
|
1031
|
1031
|
return false;
|
1032
|
1032
|
}
|
1033
|
|
-
|
|
1033
|
+
|
1034
|
1034
|
uint64_t mincap = _light_get_min_cap(ctx);
|
1035
|
1035
|
if(mincap > saved_value)
|
1036
|
1036
|
{
|
1037
|
1037
|
saved_value = mincap;
|
1038
|
1038
|
}
|
1039
|
|
-
|
|
1039
|
+
|
1040
|
1040
|
if(!ctx->run_params.device_target->set_value(ctx->run_params.device_target, saved_value))
|
1041
|
1041
|
{
|
1042
|
1042
|
LIGHT_ERR("couldn't write saved value to device target");
|
1043
|
1043
|
return false;
|
1044
|
1044
|
}
|
1045
|
|
-
|
|
1045
|
+
|
1046
|
1046
|
return true;
|
1047
|
1047
|
}
|
1048
|
1048
|
|
|
@@ -1053,11 +1053,11 @@ light_device_t *light_create_device(light_device_enumerator_t *enumerator, char
|
1053
|
1053
|
new_device->targets = NULL;
|
1054
|
1054
|
new_device->num_targets = 0;
|
1055
|
1055
|
new_device->device_data = device_data;
|
1056
|
|
-
|
|
1056
|
+
|
1057
|
1057
|
snprintf(new_device->name, sizeof(new_device->name), "%s", name);
|
1058
|
|
-
|
|
1058
|
+
|
1059
|
1059
|
_light_add_enumerator_device(enumerator, new_device);
|
1060
|
|
-
|
|
1060
|
+
|
1061
|
1061
|
return new_device;
|
1062
|
1062
|
}
|
1063
|
1063
|
|
|
@@ -1067,17 +1067,17 @@ void light_delete_device(light_device_t *device)
|
1067
|
1067
|
{
|
1068
|
1068
|
light_delete_device_target(device->targets[i]);
|
1069
|
1069
|
}
|
1070
|
|
-
|
|
1070
|
+
|
1071
|
1071
|
if(device->targets != NULL)
|
1072
|
1072
|
{
|
1073
|
1073
|
free(device->targets);
|
1074
|
1074
|
}
|
1075
|
|
-
|
|
1075
|
+
|
1076
|
1076
|
if(device->device_data != NULL)
|
1077
|
1077
|
{
|
1078
|
1078
|
free(device->device_data);
|
1079
|
1079
|
}
|
1080
|
|
-
|
|
1080
|
+
|
1081
|
1081
|
free(device);
|
1082
|
1082
|
}
|
1083
|
1083
|
|
|
@@ -1090,11 +1090,11 @@ light_device_target_t *light_create_device_target(light_device_t *device, char c
|
1090
|
1090
|
new_target->get_max_value = getmaxfunc;
|
1091
|
1091
|
new_target->custom_command = cmdfunc;
|
1092
|
1092
|
new_target->device_target_data = target_data;
|
1093
|
|
-
|
|
1093
|
+
|
1094
|
1094
|
snprintf(new_target->name, sizeof(new_target->name), "%s", name);
|
1095
|
|
-
|
|
1095
|
+
|
1096
|
1096
|
_light_add_device_target(device, new_target);
|
1097
|
|
-
|
|
1097
|
+
|
1098
|
1098
|
return new_target;
|
1099
|
1099
|
}
|
1100
|
1100
|
|
|
@@ -1104,6 +1104,6 @@ void light_delete_device_target(light_device_target_t *device_target)
|
1104
|
1104
|
{
|
1105
|
1105
|
free(device_target->device_target_data);
|
1106
|
1106
|
}
|
1107
|
|
-
|
|
1107
|
+
|
1108
|
1108
|
free(device_target);
|
1109
|
1109
|
}
|