diff --git a/include/dt8.hpp b/include/dt8.hpp index 9f73b97..d9ab60e 100644 --- a/include/dt8.hpp +++ b/include/dt8.hpp @@ -161,6 +161,10 @@ class DaliDT8 { Dt8PreferredColorType preferredColorType = Dt8PreferredColorType::xy); bool setColourRGBPreferred(int addr, int r, int g, int b, Dt8PreferredColorType preferredColorType = Dt8PreferredColorType::xy); + bool setTemporaryColourRGBWAPreferred(int addr, int r, int g, int b, int w, int amber, + Dt8PreferredColorType preferredColorType = Dt8PreferredColorType::rgbwaf); + bool setColourRGBWAPreferred(int addr, int r, int g, int b, int w, int amber, + Dt8PreferredColorType preferredColorType = Dt8PreferredColorType::rgbwaf); bool setColourRGBW(int addr, int r, int g, int b, int w); bool setColourRGBCW(int addr, int r, int g, int b, int coolWhite, int warmWhite); bool setColourRGBWAF(int addr, int r, int g, int b, int w, int amber, int freecolour, diff --git a/src/dt8.cpp b/src/dt8.cpp index 68ee49b..39fcff5 100644 --- a/src/dt8.cpp +++ b/src/dt8.cpp @@ -8,6 +8,7 @@ namespace { constexpr int kRgbControl = 0x07; constexpr int kRgbWControl = 0x0F; +constexpr int kRgbWaControl = 0x1F; constexpr int kRgbCwControl = 0x1F; constexpr int kRgbWafControl = 0x3F; @@ -37,6 +38,13 @@ DaliDT8::DaliDT8(DaliBase& base) : base_(base) {} Dt8PreferredColorType DaliDT8::resolvePreferredColorType( int address, Dt8PreferredColorType preferredColorType) { if (address < 0 || address > 63) return preferredColorType; + const auto discovery = base_.discoverDeviceTypes(address); + if (!discovery.has_value()) return preferredColorType; + if (std::find(discovery->types.begin(), discovery->types.end(), 8) == + discovery->types.end()) { + return preferredColorType; + } + const auto features = getColorTypeFeature(address); if (!features.has_value()) return preferredColorType; @@ -410,6 +418,34 @@ bool DaliDT8::setColourRGBPreferred(int addr, int r, int g, int b, activateTemporaryColour(addr); } +bool DaliDT8::setTemporaryColourRGBWAPreferred(int addr, int r, int g, int b, int w, int amber, + Dt8PreferredColorType preferredColorType) { + const int R = std::clamp(r, 0, 255); + const int G = std::clamp(g, 0, 255); + const int B = std::clamp(b, 0, 255); + const int W = std::clamp(w, 0, 255); + const int A = std::clamp(amber, 0, 255); + const auto resolved = resolvePreferredColorType(addr, preferredColorType); + + switch (resolved) { + case Dt8PreferredColorType::rgbwaf: + return setTemporaryRGBWAFDimLevels(addr, R, G, B, W, A, 254, kRgbWaControl); + case Dt8PreferredColorType::xy: { + const auto xy = DaliColor::rgb2xy(static_cast(R) / 255.0, + static_cast(G) / 255.0, + static_cast(B) / 255.0); + return setTemporaryColourXY(addr, xy[0], xy[1]); + } + } + return false; +} + +bool DaliDT8::setColourRGBWAPreferred(int addr, int r, int g, int b, int w, int amber, + Dt8PreferredColorType preferredColorType) { + return setTemporaryColourRGBWAPreferred(addr, r, g, b, w, amber, preferredColorType) && + activateTemporaryColour(addr); +} + bool DaliDT8::setColourRGBW(int addr, int r, int g, int b, int w) { return setColourRGBWAF(addr, r, g, b, w, 254, 254, kRgbWControl); }