From patchwork Wed Dec 4 13:20:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 2386 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C743961CC6 for ; Wed, 4 Dec 2019 14:21:20 +0100 (CET) Received: from uno.lan (93-34-114-233.ip49.fastwebnet.it [93.34.114.233]) (Authenticated sender: jacopo@jmondi.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 5A6B524000F; Wed, 4 Dec 2019 13:21:20 +0000 (UTC) From: Jacopo Mondi To: libcamera-devel@lists.libcamera.org Date: Wed, 4 Dec 2019 14:20:58 +0100 Message-Id: <20191204132106.21582-3-jacopo@jmondi.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191204132106.21582-1-jacopo@jmondi.org> References: <20191204132106.21582-1-jacopo@jmondi.org> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 02/10] libcamera: controls: Parse 'values' in gen-controls.py 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: , X-List-Received-Date: Wed, 04 Dec 2019 13:21:21 -0000 In preparation to add libcamera Camera definition by re-using the control generation framework, augment the gen_controls.py script to support parsing the 'values' yaml tag and generate documentation and definition of possible values associated with a Control or a Property. Signed-off-by: Jacopo Mondi --- src/libcamera/gen-controls.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/libcamera/gen-controls.py b/src/libcamera/gen-controls.py index 940386cc68c8..ca843cb9b538 100755 --- a/src/libcamera/gen-controls.py +++ b/src/libcamera/gen-controls.py @@ -11,6 +11,24 @@ import string import sys import yaml +class ValueGenerator: + doc_template = string.Template('''/** + * \\def ${name} + * \\brief ${description} */''') + def_template = string.Template('''#define ${name} ${value}''') + + def __init__(self, value): + self.info = { + 'name': value['name'], + 'value': value['value'], + 'description': value['description'] + } + + def generate_doc(self): + return self.doc_template.substitute(self.info) + + def generate_def(self): + return self.def_template.substitute(self.info) def snake_case(s): return ''.join([c.isupper() and ('_' + c) or c for c in s]).strip('_') @@ -35,14 +53,23 @@ ${description} description[0] = '\\brief ' + description[0] description = '\n'.join([(line and ' * ' or ' *') + line for line in description]) + try: + values = ctrl['values'] + except KeyError: + values = "" + info = { 'name': name, 'type': ctrl['type'], 'description': description, 'id_name': id_name, + 'values' : values, } + for v in values: + ctrls_doc.append(ValueGenerator(v).generate_doc()) ctrls_doc.append(doc_template.substitute(info)) + ctrls_def.append(def_template.substitute(info)) ctrls_map.append('\t{ ' + id_name + ', &' + name + ' },') @@ -66,11 +93,19 @@ def generate_h(controls): ids.append('\t' + id_name + ' = ' + str(id_value) + ',') + try: + values = ctrl['values'] + except KeyError: + values = "" + info = { 'name': name, 'type': ctrl['type'], + 'values' : values, } + for v in values: + ctrls.append(ValueGenerator(v).generate_def()) ctrls.append(template.substitute(info)) id_value += 1