All Projects → sdesalas → Arduino-Queue.h

sdesalas / Arduino-Queue.h

Licence: other
Generic C++ circular queue for Arduino embedded projects.

Programming Languages

C++
36643 projects - #6 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Arduino-Queue.h

Libgenerics
libgenerics is a minimalistic and generic library for C basic data structures.
Stars: ✭ 42 (-28.81%)
Mutual labels:  queue, generic
Cdsa
A library of generic intrusive data structures and algorithms in ANSI C
Stars: ✭ 549 (+830.51%)
Mutual labels:  queue, generic
Mlib
Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).
Stars: ✭ 321 (+444.07%)
Mutual labels:  queue, generic
Sc
Common libraries and data structures for C.
Stars: ✭ 161 (+172.88%)
Mutual labels:  queue, generic
yii2-deferred-tasks
Yii2 extension for handling deferred tasks (background cron jobs)
Stars: ✭ 11 (-81.36%)
Mutual labels:  queue
Redis Smq
A simple high-performance Redis message queue for Node.js.
Stars: ✭ 230 (+289.83%)
Mutual labels:  queue
Srdownloadmanager
Powerful and easy-to-use file download manager based on NSURLSession. Provide download status, progress and completion callback block.
Stars: ✭ 221 (+274.58%)
Mutual labels:  queue
Chronicle Queue
Micro second messaging that stores everything to disk
Stars: ✭ 2,489 (+4118.64%)
Mutual labels:  queue
yii2-queue-monitor
Yii2 Queue Analytics Module
Stars: ✭ 99 (+67.8%)
Mutual labels:  queue
owl
A high-performance, Redis-backed job queueing library originally built for Quirrel. Has an in-memory mode for development use cases.
Stars: ✭ 83 (+40.68%)
Mutual labels:  queue
data-structure-project
自己实现集合框架系列整理总结
Stars: ✭ 29 (-50.85%)
Mutual labels:  queue
Gearmanbundle
GearmanBundle for Symfony2
Stars: ✭ 233 (+294.92%)
Mutual labels:  queue
microq
Micro job queue built on mongo
Stars: ✭ 67 (+13.56%)
Mutual labels:  queue
Wx Promise Request
解决微信小程序 wx.request 请求的并发数限制、不支持异步问题
Stars: ✭ 226 (+283.05%)
Mutual labels:  queue
generic-for-core
🏗️ Generic Repository & UOW Pattern For ASP.NET Core
Stars: ✭ 55 (-6.78%)
Mutual labels:  generic
Promise Queue
Promise-based queue
Stars: ✭ 210 (+255.93%)
Mutual labels:  queue
Golang Examples
Some examples for the programming language Go.
Stars: ✭ 14 (-76.27%)
Mutual labels:  generic
yii2-mailqueue
Yii2 mail queue component for yii2-swiftmailer.
Stars: ✭ 15 (-74.58%)
Mutual labels:  queue
flask-redis-docker
A minimal template for dockerized flask app with redis task queue
Stars: ✭ 49 (-16.95%)
Mutual labels:  queue
Task Easy
A simple, customizable, and lightweight priority queue for promises.
Stars: ✭ 244 (+313.56%)
Mutual labels:  queue

Build Status

Queue.h

Generic C++ circular queue for Arduino embedded projects.

Why?

Because I need one, and I need it to be generic. I dabble with arduino robotics a bit and this is the cornerstone for getting the most out of the microcontroller loop - ie dont delay, just stick stuff in a queue and process it when you can.

Constructor

Queue<T> queue = Queue<T>(int maxlength = 256);

Creates a queue of a generic type T with a maximum queue size. If maxlength is not defined it will default to 256.

NOTE: If the queue grows to maxlength items (and you dont take them out) any additional items added will drop out of the queue. Please bear this in mind when defining maxlength so it is a reasonable balance between RAM usage and functional usefulness.

Examples

Queue<byte> queue = Queue<byte>(1000); // Queue of max 1000 bytes
Queue<int> queue = Queue<int>(); // Queue of max 256 int
Queue<char> queue = Queue<char>(260); // Queue of max 260 chars
Queue<Point> queue = Queue<Point>(10); // Queue of max 10 'Point', where 'Point' is a struct 
Queue<String> queue = Queue<String>(); // Queue of max 256 'String', where 'String' is a class

Methods

queue.push(T item);

Adds a generic item (of T type) at the back of the queue.

Example

Queue<byte> queue = Queue<byte>();
byte a = 255;
byte b = 0;
queue.push(a);
queue.push(b);

T item = queue.pop();

Gets a generic item (of T type) from the front of the queue.

T item = queue.peek();

Same as .pop() but keeps the item in the queue.

Example

Queue<byte> queue = Queue<byte>(); 
byte a = 255;
byte b = 0;
queue.push(a);
queue.push(b);
assert(a == queue.pop()); // true
assert(b == queue.peek()); // true
assert(b == queue.pop()); // true

int front = queue.front();

Gets the current position in the front of the queue. Used for testing queue logic.

Example

Queue<byte> queue = Queue<byte>(); 
byte a = 255;
byte b = 0;
queue.push(a);
assert(1 == queue.front()); // true
queue.push(b);
assert(2 == queue.front()); // true

int back = queue.back();

Gets the current position at the back of the queue. Used for testing queue logic.

Example

Queue<byte> queue = Queue<byte>(); 
byte a = 255;
byte b = 0;
queue.push(a);
assert(0 == queue.back()); // true
assert(1 == queue.front()); // true
queue.pop();
assert(1 == queue.back()); // true
assert(1 == queue.front()); // true

queue.clear();

Removes all items from the queue.

Example

Queue<byte> queue = Queue<byte>(); 
queue.push(1);
queue.push(2);
queue.clear();
queue.push(3);
assert(3 == queue.pop()); // true

All Together now

The following example is testable using 'Serial Monitor' over USB connection from Arduino IDE.

Copy the file Queue.h in the same folder as your *.ino code file.

Make sure you set the baud rate to 115200 and No new line.

#include "Queue.h"

Queue<char> queue = Queue<char>(5); // Max 5 chars!

void setup() {
  Serial.begin(115200);
}

void loop() {
  while(Serial.available()) {
    queue.push(Serial.read());
  }

  Serial.print(millis() / 1000);
  Serial.print(": ");
  int count = queue.count();
  if (count > 0) {
    Serial.print("Found ");
    Serial.print(count);
    Serial.print(" items.. '");
    Serial.print(queue.pop());
    Serial.print("' is the oldest. We are ");
    Serial.print(queue.front());
    Serial.print(" in front and ");
    Serial.print(queue.back());
    Serial.print(" in back. Next is.. '");
    Serial.print(queue.peek());
    Serial.println("'.");
  } else {
    Serial.println("Nothing to process..."); 
  }
  delay(2000);
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].