Add support for DT4, DT5, and DT6 devices
- Updated CMakeLists.txt to include new source files for DT4, DT5, and DT6. - Modified dali.hpp to include headers for DT4, DT5, and DT6. - Added command definitions for DT4, DT5, and DT6 in dali_define.hpp. - Enhanced DaliDeviceCapabilities to support DT4, DT5, and DT6 detection. - Implemented DT4 and DT5 classes with methods for device control and status querying. - Created DT6 class with methods for device control and status querying. - Updated decode.cpp to include new device types in the deviceTypeName mapping. - Enhanced device.cpp to handle new device capabilities.
This commit is contained in:
+147
@@ -0,0 +1,147 @@
|
||||
#include "dt4.hpp"
|
||||
|
||||
#include "dali_define.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
DaliDT4::DaliDT4(DaliBase& base) : base_(base) {}
|
||||
|
||||
bool DaliDT4::enable() { return base_.dtSelect(4); }
|
||||
|
||||
int DaliDT4::addrOf(int a) { return a * 2 + 1; }
|
||||
|
||||
std::optional<int> DaliDT4::query(int a, int code) {
|
||||
if (!enable()) return std::nullopt;
|
||||
return base_.queryCmd(static_cast<uint8_t>(addrOf(a)), static_cast<uint8_t>(code));
|
||||
}
|
||||
|
||||
std::optional<bool> DaliDT4::queryYesNo(int a, int code) {
|
||||
const auto value = query(a, code);
|
||||
if (!value.has_value()) return std::nullopt;
|
||||
return value.value() != 0;
|
||||
}
|
||||
|
||||
bool DaliDT4::enableDT4() { return enable(); }
|
||||
|
||||
bool DaliDT4::referenceSystemPower(int a) {
|
||||
return enable() && base_.sendExtCmd(addrOf(a), DALI_CMD_DT4_REFERENCE_SYSTEM_POWER) &&
|
||||
base_.sendExtCmd(addrOf(a), DALI_CMD_DT4_REFERENCE_SYSTEM_POWER);
|
||||
}
|
||||
|
||||
bool DaliDT4::selectDimmingCurve(int a, int curve) {
|
||||
const int value = std::clamp(curve, 0, 255);
|
||||
return enable() && base_.setDTR(value) &&
|
||||
base_.sendExtCmd(addrOf(a), DALI_CMD_DT4_SELECT_DIMMING_CURVE) &&
|
||||
base_.sendExtCmd(addrOf(a), DALI_CMD_DT4_SELECT_DIMMING_CURVE);
|
||||
}
|
||||
|
||||
std::optional<int> DaliDT4::getDimmingCurve(int a) { return query(a, DALI_CMD_DT4_QUERY_DIMMING_CURVE); }
|
||||
|
||||
std::optional<DaliDT4DimmerStatus> DaliDT4::getDimmerStatus(int a) {
|
||||
const auto raw = query(a, DALI_CMD_DT4_QUERY_DIMMER_STATUS);
|
||||
if (!raw.has_value()) return std::nullopt;
|
||||
return DaliDT4DimmerStatus(raw.value());
|
||||
}
|
||||
|
||||
std::optional<DaliDT4Features> DaliDT4::getFeatures(int a) {
|
||||
const auto raw1 = query(a, DALI_CMD_DT4_QUERY_FEATURES);
|
||||
if (!raw1.has_value()) return std::nullopt;
|
||||
const auto raw2 = base_.getDTR(a);
|
||||
const auto raw3 = base_.getDTR1(a);
|
||||
if (!raw2.has_value() || !raw3.has_value()) return std::nullopt;
|
||||
return DaliDT4Features(raw1.value(), raw2.value(), raw3.value());
|
||||
}
|
||||
|
||||
std::optional<DaliDT4FailureStatus> DaliDT4::getFailureStatus(int a) {
|
||||
const auto raw1 = query(a, DALI_CMD_DT4_QUERY_FAILURE_STATUS);
|
||||
if (!raw1.has_value()) return std::nullopt;
|
||||
const auto raw2 = base_.getDTR1(a);
|
||||
if (!raw2.has_value()) return std::nullopt;
|
||||
return DaliDT4FailureStatus(raw1.value(), raw2.value());
|
||||
}
|
||||
|
||||
std::optional<int> DaliDT4::getDimmerTemperatureRaw(int a) {
|
||||
return query(a, DALI_CMD_DT4_QUERY_DIMMER_TEMPERATURE);
|
||||
}
|
||||
|
||||
std::optional<int> DaliDT4::getDimmerTemperatureCelsius(int a) {
|
||||
const auto raw = getDimmerTemperatureRaw(a);
|
||||
if (!raw.has_value() || raw.value() == 0xFF) return std::nullopt;
|
||||
return raw.value() - 40;
|
||||
}
|
||||
|
||||
std::optional<int> DaliDT4::getRmsSupplyVoltageRaw(int a) {
|
||||
return query(a, DALI_CMD_DT4_QUERY_RMS_SUPPLY_VOLTAGE);
|
||||
}
|
||||
|
||||
std::optional<double> DaliDT4::getRmsSupplyVoltageVolts(int a) {
|
||||
const auto raw = getRmsSupplyVoltageRaw(a);
|
||||
if (!raw.has_value() || raw.value() == 0xFF) return std::nullopt;
|
||||
return raw.value() * 2.0;
|
||||
}
|
||||
|
||||
std::optional<int> DaliDT4::getSupplyFrequencyRaw(int a) {
|
||||
return query(a, DALI_CMD_DT4_QUERY_SUPPLY_FREQUENCY);
|
||||
}
|
||||
|
||||
std::optional<double> DaliDT4::getSupplyFrequencyHertz(int a) {
|
||||
const auto raw = getSupplyFrequencyRaw(a);
|
||||
if (!raw.has_value() || raw.value() == 0xFF) return std::nullopt;
|
||||
return raw.value() * 0.5;
|
||||
}
|
||||
|
||||
std::optional<int> DaliDT4::getRmsLoadVoltageRaw(int a) {
|
||||
return query(a, DALI_CMD_DT4_QUERY_RMS_LOAD_VOLTAGE);
|
||||
}
|
||||
|
||||
std::optional<double> DaliDT4::getRmsLoadVoltageVolts(int a) {
|
||||
const auto raw = getRmsLoadVoltageRaw(a);
|
||||
if (!raw.has_value() || raw.value() == 0xFF) return std::nullopt;
|
||||
return raw.value() * 2.0;
|
||||
}
|
||||
|
||||
std::optional<int> DaliDT4::getRmsLoadCurrentRaw(int a) {
|
||||
return query(a, DALI_CMD_DT4_QUERY_RMS_LOAD_CURRENT);
|
||||
}
|
||||
|
||||
std::optional<double> DaliDT4::getRmsLoadCurrentPercent(int a) {
|
||||
const auto raw = getRmsLoadCurrentRaw(a);
|
||||
if (!raw.has_value() || raw.value() == 0xFF) return std::nullopt;
|
||||
return raw.value() * 0.5;
|
||||
}
|
||||
|
||||
std::optional<int> DaliDT4::getRealLoadPowerRaw(int a) {
|
||||
const auto high = query(a, DALI_CMD_DT4_QUERY_REAL_LOAD_POWER);
|
||||
if (!high.has_value()) return std::nullopt;
|
||||
const auto low = base_.getDTR(a);
|
||||
if (!low.has_value()) return std::nullopt;
|
||||
return ((high.value() & 0xFF) << 8) | (low.value() & 0xFF);
|
||||
}
|
||||
|
||||
std::optional<double> DaliDT4::getRealLoadPowerWatts(int a) {
|
||||
const auto raw = getRealLoadPowerRaw(a);
|
||||
if (!raw.has_value() || raw.value() == 0xFFFF) return std::nullopt;
|
||||
return raw.value() * 0.25;
|
||||
}
|
||||
|
||||
std::optional<int> DaliDT4::getLoadRatingRaw(int a) {
|
||||
return query(a, DALI_CMD_DT4_QUERY_LOAD_RATING);
|
||||
}
|
||||
|
||||
std::optional<double> DaliDT4::getLoadRatingAmps(int a) {
|
||||
const auto raw = getLoadRatingRaw(a);
|
||||
if (!raw.has_value() || raw.value() == 0xFF) return std::nullopt;
|
||||
return raw.value() * 0.15;
|
||||
}
|
||||
|
||||
std::optional<bool> DaliDT4::isReferenceRunning(int a) {
|
||||
return queryYesNo(a, DALI_CMD_DT4_QUERY_REFERENCE_RUNNING);
|
||||
}
|
||||
|
||||
std::optional<bool> DaliDT4::isReferenceMeasurementFailed(int a) {
|
||||
return queryYesNo(a, DALI_CMD_DT4_QUERY_REFERENCE_MEASUREMENT_FAILED);
|
||||
}
|
||||
|
||||
std::optional<int> DaliDT4::getExtendedVersion(int a) {
|
||||
return query(a, DALI_CMD_DT4_QUERY_EXTENDED_VERSION);
|
||||
}
|
||||
Reference in New Issue
Block a user