[libcamera-devel] [PATCH v3 02/10] libcamera: controls: Parse 'enum' in gen-controls.py

Niklas Söderlund niklas.soderlund at ragnatech.se
Mon Dec 9 18:25:58 CET 2019


Hi Jacopo,

Thanks for your work.

On 2019-12-09 17:34:38 +0100, Jacopo Mondi wrote:
> In preparation to add libcamera Camera properties definitions by re-using
> the control generation framework, augment the gen_controls.py script to
> support parsing the 'enum' yaml tag and generate documentation and
> definition of possible values associated with a Control or a Property
> and defined through an enumeration of supported values.
> 
> Signed-off-by: Jacopo Mondi <jacopo at jmondi.org>

Reviewed-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>

> ---
>  src/libcamera/gen-controls.py | 41 +++++++++++++++++++++++++++++++++++
>  1 file changed, 41 insertions(+)
> 
> diff --git a/src/libcamera/gen-controls.py b/src/libcamera/gen-controls.py
> index 940386cc68c8..4a1ee52cdb04 100755
> --- a/src/libcamera/gen-controls.py
> +++ b/src/libcamera/gen-controls.py
> @@ -17,6 +17,10 @@ def snake_case(s):
>  
>  
>  def generate_cpp(controls):
> +    enum_doc_start_template = string.Template('''/**
> + * \enum ${name}Values\n * Supported ${name} values\n\n''')
> +    enum_doc_value_template = string.Template(''' * \\var ${name}Values::${value}
> +${description}\n *\n''')
>      doc_template = string.Template('''/**
>   * \\var extern const Control<${type}> ${name}
>  ${description}
> @@ -42,6 +46,27 @@ ${description}
>              'id_name': id_name,
>          }
>  
> +        enum_doc = []
> +        try:
> +            enum = ctrl['enum']
> +            enum_doc += enum_doc_start_template.substitute(info)
> +
> +            for value in enum:
> +                enum_description = value['description'].strip('\n').split('\n')
> +                enum_description[0] = '\\brief ' + enum_description[0]
> +                enum_description = '\n'.join([' * ' + line for line in enum_description])
> +                value_info = {
> +                    'name' : name,
> +                    'value': list(value.keys())[0],
> +                    'description': enum_description,
> +                }
> +                enum_doc += enum_doc_value_template.substitute(value_info)
> +            enum_doc += " */"
> +            enum_doc = ''.join(enum_doc)
> +            ctrls_doc.append(enum_doc)
> +        except KeyError:
> +            pass
> +
>          ctrls_doc.append(doc_template.substitute(info))
>          ctrls_def.append(def_template.substitute(info))
>          ctrls_map.append('\t{ ' + id_name + ', &' + name + ' },')
> @@ -54,6 +79,8 @@ ${description}
>  
>  
>  def generate_h(controls):
> +    enum_template_start = string.Template('''enum ${name}Values {''')
> +    enum_value_template = string.Template('''\t${name} = ${value},''')
>      template = string.Template('''extern const Control<${type}> ${name};''')
>  
>      ctrls = []
> @@ -71,6 +98,20 @@ def generate_h(controls):
>              'type': ctrl['type'],
>          }
>  
> +        try:
> +            enum = ctrl['enum']
> +            ctrls.append(enum_template_start.substitute(info))
> +
> +            for value in enum:
> +                value_info = {
> +                    'name': list(value.keys())[0],
> +                    'value': value['value'],
> +                }
> +                ctrls.append(enum_value_template.substitute(value_info))
> +            ctrls.append("};")
> +        except KeyError:
> +            pass
> +
>          ctrls.append(template.substitute(info))
>          id_value += 1
>  
> -- 
> 2.24.0
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel at lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

-- 
Regards,
Niklas Söderlund


More information about the libcamera-devel mailing list