diff --git a/include/Main.h b/include/Main.h index 67d2dbb8..5b716a09 100644 --- a/include/Main.h +++ b/include/Main.h @@ -10,3 +10,4 @@ #include "ESPConfiguration.h" #include "MqttClient.h" #include "classes/CommandBuf.h" +#include "classes/QueueBuf.h" diff --git a/include/classes/QueueBuf.h b/include/classes/QueueBuf.h new file mode 100644 index 00000000..6aa60dfe --- /dev/null +++ b/include/classes/QueueBuf.h @@ -0,0 +1,23 @@ +#pragma once +#include "Global.h" +#include +#include + +using namespace std; + +class QueueBuf; + +class QueueBuf { + public: + QueueBuf(); + ~QueueBuf(); + + void push(int element); + void pop(); + int front(); + + private: + queue queue1; +}; + +extern QueueBuf* myQueue; \ No newline at end of file diff --git a/src/Main.cpp b/src/Main.cpp index 5ceef3e7..bc5a7c4f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -41,17 +41,27 @@ void setup() { sendConfigJson = new SendJson; sendWigdetsJson = new SendJson; - myBuf = new CommandBuf; + // myBuf = new CommandBuf; + // + // myBuf->addCommand("zero"); + // myBuf->addCommand("one"); + // myBuf->addCommand("two"); + // myBuf->printCommands(); + // + // myBuf->getLastCommand(); + // myBuf->getLastCommand(); + // myBuf->getLastCommand(); + // myBuf->printCommands(); - myBuf->addCommand("zero"); - myBuf->addCommand("one"); - myBuf->addCommand("two"); - myBuf->printCommands(); + myQueue = new QueueBuf; - myBuf->getLastCommand(); - myBuf->getLastCommand(); - myBuf->getLastCommand(); - //myBuf->printCommands(); + myQueue->push(10); + myQueue->push(20); + myQueue->push(30); + + Serial.println(myQueue->front()); + Serial.println(myQueue->front()); + Serial.println(myQueue->front()); configure("/config.json"); diff --git a/src/classes/QueueBuf.cpp b/src/classes/QueueBuf.cpp new file mode 100644 index 00000000..7c62514e --- /dev/null +++ b/src/classes/QueueBuf.cpp @@ -0,0 +1,28 @@ +#include "classes/QueueBuf.h" + +QueueBuf::QueueBuf() {} +QueueBuf::~QueueBuf() {} + +//добавим элемент в конец очереди +void QueueBuf::push(int element) { + queue1.push(element); +} + +//удалим элемент из начала очереди +void QueueBuf::pop() { + if (!queue1.empty()) { + queue1.pop(); + } +} + +//вернуть элемент из начала очереди и удалить его +int QueueBuf::front() { + int ret; + if (!queue1.empty()) { + ret = queue1.front(); + queue1.pop(); + } + return ret; +} + +QueueBuf* myQueue; \ No newline at end of file