Code cleanup.
- firmware now supports SM buffering, so SMQB command is no longer needed - commmented code and repeated fragments removed
This commit is contained in:
@@ -45,7 +45,6 @@ Thanks to my wife and my daughter for their patience. :-)
|
|||||||
// #define penToggleButton 12 // pen up/down button
|
// #define penToggleButton 12 // pen up/down button
|
||||||
// #define motorsButton 4 // motors enable button
|
// #define motorsButton 4 // motors enable button
|
||||||
|
|
||||||
// #define CommandSMQB
|
|
||||||
//-----------------------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
#define penUpPosEEAddress ((uint16_t *)0)
|
#define penUpPosEEAddress ((uint16_t *)0)
|
||||||
@@ -92,10 +91,7 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
|
moveOneStep();
|
||||||
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
|
|
||||||
rotMotor.runSpeedToPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
SCmd.readSerial();
|
SCmd.readSerial();
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,6 @@ void makeComInterface(){
|
|||||||
SCmd.addCommand("SC",stepperModeConfigure);
|
SCmd.addCommand("SC",stepperModeConfigure);
|
||||||
SCmd.addCommand("SP",setPen);
|
SCmd.addCommand("SP",setPen);
|
||||||
SCmd.addCommand("SM",stepperMove);
|
SCmd.addCommand("SM",stepperMove);
|
||||||
#ifdef CommandSMQB
|
|
||||||
SCmd.addCommand("SMQB",stepperMoveQueryButton); // composite function enabling smooth movement
|
|
||||||
#endif
|
|
||||||
SCmd.addCommand("SE",ignore);
|
SCmd.addCommand("SE",ignore);
|
||||||
SCmd.addCommand("TP",togglePen);
|
SCmd.addCommand("TP",togglePen);
|
||||||
SCmd.addCommand("PO",ignore); //Engraver command, not implemented, gives fake answer
|
SCmd.addCommand("PO",ignore); //Engraver command, not implemented, gives fake answer
|
||||||
@@ -20,7 +17,7 @@ void makeComInterface(){
|
|||||||
SCmd.addCommand("QP",queryPen);
|
SCmd.addCommand("QP",queryPen);
|
||||||
SCmd.addCommand("QB",queryButton); //"PRG" Button,
|
SCmd.addCommand("QB",queryButton); //"PRG" Button,
|
||||||
SCmd.setDefaultHandler(unrecognized); // Handler for command that isn't matched (says "What?")
|
SCmd.setDefaultHandler(unrecognized); // Handler for command that isn't matched (says "What?")
|
||||||
}
|
}
|
||||||
|
|
||||||
void queryPen() {
|
void queryPen() {
|
||||||
char state;
|
char state;
|
||||||
@@ -89,10 +86,8 @@ void stepperMove() {
|
|||||||
uint16_t duration=0; //in ms
|
uint16_t duration=0; //in ms
|
||||||
int penStepsEBB=0; //Pen
|
int penStepsEBB=0; //Pen
|
||||||
int rotStepsEBB=0; //Rot
|
int rotStepsEBB=0; //Rot
|
||||||
while ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
|
|
||||||
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
|
moveToDestination();
|
||||||
rotMotor.runSpeedToPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!parseSMArgs(&duration, &penStepsEBB, &rotStepsEBB)) {
|
if (!parseSMArgs(&duration, &penStepsEBB, &rotStepsEBB)) {
|
||||||
sendError();
|
sendError();
|
||||||
@@ -103,46 +98,19 @@ void stepperMove() {
|
|||||||
|
|
||||||
if ( (penStepsEBB==0) && (rotStepsEBB==0) ) {
|
if ( (penStepsEBB==0) && (rotStepsEBB==0) ) {
|
||||||
delay(duration);
|
delay(duration);
|
||||||
//sendAck();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
doMove(duration, penStepsEBB, rotStepsEBB);
|
prepareMove(duration, penStepsEBB, rotStepsEBB);
|
||||||
//sendAck();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CommandSMQB
|
|
||||||
void stepperMoveQueryButton() {
|
|
||||||
uint16_t duration=0; //in ms
|
|
||||||
int penStepsEBB=0; //Pen
|
|
||||||
int rotStepsEBB=0; //Rot
|
|
||||||
|
|
||||||
if (!parseSMArgs(&duration, &penStepsEBB, &rotStepsEBB)) {
|
|
||||||
sendError();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( (penStepsEBB==0) && (rotStepsEBB==0) ) {
|
|
||||||
delay(duration);
|
|
||||||
queryButton();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// sending ACK before actual move to allow buffering
|
|
||||||
queryButton();
|
|
||||||
doMove(duration, penStepsEBB, rotStepsEBB);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
void setPen(){
|
void setPen(){
|
||||||
int cmd;
|
int cmd;
|
||||||
int value;
|
int value;
|
||||||
char *arg;
|
char *arg;
|
||||||
while ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
|
|
||||||
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
|
moveToDestination();
|
||||||
rotMotor.runSpeedToPosition();
|
|
||||||
}
|
|
||||||
arg = SCmd.next();
|
arg = SCmd.next();
|
||||||
if (arg != NULL) {
|
if (arg != NULL) {
|
||||||
cmd = atoi(arg);
|
cmd = atoi(arg);
|
||||||
@@ -180,10 +148,9 @@ void setPen(){
|
|||||||
void togglePen(){
|
void togglePen(){
|
||||||
int value;
|
int value;
|
||||||
char *arg;
|
char *arg;
|
||||||
while ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
|
|
||||||
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
|
moveToDestination();
|
||||||
rotMotor.runSpeedToPosition();
|
|
||||||
}
|
|
||||||
arg = SCmd.next();
|
arg = SCmd.next();
|
||||||
if (arg != NULL)
|
if (arg != NULL)
|
||||||
value = atoi(arg);
|
value = atoi(arg);
|
||||||
@@ -286,12 +253,12 @@ void stepperModeConfigure(){
|
|||||||
void sendVersion(){
|
void sendVersion(){
|
||||||
Serial.print(initSting);
|
Serial.print(initSting);
|
||||||
Serial.print("\r\n");
|
Serial.print("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void unrecognized(const char *command){
|
void unrecognized(const char *command){
|
||||||
sendError();
|
sendError();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ignore(){
|
void ignore(){
|
||||||
sendAck();
|
sendAck();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,18 +7,6 @@ void initHardware(){
|
|||||||
pinMode(enableRotMotor, OUTPUT);
|
pinMode(enableRotMotor, OUTPUT);
|
||||||
pinMode(enablePenMotor, OUTPUT);
|
pinMode(enablePenMotor, OUTPUT);
|
||||||
|
|
||||||
#ifdef prgButton
|
|
||||||
pinMode(prgButton, INPUT_PULLUP);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef penToggleButton
|
|
||||||
pinMode(penToggleButton, INPUT_PULLUP);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef motorsButton
|
|
||||||
pinMode(motorsButton, INPUT_PULLUP);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rotMotor.setMaxSpeed(2000.0);
|
rotMotor.setMaxSpeed(2000.0);
|
||||||
rotMotor.setAcceleration(10000.0);
|
rotMotor.setAcceleration(10000.0);
|
||||||
penMotor.setMaxSpeed(2000.0);
|
penMotor.setMaxSpeed(2000.0);
|
||||||
@@ -26,7 +14,7 @@ void initHardware(){
|
|||||||
motorsOff();
|
motorsOff();
|
||||||
penServo.attach(servoPin);
|
penServo.attach(servoPin);
|
||||||
penServo.write(penState);
|
penServo.write(penState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void inline loadPenPosFromEE() {
|
void inline loadPenPosFromEE() {
|
||||||
penUpPos = eeprom_read_word(penUpPosEEAddress);
|
penUpPos = eeprom_read_word(penUpPosEEAddress);
|
||||||
@@ -92,7 +80,7 @@ bool parseSMArgs(uint16_t *duration, int *penStepsEBB, int *rotStepsEBB) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void doMove(uint16_t duration, int penStepsEBB, int rotStepsEBB) {
|
void prepareMove(uint16_t duration, int penStepsEBB, int rotStepsEBB) {
|
||||||
if (!motorsEnabled) {
|
if (!motorsEnabled) {
|
||||||
motorsOn();
|
motorsOn();
|
||||||
}
|
}
|
||||||
@@ -126,12 +114,20 @@ void doMove(uint16_t duration, int penStepsEBB, int rotStepsEBB) {
|
|||||||
penMotor.move(penStepsToGo);
|
penMotor.move(penStepsToGo);
|
||||||
penMotor.setSpeed( penSpeed );
|
penMotor.setSpeed( penSpeed );
|
||||||
}
|
}
|
||||||
/*
|
}
|
||||||
|
|
||||||
|
void moveOneStep() {
|
||||||
|
if ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
|
||||||
|
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
|
||||||
|
rotMotor.runSpeedToPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void moveToDestination() {
|
||||||
while ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
|
while ( penMotor.distanceToGo() || rotMotor.distanceToGo() ) {
|
||||||
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
|
penMotor.runSpeedToPosition(); // Moving.... moving... moving....
|
||||||
rotMotor.runSpeedToPosition();
|
rotMotor.runSpeedToPosition();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setprgButtonState(){
|
void setprgButtonState(){
|
||||||
|
|||||||
10
button.h
10
button.h
@@ -29,7 +29,10 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Button(byte p, ActionCb a): debounce(0), state(1), lastState(1), action(a), pin(p) {} ;
|
Button(byte p, ActionCb a): debounce(0), state(1), lastState(1), action(a), pin(p) {
|
||||||
|
pinMode(pin, INPUT_PULLUP);
|
||||||
|
}
|
||||||
|
|
||||||
void check() {
|
void check() {
|
||||||
byte b = digitalRead(pin);
|
byte b = digitalRead(pin);
|
||||||
long t = millis();
|
long t = millis();
|
||||||
@@ -49,10 +52,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
lastState = b;
|
lastState = b;
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}; //button
|
}; //button
|
||||||
|
|
||||||
#endif //__BUTTON_H__
|
#endif //__BUTTON_H__
|
||||||
|
|||||||
Reference in New Issue
Block a user