diff --git a/Somfy.cpp b/Somfy.cpp index 81bb8fd..e37eb81 100644 --- a/Somfy.cpp +++ b/Somfy.cpp @@ -127,33 +127,43 @@ void somfy_frame_t::decodeFrame(byte* frame) { if(this->cmd == somfy_commands::RTWProto) { this->proto = radio_proto::RTW; switch(this->encKey) { + case 149: case 133: this->cmd = somfy_commands::My; break; + case 150: case 134: this->cmd = somfy_commands::Up; break; + case 151: case 135: this->cmd = somfy_commands::MyUp; break; + case 152: case 136: this->cmd = somfy_commands::Down; break; + case 153: case 137: this->cmd = somfy_commands::MyDown; break; + case 154: case 138: this->cmd = somfy_commands::UpDown; break; + case 155: case 139: this->cmd = somfy_commands::MyUpDown; break; + case 156: case 140: this->cmd = somfy_commands::Prog; break; + case 157: case 141: this->cmd = somfy_commands::SunFlag; break; + case 158: case 142: this->cmd = somfy_commands::Flag; break; @@ -302,6 +312,44 @@ void somfy_frame_t::encodeFrame(byte *frame) { break; } } + else if(this->proto == radio_proto::RTV) { + frame[1] = 0xF0; + switch(this->cmd) { + case somfy_commands::My: + frame[0] = 149; + break; + case somfy_commands::Up: + frame[0] = 150; + break; + case somfy_commands::MyUp: + frame[0] = 151; + break; + case somfy_commands::Down: + frame[0] = 152; + break; + case somfy_commands::MyDown: + frame[0] = 153; + break; + case somfy_commands::UpDown: + frame[0] = 154; + break; + case somfy_commands::MyUpDown: + frame[0] = 155; + break; + case somfy_commands::Prog: + frame[0] = 156; + break; + case somfy_commands::SunFlag: + frame[0] = 157; + break; + case somfy_commands::Flag: + frame[0] = 158; + break; + default: + break; + } + + } else { switch(this->cmd) { case somfy_commands::StepUp: @@ -1769,6 +1817,43 @@ bool SomfyShade::toJSON(JsonObject &obj) { } return true; } +bool SomfyGroup::fromJSON(JsonObject &obj) { + if(obj.containsKey("name")) strlcpy(this->name, obj["name"], sizeof(this->name)); + if(obj.containsKey("remoteAddress")) this->setRemoteAddress(obj["remoteAddress"]); + if(obj.containsKey("bitLength")) this->bitLength = obj["bitLength"]; + if(obj.containsKey("proto")) this->proto = static_cast(obj["proto"].as()); + if(obj.containsKey("linkedShades")) { + uint8_t linkedShades[SOMFY_MAX_GROUPED_SHADES]; + memset(linkedShades, 0x00, sizeof(linkedShades)); + JsonArray arr = obj["linkedShades"]; + uint8_t i = 0; + for(uint8_t shadeId : arr) { + linkedShades[i++] = shadeId; + } + } + return true; +} +bool SomfyGroup::toJSON(JsonObject &obj) { + obj["groupId"] = this->getGroupId(); + obj["name"] = this->name; + obj["remoteAddress"] = this->m_remoteAddress; + obj["lastRollingCode"] = this->lastRollingCode; + obj["bitLength"] = this->bitLength; + obj["proto"] = static_cast(this->proto); + SomfyRemote::toJSON(obj); + JsonArray arr = obj.createNestedArray("linkedShades"); + for(uint8_t i = 0; i < SOMFY_MAX_GROUPED_SHADES; i++) { + uint8_t shadeId = this->linkedShades[i]; + if(shadeId > 0 && shadeId < 255) { + SomfyShade *shade = somfy.getShadeById(shadeId); + if(shade) { + JsonObject lsd = arr.createNestedObject(); + shade->toJSON(lsd); + } + } + } + return true; +} bool SomfyRemote::toJSON(JsonObject &obj) { //obj["remotePrefId"] = this->getRemotePrefId(); obj["remoteAddress"] = this->getRemoteAddress(); diff --git a/Somfy.h b/Somfy.h index 84f8380..cc9fdd7 100644 --- a/Somfy.h +++ b/Somfy.h @@ -2,7 +2,9 @@ #define SOMFY_H #define SOMFY_MAX_SHADES 32 +#define SOMFY_MAX_GROUPS 16 #define SOMFY_MAX_LINKED_REMOTES 7 +#define SOMFY_MAX_GROUPED_SHADES 32 #define SECS_TO_MILLIS(x) ((x) * 1000) #define MINS_TO_MILLIS(x) SECS_TO_MILLIS((x) * 60) @@ -21,7 +23,8 @@ struct appver_t { }; enum class radio_proto : byte { RTS = 0x00, - RTW = 0x01 + RTW = 0x01, + RTV = 0x02 }; enum class somfy_commands : byte { Unknown0 = 0x0, @@ -260,7 +263,17 @@ class SomfyShade : public SomfyRemote { void clear(); int8_t transformPosition(float fpos); }; - +class SomfyGroup : public SomfyRemote { + protected: + uint8_t groupId = 255; + public: + char name[21] = ""; + uint8_t linkedShades[SOMFY_MAX_GROUPED_SHADES]; + void setGroupId(uint8_t id) { groupId = id; } + uint8_t getGroupId() { return groupId; } + bool fromJSON(JsonObject &obj); + bool toJSON(JsonObject &obj); +}; struct transceiver_config_t { bool printBuffer = false; bool enabled = false; diff --git a/SomfyController.ino.esp32.bin b/SomfyController.ino.esp32.bin index 19b1dff..e529176 100644 Binary files a/SomfyController.ino.esp32.bin and b/SomfyController.ino.esp32.bin differ diff --git a/SomfyController.littlefs.bin b/SomfyController.littlefs.bin index a073a60..407d5b1 100644 Binary files a/SomfyController.littlefs.bin and b/SomfyController.littlefs.bin differ diff --git a/data/index.html b/data/index.html index 58042fe..de259ef 100644 --- a/data/index.html +++ b/data/index.html @@ -221,6 +221,7 @@