diff --git a/sdk/packet.ts b/sdk/packet.ts index 6490902..724e27e 100644 --- a/sdk/packet.ts +++ b/sdk/packet.ts @@ -113,7 +113,7 @@ export async function send_data(dev: HIDDevice, data: Array, debug = fal export async function process_packets(dev: HIDDevice, responseType: number, debug = false): Promise> { let current_packet: Array = []; let seenFirstPacket = false; - let reading_packet = false; + let readingPacket = false; while (true) { const data = await nextReportCommand(dev); @@ -124,12 +124,23 @@ export async function process_packets(dev: HIDDevice, responseType: number, debu } const data_buffer = new Uint8Array(data.buffer); + if (responseType !== 121) { + console.log(data_buffer); + } + + // If we see an ACK Command just ignore it and restart + if (data_buffer[0] === ACK_COMMAND) { + readingPacket = false; + seenFirstPacket = false; + current_packet = []; + continue; + } // Wait until we see a packet start flag so we don't grab a // packet half way through - if (!reading_packet) { + if (!readingPacket) { if (data_buffer[0] & PACKET_FLAG_START_OF_COMMAND) { - reading_packet = true; + readingPacket = true; } else { continue; } @@ -140,6 +151,7 @@ export async function process_packets(dev: HIDDevice, responseType: number, debu } if (!seenFirstPacket) { + console.log(responseType, current_packet[0]); if (current_packet[0] === responseType) { seenFirstPacket = true; } else { @@ -152,7 +164,7 @@ export async function process_packets(dev: HIDDevice, responseType: number, debu // If we've gotten here and our current packet is empty, that means // we flushed it at some point. Restart if (current_packet.length === 0) { - reading_packet = false; + readingPacket = false; } }