40 lines
882 B
Python
40 lines
882 B
Python
from dataclasses import dataclass
|
|
import struct
|
|
from time import sleep
|
|
from typing import Self
|
|
import hid
|
|
|
|
VID = 0x1209
|
|
PID = 0xCC1D
|
|
INTERVAL = 0.1
|
|
|
|
|
|
@dataclass
|
|
class AudioTelemetry:
|
|
STRUCT = "<LLLLL"
|
|
LEN = struct.calcsize(STRUCT)
|
|
|
|
average_buffer_fill: int
|
|
frame_count: int
|
|
dac_underflow_count: int
|
|
usb_underflow_count: int
|
|
dac_overflow_count: int
|
|
|
|
def from_bytes(b: bytes) -> Self:
|
|
if len(b) != AudioTelemetry.LEN:
|
|
raise ValueError(f"wrong size report ({len(b)} != {AudioTelemetry.LEN})")
|
|
fields = struct.unpack(AudioTelemetry.STRUCT, b)
|
|
return AudioTelemetry(*fields)
|
|
|
|
|
|
def main():
|
|
with hid.Device(VID, PID) as h:
|
|
while True:
|
|
report = AudioTelemetry.from_bytes(h.read(AudioTelemetry.LEN))
|
|
print(f"{report}")
|
|
sleep(INTERVAL)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|