#include <USBHost_t36.h>
#define BAUD 115200
uint32_t format = USBHOST_SERIAL_8N1;
USBHost myusb;
USBSerial_BigBuffer userial(myusb, 1, PID, VID, USBSerialBase::CP210X, 0);
char buffer[512];
char mybuffer[512] = "12345612345678901234567890123456789012567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234561234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
void setup() {
myusb.begin();
userial.begin(BAUD);
Serial1.begin(BAUD);
Serial.begin(BAUD);
Serial1.println("setup completed.");
}
void loop() {
myusb.Task();
uint16_t rd, wr, n;
wr = userial.availableForWrite();
if (wr > 0){
// write to dtv
userial.write(mybuffer, sizeof(mybuffer));
Serial1.println("wrote to tuner successfully!");
}
else{
Serial1.println("userial not available");
}
unsigned long startMillis = millis();
unsigned long currentMillis;
unsigned long timeout = 2000;
while(true){
currentMillis = millis();
rd = userial.available();
if(rd > 0) break;
if(currentMillis - startMillis > timeout){
Serial1.println("timeout");
break;
}
}
if (rd > 0) {
Serial1.println("dtv available");
n = userial.readBytes((char *)buffer, rd);
Serial1.println((char *)buffer);
// check if the USB virtual serial port is ready to transmit
wr = Serial.availableForWrite();
if (wr > 0) {
// compute how much data to move, the smallest
// of rd, wr and the buffer size
if (rd > wr) rd = wr;
if (rd > 80) rd = 80;
// read data from the USB host serial port
n = userial.readBytes((char *)buffer, rd);
// write it to the USB port
Serial1.println("read data fom dtv successfully!");
}
}
delay(10);
}