This commit is contained in:
parent
7ca8fa01f2
commit
05ea46acd0
101
Peripherals/Inc/peripherals_rgb.hpp
Normal file
101
Peripherals/Inc/peripherals_rgb.hpp
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* peripherals_rgb.hpp
|
||||||
|
*
|
||||||
|
* Created on: Mar 29, 2021
|
||||||
|
* Author: erki
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PERIPHERALS_INC_PERIPHERALS_RGB_HPP_
|
||||||
|
#define PERIPHERALS_INC_PERIPHERALS_RGB_HPP_
|
||||||
|
|
||||||
|
#include "peripherals_io.hpp"
|
||||||
|
|
||||||
|
namespace Peripherals
|
||||||
|
{
|
||||||
|
|
||||||
|
enum class RgbColor : std::uint32_t
|
||||||
|
{
|
||||||
|
OFF,
|
||||||
|
RED,
|
||||||
|
GREEN,
|
||||||
|
BLUE,
|
||||||
|
CYAN,
|
||||||
|
PINK,
|
||||||
|
YELLOW,
|
||||||
|
WHITE
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct Rgb
|
||||||
|
{
|
||||||
|
using IOType = T;
|
||||||
|
|
||||||
|
IOType red;
|
||||||
|
IOType green;
|
||||||
|
IOType blue;
|
||||||
|
|
||||||
|
RgbColor color = RgbColor::OFF;
|
||||||
|
|
||||||
|
Rgb() = delete;
|
||||||
|
Rgb(const IOType& r, const IOType& g, const IOType& b)
|
||||||
|
: red(r)
|
||||||
|
, green(g)
|
||||||
|
, blue(b)
|
||||||
|
{
|
||||||
|
Set(RgbColor::OFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Set(const RgbColor& new_color)
|
||||||
|
{
|
||||||
|
color = new_color;
|
||||||
|
|
||||||
|
switch (color)
|
||||||
|
{
|
||||||
|
case RgbColor::OFF:
|
||||||
|
red.Set(false);
|
||||||
|
green.Set(false);
|
||||||
|
blue.Set(false);
|
||||||
|
break;
|
||||||
|
case RgbColor::RED:
|
||||||
|
red.Set(true);
|
||||||
|
green.Set(false);
|
||||||
|
blue.Set(false);
|
||||||
|
break;
|
||||||
|
case RgbColor::GREEN:
|
||||||
|
red.Set(false);
|
||||||
|
green.Set(true);
|
||||||
|
blue.Set(false);
|
||||||
|
break;
|
||||||
|
case RgbColor::BLUE:
|
||||||
|
red.Set(false);
|
||||||
|
green.Set(false);
|
||||||
|
blue.Set(true);
|
||||||
|
break;
|
||||||
|
case RgbColor::CYAN:
|
||||||
|
red.Set(false);
|
||||||
|
green.Set(true);
|
||||||
|
blue.Set(true);
|
||||||
|
break;
|
||||||
|
case RgbColor::PINK:
|
||||||
|
red.Set(true);
|
||||||
|
green.Set(false);
|
||||||
|
blue.Set(true);
|
||||||
|
break;
|
||||||
|
case RgbColor::YELLOW:
|
||||||
|
red.Set(true);
|
||||||
|
green.Set(true);
|
||||||
|
blue.Set(false);
|
||||||
|
break;
|
||||||
|
case RgbColor::WHITE:
|
||||||
|
red.Set(true);
|
||||||
|
green.Set(true);
|
||||||
|
blue.Set(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* PERIPHERALS_INC_PERIPHERALS_RGB_HPP_ */
|
||||||
Loading…
x
Reference in New Issue
Block a user