defragster
Senior Member+
H:# would be H:3 for Head at 3 and T:# would be T:1 for Tail at 1. That would show it wraps over the end [if you knew how many elements it had]
for ( uint16_t i = 2; i <= (([COLOR="#FF0000"](int)[/COLOR]_cabuf[[COLOR="#FF0000"](int)[/COLOR]_cbuf[(head)&(_size-1)]][0] << 8*sizeof(T)) | (int)_cabuf[(int)_cbuf[(head)&(_size-1)]][1])+1; i++ ) {
Serial.print((int)_cabuf[(int)_cbuf[(head)&(_size-1)]][i]); Serial.print(" ");
} Serial.print("("); Serial.print(([COLOR="#FF0000"](int)[/COLOR]([COLOR="#FF0000"](int)[/COLOR]_cabuf[[COLOR="#FF0000"](int)[/COLOR]_cbuf[(head)&(_size-1)]][0] << 8*sizeof(T)) | [COLOR="#FF0000"](int)[/COLOR]_cabuf[(int)_cbuf[(head)&(_size-1)]][1])); Serial.println(" entries.)");
Circular_Buffer<uint8_t, 8> k;
k.push_back(1);
k.push_back(2);
k.push_back(3);
k.push_back(4);
k.push_back(5);
k.push_back(6);
k.push_back(7);
k.push_back(8);
k.push_back(9);
k.list();
Queue Size: 8
Indice: [1] [2] [3] [4] [5] [6] [7] [0]
Entry: 2 3 4 5 6 7 8 9
Queue Size: 5
[Indice] ___________________________Entries:___________________________
0 0 1 2 3 4 5 (6 entries.)
1 6 7 8 9 10 11 (6 entries.)
2 12 13 14 15 16 17 (6 entries.)
3 18 19 20 21 22 23 (6 entries.)
4 24 25 26 27 28 29 (6 entries.)
Queue Size: 8
[Indice] [Entries]
3 18 19 20 21 22 23 (6 entries.)
4 24 25 26 27 28 29 (6 entries.)
5 18 19 20 21 22 23 (6 entries.)
6 24 25 26 27 28 29 (6 entries.)
7 18 19 20 21 22 23 (6 entries.)
0 24 25 26 27 28 29 (6 entries.)
1 18 19 20 21 22 23 (6 entries.)
2 24 25 26 27 28 29 (6 entries.)
Queue Size: 7
Indice: [0] [1] [2] [3] [4] [5] [6]
Entries: -3.1415901 -12.3456001 -78.9123383 -7.9123402 -11.9123402 -58.9123383 -18.9123402
Queue Size: 8
Indice: [1] [2] [3] [4] [5] [6] [7] [0]
Entries: 2 99 4000 399 4000 4000 4000 4000
if ( [COLOR="#FF0000"](int)[/COLOR]_cbuf[(head+i)&(_size-1)] [COLOR="#FF0000"]!=[/COLOR] _cbuf[(head+i)&(_size-1)] ) { // possible float?
Serial.print(_cbuf[(head+i)&(_size-1)][COLOR="#FF0000"][B],7[/B][/COLOR]); Serial.print("\t");
}
else {
Serial.print(_cbuf[(head+i)&(_size-1)]); Serial.print("\t\t");
}
Circular Ring Buffer Queue Size: 7 / 16
Indice: [0] [1] [2] [3] [4] [5] [6]
Entries: -3.1415901 -12.3456001 -78.9123383 -7.9123402 -11.9123402 -58.9123383 -18.9123402
Circular Array Buffer Queue Size: 4 / 4
First Entry: 6 7 8 9 10 11 (6 entries.)
Last Entry: 24 25 26 27 28 29 (6 entries.)
[Indice] [Entries]
1 6 7 8 9 10 11 (6 entries.)
2 12 13 14 15 16 17 (6 entries.)
3 18 19 20 21 22 23 (6 entries.)
0 24 25 26 27 28 29 (6 entries.)
Circular Array Buffer Queue Size: 3 / 4
First Entry: 123.4567871 789.0123291 (2 entries.)
Last Entry: 88.0199966 743.6900024 (2 entries.)
[Indice] [Entries]
0 123.4567871 789.0123291 (2 entries.)
1 333.7864380 69.1100006 (2 entries.)
2 88.0199966 743.6900024 (2 entries.)
Circular Ring Buffer Queue Size: 8 / 8
Indice: [1] [2] [3] [4] [5] [6] [7] [0]
Entries: 2 99 4000 399 4000 4000 4000 4000
Circular_Buffer<float, 4, 6> flt;
float _f[] = { [COLOR="#FF0000"]123.456789, 789.012345[/COLOR] };
float _f1[] = { 333.78643, 69.11 };
float _f2[] = { 88.02, 743.69 };
[COLOR="#FF0000"]flt.push_back[/COLOR](_f, 2);
flt.push_back(_f1, 2);
flt.push_back(_f2, 2);
flt.list();
[COLOR="#FF0000"]float dump[2];
flt.pop_front(dump, 2);
Serial.print(dump[0], 7); Serial.print(" : "); Serial.println(dump[1], 7);[/COLOR]
Circular Array Buffer Queue Size: 3 / 4
First Entry: 123.4567871 789.0123291 (2 entries.)
Last Entry: 88.0199966 743.6900024 (2 entries.)
[Indice] [Entries]
0 123.4567871 789.0123291 (2 entries.)
1 333.7864380 69.1100006 (2 entries.)
2 88.0199966 743.6900024 (2 entries.)
[COLOR="#FF0000"]123.4567871 : 789.0123291[/COLOR]
Circular_Buffer<uint32_t, 32, 250> print_test;
Circular_Buffer<uint32_t, 32, 220> print_test;
uint32_t myBuf[24]; // buffer of 24 uint32_t’s
// some code to setup your buffer data
print_test.push_back(myBuf,24);
uint32_t data[print_test.length_front()];
print_test.pop_front(data, print_test.length_front());
print_test.peek_front()[8]; // shows you value in the 7th indice of the array queue
for ( uint16_t i = 0; i < print_test.length_front(); i++ ) {
Serial.print(print_test.front()[i]);
Serial.print(“ “);
}
Serial.println();
[ATTACH]13704._xfImport[/ATTACH]
#include "circular_buffer.h"
void setup() {
Serial.begin(115200);
delay(5000);
// List example
Circular_Buffer<float, 4, 6> flt;
float _f[] = { 123.456789, 789.012345 };
float _f1[] = { 333.78643, 69.11 };
float _f2[] = { 88.02, 743.69 };
float _f3[] = { 223.456789, 989.012345 };
float _f4[] = { 433.78643, 79.11 };
float _f5[] = { 99.02, 843.69 };
flt.push_back(_f, 2); flt.list();
flt.push_back(_f1, 2); flt.list();
flt.push_back(_f2, 2); flt.list();
flt.push_back(_f3, 2); flt.list();
flt.push_back(_f4, 2); flt.list();
flt.push_back(_f5, 2); flt.list();
float dump[2];
flt.pop_front(dump, 2);
Serial.print(dump[0], 7); Serial.print(" : "); Serial.println(dump[1], 7);
}
void loop() {
// put your main code here, to run repeatedly:
}
flt.length_front(); <-- this would be the length of the queue your reading
flt.peek_front()[2]; // read the first queue item 3rd position
for ( uint16_t i = 0; i < [COLOR="#006400"]flt.length_front()[/COLOR]; i++ ) {
Serial.print([COLOR="#006400"]flt.peek_front()[i][/COLOR],7); // print 7 decimals
Serial.print(" ");
}
Serial.println();
// that wont remove it from queue, but it'll print it. You'll have to pop it to remove it.
[COLOR="#006400"]flt.pop_front();[/COLOR]
flt.remove(1); // removes indice 1 ( actually array 2 ) from queue
Circular_Buffer<uint16_t, SPI_MST_QUEUE_SLOTS, SPI_MST_DATA_BUFFER_MAX> SPI_MSTransfer::mtsca;