Enhance DaliBase and DaliBridge: add support for logarithmic brightness control in setBright and setBrightPercentage methods
Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
@@ -27,6 +27,7 @@ Dali dali(comm);
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
dali.base.setBright(5, 200); // direct arc power control
|
dali.base.setBright(5, 200); // direct arc power control
|
||||||
|
dali.base.setBright(5, 128, true); // direct arc power with logarithmic curve
|
||||||
dali.base.off(5);
|
dali.base.off(5);
|
||||||
dali.base.dtSelect(8);
|
dali.base.dtSelect(8);
|
||||||
dali.dt8.setColorTemperature(5, 4000); // Kelvin
|
dali.dt8.setColorTemperature(5, 4000); // Kelvin
|
||||||
@@ -71,6 +72,9 @@ DaliBridgeRequest request;
|
|||||||
request.modelID = "line-1-brightness";
|
request.modelID = "line-1-brightness";
|
||||||
request.value = 180;
|
request.value = 180;
|
||||||
engine.execute(request);
|
engine.execute(request);
|
||||||
|
|
||||||
|
request.value = DaliValue::Object{{"value", 128}, {"logarithmicCurve", true}};
|
||||||
|
engine.execute(request); // set_brightness with app-side logarithmic curve
|
||||||
```
|
```
|
||||||
|
|
||||||
### Supported Bridge Operations
|
### Supported Bridge Operations
|
||||||
@@ -95,6 +99,9 @@ engine.execute(request);
|
|||||||
- `start_emergency_function_test`
|
- `start_emergency_function_test`
|
||||||
- `stop_emergency_test`
|
- `stop_emergency_test`
|
||||||
|
|
||||||
|
`set_brightness` and `set_brightness_percent` accept optional
|
||||||
|
`logarithmicCurve` / `logarithmic_curve` boolean request fields.
|
||||||
|
|
||||||
Query-style operations return `data` when available and may include decoded flags in `meta`.
|
Query-style operations return `data` when available and may include decoded flags in `meta`.
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|||||||
+2
-2
@@ -50,8 +50,8 @@ class DaliBase {
|
|||||||
// Brightness helpers
|
// Brightness helpers
|
||||||
int brightnessToLog(int brightness) const;
|
int brightnessToLog(int brightness) const;
|
||||||
int logToBrightness(int logValue) const;
|
int logToBrightness(int logValue) const;
|
||||||
bool setBright(int a, int b);
|
bool setBright(int a, int b, bool logarithmicCurve = false);
|
||||||
bool setBrightPercentage(int a, double b);
|
bool setBrightPercentage(int a, double b, bool logarithmicCurve = false);
|
||||||
bool stopFade(int a);
|
bool stopFade(int a);
|
||||||
bool off(int a);
|
bool off(int a);
|
||||||
bool on(int a);
|
bool on(int a);
|
||||||
|
|||||||
+6
-4
@@ -68,16 +68,18 @@ int DaliBase::logToBrightness(int logValue) const {
|
|||||||
return static_cast<int>(val);
|
return static_cast<int>(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DaliBase::setBright(int a, int b) {
|
bool DaliBase::setBright(int a, int b, bool logarithmicCurve) {
|
||||||
int bright = std::clamp(b, 0, 254);
|
const int inputBright = std::clamp(b, 0, 254);
|
||||||
|
const int bright = logarithmicCurve ? std::clamp(brightnessToLog(inputBright), 0, 254)
|
||||||
|
: inputBright;
|
||||||
const auto addr = encodeArcAddr(a);
|
const auto addr = encodeArcAddr(a);
|
||||||
return comm_.sendCmd(addr, static_cast<uint8_t>(bright));
|
return comm_.sendCmd(addr, static_cast<uint8_t>(bright));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DaliBase::setBrightPercentage(int a, double b) {
|
bool DaliBase::setBrightPercentage(int a, double b, bool logarithmicCurve) {
|
||||||
int bright = static_cast<int>(b * 254.0 / 100.0);
|
int bright = static_cast<int>(b * 254.0 / 100.0);
|
||||||
bright = std::clamp(bright, 0, 254);
|
bright = std::clamp(bright, 0, 254);
|
||||||
return setBright(a, bright);
|
return setBright(a, bright, logarithmicCurve);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DaliBase::stopFade(int a) { return sendCmd(encodeCmdAddr(a), DALI_CMD_STOP_FADE); }
|
bool DaliBase::stopFade(int a) { return sendCmd(encodeCmdAddr(a), DALI_CMD_STOP_FADE); }
|
||||||
|
|||||||
+5
-2
@@ -649,13 +649,16 @@ DaliBridgeResult DaliBridgeEngine::executeResolved(const DaliBridgeRequest& requ
|
|||||||
result.error = "missing target address";
|
result.error = "missing target address";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
const bool logarithmicCurve =
|
||||||
|
boolParam(request, {"logarithmicCurve", "logarithmic_curve", "logCurve", "log_curve"})
|
||||||
|
.value_or(false);
|
||||||
if (operation == BridgeOperation::setBrightness) {
|
if (operation == BridgeOperation::setBrightness) {
|
||||||
const auto value = resolveIntValue(request, model);
|
const auto value = resolveIntValue(request, model);
|
||||||
if (!value.has_value()) {
|
if (!value.has_value()) {
|
||||||
result.error = "missing value";
|
result.error = "missing value";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result.ok = base_.setBright(address.value(), value.value());
|
result.ok = base_.setBright(address.value(), value.value(), logarithmicCurve);
|
||||||
result.data = value.value();
|
result.data = value.value();
|
||||||
} else if (operation == BridgeOperation::setBrightnessPercent) {
|
} else if (operation == BridgeOperation::setBrightnessPercent) {
|
||||||
const auto value = resolveDoubleValue(request);
|
const auto value = resolveDoubleValue(request);
|
||||||
@@ -663,7 +666,7 @@ DaliBridgeResult DaliBridgeEngine::executeResolved(const DaliBridgeRequest& requ
|
|||||||
result.error = "missing value";
|
result.error = "missing value";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result.ok = base_.setBrightPercentage(address.value(), value.value());
|
result.ok = base_.setBrightPercentage(address.value(), value.value(), logarithmicCurve);
|
||||||
result.data = static_cast<int>(std::lround(value.value()));
|
result.data = static_cast<int>(std::lround(value.value()));
|
||||||
} else if (operation == BridgeOperation::on) {
|
} else if (operation == BridgeOperation::on) {
|
||||||
result.ok = base_.on(address.value());
|
result.ok = base_.on(address.value());
|
||||||
|
|||||||
Reference in New Issue
Block a user