add pop function in FIFOBuff
This commit is contained in:
parent
feec2a0a91
commit
b08f1afe7f
@ -122,6 +122,34 @@ bool FIFOBuffChar_get(FIFOBuffChar_t *fifo, char *p) // Change the function para
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool FIFOBuffChar_pop(FIFOBuffChar_t *fifo)
|
||||
{
|
||||
bool ok = true;
|
||||
|
||||
if (fifo->FirstEl_p == NULL)
|
||||
{ // buffer is empty
|
||||
ok = false;
|
||||
}
|
||||
else
|
||||
{ // there is data in the buffer
|
||||
// find the second last element
|
||||
FIFOBuffChar_element_t* secondLastEl; = fifo->FirstEl_p;
|
||||
while (secondLastEl->nextElement != fifo->LastEl_p)
|
||||
{
|
||||
secondLastEl = secondLastEl->nextElement;
|
||||
}
|
||||
|
||||
// remove last element
|
||||
free(fifo->LastEl_p);
|
||||
|
||||
// update chain
|
||||
secondLastEl->nextElement == NULL;
|
||||
fifo->LastEl_p = secondLastEl;
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool FIFOBuffChar_is_full(FIFOBuffChar_t *fifo)
|
||||
{
|
||||
return fifo->full;
|
||||
|
||||
@ -32,7 +32,10 @@ extern bool FIFOBuffChar_put(FIFOBuffChar_t *fifo, char i);
|
||||
|
||||
// get value from buffer and writes it to *p if buffer not empty
|
||||
// returns true on success or false otherways
|
||||
extern bool FIFOBuffChar_get(FIFOBuffChar_t *fifo, char *p); //moet dit "char" zijn of "uint8_t"
|
||||
extern bool FIFOBuffChar_get(FIFOBuffChar_t *fifo, char *p);
|
||||
|
||||
// pop last added value from the buffer
|
||||
extern bool FIFOBuffChar_pop(FIFOBuffChar_t *fifo);
|
||||
|
||||
// returns false if last put fails to gain memory and no get is called afterwards or true otherwise
|
||||
extern bool FIFOBuffChar_is_full(FIFOBuffChar_t *fifo);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user