소스 검색

delete blank lines

loong_C 2 년 전
부모
커밋
4a9b5f7357
7개의 변경된 파일153개의 추가작업 그리고 167개의 파일을 삭제
  1. 1
    2
      src/helpers.c
  2. 0
    1
      src/helpers.h
  3. 10
    12
      src/impl/razer.c
  4. 21
    23
      src/impl/sysfs.c
  5. 0
    2
      src/impl/util.c
  6. 115
    119
      src/light.c
  7. 6
    8
      src/light.h

+ 1
- 2
src/helpers.c 파일 보기

@@ -143,7 +143,6 @@ int light_mkpath(char *dir, mode_t mode)
143 143
     char *tempdir = strdup(dir);
144 144
     light_mkpath(dirname(tempdir), mode);
145 145
     free(tempdir);
146
-    
146
+
147 147
     return mkdir(dir, mode);
148 148
 }
149
-

+ 0
- 1
src/helpers.h 파일 보기

@@ -53,4 +53,3 @@ uint64_t light_log_clamp_max(uint64_t max);
53 53
 double light_percent_clamp(double percent);
54 54
 
55 55
 int light_mkpath(char *dir, mode_t mode);
56
-

+ 10
- 12
src/impl/razer.c 파일 보기

@@ -12,7 +12,7 @@ static void _impl_razer_add_target(light_device_t *device, char const *name, cha
12 12
     impl_razer_data_t *target_data = malloc(sizeof(impl_razer_data_t));
13 13
     snprintf(target_data->brightness, sizeof(target_data->brightness), "/sys/bus/hid/drivers/razerkbd/%s/%s", device->name, filename);
14 14
     target_data->max_brightness = max_brightness;
15
-    
15
+
16 16
     // Only add targets that actually exist, as we aren't fully sure exactly what targets exist for a given device
17 17
     if(light_file_exists(target_data->brightness))
18 18
     {
@@ -33,7 +33,7 @@ static void _impl_razer_add_device(light_device_enumerator_t *enumerator, char c
33 33
 
34 34
     // Setup a target to backlight
35 35
     _impl_razer_add_target(new_device, "backlight", "matrix_brightness", 255);
36
-    
36
+
37 37
     // Setup targets to different possible leds
38 38
     _impl_razer_add_target(new_device, "game_led", "game_led_state", 1);
39 39
     _impl_razer_add_target(new_device, "macro_led", "macro_led_state", 1);
@@ -48,13 +48,13 @@ bool impl_razer_init(light_device_enumerator_t *enumerator)
48 48
     // Iterate through the led controllers and create a device_target for each controller 
49 49
     DIR *razer_dir;
50 50
     struct dirent *curr_entry;
51
-    
51
+
52 52
     if((razer_dir = opendir("/sys/bus/hid/drivers/razerkbd/")) == NULL)
53 53
     {
54 54
         // Razer driver isnt properly installed, so we cant add devices in this enumerator 
55 55
         return true;
56 56
     }
57
-    
57
+
58 58
     while((curr_entry = readdir(razer_dir)) != NULL)
59 59
     {
60 60
         // Skip dot entries
@@ -62,12 +62,12 @@ bool impl_razer_init(light_device_enumerator_t *enumerator)
62 62
         {
63 63
             continue;
64 64
         }
65
- 
65
+
66 66
         _impl_razer_add_device(enumerator, curr_entry->d_name);
67 67
     }
68
-    
68
+
69 69
     closedir(razer_dir);
70
-    
70
+
71 71
     return true;
72 72
 }
73 73
 
@@ -85,7 +85,7 @@ bool impl_razer_set(light_device_target_t *target, uint64_t in_value)
85 85
         LIGHT_ERR("failed to write to razer device");
86 86
         return false;
87 87
     }
88
-    
88
+
89 89
     return true;
90 90
 }
91 91
 
@@ -98,7 +98,7 @@ bool impl_razer_get(light_device_target_t *target, uint64_t *out_value)
98 98
         LIGHT_ERR("failed to read from razer device");
99 99
         return false;
100 100
     }
101
-    
101
+
102 102
     return true;
103 103
 }
104 104
 
@@ -107,7 +107,7 @@ bool impl_razer_getmax(light_device_target_t *target, uint64_t *out_value)
107 107
     impl_razer_data_t *data = (impl_razer_data_t*)target->device_target_data;
108 108
 
109 109
     *out_value = data->max_brightness;
110
-    
110
+
111 111
     return true;
112 112
 }
113 113
 
@@ -117,5 +117,3 @@ bool impl_razer_command(light_device_target_t *target, char const *command_strin
117 117
     // To implement support, simply parse the command string to your liking, and return false on invalid input or results!
118 118
     return true;
119 119
 }
120
-
121
-

+ 21
- 23
src/impl/sysfs.c 파일 보기

@@ -15,13 +15,13 @@ static bool _impl_sysfs_init_leds(light_device_enumerator_t *enumerator)
15 15
     // Iterate through the led controllers and create a device_target for each controller 
16 16
     DIR *leds_dir;
17 17
     struct dirent *curr_entry;
18
-    
18
+
19 19
     if((leds_dir = opendir("/sys/class/leds")) == NULL)
20 20
     {
21 21
         LIGHT_ERR("failed to open leds controller directory for reading");
22 22
         return false;
23 23
     }
24
-    
24
+
25 25
     while((curr_entry = readdir(leds_dir)) != NULL)
