summaryrefslogtreecommitdiff
path: root/src/py
diff options
context:
space:
mode:
Diffstat (limited to 'src/py')
-rwxr-xr-xsrc/py/libcamera/gen-py-controls.py32
-rw-r--r--src/py/libcamera/meson.build6
2 files changed, 20 insertions, 18 deletions
diff --git a/src/py/libcamera/gen-py-controls.py b/src/py/libcamera/gen-py-controls.py
index 8efbf95b..a18dc533 100755
--- a/src/py/libcamera/gen-py-controls.py
+++ b/src/py/libcamera/gen-py-controls.py
@@ -8,6 +8,8 @@ import string
import sys
import yaml
+from controls import Control
+
def find_common_prefix(strings):
prefix = strings[0]
@@ -28,9 +30,7 @@ def generate_py(controls, mode):
vendor_defs = []
vendors = []
for vendor, ctrl_list in controls.items():
- for ctrls in ctrl_list:
- name, ctrl = ctrls.popitem()
-
+ for ctrl in ctrl_list:
if vendor not in vendors and vendor != 'libcamera':
vendor_mode_str = f'{vendor.capitalize()}{mode.capitalize()}'
vendors_class_def.append('class Py{}\n{{\n}};\n'.format(vendor_mode_str))
@@ -44,29 +44,28 @@ def generate_py(controls, mode):
ns = 'libcamera::{}::'.format(mode)
container = 'controls'
- out += f'\t{container}.def_readonly_static("{name}", static_cast<const libcamera::ControlId *>(&{ns}{name}));\n\n'
+ out += f'\t{container}.def_readonly_static("{ctrl.name}", static_cast<const libcamera::ControlId *>(&{ns}{ctrl.name}));\n\n'
- enum = ctrl.get('enum')
- if not enum:
+ if not ctrl.is_enum:
continue
- cpp_enum = name + 'Enum'
+ cpp_enum = ctrl.name + 'Enum'
out += '\tpy::enum_<{}{}>({}, \"{}\")\n'.format(ns, cpp_enum, container, cpp_enum)
if mode == 'controls':
# Adjustments for controls
- if name == 'LensShadingMapMode':
+ if ctrl.name == 'LensShadingMapMode':
prefix = 'LensShadingMapMode'
else:
- prefix = find_common_prefix([e['name'] for e in enum])
+ prefix = find_common_prefix([e.name for e in ctrl.enum_values])
else:
# Adjustments for properties
- prefix = find_common_prefix([e['name'] for e in enum])
+ prefix = find_common_prefix([e.name for e in ctrl.enum_values])
- for entry in enum:
- cpp_enum = entry['name']
- py_enum = entry['name'][len(prefix):]
+ for entry in ctrl.enum_values:
+ cpp_enum = entry.name
+ py_enum = entry.name[len(prefix):]
out += '\t\t.value(\"{}\", {}{})\n'.format(py_enum, ns, cpp_enum)
@@ -103,9 +102,10 @@ def main(argv):
controls = {}
for input in args.input:
- data = open(input, 'rb').read()
- vendor = yaml.safe_load(data)['vendor']
- controls[vendor] = yaml.safe_load(data)['controls']
+ data = yaml.safe_load(open(input, 'rb').read())
+ vendor = data['vendor']
+ ctrls = data['controls']
+ controls[vendor] = [Control(*ctrl.popitem(), vendor) for ctrl in ctrls]
data = generate_py(controls, args.mode)
diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build
index 2e674075..6ad2d771 100644
--- a/src/py/libcamera/meson.build
+++ b/src/py/libcamera/meson.build
@@ -35,7 +35,8 @@ pycamera_sources += custom_target('py_gen_controls',
input : controls_files,
output : ['py_controls_generated.cpp'],
command : [gen_py_controls, '--mode', 'controls', '-o', '@OUTPUT@',
- '-t', gen_py_controls_template, '@INPUT@'])
+ '-t', gen_py_controls_template, '@INPUT@'],
+ env : py_build_env)
# Generate properties
@@ -45,7 +46,8 @@ pycamera_sources += custom_target('py_gen_properties',
input : properties_files,
output : ['py_properties_generated.cpp'],
command : [gen_py_controls, '--mode', 'properties', '-o', '@OUTPUT@',
- '-t', gen_py_properties_template, '@INPUT@'])
+ '-t', gen_py_properties_template, '@INPUT@'],
+ env : py_build_env)
# Generate formats