[libcamera-devel] [PATCH v5 6/7] cam: Print user-friendly camera names

Umang Jain email at uajain.com
Mon Sep 28 14:57:29 CEST 2020


Hi Niklas,

On 9/25/20 8:37 PM, Niklas Söderlund wrote:
> Instead of only printing the camera ID which is not intended for humans
> to read and parse create a more user friendly string when printing
> camera names. The ID is still printed as it is one option used to select
> camera using the --camera option.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
> Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
LGTM.👍
Reviewed-by: Umang Jain <email at uajain.com>
> ---
> * Changes since v4
> - Make cameraName() member ofr CamApp.
>
> * Changes since v1
> - Only print user-friendly names when listing cameras.
> - Update format of user-friendly names printed.
> - Update commit message.
> ---
>   src/cam/main.cpp | 31 ++++++++++++++++++++++++++++++-
>   1 file changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/src/cam/main.cpp b/src/cam/main.cpp
> index 244720b491f5c462..ed56d06c9d3386b9 100644
> --- a/src/cam/main.cpp
> +++ b/src/cam/main.cpp
> @@ -45,6 +45,8 @@ private:
>   	int infoConfiguration();
>   	int run();
>   
> +	std::string cameraName(const Camera *camera);
> +
>   	static CamApp *app_;
>   	OptionsParser::Options options_;
>   	CameraManager *cm_;
> @@ -340,7 +342,7 @@ int CamApp::run()
>   
>   		unsigned int index = 1;
>   		for (const std::shared_ptr<Camera> &cam : cm_->cameras()) {
> -			std::cout << index << ": " << cam->id() << std::endl;
> +			std::cout << index << ": " << cameraName(cam.get()) << std::endl;
>   			index++;
>   		}
>   	}
> @@ -378,6 +380,33 @@ int CamApp::run()
>   	return 0;
>   }
>   
> +std::string CamApp::cameraName(const Camera *camera)
> +{
> +	const ControlList &props = camera->properties();
> +	std::string name;
> +
> +	if (props.contains(properties::Location)) {
> +		switch (props.get(properties::Location)) {
> +		case properties::CameraLocationFront:
> +			name = "Internal front camera";
> +			break;
> +		case properties::CameraLocationBack:
> +			name = "Internal back camera";
> +			break;
> +		case properties::CameraLocationExternal:
> +			name = "External camera";
> +			break;
> +		}
> +	}
> +
> +	if (props.contains(properties::Model))
> +		name += " " + props.get(properties::Model);
> +
> +	name += " (" + camera->id() + ")";
> +
> +	return name;
> +}
> +
>   void signalHandler([[maybe_unused]] int signal)
>   {
>   	std::cout << "Exiting" << std::endl;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20200928/2f1e09d1/attachment.htm>


More information about the libcamera-devel mailing list