mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-22 13:48:29 +02:00
Adding ignore bits to narrow compare of received codes (#650)
* Adding bitmask to narrow compare of received codes Updated test to add mask configuration * Lint * Handle bitmask as ignore characters per review comment * Fixed test to cover ignore bits * Lint * Eliminate separate set_mask method per review comment
This commit is contained in:
@@ -216,13 +216,22 @@ uint32_t decode_binary_string(const std::string &data) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint32_t decode_binary_string_mask(const std::string &data) {
|
||||
uint32_t ret = 0;
|
||||
for (char c : data) {
|
||||
ret <<= 1UL;
|
||||
ret |= (c != 'x');
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool RCSwitchRawReceiver::matches(RemoteReceiveData src) {
|
||||
uint32_t decoded_code;
|
||||
uint8_t decoded_nbits;
|
||||
if (!this->protocol_.decode(src, &decoded_code, &decoded_nbits))
|
||||
return false;
|
||||
|
||||
return decoded_nbits == this->nbits_ && decoded_code == this->code_;
|
||||
return decoded_nbits == this->nbits_ && (decoded_code & this->mask_) == (this->code_ & this->mask_);
|
||||
}
|
||||
bool RCSwitchDumper::dump(RemoteReceiveData src) {
|
||||
for (uint8_t i = 1; i <= 7; i++) {
|
||||
|
||||
Reference in New Issue
Block a user