From patchwork Wed Jun 29 07:04:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 16420 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 48961BE173 for ; Wed, 29 Jun 2022 07:05:01 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E203C6565D; Wed, 29 Jun 2022 09:05:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1656486301; bh=9IF/8cQaAqh4IDA/idC7EzTVcSpnho5mCs7AV/Irp0k=; 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=xb+TSo/chmDot28pYiQ1w/6jz/Tbd9j4YOVjydHc/CrJvYW+AGE62skDslmSWIC2i uhKk6IlldYzlDOWyl5zdY+uKKcrMYj3I/DZ6FslcZljI2vspX+xTI3Vn0d0IHsD3sU qZJWgVnEWp9TXlfsUK0vKfFTaqcB1Jd/7QC9A9821Kocrvj5/oCcJVBncm+SQQOr5Y lhhYv2OjPjatxRpNBjmlzJ9U6BFVarn9/rxKD9UyVuWG6+hYjIyQrzFGkjbkcQXjIA 7+3jau2uqmDO7uhNWEP/IBnbDrP98aPSNSLPm8P+kIpP4SNHaeAXGTWiIkatfxh6hw yHKAJ9IEXCG4A== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5662E6564D for ; Wed, 29 Jun 2022 09:04:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="uwi0HuD7"; 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 B690C4A8; Wed, 29 Jun 2022 09:04:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1656486288; bh=9IF/8cQaAqh4IDA/idC7EzTVcSpnho5mCs7AV/Irp0k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uwi0HuD7b66EO0YxRi1jofo97HHNO2YIVJjAa028FY4DzLiGKmz+qpeIbgf7wv2/V 1M8odTc3n2pahu4GX5c6y30LFMqZ0Ly/wRLNZC1uMtL/kquN3yf4oBxLtiBoKDhhxb ApfnbW+lAeea3a8zb1DzfiaGPhTA20LaPVz2GbV4= To: libcamera-devel@lists.libcamera.org, David Plowman , Kieran Bingham , Laurent Pinchart , Jacopo Mondi Date: Wed, 29 Jun 2022 10:04:16 +0300 Message-Id: <20220629070416.17550-15-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220629070416.17550-1-tomi.valkeinen@ideasonboard.com> References: <20220629070416.17550-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v2 14/14] 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 --- 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 + +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())