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

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

View File

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

View File

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

View File

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

View File

@@ -56,11 +56,26 @@ void receiveEvent(int howMany) {
byte txBuffer[i2cStsBytes];
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) {
executing = true;
newCommand = false;
if (cmd.type == CommandType::G01 || cmd.type == CommandType::G00) {
if (cmd.type == CommandType::G01) {
@@ -80,8 +95,7 @@ void execCommand(Command cmd) {
if (!isnan(cmd.arg3)) {
if (cmd.arg3 < 0) {
pen.engage();
}
if (cmd.arg3 >= 0) {
} else {
pen.disengage();
}
}
@@ -93,6 +107,7 @@ void execCommand(Command cmd) {
adjustRPM();
}
newCommand = false;
return;
}
@@ -138,22 +153,6 @@ void steppersRoutine() {
if (tick % servoStepperDelay == 0) {
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;
}
if (eggStepper.getRemainingSteps() == 0 &&