[libcamera-devel] [PATCH v5 10/13] py: Add hotplug-monitor.py
Tomi Valkeinen
tomi.valkeinen at ideasonboard.com
Sat Jun 3 09:56:12 CEST 2023
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 100755 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 100755
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())
--
2.34.1
More information about the libcamera-devel
mailing list