@@ -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 */
new file mode 100644
@@ -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}
+}