update LIDARLite_v3HP just to be functionnal. IUT GEII NICE
Revision 2:d6e45ac03963, committed 2022-02-09
- Comitter:
- vermaelen
- Date:
- Wed Feb 09 15:13:07 2022 +0000
- Parent:
- 1:bd9e4d198947
- Commit message:
- plein de changement, ca marche
Changed in this revision
LIDARLite_v3HP.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r bd9e4d198947 -r d6e45ac03963 LIDARLite_v3HP.cpp --- a/LIDARLite_v3HP.cpp Wed Feb 09 14:21:29 2022 +0000 +++ b/LIDARLite_v3HP.cpp Wed Feb 09 15:13:07 2022 +0000 @@ -51,14 +51,14 @@ ------------------------------------------------------------------------------*/ LIDARLite_v3HP::LIDARLite_v3HP(I2C *i2c):i2c_(i2c) { - addr_ = LIDARLITE_ADDR_DEFAULT; + addr_ = LIDARLITE_ADDR_DEFAULT; } /* LIDARLite_v3HP::LIDARLite_v3HP */ LIDARLite_v3HP::LIDARLite_v3HP(I2C *i2c, uint8_t &addr):i2c_(i2c) -{ +{ addr_ = addr; - + } /* LIDARLite_v3HP::LIDARLite_v3HP */ void LIDARLite_v3HP::configure(const uint8_t &configuration, const uint8_t &lidarliteAddress) @@ -68,8 +68,7 @@ uint8_t refCountMax; uint8_t thresholdBypass; - switch (configuration) - { + switch (configuration) { case 0: // Default mode, balanced performance sigCountMax = 0x80; // Default acqConfigReg = 0x08; // Default @@ -120,9 +119,9 @@ break; } - write(0x02, &sigCountMax , 1, lidarliteAddress); - write(0x04, &acqConfigReg , 1, lidarliteAddress); - write(0x12, &refCountMax , 1, lidarliteAddress); + write(0x02, &sigCountMax, 1, lidarliteAddress); + write(0x04, &acqConfigReg, 1, lidarliteAddress); + write(0x12, &refCountMax, 1, lidarliteAddress); write(0x1c, &thresholdBypass, 1, lidarliteAddress); } /* LIDARLite_v3HP::configure */ @@ -159,8 +158,7 @@ write(0x1e, dataBytes, 1, lidarliteAddress); // If desired, disable default I2C device address (using the new I2C device address) - if (disableDefault) - { + if (disableDefault) { read (0x1e, dataBytes, 1, newAddress); dataBytes[0] = dataBytes[0] | (1 << 3); // set bit to disable default address write(0x1e, dataBytes, 1, newAddress); @@ -179,9 +177,11 @@ ------------------------------------------------------------------------------*/ void LIDARLite_v3HP::takeRange(const uint8_t &lidarliteAddress) { - uint8_t dataByte = 0x01; - - write(0x00, &dataByte, 1, lidarliteAddress); + // uint8_t dataByte= 0x04; + char start[2]={0,4}; + i2c_->write((lidarliteAddress<<1), start, 2); + // write(0x00, &dataByte, 1, lidarliteAddress); + // i2c.write(0xC4,start,2); //on lance la mesure } /* LIDARLite_v3HP::takeRange */ /*------------------------------------------------------------------------------ @@ -197,26 +197,35 @@ void LIDARLite_v3HP::waitForBusy(const uint8_t &lidarliteAddress) { uint16_t busyCounter = 0; // busyCounter counts number of times busy flag is checked, for timeout - uint8_t busyFlag = 1; // busyFlag monitors when the device is done with a measurement + char busyFlag ; // busyFlag monitors when the device is done with a measurement + char status=0x01; //status register + + /* i2c_->write((lidarliteAddress<<1), &status, 1);//choix de l'adresse à lire... - while (busyFlag) // Loop until device is not busy - { - // Handle timeout condition, exit while loop and goto bailout - if (busyCounter > 9999) - { + // Loop until device is not busy + do{ + // Handle timeout condition, exit while loop and goto bailout + if (busyCounter > 99) + { + break; + } + + busyFlag = getBusyFlag(lidarliteAddress); + printf("."); + + // Increment busyCounter for timeout + busyCounter++; + }while (busyFlag!=0) ;*/ + i2c_->write((lidarliteAddress<<1), &status, 1); + do { + i2c_->read((lidarliteAddress<<1), &busyFlag, 1); + busyCounter++; + if (busyCounter > 99) { break; } - - busyFlag = getBusyFlag(lidarliteAddress); + putchar('.'); // pour voir le nombre de wait + } while((busyFlag&1)!=0); - // Increment busyCounter for timeout - busyCounter++; - } - - // bailout reports error over serial - if (busyCounter > 9999) - { - } } /* LIDARLite_v3HP::waitForBusy */ /*------------------------------------------------------------------------------ @@ -231,15 +240,14 @@ ------------------------------------------------------------------------------*/ uint8_t LIDARLite_v3HP::getBusyFlag(const uint8_t &lidarliteAddress) { - uint8_t busyFlag; // busyFlag monitors when the device is done with a measurement + char busyFlag; // busyFlag monitors when the device is done with a measurement // Read status register to check busy flag - read(0x01, &busyFlag, 1, lidarliteAddress); + //read(0x01, &busyFlag, 1, lidarliteAddress); + i2c_->read((lidarliteAddress<<1), &busyFlag, 1); // STATUS bit 0 is busyFlag - busyFlag &= 0x01; - - return busyFlag; + return (busyFlag&0x01); } /* LIDARLite_v3HP::getBusyFlag */ /*------------------------------------------------------------------------------ @@ -262,13 +270,13 @@ { uint16_t distance; uint8_t dataByteHigh; - uint8_t dataByteLow; + uint8_t dataByteLow; // Read two bytes from register 0x0f and 0x10 (autoincrement) // ca marche pas !!!! - // read(0x0f, dataBytes, 2, lidarliteAddress); - read(0x0f, dataByteHigh, 1, lidarliteAddress); - read(0x0f, dataByteLow, 1, lidarliteAddress); + // read(0x0f, dataBytes, 2, lidarliteAddress); + read(0x0f, &dataByteHigh, 1, lidarliteAddress); + read(0x10, &dataByteLow, 1, lidarliteAddress); distance =(dataByteHigh<<8)+dataByteLow; return (distance); } /* LIDARLite_v3HP::readDistance */ @@ -356,12 +364,11 @@ // ----------------------------------------------------------------- // I2C.write(i2cAddress, *data, length, repeated = false) - - nackCatcher = i2c_->write(lidarliteAddress<<1, (char *)dataBytes, numBytes, false); + + nackCatcher = i2c_->write((lidarliteAddress<<1), (char *)dataBytes, numBytes, false); // A nack means the device is not responding. Report the error over serial. - if (nackCatcher != 0) - { + if (nackCatcher != 0) { printf("> nack\n\r"); } @@ -391,20 +398,19 @@ const uint16_t &numBytes, const uint8_t &lidarliteAddress) { int nackCatcher = 0; - + char regAddrC = char(regAddr); - + // A nack means the device is not responding, report the error over serial - nackCatcher = i2c_->write(lidarliteAddress<<1, ®AddrC, 1, false); // false means perform repeated start - - if (nackCatcher != 0) - { + nackCatcher = i2c_->write((lidarliteAddress<<1), ®AddrC, 1, false); // false means perform repeated start + + if (nackCatcher != 0) { printf("> nack\n\r"); } // Perform read, save in dataBytes array - i2c_->read(lidarliteAddress<<1, (char *)dataBytes, numBytes); - + i2c_->read((lidarliteAddress<<1), (char *)dataBytes, numBytes); + } /* LIDARLite_v3HP::read */ /*------------------------------------------------------------------------------ @@ -443,8 +449,7 @@ dataBytes[0] = 0x07; write(0x40, dataBytes, 1, lidarliteAddress); - for (i=0 ; i<numberOfReadings ; i++) - { + for (i=0 ; i<numberOfReadings ; i++) { read(0x52, dataBytes, 2, lidarliteAddress); // Low byte is the value of the correlation record @@ -452,12 +457,11 @@ // if upper byte lsb is one, the value is negative // so here we test to artifically sign extend the data - if ( (int) dataBytes[1] == 1) - { + if ( (int) dataBytes[1] == 1) { correlationValue |= 0xff00; } printf("%d\n\r", correlationValue); - + } // test mode disable