diff mbox series

v4l2-ctl: Add --get/--set-ctrl support for INTEGER and INTEGER64 arrays

Message ID 20230525133559.211048-1-dlp@qtec.com
State New
Headers show
Series v4l2-ctl: Add --get/--set-ctrl support for INTEGER and INTEGER64 arrays | expand

Commit Message

Daniel Lundberg Pedersen May 25, 2023, 1:35 p.m. UTC
Add support for INTEGER and INTEGER64 arrays.

Also print error if trying to print unkown array type

Signed-off-by: Daniel Lundberg Pedersen <dlp@qtec.com>
---
NOTE: This patch depends on the fixed pointer types for p_s32 and p_s64
from this patch:
https://lore.kernel.org/linux-media/20230501145707.4088026-2-dlp@qtec.com/

 utils/v4l2-ctl/v4l2-ctl-common.cpp | 34 +++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

--
2.38.5

Comments

Daniel Lundberg Pedersen Aug. 15, 2023, 2:34 p.m. UTC | #1
Hi

Gentle ping Hans

Regards Daniel

On 25/05/2023 15:35, Daniel Lundberg Pedersen wrote:
> Add support for INTEGER and INTEGER64 arrays.
> 
> Also print error if trying to print unkown array type
> 
> Signed-off-by: Daniel Lundberg Pedersen <dlp@qtec.com>
> ---
> NOTE: This patch depends on the fixed pointer types for p_s32 and p_s64
> from this patch:
> https://lore.kernel.org/linux-media/20230501145707.4088026-2-dlp@qtec.com/
> 
>  utils/v4l2-ctl/v4l2-ctl-common.cpp | 34 +++++++++++++++++++++++++++++-
>  1 file changed, 33 insertions(+), 1 deletion(-)
> 
> diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp b/utils/v4l2-ctl/v4l2-ctl-common.cpp
> index a1cc93c825c8..d753f64d8e30 100644
> --- a/utils/v4l2-ctl/v4l2-ctl-common.cpp
> +++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp
> @@ -472,6 +472,26 @@ static void print_array(const v4l2_query_ext_ctrl &qc, const v4l2_ext_control &c
>  			}
>  			printf("\n");
>  			break;
> +		case V4L2_CTRL_TYPE_INTEGER:
> +			for (i = from; i <= to; i++) {
> +				printf("%10i", ctrl.p_s32[idx + i]);
> +				if (i < to)
> +					printf(", ");
> +			}
> +			printf("\n");
> +			break;
> +		case V4L2_CTRL_TYPE_INTEGER64:
> +			for (i = from; i <= to; i++) {
> +				printf("%12lli", ctrl.p_s64[idx + i]);
> +				if (i < to)
> +					printf(", ");
> +			}
> +			printf("\n");
> +			break;
> +		default:
> +			fprintf(stderr, "%s: unsupported array type\n",
> +					qc.name);
> +			break;
>  		}
>  	}
>  }
> @@ -1149,6 +1169,18 @@ void common_set(cv4l_fd &_fd)
>  						if (idx_in_subset(qc, subset, divide, i))
>  							ctrl.p_u32[i] = v;
>  					break;
> +				case V4L2_CTRL_TYPE_INTEGER:
> +					v = strtol(set_ctrl.second.c_str(), nullptr, 0);
> +					for (i = 0; i < qc.elems; i++)
> +						if (idx_in_subset(qc, subset, divide, i))
> +							ctrl.p_s32[i] = v;
> +					break;
> +				case V4L2_CTRL_TYPE_INTEGER64:
> +					v = strtol(set_ctrl.second.c_str(), nullptr, 0);
> +					for (i = 0; i < qc.elems; i++)
> +						if (idx_in_subset(qc, subset, divide, i))
> +							ctrl.p_s64[i] = v;
> +					break;
>  				case V4L2_CTRL_TYPE_STRING:
>  					strncpy(ctrl.string, set_ctrl.second.c_str(), qc.maximum);
>  					ctrl.string[qc.maximum] = 0;
> --
> 2.38.5
>
diff mbox series

Patch

diff --git a/utils/v4l2-ctl/v4l2-ctl-common.cpp b/utils/v4l2-ctl/v4l2-ctl-common.cpp
index a1cc93c825c8..d753f64d8e30 100644
--- a/utils/v4l2-ctl/v4l2-ctl-common.cpp
+++ b/utils/v4l2-ctl/v4l2-ctl-common.cpp
@@ -472,6 +472,26 @@  static void print_array(const v4l2_query_ext_ctrl &qc, const v4l2_ext_control &c
 			}
 			printf("\n");
 			break;
+		case V4L2_CTRL_TYPE_INTEGER:
+			for (i = from; i <= to; i++) {
+				printf("%10i", ctrl.p_s32[idx + i]);
+				if (i < to)
+					printf(", ");
+			}
+			printf("\n");
+			break;
+		case V4L2_CTRL_TYPE_INTEGER64:
+			for (i = from; i <= to; i++) {
+				printf("%12lli", ctrl.p_s64[idx + i]);
+				if (i < to)
+					printf(", ");
+			}
+			printf("\n");
+			break;
+		default:
+			fprintf(stderr, "%s: unsupported array type\n",
+					qc.name);
+			break;
 		}
 	}
 }
@@ -1149,6 +1169,18 @@  void common_set(cv4l_fd &_fd)
 						if (idx_in_subset(qc, subset, divide, i))
 							ctrl.p_u32[i] = v;
 					break;
+				case V4L2_CTRL_TYPE_INTEGER:
+					v = strtol(set_ctrl.second.c_str(), nullptr, 0);
+					for (i = 0; i < qc.elems; i++)
+						if (idx_in_subset(qc, subset, divide, i))
+							ctrl.p_s32[i] = v;
+					break;
+				case V4L2_CTRL_TYPE_INTEGER64:
+					v = strtol(set_ctrl.second.c_str(), nullptr, 0);
+					for (i = 0; i < qc.elems; i++)
+						if (idx_in_subset(qc, subset, divide, i))
+							ctrl.p_s64[i] = v;
+					break;
 				case V4L2_CTRL_TYPE_STRING:
 					strncpy(ctrl.string, set_ctrl.second.c_str(), qc.maximum);
 					ctrl.string[qc.maximum] = 0;