26 26
     {
27 27
         // Skip dot entries
@@ -29,18 +29,18 @@ static bool _impl_sysfs_init_leds(light_device_enumerator_t *enumerator)
29 29
         {
30 30
             continue;
31 31
         }
32
-        
32
+
33 33
         // Setup the target data 
34 34
         impl_sysfs_data_t *dev_data = malloc(sizeof(impl_sysfs_data_t));
35 35
         snprintf(dev_data->brightness, sizeof(dev_data->brightness), "/sys/class/leds/%s/brightness", curr_entry->d_name);
36 36
         snprintf(dev_data->max_brightness, sizeof(dev_data->max_brightness), "/sys/class/leds/%s/max_brightness", curr_entry->d_name);
37
-        
37
+
38 38
         // Create a new device target for the controller 
39 39
         light_create_device_target(leds_device, curr_entry->d_name, impl_sysfs_set, impl_sysfs_get, impl_sysfs_getmax, impl_sysfs_command, dev_data);
40 40
     }
41
-    
41
+
42 42
     closedir(leds_dir);
43
-    
43
+
44 44
     return true;
45 45
 }
46 46
 
@@ -52,17 +52,17 @@ static bool _impl_sysfs_init_backlight(light_device_enumerator_t *enumerator)
52 52
     // Iterate through the backlight controllers and create a device_target for each controller 
53 53
     DIR *backlight_dir;
54 54
     struct dirent *curr_entry;
55
-    
55
+
56 56
     // Keep track of the best controller, and create an autodevice from that
57 57
     char best_controller[NAME_MAX];
58 58
     uint64_t best_value = 0;
59
-    
59
+
60 60
     if((backlight_dir = opendir("/sys/class/backlight")) == NULL)
61 61
     {
62 62
         LIGHT_ERR("failed to open backlight controller directory for reading");
63 63
         return false;
64 64
     }
65
-    
65
+
66 66
     while((curr_entry = readdir(backlight_dir)) != NULL)
67 67
     {
68 68
         // Skip dot entries
@@ -70,15 +70,15 @@ static bool _impl_sysfs_init_backlight(light_device_enumerator_t *enumerator)
70 70
         {
71 71
             continue;
72 72
         }
73
-        
73
+
74 74
         // Setup the target data 
75 75
         impl_sysfs_data_t *dev_data = malloc(sizeof(impl_sysfs_data_t));
76 76
         snprintf(dev_data->brightness, sizeof(dev_data->brightness), "/sys/class/backlight/%s/brightness", curr_entry->d_name);
77 77
         snprintf(dev_data->max_brightness, sizeof(dev_data->max_brightness), "/sys/class/backlight/%s/max_brightness", curr_entry->d_name);
78
-        
78
+
79 79
         // Create a new device target for the controller 
80 80
         light_create_device_target(backlight_device, curr_entry->d_name, impl_sysfs_set, impl_sysfs_get, impl_sysfs_getmax, impl_sysfs_command, dev_data);
81
-        
81
+
82 82
         // Read the max brightness to get the best one
83 83
         uint64_t curr_value = 0;
84 84
         if(light_file_read_uint64(dev_data->max_brightness, &curr_value))
@@ -90,9 +90,9 @@ static bool _impl_sysfs_init_backlight(light_device_enumerator_t *enumerator)
90 90
             }
91 91
         }
92 92
     }
93
-    
93
+
94 94
     closedir(backlight_dir);
95
-    
95
+
96 96
     // If we found at least one usable controller, create an auto target mapped to that controller
97 97
     if(best_value > 0)
98 98
     {
@@ -100,11 +100,11 @@ static bool _impl_sysfs_init_backlight(light_device_enumerator_t *enumerator)
100 100
         impl_sysfs_data_t *dev_data = malloc(sizeof(impl_sysfs_data_t));
101 101
         snprintf(dev_data->brightness, sizeof(dev_data->brightness), "/sys/class/backlight/%s/brightness", best_controller);
102 102
         snprintf(dev_data->max_brightness, sizeof(dev_data->max_brightness), "/sys/class/backlight/%s/max_brightness", best_controller);
103
-        
103
+
104 104
         // Create a new device target for the controller 
105 105
         light_create_device_target(backlight_device, "auto", impl_sysfs_set, impl_sysfs_get, impl_sysfs_getmax, impl_sysfs_command, dev_data);
106 106
     }
107
-    
107
+
108 108
     return true;
109 109
 }
110 110
 
@@ -112,10 +112,10 @@ bool impl_sysfs_init(light_device_enumerator_t *enumerator)
112 112
 {
113 113
     // Create a device for the backlight 
114 114
     _impl_sysfs_init_backlight(enumerator);
115
-    
115
+
116 116
     // Create devices for the leds
117 117
     _impl_sysfs_init_leds(enumerator);
118
-    
118
+
119 119
     return true;
120 120
 }
121 121
 
@@ -133,7 +133,7 @@ bool impl_sysfs_set(light_device_target_t *target, uint64_t in_value)
133 133
         LIGHT_ERR("failed to write to sysfs device");
134 134
         return false;
135 135
     }
136
-    
136
+
137 137
     return true;
138 138
 }
139 139
 
@@ -146,7 +146,7 @@ bool impl_sysfs_get(light_device_target_t *target, uint64_t *out_value)
146 146
         LIGHT_ERR("failed to read from sysfs device");
147 147
         return false;
148 148
     }
149
-    
149
+
150 150
     return true;
