RGB peripheral
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Erki 2021-03-29 23:32:35 +03:00
parent 7ca8fa01f2
commit 05ea46acd0

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