Skip to content

Commit

Permalink
Fixed IDevice::Shell() seem's to have been caused by an issue during …
Browse files Browse the repository at this point in the history
…the connection.
  • Loading branch information
GreySyntax committed Oct 16, 2010
1 parent 37d2a22 commit e908613
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
24 changes: 10 additions & 14 deletions src/IDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool IDevice::Connect() {
return false;
}

if (! USB.ClaimInterface(0) && ! USB.ClaimInterface(1)) {
if (! USB.ClaimInterface(0) || ! USB.ClaimInterface(1)) {

cout << "[IDevice::Connect] Failed to claim interface's." << endl;
//Disconnect();
Expand Down Expand Up @@ -169,17 +169,10 @@ void IDevice::Shell() {
Connect();
}

if (! USB.IsConnected() //||
//! USB.Configure(1) ||
//! USB.ClaimAltInterface(1, 1)
) {
if (! USB.IsConnected() || ! USB.Configure(1) || ! USB.ClaimAltInterface(1, 1)) {

return;
}

USB.Configure(1);
USB.ReleaseInterface(1);
USB.ClaimAltInterface(1, 1);

char* buffer = (char*)malloc(kBufferSize);

Expand All @@ -191,19 +184,22 @@ void IDevice::Shell() {
//TODO Log to file

bool runShell = true;
int available = 0, pos = 0;

while (runShell) {

int available = 0;
available = 0;

memset(buffer, 0, kBufferSize);
libusb_bulk_transfer(USB.handle, 0x81, (unsigned char*)buffer, 0x10000, &available, 500);
// USB.Read(0x81, buffer, kBufferSize, &available, kCommandTimeout);
USB.Read(0x81, buffer, kBufferSize, &available, kCommandTimeout);

if (available > 0) {

cout << &buffer[available];

for (pos = 0; pos < available; pos++) {

cout << buffer[pos];
}

free(buffer);
buffer = (char*)malloc(kBufferSize);
}
Expand Down
10 changes: 3 additions & 7 deletions src/LazyUSB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ bool LazyUSB::Configure(int mode) {

#else

/*int configuration = 0;
int configuration = 0;
libusb_get_configuration(handle, &configuration);

if (configuration == mode) {

cout << "[LazyUSB::Configure] Requested configuration allready set." << endl;
return true;
}*/
}

if (libusb_set_configuration(handle, mode) < 0) {

Expand Down Expand Up @@ -168,8 +168,8 @@ bool LazyUSB::Open(int vendorID, int productID) {

if (handle == NULL) {
#else

libusb_init(NULL);
libusb_set_debug(NULL, 2);

if ((handle = libusb_open_device_with_vid_pid(NULL, vendorID, productID)) == NULL) {
#endif
Expand Down Expand Up @@ -250,8 +250,6 @@ int LazyUSB::Read(unsigned char endPoint, char* data, int length, int* actual_le
res = libusb_bulk_transfer(handle, endPoint, (unsigned char*)data, length, actual_length, timeout);
#endif

cout << "[LazyUSB::Read] Result: #" << res << endl;

return res;
}

Expand All @@ -272,8 +270,6 @@ int LazyUSB::Write(unsigned char endPoint, char* data, int length, int* actual_l
res = libusb_bulk_transfer(handle, endPoint, (unsigned char*)data, length, actual_length, timeout);
#endif

cout << "[LazyUSB::Write] Result: #" << res << endl;

return res;
}

Expand Down

0 comments on commit e908613

Please sign in to comment.