151 151
 }
152 152
 
@@ -159,7 +159,7 @@ bool impl_sysfs_getmax(light_device_target_t *target, uint64_t *out_value)
159 159
         LIGHT_ERR("failed to read from sysfs device");
160 160
         return false;
161 161
     }
162
-    
162
+
163 163
     return true;
164 164
 }
165 165
 
@@ -169,5 +169,3 @@ bool impl_sysfs_command(light_device_target_t *target, char const *command_strin
169 169
     // To implement support, simply parse the command string to your liking, and return false on invalid input or results!
170 170
     return true;
171 171
 }
172
-
173
-

+ 0
- 2
src/impl/util.c 파일 보기

@@ -45,5 +45,3 @@ bool impl_util_dryrun_command(light_device_target_t *target, char const *command
45 45
     LIGHT_NOTE("impl_util_dryrun_command: running custom command on utility target %s: \"%s\"", target->name, command_string);
46 46
     return true;
47 47
 }
48
-
49
-

+ 115
- 119
src/light.c 파일 보기

@@ -17,28 +17,27 @@
17 17
 
18 18
 /* Static helper functions for this file only, prefix with _ */
19 19
 
20
-
21 20
 static void _light_add_enumerator_device(light_device_enumerator_t *enumerator, light_device_t *new_device)
22 21
 {
23 22
     // Create a new device array 
24 23
     uint64_t new_num_devices = enumerator->num_devices + 1;
25 24
     light_device_t **new_devices = malloc(new_num_devices * sizeof(light_device_t*));
26
-    
25
+
27 26
     // Copy old device array to new one
28 27
     for(uint64_t i = 0; i < enumerator->num_devices; i++)
29 28
     {
30 29
         new_devices[i] = enumerator->devices[i];
31 30
     }
32
-    
31
+
33 32
     // Set the new device
34 33
     new_devices[enumerator->num_devices] = new_device;
35
-    
34
+
36 35
     // Free the old devices array, if needed
37 36
     if(enumerator->devices != NULL)
38 37
     {
39 38
         free(enumerator->devices);
40 39
     }
41
-    
40
+
42 41
     // Replace the devices array with the new one
43 42
     enumerator->devices = new_devices;
44 43
     enumerator->num_devices = new_num_devices;
@@ -49,22 +48,22 @@ static void _light_add_device_target(light_device_t *device, light_device_target
49 48
     // Create a new targets array 
50 49
     uint64_t new_num_targets = device->num_targets + 1;
51 50
     light_device_target_t **new_targets = malloc(new_num_targets * sizeof(light_device_target_t*));
52
-    
51
+
53 52
     // Copy old targets array to new one
54 53
     for(uint64_t i = 0; i < device->num_targets; i++)
55 54
     {
56 55
         new_targets[i] = device->targets[i];
57 56
     }
58
-    
57
+
59 58
     // Set the new target
60 59
     new_targets[device->num_targets] = new_target;
61
-    
60
+
62 61
     // Free the old targets array, if needed
63 62
     if(device->targets != NULL)
64 63
     {
65 64
         free(device->targets);
66 65
     }
67
-    
66
+
68 67
     // Replace the targets array with the new one
69 68
     device->targets= new_targets;
70 69
     device->num_targets = new_num_targets;
@@ -103,7 +102,7 @@ static uint64_t _light_get_min_cap(light_context_t *ctx)
103 102
     {
104 103
         return 0;
105 104
     }
106
-    
105
+
107 106
     return minimum_value;
108 107
 }
109 108
 
@@ -116,7 +115,7 @@ static light_device_enumerator_t* _light_find_enumerator(light_context_t *ctx, c
116 115
             return ctx->enumerators[e];
117 116
         }
118 117
     }
119
-    
118
+
120 119
     return NULL;
121 120
 }
122 121
 
@@ -129,7 +128,7 @@ static light_device_t* _light_find_device(light_device_enumerator_t *en, char co
129 128
             return en->devices[d];
130 129
         }
131 130
     }
132
-    
131
+
133 132
     return NULL;
134 133
 }
135 134
 
@@ -142,24 +141,24 @@ static light_device_target_t* _light_find_target(light_device_t * dev, char cons
142 141
             return dev->targets[t];
143 142
         }
144 143
     }
145
-    
144
+
146 145
     return NULL;
147 146
 }
148 147
 
149 148
 static bool _light_raw_to_percent(light_device_target_t *target, uint64_t inraw, double *outpercent)
150 149
 {
151
-        double inraw_d = (double)inraw;
152
-        uint64_t max_value = 0;
153
-        if(!target->get_max_value(target, &max_value))
154
-        {
155
-            LIGHT_ERR("couldn't read from target");
156
-            return false;
157
-        }
158
-        double max_value_d = (double)max_value;
159
-        double percent = light_percent_clamp((inraw_d / max_value_d) * 100.0);
160
-        *outpercent = percent;
161
-        
162
-        return true;
150
+    double inraw_d = (double)inraw;
151
+    uint64_t max_value = 0;
152
+    if(!target->get_max_value(target, &max_value))
153
+    {
154
+        LIGHT_ERR("couldn't read from target");
155
+        return false;
156
+    }
157
+    double max_value_d = (double)max_value;
158
+    double percent = light_percent_clamp((inraw_d / max_value_d) * 100.0);
159
+    *outpercent = percent;
160
+
161
+    return true;
163 162
 }
164 163
 
