// HidUtility asks if a packet should be sent to the device // Prepare the buffer and request a transfer public void SendPacketHandler(object sender, UsbBuffer OutBuffer) { // Fill entire buffer with 0xFF OutBuffer.clear(); if (ToggleLedPending == true) { // The first byte is the "Report ID" and does not get sent over the USB bus. Always set = 0. OutBuffer.buffer[0] = 0; // 0x80 is the "Toggle LED" command in the firmware OutBuffer.buffer[1] = 0x80; ToggleLedPending = false; LastCommand = 0x80; } else if (LastCommand == 0x81) { // The first byte is the "Report ID" and does not get sent over the USB bus. Always set = 0. OutBuffer.buffer[0] = 0x00; // READ_POT command (see the firmware source code), gets 10-bit ADC Value OutBuffer.buffer[1] = 0x37; LastCommand = 0x37; } else { // The first byte is the "Report ID" and does not get sent over the USB bus. Always set = 0. OutBuffer.buffer[0] = 0x00; // 0x81 is the "Get Pushbutton State" command in the firmware OutBuffer.buffer[1] = 0x81; LastCommand = 0x81; } // Request that this buffer be sent OutBuffer.RequestTransfer = true; }
// HidUtility asks if a packet should be sent to the device // Prepare the buffer and request a transfer public void SendPacketHandler(object sender, UsbBuffer OutBuffer) { DebugString = "Start SendPacketHandler"; // Fill entire buffer with 0xFF OutBuffer.clear(); // The first byte is the "Report ID" and does not get sent over the USB bus. Always set = 0. OutBuffer.buffer[0] = 0x00; //Prepare data to send byte NextPacket; if (PacketsToRequest.Count >= 1) { NextPacket = PacketsToRequest[0]; PacketsToRequest.RemoveAt(0); } else { NextPacket = 0x10; } OutBuffer.buffer[1] = NextPacket; PacketsToRequest.Add(NextPacket); int position = 2; while ((position <= 64) && (PendingCommands.Count > 0)) { List <byte> CommandBytes = PendingCommands[0].GetByteList(); //Check if entire command fits into current buffer if ((64 - position) >= CommandBytes.Count) { foreach (byte b in CommandBytes) { OutBuffer.buffer[position] = b; ++position; } PendingCommands.RemoveAt(0); } else { position += CommandBytes.Count; break; } } //Request the packet to be sent over the bus OutBuffer.RequestTransfer = true; DebugString = "End SendPacketHandler"; }