cmake: results to bin & lib dirs
[android/external-libkmsxx.git] / utils / kmsblank.cpp
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <algorithm>
5 #include <kms++.h>
6 #include <kms++util.h>
7 #include "opts.h"
9 using namespace std;
10 using namespace kms;
12 static const char* usage_str =
13                 "Usage: kmsblank [OPTION]...\n\n"
14                 "Blank screen(s)\n\n"
15                 "Options:\n"
16                 "      --device=DEVICE       DEVICE is the path to DRM card to open\n"
17                 "  -c, --connector=CONN      CONN is <connector>\n"
18                 "  -t, --time=TIME           blank/unblank in TIME intervals\n"
19                 "\n"
20                 "<connector> can be given by index (<idx>) or id (@<id>).\n"
21                 "<connector> can also be given by name.\n"
22                 ;
24 static void usage()
25 {
26         puts(usage_str);
27 }
29 int main(int argc, char **argv)
30 {
31         string dev_path = "/dev/dri/card0";
33         vector<string> conn_strs;
34         uint32_t time = 0;
36         OptionSet optionset = {
37                 Option("|device=", [&dev_path](string s)
38                 {
39                         dev_path = s;
40                 }),
41                 Option("c|connector=", [&conn_strs](string str)
42                 {
43                         conn_strs.push_back(str);
44                 }),
45                 Option("t|time=", [&time](string str)
46                 {
47                         time = stoul(str);
48                 }),
49                 Option("h|help", []()
50                 {
51                         usage();
52                         exit(-1);
53                 }),
54         };
56         optionset.parse(argc, argv);
58         if (optionset.params().size() > 0) {
59                 usage();
60                 exit(-1);
61         }
63         Card card(dev_path);
65         vector<Connector*> conns;
67         if (conn_strs.size() > 0) {
68                 for (string s : conn_strs) {
69                         auto c = resolve_connector(card, 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();