-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathSimpleQueueStatic.ino
62 lines (47 loc) · 1.14 KB
/
SimpleQueueStatic.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
/*
Simple Queue Static
Simple queue demonstration using static queue data array
LIFO / FIFO implementations can be tested by changing IMPLEMENTATION
This example code is in the public domain.
created 15 November 2022
by SMFSW
*/
#include <cppQueue.h>
#define IMPLEMENTATION LIFO
typedef struct strRec {
uint16_t entry1;
uint16_t entry2;
} Rec;
Rec tab[6] = {
{ 0x1234, 0x3456 },
{ 0x5678, 0x7890 },
{ 0x90AB, 0xABCD },
{ 0xCDEF, 0xEFDC },
{ 0xDCBA, 0xBA09 },
{ 0x0987, 0x8765 }
};
#define NB_ITEMS 10
Rec q_dat[NB_ITEMS];
cppQueue q(sizeof(Rec), NB_ITEMS, IMPLEMENTATION, false, q_dat, sizeof(q_dat)); // Instantiate queue with static queue data arguments
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(115200);
}
// 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];
q.push(&rec);
}
for (i = 0 ; i < sizeof(tab)/sizeof(Rec) ; i++)
{
Rec rec;
q.pop(&rec);
Serial.print(rec.entry1, HEX);
Serial.print(" ");
Serial.println(rec.entry2, HEX);
}
while(1);
}