-
Notifications
You must be signed in to change notification settings - Fork 16
/
QueueIdxPeeking.ino
67 lines (51 loc) · 1.17 KB
/
QueueIdxPeeking.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
QueueIdxPeeking
LIFO / FIFO implementations can be tested by changing IMPLEMENTATION
This example code is in the public domain.
created 3 November 2019
by SMFSW
*/
#include <cQueue.h>
#define IMPLEMENTATION FIFO
#define OVERWRITE true
#define NB_RECS 6
typedef struct strRec {
uint16_t entry1;
uint16_t entry2;
} Rec;
Rec tab[9] = {
{ 0x1234, 0x3456 },
{ 0x5678, 0x7890 },
{ 0x90AB, 0xABCD },
{ 0xCDEF, 0xEFDC },
{ 0xDCBA, 0xBA09 },
{ 0x0987, 0x8765 },
{ 0x6543, 0x2112 },
{ 0x1234, 0x5678 },
{ 0x7890, 0xABCD }
};
Queue_t q; // Queue declaration
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(115200);
q_init(&q, sizeof(Rec), NB_RECS, IMPLEMENTATION, OVERWRITE);
}
// the loop function runs over and over again forever
void loop() {
unsigned int i;
for (i = 0 ; i < sizeof(tab)/sizeof(Rec) ; i++)
{
Rec rec = tab[i % (sizeof(tab)/sizeof(Rec))];
q_push(&q, &rec);
}
for (i = 0 ; i < NB_RECS+1 ; i++)
{
Rec rec = {0xffff,0xffff};
q_peekIdx(&q, &rec, i);
Serial.print(" ");
Serial.print(rec.entry1, HEX);
Serial.print(" ");
Serial.println(rec.entry2, HEX);
}
while(1);
}