From patchwork Sat Dec 29 03:31:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Niklas_S=C3=B6derlund?= X-Patchwork-Id: 108 Return-Path: Received: from bin-mail-out-05.binero.net (bin-mail-out-05.binero.net [195.74.38.228]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CBAF260B31 for ; Sat, 29 Dec 2018 04:31:42 +0100 (CET) X-Halon-ID: 37df51c5-0b1a-11e9-911a-0050569116f7 Authorized-sender: niklas@soderlund.pp.se Received: from bismarck.berto.se (unknown [89.233.230.99]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id 37df51c5-0b1a-11e9-911a-0050569116f7; Sat, 29 Dec 2018 04:31:30 +0100 (CET) From: =?utf-8?q?Niklas_S=C3=B6derlund?= To: libcamera-devel@lists.libcamera.org Date: Sat, 29 Dec 2018 04:31:34 +0100 Message-Id: <20181229033134.26927-1-niklas.soderlund@ragnatech.se> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] cam-ctl: add utility to control cameras X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Dec 2018 03:31:43 -0000 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 --- 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 +#include +#include +#include + +#include + +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 " << 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')