hi sir am working project on usb hub...
here two devices are present 1. usb pendrive 2. usb keyboard
but without pendrive keyboard not working how to solve this problem..
my code:
/---------------------------------------------------------------------------------------------------/
#include <usbhub.h>
#include <string.h>
#include "pgmstrings.h"
#include <SPI.h>
#include <UsbFat.h>
#include <masstorage.h>
#include <hidboot.h>
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
/---------------------------------------------------------------------------------------------------/
String receivedChars;
/---------------------------------------------------------------------------------------------------/
USB Usb;
USBHub Hub(&Usb);
/---------------------------------------------------------------------------------------------------/
BulkOnly bulk(&Usb);
UsbFat key1(&bulk);
FatFile file;
void(* resetFunc) (void) = 0;
/---------------------------------------------------------------------------------------------------/
void fDrive()
{
if (!key1.begin()) {}
while(Serial.available()>0)
{
receivedChars = Serial.readString();
Serial.println(receivedChars);
if(receivedChars == "cowfat")
{
cowfatFunc();
}
else
{
Serial.println("wrongfilename");
delay(200);
resetFunc();
}
}
}
/---------------------------------------------------------------------------------------------------/
void cowfatFunc()
{
if (!file.open("cowfat.csv", O_RDONLY)) { Serial.println(F("open failed"));}
else{ Serial.println("Filefound");}
delay(200);
resetFunc();
}
/---------------------------------------------------------------------------------------------------/
class KbdRptParser : public KeyboardReportParser
{
virtual void OnKeyDown (uint8_t mod, uint8_t key);
};
/---------------------------------------------------------------------------------------------------/
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
if(key <= 82 && key >= 40) Serial.println(key);
}
/---------------------------------------------------------------------------------------------------/
HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb); KbdRptParser Prs;
/---------------------------------------------------------------------------------------------------/
void setup()
{
Serial.begin( 115200 );
Serial.println("------------------------");
Serial.println("Start");
if (!initUSB(&Usb))
{
Serial.println(F("initUSB failed"));
}
Keyboard.SetReportParser(0, (HIDReportParser*)&Prs);
}
/---------------------------------------------------------------------------------------------------/
void loop()
{
fDrive();
Usb.Task();
}
/--------------------------------------------------------------------------/
sample output:
Start
69
69
69
69
cowfat
Filefound
Start
68
67
67
67
67
67
cow
wrongfilename
Start




