PushButton/GPIO¶
Goal¶
Create a PushButton
implementation PushButtonGPIO
that uses
libgpiod
to read the switch states.
How¶
class PushButtonGPIO : public PushButton
{
public:
PushButtonGPIO(const std::string& gpiodevice, int line_number);
...
};
gpiodevice
is for example/dev/gpiochip0
line_number
is the number of the GPIO line (see for example the Raspberry Pi pinout diagram)
Use the libgpiod
library to implement the get_state()
method.
Testing¶
Real hardware cannot be tested using unit tests (at least not
easily). Write a test program (in tests/
) that uses
PushButtonGPIO
to read the switch state and output its value.