-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from vascojdb/master
Major updates for ESP8266. Changed constructors with configurable items count and/or bytes size
- Loading branch information
Showing
4 changed files
with
331 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
Author: Vasco Baptista | ||
email: [email protected] | ||
An example of using Einar Arnason's queue | ||
In this example we create a queue of int's | ||
limited by the maximum amount of items | ||
Usage and further info: | ||
https://github.com/EinarArnason/ArduinoQueue | ||
*/ | ||
|
||
#include "Queue.h" | ||
|
||
#define QUEUE_SIZE_ITEMS 10 | ||
|
||
// Queue creation: | ||
DataQueue<int> intQueue(QUEUE_SIZE_ITEMS); | ||
|
||
void printQueueStats() { | ||
Serial.println(""); | ||
Serial.printf("Size of each element: %u bytes\r\n", intQueue.item_size()); | ||
Serial.printf("Items in queue now: %u items\r\n", intQueue.item_count()); | ||
Serial.printf("Queue actual max items: %u items\r\n", intQueue.max_queue_size()); | ||
Serial.printf("Queue actual max memory: %u bytes\r\n", intQueue.max_memory_size()); | ||
Serial.println(""); | ||
} | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
Serial.println(""); | ||
Serial.println("========== Queue example =========="); | ||
Serial.printf("Desired max item size: %u items\r\n", QUEUE_SIZE_ITEMS); | ||
Serial.println("==================================="); | ||
} | ||
|
||
void loop() { | ||
printQueueStats(); | ||
|
||
// Add elements: (add more than the queue size for demo purposes) | ||
for(int n=1; n<QUEUE_SIZE_ITEMS+5; n++) { | ||
if (!intQueue.isFull()) { | ||
Serial.printf("Adding value: %i\r\n", n); | ||
intQueue.enqueue(n); | ||
} | ||
else { | ||
Serial.println("Queue is full!"); | ||
} | ||
} | ||
|
||
printQueueStats(); | ||
|
||
// Remove elements: (remove more than the queue size for demo purposes) | ||
for(int n=1; n<QUEUE_SIZE_ITEMS+5; n++) { | ||
if (!intQueue.isEmpty()) { | ||
|
||
int value = intQueue.dequeue(); | ||
Serial.printf("Removed value: %i\r\n", value); | ||
} | ||
else { | ||
Serial.println("Queue is empty!"); | ||
} | ||
} | ||
|
||
printQueueStats(); | ||
|
||
// Loop forever | ||
while(true) { | ||
#ifdef ESP8266 | ||
ESP.wdtFeed(); | ||
#endif | ||
} | ||
} |
Oops, something went wrong.