mirror of
https://github.com/usatiuk/EggbotWireless.git
synced 2025-10-26 08:47:49 +01:00
make a QueueManager
This commit is contained in:
@@ -7,7 +7,4 @@
|
|||||||
#include "LocalCommand.h"
|
#include "LocalCommand.h"
|
||||||
#include "common/Commands.h"
|
#include "common/Commands.h"
|
||||||
|
|
||||||
extern std::queue<Command> commandQueue;
|
|
||||||
extern std::queue<LCommand> lCommandQueue;
|
|
||||||
|
|
||||||
#endif // GLOBALS_H
|
#endif // GLOBALS_H
|
||||||
35
Firmware/EggbotWireless/include/QueueManager.h
Normal file
35
Firmware/EggbotWireless/include/QueueManager.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#ifndef QUEUE_MANAGER_H
|
||||||
|
#define QUEUE_MANAGER_h
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <string>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
#include "common/Commands.h"
|
||||||
|
#include "LocalCommand.h"
|
||||||
|
#include "Executor.h"
|
||||||
|
#include "LocalExecutor.h"
|
||||||
|
#include "common/Status.h"
|
||||||
|
#include "Power.h"
|
||||||
|
#include "GCodeParser.h"
|
||||||
|
|
||||||
|
class QueueManager {
|
||||||
|
private:
|
||||||
|
std::queue<Command> commandQueue;
|
||||||
|
std::queue<LCommand> lCommandQueue;
|
||||||
|
|
||||||
|
bool shouldPrintSts;
|
||||||
|
void printSts(Status status);
|
||||||
|
|
||||||
|
public:
|
||||||
|
QueueManager();
|
||||||
|
void init();
|
||||||
|
void loopRoutine();
|
||||||
|
uint8_t execQueueNum();
|
||||||
|
void putCommand(std::string cmd);
|
||||||
|
void putCommand(char *cmd);
|
||||||
|
};
|
||||||
|
|
||||||
|
extern QueueManager queueManager;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,4 +1 @@
|
|||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
|
|
||||||
std::queue<Command> commandQueue;
|
|
||||||
std::queue<LCommand> lCommandQueue;
|
|
||||||
|
|||||||
47
Firmware/EggbotWireless/src/QueueManager.cpp
Normal file
47
Firmware/EggbotWireless/src/QueueManager.cpp
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#include "QueueManager.h"
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QueueManager::loopRoutine() {
|
||||||
|
Status status = executor.status();
|
||||||
|
if (shouldPrintSts) {
|
||||||
|
shouldPrintSts = false;
|
||||||
|
printSts(status);
|
||||||
|
}
|
||||||
|
if (status.type == StatusType::NEXT && !commandQueue.empty()) {
|
||||||
|
power.commandHook();
|
||||||
|
executor.execCommand(commandQueue.front());
|
||||||
|
commandQueue.pop();
|
||||||
|
shouldPrintSts = true;
|
||||||
|
}
|
||||||
|
if (!lCommandQueue.empty()) {
|
||||||
|
localExecutor.execCommand(lCommandQueue.front());
|
||||||
|
lCommandQueue.pop();
|
||||||
|
shouldPrintSts = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QueueManager::putCommand(std::string cmd) {
|
||||||
|
if (toupper(cmd[0]) == 'L') {
|
||||||
|
lCommandQueue.emplace(cmd);
|
||||||
|
} else {
|
||||||
|
commandQueue.push(parseGCode(cmd));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QueueManager queueManager;
|
||||||
@@ -15,10 +15,9 @@
|
|||||||
#include "Power.h"
|
#include "Power.h"
|
||||||
#include "WiFiManager.h"
|
#include "WiFiManager.h"
|
||||||
#include "WebAPI.h"
|
#include "WebAPI.h"
|
||||||
|
#include "QueueManager.h"
|
||||||
#include "common/Commands.h"
|
#include "common/Commands.h"
|
||||||
|
|
||||||
bool shouldPrintSts;
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Wire.begin(12, 13);
|
Wire.begin(12, 13);
|
||||||
@@ -30,22 +29,8 @@ void setup() {
|
|||||||
webApi.init();
|
webApi.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void 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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void serialLoop() {
|
void serialLoop() {
|
||||||
static std::string inString;
|
static std::string inString;
|
||||||
static bool localCmd = false;
|
|
||||||
while (Serial.available() > 0) {
|
while (Serial.available() > 0) {
|
||||||
char inChar = Serial.read();
|
char inChar = Serial.read();
|
||||||
|
|
||||||
@@ -54,17 +39,8 @@ void serialLoop() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inString.length() == 0 && toupper(inChar) == 'L') {
|
|
||||||
localCmd = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inChar == '\n') {
|
if (inChar == '\n') {
|
||||||
if (localCmd) {
|
queueManager.putCommand(inString);
|
||||||
lCommandQueue.emplace(inString);
|
|
||||||
localCmd = false;
|
|
||||||
} else {
|
|
||||||
commandQueue.push(parseGCode(inString));
|
|
||||||
}
|
|
||||||
inString = "";
|
inString = "";
|
||||||
} else {
|
} else {
|
||||||
inString += inChar;
|
inString += inChar;
|
||||||
@@ -72,28 +48,9 @@ void serialLoop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void commandsLoop() {
|
|
||||||
Status status = executor.status();
|
|
||||||
if (shouldPrintSts) {
|
|
||||||
shouldPrintSts = false;
|
|
||||||
printSts(status);
|
|
||||||
}
|
|
||||||
if (status.type == StatusType::NEXT && !commandQueue.empty()) {
|
|
||||||
power.commandHook();
|
|
||||||
executor.execCommand(commandQueue.front());
|
|
||||||
commandQueue.pop();
|
|
||||||
shouldPrintSts = true;
|
|
||||||
}
|
|
||||||
if (!lCommandQueue.empty()) {
|
|
||||||
localExecutor.execCommand(lCommandQueue.front());
|
|
||||||
lCommandQueue.pop();
|
|
||||||
shouldPrintSts = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
serialLoop();
|
serialLoop();
|
||||||
commandsLoop();
|
queueManager.loopRoutine();
|
||||||
|
|
||||||
MDNS.update();
|
MDNS.update();
|
||||||
webApi.loopRoutine();
|
webApi.loopRoutine();
|
||||||
|
|||||||
Reference in New Issue
Block a user