mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 14:33:34 +08:00
INA226: refactor spacing and return codes
This commit is contained in:
@@ -112,7 +112,7 @@ int INA226::read(uint8_t address)
|
|||||||
|
|
||||||
int ret = transfer(&address, 1, &data.b[0], sizeof(data.b));
|
int ret = transfer(&address, 1, &data.b[0], sizeof(data.b));
|
||||||
|
|
||||||
if (OK != ret) {
|
if (ret != PX4_OK) {
|
||||||
perf_count(_comms_errors);
|
perf_count(_comms_errors);
|
||||||
PX4_DEBUG("i2c::transfer returned %d", ret);
|
PX4_DEBUG("i2c::transfer returned %d", ret);
|
||||||
return -1;
|
return -1;
|
||||||
@@ -133,7 +133,7 @@ INA226::init()
|
|||||||
int ret = PX4_ERROR;
|
int ret = PX4_ERROR;
|
||||||
|
|
||||||
/* do I2C init (and probe) first */
|
/* do I2C init (and probe) first */
|
||||||
if (I2C::init() != OK) {
|
if (I2C::init() != PX4_OK) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,13 +151,13 @@ INA226::init()
|
|||||||
ret = write(INA226_REG_CONFIGURATION, _config);
|
ret = write(INA226_REG_CONFIGURATION, _config);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ret = OK;
|
ret = PX4_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
start();
|
start();
|
||||||
_sensor_ok = true;
|
_sensor_ok = true;
|
||||||
|
|
||||||
_initialized = ret == OK;
|
_initialized = ret == PX4_OK;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,13 +196,13 @@ INA226::probe()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return PX4_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
INA226::measure()
|
INA226::measure()
|
||||||
{
|
{
|
||||||
int ret = OK;
|
int ret = PX4_OK;
|
||||||
|
|
||||||
if (_mode_triggered) {
|
if (_mode_triggered) {
|
||||||
ret = write(INA226_REG_CONFIGURATION, _config);
|
ret = write(INA226_REG_CONFIGURATION, _config);
|
||||||
@@ -266,7 +266,7 @@ INA226::collect()
|
|||||||
_actuator_controls.control[actuator_controls_s::INDEX_THROTTLE]
|
_actuator_controls.control[actuator_controls_s::INDEX_THROTTLE]
|
||||||
);
|
);
|
||||||
|
|
||||||
ret = OK;
|
ret = PX4_OK;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
_battery.updateBatteryStatus(
|
_battery.updateBatteryStatus(
|
||||||
@@ -281,7 +281,7 @@ INA226::collect()
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != OK) {
|
if (ret != PX4_OK) {
|
||||||
PX4_DEBUG("error reading from sensor: %d", ret);
|
PX4_DEBUG("error reading from sensor: %d", ret);
|
||||||
perf_count(_comms_errors);
|
perf_count(_comms_errors);
|
||||||
}
|
}
|
||||||
@@ -309,9 +309,8 @@ INA226::RunImpl()
|
|||||||
{
|
{
|
||||||
if (_initialized) {
|
if (_initialized) {
|
||||||
if (_collect_phase) {
|
if (_collect_phase) {
|
||||||
|
|
||||||
/* perform collection */
|
/* perform collection */
|
||||||
if (OK != collect()) {
|
if (collect() != PX4_OK) {
|
||||||
perf_count(_collection_errors);
|
perf_count(_collection_errors);
|
||||||
/* if error restart the measurement state machine */
|
/* if error restart the measurement state machine */
|
||||||
start();
|
start();
|
||||||
@@ -322,7 +321,6 @@ INA226::RunImpl()
|
|||||||
_collect_phase = !_mode_triggered;
|
_collect_phase = !_mode_triggered;
|
||||||
|
|
||||||
if (_measure_interval > INA226_CONVERSION_INTERVAL) {
|
if (_measure_interval > INA226_CONVERSION_INTERVAL) {
|
||||||
|
|
||||||
/* schedule a fresh cycle call when we are ready to measure again */
|
/* schedule a fresh cycle call when we are ready to measure again */
|
||||||
ScheduleDelayed(_measure_interval - INA226_CONVERSION_INTERVAL);
|
ScheduleDelayed(_measure_interval - INA226_CONVERSION_INTERVAL);
|
||||||
return;
|
return;
|
||||||
@@ -332,7 +330,7 @@ INA226::RunImpl()
|
|||||||
/* Measurement phase */
|
/* Measurement phase */
|
||||||
|
|
||||||
/* Perform measurement */
|
/* Perform measurement */
|
||||||
if (OK != measure()) {
|
if (measure() != PX4_OK) {
|
||||||
perf_count(_measure_errors);
|
perf_count(_measure_errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,7 +351,7 @@ INA226::RunImpl()
|
|||||||
0.0f
|
0.0f
|
||||||
);
|
);
|
||||||
|
|
||||||
if (init() != OK) {
|
if (init() != PX4_OK) {
|
||||||
ScheduleDelayed(INA226_INIT_RETRY_INTERVAL_US);
|
ScheduleDelayed(INA226_INIT_RETRY_INTERVAL_US);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ public:
|
|||||||
* Tries to call the init() function. If it fails, then it will schedule to retry again in
|
* Tries to call the init() function. If it fails, then it will schedule to retry again in
|
||||||
* INA226_INIT_RETRY_INTERVAL_US microseconds. It will keep retrying at this interval until initialization succeeds.
|
* INA226_INIT_RETRY_INTERVAL_US microseconds. It will keep retrying at this interval until initialization succeeds.
|
||||||
*
|
*
|
||||||
* @return OK if initialization succeeded on the first try. Negative value otherwise.
|
* @return PX4_OK if initialization succeeded on the first try. Negative value otherwise.
|
||||||
*/
|
*/
|
||||||
int force_init();
|
int force_init();
|
||||||
|
|
||||||
@@ -171,16 +171,8 @@ private:
|
|||||||
uORB::Subscription _actuators_sub{ORB_ID(actuator_controls_0)};
|
uORB::Subscription _actuators_sub{ORB_ID(actuator_controls_0)};
|
||||||
uORB::Subscription _parameters_sub{ORB_ID(parameter_update)};
|
uORB::Subscription _parameters_sub{ORB_ID(parameter_update)};
|
||||||
|
|
||||||
|
int read(uint8_t address);
|
||||||
/**
|
int write(uint8_t address, uint16_t data);
|
||||||
* Test whetpower_monitorhe device supported by the driver is present at a
|
|
||||||
* specific address.
|
|
||||||
*
|
|
||||||
* @param address The I2C bus address to read or write.
|
|
||||||
* @return .
|
|
||||||
*/
|
|
||||||
int read(uint8_t address);
|
|
||||||
int write(uint8_t address, uint16_t data);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise the automatic measurement state machine and start it.
|
* Initialise the automatic measurement state machine and start it.
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ I2CSPIDriverBase *INA226::instantiate(const BusCLIArguments &cli, const BusInsta
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (cli.custom1 == 1) {
|
if (cli.custom1 == 1) {
|
||||||
if (instance->force_init() != OK) {
|
if (instance->force_init() != PX4_OK) {
|
||||||
PX4_INFO("Failed to init INA226 on bus %d, but will try again periodically.", iterator.bus());
|
PX4_INFO("Failed to init INA226 on bus %d, but will try again periodically.", iterator.bus());
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (OK != instance->init()) {
|
} else if (instance->init() != PX4_OK) {
|
||||||
delete instance;
|
delete instance;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user