skullc-peripherals/Peripherals/Inc/peripherals_rgb.hpp
Erki 60bad24319
Some checks failed
continuous-integration/drone/push Build is failing
The great renaming, part 1
2021-06-08 23:18:56 +03:00

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_ */