Browse Source

Adds ability to remove a node from the device tree

pull/148/head
riban 2 years ago
parent
commit
3fa5d82c83
2 changed files with 48 additions and 0 deletions
  1. +47
    -0
      wiringPi/wiringPi.c
  2. +1
    -0
      wiringPi/wiringPi.h

+ 47
- 0
wiringPi/wiringPi.c View File

@@ -1369,6 +1369,53 @@ struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins)
return node ;
}

/*
* wiringPiRemoveNode:
* Remove an existing GPIO node from the wiringPi handling system
*********************************************************************************
*/

int wiringPiRemoveNode (int pinBase)
{
struct wiringPiNodeStruct *node ;
struct wiringPiNodeStruct *nodePrevious ;

// Don't try if there are no nodes in the tree or pinBase in naitive GPI range
if (wiringPiNodes == NULL || pinBase < 64)
return FALSE;

// Find node
node = wiringPiFindNode (pinBase) ;
if (node == NULL)
return FALSE;

// Remove node pointer from tree
if (node == wiringPiNodes)
{
wiringPiNodes = node->next;
}
else
{

nodePrevious = wiringPiNodes;

while (nodePrevious != NULL) {
if (nodePrevious->next == node) {
nodePrevious->next = node->next;
break;
}
nodePrevious = nodePrevious->next;
}
}

//!@todo Run device specific code

// Recover memory allocated to node
free(node);

return TRUE ;
}


#ifdef notYetReady
/*


+ 1
- 0
wiringPi/wiringPi.h View File

@@ -198,6 +198,7 @@ extern int wiringPiFailure (int fatal, const char *message, ...) ;

extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;
extern int wiringPiRemoveNode (int pinBase) ;

extern void wiringPiVersion (int *major, int *minor) ;
extern int wiringPiSetup (void) ;


Loading…
Cancel
Save