[v3,2/3] apps: cam: Print control enum values more nicely
diff mbox series

Message ID 20240911093600.671979-3-paul.elder@ideasonboard.com
State Superseded
Headers show
Series
  • libcamera: controls: Add enum information to ControlId
Related show

Commit Message

Paul Elder Sept. 11, 2024, 9:35 a.m. UTC
Now that enum names can be obtained from ControlId, use that information
to print out the list of supported enum values in --list-controls.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>

---
Changes in v3:
- s/enumName/enumToString/

No change in v2
---
 src/apps/cam/camera_session.cpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Laurent Pinchart Sept. 11, 2024, 4:10 p.m. UTC | #1
Hi Paul,

Thank you for the patch.

On Wed, Sep 11, 2024 at 11:35:59AM +0200, Paul Elder wrote:
> Now that enum names can be obtained from ControlId, use that information
> to print out the list of supported enum values in --list-controls.

An example of the new output (shortened to one control) would be nice
here.

> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
> 
> ---
> Changes in v3:
> - s/enumName/enumToString/
> 
> No change in v2
> ---
>  src/apps/cam/camera_session.cpp | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/src/apps/cam/camera_session.cpp b/src/apps/cam/camera_session.cpp
> index 097dc4792..37de6c9f3 100644
> --- a/src/apps/cam/camera_session.cpp
> +++ b/src/apps/cam/camera_session.cpp
> @@ -159,8 +159,16 @@ CameraSession::~CameraSession()
>  void CameraSession::listControls() const
>  {
>  	for (const auto &[id, info] : camera_->controls()) {
> -		std::cout << "Control: " << id->name() << ": "
> -			  << info.toString() << std::endl;
> +		if (info.values().size() == 0) {

		if (info.values().empty()) {

> +			std::cout << "Control: " << id->name() << ": "
> +				  << info.toString() << std::endl;
> +		} else {
> +			std::cout << "Control: " << id->name() << ": " << std::endl;

Extra space in ": ".

> +			for (const auto &value : info.values()) {
> +				int32_t val = value.get<int32_t>();
> +				std::cout << "  - " << id->enumToString(val) << " (" << val << ")" << std::endl;
> +			}
> +		}
>  	}
>  }
>
Laurent Pinchart Sept. 11, 2024, 4:12 p.m. UTC | #2
On Wed, Sep 11, 2024 at 07:10:01PM +0300, Laurent Pinchart wrote:
> Hi Paul,
> 
> Thank you for the patch.
> 
> On Wed, Sep 11, 2024 at 11:35:59AM +0200, Paul Elder wrote:
> > Now that enum names can be obtained from ControlId, use that information
> > to print out the list of supported enum values in --list-controls.
> 
> An example of the new output (shortened to one control) would be nice
> here.
> 
> > Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> > Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
> > 
> > ---
> > Changes in v3:
> > - s/enumName/enumToString/
> > 
> > No change in v2
> > ---
> >  src/apps/cam/camera_session.cpp | 12 ++++++++++--
> >  1 file changed, 10 insertions(+), 2 deletions(-)
> > 
> > diff --git a/src/apps/cam/camera_session.cpp b/src/apps/cam/camera_session.cpp
> > index 097dc4792..37de6c9f3 100644
> > --- a/src/apps/cam/camera_session.cpp
> > +++ b/src/apps/cam/camera_session.cpp
> > @@ -159,8 +159,16 @@ CameraSession::~CameraSession()
> >  void CameraSession::listControls() const
> >  {
> >  	for (const auto &[id, info] : camera_->controls()) {
> > -		std::cout << "Control: " << id->name() << ": "
> > -			  << info.toString() << std::endl;
> > +		if (info.values().size() == 0) {
> 
> 		if (info.values().empty()) {
> 
> > +			std::cout << "Control: " << id->name() << ": "
> > +				  << info.toString() << std::endl;
> > +		} else {
> > +			std::cout << "Control: " << id->name() << ": " << std::endl;
> 
> Extra space in ": ".
> 
> > +			for (const auto &value : info.values()) {

If you expose the whole map as proposed in the review of 1/3, you could
iterate over the enumerators map, that would be move efficient than
looking up each entry.

> > +				int32_t val = value.get<int32_t>();
> > +				std::cout << "  - " << id->enumToString(val) << " (" << val << ")" << std::endl;
> > +			}
> > +		}
> >  	}
> >  }
> >

Patch
diff mbox series

diff --git a/src/apps/cam/camera_session.cpp b/src/apps/cam/camera_session.cpp
index 097dc4792..37de6c9f3 100644
--- a/src/apps/cam/camera_session.cpp
+++ b/src/apps/cam/camera_session.cpp
@@ -159,8 +159,16 @@  CameraSession::~CameraSession()
 void CameraSession::listControls() const
 {
 	for (const auto &[id, info] : camera_->controls()) {
-		std::cout << "Control: " << id->name() << ": "
-			  << info.toString() << std::endl;
+		if (info.values().size() == 0) {
+			std::cout << "Control: " << id->name() << ": "
+				  << info.toString() << std::endl;
+		} else {
+			std::cout << "Control: " << id->name() << ": " << std::endl;
+			for (const auto &value : info.values()) {
+				int32_t val = value.get<int32_t>();
+				std::cout << "  - " << id->enumToString(val) << " (" << val << ")" << std::endl;
+			}
+		}
 	}
 }