void APP_DeviceCustomHIDTasks()
{
//Check if we have received an OUT data packet from the host
if(HIDRxHandleBusy(USBOutHandle) == false)
{
//We just received a packet of data from the USB host.
//Check the first uint8_t of the packet to see what command the host
//application software wants us to fulfill.
switch(ReceivedDataBuffer[0]) //Look at the data the host sent, to see what kind of application specific command it sent.
{
case COMMAND_TOGGLE_LED: //Toggle LEDs command
LED_Toggle(LED_USB_DEVICE_HID_CUSTOM);
break;
case COMMAND_GET_BUTTON_STATUS: //Get push button state
//Check to make sure the endpoint/buffer is free before we modify the contents
if(!HIDTxHandleBusy(USBInHandle)) <<<< this is always false( jumps over)
{
ToSendDataBuffer[0] = 0x81; //Echo back to the host PC the command we are fulfilling in the first uint8_t. In this case, the Get Pushbutton State command.
if(BUTTON_IsPressed(BUTTON_USB_DEVICE_HID_CUSTOM) == false) //pushbutton not pressed, pull up resistor on circuit board is pulling the PORT pin high
{
ToSendDataBuffer[1] = 0x01;
}
else //sw3 must be == 0, pushbutton is pressed and overpowering the pull up resistor
{
ToSendDataBuffer[1] = 0x00;
}
//Prepare the USB module to send the data packet to the host
//LATC6 = ~LATC6;
USBInHandle = HIDTxPacket(CUSTOM_DEVICE_HID_EP, (uint8_t*)&ToSendDataBuffer[0],64);
}
break;
}
//Re-arm the OUT endpoint, so we can receive the next OUT data packet
//that the host may try to send us.
//USBInHandle = HIDTxPacket(CUSTOM_DEVICE_HID_EP, (uint8_t*)&ToSendDataBuffer[0],64);
LATC6 =~ LATC6;
USBOutHandle = HIDRxPacket(CUSTOM_DEVICE_HID_EP, (uint8_t*)&ReceivedDataBuffer, 64);
}
}
void APP_cmd(void) {
memset( ToSendDataBuffer, ' ', sizeof(ToSendDataBuffer) ); //clear buffer
switch (ReceivedDataBuffer[1]) {
case CID_VERSION:// send version info-string
ToSendDataBuffer[1] = CID_VERSION | ID_MESSAGE;
ToSendDataBuffer[0] = sizeof (strVersion) + 1;
int max_packet_num = MAX_NUM_BYTES/64; //MAX_NUM_BYTES = 300
for (unsigned char packet_num = 0; packet_num < max_packet_num; packet_num ++)
{
for ( num_of_samples = 2 ; num_of_samples < 64 ; num_of_samples++ )
{
ToSendDataBuffer[num_of_samples] = packet_num;
}
USBInHandle = HIDTxPacket(HID_EP,(uint8_t *)ToSendDataBuffer, 64);
}
Flags.IN_TODO = 1;
break;
.
. //other "case"s
.
}//switch (usb_outPck.ID.all)
if (Flags.IN_TODO == 0) // generate std. ACK
{
ToSendDataBuffer[1] = ReceivedDataBuffer[1] | ID_MESSAGE;
ToSendDataBuffer[0] = 1;
Flags.IN_TODO = 1;
}
}
void MainWindow::rxHandler()
{
QString s = "";
io_result = hid_read(connected_device, inBuffer, 65);
if (io_result == 64){
if(ui->cbTimeStamp->isChecked()){
ui->teInHEX->insertPlainText("\r" + QString::number(timeStamp.elapsed())+ "ms -> ");
ui->teInHEX->ensureCursorVisible();
}
for (int i = 0; i<= inBuffer[0];i++){
s += QString("%1").arg(inBuffer[i],3,16);
}
ui->teInHEX->append(s);
ui->teInHEX->ensureCursorVisible(); // (for auto-scolling)
ui->teInASCII->append((char*)&inBuffer);
ui->teInASCII->ensureCursorVisible();
// if (inBuffer[1] == IDERROR){ // multiple possibilities ------------ERROR
// edErrors->Text = "ERROR: unknown Device error";
// }else
switch (inBuffer[1] - ID_MESSAGE) //---------------------- MESSAGE
{
case CID_VERSION: // version info-string
//ui->lbVersion->setText((char*)&inBuffer[2]);
for (int packet_num = 0; packet_num < max_packet_num ; packet_num++)
{
for (long int count = 0; count < 65; count++)
{
long int numm = count + packet_num * 64;
my_store[numm] = inBuffer[count];
}
io_result = hid_write(connected_device, inBuffer, 65);
}
myfile.open("file.txt", ios::out | ios::binary);
for (int ii=0 ; ii <300 ; ii++)
myfile << " " << hex << int(checkin2[ii]) << endl;
myfile.close();
break;
}
}
}
Users browsing this forum: No registered users and 18 guests