Update RFPowerView to v0.0.3
This commit is contained in:
@@ -28,4 +28,4 @@ lib_deps =
|
|||||||
|
|
||||||
ArduinoJson=https://github.com/bblanchon/ArduinoJson#v7.0.0
|
ArduinoJson=https://github.com/bblanchon/ArduinoJson#v7.0.0
|
||||||
|
|
||||||
RFPowerView=https://git.mattway.com.au/matt/RFPowerView.git#v0.0.2
|
RFPowerView=https://git.mattway.com.au/matt/RFPowerView.git#v0.0.3
|
||||||
|
|||||||
55
src/main.cpp
55
src/main.cpp
@@ -83,7 +83,7 @@ void setup() {
|
|||||||
shades.push_back(Shade{0x3EB8, "living_room_door_blind", "Living Room Door Blind", -1, -1, 0, 0, nullptr});
|
shades.push_back(Shade{0x3EB8, "living_room_door_blind", "Living Room Door Blind", -1, -1, 0, 0, nullptr});
|
||||||
shades.push_back(Shade{0x5463, "living_room_window_blind", "Living Room Window Blind", -1, -1, 0, 0, nullptr});
|
shades.push_back(Shade{0x5463, "living_room_window_blind", "Living Room Window Blind", -1, -1, 0, 0, nullptr});
|
||||||
|
|
||||||
powerView.setPacketCallback(processPacket);
|
powerView.setPacketReceivedCallback(processPacket);
|
||||||
if (!powerView.begin()) {
|
if (!powerView.begin()) {
|
||||||
Serial.println("Failed to start RFPowerView");
|
Serial.println("Failed to start RFPowerView");
|
||||||
return;
|
return;
|
||||||
@@ -107,8 +107,25 @@ void loop() {
|
|||||||
void processPacket(const Packet *packet) {
|
void processPacket(const Packet *packet) {
|
||||||
Serial.println("Got a packet");
|
Serial.println("Got a packet");
|
||||||
|
|
||||||
|
uint16_t source = -1;
|
||||||
|
|
||||||
|
if (std::holds_alternative<BroadcastHeader>(packet->header)) {
|
||||||
|
auto header = std::get<BroadcastHeader>(packet->header);
|
||||||
|
source = header.source;
|
||||||
|
} else if (std::holds_alternative<UnicastHeader>(packet->header)) {
|
||||||
|
auto header = std::get<UnicastHeader>(packet->header);
|
||||||
|
source = header.source;
|
||||||
|
} else if (std::holds_alternative<GroupsHeader>(packet->header)) {
|
||||||
|
auto header = std::get<GroupsHeader>(packet->header);
|
||||||
|
source = header.source;
|
||||||
|
} else {
|
||||||
|
Serial.print("Cannot process packet, unknown header");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Update last rolling codes each time a packet from a real hub is detected
|
// Update last rolling codes each time a packet from a real hub is detected
|
||||||
if (packet->source == 0x0000) {
|
if (source == 0x0000) {
|
||||||
|
Serial.println("Updating rolling codes");
|
||||||
lastRollingCode1 = packet->rollingCode1;
|
lastRollingCode1 = packet->rollingCode1;
|
||||||
lastRollingCode2 = packet->rollingCode2;
|
lastRollingCode2 = packet->rollingCode2;
|
||||||
}
|
}
|
||||||
@@ -119,7 +136,7 @@ void processPacket(const Packet *packet) {
|
|||||||
Field field = parameters.fields[i];
|
Field field = parameters.fields[i];
|
||||||
if (field.identifier == 0x50) {
|
if (field.identifier == 0x50) {
|
||||||
for (size_t i = 0; i < shades.size(); i++) {
|
for (size_t i = 0; i < shades.size(); i++) {
|
||||||
if (packet->source == shades[i].ID) {
|
if (source == shades[i].ID) {
|
||||||
uint16_t value = std::get<uint16_t>(field.value);
|
uint16_t value = std::get<uint16_t>(field.value);
|
||||||
uint8_t position = (uint8_t)std::round(((float)value / 0xFFFF) * 100);
|
uint8_t position = (uint8_t)std::round(((float)value / 0xFFFF) * 100);
|
||||||
|
|
||||||
@@ -135,7 +152,7 @@ void processPacket(const Packet *packet) {
|
|||||||
}
|
}
|
||||||
} else if (field.identifier == 0x42) {
|
} else if (field.identifier == 0x42) {
|
||||||
for (size_t i = 0; i < shades.size(); i++) {
|
for (size_t i = 0; i < shades.size(); i++) {
|
||||||
if (packet->source == shades[i].ID) {
|
if (source == shades[i].ID) {
|
||||||
uint8_t value = std::get<uint8_t>(field.value);
|
uint8_t value = std::get<uint8_t>(field.value);
|
||||||
uint8_t battery = uint8_t(((float)value / 200) * 100);
|
uint8_t battery = uint8_t(((float)value / 200) * 100);
|
||||||
|
|
||||||
@@ -168,8 +185,10 @@ void onConnectionEstablished() {
|
|||||||
|
|
||||||
bool sendOpenPacket(uint16_t destination) {
|
bool sendOpenPacket(uint16_t destination) {
|
||||||
Packet packet;
|
Packet packet;
|
||||||
packet.destination = destination;
|
auto header = UnicastHeader {};
|
||||||
packet.source = 0x0000;
|
header.destination = destination;
|
||||||
|
header.source = 0x0000;
|
||||||
|
packet.header = header;
|
||||||
packet.type = PacketType::OPEN;
|
packet.type = PacketType::OPEN;
|
||||||
|
|
||||||
return sendPacket(&packet);
|
return sendPacket(&packet);
|
||||||
@@ -177,8 +196,10 @@ bool sendOpenPacket(uint16_t destination) {
|
|||||||
|
|
||||||
bool sendClosePacket(uint16_t destination) {
|
bool sendClosePacket(uint16_t destination) {
|
||||||
Packet packet;
|
Packet packet;
|
||||||
packet.destination = destination;
|
auto header = UnicastHeader {};
|
||||||
packet.source = 0x0000;
|
header.destination = destination;
|
||||||
|
header.source = 0x0000;
|
||||||
|
packet.header = header;
|
||||||
packet.type = PacketType::CLOSE;
|
packet.type = PacketType::CLOSE;
|
||||||
|
|
||||||
return sendPacket(&packet);
|
return sendPacket(&packet);
|
||||||
@@ -186,8 +207,10 @@ bool sendClosePacket(uint16_t destination) {
|
|||||||
|
|
||||||
bool sendStopPacket(uint16_t destination) {
|
bool sendStopPacket(uint16_t destination) {
|
||||||
Packet packet;
|
Packet packet;
|
||||||
packet.destination = destination;
|
auto header = UnicastHeader {};
|
||||||
packet.source = 0x0000;
|
header.destination = destination;
|
||||||
|
header.source = 0x0000;
|
||||||
|
packet.header = header;
|
||||||
packet.type = PacketType::STOP;
|
packet.type = PacketType::STOP;
|
||||||
|
|
||||||
return sendPacket(&packet);
|
return sendPacket(&packet);
|
||||||
@@ -195,8 +218,10 @@ bool sendStopPacket(uint16_t destination) {
|
|||||||
|
|
||||||
bool sendSetPosition(uint16_t destination, float percentage) {
|
bool sendSetPosition(uint16_t destination, float percentage) {
|
||||||
Packet packet;
|
Packet packet;
|
||||||
packet.destination = destination;
|
auto header = UnicastHeader {};
|
||||||
packet.source = 0x0000;
|
header.destination = destination;
|
||||||
|
header.source = 0x0000;
|
||||||
|
packet.header = header;
|
||||||
packet.type = PacketType::FIELD_COMMAND;
|
packet.type = PacketType::FIELD_COMMAND;
|
||||||
|
|
||||||
std::vector<Field> fields;
|
std::vector<Field> fields;
|
||||||
@@ -213,8 +238,10 @@ bool sendSetPosition(uint16_t destination, float percentage) {
|
|||||||
|
|
||||||
bool sendFetchPosition(uint16_t destination) {
|
bool sendFetchPosition(uint16_t destination) {
|
||||||
Packet packet;
|
Packet packet;
|
||||||
packet.destination = destination;
|
auto header = UnicastHeader {};
|
||||||
packet.source = 0x0000;
|
header.destination = destination;
|
||||||
|
header.source = 0x0000;
|
||||||
|
packet.header = header;
|
||||||
packet.type = PacketType::FIELD_COMMAND;
|
packet.type = PacketType::FIELD_COMMAND;
|
||||||
|
|
||||||
std::vector<Field> fields;
|
std::vector<Field> fields;
|
||||||
|
|||||||
Reference in New Issue
Block a user