Removed unused variables.

This commit is contained in:
2026-02-21 15:43:09 +01:00
parent c1bc52c5a3
commit 556c7888de
5 changed files with 87 additions and 123 deletions

View File

@@ -188,7 +188,7 @@ async function pollLogs() {
return;
}
Log(String("Config gespeichert: penUpPos=") + g_iPEN_UP_POS + ", penDownPos=" + g_iPEN_DOWN_POS);
Log(String("Config gespeichert: penUpPos=") + g_iPenUpPos + ", penDownPos=" + g_iPenDownPos);
server.send(200, "application/json", buildConfigJson());
}
@@ -273,7 +273,7 @@ bool loadConfigFromFile()
param->description = item["description"].as<String>();
}
}
Log(String("Config geladen: penUpPos=") + g_iPEN_UP_POS + ", penDownPos=" + g_iPEN_DOWN_POS);
Log(String("Config geladen: penUpPos=") + g_iPenUpPos + ", penDownPos=" + g_iPenDownPos);
return true;
}

View File

@@ -2,8 +2,9 @@
void queryPen()
{
Log(__FUNCTION__);
char state;
if (penState == g_iPEN_UP_POS)
if (g_iPenState == g_iPenUpPos)
state = '1';
else
state = '0';
@@ -13,26 +14,28 @@ void queryPen()
void queryButton()
{
Serial.print(String(prgButtonState) + "\r\n");
Serial.print(String(g_bPrgButtonState) + "\r\n");
sendAck();
prgButtonState = 0;
g_bPrgButtonState = 0;
}
void queryLayer()
{
Serial.print(String(layer) + "\r\n");
Log(__FUNCTION__);
Serial.print(String(g_uiLayer) + "\r\n");
sendAck();
}
void setLayer()
{
Log(__FUNCTION__);
uint32_t value = 0;
char *arg1;
arg1 = SCmd.next();
if (arg1 != NULL)
{
value = atoi(arg1);
layer = value;
g_uiLayer = value;
sendAck();
}
else
@@ -41,19 +44,20 @@ void setLayer()
void queryNodeCount()
{
Serial.print(String(nodeCount) + "\r\n");
Serial.print(String(g_uiNodeCount) + "\r\n");
sendAck();
}
void setNodeCount()
{
Log(__FUNCTION__);
uint32_t value = 0;
char *arg1;
arg1 = SCmd.next();
if (arg1 != NULL)
{
value = atoi(arg1);
nodeCount = value;
g_uiNodeCount = value;
sendAck();
}
else
@@ -62,18 +66,19 @@ void setNodeCount()
void nodeCountIncrement()
{
nodeCount = nodeCount++;
g_uiNodeCount = g_uiNodeCount++;
sendAck();
}
void nodeCountDecrement()
{
nodeCount = nodeCount--;
g_uiNodeCount = g_uiNodeCount--;
sendAck();
}
void stepperMove()
{
Log(__FUNCTION__);
uint16_t duration = 0; // in ms
int penStepsEBB = 0; // Pen
int rotStepsEBB = 0; // Rot
@@ -99,6 +104,7 @@ void stepperMove()
void setPen()
{
Log(__FUNCTION__);
int cmd;
int value;
char *arg;
@@ -113,17 +119,11 @@ void setPen()
switch (cmd)
{
case 0:
penServo.write(g_iPEN_UP_POS);
penState = g_iPEN_UP_POS;
sprintf(cstrMsg, "PEN down: %d", g_iPEN_UP_POS);
Log(cstrMsg);
penServo.write(g_iPenUpPos);
break;
case 1:
penServo.write(g_iPEN_DOWN_POS);
penState = g_iPEN_DOWN_POS;
sprintf(cstrMsg, "PEN up: %d", g_iPEN_DOWN_POS);
Log(cstrMsg);
penServo.write(g_iPenDownPos);
break;
default:
@@ -150,6 +150,7 @@ void setPen()
void togglePen()
{
Log(__FUNCTION__);
int value;
char *arg;
@@ -168,20 +169,22 @@ void togglePen()
void doTogglePen()
{
if (penState == g_iPEN_UP_POS)
Log(__FUNCTION__);
if (g_iPenState == g_iPenUpPos)
{
penServo.write(g_iPEN_DOWN_POS);
penState = g_iPEN_DOWN_POS;
penServo.write(g_iPenDownPos);
g_iPenState = g_iPenDownPos;
}
else
{
penServo.write(g_iPEN_UP_POS);
penState = g_iPEN_UP_POS;
penServo.write(g_iPenUpPos);
g_iPenState = g_iPenUpPos;
}
}
void enableMotors()
{
Log(__FUNCTION__);
int cmd;
int value;
char *arg;
@@ -230,6 +233,7 @@ void enableMotors()
void stepperModeConfigure()
{
Log(__FUNCTION__);
int cmd;
int value;
char *arg;
@@ -245,14 +249,12 @@ void stepperModeConfigure()
switch (cmd)
{
case 4:
g_iPEN_DOWN_POS = (int)((float)(value - 6000) / (float)133.3); // transformation from EBB to PWM-Servo
Log(String("SC set PEN_DOWN_POS -> ") + g_iPEN_DOWN_POS + " (raw " + value + ")");
g_iPenDownPos = (int)((float)(value - 6000) / (float)133.3); // transformation from EBB to PWM-Servo
storePenDownPosInEE();
sendAck();
break;
case 5:
g_iPEN_UP_POS = (int)((float)(value - 6000) / (float)133.3); // transformation from EBB to PWM-Servo
Log(String("SC set PEN_UP_POS -> ") + g_iPEN_UP_POS + " (raw " + value + ")");
g_iPenUpPos = (int)((float)(value - 6000) / (float)133.3); // transformation from EBB to PWM-Servo
storePenUpPosInEE();
sendAck();
break;
@@ -263,11 +265,11 @@ void stepperModeConfigure()
sendAck();
break;
case 11:
servoRateUp = value;
g_iServoRateUp = value;
sendAck();
break;
case 12:
servoRateDown = value;
g_iServoRateDown = value;
sendAck();
break;
default:
@@ -278,17 +280,20 @@ void stepperModeConfigure()
void sendVersion()
{
Log(__FUNCTION__);
Serial.print(initSting);
Serial.print("\r\n");
}
void unrecognized(const char *command)
{
Log(__FUNCTION__);
sendError();
}
void ignore()
{
Log(__FUNCTION__);
sendAck();
}

View File

@@ -4,10 +4,10 @@ void initHardware()
{
if (!initConfigStore())
{
g_iPEN_UP_POS = 5;
g_iPEN_DOWN_POS = 20;
g_iPenUpPos = 5;
g_iPenDownPos = 20;
}
penState = g_iPEN_UP_POS;
g_iPenState = g_iPenUpPos;
g_stepEngine.init();
g_pStepperRotate = g_stepEngine.stepperConnectToPin(step1);
@@ -36,7 +36,7 @@ void initHardware()
motorsOff();
penServo.attach(servoPin);
penServo.write(penState);
penServo.write(g_iPenState);
}
void storePenUpPosInEE()
@@ -51,35 +51,36 @@ void storePenDownPosInEE()
void sendAck()
{
Log(__FUNCTION__);
Serial.print("OK\r\n");
}
void sendError()
{
Log(__FUNCTION__);
Serial.print("unknown CMD\r\n");
}
void motorsOff()
{
// digitalWrite(enableRotMotor, HIGH);
// digitalWrite(enablePenMotor, HIGH);
Log(__FUNCTION__);
g_pStepperPen->disableOutputs();
g_pStepperRotate->disableOutputs();
motorsEnabled = 0;
g_bMotorsEnabled = 0;
}
void motorsOn()
{
// digitalWrite(enableRotMotor, LOW) ;
// digitalWrite(enablePenMotor, LOW) ;
Log(__FUNCTION__);
g_pStepperPen->enableOutputs();
g_pStepperRotate->enableOutputs();
motorsEnabled = 1;
g_bMotorsEnabled = 1;
}
void toggleMotors()
{
if (motorsEnabled)
Log(__FUNCTION__);
if (g_bMotorsEnabled)
{
motorsOff();
}
@@ -117,36 +118,18 @@ bool parseSMArgs(uint16_t *duration, int *penStepsEBB, int *rotStepsEBB)
void prepareMove(uint16_t duration, int penStepsEBB, int rotStepsEBB)
{
if (!motorsEnabled)
if (!g_bMotorsEnabled)
{
motorsOn();
}
if (duration == 0)
{
duration = 1;
}
if (penStepCorrection == 0)
{
penStepCorrection = 1;
}
if (rotStepCorrection == 0)
{
rotStepCorrection = 1;
}
if ((1 == rotStepCorrection) && (1 == penStepCorrection))
if ((1 == fROT_STEP_CORRECTION) && (1 == fPEN_STEP_CORRECTION))
{ // if coordinatessystems are identical
// set Coordinates and Speed
// rotMotor.move(rotStepsEBB);
// rotMotor.setSpeed(abs((float)rotStepsEBB * (float)1000 / (float)duration));
g_pStepperRotate->move(rotStepsEBB);
g_pStepperRotate->setSpeedInTicks(abs((float)rotStepsEBB * (float)1000 / (float)duration));
// penMotor.move(penStepsEBB);
// penMotor.setSpeed(abs((float)penStepsEBB * (float)1000 / (float)duration));
g_pStepperPen->move(penStepsEBB);
g_pStepperPen->setSpeedInTicks(abs((float)penStepsEBB * (float)1000 / (float)duration));
}
@@ -154,14 +137,14 @@ void prepareMove(uint16_t duration, int penStepsEBB, int rotStepsEBB)
{
// incoming EBB-Steps will be multiplied by 16, then Integer-maths is done, result will be divided by 16
// This make thinks here really complicated, but floating point-math kills performance and memory, believe me... I tried...
long rotSteps = ((long)rotStepsEBB * 16 / rotStepCorrection) + (long)rotStepError; // correct incoming EBB-Steps to our microstep-Setting and multiply by 16 to avoid floatingpoint...
long penSteps = ((long)penStepsEBB * 16 / penStepCorrection) + (long)penStepError;
long rotSteps = ((long)rotStepsEBB * 16 / fROT_STEP_CORRECTION) + (long)g_iRotStepError; // correct incoming EBB-Steps to our microstep-Setting and multiply by 16 to avoid floatingpoint...
long penSteps = ((long)penStepsEBB * 16 / fPEN_STEP_CORRECTION) + (long)g_iPenStepError;
int rotStepsToGo = (int)(rotSteps / 16); // Calc Steps to go, which are possible on our machine
int penStepsToGo = (int)(penSteps / 16);
rotStepError = (long)rotSteps - ((long)rotStepsToGo * (long)16); // calc Position-Error, if there is one
penStepError = (long)penSteps - ((long)penStepsToGo * (long)16);
g_iRotStepError = (long)rotSteps - ((long)rotStepsToGo * (long)16); // calc Position-Error, if there is one
g_iPenStepError = (long)penSteps - ((long)penStepsToGo * (long)16);
long temp_rotSpeed = ((long)rotStepsToGo * (long)1000 / (long)duration); // calc Speed in Integer Math
long temp_penSpeed = ((long)penStepsToGo * (long)1000 / (long)duration);
@@ -170,13 +153,9 @@ void prepareMove(uint16_t duration, int penStepsEBB, int rotStepsEBB)
float penSpeed = (float)abs(temp_penSpeed);
// set Coordinates and Speed
// rotMotor.move(rotStepsToGo); // finally, let us set the target position...
// rotMotor.setSpeed(rotSpeed); // and the Speed!
g_pStepperRotate->move(rotStepsToGo);
g_pStepperRotate->setSpeedInTicks(rotSpeed);
// penMotor.move(penStepsToGo);
// penMotor.setSpeed(penSpeed);
g_pStepperPen->move(penStepsToGo);
g_pStepperPen->setSpeedInTicks(penSpeed);
}
@@ -184,27 +163,15 @@ void prepareMove(uint16_t duration, int penStepsEBB, int rotStepsEBB)
void moveOneStep()
{
while (g_pStepperPen->isRunning() || g_pStepperRotate->isRunning())
;
// if (penMotor.distanceToGo() || rotMotor.distanceToGo())
// {
// penMotor.runSpeedToPosition(); // Moving.... moving... moving....
// rotMotor.runSpeedToPosition();
// }
while (g_pStepperPen->isRunning() || g_pStepperRotate->isRunning());
}
void moveToDestination()
{
while (g_pStepperPen->isRunning() || g_pStepperRotate->isRunning())
;
// while (penMotor.distanceToGo() || rotMotor.distanceToGo())
// {
// penMotor.runSpeedToPosition(); // Moving.... moving... moving....
// rotMotor.runSpeedToPosition();
// }
while (g_pStepperPen->isRunning() || g_pStepperRotate->isRunning());
}
void setprgButtonState()
{
prgButtonState = 1;
g_bPrgButtonState = 1;
}

View File

@@ -34,8 +34,6 @@ FastAccelStepper *g_pStepperRotate = NULL;
FastAccelStepper *g_pStepperPen = NULL;
// make Objects
// FastAccelStepper rotMotor(FastAccelStepper::DRIVER, step1, dir1);
// FastAccelStepper penMotor(FastAccelStepper::DRIVER, step2, dir2);
Servo penServo;
SerialCommand SCmd;
@@ -49,29 +47,28 @@ Button penToggle(penToggleButton, doTogglePen);
#ifdef motorsButton
Button motorsToggle(motorsButton, toggleMotors);
#endif
// Variables... be careful, by messing around here, everything has a reason and crossrelations...
int penMin = 0;
int penMax = 0;
int g_iPEN_UP_POS = 5; // can be overwritten from EBB-Command SC
int g_iPEN_DOWN_POS = 20; // can be overwritten from EBB-Command SC
int servoRateUp = 0; // from EBB-Protocol not implemented on machine-side
int servoRateDown = 0; // from EBB-Protocol not implemented on machine-side
long rotStepError = 0;
long penStepError = 0;
int penState = g_iPEN_UP_POS;
uint32_t nodeCount = 0;
unsigned int layer = 0;
boolean prgButtonState = 0;
uint8_t rotStepCorrection = 16 / rotMicrostep; // devide EBB-Coordinates by this factor to get EGGduino-Steps
uint8_t penStepCorrection = 16 / penMicrostep; // devide EBB-Coordinates by this factor to get EGGduino-Steps
float rotSpeed = 0;
float penSpeed = 0; // these are local variables for Function SteppermotorMove-Command, but for performance-reasons it will be initialized here
boolean motorsEnabled = 0;
int g_iPenUpPos = 5; // can be overwritten from EBB-Command SC
int g_iPenDownPos = 20; // can be overwritten from EBB-Command SC
int g_iServoRateUp = 0; // from EBB-Protocol not implemented on machine-side
int g_iServoRateDown = 0; // from EBB-Protocol not implemented on machine-side
long g_iRotStepError = 0;
long g_iPenStepError = 0;
int g_iPenState = g_iPenUpPos;
uint32_t g_uiNodeCount = 0;
unsigned int g_uiLayer = 0;
boolean g_bPrgButtonState = 0;
float fROT_STEP_CORRECTION = 16.0 / rotMicrostep; // devide EBB-Coordinates by this factor to get EGGduino-Steps
float fPEN_STEP_CORRECTION = 16.0 / penMicrostep; // devide EBB-Coordinates by this factor to get EGGduino-Steps
boolean g_bMotorsEnabled = 0;
// Stepper Test
#ifdef TEST
// #define dirPinStepper 16
// #define enablePinStepper 12
// #define stepPinStepper 26
#endif
void setup()
{
@@ -135,10 +132,11 @@ void loop()
}
Log("Alive");
}
#endif
#else
// moveOneStep();
SCmd.readSerial();
handleWebInterface();
#endif
#ifdef penToggleButton
penToggle.check();