summaryrefslogtreecommitdiff
path: root/src/py
diff options
context:
space:
mode:
Diffstat (limited to 'src/py')
-rwxr-xr-xsrc/py/libcamera/gen-py-controls.py29
-rw-r--r--src/py/libcamera/meson.build14
-rw-r--r--src/py/libcamera/py_main.cpp2
-rw-r--r--src/py/libcamera/py_properties_generated.cpp.in30
4 files changed, 65 insertions, 10 deletions
diff --git a/src/py/libcamera/gen-py-controls.py b/src/py/libcamera/gen-py-controls.py
index 4c072e60..99f3bbcf 100755
--- a/src/py/libcamera/gen-py-controls.py
+++ b/src/py/libcamera/gen-py-controls.py
@@ -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)
diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build
index e8010846..afa7efed 100644
--- a/src/py/libcamera/meson.build
+++ b/src/py/libcamera/meson.build
@@ -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
diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp
index f903f1d2..3220a9e6 100644
--- a/src/py/libcamera/py_main.cpp
+++ b/src/py/libcamera/py_main.cpp
@@ -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 */
diff --git a/src/py/libcamera/py_properties_generated.cpp.in b/src/py/libcamera/py_properties_generated.cpp.in
new file mode 100644
index 00000000..044b2b2a
--- /dev/null
+++ b/src/py/libcamera/py_properties_generated.cpp.in
@@ -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}
+}