diff --git a/.gitignore b/.gitignore index b9d6bd9..241ff6e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,8 @@ local.properties .classpath .settings/ .loadpath +.vscode +.pio # External tool builders .externalToolBuilders/ diff --git a/include/EggDuino.h b/include/EggDuino.h new file mode 100644 index 0000000..f273198 --- /dev/null +++ b/include/EggDuino.h @@ -0,0 +1,71 @@ +#ifndef EGGDUINO_H +#define EGGDUINO_H + +#include +#include +#include + +#include "AccelStepper.h" +#include "SerialCommand.h" +#include "button.h" + +// implemented Eggbot-Protocol-Version v13 +#define initSting "EBBv13_and_above Protocol emulated by Eggduino-Firmware V1.6a" + +// Rotational Stepper +#define step1 11 +#define dir1 10 +#define enableRotMotor 9 +#define rotMicrostep 16 + +// Pen Stepper +#define step2 8 +#define dir2 7 +#define enablePenMotor 6 +#define penMicrostep 16 + +#define servoPin 3 + +#define penUpPosEEAddress ((uint16_t *)0) +#define penDownPosEEAddress ((uint16_t *)2) + +extern AccelStepper rotMotor; +extern AccelStepper penMotor; +extern Servo penServo; +extern SerialCommand SCmd; + +extern int penMin; +extern int penMax; +extern int penUpPos; +extern int penDownPos; +extern int servoRateUp; +extern int servoRateDown; +extern long rotStepError; +extern long penStepError; +extern int penState; +extern uint32_t nodeCount; +extern unsigned int layer; +extern boolean prgButtonState; +extern uint8_t rotStepCorrection; +extern uint8_t penStepCorrection; +extern float rotSpeed; +extern float penSpeed; +extern boolean motorsEnabled; + +void makeComInterface(); +void initHardware(); +void moveOneStep(); +void moveToDestination(); +void sendAck(); +void sendError(); +void motorsOff(); +void motorsOn(); +void toggleMotors(); +void doTogglePen(); +void setprgButtonState(); +bool parseSMArgs(uint16_t *duration, int *penStepsEBB, int *rotStepsEBB); +void prepareMove(uint16_t duration, int penStepsEBB, int rotStepsEBB); +void storePenUpPosInEE(); +void storePenDownPosInEE(); + +#endif diff --git a/button.h b/include/button.h similarity index 100% rename from button.h rename to include/button.h diff --git a/AccelStepper.cpp b/lib/AccelStepper/src/AccelStepper.cpp similarity index 100% rename from AccelStepper.cpp rename to lib/AccelStepper/src/AccelStepper.cpp diff --git a/AccelStepper.h b/lib/AccelStepper/src/AccelStepper.h similarity index 100% rename from AccelStepper.h rename to lib/AccelStepper/src/AccelStepper.h diff --git a/SerialCommand.cpp b/lib/SerialCommand/src/SerialCommand.cpp similarity index 100% rename from SerialCommand.cpp rename to lib/SerialCommand/src/SerialCommand.cpp diff --git a/SerialCommand.h b/lib/SerialCommand/src/SerialCommand.h similarity index 100% rename from SerialCommand.h rename to lib/SerialCommand/src/SerialCommand.h diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..69efc37 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,18 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:uno] +platform = atmelavr +board = uno +framework = arduino +monitor_speed = 9600 +upload_speed = 115200 +upload_port= COM3 +lib_deps = arduino-libraries/Servo@^1.3.0 diff --git a/Functions.ino b/src/Functions.cpp similarity index 99% rename from Functions.ino rename to src/Functions.cpp index 6ca5960..540a5ee 100644 --- a/Functions.ino +++ b/src/Functions.cpp @@ -1,23 +1,5 @@ +#include "EggDuino.h" -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?") -} void queryPen() { char state; @@ -262,3 +244,23 @@ void unrecognized(const char *command){ 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, + SCmd.setDefaultHandler(unrecognized); // Handler for command that isn't matched (says "What?") +} \ No newline at end of file diff --git a/Helper_Functions.ino b/src/Helper_Functions.cpp similarity index 96% rename from Helper_Functions.ino rename to src/Helper_Functions.cpp index b3b5cb0..6d1d7eb 100644 --- a/Helper_Functions.ino +++ b/src/Helper_Functions.cpp @@ -1,3 +1,11 @@ +#include "EggDuino.h" + +inline void loadPenPosFromEE() { + penUpPos = eeprom_read_word(penUpPosEEAddress); + penDownPos = eeprom_read_word(penDownPosEEAddress); + penState = penUpPos; +} + void initHardware(){ // enable eeprom wait in avr/eeprom.h functions SPMCSR &= ~SELFPRGEN; @@ -16,25 +24,21 @@ void initHardware(){ penServo.write(penState); } -inline void loadPenPosFromEE() { - penUpPos = eeprom_read_word(penUpPosEEAddress); - penDownPos = eeprom_read_word(penDownPosEEAddress); - penState = penUpPos; -} -inline void storePenUpPosInEE() { + +void storePenUpPosInEE() { eeprom_update_word(penUpPosEEAddress, penUpPos); } -inline void storePenDownPosInEE() { +void storePenDownPosInEE() { eeprom_update_word(penDownPosEEAddress, penDownPos); } -inline void sendAck(){ +void sendAck(){ Serial.print("OK\r\n"); } -inline void sendError(){ +void sendError(){ Serial.print("unknown CMD\r\n"); } diff --git a/EggDuino.ino b/src/main.cpp similarity index 78% rename from EggDuino.ino rename to src/main.cpp index 9e7b642..a77e19c 100644 --- a/EggDuino.ino +++ b/src/main.cpp @@ -19,25 +19,7 @@ 2 implement homing sequence via microswitch or optical device */ -#include "AccelStepper.h" // nice lib from http://www.airspayce.com/mikem/arduino/AccelStepper/ -#include -#include "SerialCommand.h" //nice lib from Stefan Rado, https://github.com/kroimon/Arduino-SerialCommand -#include -#include "button.h" - -#define initSting "EBBv13_and_above Protocol emulated by Eggduino-Firmware V1.6a" -//Rotational Stepper: -#define step1 11 -#define dir1 10 -#define enableRotMotor 9 -#define rotMicrostep 16 //MicrostepMode, only 1,2,4,8,16 allowed, because of Integer-Math in this Sketch -//Pen Stepper: -#define step2 8 -#define dir2 7 -#define enablePenMotor 6 -#define penMicrostep 16 //MicrostepMode, only 1,2,4,8,16 allowed, because of Integer-Math in this Sketch - -#define servoPin 3 //Servo +#include "EggDuino.h" // EXTRAFEATURES - UNCOMMENT TO USE THEM ------------------------------------------------------------------- @@ -47,9 +29,6 @@ //----------------------------------------------------------------------------------------------------------- -#define penUpPosEEAddress ((uint16_t *)0) -#define penDownPosEEAddress ((uint16_t *)2) - //make Objects AccelStepper rotMotor(1, step1, dir1); AccelStepper penMotor(1, step2, dir2);