#include #include #include #include #include #include #include #include #include #include #include #include #include #include "pgmstrings.h" class ACMAsyncOper : public CDCAsyncOper { public: virtual uint8_t OnInit(ACM *pacm); }; uint8_t ACMAsyncOper::OnInit(ACM *pacm) { uint8_t rcode; // Set DTR = 1 RTS=1 rcode = pacm->SetControlLineState(3); if (rcode) { ErrorMessage(PSTR("SetControlLineState"), rcode); return rcode; } LINE_CODING lc; lc.dwDTERate = 115200; lc.bCharFormat = 0; lc.bParityType = 0; lc.bDataBits = 8; rcode = pacm->SetLineCoding(&lc); if (rcode) ErrorMessage(PSTR("SetLineCoding"), rcode); return rcode; } USB Usb; //USBHub Hub(&Usb); ACMAsyncOper AsyncOper; ACM Acm(&Usb, &AsyncOper); void setup() { Serial.begin( 115200 ); Serial.println("Start"); if (Usb.Init() == -1) Serial.println("OSCOKIRQ failed to assert"); delay( 200 ); } void loop() { Usb.Task(); if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { uint8_t rcode; /* reading the keyboard */ if(Serial.available()) { uint8_t data= Serial.read(); /* sending to the phone */ rcode = Acm.SndData(1, &data); if (rcode) ErrorMessage(PSTR("SndData"), rcode); }//if(Serial.available()... delay(50); /* reading the phone */ /* buffer size must be larger than max.packet size */ uint8_t buf[32]; uint16_t rcvd = 32; rcode = Acm.RcvData(&rcvd, buf); if (rcode && rcode != hrNAK) ErrorMessage(PSTR("Ret"), rcode); if( rcvd ) { //more than zero bytes received for(uint16_t i=0; i < rcvd; i++ ) { Serial.print(buf[i]); //printing on the screen } } delay(10); }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING.. }