diff --git a/Somfy.cpp b/Somfy.cpp index 1cae433..2e994e6 100644 --- a/Somfy.cpp +++ b/Somfy.cpp @@ -313,6 +313,7 @@ void somfy_frame_t::encode80BitFrame(byte *frame, uint8_t repeat) { } void somfy_frame_t::encodeFrame(byte *frame) { const byte btn = static_cast(cmd); + this->valid = true; frame[0] = this->encKey; // Encryption key. Doesn't matter much frame[1] = (btn & 0x0F) << 4; // Which button did you press? The 4 LSB will be the checksum frame[2] = this->rollingCode >> 8; // Rolling code (big endian) @@ -432,6 +433,7 @@ void somfy_frame_t::print() { Serial.print(" CS:"); Serial.println(this->checksum); } +bool somfy_frame_t::isSynonym(somfy_frame_t &frame) { return this->remoteAddress == frame.remoteAddress && this->cmd != frame.cmd && this->rollingCode == frame.rollingCode; } bool somfy_frame_t::isRepeat(somfy_frame_t &frame) { return this->remoteAddress == frame.remoteAddress && this->cmd == frame.cmd && this->rollingCode == frame.rollingCode; } void somfy_frame_t::copy(somfy_frame_t &frame) { if(this->isRepeat(frame)) { @@ -440,8 +442,9 @@ void somfy_frame_t::copy(somfy_frame_t &frame) { this->lqi = frame.lqi; } else { + this->synonym = this->isSynonym(frame); this->valid = frame.valid; - this->processed = frame.processed; + if(!this->synonym) this->processed = frame.processed; this->rssi = frame.rssi; this->lqi = frame.lqi; this->cmd = frame.cmd; @@ -2398,6 +2401,7 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) { this->lastFrame.await = curTime + 500; } else { + if(this->lastFrame.processed) return; Serial.println("Moving to My target"); this->lastFrame.processed = true; if(this->myTiltPos >= 0.0f && this->myTiltPos <= 100.0f) this->p_tiltTarget(this->myTiltPos); @@ -2406,6 +2410,7 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) { } } else { + if(this->lastFrame.processed) return; this->lastFrame.processed = true; if(!internal) { if(this->tiltType != tilt_types::tiltonly) this->p_target(this->currentPos); @@ -2511,8 +2516,10 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) { this->lastFrame.processed = true; this->p_target(this->currentPos); this->p_tiltTarget(this->currentTiltPos); + this->emitCommand(cmd, internal ? "internal" : "remote", frame.remoteAddress); break; case somfy_commands::Favorite: + if(this->lastFrame.processed) return; this->lastFrame.processed = true; if(this->simMy()) { this->moveToMyPosition(); @@ -3895,6 +3902,7 @@ void SomfyRemote::sendCommand(somfy_commands cmd, uint8_t repeat, uint8_t stepSi this->lastFrame.repeats = repeat; this->lastFrame.bitLength = this->bitLength; this->lastFrame.stepSize = stepSize; + this->lastFrame.valid = true; // Match the encKey to the rolling code. These keys range from 160 to 175. this->lastFrame.encKey = 0xA0 | static_cast(this->lastFrame.rollingCode & 0x000F); this->lastFrame.proto = this->proto; diff --git a/Somfy.h b/Somfy.h index 26d6bb4..aad8823 100644 --- a/Somfy.h +++ b/Somfy.h @@ -171,6 +171,7 @@ struct somfy_relay_t { struct somfy_frame_t { bool valid = false; bool processed = false; + bool synonym = false; radio_proto proto = radio_proto::RTS; int rssi = 0; byte lqi = 0x0; @@ -192,6 +193,7 @@ struct somfy_frame_t { void decodeFrame(byte* frame); void decodeFrame(somfy_rx_t *rx); bool isRepeat(somfy_frame_t &f); + bool isSynonym(somfy_frame_t &f); void copy(somfy_frame_t &f); }; diff --git a/SomfyController.ino.esp32.bin b/SomfyController.ino.esp32.bin index 827292b..b0fc392 100644 Binary files a/SomfyController.ino.esp32.bin and b/SomfyController.ino.esp32.bin differ diff --git a/SomfyController.ino.esp32s3.bin b/SomfyController.ino.esp32s3.bin index b4c5890..54c0774 100644 Binary files a/SomfyController.ino.esp32s3.bin and b/SomfyController.ino.esp32s3.bin differ