From da9feeb699ff89df63d5ad9e5e79f3054e71b6db Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Tue, 9 Jun 2020 17:38:09 +0200 Subject: [PATCH] INA226: refactor spacing and return codes --- src/drivers/power_monitor/ina226/ina226.cpp | 24 +++++++++---------- src/drivers/power_monitor/ina226/ina226.h | 14 +++-------- .../power_monitor/ina226/ina226_main.cpp | 4 ++-- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/src/drivers/power_monitor/ina226/ina226.cpp b/src/drivers/power_monitor/ina226/ina226.cpp index aca2c9f5d3..5b5c30f2d3 100644 --- a/src/drivers/power_monitor/ina226/ina226.cpp +++ b/src/drivers/power_monitor/ina226/ina226.cpp @@ -112,7 +112,7 @@ int INA226::read(uint8_t address) int ret = transfer(&address, 1, &data.b[0], sizeof(data.b)); - if (OK != ret) { + if (ret != PX4_OK) { perf_count(_comms_errors); PX4_DEBUG("i2c::transfer returned %d", ret); return -1; @@ -133,7 +133,7 @@ INA226::init() int ret = PX4_ERROR; /* do I2C init (and probe) first */ - if (I2C::init() != OK) { + if (I2C::init() != PX4_OK) { return ret; } @@ -151,13 +151,13 @@ INA226::init() ret = write(INA226_REG_CONFIGURATION, _config); } else { - ret = OK; + ret = PX4_OK; } start(); _sensor_ok = true; - _initialized = ret == OK; + _initialized = ret == PX4_OK; return ret; } @@ -196,13 +196,13 @@ INA226::probe() return -1; } - return OK; + return PX4_OK; } int INA226::measure() { - int ret = OK; + int ret = PX4_OK; if (_mode_triggered) { ret = write(INA226_REG_CONFIGURATION, _config); @@ -266,7 +266,7 @@ INA226::collect() _actuator_controls.control[actuator_controls_s::INDEX_THROTTLE] ); - ret = OK; + ret = PX4_OK; } else { _battery.updateBatteryStatus( @@ -281,7 +281,7 @@ INA226::collect() ret = -1; } - if (ret != OK) { + if (ret != PX4_OK) { PX4_DEBUG("error reading from sensor: %d", ret); perf_count(_comms_errors); } @@ -309,9 +309,8 @@ INA226::RunImpl() { if (_initialized) { if (_collect_phase) { - /* perform collection */ - if (OK != collect()) { + if (collect() != PX4_OK) { perf_count(_collection_errors); /* if error restart the measurement state machine */ start(); @@ -322,7 +321,6 @@ INA226::RunImpl() _collect_phase = !_mode_triggered; if (_measure_interval > INA226_CONVERSION_INTERVAL) { - /* schedule a fresh cycle call when we are ready to measure again */ ScheduleDelayed(_measure_interval - INA226_CONVERSION_INTERVAL); return; @@ -332,7 +330,7 @@ INA226::RunImpl() /* Measurement phase */ /* Perform measurement */ - if (OK != measure()) { + if (measure() != PX4_OK) { perf_count(_measure_errors); } @@ -353,7 +351,7 @@ INA226::RunImpl() 0.0f ); - if (init() != OK) { + if (init() != PX4_OK) { ScheduleDelayed(INA226_INIT_RETRY_INTERVAL_US); } } diff --git a/src/drivers/power_monitor/ina226/ina226.h b/src/drivers/power_monitor/ina226/ina226.h index 06f2c8846e..7a27cb27d0 100644 --- a/src/drivers/power_monitor/ina226/ina226.h +++ b/src/drivers/power_monitor/ina226/ina226.h @@ -129,7 +129,7 @@ public: * 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. * - * @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(); @@ -171,16 +171,8 @@ private: uORB::Subscription _actuators_sub{ORB_ID(actuator_controls_0)}; uORB::Subscription _parameters_sub{ORB_ID(parameter_update)}; - - /** - * 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); + int read(uint8_t address); + int write(uint8_t address, uint16_t data); /** * Initialise the automatic measurement state machine and start it. diff --git a/src/drivers/power_monitor/ina226/ina226_main.cpp b/src/drivers/power_monitor/ina226/ina226_main.cpp index 81e7b961e7..c2471ce484 100644 --- a/src/drivers/power_monitor/ina226/ina226_main.cpp +++ b/src/drivers/power_monitor/ina226/ina226_main.cpp @@ -16,11 +16,11 @@ I2CSPIDriverBase *INA226::instantiate(const BusCLIArguments &cli, const BusInsta } 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()); } - } else if (OK != instance->init()) { + } else if (instance->init() != PX4_OK) { delete instance; return nullptr; }