From patchwork Sat Jun 3 07:56:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 18695 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 778F6C32AA for ; Sat, 3 Jun 2023 07:57:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 168C7626FA; Sat, 3 Jun 2023 09:57:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1685779041; bh=cAWEa3NfkVrbPYoK1a6BVS1X1Z4HPm6BjAhCUj9LxvE=; 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=yxGTIa4g56l4Qig53E5gcYEfwtzVn40UtqpPR9oS6vLMtv3kTVF79hcSvzWwzA4Uj D3S1pQjcKxCIOBBtA5JLDOJGaehP2JRoZZVNLlQ3fMfOvxRlmhw3pcvAmKkHzsxtgt EKbWg3WAiMhJXYd5wKfXv2UyIFUM+QidvsbpN4Hw3IVs4zuq4Drpsi9AhvLl8gNu5P tWlCvh0lJobH+ExVDL/tEikmI/IC9hNjMWqUGA7drBYeAzC8Cotj7GLt46922oJmZO nYpuPgiEoxw2yPfY0/IXqFxlacndMYIEdjBO5lYDn4x5jJ7k5o03V0FtP3520OlaHL uEwGbI739Bm1g== 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 F1EC56287F for ; Sat, 3 Jun 2023 09:57:14 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZuIBQlVE"; dkim-atps=neutral Received: from desky.lan (91-154-35-171.elisa-laajakaista.fi [91.154.35.171]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 798DD468; Sat, 3 Jun 2023 09:56:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1685779011; bh=cAWEa3NfkVrbPYoK1a6BVS1X1Z4HPm6BjAhCUj9LxvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZuIBQlVELOalRw3/SWukS6J+om2ESeP8WrSockLvaGHJ2D08B4ZA5Ulx7FECMkPlK e7GSwZywsrVDeopm0dTE85CXvlVzmbDK2RHS21boVjRZmJhEatspoNOKlgScZJmnnZ gQq9CuxvyGf1H0CjVQNFipdqnW8W+iBMIDuTxFy8= To: libcamera-devel@lists.libcamera.org Date: Sat, 3 Jun 2023 10:56:12 +0300 Message-Id: <20230603075615.20663-11-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230603075615.20663-1-tomi.valkeinen@ideasonboard.com> References: <20230603075615.20663-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v5 10/13] 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 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 + +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())