165 164
 static bool _light_percent_to_raw(light_device_target_t *target, double inpercent, uint64_t *outraw)
@@ -175,7 +174,7 @@ static bool _light_percent_to_raw(light_device_target_t *target, double inpercen
175 174
     double target_value_d = max_value_d * (light_percent_clamp(inpercent) / 100.0);
176 175
     uint64_t target_value = LIGHT_CLAMP((uint64_t)target_value_d, 0, max_value);
177 176
     *outraw = target_value;
178
-    
177
+
179 178
     return true;
180 179
 }
181 180
 
@@ -224,7 +223,7 @@ static bool _light_set_context_command(light_context_t *ctx, LFUNCCOMMAND new_cm
224 223
         LIGHT_WARN("a command was already set. ignoring.");
225 224
         return false;
226 225
     }
227
-    
226
+
228 227
     ctx->run_params.command = new_cmd;
229 228
     return true;
230 229
 }
@@ -233,20 +232,20 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
233 232
 {
234 233
     int32_t curr_arg = -1;
235 234
     int32_t log_level = 0;
236
-    
235
+
237 236
     char ctrl_name[NAME_MAX];
238 237
     bool need_value = false;
239 238
     bool need_float_value = false;
240 239
     bool need_target = true; // default cmd is get brightness
241 240
     bool specified_target = false;
242 241
     snprintf(ctrl_name, sizeof(ctrl_name), "%s", "sysfs/backlight/auto");
243
-    
242
+
244 243
     while((curr_arg = getopt(argc, argv, "HhVGSLMNPAUTOIv:s:r")) != -1)
245 244
     {
246 245
         switch(curr_arg)
247 246
         {
248 247
             // Options
249
-            
248
+
250 249
             case 'v':
251 250
                 if(sscanf(optarg, "%i", &log_level) != 1)
252 251
                 {
@@ -254,14 +253,14 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
254 253
                     _light_print_usage();
255 254
                     return false;
256 255
                 }
257
-                
256
+
258 257
                 if(log_level < 0 || log_level > 3)
259 258
                 {
260 259
                     fprintf(stderr, "-v argument must be between 0 and 3.\n\n");
261 260
                     _light_print_usage();
262 261
                     return false;
263 262
                 }
264
-                
263
+
265 264
                 light_loglevel = (light_loglevel_t)log_level;
266 265
                 break;
267 266
             case 's':
@@ -271,7 +270,7 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
271 270
             case 'r':
272 271
                 ctx->run_params.raw_mode = true;
273 272
                 break;
274
-            
273
+
275 274
             // Commands
276 275
             case 'H':
277 276
             case 'h':
@@ -335,7 +334,7 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
335 334
     {
336 335
         _light_set_context_command(ctx, light_cmd_get_brightness);
337 336
     }
338
-    
337
+
339 338
     if(need_target)
340 339
     {
341 340
         light_device_target_t *curr_target = light_find_device_target(ctx, ctrl_name);
@@ -352,7 +351,7 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
352 351
                 curr_target = light_find_device_target(ctx, "util/test/dryrun");
353 352
             }
354 353
         }
355
-        
354
+
356 355
         ctx->run_params.device_target = curr_target;
357 356
     }
358 357
 
@@ -386,7 +385,7 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
386 385
                 _light_print_usage();
387 386
                 return false;
388 387
             }
389
-            
388
+
390 389
             percent_value = light_percent_clamp(percent_value);
391 390
             
392 391
             uint64_t raw_value = 0;
@@ -395,7 +394,7 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
395 394
                 LIGHT_ERR("failed to convert from percent to raw for device target");
396 395
                 return false;
397 396
             }
398
-            
397
+
399 398
             ctx->run_params.value = raw_value;
400 399
         }
401 400
     }
@@ -411,12 +410,9 @@ static bool _light_parse_arguments(light_context_t *ctx, int argc, char** argv)
411 410
     }
412 411
 
413 412
     return true;
414
-    
415 413
 }
416 414
 
417 415
 
418
-
419
-
420 416
 /* API function definitions */
421 417
 
422 418
 light_context_t* light_initialize(int argc, char **argv)
@@ -456,7 +452,6 @@ light_context_t* light_initialize(int argc, char **argv)
456 452
     else
457 453
     {
458 454
         char *xdg_conf = getenv("XDG_CONFIG_HOME");
459
-        
460 455
         if(xdg_conf != NULL)
461 456
         {
462 457
             snprintf(new_ctx->sys_params.conf_dir, sizeof(new_ctx->sys_params.conf_dir), "%s/light", xdg_conf);
@@ -466,7 +461,7 @@ light_context_t* light_initialize(int argc, char **argv)
466 461
             snprintf(new_ctx->sys_params.conf_dir, sizeof(new_ctx->sys_params.conf_dir), "%s/.config/light", getenv("HOME"));
467 462
         }
468 463
     }
469
-    
464
+
470 465
     // Make sure the configuration folder exists, otherwise attempt to create it
471 466
     int32_t rc = light_mkpath(new_ctx->sys_params.conf_dir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
472 467
     if(rc && errno != EEXIST)
@@ -474,7 +469,7 @@ light_context_t* light_initialize(int argc, char **argv)
474 469
         LIGHT_WARN("couldn't create configuration directory");
475 470
         return false;
476 471
     }
477
-    
472
+
478 473
     // Create the built-in enumerators
479 474
     light_create_enumerator(new_ctx, "sysfs", &impl_sysfs_init, &impl_sysfs_free);
