mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-21 04:33:10 +08:00
batt_smbus: remove usleep
Also restore I2C address after performing command line search for devices
This commit is contained in:
@@ -282,6 +282,7 @@ BATT_SMBUS::search()
|
||||
{
|
||||
bool found_slave = false;
|
||||
uint16_t tmp;
|
||||
int16_t orig_addr = get_address();
|
||||
|
||||
// search through all valid SMBus addresses
|
||||
for (uint8_t i = BATT_SMBUS_ADDR_MIN; i <= BATT_SMBUS_ADDR_MAX; i++) {
|
||||
@@ -296,6 +297,9 @@ BATT_SMBUS::search()
|
||||
usleep(1);
|
||||
}
|
||||
|
||||
// restore original i2c address
|
||||
set_address(orig_addr);
|
||||
|
||||
// display completion message
|
||||
if (found_slave) {
|
||||
warnx("Done.");
|
||||
@@ -367,7 +371,6 @@ BATT_SMBUS::cycle()
|
||||
new_report.voltage_v = ((float)tmp) / 1000.0f;
|
||||
|
||||
// read current
|
||||
usleep(1);
|
||||
uint8_t buff[4];
|
||||
|
||||
if (read_block(BATT_SMBUS_CURRENT, buff, 4, false) == 4) {
|
||||
@@ -376,7 +379,6 @@ BATT_SMBUS::cycle()
|
||||
|
||||
// read battery design capacity
|
||||
if (_batt_design_capacity == 0) {
|
||||
usleep(1);
|
||||
if (read_reg(BATT_SMBUS_DESIGN_CAPACITY, tmp) == OK) {
|
||||
_batt_design_capacity = tmp;
|
||||
}
|
||||
@@ -384,7 +386,6 @@ BATT_SMBUS::cycle()
|
||||
|
||||
// read remaining capacity
|
||||
if (_batt_design_capacity > 0) {
|
||||
usleep(1);
|
||||
if (read_reg(BATT_SMBUS_REMAINING_CAPACITY, tmp) == OK) {
|
||||
if (tmp < _batt_design_capacity) {
|
||||
new_report.discharged_mah = _batt_design_capacity - tmp;
|
||||
@@ -451,8 +452,6 @@ BATT_SMBUS::read_block(uint8_t reg, uint8_t *data, uint8_t max_len, bool append_
|
||||
{
|
||||
uint8_t buff[max_len + 2]; // buffer to hold results
|
||||
|
||||
usleep(1);
|
||||
|
||||
// read bytes including PEC
|
||||
int ret = transfer(®, 1, buff, max_len + 2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user