[libcamera-devel] [PATCH] cam-ctl: add utility to control cameras

Niklas Söderlund niklas.soderlund at ragnatech.se
Sat Dec 29 04:31:34 CET 2018


Provide a utility to interact with cameras. This initial state is
limited and only supports listing cameras in the system and selecting a
camera to interact with.

There is not much a interacting possible yet with a camera so the tool
simply exercise the API to get and put a camera.

Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
---
 src/cam-ctl/main.cpp    | 98 +++++++++++++++++++++++++++++++++++++++++
 src/cam-ctl/meson.build |  7 +++
 src/meson.build         |  1 +
 3 files changed, 106 insertions(+)
 create mode 100644 src/cam-ctl/main.cpp
 create mode 100644 src/cam-ctl/meson.build

---

Hi,

I'm not sure this is ready to be merged but I thought it good to share 
it on the ML to avoid redoing the work as more pieces come together.

diff --git a/src/cam-ctl/main.cpp b/src/cam-ctl/main.cpp
new file mode 100644
index 0000000000000000..0bf76cef3efc8741
--- /dev/null
+++ b/src/cam-ctl/main.cpp
@@ -0,0 +1,98 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2018, Google Inc.
+ *
+ * main.cpp - cam-ctl a tool to interact with the library
+ */
+
+#include <getopt.h>
+#include <iostream>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <libcamera/libcamera.h>
+
+using namespace std;
+using namespace libcamera;
+
+enum Option {
+	OptCamera = 1,
+	OptList,
+	OptLast,
+};
+
+static struct option long_options[] = {
+	{ "camera", required_argument, 0, 'c' },
+	{ "list", no_argument, 0, 'l' },
+};
+
+char options[OptLast];
+
+void usage()
+{
+	cout << "Options:" << endl;
+	cout << "  --camera <camera>" << endl;
+	cout << "  --list" << endl;
+}
+
+int main(int argc, char **argv)
+{
+	CameraManager *cm;
+	string camera;
+
+	if (argc == 1) {
+		usage();
+		return 0;
+	}
+
+	while (1) {
+		int c, option_index = 0;
+
+		c = getopt_long (argc, argv, "c:l", long_options, &option_index);
+
+		if (c == -1)
+			break;
+
+		switch (c) {
+		case 'c':
+			options[OptCamera] = 1;
+			camera = optarg;
+			break;
+		case 'l':
+			options[OptList] = 1;
+			break;
+		case '?':
+			break;
+		default:
+			abort();
+		}
+	}
+
+	cm = new CameraManager();
+	if (!cm)
+		return -ENOMEM;
+
+	cm->start();
+
+	if (options[OptList]) {
+		for (auto name : cm->list())
+			cout << "- " << name << endl;
+	}
+
+	if (options[OptCamera]) {
+		Camera *cam = cm->get(camera);
+
+		if (cam) {
+			cout << "Using camera: " << cam->name() << endl;
+			cam->put();
+		} else {
+			cout << "Can't find camera '" << camera << "'" << endl;
+		}
+	}
+
+	cm->stop();
+
+	delete cm;
+
+	return 0;
+}
diff --git a/src/cam-ctl/meson.build b/src/cam-ctl/meson.build
new file mode 100644
index 0000000000000000..7c27a19dae98fe96
--- /dev/null
+++ b/src/cam-ctl/meson.build
@@ -0,0 +1,7 @@
+cam_ctl_sources = files([
+    'main.cpp',
+])
+
+cam_ctl = executable('cam-ctl', cam_ctl_sources,
+                       link_with : libcamera,
+                       include_directories : libcamera_includes)
diff --git a/src/meson.build b/src/meson.build
index 4ce9668caa7b8997..86e5290e5e66eb68 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1 +1,2 @@
 subdir('libcamera')
+subdir('cam-ctl')
-- 
2.20.1



More information about the libcamera-devel mailing list