summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2016-06-03 19:42:47 +0300
committerTomi Valkeinen <tomi.valkeinen@ti.com>2016-06-07 17:01:54 +0300
commitba5ae9472e88e28b47a8564972f98891694df7c2 (patch)
tree92db80b96cfe28f996408fa92abb5e0fde54d136 /utils
parentdce7c0afa22ca6568bbf6cca6a9cd669ef8b4b28 (diff)
add kmsblank app
Diffstat (limited to 'utils')
-rw-r--r--utils/CMakeLists.txt3
-rw-r--r--utils/kmsblank.cpp104
2 files changed, 107 insertions, 0 deletions
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index 232c674..27e4bec 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -15,3 +15,6 @@ target_link_libraries(fbtestpat kms++util)
add_executable (kmscapture kmscapture.cpp)
target_link_libraries(kmscapture kms++ kms++util ${LIBDRM_LIBRARIES})
+
+add_executable (kmsblank kmsblank.cpp)
+target_link_libraries(kmsblank kms++ kms++util ${LIBDRM_LIBRARIES})
diff --git a/utils/kmsblank.cpp b/utils/kmsblank.cpp
new file mode 100644
index 0000000..8b883bb
--- /dev/null
+++ b/utils/kmsblank.cpp
@@ -0,0 +1,104 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <algorithm>
+
+#include <kms++.h>
+#include <kms++util.h>
+#include "opts.h"
+
+using namespace std;
+using namespace kms;
+
+static const char* usage_str =
+ "Usage: kmsblank [OPTION]...\n\n"
+ "Blank screen(s)\n\n"
+ "Options:\n"
+ " --device=DEVICE DEVICE is the path to DRM card to open\n"
+ " -c, --connector=CONN CONN is <connector>\n"
+ " -t, --time=TIME blank/unblank in TIME intervals\n"
+ "\n"
+ "<connector> can be given by index (<idx>) or id (@<id>).\n"
+ "<connector> can also be given by name.\n"
+ ;
+
+static void usage()
+{
+ puts(usage_str);
+}
+
+int main(int argc, char **argv)
+{
+ string dev_path = "/dev/dri/card0";
+
+ vector<string> conn_strs;
+ uint32_t time = 0;
+
+ OptionSet optionset = {
+ Option("|device=", [&dev_path](string s)
+ {
+ dev_path = s;
+ }),
+ Option("c|connector=", [&conn_strs](string str)
+ {
+ conn_strs.push_back(str);
+ }),
+ Option("t|time=", [&time](string str)
+ {
+ time = stoul(str);
+ }),
+ Option("h|help", []()
+ {
+ usage();
+ exit(-1);
+ }),
+ };
+
+ optionset.parse(argc, argv);
+
+ if (optionset.params().size() > 0) {
+ usage();
+ exit(-1);
+ }
+
+ Card card(dev_path);
+
+ vector<Connector*> conns;
+
+ if (conn_strs.size() > 0) {
+ for (string s : conn_strs) {
+ auto c = resolve_connector(card, s);
+ if (!c)
+ EXIT("Failed to resolve connector '%s'", s.c_str());
+ conns.push_back(c);
+ }
+ } else {
+ conns = card.get_connectors();
+ }
+
+ bool blank = true;
+
+ while (true) {
+ for (Connector* conn : conns) {
+ if (!conn->connected()) {
+ printf("Connector %u not connected\n", conn->idx());
+ continue;
+ }
+
+ printf("Connector %u: %sblank\n", conn->idx(), blank ? "" : "un");
+ int r = conn->set_prop_value("DPMS", blank ? 3 : 0);
+ if (r)
+ EXIT("Failed to set DPMS: %d", r);
+ }
+
+ if (time == 0)
+ break;
+
+ usleep(1000 * time);
+
+ blank = !blank;
+ }
+
+ printf("press enter to exit\n");
+
+ getchar();
+}