YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
led_interface.h
1// ---------------------------------------------
2// This file is part of
3// _ _ __ _ _ __ __
4// ( \/ ) /__\ ( )_( ) /__\ ( )
5// \ / /(__)\ ) _ ( /(__)\ )(__
6// (__)(__)(__)(_) (_)(__)(__)(____)
7//
8// Yet Another HW Abstraction Library
9// Copyright (C) Andreas Terstegge
10// BSD Licensed (see file LICENSE)
11//
12// ---------------------------------------------
13//
14// This file defines a generic and abstract C++
15// interfaces for different kinds of LEDs
16
17#ifndef _LED_INTERFACE_H_
18#define _LED_INTERFACE_H_
19
20#include <cstdint>
21
22// Plain one-color LED, typically connected to a GPIO pin
24public:
25 // Switch LED on and off
26 virtual void on() = 0;
27 virtual void off() = 0;
28 virtual void toggle() = 0;
29 virtual bool is_on() = 0;
30
31 // Assignment operator for easier access
32 inline void operator = (bool v) {
33 if (v) on(); else off();
34 }
35
36protected:
37 virtual ~led_interface() = default;
38};
39
40// Plain one-color LED with brigthness control
42public:
43 // Set LED brightness (0 min, 255 max)
44 virtual void set_brightness(uint8_t b) = 0;
45
46 // Use the pre-defined bool assignment operator
47 using led_interface::operator= ;
48
49protected:
50 ~led_dim_interface() override = default;
51};
52
53// RGB LED
55public:
56 // Set color of LED (24-bit RGB value)
57 virtual void set_color(uint32_t rgb) = 0;
58
59 // Set the color of the LED if it is used as
60 // a plain on/off LED (24-bit RGB value)
61 virtual void set_on_color(uint32_t rgb) = 0;
62
63 // Use the pre-defined bool assignment operator
64 using led_interface::operator= ;
65
66 // RGB Assignment operator for easier access. We
67 // use int as parameter type, so we don't need
68 // a cast when writing rgb_led = 0x121212;
69 inline void operator = (int rgb) {
70 set_color(rgb);
71 }
72
73protected:
74 ~led_rgb_interface() override = default;
75};
76
77#endif // _LED_INTERFACE_H_