Skip to content

Commit

Permalink
change config to allow short if blocks; reformat again
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Feb 20, 2024
1 parent 9ed6273 commit 52bcc39
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
Expand Down
42 changes: 14 additions & 28 deletions RF24Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ template<class network_t, class radio_t>
uint8_t ESBMesh<network_t, radio_t>::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) {
Expand Down Expand Up @@ -107,8 +106,7 @@ uint8_t ESBMesh<network_t, radio_t>::update()
template<class network_t, class radio_t>
bool ESBMesh<network_t, radio_t>::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);
Expand All @@ -119,8 +117,7 @@ bool ESBMesh<network_t, radio_t>::write(uint16_t to_node, const void* data, uint
template<class network_t, class radio_t>
bool ESBMesh<network_t, radio_t>::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;
Expand Down Expand Up @@ -177,10 +174,8 @@ int16_t ESBMesh<network_t, radio_t>::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)
Expand Down Expand Up @@ -215,12 +210,9 @@ int16_t ESBMesh<network_t, radio_t>::getAddress(uint8_t nodeID)
template<class network_t, class radio_t>
int16_t ESBMesh<network_t, radio_t>::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
Expand All @@ -238,8 +230,7 @@ int16_t ESBMesh<network_t, radio_t>::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));
Expand Down Expand Up @@ -276,8 +267,7 @@ void ESBMesh<network_t, radio_t>::beginDefault()
template<class network_t, class radio_t>
bool ESBMesh<network_t, radio_t>::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)) {
Expand All @@ -292,8 +282,7 @@ bool ESBMesh<network_t, radio_t>::releaseAddress()
template<class network_t, class radio_t>
uint16_t ESBMesh<network_t, radio_t>::renewAddress(uint32_t timeout)
{
if (radio.available())
network.update();
if (radio.available()) network.update();

uint8_t reqCounter = 0;
uint8_t totalReqs = 0;
Expand All @@ -302,8 +291,7 @@ uint16_t ESBMesh<network_t, radio_t>::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();
Expand Down Expand Up @@ -485,8 +473,7 @@ void ESBMesh<network_t, radio_t>::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();
Expand Down Expand Up @@ -565,8 +552,7 @@ void ESBMesh<network_t, radio_t>::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));
Expand Down
3 changes: 1 addition & 2 deletions RF24Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 3 additions & 6 deletions examples_RPi/ncurses/RF24Mesh_Ncurses_Master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 52bcc39

Please sign in to comment.