Removed not needed config for pen. Use inkscape interface.

This commit is contained in:
Holger Weber
2026-02-13 01:12:39 +01:00
parent 42e9c4d97b
commit 53e51dc50b
5 changed files with 213 additions and 143 deletions

View File

@@ -1,84 +1,95 @@
#include "EggDuino.h"
void queryPen() {
void queryPen()
{
char state;
if (penState==penUpPos)
state='1';
if (penState == g_iPEN_UP_POS)
state = '1';
else
state='0';
Serial.print(String(state)+"\r\n");
state = '0';
Serial.print(String(state) + "\r\n");
sendAck();
}
void queryButton() {
Serial.print(String(prgButtonState) +"\r\n");
void queryButton()
{
Serial.print(String(prgButtonState) + "\r\n");
sendAck();
prgButtonState = 0;
}
void queryLayer() {
Serial.print(String(layer) +"\r\n");
void queryLayer()
{
Serial.print(String(layer) + "\r\n");
sendAck();
}
}
void setLayer() {
uint32_t value=0;
void setLayer()
{
uint32_t value = 0;
char *arg1;
arg1 = SCmd.next();
if (arg1 != NULL) {
if (arg1 != NULL)
{
value = atoi(arg1);
layer=value;
layer = value;
sendAck();
}
else
sendError();
}
void queryNodeCount() {
Serial.print(String(nodeCount) +"\r\n");
void queryNodeCount()
{
Serial.print(String(nodeCount) + "\r\n");
sendAck();
}
void setNodeCount() {
uint32_t value=0;
void setNodeCount()
{
uint32_t value = 0;
char *arg1;
arg1 = SCmd.next();
if (arg1 != NULL) {
if (arg1 != NULL)
{
value = atoi(arg1);
nodeCount=value;
nodeCount = value;
sendAck();
}
else
sendError();
}
void nodeCountIncrement() {
nodeCount=nodeCount++;
sendAck();
}
void nodeCountDecrement() {
nodeCount=nodeCount--;
void nodeCountIncrement()
{
nodeCount = nodeCount++;
sendAck();
}
void stepperMove() {
uint16_t duration=0; //in ms
int penStepsEBB=0; //Pen
int rotStepsEBB=0; //Rot
void nodeCountDecrement()
{
nodeCount = nodeCount--;
sendAck();
}
void stepperMove()
{
uint16_t duration = 0; // in ms
int penStepsEBB = 0; // Pen
int rotStepsEBB = 0; // Rot
moveToDestination();
if (!parseSMArgs(&duration, &penStepsEBB, &rotStepsEBB)) {
if (!parseSMArgs(&duration, &penStepsEBB, &rotStepsEBB))
{
sendError();
return;
}
sendAck();
if ( (penStepsEBB==0) && (rotStepsEBB==0) ) {
if ((penStepsEBB == 0) && (rotStepsEBB == 0))
{
delay(duration);
return;
}
@@ -86,48 +97,59 @@ void stepperMove() {
prepareMove(duration, penStepsEBB, rotStepsEBB);
}
void setPen(){
void setPen()
{
int cmd;
int value;
char *arg;
char cstrMsg[20];
moveToDestination();
arg = SCmd.next();
if (arg != NULL) {
if (arg != NULL)
{
cmd = atoi(arg);
switch (cmd) {
case 0:
penServo.write(penUpPos);
penState=penUpPos;
break;
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);
break;
case 1:
penServo.write(penDownPos);
penState=penDownPos;
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);
break;
default:
sendError();
default:
sendError();
}
}
char *val;
val = SCmd.next();
if (val != NULL) {
if (val != NULL)
{
value = atoi(val);
sendAck();
delay(value);
}
if (val==NULL && arg !=NULL) {
if (val == NULL && arg != NULL)
{
sendAck();
delay(500);
}
// Serial.println("delay");
if (val==NULL && arg ==NULL)
if (val == NULL && arg == NULL)
sendError();
}
}
void togglePen(){
void togglePen()
{
int value;
char *arg;
@@ -144,17 +166,22 @@ void togglePen(){
delay(value);
}
void doTogglePen() {
if (penState==penUpPos) {
penServo.write(penDownPos);
penState=penDownPos;
} else {
penServo.write(penUpPos);
penState=penUpPos;
void doTogglePen()
{
if (penState == g_iPEN_UP_POS)
{
penServo.write(g_iPEN_DOWN_POS);
penState = g_iPEN_DOWN_POS;
}
else
{
penServo.write(g_iPEN_UP_POS);
penState = g_iPEN_UP_POS;
}
}
void enableMotors(){
void enableMotors()
{
int cmd;
int value;
char *arg;
@@ -165,35 +192,44 @@ void enableMotors(){
val = SCmd.next();
if (val != NULL)
value = atoi(val);
//values parsed
if ((arg != NULL) && (val == NULL)){
switch (cmd) {
case 0: motorsOff();
sendAck();
break;
case 1: motorsOn();
sendAck();
break;
default:
sendError();
// values parsed
if ((arg != NULL) && (val == NULL))
{
switch (cmd)
{
case 0:
motorsOff();
sendAck();
break;
case 1:
motorsOn();
sendAck();
break;
default:
sendError();
}
}
//the following implementaion is a little bit cheated, because i did not know, how to implement different values for first and second argument.
if ((arg != NULL) && (val != NULL)){
switch (value) {
case 0: motorsOff();
sendAck();
break;
case 1: motorsOn();
sendAck();
break;
default:
sendError();
// the following implementaion is a little bit cheated, because i did not know, how to implement different values for first and second argument.
if ((arg != NULL) && (val != NULL))
{
switch (value)
{
case 0:
motorsOff();
sendAck();
break;
case 1:
motorsOn();
sendAck();
break;
default:
sendError();
}
}
}
void stepperModeConfigure(){
void stepperModeConfigure()
{
int cmd;
int value;
char *arg;
@@ -204,63 +240,75 @@ void stepperModeConfigure(){
val = SCmd.next();
if (val != NULL)
value = atoi(val);
if ((arg != NULL) && (val != NULL)){
switch (cmd) {
case 4: penDownPos= (int) ((float) (value-6000)/(float) 133.3); // transformation from EBB to PWM-Servo
storePenDownPosInEE();
sendAck();
break;
case 5: penUpPos= (int)((float) (value-6000)/(float) 133.3); // transformation from EBB to PWM-Servo
storePenUpPosInEE();
sendAck();
break;
case 6: //rotMin=value; ignored
sendAck();
break;
case 7: //rotMax=value; ignored
sendAck();
break;
case 11: servoRateUp=value;
sendAck();
break;
case 12: servoRateDown=value;
sendAck();
break;
default:
sendError();
if ((arg != NULL) && (val != NULL))
{
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 + ")");
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 + ")");
storePenUpPosInEE();
sendAck();
break;
case 6: // rotMin=value; ignored
sendAck();
break;
case 7: // rotMax=value; ignored
sendAck();
break;
case 11:
servoRateUp = value;
sendAck();
break;
case 12:
servoRateDown = value;
sendAck();
break;
default:
sendError();
}
}
}
void sendVersion(){
void sendVersion()
{
Serial.print(initSting);
Serial.print("\r\n");
}
void unrecognized(const char *command){
void unrecognized(const char *command)
{
sendError();
}
void ignore(){
void ignore()
{
sendAck();
}
void makeComInterface(){
SCmd.addCommand("v",sendVersion);
SCmd.addCommand("EM",enableMotors);
SCmd.addCommand("SC",stepperModeConfigure);
SCmd.addCommand("SP",setPen);
SCmd.addCommand("SM",stepperMove);
SCmd.addCommand("SE",ignore);
SCmd.addCommand("TP",togglePen);
SCmd.addCommand("PO",ignore); //Engraver command, not implemented, gives fake answer
SCmd.addCommand("NI",nodeCountIncrement);
SCmd.addCommand("ND",nodeCountDecrement);
SCmd.addCommand("SN",setNodeCount);
SCmd.addCommand("QN",queryNodeCount);
SCmd.addCommand("SL",setLayer);
SCmd.addCommand("QL",queryLayer);
SCmd.addCommand("QP",queryPen);
SCmd.addCommand("QB",queryButton); //"PRG" Button,
void makeComInterface()
{
SCmd.addCommand("v", sendVersion);
SCmd.addCommand("EM", enableMotors);
SCmd.addCommand("SC", stepperModeConfigure);
SCmd.addCommand("SP", setPen);
SCmd.addCommand("SM", stepperMove);
SCmd.addCommand("SE", ignore);
SCmd.addCommand("TP", togglePen);
SCmd.addCommand("PO", ignore); // Engraver command, not implemented, gives fake answer
SCmd.addCommand("NI", nodeCountIncrement);
SCmd.addCommand("ND", nodeCountDecrement);
SCmd.addCommand("SN", setNodeCount);
SCmd.addCommand("QN", queryNodeCount);
SCmd.addCommand("SL", setLayer);
SCmd.addCommand("QL", queryLayer);
SCmd.addCommand("QP", queryPen);
SCmd.addCommand("QB", queryButton); //"PRG" Button,
SCmd.setDefaultHandler(unrecognized); // Handler for command that isn't matched (says "What?")
}
}