Skip to content

Commit

Permalink
USB/ANT: Detect device removal
Browse files Browse the repository at this point in the history
Handle "i/o error" and "no such device or address", so that we
recognise when the USB device has been removed..
  • Loading branch information
dresco committed Mar 30, 2017
1 parent 239f430 commit 5c39291
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/ANT/ANT.cpp
Expand Up @@ -264,8 +264,24 @@ void ANT::run()
{
// read more bytes from the device
uint8_t byte;
if (rawRead(&byte, 1) > 0) receiveByte((unsigned char)byte);
else msleep(5);

int rc = rawRead(&byte, 1);

if (rc > 0)
receiveByte((unsigned char)byte);
else {

// Recognise USB device removal. Linux transitions through -5 (I/O error)
// to -6 (No such device or address). Windows seems to stick on -5

if ((rc == -ENXIO) || (rc == -EIO && OperatingSystem == WINDOWS))
{
qDebug() << "Error communicating with USB ANT device!! Device removed?";
Status = 0;
}

msleep(5);
}

//----------------------------------------------------------------------
// LISTEN TO CONTROLLER FOR COMMANDS
Expand Down

0 comments on commit 5c39291

Please sign in to comment.