From 898358f4e62565e38f9fc25a4f3102a7a96f7c91 Mon Sep 17 00:00:00 2001 From: linuswck Date: Mon, 25 Mar 2024 12:43:02 +0800 Subject: [PATCH] pykirdy: Add reporting interval in report_mode --- pykirdy/driver/kirdy_async.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pykirdy/driver/kirdy_async.py b/pykirdy/driver/kirdy_async.py index 70ffb59..2b4632f 100644 --- a/pykirdy/driver/kirdy_async.py +++ b/pykirdy/driver/kirdy_async.py @@ -691,16 +691,20 @@ class Kirdy: await asyncio.sleep(0.1) raise NoAckRecv - async def report_mode(self): + async def report_mode(self, report_interval = 0.0, buffer_size = 16384): """ - Start reporting device status in json object + Start reporting device status in json object. Optional report_interval can be added to discard unwanted samples. + Only the latest status report received within the buffer is returned. + - polling interval: float/int (unit: seconds) + - buffer_size: int """ await self.device.set_active_report_mode(True) self._report_mode_on = True while self._report_mode_on: + await asyncio.sleep(report_interval) async with self._cmd_lock: - yield await self._read_response() + yield await self._read_response(buffer_size) await self.device.set_active_report_mode(False)