why did i even think of THAT?

This commit is contained in:
2019-08-06 12:25:06 +03:00
parent 6e451b3b9a
commit ccde6e8ae5
6 changed files with 21 additions and 34 deletions

View File

@@ -62,7 +62,7 @@ export class GcodeSenderComponent extends React.PureComponent<
const gcodeLinesQueue = [...this.state.gcodeLinesQueue]; const gcodeLinesQueue = [...this.state.gcodeLinesQueue];
const gcodeLinesSent = [...this.state.gcodeLinesSent]; const gcodeLinesSent = [...this.state.gcodeLinesSent];
const { executing } = this.state; const { executing } = this.state;
if (executing && status.commandQueue < 1) { if (executing && status.commandQueue < 10) {
if (gcodeLinesQueue && gcodeLinesQueue.length > 0) { if (gcodeLinesQueue && gcodeLinesQueue.length > 0) {
const command = gcodeLinesQueue.shift(); const command = gcodeLinesQueue.shift();
console.log(parseCommand(command)); console.log(parseCommand(command));

View File

@@ -10,8 +10,6 @@
class Executor class Executor
{ {
private: private:
unsigned long lastStsTime;
Status lastSts;
public: public:
Executor(/* args */); Executor(/* args */);
void execCommand(Command command); void execCommand(Command command);

View File

@@ -24,12 +24,6 @@ void Executor::execCommand(Command command) {
} }
Status Executor::status() { Status Executor::status() {
unsigned long reqTime = millis();
if (reqTime - lastStsTime < lastStsTTL) {
return lastSts;
}
Status status; Status status;
unsigned int curByte; unsigned int curByte;
byte rxBuffer[i2cStsBytes]; byte rxBuffer[i2cStsBytes];
@@ -45,8 +39,5 @@ Status Executor::status() {
} }
} }
lastStsTime = millis();
lastSts = status;
return status; return status;
} }

View File

@@ -38,6 +38,7 @@ void QueueManager::loopRoutine() {
void QueueManager::putCommand(std::string cmd) { void QueueManager::putCommand(std::string cmd) {
if (!std::isalnum(cmd[0])) { if (!std::isalnum(cmd[0])) {
Serial.println("OK");
return; return;
} }

View File

@@ -9,7 +9,6 @@ Pen::Pen(int pin, int posEngaged, int posDisengaged)
void Pen::engage() { void Pen::engage() {
if (!engaged) { if (!engaged) {
servo.attach(pin); servo.attach(pin);
delay(5);
servo.write(posEngaged); servo.write(posEngaged);
delay(200); delay(200);
servo.detach(); servo.detach();
@@ -20,7 +19,6 @@ void Pen::engage() {
void Pen::disengage() { void Pen::disengage() {
if (engaged) { if (engaged) {
servo.attach(pin); servo.attach(pin);
delay(5);
servo.write(posDisengaged); servo.write(posDisengaged);
delay(200); delay(200);
servo.detach(); servo.detach();

View File

@@ -56,11 +56,26 @@ void receiveEvent(int howMany) {
byte txBuffer[i2cStsBytes]; byte txBuffer[i2cStsBytes];
Status sts; Status sts;
void requestEvent() { Wire.write(txBuffer, i2cStsBytes); } void requestEvent() {
if (executing || newCommand) {
sts.type = StatusType::WAIT;
} else {
sts.type = StatusType::NEXT;
}
sts.mmS = servoStepper.getPosMm();
sts.mmE = eggStepper.getPosMm();
sts.feedrate = curRPM;
sts.pEng = (float)pen.getEngaged();
sts.toBytes(txBuffer);
Wire.write(txBuffer, i2cStsBytes);
}
void execCommand(Command cmd) { void execCommand(Command cmd) {
executing = true; executing = true;
newCommand = false;
if (cmd.type == CommandType::G01 || cmd.type == CommandType::G00) { if (cmd.type == CommandType::G01 || cmd.type == CommandType::G00) {
if (cmd.type == CommandType::G01) { if (cmd.type == CommandType::G01) {
@@ -80,8 +95,7 @@ void execCommand(Command cmd) {
if (!isnan(cmd.arg3)) { if (!isnan(cmd.arg3)) {
if (cmd.arg3 < 0) { if (cmd.arg3 < 0) {
pen.engage(); pen.engage();
} } else {
if (cmd.arg3 >= 0) {
pen.disengage(); pen.disengage();
} }
} }
@@ -93,6 +107,7 @@ void execCommand(Command cmd) {
adjustRPM(); adjustRPM();
} }
newCommand = false;
return; return;
} }
@@ -138,22 +153,6 @@ void steppersRoutine() {
if (tick % servoStepperDelay == 0) { if (tick % servoStepperDelay == 0) {
servoStepper.doStep(); servoStepper.doStep();
} }
if (tick % stsUpdDelay == 0) {
if (executing || newCommand) {
sts.type = StatusType::WAIT;
} else {
sts.type = StatusType::NEXT;
}
sts.mmS = servoStepper.getPosMm();
sts.mmE = eggStepper.getPosMm();
sts.feedrate = curRPM;
sts.pEng = (float)pen.getEngaged();
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { sts.toBytes(txBuffer); }
}
armed = true; armed = true;
} }
if (eggStepper.getRemainingSteps() == 0 && if (eggStepper.getRemainingSteps() == 0 &&