From patchwork Thu Mar 9 14:25:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomi Valkeinen X-Patchwork-Id: 18370 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 12841C3262 for ; Thu, 9 Mar 2023 14:26:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B974D626F4; Thu, 9 Mar 2023 15:26:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1678371987; bh=bggb8XXvFlEgt5vvMs4RTDr+kH9sme6KyV0CMYByloU=; 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=y2WXLlNfZgxlli+YJbj4yXzu6lRep6ma9lwz3LgXFSw6GZN1Ogqrv3Z8bwfGQEZ8s Wa7S7YR2Kn/+MYXLBV4sefKsB7SKPg5AMymd85P8EAErx5n1fuJ//sWSkIe2SUm0Ek U2lZpRQLYQtzvfTyUQjVAF8yuKjLLMWAlyyhseiBGm5+MNAiPenKS9/PRcI9Gt4X6D lRqbEFsK8jOzBC+C0fCsXanZUi7qKEnUeFOW3Q9cqWgONiDn0/pn4haYGPTlJkibmY aMG7Tk9giwpKgUX5DJAEiLBrgZnfWhnIAnKXjkfh9GQXZvoOOzb5IlLDFo5x3fqQcL KlsNvusNUcGlw== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 24578626E2 for ; Thu, 9 Mar 2023 15:26:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="SkfGjKZ3"; dkim-atps=neutral Received: from desky.lan (91-154-32-225.elisa-laajakaista.fi [91.154.32.225]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A34BC886; Thu, 9 Mar 2023 15:26:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1678371979; bh=bggb8XXvFlEgt5vvMs4RTDr+kH9sme6KyV0CMYByloU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SkfGjKZ3qE+0p3/BPAHWalisS1nEMqjrGo2OtlAfW/pNCLPVcW+yLhAwGyC12M3Si cODsuAJGzPT9dX49xVdtRW0l2d4Z3M4gMaDkUwHcqW+Z2iAopz/Zk7LVCv9ktYy0mj NhFl3KdTLT+G4SYT2BZRPnvfJjYOD3L1DTraYpIo= To: libcamera-devel@lists.libcamera.org Date: Thu, 9 Mar 2023 16:25:55 +0200 Message-Id: <20230309142601.70556-10-tomi.valkeinen@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230309142601.70556-1-tomi.valkeinen@ideasonboard.com> References: <20230309142601.70556-1-tomi.valkeinen@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v4 09/15] 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())