A fast, pre-allocated queue of characters for MicroPython. More...
Public Member Functions | |
def | __init__ (self, int size) |
A fast, pre-allocated queue of characters for MicroPython. More... | |
bool | any () |
Checks if there are any items available in the queue. More... | |
int | available () |
Checks how many items are available to be read from the queue. More... | |
def | put (int data) |
Put a character or string into the queue. More... | |
int | get () |
Get an item from the queue if one is available. More... | |
def | clear () |
Empty the queue. More... | |
bool | full () |
Check whether the queue is currently full. More... | |
int | max_full () |
Get the maximum number of unread items that have been in the queue. More... | |
A fast, pre-allocated queue of characters for MicroPython.
Either bytes or Unicode (str) characters may be written into a ByteQueue; only bytes will be stored and retrieved from it. This class is written in C for speed. When a ByteQueue object is created, memory is allocated to hold the given number of items. Data is put into the queue with its put() method, and the oldest available data is retrieved with the get() method. Because running put() and get() doesn't allocate any memory, it can be used in interrupt callbacks.
When one creates a queue, one specifies the number of items which can be stored at once in the queue. After creating a queue, one writes items into a queue using its put() method. Writing into a full queue causes the oldest data to be erased; method full() can be used before writing to check for such a problem. Reading from the queue is done by a call to get(), which returns the oldest available data item or None
if the queue is empty:
def cqueue.ByteQueue.__init__ | ( | self, | |
int | size | ||
) |
A fast, pre-allocated queue of characters for MicroPython.
Either bytes or Unicode (str) characters may be written into a ByteQueue; only bytes will be stored and retrieved from it. This class is written in C for speed. When a ByteQueue object is created, memory is allocated to hold the given number of items. Data is put into the queue with its put() method, and the oldest available data is retrieved with the get() method. Because running put() and get() doesn't allocate any memory, it can be used in interrupt callbacks.
When one creates a queue, one specifies the number of items which can be stored at once in the queue. After creating a queue, one writes items into a queue using its put() method. Writing into a full queue causes the oldest data to be erased; method full() can be used before writing to check for such a problem. Reading from the queue is done by a call to get(), which returns the oldest available data item or None
if the queue is empty:
Create a fast queue for characters.
When the queue is created, memory is allocated for the given number of items. Putting items into the queue won't cause new memory to be allocated, so the queue can be used in interrupt callbacks and will run quickly.
size | The maximum number of integers that the queue can hold |
bool cqueue.ByteQueue.any | ( | ) |
Checks if there are any items available in the queue.
True
if there is at least one item in the queue, False
if not int cqueue.ByteQueue.available | ( | ) |
Checks how many items are available to be read from the queue.
def cqueue.ByteQueue.clear | ( | ) |
Empty the queue.
The pointers used to access data in the queue are reset to their empty positions. The contents of the memory are not changed and no new memory is allocated.
bool cqueue.ByteQueue.full | ( | ) |
Check whether the queue is currently full.
If the queue is full, writing new data will cause the oldest data to be overwritten and lost.
True
if the queue is currently full or False
if not int cqueue.ByteQueue.get | ( | ) |
Get an item from the queue if one is available.
If the queue is empty, None
will be returned.
None
if the queue is currently empty. int cqueue.ByteQueue.max_full | ( | ) |
Get the maximum number of unread items that have been in the queue.
This method returns the maximum number of items that have been in the queue at any point since the queue was created or cleared.
def cqueue.ByteQueue.put | ( | int | data | ) |
Put a character or string into the queue.
If the queue is already full, the oldest data will be overwritten. If this could cause problems, one can call full()
to check if the queue is already full before writing the data.
data | An integer to be put into the back of the queue |