[libcamera-devel,2/2] cam: Add an option to list camera controls

Message ID 20200424234237.19604-2-laurent.pinchart@ideasonboard.com
State Accepted
Commit 175cd1061112992df9dee2c51f641d60a3d1705c
Headers show
Series
  • [libcamera-devel,1/2] cam: Rename OptProps to OptListProperties
Related show

Commit Message

Laurent Pinchart April 24, 2020, 11:42 p.m. UTC
Add a new --list-controls option to print information about all the
controls supported by a camera.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 src/cam/main.cpp | 28 ++++++++++++++++++++++++++++
 src/cam/main.h   |  1 +
 2 files changed, 29 insertions(+)

Comments

Jacopo Mondi April 26, 2020, 2:53 p.m. UTC | #1
Hi Laurent,

On Sat, Apr 25, 2020 at 02:42:37AM +0300, Laurent Pinchart wrote:
> Add a new --list-controls option to print information about all the
> controls supported by a camera.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  src/cam/main.cpp | 28 ++++++++++++++++++++++++++++
>  src/cam/main.h   |  1 +
>  2 files changed, 29 insertions(+)
>
> diff --git a/src/cam/main.cpp b/src/cam/main.cpp
> index 340849e74ddd..ced4f567b8f3 100644
> --- a/src/cam/main.cpp
> +++ b/src/cam/main.cpp
> @@ -37,6 +37,7 @@ public:
>  private:
>  	int parseOptions(int argc, char *argv[]);
>  	int prepareConfig();
> +	int listControls();
>  	int listProperties();
>  	int infoConfiguration();
>  	int run();
> @@ -182,6 +183,8 @@ int CamApp::parseOptions(int argc, char *argv[])
>  	parser.addOption(OptInfo, OptionNone,
>  			 "Display information about stream(s)", "info");
>  	parser.addOption(OptList, OptionNone, "List all cameras", "list");
> +	parser.addOption(OptListControls, OptionNone, "List cameras controls",
> +			 "list-controls");
>  	parser.addOption(OptListProperties, OptionNone, "List cameras properties",
>  			 "list-properties");
>
> @@ -276,6 +279,25 @@ int CamApp::prepareConfig()
>  	return 0;
>  }
>
> +int CamApp::listControls()
> +{
> +	if (!camera_) {
> +		std::cout << "Cannot list controls without a camera"
> +			  << std::endl;
> +		return -EINVAL;
> +	}
> +
> +	for (const auto &ctrl : camera_->controls()) {
> +		const ControlId *id = ctrl.first;
> +		const ControlInfo &info = ctrl.second;
> +
> +		std::cout << "Control: " << id->name() << ": "
> +			  << info.toString() << std::endl;
> +	}
> +
> +	return 0;
> +}
> +
>  int CamApp::listProperties()
>  {
>  	if (!camera_) {
> @@ -339,6 +361,12 @@ int CamApp::run()
>  		}
>  	}
>
> +	if (options_.isSet(OptListControls)) {
> +		ret = listControls();
> +		if (ret)
> +			return ret;
> +	}
> +
>  	if (options_.isSet(OptListProperties)) {
>  		ret = listProperties();
>  		if (ret)
> diff --git a/src/cam/main.h b/src/cam/main.h
> index d23c6dfb202e..4a130d8dd290 100644
> --- a/src/cam/main.h
> +++ b/src/cam/main.h
> @@ -16,6 +16,7 @@ enum {
>  	OptList = 'l',
>  	OptListProperties = 'p',
>  	OptStream = 's',
> +	OptListControls = 256,

Is this intentional as we don't have a short version of the
--list-controls option available ?

Apart from this, very useful
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
  j

>  };
>
>  #endif /* __CAM_MAIN_H__ */
> --
> Regards,
>
> Laurent Pinchart
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Laurent Pinchart April 26, 2020, 4:09 p.m. UTC | #2
Hi Jacopo,

On Sun, Apr 26, 2020 at 04:53:54PM +0200, Jacopo Mondi wrote:
> On Sat, Apr 25, 2020 at 02:42:37AM +0300, Laurent Pinchart wrote:
> > Add a new --list-controls option to print information about all the
> > controls supported by a camera.
> >
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  src/cam/main.cpp | 28 ++++++++++++++++++++++++++++
> >  src/cam/main.h   |  1 +
> >  2 files changed, 29 insertions(+)
> >
> > diff --git a/src/cam/main.cpp b/src/cam/main.cpp
> > index 340849e74ddd..ced4f567b8f3 100644
> > --- a/src/cam/main.cpp
> > +++ b/src/cam/main.cpp
> > @@ -37,6 +37,7 @@ public:
> >  private:
> >  	int parseOptions(int argc, char *argv[]);
> >  	int prepareConfig();
> > +	int listControls();
> >  	int listProperties();
> >  	int infoConfiguration();
> >  	int run();
> > @@ -182,6 +183,8 @@ int CamApp::parseOptions(int argc, char *argv[])
> >  	parser.addOption(OptInfo, OptionNone,
> >  			 "Display information about stream(s)", "info");
> >  	parser.addOption(OptList, OptionNone, "List all cameras", "list");
> > +	parser.addOption(OptListControls, OptionNone, "List cameras controls",
> > +			 "list-controls");
> >  	parser.addOption(OptListProperties, OptionNone, "List cameras properties",
> >  			 "list-properties");
> >
> > @@ -276,6 +279,25 @@ int CamApp::prepareConfig()
> >  	return 0;
> >  }
> >
> > +int CamApp::listControls()
> > +{
> > +	if (!camera_) {
> > +		std::cout << "Cannot list controls without a camera"
> > +			  << std::endl;
> > +		return -EINVAL;
> > +	}
> > +
> > +	for (const auto &ctrl : camera_->controls()) {
> > +		const ControlId *id = ctrl.first;
> > +		const ControlInfo &info = ctrl.second;
> > +
> > +		std::cout << "Control: " << id->name() << ": "
> > +			  << info.toString() << std::endl;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> >  int CamApp::listProperties()
> >  {
> >  	if (!camera_) {
> > @@ -339,6 +361,12 @@ int CamApp::run()
> >  		}
> >  	}
> >
> > +	if (options_.isSet(OptListControls)) {
> > +		ret = listControls();
> > +		if (ret)
> > +			return ret;
> > +	}
> > +
> >  	if (options_.isSet(OptListProperties)) {
> >  		ret = listProperties();
> >  		if (ret)
> > diff --git a/src/cam/main.h b/src/cam/main.h
> > index d23c6dfb202e..4a130d8dd290 100644
> > --- a/src/cam/main.h
> > +++ b/src/cam/main.h
> > @@ -16,6 +16,7 @@ enum {
> >  	OptList = 'l',
> >  	OptListProperties = 'p',
> >  	OptStream = 's',
> > +	OptListControls = 256,
> 
> Is this intentional as we don't have a short version of the
> --list-controls option available ?

Correct. It's a common practice to start option that have no short form
at 256 to avoid any clash (I'm sure we could start at 128 without any
problem, but 256 is guaranteed to be safe).

> Apart from this, very useful

Thanks.

> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> 
> >  };
> >
> >  #endif /* __CAM_MAIN_H__ */

Patch

diff --git a/src/cam/main.cpp b/src/cam/main.cpp
index 340849e74ddd..ced4f567b8f3 100644
--- a/src/cam/main.cpp
+++ b/src/cam/main.cpp
@@ -37,6 +37,7 @@  public:
 private:
 	int parseOptions(int argc, char *argv[]);
 	int prepareConfig();
+	int listControls();
 	int listProperties();
 	int infoConfiguration();
 	int run();
@@ -182,6 +183,8 @@  int CamApp::parseOptions(int argc, char *argv[])
 	parser.addOption(OptInfo, OptionNone,
 			 "Display information about stream(s)", "info");
 	parser.addOption(OptList, OptionNone, "List all cameras", "list");
+	parser.addOption(OptListControls, OptionNone, "List cameras controls",
+			 "list-controls");
 	parser.addOption(OptListProperties, OptionNone, "List cameras properties",
 			 "list-properties");
 
@@ -276,6 +279,25 @@  int CamApp::prepareConfig()
 	return 0;
 }
 
+int CamApp::listControls()
+{
+	if (!camera_) {
+		std::cout << "Cannot list controls without a camera"
+			  << std::endl;
+		return -EINVAL;
+	}
+
+	for (const auto &ctrl : camera_->controls()) {
+		const ControlId *id = ctrl.first;
+		const ControlInfo &info = ctrl.second;
+
+		std::cout << "Control: " << id->name() << ": "
+			  << info.toString() << std::endl;
+	}
+
+	return 0;
+}
+
 int CamApp::listProperties()
 {
 	if (!camera_) {
@@ -339,6 +361,12 @@  int CamApp::run()
 		}
 	}
 
+	if (options_.isSet(OptListControls)) {
+		ret = listControls();
+		if (ret)
+			return ret;
+	}
+
 	if (options_.isSet(OptListProperties)) {
 		ret = listProperties();
 		if (ret)
diff --git a/src/cam/main.h b/src/cam/main.h
index d23c6dfb202e..4a130d8dd290 100644
--- a/src/cam/main.h
+++ b/src/cam/main.h
@@ -16,6 +16,7 @@  enum {
 	OptList = 'l',
 	OptListProperties = 'p',
 	OptStream = 's',
+	OptListControls = 256,
 };
 
 #endif /* __CAM_MAIN_H__ */