97 lines
1.6 KiB
C++
97 lines
1.6 KiB
C++
/*
|
|
* peripherals_rgb.hpp
|
|
*
|
|
* Created on: Mar 29, 2021
|
|
* Author: erki
|
|
*/
|
|
|
|
#ifndef SKULLC_PERIPHERALS_RGB_HPP_
|
|
#define SKULLC_PERIPHERALS_RGB_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;
|
|
}
|
|
}
|
|
};
|
|
|
|
}// namespace Peripherals
|
|
|
|
#endif /* SKULLC_PERIPHERALS_RGB_HPP_ */
|