YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
include
interface
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
23
class
led_interface
{
24
public
:
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
36
protected
:
37
virtual
~led_interface
() =
default
;
38
};
39
40
// Plain one-color LED with brigthness control
41
class
led_dim_interface
:
public
led_interface
{
42
public
:
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
49
protected
:
50
~led_dim_interface
()
override
=
default
;
51
};
52
53
// RGB LED
54
class
led_rgb_interface
:
public
led_interface
{
55
public
:
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
73
protected
:
74
~led_rgb_interface
()
override
=
default
;
75
};
76
77
#endif
// _LED_INTERFACE_H_
led_dim_interface
Definition
led_interface.h:41
led_interface
Definition
led_interface.h:23
led_rgb_interface
Definition
led_interface.h:54
Generated by
1.12.0