From patchwork Fri Jul 1 08:45:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 16509 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 0B121BD808 for ; Fri, 1 Jul 2022 08:45:59 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B17AD656AC; Fri, 1 Jul 2022 10:45:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656665158; bh=COD1ICfp6x0GrWGYRioB2UOSOOeDG2n1CiaJWo9k4JI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=V1ZOyf7HyZRUFC7znqPbZdtm7Fy/eLz5Rfn8Au5WIs6Xm9qrfE74FtDiGiYFU/NHB Xfg71To2DcZAahLUgl+IOHq9G48vZD3bw1QHCkc2MZIwRG7CJt1BzpJFAimy60XKoW JJgoY8+/6co3NJq4/00bh7zXQjSHa6ky/pGST0uTA9//GA6nqETGdGBEngPydJakfl RCGcRZA6cRsIrgjEYNiHQccb3jHkVgCpfVasdqoe5aOArQ9AniJBYViMK6VvinOoxa KAV0QoY8eU8l5oI6Hv+XvNHKRA98NBnazIlZ/Diqg7RfHOfkmZIZUbOeA3xOtD4l93 /F4vXiVzPdt3A== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B17C365654 for ; Fri, 1 Jul 2022 10:45:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BK/cBtr2"; dkim-atps=neutral Received: from deskari.lan (91-158-154-79.elisa-laajakaista.fi [91.158.154.79]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 25DA26D1; Fri, 1 Jul 2022 10:45:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1656665148; bh=COD1ICfp6x0GrWGYRioB2UOSOOeDG2n1CiaJWo9k4JI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BK/cBtr2y4RUHaaOQ0tjINwT7ty1NajK20a/UVJlOWSBy0b1XYvjGlO3igCj4ROZa S/zKC6+XrQ86kycS06No5JFgc7vBkLqjBsHvd5C0rK0fYMeKtsyxZfzL05VYY/4atk 32ijAwSE5fiwJyWQ6k9uzN1kfqTQIUBmw1RyTDN0= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Fri, 1 Jul 2022 11:45:21 +0300 Message-Id: <20220701084521.31831-18-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220701084521.31831-1-tomi.valkeinen@ideasonboard.com> References: <20220701084521.31831-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v3 17/17] py: Add hotplug-monitor.py X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tomi Valkeinen via libcamera-devel From: Tomi Valkeinen Reply-To: Tomi Valkeinen Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a simple example script which waits for camera hotplug events. Signed-off-by: Tomi Valkeinen Reviewed-by: Laurent Pinchart --- 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 + +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())