480 475
     light_create_enumerator(new_ctx, "util", &impl_util_init, &impl_util_free);
@@ -496,7 +491,7 @@ light_context_t* light_initialize(int argc, char **argv)
496 491
         LIGHT_ERR("failed to parse arguments");
497 492
         return NULL;
498 493
     }
499
-    
494
+
500 495
     return new_ctx;
501 496
 }
502 497
 
@@ -507,7 +502,7 @@ bool light_execute(light_context_t *ctx)
507 502
         LIGHT_ERR("run parameters command was null, can't execute");
508 503
         return false;
509 504
     }
510
-    
505
+
511 506
     return ctx->run_params.command(ctx);
512 507
 }
513 508
 
@@ -517,7 +512,7 @@ void light_free(light_context_t *ctx)
517 512
     {
518 513
         LIGHT_WARN("failed to free all enumerators");
519 514
     }
520
-    
515
+
521 516
     free(ctx);
522 517
 }
523 518
 
@@ -526,29 +521,29 @@ light_device_enumerator_t * light_create_enumerator(light_context_t *ctx, char c
526 521
     // Create a new enumerator array 
527 522
     uint64_t new_num_enumerators = ctx->num_enumerators + 1;
528 523
     light_device_enumerator_t **new_enumerators = malloc(new_num_enumerators * sizeof(light_device_enumerator_t*));
529
-    
524
+
530 525
     // Copy old enumerator array to new one
531 526
     for(uint64_t i = 0; i < ctx->num_enumerators; i++)
532 527
     {
533 528
         new_enumerators[i] = ctx->enumerators[i];
534 529
     }
535
-    
530
+
536 531
     // Allocate the new enumerator
537 532
     new_enumerators[ctx->num_enumerators] = malloc(sizeof(light_device_enumerator_t));
538 533
     light_device_enumerator_t *returner = new_enumerators[ctx->num_enumerators];
539
-    
534
+
540 535
     returner->devices = NULL;
541 536
     returner->num_devices = 0;
542 537
     returner->init = init_func;
543 538
     returner->free = free_func;
544 539
     snprintf(returner->name, sizeof(returner->name), "%s", name);
545
-    
540
+
546 541
     // Free the old enumerator array, if needed
547 542
     if(ctx->enumerators != NULL)
548 543
     {
549 544
         free(ctx->enumerators);
550 545
     }
551
-    
546
+
552 547
     // Replace the enumerator array with the new one
553 548
     ctx->enumerators = new_enumerators;
554 549
     ctx->num_enumerators = new_num_enumerators;
@@ -568,7 +563,7 @@ bool light_init_enumerators(light_context_t *ctx)
568 563
             success = false;
569 564
         }
570 565
     }
571
-    
566
+
572 567
     return success;
573 568
 }
574 569
 
@@ -578,30 +573,29 @@ bool light_free_enumerators(light_context_t *ctx)
578 573
     for(uint64_t i = 0; i < ctx->num_enumerators; i++)
579 574
     {
580 575
         light_device_enumerator_t * curr_enumerator = ctx->enumerators[i];
581
-        
582 576
         if(!curr_enumerator->free(curr_enumerator))
583 577
         {
584 578
             success = false;
585 579
         }
586
-        
580
+
587 581
         if(curr_enumerator->devices != NULL)
588 582
         {
589 583
             for(uint64_t d = 0; d < curr_enumerator->num_devices; d++)
590 584
             {
591 585
                 light_delete_device(curr_enumerator->devices[d]);
592 586
             }
593
-            
587
+
594 588
             free(curr_enumerator->devices);
595 589
             curr_enumerator->devices = NULL;
596 590
         }
597
-        
591
+
598 592
         free(curr_enumerator);
599 593
     }
600
-    
594
+
601 595
     free(ctx->enumerators);
602 596
     ctx->enumerators = NULL;
603 597
     ctx->num_enumerators = 0;
604
-    
598
+
605 599
     return success;
606 600
 }
607 601
 
@@ -614,11 +608,11 @@ bool light_split_target_path(char const *in_path, light_target_path_t *out_path)
614 608
         LIGHT_WARN("invalid path passed to split_target_path");
615 609
         return false;
616 610
     }
617
-    
611
+
618 612
     size_t size = end - begin;
619 613
     strncpy(out_path->enumerator, begin, size);
620 614
     out_path->enumerator[size] = '\0';
621
-    
615
+
622 616
     begin = end + 1;
623 617
     end = strstr(begin, "/");
624 618
     if(end == NULL)
@@ -626,13 +620,13 @@ bool light_split_target_path(char const *in_path, light_target_path_t *out_path)
626 620
         LIGHT_WARN("invalid path passed to split_target_path");
627 621
         return false;
628 622
     }
629
-    
623
+
630 624
     size = end - begin;
631 625
     strncpy(out_path->device, begin, size);
632 626
     out_path->device[size] = '\0';
633
-    
627
+
634 628
     strcpy(out_path->target, end + 1);
635
-    
629
+
636 630
     return true;
637 631
 }
638 632
 
@@ -644,7 +638,7 @@ light_device_target_t* light_find_device_target(light_context_t *ctx, char const
644 638
         LIGHT_WARN("light_find_device_target needs a path in the format of \"enumerator/device/target\", the following format is not recognized:  \"%s\"", name);
645 639
         return NULL;
646 640
     }
