From patchwork Wed Oct 16 11:51:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Elder X-Patchwork-Id: 21641 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id E3A94C326C for ; Wed, 16 Oct 2024 11:51:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A606C65383; Wed, 16 Oct 2024 13:51:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="G4vLW2g2"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 429616537E for ; Wed, 16 Oct 2024 13:51:44 +0200 (CEST) Received: from neptunite.flets-east.jp (unknown [IPv6:2404:7a81:160:2100:b5b2:fcb4:385e:af78]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D0483A57; Wed, 16 Oct 2024 13:50:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1729079401; bh=O40L6TO6S8rmwUsuRold0X3uyhw/9wQJBT1jU0tbeAY=; h=From:To:Cc:Subject:Date:From; b=G4vLW2g2nCnFcLAVSv7UUaDpGUGZmRfQDt/GMJaDXoUKyFrgro2Rf6qXshdIH6PV3 +7LtzfI/TZ0qcs3cNOGRJ6ZQmbe1LEQV17Mc85FDjmOCzGizqvYuMlyWpnw006SdLp 4m7gKeIwc4s6VSBOY4ern3np+nmDxt25ot7jZKYs= From: Paul Elder To: libcamera-devel@lists.libcamera.org Cc: Paul Elder Subject: [PATCH v2] py: Add bindings for ControlId array information Date: Wed, 16 Oct 2024 20:51:30 +0900 Message-Id: <20241016115130.1508308-1-paul.elder@ideasonboard.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add python bindings for querying whether or not a ControlId is an array type, and the size. Example usage: >>> cid libcamera.ControlId(28, FrameDurationLimits[2], ControlType.Integer64) >>> cid.isArray True >>> cid.size 2 Signed-off-by: Paul Elder Reviewed-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- Changes in v2: - add size to __repr__ --- src/py/libcamera/py_main.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp index 983b76f6e998..cbde8be16d43 100644 --- a/src/py/libcamera/py_main.cpp +++ b/src/py/libcamera/py_main.cpp @@ -7,6 +7,7 @@ #include "py_main.h" +#include #include #include #include @@ -400,10 +401,22 @@ PYBIND11_MODULE(_libcamera, m) .def_property_readonly("id", &ControlId::id) .def_property_readonly("name", &ControlId::name) .def_property_readonly("type", &ControlId::type) + .def_property_readonly("isArray", &ControlId::isArray) + .def_property_readonly("size", &ControlId::size) .def("__str__", [](const ControlId &self) { return self.name(); }) .def("__repr__", [](const ControlId &self) { - return py::str("libcamera.ControlId({}, {}, {})") - .format(self.id(), self.name(), self.type()); + std::string sizeStr = ""; + if (self.isArray()) { + sizeStr = "["; + size_t size = self.size(); + if (size == std::numeric_limits::max()) + sizeStr += "n"; + else + sizeStr += std::to_string(size); + sizeStr += "]"; + } + return py::str("libcamera.ControlId({}, {}{}, {})") + .format(self.id(), self.name(), sizeStr, self.type()); }) .def("enumerators", &ControlId::enumerators);