From 8ed53469922e0d3aee3ccf7c973627d7be3aea8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Mon, 29 May 2023 16:02:26 +0200 Subject: [PATCH] Somfy: add Sun status command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Álvaro Fernández Rojas --- Somfy.cpp | 7 ++++++- Somfy.h | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Somfy.cpp b/Somfy.cpp index 79251db..c3430d0 100644 --- a/Somfy.cpp +++ b/Somfy.cpp @@ -91,6 +91,8 @@ String translateSomfyCommand(const somfy_commands cmd) { return "Step Up"; case somfy_commands::StepDown: return "Step Down"; + case somfy_commands::Status: + return "Status"; default: return "Unknown(" + String((uint8_t)cmd) + ")"; } @@ -173,9 +175,12 @@ void somfy_frame_t::decodeFrame(byte* frame) { case somfy_commands::SunFlag: case somfy_commands::Flag: break; + case somfy_commands::Status: + this->rollingCode = 0; + this->sun = !!(decoded[3] & STATUS_SUN); + break; case somfy_commands::UnknownC: case somfy_commands::UnknownD: - case somfy_commands::UnknownE: case somfy_commands::RTWProto: this->valid = false; break; diff --git a/Somfy.h b/Somfy.h index def21cc..a6d77ee 100644 --- a/Somfy.h +++ b/Somfy.h @@ -28,7 +28,7 @@ enum class somfy_commands : byte { StepDown = 0xB, UnknownC = 0xC, UnknownD = 0xD, - UnknownE = 0xE, // This command byte has been witnessed in the wild but cannot tell if it is from Somfy. No rolling code is sent with this and it is 56-bits. + Status = 0xE, RTWProto = 0xF, // RTW Protocol // Command extensions for 80 bit frames StepUp = 0x8B @@ -52,6 +52,12 @@ somfy_commands translateSomfyCommand(const String& string); #define MAX_RX_BUFFER 3 #define MAX_TX_BUFFER 3 +#if !defined(BIT) +#define BIT(x) (1 << (x)) +#endif /* BIT */ + +#define STATUS_SUN BIT(1) + typedef enum { waiting_synchro = 0, receiving_data = 1, @@ -110,6 +116,7 @@ typedef struct somfy_frame_t { uint32_t await = 0; uint8_t bitLength = 56; uint16_t pulseCount = 0; + bool sun = false; void print(); void encodeFrame(byte *frame); void decodeFrame(byte* frame);