semf
digitalout.cpp
Go to the documentation of this file.
1
12
13namespace semf
14{
15DigitalOut::DigitalOut(Gpio& gpio, bool inverted)
16: m_gpio(gpio),
17 m_inverted(inverted)
18{
19}
20
21void DigitalOut::setInverted(bool inverted)
22{
23 SEMF_INFO("set inverted to %d", inverted);
24 m_inverted = inverted;
25}
26
28{
29 if (state == Low)
30 {
31 if (!m_inverted)
32 {
33 SEMF_INFO("reset gpio, State is LOW");
34 m_gpio.reset();
35 }
36 else
37 {
38 SEMF_INFO("set gpio, State is LOW");
39 m_gpio.set();
40 }
41 }
42 else
43 {
44 if (!m_inverted)
45 {
46 SEMF_INFO("set gpio, State is HIGH");
47 m_gpio.set();
48 }
49 else
50 {
51 SEMF_INFO("reset gpio, State is HIGH");
52 m_gpio.reset();
53 }
54 }
55}
56
58{
59 set(Low);
60}
61
63{
64 SEMF_INFO("toggle");
65 set(static_cast<State>(!m_gpio.state()));
66}
67
69{
70 return static_cast<State>(m_gpio.state());
71}
72} /* namespace semf */
State state() const override
Gets the present/current state of a GPIO pin.
Definition: digitalout.cpp:68
void set(State state=High) override
Sets the output level of a GPIO pin.
Definition: digitalout.cpp:27
void reset() override
Definition: digitalout.cpp:57
DigitalOut(Gpio &gpio, bool inverted=false)
Constructor.
Definition: digitalout.cpp:15
void setInverted(bool inverted) override
Configures the inversion of the output.
Definition: digitalout.cpp:21
void toggle() override
Definition: digitalout.cpp:62
Interface class for using a GPIO pin of the microcontroller.
Definition: gpio.h:23
virtual void set()=0
virtual bool state() const =0
Returns the current state of the pin.
virtual void reset()=0
#define SEMF_INFO(...)
Definition: debug.h:41