# HG changeset patch # User Paul Boddie # Date 1361648087 0 # Node ID b58a34713be6cd533947832ef03c42a367bae104 # Parent b88b2b0c03668ec961faed93913b3e59f94b528d Added detection of devices that are already connected. diff -r b88b2b0c0366 -r b58a34713be6 test.c --- a/test.c Sat Feb 23 19:10:59 2013 +0000 +++ b/test.c Sat Feb 23 19:34:47 2013 +0000 @@ -487,13 +487,16 @@ return timeout; } +/** + * Return whether the bus is ready to be sampled. The application note claims + * that the SAMPLEBUS bit is cleared, but this does not seem to be the case. + */ uint8_t samplebusready() { uint8_t result; result = max_read(MAX_REG_HCTL, NULL); - - return !(result & MAX_HCTL_SAMPLEBUS); + return result & MAX_HCTL_SAMPLEBUS; } void samplebus() @@ -677,6 +680,17 @@ revision = max_read(MAX_REG_REVISION, &status); printf("Revision = %x\n", revision); + /* Sample the bus for any devices that are already connected. */ + + samplebus(); + + if (devicechanged()) + { + devstate = MAX_DEVSTATE_CONNECTED; + } + + /* Enter the main processing loop. */ + for (count = 0; count <= 65535; count++) { if (!PIN(MAX_INT))