From e1addf9e5d60de5607748d4160bbc1beb6e0f15b Mon Sep 17 00:00:00 2001 From: majuss Date: Fri, 10 Jan 2025 21:59:05 +0100 Subject: [PATCH] implemented four button remote --- src/enocean.cpp | 96 +++++++++++++++++++++++++++++++++++-------------- src/enocean.h | 5 ++- 2 files changed, 74 insertions(+), 27 deletions(-) diff --git a/src/enocean.cpp b/src/enocean.cpp index 0769127..2263513 100644 --- a/src/enocean.cpp +++ b/src/enocean.cpp @@ -8,6 +8,7 @@ union DataLength Packet::Packet() { + // Initialize packet data memset(header, 0, ENOCEAN_HEADER); memset(payload, 0, ENOCEAN_MAX_DATA); memset(dataBytes, 0, sizeof(dataBytes)); @@ -16,15 +17,18 @@ Packet::Packet() dataLength = 0; payloadLength = 0; radioTelegramType = "Unknown"; - type = 0; + type = ""; rssi = 0; state = "Unknown"; + // init done + + // Serial2.readBytes(header, ENOCEAN_HEADER); } bool Packet::checkHeaderCRC8(byte CRC8H) { getPacketLength(); - type = header[3]; + // type = header[3]; crc8.begin(); uint8_t checksum = crc8.get_crc8(header, ENOCEAN_HEADER); return checksum == CRC8H; @@ -64,53 +68,83 @@ void Packet::handleTelegram() { byte rorgByte = enocean_data[0]; - if (rorgByte == 0xF6) + switch (rorgByte) { + case 0xF6: + Serial.println("RORG is RPS"); handleRPSTelegram(); - } - else if (rorgByte == 0xD5) - { + break; + + case 0xD5: radioTelegramType = "1BS"; // 1 Byte communication - } - else if (rorgByte == 0xA5) - { + break; + + case 0xA5: radioTelegramType = "4BS"; // 4 Byte communication - } - else if (rorgByte == 0xD2) - { + break; + + case 0xD2: radioTelegramType = "VLD"; // Variable Length Data - } - else - { + break; + + default: Serial.println("Unknown radio telegram type (rorg)"); + break; } + rssi = enocean_optional[5] * -1; memcpy(senderAddress, &enocean_data[2], 4); - } void Packet::handleRPSTelegram() { radioTelegramType = "RPS"; // Repeated Switch Communication dataBytes[0] = enocean_data[1]; + Serial.println(dataBytes[0]); - if (dataBytes[0] == 0xE0 || dataBytes[0] == 0xC0) + switch (dataBytes[0]) { + case 0xE0: // Windows handles + case 0xC0: + type = "window_handle"; state = "on"; - } - else if (dataBytes[0] == 0xF0) - { + break; + case 0x70: // 4-button remote + type = "four_button_remote_button4"; + state = "on"; + break; + case 0x50: + type = "four_button_remote_button3"; + state = "on"; + break; + case 0x30: + type = "four_button_remote_button2"; + state = "on"; + break; + case 0x10: + type = "four_button_remote_button1"; + state = "on"; + break; + case 0xF0: + type = "window_handle"; state = "off"; - } - else - { + break; + case 0x00: + type = "four_button_remote_off"; + state = "off"; + break; + case 0xD0: state = "unknown"; - } + break; + default: + // Handle other cases if needed + break; + } // Implementation of RPS handling } -byte* Packet::getHeader() +byte *Packet::getHeader() { return header; } @@ -118,7 +152,17 @@ String Packet::getState() { return state; } -byte* Packet::getSenderAddress() +byte *Packet::getSenderAddress() { return senderAddress; } + +int8_t Packet::getRssi() +{ + return rssi; +} + +String Packet::getType() +{ + return type; +} \ No newline at end of file diff --git a/src/enocean.h b/src/enocean.h index ed735bf..572777d 100644 --- a/src/enocean.h +++ b/src/enocean.h @@ -11,7 +11,9 @@ class Packet { bool checkDataCRC8(byte CRC8D); byte* getHeader(); String getState(); + String getType(); byte* getSenderAddress(); + int8_t getRssi(); uint8_t payloadLength; byte enocean_data[ENOCEAN_MAX_DATA]; byte enocean_optional[ENOCEAN_MAX_DATA]; @@ -24,9 +26,10 @@ class Packet { void handleRPSTelegram(); void getPacketLength(); byte payload[ENOCEAN_MAX_DATA]; - byte rssi; + int8_t rssi; byte type; CRC8 crc8{}; + String type; String radioTelegramType; byte dataBytes[4];