Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions components/ads7138/include/ads7138.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,13 @@ class Ads7138 {
*/
std::vector<float> get_all_mv() {
std::lock_guard<std::recursive_mutex> lock(mutex_);
std::vector<float> values;
// TODO: handle the non-autonomous case
auto raw_values = read_recent_all();
std::vector<float> values(analog_inputs_.size());
// convert the raw values (uint16_t) to mv (float)
std::transform(raw_values.begin(), raw_values.end(), std::back_inserter(values),
[this](uint16_t raw) { return raw_to_mv(raw); });
for (int i = 0; i < raw_values.size(); i++) {
values[i] = raw_to_mv(raw_values[i]);
}
return values;
}

Expand All @@ -255,9 +256,9 @@ class Ads7138 {
// TODO: handle the non-autonomous case
auto raw_values = read_mapped_recent_all();
// convert the raw values (uint16_t) to mv (float)
std::transform(
raw_values.begin(), raw_values.end(), std::inserter(values, values.end()),
[this](const auto &pair) { return std::make_pair(pair.first, raw_to_mv(pair.second)); });
for (auto &[channel, raw] : raw_values) {
values[channel] = raw_to_mv(raw);
}
return values;
}

Expand Down Expand Up @@ -925,16 +926,17 @@ class Ads7138 {
return {};
}
logger_.info("Reading recent values for all channels");
std::vector<uint16_t> values;
std::vector<uint16_t> values(analog_inputs_.size());
uint8_t raw_values[16];
read_many_(Register::RECENT_CH0_LSB, raw_values, 16);
int analog_index = 0;
// only pull out the ones that were configured as analog inputs
for (int i = 0; i < 8; i++) {
if (is_analog_input(static_cast<Channel>(i))) {
// read both the LSB AND MSB registers and combine them (lsb is first)
uint8_t lsb = raw_values[i * 2];
uint8_t msb = raw_values[i * 2 + 1];
values.push_back((msb << 8) | lsb);
values[analog_index++] = (msb << 8) | lsb;
}
}
return values;
Expand Down Expand Up @@ -984,16 +986,17 @@ class Ads7138 {
return {};
}
logger_.info("Reading max values for all channels");
std::vector<uint16_t> values;
std::vector<uint16_t> values(analog_inputs_.size());
uint8_t raw_values[16];
int analog_index = 0;
read_many_(Register::MAX_CH0_LSB, raw_values, 16);
// only pull out the ones that were configured as analog inputs
for (int i = 0; i < 8; i++) {
if (is_analog_input(static_cast<Channel>(i))) {
// read both the LSB AND MSB registers and combine them (lsb first)
uint8_t lsb = raw_values[i * 2];
uint8_t msb = raw_values[i * 2 + 1];
values.push_back((msb << 8) | lsb);
values[analog_index++] = (msb << 8) | lsb;
}
}
return values;
Expand Down Expand Up @@ -1021,16 +1024,17 @@ class Ads7138 {
return {};
}
logger_.info("Reading min values for all channels");
std::vector<uint16_t> values;
std::vector<uint16_t> values(analog_inputs_.size());
uint8_t raw_values[16];
int analog_index = 0;
read_many_(Register::MIN_CH0_LSB, raw_values, 16);
// only pull out the ones that were configured as analog inputs
for (int i = 0; i < 8; i++) {
if (is_analog_input(static_cast<Channel>(i))) {
// read both the LSB AND MSB registers and combine them (lsb first)
uint8_t lsb = raw_values[i * 2];
uint8_t msb = raw_values[i * 2 + 1];
values.push_back((msb << 8) | lsb);
values[analog_index++] = (msb << 8) | lsb;
}
}
return values;
Expand Down