[libcamera-devel] [PATCH v3 17/17] py: Add hotplug-monitor.py
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Thu Aug 18 23:06:59 CEST 2022
Hi Tomi,
Thank you for the patch.
On Fri, Jul 01, 2022 at 11:45:21AM +0300, Tomi Valkeinen wrote:
> Add a simple example script which waits for camera hotplug events.
>
> Signed-off-by: Tomi Valkeinen <tomi.valkeinen at ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> ---
> src/py/examples/hotplug-monitor.py | 39 ++++++++++++++++++++++++++++++
> 1 file changed, 39 insertions(+)
> create mode 100644 src/py/examples/hotplug-monitor.py
>
> diff --git a/src/py/examples/hotplug-monitor.py b/src/py/examples/hotplug-monitor.py
> new file mode 100644
> index 00000000..5f42970c
> --- /dev/null
> +++ b/src/py/examples/hotplug-monitor.py
> @@ -0,0 +1,39 @@
> +#!/usr/bin/env python3
> +
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +# Copyright (C) 2022, Tomi Valkeinen <tomi.valkeinen at ideasonboard.com>
> +
> +import libcamera as libcam
> +import selectors
> +import sys
> +
> +
> +def main():
> + cm = libcam.CameraManager.singleton()
> +
> + sel = selectors.DefaultSelector()
> + sel.register(cm.event_fd, selectors.EVENT_READ)
> +
> + print('Waiting for camera hotplug events... (CTRL-C to exit)')
> +
> + while True:
> + try:
> + events = sel.select()
> + if not events:
> + continue
> + except KeyboardInterrupt:
> + break
> +
> + events = cm.get_events()
> +
> + for ev in events:
> + if ev.type == libcam.Event.Type.CameraAdded:
> + print('Camera added:', ev.camera)
> + elif ev.type == libcam.Event.Type.CameraRemoved:
> + print('Camera removed:', ev.camera)
> +
> + return 0
> +
> +
> +if __name__ == '__main__':
> + sys.exit(main())
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list