mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-24 04:23:33 +08:00
ads1115: Probe for reset value before init, do not spam console on device lost
This commit is contained in:
committed by
Thomas Stastny
parent
38505c80be
commit
da14650aa2
@@ -39,7 +39,6 @@ int ADS1115::init()
|
|||||||
int ret = I2C::init();
|
int ret = I2C::init();
|
||||||
|
|
||||||
if (ret != PX4_OK) {
|
if (ret != PX4_OK) {
|
||||||
PX4_ERR("I2C init failed");
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +60,24 @@ int ADS1115::init()
|
|||||||
return PX4_OK;
|
return PX4_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ADS1115::probe()
|
||||||
|
{
|
||||||
|
uint8_t buf[2] = {};
|
||||||
|
int ret = readReg(ADDRESSPOINTER_REG_CONFIG, buf, 2);
|
||||||
|
|
||||||
|
if (ret != PX4_OK) {
|
||||||
|
DEVICE_DEBUG("readReg failed (%i)", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buf[0] != CONFIG_RESET_VALUE_HIGH || buf[1] != CONFIG_RESET_VALUE_LOW) {
|
||||||
|
DEVICE_DEBUG("ADS1115 not found");
|
||||||
|
return PX4_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PX4_OK;
|
||||||
|
}
|
||||||
|
|
||||||
int ADS1115::setChannel(ADS1115::ChannelSelection ch)
|
int ADS1115::setChannel(ADS1115::ChannelSelection ch)
|
||||||
{
|
{
|
||||||
uint8_t buf[2] = {};
|
uint8_t buf[2] = {};
|
||||||
|
|||||||
@@ -93,6 +93,9 @@
|
|||||||
#define CONFIG_LOW_COMP_QU_AFTER4 0x02
|
#define CONFIG_LOW_COMP_QU_AFTER4 0x02
|
||||||
#define CONFIG_LOW_COMP_QU_DISABLE 0x03
|
#define CONFIG_LOW_COMP_QU_DISABLE 0x03
|
||||||
|
|
||||||
|
#define CONFIG_RESET_VALUE_HIGH 0x85
|
||||||
|
#define CONFIG_RESET_VALUE_LOW 0x83
|
||||||
|
|
||||||
using namespace time_literals;
|
using namespace time_literals;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -114,6 +117,8 @@ public:
|
|||||||
|
|
||||||
void RunImpl();
|
void RunImpl();
|
||||||
|
|
||||||
|
int probe() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void print_status() override;
|
void print_status() override;
|
||||||
@@ -132,6 +137,8 @@ private:
|
|||||||
|
|
||||||
int _channel_cycle_count{0};
|
int _channel_cycle_count{0};
|
||||||
|
|
||||||
|
bool _reported_ready_last_cycle{false};
|
||||||
|
|
||||||
// ADS1115 logic part
|
// ADS1115 logic part
|
||||||
enum ChannelSelection {
|
enum ChannelSelection {
|
||||||
Invalid = -1, A0 = 0, A1, A2, A3
|
Invalid = -1, A0 = 0, A1, A2, A3
|
||||||
|
|||||||
@@ -80,6 +80,11 @@ void ADS1115::RunImpl()
|
|||||||
_adc_report.timestamp = hrt_absolute_time();
|
_adc_report.timestamp = hrt_absolute_time();
|
||||||
|
|
||||||
if (isSampleReady()) { // whether ADS1115 is ready to be read or not
|
if (isSampleReady()) { // whether ADS1115 is ready to be read or not
|
||||||
|
if (!_reported_ready_last_cycle) {
|
||||||
|
PX4_INFO("ADS1115: reported ready");
|
||||||
|
_reported_ready_last_cycle = true;
|
||||||
|
}
|
||||||
|
|
||||||
int16_t buf;
|
int16_t buf;
|
||||||
ADS1115::ChannelSelection ch = cycleMeasure(&buf);
|
ADS1115::ChannelSelection ch = cycleMeasure(&buf);
|
||||||
++_channel_cycle_count;
|
++_channel_cycle_count;
|
||||||
@@ -118,7 +123,10 @@ void ADS1115::RunImpl()
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
PX4_WARN("ADS1115 not ready!");
|
if (_reported_ready_last_cycle) {
|
||||||
|
_reported_ready_last_cycle = false;
|
||||||
|
PX4_ERR("ADS1115: not ready. Device lost?");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
perf_end(_cycle_perf);
|
perf_end(_cycle_perf);
|
||||||
|
|||||||
Reference in New Issue
Block a user