]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android/external-libkmsxx.git/blob - utils/kmsblank.cpp
kmstest: add help text about env variables
[android/external-libkmsxx.git] / utils / kmsblank.cpp
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <algorithm>
5 #include <kms++/kms++.h>
6 #include <kms++util/kms++util.h>
8 using namespace std;
9 using namespace kms;
11 static const char* usage_str =
12                 "Usage: kmsblank [OPTION]...\n\n"
13                 "Blank screen(s)\n\n"
14                 "Options:\n"
15                 "      --device=DEVICE       DEVICE is the path to DRM card to open\n"
16                 "  -c, --connector=CONN      CONN is <connector>\n"
17                 "  -t, --time=TIME           blank/unblank in TIME intervals\n"
18                 "\n"
19                 "<connector> can be given by index (<idx>) or id (@<id>).\n"
20                 "<connector> can also be given by name.\n"
21                 ;
23 static void usage()
24 {
25         puts(usage_str);
26 }
28 int main(int argc, char **argv)
29 {
30         string dev_path = "/dev/dri/card0";
32         vector<string> conn_strs;
33         uint32_t time = 0;
35         OptionSet optionset = {
36                 Option("|device=", [&dev_path](string s)
37                 {
38                         dev_path = s;
39                 }),
40                 Option("c|connector=", [&conn_strs](string str)
41                 {
42                         conn_strs.push_back(str);
43                 }),
44                 Option("t|time=", [&time](string str)
45                 {
46                         time = stoul(str);
47                 }),
48                 Option("h|help", []()
49                 {
50                         usage();
51                         exit(-1);
52                 }),
53         };
55         optionset.parse(argc, argv);
57         if (optionset.params().size() > 0) {
58                 usage();
59                 exit(-1);
60         }
62         Card card(dev_path);
63         ResourceManager resman(card);
65         vector<Connector*> conns;
67         if (conn_strs.size() > 0) {
68                 for (string s : conn_strs) {
69                         auto c = resman.reserve_connector(s);
70                         if (!c)
71                                 EXIT("Failed to resolve connector '%s'", s.c_str());
72                         conns.push_back(c);
73                 }
74         } else {
75                 conns = card.get_connectors();
76         }
78         bool blank = true;
80         while (true) {
81                 for (Connector* conn : conns) {
82                         if (!conn->connected()) {
83                                 printf("Connector %u not connected\n", conn->idx());
84                                 continue;
85                         }
87                         printf("Connector %u: %sblank\n", conn->idx(), blank ? "" : "un");
88                         int r = conn->set_prop_value("DPMS", blank ? 3 : 0);
89                         if (r)
90                                 EXIT("Failed to set DPMS: %d", r);
91                 }
93                 if (time == 0)
94                         break;
96                 usleep(1000 * time);
98                 blank = !blank;
99         }
101         printf("press enter to exit\n");
103         getchar();