|
@@ -10,12 +10,8 @@
|
10
|
10
|
static bool _impl_sysfs_init_leds(light_device_enumerator_t *enumerator)
|
11
|
11
|
{
|
12
|
12
|
// Create a new backlight device
|
13
|
|
- light_device_t *leds_device = malloc(sizeof(light_device_t));
|
14
|
|
- snprintf(leds_device->name, sizeof(leds_device->name), "%s", "leds");
|
15
|
|
-
|
16
|
|
- // Add it to the enumerator
|
17
|
|
- light_add_enumerator_device(enumerator, leds_device);
|
18
|
|
-
|
|
13
|
+ light_device_t *leds_device = light_create_device(enumerator, "leds", NULL);
|
|
14
|
+
|
19
|
15
|
// Iterate through the led controllers and create a device_target for each controller
|
20
|
16
|
DIR *leds_dir;
|
21
|
17
|
struct dirent *curr_entry;
|
|
@@ -34,24 +30,13 @@ static bool _impl_sysfs_init_leds(light_device_enumerator_t *enumerator)
|
34
|
30
|
continue;
|
35
|
31
|
}
|
36
|
32
|
|
37
|
|
- // Create a new device target for the controller
|
38
|
|
- light_device_target_t *led_controller = malloc(sizeof(light_device_target_t));
|
39
|
|
- snprintf(led_controller->name, sizeof(led_controller->name), "%s", curr_entry->d_name);
|
40
|
|
-
|
41
|
|
- // Setup the function bindings
|
42
|
|
- led_controller->set_value = impl_sysfs_set;
|
43
|
|
- led_controller->get_value = impl_sysfs_get;
|
44
|
|
- led_controller->get_max_value = impl_sysfs_getmax;
|
45
|
|
- led_controller->custom_command = impl_sysfs_command;
|
46
|
|
-
|
47
|
33
|
// Setup the target data
|
48
|
34
|
impl_sysfs_data_t *dev_data = malloc(sizeof(impl_sysfs_data_t));
|
49
|
|
- led_controller->device_target_data = dev_data;
|
50
|
35
|
snprintf(dev_data->brightness, sizeof(dev_data->brightness), "/sys/class/leds/%s/brightness", curr_entry->d_name);
|
51
|
36
|
snprintf(dev_data->max_brightness, sizeof(dev_data->max_brightness), "/sys/class/leds/%s/max_brightness", curr_entry->d_name);
|
52
|
37
|
|
53
|
|
- // Add it to the device
|
54
|
|
- light_add_device_target(leds_device, led_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);
|
55
|
40
|
}
|
56
|
41
|
|
57
|
42
|
closedir(leds_dir);
|
|
@@ -62,12 +47,8 @@ static bool _impl_sysfs_init_leds(light_device_enumerator_t *enumerator)
|
62
|
47
|
static bool _impl_sysfs_init_backlight(light_device_enumerator_t *enumerator)
|
63
|
48
|
{
|
64
|
49
|
// Create a new backlight device
|
65
|
|
- light_device_t *backlight_device = malloc(sizeof(light_device_t));
|
66
|
|
- snprintf(backlight_device->name, sizeof(backlight_device->name), "%s", "backlight");
|
67
|
|
-
|
68
|
|
- // Add it to the enumerator
|
69
|
|
- light_add_enumerator_device(enumerator, backlight_device);
|
70
|
|
-
|
|
50
|
+ light_device_t *backlight_device = light_create_device(enumerator, "backlight", NULL);
|
|
51
|
+
|
71
|
52
|
// Iterate through the backlight controllers and create a device_target for each controller
|
72
|
53
|
DIR *backlight_dir;
|
73
|
54
|
struct dirent *curr_entry;
|
|
@@ -90,22 +71,14 @@ static bool _impl_sysfs_init_backlight(light_device_enumerator_t *enumerator)
|
90
|
71
|
continue;
|
91
|
72
|
}
|
92
|
73
|
|
93
|
|
- // Create a new device target for the controller
|
94
|
|
- light_device_target_t *backlight_controller = malloc(sizeof(light_device_target_t));
|
95
|
|
- snprintf(backlight_controller->name, sizeof(backlight_controller->name), "%s", curr_entry->d_name);
|
96
|
|
-
|
97
|
|
- // Setup the function bindings
|
98
|
|
- backlight_controller->set_value = impl_sysfs_set;
|
99
|
|
- backlight_controller->get_value = impl_sysfs_get;
|
100
|
|
- backlight_controller->get_max_value = impl_sysfs_getmax;
|
101
|
|
- backlight_controller->custom_command = impl_sysfs_command;
|
102
|
|
-
|
103
|
74
|
// Setup the target data
|
104
|
75
|
impl_sysfs_data_t *dev_data = malloc(sizeof(impl_sysfs_data_t));
|
105
|
|
- backlight_controller->device_target_data = dev_data;
|
106
|
76
|
snprintf(dev_data->brightness, sizeof(dev_data->brightness), "/sys/class/backlight/%s/brightness", curr_entry->d_name);
|
107
|
77
|
snprintf(dev_data->max_brightness, sizeof(dev_data->max_brightness), "/sys/class/backlight/%s/max_brightness", curr_entry->d_name);
|
108
|
78
|
|
|
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);
|
|
81
|
+
|
109
|
82
|
// Read the max brightness to get the best one
|
110
|
83
|
uint64_t curr_value = 0;
|
111
|
84
|
if(light_file_read_uint64(dev_data->max_brightness, &curr_value))
|
|
@@ -113,34 +86,24 @@ static bool _impl_sysfs_init_backlight(light_device_enumerator_t *enumerator)
|
113
|
86
|
if(curr_value > best_value)
|
114
|
87
|
{
|
115
|
88
|
best_value = curr_value;
|
116
|
|
- snprintf(best_controller, sizeof(best_controller), "%s", backlight_controller->name);
|
|
89
|
+ snprintf(best_controller, sizeof(best_controller), "%s", curr_entry->d_name);
|
117
|
90
|
}
|
118
|
91
|
}
|
119
|
|
-
|
120
|
|
- // Add it to the device
|
121
|
|
- light_add_device_target(backlight_device, backlight_controller);
|
122
|
92
|
}
|
123
|
93
|
|
124
|
94
|
closedir(backlight_dir);
|
125
|
95
|
|
126
|
|
- // Create an auto controller
|
127
|
|
- light_device_target_t *auto_controller = malloc(sizeof(light_device_target_t));
|
128
|
|
- snprintf(auto_controller->name, sizeof(auto_controller->name), "%s", "auto");
|
129
|
|
-
|
130
|
|
- // Setup the function bindings
|
131
|
|
- auto_controller->set_value = impl_sysfs_set;
|
132
|
|
- auto_controller->get_value = impl_sysfs_get;
|
133
|
|
- auto_controller->get_max_value = impl_sysfs_getmax;
|
134
|
|
- auto_controller->custom_command = impl_sysfs_command;
|
135
|
|
-
|
136
|
|
- // Setup the target data
|
137
|
|
- impl_sysfs_data_t *dev_data = malloc(sizeof(impl_sysfs_data_t));
|
138
|
|
- auto_controller->device_target_data = dev_data;
|
139
|
|
- snprintf(dev_data->brightness, sizeof(dev_data->brightness), "/sys/class/backlight/%s/brightness", best_controller);
|
140
|
|
- snprintf(dev_data->max_brightness, sizeof(dev_data->max_brightness), "/sys/class/backlight/%s/max_brightness", best_controller);
|
141
|
|
-
|
142
|
|
- // Add it to the device
|
143
|
|
- light_add_device_target(backlight_device, auto_controller);
|
|
96
|
+ // If we found at least one usable controller, create an auto target mapped to that controller
|
|
97
|
+ if(best_value > 0)
|
|
98
|
+ {
|
|
99
|
+ // Setup the target data
|
|
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);
|
|
102
|
+ snprintf(dev_data->max_brightness, sizeof(dev_data->max_brightness), "/sys/class/backlight/%s/max_brightness", best_controller);
|
|
103
|
+
|
|
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);
|
|
106
|
+ }
|
144
|
107
|
|
145
|
108
|
return true;
|
146
|
109
|
}
|
|
@@ -158,46 +121,6 @@ bool impl_sysfs_init(light_device_enumerator_t *enumerator)
|
158
|
121
|
|
159
|
122
|
bool impl_sysfs_free(light_device_enumerator_t *enumerator)
|
160
|
123
|
{
|
161
|
|
- // Iterate through the devices in the enumerator
|
162
|
|
- for(uint64_t d = 0; d < enumerator->num_devices; d++)
|
163
|
|
- {
|
164
|
|
- light_device_t *curr_device = enumerator->devices[d];
|
165
|
|
-
|
166
|
|
- // If the given device points to NULL, we can safely skip it
|
167
|
|
- if(curr_device == NULL)
|
168
|
|
- {
|
169
|
|
- continue;
|
170
|
|
- }
|
171
|
|
-
|
172
|
|
- for(uint64_t t = 0; t < curr_device->num_targets; t++)
|
173
|
|
- {
|
174
|
|
- light_device_target_t *curr_target = curr_device->targets[t];
|
175
|
|
-
|
176
|
|
- if(curr_target == NULL)
|
177
|
|
- {
|
178
|
|
- continue;
|
179
|
|
- }
|
180
|
|
-
|
181
|
|
- if(curr_target->device_target_data != NULL)
|
182
|
|
- {
|
183
|
|
- free(curr_target->device_target_data);
|
184
|
|
- }
|
185
|
|
-
|
186
|
|
- free(curr_target);
|
187
|
|
- }
|
188
|
|
-
|
189
|
|
- // If the given device has any device_data, free it
|
190
|
|
- if(curr_device->device_data != NULL)
|
191
|
|
- {
|
192
|
|
- free(curr_device->device_data);
|
193
|
|
- }
|
194
|
|
-
|
195
|
|
- light_dispose_device(curr_device);
|
196
|
|
-
|
197
|
|
- // Free the device
|
198
|
|
- free(curr_device);
|
199
|
|
- }
|
200
|
|
-
|
201
|
124
|
return true;
|
202
|
125
|
}
|
203
|
126
|
|