[libcamera-devel] [PATCH v2 14/14] py: Add hotplug-monitor.py
Tomi Valkeinen
tomi.valkeinen at ideasonboard.com
Wed Jun 29 09:04:16 CEST 2022
Add a simple example script which waits for camera hotplug events.
Signed-off-by: Tomi Valkeinen <tomi.valkeinen at ideasonboard.com>
---
src/py/examples/hotplug-monitor.py | 38 ++++++++++++++++++++++++++++++
1 file changed, 38 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..787aa45a
--- /dev/null
+++ b/src/py/examples/hotplug-monitor.py
@@ -0,0 +1,38 @@
+#!/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()
+
+ 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())
--
2.34.1
More information about the libcamera-devel
mailing list