RTLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
led.h
Go to the documentation of this file.
1 /*
2  * This file is part of RTLib.
3  *
4  * Copyright (C) 2017-2018 Derppening <david.18.19.21@gmail.com>
5  *
6  * RTLib is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * RTLib is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with RTLib. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef RTLIB_LIB_LED_H_
21 #define RTLIB_LIB_LED_H_
22 
23 #include <cstdint>
24 
25 #include "config/config.h"
26 #include "core/gpio.h"
27 
28 static_assert(LIB_USE_LED > 0, "Led library is disabled in your configuration.");
29 
36 class Led {
37  public:
41  struct Config {
47  uint8_t id = 0;
51  bool polarity = false;
52  };
53 
59  explicit Led(const Config& config);
60 
64  ~Led() = default;
65 
71  Led(Led&& other) noexcept = default;
78  Led& operator=(Led&& other) noexcept = default;
79 
86  Led(const Led&) = delete;
93  Led& operator=(const Led&) = delete;
94 
103  void SetEnable(bool flag);
107  void Switch();
108 
109  protected:
113  CORE_NS::GPIO* GetGpio() { return &gpio_; }
114 
115  private:
116  CORE_NS::GPIO gpio_;
117  bool polarity_;
118 };
119 
120 #endif // RTLIB_LIB_LED_H_
Helper file for selecting which GPIO class to enable.
Configuration for LED.
Definition: led.h:41
HAL implementation for LEDs.
Definition: led.h:36
Helper file for selecting device configurations.
~Led()=default
Default trivial destructor.
void Switch()
Toggles the state of the LED, i.e. On -> Off, vice versa.
Definition: led.cpp:68
CORE_NS::GPIO * GetGpio()
Definition: led.h:113
void SetEnable(bool flag)
Sets the state of the LED.
Definition: led.cpp:64
bool polarity
If true, LED is assumed to be active low.
Definition: led.h:51
Led(const Config &config)
Default constructor for LED.
Definition: led.cpp:54