mirror of
https://github.com/usatiuk/EggbotWireless.git
synced 2025-10-26 16:57:48 +01:00
putCommand api
This commit is contained in:
@@ -25,7 +25,7 @@ class QueueManager {
|
|||||||
QueueManager();
|
QueueManager();
|
||||||
void init();
|
void init();
|
||||||
void loopRoutine();
|
void loopRoutine();
|
||||||
uint8_t execQueueNum();
|
uint8_t execQueueSize();
|
||||||
void putCommand(std::string cmd);
|
void putCommand(std::string cmd);
|
||||||
void putCommand(char *cmd);
|
void putCommand(char *cmd);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
class WebAPI {
|
class WebAPI {
|
||||||
private:
|
private:
|
||||||
void handleNotFound();
|
void handleNotFound();
|
||||||
|
void handlePutCommand();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WebAPI();
|
WebAPI();
|
||||||
|
|||||||
@@ -5,16 +5,16 @@ QueueManager::QueueManager() {}
|
|||||||
void QueueManager::init() {}
|
void QueueManager::init() {}
|
||||||
|
|
||||||
void QueueManager::printSts(Status status) {
|
void QueueManager::printSts(Status status) {
|
||||||
if (status.type == StatusType::WAIT) {
|
if (status.type == StatusType::WAIT) {
|
||||||
shouldPrintSts = true;
|
shouldPrintSts = true;
|
||||||
} else if (status.type == StatusType::NEXT) {
|
} else if (status.type == StatusType::NEXT) {
|
||||||
Serial.println("OK");
|
Serial.println("OK");
|
||||||
} else if (status.type == StatusType::TIMEOUT) {
|
} else if (status.type == StatusType::TIMEOUT) {
|
||||||
Serial.println("Timeout");
|
Serial.println("Timeout");
|
||||||
} else {
|
} else {
|
||||||
Serial.print("Error: ");
|
Serial.print("Error: ");
|
||||||
Serial.println(static_cast<int>(status.type));
|
Serial.println(static_cast<int>(status.type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueueManager::loopRoutine() {
|
void QueueManager::loopRoutine() {
|
||||||
@@ -44,4 +44,10 @@ void QueueManager::putCommand(std::string cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t QueueManager::execQueueSize() {
|
||||||
|
return commandQueue.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void QueueManager::putCommand(char *cmd) { putCommand(std::string(cmd)); }
|
||||||
|
|
||||||
QueueManager queueManager;
|
QueueManager queueManager;
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "WebAPI.h"
|
#include "WebAPI.h"
|
||||||
|
#include "QueueManager.h"
|
||||||
|
|
||||||
ESP8266WebServer server(80);
|
ESP8266WebServer server(80);
|
||||||
|
|
||||||
@@ -8,7 +9,13 @@ void WebAPI::handleNotFound() {
|
|||||||
server.send(404, "text/plain", "File Not Found\n\n");
|
server.send(404, "text/plain", "File Not Found\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebAPI::handlePutCommand() {
|
||||||
|
queueManager.putCommand(server.arg("plain").c_str());
|
||||||
|
server.send(200, "text/plain", String(queueManager.execQueueSize()));
|
||||||
|
}
|
||||||
|
|
||||||
void WebAPI::init() {
|
void WebAPI::init() {
|
||||||
|
server.on("/putCommand", HTTP_POST, std::bind(&WebAPI::handlePutCommand, this));
|
||||||
server.onNotFound(std::bind(&WebAPI::handleNotFound, this));
|
server.onNotFound(std::bind(&WebAPI::handleNotFound, this));
|
||||||
server.begin();
|
server.begin();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user