ME405 Library  Version 0.38
Python library in support of ME405 class
cqueue.IntQueue Class Reference

A fast, pre-allocated queue of integers for MicroPython. More...

Public Member Functions

def __init__ (self, int size)
 A fast, pre-allocated queue of integers 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 an integer 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...
 

Detailed Description

A fast, pre-allocated queue of integers for MicroPython.

This class is written in C for speed. When an IntQueue 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:

QUEUE_SIZE = 42
int_queue = cqueue.IntQueue(QUEUE_SIZE)
for count in range(27):
int_queue.put(count) # Or do this in interrupt callback
...
while int_queue.any():
print(int_queue.get())
A fast, pre-allocated queue of integers for MicroPython.
Definition: cqueue.py:131

Constructor & Destructor Documentation

◆ __init__()

def cqueue.IntQueue.__init__ (   self,
int  size 
)

A fast, pre-allocated queue of integers for MicroPython.

This class is written in C for speed. When an IntQueue 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:

QUEUE_SIZE = 42
int_queue = cqueue.IntQueue(QUEUE_SIZE)
for count in range(27):
int_queue.put(count) # Or do this in interrupt callback
...
while int_queue.any():
print(int_queue.get())

Create a fast queue for integers.

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.

Parameters
sizeThe maximum number of integers that the queue can hold

Member Function Documentation

◆ any()

bool cqueue.IntQueue.any ( )

Checks if there are any items available in the queue.

Returns
True if there is at least one item in the queue, False if not

◆ available()

int cqueue.IntQueue.available ( )

Checks how many items are available to be read from the queue.

Returns
An integer containing the number of items in the queue

◆ clear()

def cqueue.IntQueue.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.

◆ full()

bool cqueue.IntQueue.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.

Returns
True if the queue is currently full or False if not

◆ get()

int cqueue.IntQueue.get ( )

Get an item from the queue if one is available.

If the queue is empty, None will be returned.

Returns
The oldest integer in the queue, or None if the queue is currently empty.

◆ max_full()

int cqueue.IntQueue.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.

Returns
The maximum number of items that have been in the queue

◆ put()

def cqueue.IntQueue.put ( int  data)

Put an integer 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.

Parameters
dataAn integer to be put into the back of the queue

The documentation for this class was generated from the following file: