| 76 | |
| 77 | |
| 78 | class P2Pro: |
| 79 | _dev: usb.core.Device |
| 80 | |
| 81 | def __init__(self): |
| 82 | self._dev = usb.core.find(idVendor=0x0BDA, idProduct=0x5830) |
| 83 | if (self._dev == None): |
| 84 | raise FileNotFoundError("Infiray P2 Pro thermal module not found, please connect and try again!") |
| 85 | pass |
| 86 | |
| 87 | def _check_camera_ready(self) -> bool: |
| 88 | """ |
| 89 | Checks if the camera is ready (i2c_usb_check_access_done in the SDK) |
| 90 | |
| 91 | :return: True if the camera is ready |
| 92 | :raises UserWarning: When the return code of the camera is abnormal |
| 93 | """ |
| 94 | ret = self._dev.ctrl_transfer(0xC1, 0x44, 0x78, 0x200, 1) |
| 95 | if (ret[0] & 1 == 0 and ret[0] & 2 == 0): |
| 96 | return True |
| 97 | if (ret[0] & 0xFC != 0): |
| 98 | raise UserWarning(f"vdcmd status error {ret[0]:#X}") |
| 99 | return False |
| 100 | |
| 101 | def _block_until_camera_ready(self, timeout: int = 5) -> bool: |
| 102 | """ |
| 103 | Blocks until the camera is ready or the timeout is reached |
| 104 | |
| 105 | :param timeout: Timeout in seconds |
| 106 | :return: True if the camera is ready, False if the timout occured |
| 107 | :raises UserWarning: When the return code of the camera is abnormal |
| 108 | """ |
| 109 | start = time.time() |
| 110 | while True: |
| 111 | if (self._check_camera_ready()): |
| 112 | return True |
| 113 | time.sleep(0.001) |
| 114 | if (time.time() > start + timeout): |
| 115 | return False |
| 116 | |
| 117 | def _long_cmd_write(self, cmd: int, p1: int, p2: int, p3: int = 0, p4: int = 0): |
| 118 | data1 = struct.pack("<H", cmd) |
| 119 | data1 += struct.pack(">HI", p1, p2) |
| 120 | data2 = struct.pack(">II", p3, p4) |
| 121 | log.debug(f'l_cmd_w {0x9d00:#x} {data1.hex()}') |
| 122 | log.debug(f'l_cmd_w {0x1d08:#x} {data2.hex()} ') |
| 123 | self._dev.ctrl_transfer(0x41, 0x45, 0x78, 0x9d00, data1) |
| 124 | self._dev.ctrl_transfer(0x41, 0x45, 0x78, 0x1d08, data2) |
| 125 | self._block_until_camera_ready() |
| 126 | |
| 127 | def _long_cmd_read(self, cmd: int, p1: int, p2: int = 0, p3: int = 0, dataLen: int = 2): |
| 128 | data1 = struct.pack("<H", cmd) |
| 129 | data1 += struct.pack(">HI", p1, p2) |
| 130 | data2 = struct.pack(">II", p3, dataLen) |
| 131 | log.debug(f'l_cmd_r {0x9d00:#x} {data1.hex()}') |
| 132 | log.debug(f'l_cmd_r {0x1d08:#x} {data2.hex()} ') |
| 133 | self._dev.ctrl_transfer(0x41, 0x45, 0x78, 0x9d00, data1) |
| 134 | self._dev.ctrl_transfer(0x41, 0x45, 0x78, 0x1d08, data2) |
| 135 | self._block_until_camera_ready() |
nothing calls this directly
no outgoing calls
no test coverage detected