py: Generate bindings for properties
Generate bindings for properties in a very similar way as done for controls. We do need to distinguish between the two, and thus I added --properties flag to gen-py-controls.py. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
7a0a464dd1
commit
a69b73cc58
4 changed files with 65 additions and 10 deletions
|
@ -21,17 +21,17 @@ def find_common_prefix(strings):
|
|||
return prefix
|
||||
|
||||
|
||||
def generate_py(controls):
|
||||
def generate_py(controls, mode):
|
||||
out = ''
|
||||
|
||||
for ctrl in controls:
|
||||
name, ctrl = ctrl.popitem()
|
||||
|
||||
if ctrl.get('draft'):
|
||||
ns = 'libcamera::controls::draft::'
|
||||
ns = 'libcamera::{}::draft::'.format(mode)
|
||||
container = 'draft'
|
||||
else:
|
||||
ns = 'libcamera::controls::'
|
||||
ns = 'libcamera::{}::'.format(mode)
|
||||
container = 'controls'
|
||||
|
||||
out += f'\t{container}.def_readonly_static("{name}", static_cast<const libcamera::ControlId *>(&{ns}{name}));\n\n'
|
||||
|
@ -44,12 +44,17 @@ def generate_py(controls):
|
|||
|
||||
out += '\tpy::enum_<{}{}>({}, \"{}\")\n'.format(ns, cpp_enum, container, cpp_enum)
|
||||
|
||||
if name == 'LensShadingMapMode':
|
||||
prefix = 'LensShadingMapMode'
|
||||
elif name == 'SceneFlicker':
|
||||
# If we strip the prefix, we would get '50Hz', which is illegal name
|
||||
prefix = ''
|
||||
if mode == 'controls':
|
||||
# Adjustments for controls
|
||||
if name == 'LensShadingMapMode':
|
||||
prefix = 'LensShadingMapMode'
|
||||
elif name == 'SceneFlicker':
|
||||
# If we strip the prefix, we would get '50Hz', which is illegal name
|
||||
prefix = ''
|
||||
else:
|
||||
prefix = find_common_prefix([e['name'] for e in enum])
|
||||
else:
|
||||
# Adjustments for properties
|
||||
prefix = find_common_prefix([e['name'] for e in enum])
|
||||
|
||||
for entry in enum:
|
||||
|
@ -79,12 +84,18 @@ def main(argv):
|
|||
help='Input file name.')
|
||||
parser.add_argument('template', type=str,
|
||||
help='Template file name.')
|
||||
parser.add_argument('--mode', type=str, required=True,
|
||||
help='Mode is either "controls" or "properties"')
|
||||
args = parser.parse_args(argv[1:])
|
||||
|
||||
if args.mode not in ['controls', 'properties']:
|
||||
print(f'Invalid mode option "{args.mode}"', file=sys.stderr)
|
||||
return -1
|
||||
|
||||
data = open(args.input, 'rb').read()
|
||||
controls = yaml.safe_load(data)['controls']
|
||||
|
||||
data = generate_py(controls)
|
||||
data = generate_py(controls, args.mode)
|
||||
|
||||
data = fill_template(args.template, data)
|
||||
|
||||
|
|
|
@ -30,7 +30,19 @@ gen_py_controls = files('gen-py-controls.py')
|
|||
pycamera_sources += custom_target('py_gen_controls',
|
||||
input : gen_py_controls_input_files,
|
||||
output : ['py_controls_generated.cpp'],
|
||||
command : [gen_py_controls, '-o', '@OUTPUT@', '@INPUT@'])
|
||||
command : [gen_py_controls, '--mode', 'controls', '-o', '@OUTPUT@', '@INPUT@'])
|
||||
|
||||
# Generate properties
|
||||
|
||||
gen_py_property_enums_input_files = files([
|
||||
'../../libcamera/property_ids.yaml',
|
||||
'py_properties_generated.cpp.in',
|
||||
])
|
||||
|
||||
pycamera_sources += custom_target('py_gen_properties',
|
||||
input : gen_py_property_enums_input_files,
|
||||
output : ['py_properties_generated.cpp'],
|
||||
command : [gen_py_controls, '--mode', 'properties', '-o', '@OUTPUT@', '@INPUT@'])
|
||||
|
||||
# Generate formats
|
||||
|
||||
|
|
|
@ -130,12 +130,14 @@ void init_py_enums(py::module &m);
|
|||
void init_py_controls_generated(py::module &m);
|
||||
void init_py_formats_generated(py::module &m);
|
||||
void init_py_geometry(py::module &m);
|
||||
void init_py_properties_generated(py::module &m);
|
||||
|
||||
PYBIND11_MODULE(_libcamera, m)
|
||||
{
|
||||
init_py_enums(m);
|
||||
init_py_controls_generated(m);
|
||||
init_py_geometry(m);
|
||||
init_py_properties_generated(m);
|
||||
|
||||
/* Forward declarations */
|
||||
|
||||
|
|
30
src/py/libcamera/py_properties_generated.cpp.in
Normal file
30
src/py/libcamera/py_properties_generated.cpp.in
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2022, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
|
||||
*
|
||||
* Python bindings - Auto-generated properties
|
||||
*
|
||||
* This file is auto-generated. Do not edit.
|
||||
*/
|
||||
|
||||
#include <libcamera/property_ids.h>
|
||||
|
||||
#include <pybind11/smart_holder.h>
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
class PyProperties
|
||||
{
|
||||
};
|
||||
|
||||
class PyDraftProperties
|
||||
{
|
||||
};
|
||||
|
||||
void init_py_properties_generated(py::module& m)
|
||||
{
|
||||
auto controls = py::class_<PyProperties>(m, "properties");
|
||||
auto draft = py::class_<PyDraftProperties>(controls, "draft");
|
||||
|
||||
${controls}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue