Skip to content

Commit

Permalink
Adjust setAddress function
Browse files Browse the repository at this point in the history
- Searching by address and changing nodeID has unintended consequences, and should be optional since it is setAddress not setNodeID, so make it optional...
  • Loading branch information
TMRh20 committed Aug 17, 2020
1 parent c2354ff commit 7a4a8e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
13 changes: 7 additions & 6 deletions RF24Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,27 +444,28 @@ void RF24Mesh::setStaticAddress(uint8_t nodeID, uint16_t address){

/*****************************************************/

void RF24Mesh::setAddress(uint8_t nodeID, uint16_t address){

void RF24Mesh::setAddress(uint8_t nodeID, uint16_t address, bool searchBy){

//Look for the node in the list
for(uint8_t i=0; i<addrListTop; i++){
if(searchBy == false){
if( addrList[i].nodeID == nodeID){
addrList[i].address = address;
#if defined (__linux) && !defined(__ARDUINO_X86__)
saveDHCP();
#endif
return; //Found & set, complete
}else
}
}else{ // Search by address, set the nodeID
if( addrList[i].address == address){
//printf("*** Addr 0%o Found, reassign fr ID %d to ID %d ***\n", addrList[i].address,addrList[i].nodeID,nodeID);
addrList[i].nodeID = nodeID;
#if defined (__linux) && !defined(__ARDUINO_X86__)
saveDHCP();
#endif

#endif
return;
}
}
}
}

if(addrListTop > 0 && addrListTop % MESH_MEM_ALLOC_SIZE == 0){
Expand Down
17 changes: 13 additions & 4 deletions RF24Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,12 @@ class RF24Mesh
*
* @code
* void myCallbackFunction(){
* someValue = someOtherValue
* someValue = someOtherValue;
* }
* mesh.setCallback(myCallbackFunction);
* @endcode
*
* @param meshCallback Then name of a function to call
* @param meshCallback The name of a function to call
*/
void setCallback( void (*meshCallback)(void) );

Expand All @@ -238,13 +238,22 @@ class RF24Mesh
* Set a static address for node 02, with nodeID 23, since it will just be a static routing node for example
* running on an ATTiny chip.
*
* mesh.setStaticAddress(23,02);
* mesh.setAddress(23,02);
* @endcode
*
* @code
* Change/set the nodeID for an existing address
*
* uint16_t address = 012;
* mesh.setAddress(3,address,true);
* @endcode
*
* @param nodeID The nodeID to assign
* @param address The octal RF24Network address to assign
* @param searchBy Optional parameter. Default is search by nodeID and set the address. True allows searching by address and setting nodeID.
* @return If the nodeID exists in the list,
*/
void setAddress(uint8_t nodeID, uint16_t address);
void setAddress(uint8_t nodeID, uint16_t address, bool searchBy = false);

void saveDHCP();
void loadDHCP();
Expand Down

0 comments on commit 7a4a8e5

Please sign in to comment.