Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

diagnostics, floats

  • Loading branch information...
commit 5587fb221bddd1d432f7fb15a3a7a3d312b853d1 1 parent 812c8bc
Karl Anderson kra authored
Showing with 15 additions and 10 deletions.
  1. +15 −10 effects/Queue/Queue.h
25 effects/Queue/Queue.h
View
@@ -7,17 +7,22 @@
#include <Arduino.h>
+void die(const char *message)
+{
+ Serial.println(message);
+}
+
class Queue {
public:
Queue(const int s);
~Queue();
- void push(const int i);
- int pop();
+ void push(const float i);
+ float pop();
bool isEmpty() const;
bool isFull() const;
private:
- int *contents;
+ float *contents;
int size;
int items;
int head;
@@ -29,8 +34,8 @@ Queue::Queue(const int s = 10) {
items = 0;
head = 0;
tail = 0;
- contents = (int *) malloc (sizeof (int) * size);
- //if (contents == NULL) die
+ contents = (float *) malloc (sizeof (float) * size);
+ if (contents == NULL) die("out of memory");
}
Queue::~Queue() {
@@ -42,15 +47,15 @@ Queue::~Queue() {
tail = 0;
}
-void Queue::push(const int i) {
- //if (isFull()) die
+void Queue::push(const float i) {
+ if (isFull()) die("bad push");
contents[tail++] = i;
if (tail == size) tail = 0;
items++;
}
-int Queue::pop() {
- //if (isEmpty()) die
- int item = contents[head++];
+float Queue::pop() {
+ if (isEmpty()) die("bad pop");
+ float item = contents[head++];
items--;
if (head == size) head = 0;
return item;
Please sign in to comment.
Something went wrong with that request. Please try again.