[libcamera-devel] [PATCH] cam: Allow selecting cameras by index
Jacopo Mondi
jacopo at jmondi.org
Tue Jun 18 09:40:33 CEST 2019
Hi Laurent,
On Mon, Jun 17, 2019 at 01:09:10PM +0300, Laurent Pinchart wrote:
> As camera names can be cumbersome to type, selection of cameras by index
> from a list can be useful. Print the list of detected cameras with an
> index for each item, and interpret the camera name as an index if it is
> a numerical value in the range from 1 to the number of cameras.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo at jmondi.org>
and tested on IPU3 Soraka.
Thanks
j
> ---
> src/cam/main.cpp | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/src/cam/main.cpp b/src/cam/main.cpp
> index f03a9faf87fa..0e7610b1befd 100644
> --- a/src/cam/main.cpp
> +++ b/src/cam/main.cpp
> @@ -73,7 +73,14 @@ int CamApp::init(int argc, char **argv)
> }
>
> if (options_.isSet(OptCamera)) {
> - camera_ = cm_->get(options_[OptCamera]);
> + const std::string &cameraName = options_[OptCamera];
> + char *endptr;
> + unsigned long index = strtoul(cameraName.c_str(), &endptr, 10);
> + if (*endptr == '\0' && index > 0 && index <= cm_->cameras().size())
> + camera_ = cm_->cameras()[index - 1];
> + else
> + camera_ = cm_->get(cameraName);
> +
> if (!camera_) {
> std::cout << "Camera "
> << std::string(options_[OptCamera])
> @@ -172,8 +179,12 @@ int CamApp::run()
> {
> if (options_.isSet(OptList)) {
> std::cout << "Available cameras:" << std::endl;
> - for (const std::shared_ptr<Camera> &cam : cm_->cameras())
> - std::cout << "- " << cam->name() << std::endl;
> +
> + unsigned int index = 1;
> + for (const std::shared_ptr<Camera> &cam : cm_->cameras()) {
> + std::cout << index << ": " << cam->name() << std::endl;
> + index++;
> + }
> }
>
> if (options_.isSet(OptCapture)) {
> --
> Regards,
>
> Laurent Pinchart
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20190618/d9275c8b/attachment.sig>
More information about the libcamera-devel
mailing list