modm API documentation
modm::ButtonGroup< T > Class Template Reference

#include <modm/ui/button_group.hpp>

Classes

struct  State
 

Public Member Functions

 ButtonGroup (T repeatmask, uint16_t timeout=50, uint16_t interval=20)
 
getState (T mask) const
 Get the current (debounced) state of a key.
 
bool isPressed (T mask)
 
bool isReleased (T mask)
 Check if a key has been released.
 
bool isRepeated (T mask)
 
bool isPressedShort (T mask)
 
bool isPressedLong (T mask)
 
void update (T input)
 Update internal debounced. Call this function periodically every 5 to 10ms. More...
 

Public Attributes

State pressed
 
State released
 
State repeated
 

Detailed Description

template<std::unsigned_integral T = uint8_t>
class modm::ButtonGroup< T >

Template Parameters
TStorage type for Button states. Each button requires one bit.

Constructor & Destructor Documentation

template<std::unsigned_integral T = uint8_t>
modm::ButtonGroup< T >::ButtonGroup ( repeatmask,
uint16_t  timeout = 50,
uint16_t  interval = 20 
)
inline
Parameters
repeatmaskonly buttons listed here can be used with the methods isRepeated(), isPressedShort() and isPressedLong()
timeoutButton press period (number of update cycles) until begin of repeat
intervalButton press period (number of update cycles) for follow up repeats

Member Function Documentation

template<std::unsigned_integral T = uint8_t>
bool modm::ButtonGroup< T >::isPressed ( mask)
inline

Check if a key has been pressed. Each pressed key is only reported once.

...
while (true) {
...
if (buttons.isPressed(modm::ButtonGroup::BUTTON0)) {
// do something
}
}
template<std::unsigned_integral T = uint8_t>
bool modm::ButtonGroup< T >::isPressedLong ( mask)
inline

Get buttons which were pressed long

Warning
Use this function only in combination with isPressedShort(), otherwise it will not work correctly!
See also
isPressedShort()
template<std::unsigned_integral T = uint8_t>
bool modm::ButtonGroup< T >::isPressedShort ( mask)
inline

Get buttons which were pressed short.

modm::ButtonGroup<> buttons(modm::ButtonGroup::BUTTON0);
...
while (true) {
...
if (buttons.isPressedShort(modm::ButtonGroup::BUTTON0)) {
// do something
}
if (buttons.isPressedLong(modm::ButtonGroup::BUTTON0)) {
// do something different
}
}
Warning
Use this function only in combination with isPressedLong(), otherwise it will not work correctly!
See also
isPressedLong()
template<std::unsigned_integral T = uint8_t>
bool modm::ButtonGroup< T >::isRepeated ( mask)
inline

Check if a key has been pressed long enough such that the key repeat functionality kicks in.

After a small setup delay the key is reported being pressed subsequent calls to this function. This simulates the user repeatedly pressing and releasing the key.

modm::ButtonGroup<> buttons(modm::ButtonGroup::BUTTON0);
...
while (true) {
...
if (buttons.isPressed(modm::ButtonGroup::BUTTON0) ||
buttons.isRepeated(modm::ButtonGroup::BUTTON0))
{
// do something
}
}
See also
isPressed()
template<std::unsigned_integral T = uint8_t>
void modm::ButtonGroup< T >::update ( input)
inline

Update internal debounced. Call this function periodically every 5 to 10ms.

Parameters
inputInverted input signals

The documentation for this class was generated from the following file: