new file mode 100644
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2022, Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
+
+import libcamera as libcam
+import selectors
+import sys
+
+
+def main():
+ cm = libcam.CameraManager.singleton()
+
+ cm.camera_added = lambda c: print('Camera added:', c)
+ cm.camera_removed = lambda c: print('Camera removed:', c)
+
+ 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
+
+ cm.dispatch_events()
+
+ cm.discard_events()
+
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())
Add a simple example script which waits for camera hotplug events. Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> --- src/py/examples/hotplug-monitor.py | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/py/examples/hotplug-monitor.py