647
-    
641
+
648 642
     /*
649 643
     Uncomment to debug the split function
650 644
     printf("enumerator: %s %u\ndevice: %s %u\ntarget: %s %u\n",
@@ -652,30 +646,30 @@ light_device_target_t* light_find_device_target(light_context_t *ctx, char const
652 646
             new_path.device, strlen(new_path.device),
653 647
             new_path.target, strlen(new_path.target));
654 648
     */
655
-    
649
+
656 650
     // find a matching enumerator 
657
-    
651
+
658 652
     light_device_enumerator_t *enumerator = _light_find_enumerator(ctx, new_path.enumerator);
659 653
     if(enumerator == NULL)
660 654
     {
661 655
         LIGHT_WARN("no such enumerator, \"%s\"", new_path.enumerator);
662 656
         return NULL;
663 657
     }
664
-    
658
+
665 659
     light_device_t *device = _light_find_device(enumerator, new_path.device);
666 660
     if(device == NULL)
667 661
     {
668 662
         LIGHT_WARN("no such device, \"%s\"", new_path.device);
669 663
         return NULL;
670 664
     }
671
-    
665
+
672 666
     light_device_target_t *target = _light_find_target(device, new_path.target);
673 667
     if(target == NULL)
674 668
     {
675 669
         LIGHT_WARN("no such target, \"%s\"", new_path.target);
676 670
         return NULL;
677 671
     }
678
-    
672
+
679 673
     return target;
680 674
 }
681 675
 
@@ -703,12 +697,11 @@ bool light_cmd_list_devices(light_context_t *ctx)
703 697
             for(uint64_t target = 0; target < curr_device->num_targets; target++)
704 698
             {
705 699
                 light_device_target_t *curr_target = curr_device->targets[target];
706
-                
707 700
                 printf("\t%s/%s/%s\n", curr_enumerator->name, curr_device->name, curr_target->name);
708 701
             }
709 702
         }
710 703
     }
711
-    
704
+
712 705
     return true;
713 706
 }
714 707
 
@@ -720,21 +713,20 @@ bool light_cmd_set_brightness(light_context_t *ctx)
720 713
         LIGHT_ERR("didn't have a valid target, programmer mistake");
721 714
         return false;
722 715
     }
723
-    
724
-    
716
+
725 717
     uint64_t mincap = _light_get_min_cap(ctx);
726 718
     uint64_t value = ctx->run_params.value;
727 719
     if(mincap > value)
728 720
     {
729 721
         value = mincap;
730 722
     }
731
-    
723
+
732 724
     if(!target->set_value(target, value))
733 725
     {
734 726
         LIGHT_ERR("failed to write to target");
735 727
         return false;
736 728
     }
737
-    
729
+
738 730
     return true;
739 731
 }
740 732
 
@@ -746,14 +738,14 @@ bool light_cmd_get_brightness(light_context_t *ctx)
746 738
         LIGHT_ERR("didn't have a valid target, programmer mistake");
747 739
         return false;
748 740
     }
749
-    
741
+
750 742
     uint64_t value = 0;
751 743
     if(!target->get_value(target, &value))
752 744
     {
753 745
         LIGHT_ERR("failed to read from target");
754 746
         return false;
755 747
     }
756
-    
748
+
757 749
     if(ctx->run_params.raw_mode)
758 750
     {
759 751
         printf("%" PRIu64 "\n", value);
@@ -768,7 +760,7 @@ bool light_cmd_get_brightness(light_context_t *ctx)
768 760
         }
769 761
         printf("%.2f\n", percent);
770 762
     }
771
-    
763
+
772 764
     return true;
773 765
 }
774 766
 
@@ -780,20 +772,20 @@ bool light_cmd_get_max_brightness(light_context_t *ctx)
780 772
         LIGHT_ERR("didn't have a valid target, programmer mistake");
781 773
         return false;
782 774
     }
783
-    
775
+
784 776
     if(!ctx->run_params.raw_mode)
785 777
     {
786 778
         printf("100.0\n");
787 779
         return true;
788 780
     }
789
-    
781
+
790 782
     uint64_t max_value = 0;
791 783
     if(!target->get_max_value(target, &max_value))
792 784
     {
793 785
         LIGHT_ERR("failed to read from device target");
794 786
         return false;
795 787
     }
796
-    
788
+
797 789
     printf("%" PRIu64 "\n", max_value);
798 790
     return true;
799 791
 }
@@ -802,7 +794,7 @@ bool light_cmd_set_min_brightness(light_context_t *ctx)
802 794
 {
803 795
     char target_path[NAME_MAX];
804 796
     _light_get_target_path(ctx, target_path, sizeof(target_path));
805
-    
797
+
806 798
     // Make sure the target folder exists, otherwise attempt to create it
807 799
     int32_t rc = light_mkpath(target_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
808 800
     if(rc && errno != EEXIST)
@@ -810,16 +802,16 @@ bool light_cmd_set_min_brightness(light_context_t *ctx)
810 802
         LIGHT_ERR("couldn't create target directory for minimum brightness");
811 803
         return false;
812 804
     }
813
-    
805
+
814 806
     char target_filepath[NAME_MAX];
815 807
     _light_get_target_file(ctx, target_filepath, sizeof(target_filepath), "minimum");
816
-    
808
+
817 809
     if(!light_file_write_uint64(target_filepath, ctx->run_params.value))
818 810
     {
819 811
         LIGHT_ERR("couldn't write value to minimum file");
820 812
         return false;
821 813
     }
822
-    
814
+
823 815
     return true;
824 816
 }
