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