#pragma once #include "Selector.hpp" #include #include #include BEGIN_CS_NAMESPACE template class GenericManyButtonsSelector : public GenericSelector { using Parent = GenericSelector; public: GenericManyButtonsSelector(Selectable &selectable, const Callback &callback, const PinList &buttonPins) : GenericSelector {selectable, callback}, buttons(AH::copyAs(buttonPins)) {} void begin() override { Parent::begin(); for (auto &btn : buttons) btn.begin(); } void update() override { Parent::update(); for (setting_t i = 0; i < N; i++) if (buttons[i].update() == AH::Button::Falling && buttons[this->get()].getState() != AH::Button::Pressed) this->set(i); } void invert() { for (auto &btn : buttons) btn.invert(); } private: AH::Array buttons; }; // -------------------------------------------------------------------------- // /** * @brief Selector that reads from @f$ N @f$ buttons. * * Pressing the @f$ n @f$-th button selects the @f$ n @f$-th setting. * * @htmlonly * * @endhtmlonly * * @ingroup Selectors * * @tparam N * The number of settings. */ template class ManyButtonsSelector : public GenericManyButtonsSelector { public: ManyButtonsSelector(Selectable &selectable, const PinList &buttonPins) : GenericManyButtonsSelector { selectable, {}, buttonPins, } {} }; END_CS_NAMESPACE