825 817
 
@@ -842,7 +834,7 @@ bool light_cmd_get_min_brightness(light_context_t *ctx)
842 834
 
843 835
         return true;
844 836
     }
845
-    
837
+
846 838
     if(ctx->run_params.raw_mode)
847 839
     {
848 840
         printf("%" PRIu64 "\n", minimum_value);
@@ -855,10 +847,10 @@ bool light_cmd_get_min_brightness(light_context_t *ctx)
855 847
             LIGHT_ERR("failed to convert value from raw to percent for device target");
856 848
             return false;
857 849
         }
858
-        
850
+
859 851
         printf("%.2f\n", minimum_d);
860 852
     }
861
-    
853
+
862 854
     return true;
863 855
 }
864 856
 
@@ -870,41 +862,39 @@ bool light_cmd_add_brightness(light_context_t *ctx)
870 862
         LIGHT_ERR("didn't have a valid target, programmer mistake");
871 863
         return false;
872 864
     }
873
-    
865
+
874 866
     uint64_t value = 0;
875 867
     if(!target->get_value(target, &value))
876 868
     {
877 869
         LIGHT_ERR("failed to read from target");
878 870
         return false;
879 871
     }
880
-    
872
+
881 873
     uint64_t max_value = 0;
882 874
     if(!target->get_max_value(target, &max_value))
883 875
     {
884 876
         LIGHT_ERR("failed to read from target");
885 877
         return false;
886 878
     }
887
-    
879
+
888 880
     value += ctx->run_params.value;
889
-    
890 881
     uint64_t mincap = _light_get_min_cap(ctx);
891 882
     if(mincap > value)
892 883
     {
893 884
         value = mincap;
894 885
     }
895
-    
896
-    
886
+
897 887
     if(value > max_value)
898 888
     {
899 889
         value = max_value;
900 890
     }
901
-    
891
+
902 892
     if(!target->set_value(target, value))
903 893
     {
904 894
         LIGHT_ERR("failed to write to target");
905 895
         return false;
906 896
     }
907
-    
897
+
908 898
     return true;
909 899
 }
910 900
 
@@ -916,14 +906,14 @@ bool light_cmd_sub_brightness(light_context_t *ctx)
916 906
         LIGHT_ERR("didn't have a valid target, programmer mistake");
917 907
         return false;
918 908
     }
919
-    
909
+
920 910
     uint64_t value = 0;
921 911
     if(!target->get_value(target, &value))
922 912
     {
923 913
         LIGHT_ERR("failed to read from target");
924 914
         return false;
925 915
     }
926
-    
916
+
927 917
     if(value > ctx->run_params.value)
928 918
     {
929 919
         value -= ctx->run_params.value;
@@ -932,7 +922,7 @@ bool light_cmd_sub_brightness(light_context_t *ctx)
932 922
     {
933 923
         value = 0;
934 924
     }
935
-    
925
+
936 926
     uint64_t mincap = _light_get_min_cap(ctx);
937 927
     if(mincap > value)
938 928
     {
@@ -944,7 +934,7 @@ bool light_cmd_sub_brightness(light_context_t *ctx)
944 934
         LIGHT_ERR("failed to write to target");
945 935
         return false;
946 936
     }
947
-    
937
+
948 938
     return true;
949 939
 }
950 940
 
@@ -973,7 +963,7 @@ bool light_cmd_mul_brightness(light_context_t *ctx)
973 963
 
974 964
     uint64_t old_value = value;
975 965
     value *= ctx->run_params.float_value;
976
- 
966
+
977 967
     // Check that we actually de/increase value
978 968
     if(value == old_value)
979 969
     {
@@ -1007,7 +997,7 @@ bool light_cmd_save_brightness(light_context_t *ctx)
1007 997
 {
1008 998
     char target_path[NAME_MAX];
1009 999
     _light_get_target_path(ctx, target_path, sizeof(target_path));
1010
-    
1000
+
1011 1001
     // Make sure the target folder exists, otherwise attempt to create it
1012 1002
     int32_t rc = light_mkpath(target_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
1013 1003
     if(rc && errno != EEXIST)
@@ -1015,7 +1005,7 @@ bool light_cmd_save_brightness(light_context_t *ctx)
1015 1005
         LIGHT_ERR("couldn't create target directory for save brightness");
1016 1006
         return false;
1017 1007
     }
1018
-    
1008
+
1019 1009
     char target_filepath[NAME_MAX];
1020 1010
     _light_get_target_file(ctx, target_filepath, sizeof(target_filepath), "save");
1021 1011
 
@@ -1025,13 +1015,13 @@ bool light_cmd_save_brightness(light_context_t *ctx)
1025 1015
         LIGHT_ERR("couldn't read from device target");
1026 1016
         return false;
1027 1017
     }
1028
-    
1018
+
1029 1019
     if(!light_file_write_uint64(target_filepath, curr_value))
1030 1020
     {
1031 1021
         LIGHT_ERR("couldn't write value to savefile");
1032 1022
         return false;
1033 1023
     }
1034
-    
1024
+
1035 1025
     return true;
1036 1026
 }
1037 1027
 
@@ -1046,19 +1036,19 @@ bool light_cmd_restore_brightness(light_context_t *ctx)
1046 1036
         LIGHT_ERR("couldn't read value from savefile");
1047 1037
         return false;
1048 1038
     }
