mirror of
https://github.com/usatiuk/EggbotWireless.git
synced 2025-10-26 16:57:48 +01:00
basic gcode sender thing
This commit is contained in:
@@ -10,6 +10,8 @@ class WebAPI {
|
||||
void handleNotFound();
|
||||
void handlePutCommand();
|
||||
void handleGetStatus();
|
||||
void sendCORS();
|
||||
|
||||
String getStatusJson();
|
||||
public:
|
||||
WebAPI();
|
||||
|
||||
@@ -37,16 +37,19 @@ void QueueManager::loopRoutine() {
|
||||
}
|
||||
|
||||
void QueueManager::putCommand(std::string cmd) {
|
||||
if (!std::isalnum(cmd[0])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (toupper(cmd[0]) == 'L') {
|
||||
lCommandQueue.emplace(cmd);
|
||||
} else {
|
||||
commandQueue.push(parseGCode(cmd));
|
||||
Command cmdp = parseGCode(cmd);
|
||||
commandQueue.push(cmdp);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t QueueManager::execQueueSize() {
|
||||
return commandQueue.size();
|
||||
}
|
||||
uint8_t QueueManager::execQueueSize() { return commandQueue.size(); }
|
||||
|
||||
void QueueManager::putCommand(char *cmd) { putCommand(std::string(cmd)); }
|
||||
|
||||
|
||||
@@ -23,16 +23,33 @@ String WebAPI::getStatusJson() {
|
||||
return out;
|
||||
}
|
||||
|
||||
void WebAPI::sendCORS() {
|
||||
server.sendHeader("Access-Control-Allow-Origin", "*");
|
||||
server.sendHeader("Access-Control-Max-Age", "10000");
|
||||
server.sendHeader("Access-Control-Allow-Methods", "PUT,POST,GET,OPTIONS");
|
||||
server.sendHeader("Access-Control-Allow-Headers",
|
||||
"X-Requested-With, X-HTTP-Method-Override, "
|
||||
"Content-Type, Cache-Control, Accept");
|
||||
}
|
||||
|
||||
void WebAPI::handleNotFound() {
|
||||
server.send(404, "text/plain", "File Not Found\n\n");
|
||||
if (server.method() == HTTP_OPTIONS) {
|
||||
sendCORS();
|
||||
server.send(204);
|
||||
} else {
|
||||
server.send(404, "text/plain", "");
|
||||
}
|
||||
}
|
||||
|
||||
void WebAPI::handlePutCommand() {
|
||||
queueManager.putCommand(server.arg("plain").c_str());
|
||||
sendCORS();
|
||||
String cmd = server.arg("plain");
|
||||
queueManager.putCommand(cmd.c_str());
|
||||
server.send(200, "application/json", getStatusJson());
|
||||
}
|
||||
|
||||
void WebAPI::handleGetStatus() {
|
||||
sendCORS();
|
||||
server.send(200, "application/json", getStatusJson());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user