From 52bcc39505fc039683bf13bd324cd3fffecbe539 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Tue, 20 Feb 2024 04:24:48 -0800 Subject: [PATCH] change config to allow short if blocks; reformat again --- .clang-format | 2 +- RF24Mesh.cpp | 42 +++++++------------ RF24Mesh.h | 3 +- .../ncurses/RF24Mesh_Ncurses_Master.cpp | 9 ++-- 4 files changed, 19 insertions(+), 37 deletions(-) diff --git a/.clang-format b/.clang-format index c02cf2f..4b89c55 100644 --- a/.clang-format +++ b/.clang-format @@ -19,7 +19,7 @@ AllowShortBlocksOnASingleLine: Empty AllowShortCaseLabelsOnASingleLine: true AllowShortFunctionsOnASingleLine: All AllowShortLambdasOnASingleLine: All -AllowShortIfStatementsOnASingleLine: Never +AllowShortIfStatementsOnASingleLine: AllIfsAndElse AllowShortLoopsOnASingleLine: false AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: false diff --git a/RF24Mesh.cpp b/RF24Mesh.cpp index 1257743..6bae0bf 100644 --- a/RF24Mesh.cpp +++ b/RF24Mesh.cpp @@ -63,8 +63,7 @@ template uint8_t ESBMesh::update() { uint8_t type = network.update(); - if (mesh_address == MESH_DEFAULT_ADDRESS) - return type; + if (mesh_address == MESH_DEFAULT_ADDRESS) return type; #if !defined(MESH_NOMASTER) if (type == NETWORK_REQ_ADDRESS) { @@ -107,8 +106,7 @@ uint8_t ESBMesh::update() template bool ESBMesh::write(uint16_t to_node, const void* data, uint8_t msg_type, size_t size) { - if (mesh_address == MESH_DEFAULT_ADDRESS) - return 0; + if (mesh_address == MESH_DEFAULT_ADDRESS) return 0; RF24NetworkHeader header(to_node, msg_type); return network.write(header, data, size); @@ -119,8 +117,7 @@ bool ESBMesh::write(uint16_t to_node, const void* data, uint template bool ESBMesh::write(const void* data, uint8_t msg_type, size_t size, uint8_t nodeID) { - if (mesh_address == MESH_DEFAULT_ADDRESS) - return 0; + if (mesh_address == MESH_DEFAULT_ADDRESS) return 0; int16_t toNode = 0; uint32_t lookupTimeout = millis() + MESH_WRITE_TIMEOUT; @@ -177,10 +174,8 @@ int16_t ESBMesh::getAddress(uint8_t nodeID) { // Master will return and send 00 address for a nodeID with address 0, -1 if not found //if (nodeID == _nodeID) return mesh_address; - if (!nodeID) - return 0; - if (mesh_address == MESH_DEFAULT_ADDRESS) - return -2; + if (!nodeID) return 0; + if (mesh_address == MESH_DEFAULT_ADDRESS) return -2; // Lets say 0 if nodeID 0, -1 if write failed or timed out, -2 if not found in list or address is default, #if !defined(MESH_NOMASTER) @@ -215,12 +210,9 @@ int16_t ESBMesh::getAddress(uint8_t nodeID) template int16_t ESBMesh::getNodeID(uint16_t address) { - if (address == MESH_BLANK_ID) - return _nodeID; - if (address == 0) - return 0; - if (mesh_address == MESH_DEFAULT_ADDRESS) - return -2; + if (address == MESH_BLANK_ID) return _nodeID; + if (address == 0) return 0; + if (mesh_address == MESH_DEFAULT_ADDRESS) return -2; #if !defined(MESH_NOMASTER) if (!mesh_address) { //Master Node @@ -238,8 +230,7 @@ int16_t ESBMesh::getNodeID(uint16_t address) uint32_t timer = millis(); while (network.update() != MESH_ID_LOOKUP) { MESH_CALLBACK - if (millis() - timer > MESH_LOOKUP_TIMEOUT) - return -1; + if (millis() - timer > MESH_LOOKUP_TIMEOUT) return -1; } int16_t ID = 0; memcpy(&ID, &network.frame_buffer[sizeof(RF24NetworkHeader)], sizeof(ID)); @@ -276,8 +267,7 @@ void ESBMesh::beginDefault() template bool ESBMesh::releaseAddress() { - if (mesh_address == MESH_DEFAULT_ADDRESS) - return 0; + if (mesh_address == MESH_DEFAULT_ADDRESS) return 0; RF24NetworkHeader header(00, MESH_ADDR_RELEASE); if (network.write(header, 0, 0)) { @@ -292,8 +282,7 @@ bool ESBMesh::releaseAddress() template uint16_t ESBMesh::renewAddress(uint32_t timeout) { - if (radio.available()) - network.update(); + if (radio.available()) network.update(); uint8_t reqCounter = 0; uint8_t totalReqs = 0; @@ -302,8 +291,7 @@ uint16_t ESBMesh::renewAddress(uint32_t timeout) uint32_t start = millis(); while (!requestAddress(reqCounter)) { - if (millis() - start > timeout) - break; + if (millis() - start > timeout) break; uint32_t timeoutInternal = 50 + ((totalReqs + 1) * (reqCounter + 1)) * 2; uint32_t startInternal = millis(); @@ -485,8 +473,7 @@ void ESBMesh::loadDHCP() #if defined(__linux) && !defined(__ARDUINO_X86__) std::ifstream infile("dhcplist.txt", std::ifstream::binary); - if (!infile) - return; + if (!infile) return; infile.seekg(0, infile.end); int length = infile.tellg(); @@ -565,8 +552,7 @@ void ESBMesh::DHCP() bool found = false; newAddress = fwd_by | (i << shiftVal); - if (newAddress == MESH_DEFAULT_ADDRESS) - continue; + if (newAddress == MESH_DEFAULT_ADDRESS) continue; for (uint8_t i = 0; i < addrListTop; i++) { IF_MESH_DEBUG_MINIMAL(printf_P(PSTR("ID: %d ADDR: 0%o\n"), addrList[i].nodeID, addrList[i].address)); diff --git a/RF24Mesh.h b/RF24Mesh.h index 042d812..a1223ea 100644 --- a/RF24Mesh.h +++ b/RF24Mesh.h @@ -249,8 +249,7 @@ class ESBMesh void setCallback(void (*meshCallback)(void)); #define MESH_CALLBACK \ - if (meshCallback) \ - meshCallback(); + if (meshCallback) meshCallback(); /** * Set or change a @ref _nodeID "nodeID" : node address (key : value) pair manually. diff --git a/examples_RPi/ncurses/RF24Mesh_Ncurses_Master.cpp b/examples_RPi/ncurses/RF24Mesh_Ncurses_Master.cpp index 4ba0d51..34e2852 100644 --- a/examples_RPi/ncurses/RF24Mesh_Ncurses_Master.cpp +++ b/examples_RPi/ncurses/RF24Mesh_Ncurses_Master.cpp @@ -241,8 +241,7 @@ void drawTopology() int y = 0; int x = 0; getyx(topoPad, y, x); - if (x >= topoPadmaxX) - wprintw(topoPad, "\n"); + if (x >= topoPadmaxX) wprintw(topoPad, "\n"); wprintw(topoPad, "0%o[%d] ", mesh.addrList[j].address, mesh.addrList[j].nodeID); } } @@ -262,8 +261,7 @@ void drawTopology() int y = 0; int x = 0; getyx(topoPad, y, x); - if (x >= topoPadmaxX) - wprintw(topoPad, "\n"); + if (x >= topoPadmaxX) wprintw(topoPad, "\n"); wprintw(topoPad, "0%o[%d] ", mesh.addrList[j].address, mesh.addrList[j].nodeID); } } @@ -283,8 +281,7 @@ void drawTopology() int y = 0; int x = 0; getyx(topoPad, y, x); - if (x >= topoPadmaxX) - wprintw(topoPad, "\n"); + if (x >= topoPadmaxX) wprintw(topoPad, "\n"); wprintw(topoPad, "0%o[%d] ", mesh.addrList[j].address, mesh.addrList[j].nodeID); } }