Enhance DALI device type discovery and query handling
- Introduce DaliDeviceTypeDiscovery struct for managing device type queries. - Implement discoverDeviceTypes method in DaliBase for improved device type detection. - Update DaliComm to handle query responses more robustly, including handling multiple device replies. - Add setDetectedDeviceTypes method in DaliDevice to manage detected device types and capabilities.
This commit is contained in:
@@ -23,6 +23,14 @@ struct DaliStatus {
|
||||
static DaliStatus fromByte(uint8_t status);
|
||||
};
|
||||
|
||||
struct DaliDeviceTypeDiscovery {
|
||||
std::optional<int> rawQueryType;
|
||||
std::vector<int> types;
|
||||
|
||||
std::optional<int> primaryType() const;
|
||||
std::vector<int> extraTypes() const;
|
||||
};
|
||||
|
||||
class DaliBase {
|
||||
public:
|
||||
explicit DaliBase(DaliComm& comm);
|
||||
@@ -85,6 +93,8 @@ class DaliBase {
|
||||
std::optional<bool> getOnlineStatus(int a);
|
||||
std::optional<int> getBright(int a);
|
||||
std::optional<int> getDeviceType(int a);
|
||||
std::optional<DaliDeviceTypeDiscovery> discoverDeviceTypes(
|
||||
int a, const std::vector<int>& fallbackTypes = {}, int maxNextTypes = 16);
|
||||
std::optional<int> getPhysicalMinLevel(int a);
|
||||
std::optional<int> getDeviceVersion(int a);
|
||||
|
||||
@@ -161,6 +171,11 @@ class DaliBase {
|
||||
private:
|
||||
DaliComm& comm_;
|
||||
|
||||
std::vector<int> discoverNextDeviceTypes(int a, int maxNextTypes);
|
||||
std::vector<int> probeSupportedDeviceTypes(int a, const std::vector<int>& fallbackTypes);
|
||||
std::optional<int> queryExtendedVersionForDeviceType(int a, int deviceType);
|
||||
static bool isRealDeviceTypeValue(int value);
|
||||
|
||||
static uint8_t encodeCmdAddr(int dec_addr);
|
||||
static uint8_t encodeArcAddr(int dec_addr);
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
// - Send: [0x10, addr, cmd]
|
||||
// - Ext: [0x11, addr, cmd] (sent twice with a small delay)
|
||||
// - Query: [0x12, addr, cmd] -> expects [0xFF, data] on success
|
||||
// COMPARE may also return [0xFD, data] when multiple devices reply together
|
||||
// Callers provide UART callbacks; this class only builds frames and parses basic responses.
|
||||
class DaliComm {
|
||||
public:
|
||||
@@ -50,7 +51,8 @@ class DaliComm {
|
||||
bool sendCmd(uint8_t addr, uint8_t cmd) const;
|
||||
// Send extended command frame (0x11).
|
||||
bool sendExtCmd(uint8_t addr, uint8_t cmd) const;
|
||||
// Send query frame (0x12) and parse single-byte response. Returns nullopt on no/invalid response.
|
||||
// Send query frame (0x12) and parse single-byte response. Returns nullopt on no/invalid response,
|
||||
// except COMPARE where 0xFD collisions are treated as a positive match.
|
||||
std::optional<uint8_t> queryCmd(uint8_t addr, uint8_t cmd) const;
|
||||
|
||||
// Helpers to mirror Dart address conversion (DEC short address -> DALI odd/even encoded).
|
||||
@@ -63,6 +65,7 @@ class DaliComm {
|
||||
TransactCallback transact_;
|
||||
DelayCallback delay_;
|
||||
|
||||
void prepareForQuery() const;
|
||||
bool writeFrame(const std::vector<uint8_t>& frame) const;
|
||||
void sleepMs(uint32_t ms) const;
|
||||
};
|
||||
|
||||
@@ -116,4 +116,5 @@ struct DaliDevice {
|
||||
|
||||
std::string displayName() const;
|
||||
void merge(const DaliDevice& other);
|
||||
void setDetectedDeviceTypes(const std::optional<int>& rawQueryType, const std::vector<int>& types);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user