Add support for power-on and system failure level snapshots in DaliDT8

This commit is contained in:
Tony
2026-04-29 19:39:23 +08:00
parent 4c20fc2ae3
commit 84b3d29ed8
2 changed files with 59 additions and 0 deletions
+17
View File
@@ -66,6 +66,17 @@ struct SceneColorReport {
bool hasColorTemperature() const { return colorTemperature.has_value(); }
};
struct Dt8LevelColorReport {
int level = 0;
int colorTypeValue = 0;
std::vector<double> xy;
std::optional<int> colorTemperature;
ColorType colorType() const { return ColorType(colorTypeValue); }
bool hasXy() const { return xy.size() == 2; }
bool hasColorTemperature() const { return colorTemperature.has_value(); }
};
enum class Dt8SceneStoreColorMode {
disabled,
colorTemperature,
@@ -176,6 +187,10 @@ class DaliDT8 {
bool storeSceneSnapshot(int address, int scene, int brightness,
Dt8SceneStoreColorMode colorMode = Dt8SceneStoreColorMode::disabled,
int colorTemperature = 0, int red = 0, int green = 0, int blue = 0);
bool storePowerOnLevelSnapshot(int address, int level);
bool storeSystemFailureLevelSnapshot(int address, int level);
std::optional<Dt8LevelColorReport> getPowerOnLevelColorReport(int a);
std::optional<Dt8LevelColorReport> getSystemFailureLevelColorReport(int a);
bool storeColourTempLimitRaw(int a, int limitType, int mirek);
bool storeColourTempLimit(int a, int limitType, int kelvin);
bool setGearAutoActivate(int a, bool enable);
@@ -189,5 +204,7 @@ class DaliDT8 {
std::optional<int> getExtendedVersion(int a);
private:
std::optional<Dt8LevelColorReport> buildLevelColorReport(int a, std::optional<int> level);
DaliBase& base_;
};
+42
View File
@@ -328,6 +328,19 @@ bool DaliDT8::storeSceneSnapshot(int address, int scene, int brightness,
return base_.dtSelect(8) && base_.storeDTRAsSceneBright(address, sceneIndex);
}
bool DaliDT8::storePowerOnLevelSnapshot(int address, int level) {
const int storedLevel = std::clamp(level, 0, 254);
// DT SELECT is one-shot and SET DTR consumes any earlier selection.
return base_.setDTR(storedLevel) && base_.dtSelect(8) && base_.storeDTRAsPoweredBright(address);
}
bool DaliDT8::storeSystemFailureLevelSnapshot(int address, int level) {
const int storedLevel = std::clamp(level, 0, 254);
// DT SELECT is one-shot and SET DTR consumes any earlier selection.
return base_.setDTR(storedLevel) && base_.dtSelect(8) &&
base_.storeDTRAsSystemFailureLevel(address);
}
bool DaliDT8::activateTemporaryColour(int a) { return base_.dtSelect(8) && base_.activate(a); }
std::optional<int> DaliDT8::getPrimaryDimLevel(int a, int n) {
@@ -452,6 +465,35 @@ std::vector<double> DaliDT8::getSceneColor(int a, int sense) {
return report->xy;
}
std::optional<Dt8LevelColorReport> DaliDT8::buildLevelColorReport(int a, std::optional<int> level) {
if (!level.has_value() || level.value() == 255) return std::nullopt;
Dt8LevelColorReport report;
report.level = level.value();
report.colorTypeValue = getReportColourType(a).value_or(0);
const ColorType colorType(report.colorTypeValue);
if (colorType.xy()) {
report.xy = getReportColour(a);
return report;
}
if (colorType.ct()) {
report.colorTemperature = getReportColorTemperature(a);
return report;
}
return report;
}
std::optional<Dt8LevelColorReport> DaliDT8::getPowerOnLevelColorReport(int a) {
return buildLevelColorReport(a, base_.getPowerOnLevel(a));
}
std::optional<Dt8LevelColorReport> DaliDT8::getSystemFailureLevelColorReport(int a) {
return buildLevelColorReport(a, base_.getSystemFailureLevel(a));
}
bool DaliDT8::storePrimaryTy(int a, int n, int ty) {
int idx = std::clamp(n, 0, 5);
int t = std::clamp(ty, 0, 65535);