Skip to content

Commit

Permalink
Config: using C++ constexpr sort
Browse files Browse the repository at this point in the history
  • Loading branch information
PBrunot committed Jul 21, 2024
1 parent 3899ca5 commit 5586f17
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions include/PinsConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,28 @@ namespace fabomatic
pins.led.blue_pin,
pins.buttons.factory_defaults_pin};

// No constexpr std::sort available
for (auto i = 0; i < pin_nums.size(); ++i)
// C++20 provides constexpr sorting
std::sort(pin_nums.begin(), pin_nums.end());

uint8_t previous = NO_PIN;
for (const auto pin : pin_nums)
{
if (pin_nums[i] == NO_PIN)
if (pin == NO_PIN)
{
continue;
}

for (auto j = i + 1; j < pin_nums.size(); ++j)
if (pin == previous)
{
if (pin_nums[i] == pin_nums[j])
return false;
return false;
}

previous = pin;

// Check pins numbers are convertible to gpio_num_t
static_cast<gpio_num_t>(pin_nums[i]);
[[maybe_unused]] auto test = static_cast<gpio_num_t>(pin);
}

return true;
}

Expand Down

0 comments on commit 5586f17

Please sign in to comment.