Browse Source

Merge 4a9b5f7357cc720acb86af7d5f03ba0d5bbd6111 into c5fb45423ec1ee1080e442e061ccfcdb98b32e4a

loong-C 2 years ago
parent
commit
afba1192bc
No account linked to committer's email
7 changed files with 153 additions and 167 deletions
  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 View File

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

+ 0
- 1
src/helpers.h View File

53
 double light_percent_clamp(double percent);
53
 double light_percent_clamp(double percent);
54
 
54
 
55
 int light_mkpath(char *dir, mode_t mode);
55
 int light_mkpath(char *dir, mode_t mode);
56
-

+ 10
- 12
src/impl/razer.c View File

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

+ 21
- 23
src/impl/sysfs.c View File

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

+ 0
- 2
src/impl/util.c View File

45
     LIGHT_NOTE("impl_util_dryrun_command: running custom command on utility target %s: \"%s\"", target->name, command_string);
45
     LIGHT_NOTE("impl_util_dryrun_command: running custom command on utility target %s: \"%s\"", target->name, command_string);
46
     return true;
46
     return true;
47
 }
47
 }
48
-
49
-

+ 115
- 119
src/light.c View File

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

+ 6
- 8
src/light.h View File

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