-
Notifications
You must be signed in to change notification settings - Fork 0
/
CQueue.h
72 lines (55 loc) · 1.84 KB
/
CQueue.h
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
68
69
70
71
72
#ifndef _CQUEUE_H
#define _CQUEUE_H
#include <Arduino.h>
#include <Keyboard.h>
#include <stdint.h>
#include "attribute.h"
class CQueue
{
public:
// Data type of elements in the queue
typedef Card QDataType; /* Change `Card` to any data type you want
(e.g. byte, char, int, etc.) */
// Pass pointer to function to another function (call back function)
typedef void (*CallBackFunc) (QDataType*); //< [WARNING] POINTER HERE IS IMPORTANT
CQueue(); //< Default constructor
bool isEmpty();
bool isFull();
/**
* @brief Enqueue data
* @param
* - data: data (const) need to be enqueued
* @return
* - STATUS_SUCCESS: Enqueue data successfully.
* - ERR_QUEUE_FULL: the queue is full, can not enqueue anymore.
*/
Status enqueue(const QDataType data);
/**
* @brief Dequeue the top element of the queue
* @param none
* @return
* - STATUS_SUCCESS: Enqueue data successfully.
* - ERR_QUEUE_EMPTY: the queue is empty, can not dequeue anymore.
*/
Status dequeue();
const byte getSize(); //< Get queue's size at the moment this func is called
const byte getCapacity(); //< Get capacity of the queue
QDataType* getQueueData(); //< return pointer to the first element of
// the queue array
/**
* @public
* @brief Debug function
* @param pointer to the data-displaying function
* @return none
*/
void _debugPrint(CallBackFunc func);
private:
enum QueueInfo: byte {
_CAPACITY = 25 //< Maximum capacity of the queue
};
byte _size; //< Keep track of queue's size
int8_t _head; //< Pay attention to data type of `_head` and `_tail` is
int8_t _tail; // `int8_t` not `byte`.
QDataType _data[_CAPACITY]; //< Queue's data
};
#endif