Rpi-hw  0.7.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
rpihw::keypad::base Class Referenceabstract

Generic keypad controller. More...

#include <base.hpp>

+ Inheritance diagram for rpihw::keypad::base:

Public Types

typedef std::map< uint8_t,
uint8_t > 
T_Keymap
 The keymap type.
 

Public Member Functions

 base (size_t total, std::initializer_list< uint8_t > pins)
 Constructor method. More...
 
 base (size_t total, std::initializer_list< uint8_t > pins, const std::vector< uint8_t > &keymap)
 Constructor method. More...
 
 base (size_t total, const std::vector< uint8_t > &pins)
 Constructor method. More...
 
 base (size_t total, const std::vector< uint8_t > &pins, const std::vector< uint8_t > &keymap)
 Constructor method. More...
 
virtual ~base ()
 Destructor method.
 
virtual void setKeymap (const std::vector< uint8_t > &keymap)
 Sets the keymap. More...
 
virtual void addEventListener (T_EventListener listener)
 Sets the keypad event listener. More...
 
virtual void setRefreshRate (float frequency)
 Sets the frequency with which buttons are read. More...
 
virtual float getRefreshRate () const
 Returns the frequency with which buttons are read.
 
virtual bool state (size_t index) const
 Returns a button state. More...
 
virtual bool pressed (size_t index) const
 Checks if a button is pressed. More...
 
virtual bool released (size_t index) const
 Checks if a button is released. More...
 
virtual const std::vector< bool > & state () const
 Returns the list of button states.
 
virtual bool keyState (uint8_t key) const
 Returns a key state. More...
 
virtual bool keyPressed (uint8_t key) const
 Checks if a key is pressed. More...
 
virtual bool keyReleased (uint8_t key) const
 Checks if a key is released. More...
 
virtual std::vector< uint8_t > keyState () const
 Returns the list of pressed keys.
 
virtual size_t numOfKeys () const
 Returns the number of keys.
 

Protected Member Functions

virtual void update ()=0
 Updates the state of buttons (threading function).
 

Protected Attributes

size_t m_nkeys
 Number of the keys.
 
iface::inputm_input
 Buttons input interface.
 
T_Keymap m_keymap
 The keymap vector.
 
std::vector< bool > m_keystate
 Button states (0 = up, 1 = down).
 
std::vector< bool > m_pressed
 Pressed buttons (0 = none, 1 = pressed).
 
std::vector< bool > m_released
 Pressed buttons (0 = none, 1 = released).
 
float m_frequency
 The refresh rate.
 
std::thread * m_thread
 Updating thread.
 
std::mutex * m_mutex
 Mutex of the updating thread.
 
T_EventListener m_event_listener
 The keypad event listener.
 

Detailed Description

Generic keypad controller.

Examples:
keypad/16keys2.cpp.

Definition at line 59 of file base.hpp.

Constructor & Destructor Documentation

rpihw::keypad::base::base ( size_t  total,
std::initializer_list< uint8_t >  pins 
)

Constructor method.

Parameters
[in]totalNumber of the buttons.
[in]pinsSequence of uint8_t containing the input GPIOs.
rpihw::keypad::base::base ( size_t  total,
std::initializer_list< uint8_t >  pins,
const std::vector< uint8_t > &  keymap 
)

Constructor method.

Parameters
[in]totalNumber of the buttons.
[in]pinsSequence of uint8_t containing the input GPIOs.
[in]keymapThe keymap vector.
rpihw::keypad::base::base ( size_t  total,
const std::vector< uint8_t > &  pins 
)

Constructor method.

Parameters
[in]totalNumber of the buttons.
[in]pinsVector containing the input GPIO pins.
rpihw::keypad::base::base ( size_t  total,
const std::vector< uint8_t > &  pins,
const std::vector< uint8_t > &  keymap 
)

Constructor method.

Parameters
[in]totalNumber of the buttons.
[in]pinsVector containing the input GPIO pins.
[in]keymapThe keymap vector.

Member Function Documentation

void rpihw::keypad::base::addEventListener ( T_EventListener  listener)
inlinevirtual

Sets the keypad event listener.

Parameters
[in]listenerThe event listener.

Definition at line 30 of file base-inl.hpp.

virtual bool rpihw::keypad::base::keyPressed ( uint8_t  key) const
virtual

Checks if a key is pressed.

Parameters
[in]keyThe key button.
Returns
Return true if button is pressed.
virtual bool rpihw::keypad::base::keyReleased ( uint8_t  key) const
virtual

Checks if a key is released.

Parameters
[in]keyThe key button.
Returns
Return true if button is released.
virtual bool rpihw::keypad::base::keyState ( uint8_t  key) const
virtual

Returns a key state.

Parameters
[in]keyThe key button.
Returns
The state of the button.
Examples:
keypad/16keys1.cpp, and keypad/16keys2.cpp.
virtual bool rpihw::keypad::base::pressed ( size_t  index) const
virtual

Checks if a button is pressed.

Parameters
[in]indexThe index position of the input pin.
Returns
Return true if button is pressed.
virtual bool rpihw::keypad::base::released ( size_t  index) const
virtual

Checks if a button is released.

Parameters
[in]indexThe index position of the input pin.
Returns
Return true if button is released.
virtual void rpihw::keypad::base::setKeymap ( const std::vector< uint8_t > &  keymap)
virtual

Sets the keymap.

Parameters
[in]keymapThe keymap vector.
void rpihw::keypad::base::setRefreshRate ( float  frequency)
inlinevirtual

Sets the frequency with which buttons are read.

Parameters
[in]frequencyThe refresh rate in Hz.

Definition at line 37 of file base-inl.hpp.

virtual bool rpihw::keypad::base::state ( size_t  index) const
virtual

Returns a button state.

Parameters
[in]indexThe index position of the input pin.
Returns
The state of the button.
Examples:
keypad/12keys1.cpp.

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