Skip to content

Commit

Permalink
implemented four button remote
Browse files Browse the repository at this point in the history
  • Loading branch information
majuss committed Jan 10, 2025
1 parent 5925bbe commit e1addf9
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 27 deletions.
96 changes: 70 additions & 26 deletions src/enocean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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;
Expand Down Expand Up @@ -64,61 +68,101 @@ 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;
}
String Packet::getState()
{
return state;
}
byte* Packet::getSenderAddress()
byte *Packet::getSenderAddress()
{
return senderAddress;
}

int8_t Packet::getRssi()
{
return rssi;
}

String Packet::getType()
{
return type;
}
5 changes: 4 additions & 1 deletion src/enocean.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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];

Expand Down

0 comments on commit e1addf9

Please sign in to comment.