forked from Archive/PX4-Autopilot
ads1115: Probe for reset value before init, do not spam console on device lost
This commit is contained in:
parent
38505c80be
commit
da14650aa2
|
@ -39,7 +39,6 @@ int ADS1115::init()
|
|||
int ret = I2C::init();
|
||||
|
||||
if (ret != PX4_OK) {
|
||||
PX4_ERR("I2C init failed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -61,6 +60,24 @@ int ADS1115::init()
|
|||
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)
|
||||
{
|
||||
uint8_t buf[2] = {};
|
||||
|
|
|
@ -93,6 +93,9 @@
|
|||
#define CONFIG_LOW_COMP_QU_AFTER4 0x02
|
||||
#define CONFIG_LOW_COMP_QU_DISABLE 0x03
|
||||
|
||||
#define CONFIG_RESET_VALUE_HIGH 0x85
|
||||
#define CONFIG_RESET_VALUE_LOW 0x83
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
/*
|
||||
|
@ -114,6 +117,8 @@ public:
|
|||
|
||||
void RunImpl();
|
||||
|
||||
int probe() override;
|
||||
|
||||
protected:
|
||||
|
||||
void print_status() override;
|
||||
|
@ -132,6 +137,8 @@ private:
|
|||
|
||||
int _channel_cycle_count{0};
|
||||
|
||||
bool _reported_ready_last_cycle{false};
|
||||
|
||||
// ADS1115 logic part
|
||||
enum ChannelSelection {
|
||||
Invalid = -1, A0 = 0, A1, A2, A3
|
||||
|
|
|
@ -80,6 +80,11 @@ void ADS1115::RunImpl()
|
|||
_adc_report.timestamp = hrt_absolute_time();
|
||||
|
||||
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;
|
||||
ADS1115::ChannelSelection ch = cycleMeasure(&buf);
|
||||
++_channel_cycle_count;
|
||||
|
@ -118,7 +123,10 @@ void ADS1115::RunImpl()
|
|||
}
|
||||
|
||||
} 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);
|
||||
|
|
Loading…
Reference in New Issue