skullc-peripherals/Peripherals/Inc/peripherals_rgb.hpp
Erki 55a8efa579
All checks were successful
continuous-integration/drone/push Build is passing
Clang format pass
2021-04-03 17:49:25 +03:00

97 lines
1.7 KiB
C++

/*
* peripherals_rgb.hpp
*
* Created on: Mar 29, 2021
* Author: erki
*/
#ifndef PERIPHERALS_INC_PERIPHERALS_RGB_HPP_
#define PERIPHERALS_INC_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 /* PERIPHERALS_INC_PERIPHERALS_RGB_HPP_ */