1049
-    
1039
+
1050 1040
     uint64_t mincap = _light_get_min_cap(ctx);
1051 1041
     if(mincap > saved_value)
1052 1042
     {
1053 1043
         saved_value = mincap;
1054 1044
     }
1055
-    
1045
+
1056 1046
     if(!ctx->run_params.device_target->set_value(ctx->run_params.device_target, saved_value))
1057 1047
     {
1058 1048
         LIGHT_ERR("couldn't write saved value to device target");
1059 1049
         return false;
1060 1050
     }
1061
-    
1051
+
1062 1052
     return true;
1063 1053
 }
1064 1054
 
@@ -1069,11 +1059,11 @@ light_device_t *light_create_device(light_device_enumerator_t *enumerator, char
1069 1059
     new_device->targets = NULL;
1070 1060
     new_device->num_targets = 0;
1071 1061
     new_device->device_data = device_data;
1072
-    
1062
+
1073 1063
     snprintf(new_device->name, sizeof(new_device->name), "%s", name);
1074
-    
1064
+
1075 1065
     _light_add_enumerator_device(enumerator, new_device);
1076
-    
1066
+
1077 1067
     return new_device;
1078 1068
 }
1079 1069
 
@@ -1083,21 +1073,27 @@ void light_delete_device(light_device_t *device)
1083 1073
     {
1084 1074
         light_delete_device_target(device->targets[i]);
1085 1075
     }
1086
-    
1076
+
1087 1077
     if(device->targets != NULL)
1088 1078
     {
1089 1079
         free(device->targets);
1090 1080
     }
1091
-    
1081
+
1092 1082
     if(device->device_data != NULL)
1093 1083
     {
1094 1084
         free(device->device_data);
1095 1085
     }
1096
-    
1086
+
1097 1087
     free(device);
1098 1088
 }
1099 1089
 
1100
-light_device_target_t *light_create_device_target(light_device_t *device, char const *name, LFUNCVALSET setfunc, LFUNCVALGET getfunc, LFUNCMAXVALGET getmaxfunc, LFUNCCUSTOMCMD cmdfunc, void *target_data)
1090
+light_device_target_t *light_create_device_target(light_device_t *device,
1091
+                                                    char const *name,
1092
+                                                    LFUNCVALSET setfunc,
1093
+                                                    LFUNCVALGET getfunc,
1094
+                                                    LFUNCMAXVALGET getmaxfunc,
1095
+                                                    LFUNCCUSTOMCMD cmdfunc,
1096
+                                                    void *target_data)
1101 1097
 {
1102 1098
     light_device_target_t *new_target = malloc(sizeof(light_device_target_t));
1103 1099
     new_target->device = device;
@@ -1106,11 +1102,11 @@ light_device_target_t *light_create_device_target(light_device_t *device, char c
1106 1102
     new_target->get_max_value = getmaxfunc;
1107 1103
     new_target->custom_command = cmdfunc;
1108 1104
     new_target->device_target_data = target_data;
1109
-    
1105
+
1110 1106
     snprintf(new_target->name, sizeof(new_target->name), "%s", name);
1111
-    
1107
+
1112 1108
     _light_add_device_target(device, new_target);
1113
-    
1109
+
1114 1110
     return new_target;
1115 1111
 }
1116 1112
 
@@ -1120,6 +1116,6 @@ void light_delete_device_target(light_device_target_t *device_target)
1120 1116
     {
1121 1117
         free(device_target->device_target_data);
1122 1118
     }
1123
-    
1119
+
1124 1120
     free(device_target);
1125 1121
 }

+ 6
- 8
src/light.h 파일 보기

@@ -8,7 +8,7 @@
8 8
 
9 9
 #include "config.h"
10 10
 
11
-#define LIGHT_YEAR   "2012 - 2018"
11
+#define LIGHT_YEAR   "2012 - 2022"
12 12
 #define LIGHT_AUTHOR "Fredrik Haikarainen"
13 13
 
14 14
 struct _light_device_target_t;
@@ -41,14 +41,13 @@ struct _light_device_target_t
41 41
 /* Describes a device (a backlight, a keyboard, a led-strip) */
42 42
 struct _light_device_t
43 43
 {
44
-    char                  name[256];
45
-    light_device_target_t **targets;
46
-    uint64_t              num_targets;
47
-    void                  *device_data;
44
+    char                      name[256];
45
+    light_device_target_t     **targets;
46
+    uint64_t                  num_targets;
47
+    void                      *device_data;
48 48
     light_device_enumerator_t *enumerator;
49 49
 };
50 50
 
51
-
52 51
 typedef bool (*LFUNCENUMINIT)(light_device_enumerator_t*);
53 52
 typedef bool (*LFUNCENUMFREE)(light_device_enumerator_t*);
54 53
 
@@ -84,7 +83,7 @@ struct _light_context_t
84 83
     {
85 84
         char                    conf_dir[NAME_MAX]; // The path to the application cache directory 
86 85
     } sys_params;
87
-    
86
+
88 87
     light_device_enumerator_t   **enumerators;
89 88
     uint64_t                    num_enumerators;
90 89
 };
@@ -146,4 +145,3 @@ bool light_split_target_path(char const * in_path, light_target_path_t *out_path
146 145
 
147 146
 /* Returns the found device target, or null. Name should be enumerator/device/target */
148 147
 light_device_target_t* light_find_device_target(light_context_t *ctx, char const * name);
149
-