浏览代码

implement util enumerator, dryrun, fix #60

Fredrik Svantesson 5 年前
父节点
当前提交
7bf19b3ebb
共有 4 个文件被更改,包括 67 次插入1 次删除
  1. 1
    1
      src/Makefile.am
  2. 49
    0
      src/impl/util.c
  3. 15
    0
      src/impl/util.h
  4. 2
    0
      src/light.c

+ 1
- 1
src/Makefile.am 查看文件

@@ -1,5 +1,5 @@
1 1
 bin_PROGRAMS   = light
2
-light_SOURCES  = main.c light.c light.h helpers.c helpers.h impl/sysfs.c impl/sysfs.h
2
+light_SOURCES  = main.c light.c light.h helpers.c helpers.h impl/sysfs.c impl/sysfs.h impl/util.h impl/util.c
3 3
 light_CPPFLAGS = -I../include -D_GNU_SOURCE
4 4
 light_CFLAGS   = -W -Wall -Wextra -std=gnu18 -Wno-type-limits -Wno-format-truncation -Wno-unused-parameter
5 5
 

+ 49
- 0
src/impl/util.c 查看文件

@@ -0,0 +1,49 @@
1
+
2
+#include "impl/util.h"
3
+#include "light.h"
4
+#include "helpers.h"
5
+
6
+#include <stdio.h> //snprintf
7
+#include <stdlib.h> // malloc, free
8
+#include <dirent.h> // opendir, readdir
9
+#include <inttypes.h> // PRIu64
10
+
11
+bool impl_util_init(light_device_enumerator_t *enumerator)
12
+{
13
+    light_device_t *util_device = light_create_device(enumerator, "test", NULL);
14
+    light_create_device_target(util_device, "dryrun", impl_util_dryrun_set, impl_util_dryrun_get, impl_util_dryrun_getmax, impl_util_dryrun_command, NULL);
15
+    return true;
16
+}
17
+
18
+bool impl_util_free(light_device_enumerator_t *enumerator)
19
+{
20
+    return true;
21
+}
22
+
23
+bool impl_util_dryrun_set(light_device_target_t *target, uint64_t in_value)
24
+{
25
+    LIGHT_NOTE("impl_util_dryrun_set: writing brightness %" PRIu64 " to utility target %s", in_value, target->name);
26
+    return true;
27
+}
28
+
29
+bool impl_util_dryrun_get(light_device_target_t *target, uint64_t *out_value)
30
+{
31
+    LIGHT_NOTE("impl_util_dryrun_get: reading brightness (0) from utility target %s", target->name);
32
+    *out_value = 0;
33
+    return true;
34
+}
35
+
36
+bool impl_util_dryrun_getmax(light_device_target_t *target, uint64_t *out_value)
37
+{
38
+    LIGHT_NOTE("impl_util_dryrun_getmax: reading max. brightness (255) from utility target %s", target->name);
39
+    *out_value = 255;
40
+    return true;
41
+}
42
+
43
+bool impl_util_dryrun_command(light_device_target_t *target, char const *command_string)
44
+{
45
+    LIGHT_NOTE("impl_util_dryrun_command: running custom command on utility target %s: \"%s\"", target->name, command_string);
46
+    return true;
47
+}
48
+
49
+

+ 15
- 0
src/impl/util.h 查看文件

@@ -0,0 +1,15 @@
1
+
2
+#pragma once 
3
+
4
+#include "light.h"
5
+
6
+// Implementation of the util enumerator
7
+// Enumerates devices for utilities and testing
8
+
9
+bool impl_util_init(light_device_enumerator_t *enumerator);
10
+bool impl_util_free(light_device_enumerator_t *enumerator);
11
+
12
+bool impl_util_dryrun_set(light_device_target_t *target, uint64_t in_value);
13
+bool impl_util_dryrun_get(light_device_target_t *target, uint64_t *out_value);
14
+bool impl_util_dryrun_getmax(light_device_target_t *target, uint64_t *out_value);
15
+bool impl_util_dryrun_command(light_device_target_t *target, char const *command_string);

+ 2
- 0
src/light.c 查看文件

@@ -4,6 +4,7 @@
4 4
 
5 5
 // The different device implementations
6 6
 #include "impl/sysfs.h"
7
+#include "impl/util.h"
7 8
 //#include "impl/razer.h"
8 9
 
9 10
 #include <stdlib.h> // malloc, free
@@ -431,6 +432,7 @@ light_context_t* light_initialize(int argc, char **argv)
431 432
     
432 433
     // Create the built-in enumerators
433 434
     light_create_enumerator(new_ctx, "sysfs", &impl_sysfs_init, &impl_sysfs_free);
435
+    light_create_enumerator(new_ctx, "util", &impl_util_init, &impl_util_free);
434 436
     //light_create_enumerator(new_ctx, "razer", &impl_razer_init, &impl_razer_free);
435 437
 
436 438
     // This is where we would create enumerators from plugins as well