Enhance DaliDT8: add methods for temporary RGBWA color control and improve preferred color type resolution

Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
Tony
2026-06-15 17:37:35 +08:00
parent 5e02d9baaa
commit 34d77aa9fe
2 changed files with 40 additions and 0 deletions
+4
View File
@@ -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,
+36
View File
@@ -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<double>(R) / 255.0,
static_cast<double>(G) / 255.0,
static_cast<double>(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);
}