Skip to content

Commit

Permalink
fix: Update std::accumulate use (#139)
Browse files Browse the repository at this point in the history
* Fix use of std::accumulate in ads7138
* Fix use of std::accumulate in controller
  • Loading branch information
finger563 authored Jan 8, 2024
1 parent 7b711fd commit aa3e909
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 4 additions & 6 deletions components/ads7138/include/ads7138.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -929,8 +929,8 @@ class Ads7138 {
logger_.info("Setting digital mode for outputs {} and inputs {}", digital_outputs_,
digital_inputs_);
uint8_t data = 0;
std::accumulate(digital_inputs_.begin(), digital_inputs_.end(), data, bit_pred);
std::accumulate(digital_outputs_.begin(), digital_outputs_.end(), data, bit_pred);
data = std::accumulate(digital_inputs_.begin(), digital_inputs_.end(), data, bit_pred);
data = std::accumulate(digital_outputs_.begin(), digital_outputs_.end(), data, bit_pred);
// don't have to do anything for analog inputs since they are the default
// state (0)
write_one_(Register::PIN_CFG, data, ec);
Expand All @@ -939,8 +939,7 @@ class Ads7138 {
void set_digital_io_direction(std::error_code &ec) {
logger_.info("Setting digital output for pins {}", digital_outputs_);
// default direction is input (0)
uint8_t data = 0;
std::accumulate(digital_outputs_.begin(), digital_outputs_.end(), data, bit_pred);
uint8_t data = std::accumulate(digital_outputs_.begin(), digital_outputs_.end(), 0, bit_pred);
write_one_(Register::GPIO_CFG, data, ec);
}

Expand All @@ -949,8 +948,7 @@ class Ads7138 {
if (mode_ == Mode::AUTONOMOUS) {
logger_.info("Setting analog inputs for autonomous mode");
// configure the analog inputs for autonomous conversion sequence
uint8_t data = 0;
std::accumulate(analog_inputs_.begin(), analog_inputs_.end(), data, bit_pred);
uint8_t data = std::accumulate(analog_inputs_.begin(), analog_inputs_.end(), 0, bit_pred);
write_one_(Register::AUTO_SEQ_CH_SEL, data, ec);
}
}
Expand Down
6 changes: 3 additions & 3 deletions components/controller/include/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ class Controller {
std::copy_if(gpio_.begin(), gpio_.end(), std::back_inserter(actual_gpios),
[](int gpio) { return gpio != -1; });

uint64_t pin_mask = 0;
std::accumulate(actual_gpios.begin(), actual_gpios.end(), pin_mask,
[](uint64_t mask, int gpio) { return mask | (1ULL << gpio); });
uint64_t pin_mask =
std::accumulate(actual_gpios.begin(), actual_gpios.end(), 0,
[](uint64_t mask, int gpio) { return mask | (1ULL << gpio); });
gpio_config_t io_config = {
.pin_bit_mask = pin_mask,
.mode = GPIO_MODE_INPUT,
Expand Down

0 comments on commit aa3e909

Please sign in to comment.