Skip to content

Commit

Permalink
Remove duplicated code in branches
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold856 committed Jun 19, 2024
1 parent 11dbd29 commit 8dd447c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 84 deletions.
31 changes: 9 additions & 22 deletions wpilibc/src/main/native/cpp/ADIS16448_IMU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,29 +378,16 @@ bool ADIS16448_IMU::SwitchToStandardSPI() {
m_spi->SetClockRate(1000000);
m_spi->SetMode(frc::SPI::Mode::kMode3);
m_spi->SetChipSelectActiveLow();
ReadRegister(PROD_ID); // Dummy read

// Validate the product ID
uint16_t prod_id = ReadRegister(PROD_ID);
if (prod_id != 16448) {
REPORT_ERROR("Could not find ADIS16448!");
Close();
return false;
}
return true;
} else {
// Maybe the SPI port is active, but not in auto SPI mode? Try to read the
// product ID.
ReadRegister(PROD_ID); // Dummy read
uint16_t prod_id = ReadRegister(PROD_ID);
if (prod_id != 16448) {
REPORT_ERROR("Could not find ADIS16448!");
Close();
return false;
} else {
return true;
}
}
ReadRegister(PROD_ID); // Dummy read
// Validate the product ID
uint16_t prod_id = ReadRegister(PROD_ID);
if (prod_id != 16448) {
REPORT_ERROR("Could not find ADIS16448!");
Close();
return false;
}
return true;
}

void ADIS16448_IMU::InitOffsetBuffer(int size) {
Expand Down
31 changes: 9 additions & 22 deletions wpilibc/src/main/native/cpp/ADIS16470_IMU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,29 +356,16 @@ bool ADIS16470_IMU::SwitchToStandardSPI() {
m_spi->SetClockRate(2000000);
m_spi->SetMode(frc::SPI::Mode::kMode3);
m_spi->SetChipSelectActiveLow();
ReadRegister(PROD_ID); // Dummy read

// Validate the product ID
uint16_t prod_id = ReadRegister(PROD_ID);
if (prod_id != 16982 && prod_id != 16470) {
REPORT_ERROR("Could not find ADIS16470!");
Close();
return false;
}
return true;
} else {
// Maybe the SPI port is active, but not in auto SPI mode? Try to read the
// product ID.
ReadRegister(PROD_ID); // Dummy read
uint16_t prod_id = ReadRegister(PROD_ID);
if (prod_id != 16982 && prod_id != 16470) {
REPORT_ERROR("Could not find ADIS16470!");
Close();
return false;
} else {
return true;
}
}
ReadRegister(PROD_ID); // Dummy read
// Validate the product ID
uint16_t prod_id = ReadRegister(PROD_ID);
if (prod_id != 16982 && prod_id != 16470) {
REPORT_ERROR("Could not find ADIS16470!");
Close();
return false;
}
return true;
}

/**
Expand Down
28 changes: 8 additions & 20 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16448_IMU.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,27 +424,15 @@ private boolean switchToStandardSPI() {
m_spi.setClockRate(1000000);
m_spi.setMode(SPI.Mode.kMode3);
m_spi.setChipSelectActiveLow();
readRegister(PROD_ID); // Dummy read

// Validate the product ID
if (readRegister(PROD_ID) != 16448) {
DriverStation.reportError("Could not find ADIS16448", false);
close();
return false;
}
return true;
} else {
// Maybe the SPI port is active, but not in auto SPI mode? Try to read the
// product ID.
readRegister(PROD_ID); // dummy read
if (readRegister(PROD_ID) != 16448) {
DriverStation.reportError("Could not find an ADIS16448", false);
close();
return false;
} else {
return true;
}
}
readRegister(PROD_ID); // Dummy read
// Validate the product ID
if (readRegister(PROD_ID) != 16448) {
DriverStation.reportError("Could not find ADIS16448", false);
close();
return false;
}
return true;
}

boolean switchToAutoSPI() {
Expand Down
28 changes: 8 additions & 20 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java
Original file line number Diff line number Diff line change
Expand Up @@ -478,27 +478,15 @@ private boolean switchToStandardSPI() {
m_spi.setClockRate(2000000);
m_spi.setMode(SPI.Mode.kMode3);
m_spi.setChipSelectActiveLow();
readRegister(PROD_ID); // Dummy read

// Validate the product ID
if (readRegister(PROD_ID) != 16982) {
DriverStation.reportError("Could not find ADIS16470", false);
close();
return false;
}
return true;
} else {
// Maybe the SPI port is active, but not in auto SPI mode? Try to read the
// product ID.
readRegister(PROD_ID); // dummy read
if (readRegister(PROD_ID) != 16982) {
DriverStation.reportError("Could not find an ADIS16470", false);
close();
return false;
} else {
return true;
}
}
readRegister(PROD_ID); // Dummy read
// Validate the product ID
if (readRegister(PROD_ID) != 16982) {
DriverStation.reportError("Could not find an ADIS16470", false);
close();
return false;
}
return true;
}

/**
Expand Down

0 comments on commit 8dd447c

Please sign in to comment.