1
0
Fork 0

pykirdy: Add reporting interval in report_mode

This commit is contained in:
linuswck 2024-03-25 12:43:02 +08:00
parent a13c6fa86c
commit 898358f4e6
1 changed files with 7 additions and 3 deletions

View File

@ -691,16 +691,20 @@ class Kirdy:
await asyncio.sleep(0.1) await asyncio.sleep(0.1)
raise NoAckRecv 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) await self.device.set_active_report_mode(True)
self._report_mode_on = True self._report_mode_on = True
while self._report_mode_on: while self._report_mode_on:
await asyncio.sleep(report_interval)
async with self._cmd_lock: 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) await self.device.set_active_report_mode(False)