no message

This commit is contained in:
Mario Voigt 2019-08-07 14:27:54 +02:00
parent 7474a6e633
commit e159e15327
72 changed files with 97625 additions and 1 deletions

View File

@ -1,2 +1,5 @@
# The-Legend-of-Delta
# Firmware
Repetier firmware for all RAMBo controlled SeeMeCNC 3D Printers. One firmware, configuarable for all RAMBo deltas.
This firmware is based off of Repetier Firmware, through many years and versions, as well as some integration with features of marlin and others work.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,53 @@
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Repetier-Firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
This firmware is a nearly complete rewrite of the sprinter firmware
by kliment (https://github.com/kliment/Sprinter)
which based on Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
Functions in this file are used to communicate using ascii or repetier protocol.
*/
#ifndef COMMANDS_H_INCLUDED
#define COMMANDS_H_INCLUDED
class Commands
{
public:
static void commandLoop();
static void checkForPeriodicalActions(bool allowNewMoves);
static void processArc(GCode *com);
static void processGCode(GCode *com);
static void processMCode(GCode *com);
static void executeGCode(GCode *com);
static void waitUntilEndOfAllMoves();
static void waitUntilEndOfAllBuffers();
static void printCurrentPosition(FSTRINGPARAM(s));
static void printTemperatures(bool showRaw = false);
static void setFanSpeed(int speed,bool wait); /// Set fan speed 0..255
static void changeFeedrateMultiply(int factorInPercent);
static void changeFlowrateMultiply(int factorInPercent);
static void changeHorizontalRadius(float hradius);
static void reportPrinterUsage();
static void emergencyStop();
static void checkFreeMemory();
static void writeLowestFreeRAM();
private:
static int lowestRAMValue;
static int lowestRAMValueSend;
};
#endif // COMMANDS_H_INCLUDED

View File

@ -0,0 +1,583 @@
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Repetier-Firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
This firmware is a nearly complete rewrite of the sprinter firmware
by kliment (https://github.com/kliment/Sprinter)
which based on Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
*/
#include "Repetier.h"
#if DRIVE_SYSTEM == DELTA
FSTRINGVALUE(Com::tFirmware,"FIRMWARE_NAME:Repetier_"REPETIER_VERSION" FIRMWARE_DATE:"FIRMWARE_DATE" MACHINE_TYPE:"UI_TEXT_PRINTER_READY" ")
#else
#if DRIVE_SYSTEM == CARTESIAN
FSTRINGVALUE(Com::tFirmware,"FIRMWARE_NAME:Repetier_" REPETIER_VERSION " FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:" XSTR(NUM_EXTRUDER) " REPETIER_PROTOCOL:3")
#else
FSTRINGVALUE(Com::tFirmware,"FIRMWARE_NAME:Repetier_" REPETIER_VERSION " FIRMWARE_URL:https://github.com/repetier/Repetier-Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Core_XY EXTRUDER_COUNT:" XSTR(NUM_EXTRUDER) " REPETIER_PROTOCOL:3")
#endif
#endif
FSTRINGVALUE(Com::tDebug,"Debug:")
FSTRINGVALUE(Com::tOk,"ok")
FSTRINGVALUE(Com::tNewline,"\r\n")
FSTRINGVALUE(Com::tNAN,"NAN")
FSTRINGVALUE(Com::tINF,"INF")
FSTRINGVALUE(Com::tError,"Error:")
FSTRINGVALUE(Com::tInfo,"Info:")
FSTRINGVALUE(Com::tWarning,"Warning:")
FSTRINGVALUE(Com::tResend,"Resend:")
FSTRINGVALUE(Com::tEcho,"Echo:")
FSTRINGVALUE(Com::tOkSpace,"ok ")
FSTRINGVALUE(Com::tWrongChecksum,"Wrong checksum")
FSTRINGVALUE(Com::tMissingChecksum,"Missing checksum")
FSTRINGVALUE(Com::tFormatError,"Format error")
FSTRINGVALUE(Com::tDonePrinting,"Done printing file")
FSTRINGVALUE(Com::tX," X")
FSTRINGVALUE(Com::tY," Y")
FSTRINGVALUE(Com::tZ," Z")
FSTRINGVALUE(Com::tE," E")
FSTRINGVALUE(Com::tF," F")
FSTRINGVALUE(Com::tS," S")
FSTRINGVALUE(Com::tP," P")
FSTRINGVALUE(Com::tI," I")
FSTRINGVALUE(Com::tJ," J")
FSTRINGVALUE(Com::tR," R")
FSTRINGVALUE(Com::tSDReadError,"SD read error")
FSTRINGVALUE(Com::tExpectedLine,"Error:expected line ")
FSTRINGVALUE(Com::tGot," got ")
FSTRINGVALUE(Com::tSkip,"skip ")
FSTRINGVALUE(Com::tBLK,"BLK ")
FSTRINGVALUE(Com::tStart,"start")
FSTRINGVALUE(Com::tPowerUp,"PowerUp")
FSTRINGVALUE(Com::tExternalReset,"External Reset")
FSTRINGVALUE(Com::tBrownOut,"Brown out Reset")
FSTRINGVALUE(Com::tWatchdog,"Watchdog Reset")
FSTRINGVALUE(Com::tSoftwareReset,"Software Reset")
FSTRINGVALUE(Com::tUnknownCommand,"Unknown command:")
FSTRINGVALUE(Com::tFreeRAM,"Free RAM:")
FSTRINGVALUE(Com::tXColon,"X:")
FSTRINGVALUE(Com::tSpaceXColon," X:")
FSTRINGVALUE(Com::tSpaceYColon," Y:")
FSTRINGVALUE(Com::tSpaceZColon," Z:")
FSTRINGVALUE(Com::tSpaceEColon," E:")
FSTRINGVALUE(Com::tTColon,"T:")
FSTRINGVALUE(Com::tSpaceBColon," B:")
FSTRINGVALUE(Com::tSpaceAtColon," @:")
FSTRINGVALUE(Com::tSpaceT," T")
FSTRINGVALUE(Com::tSpaceAt," @")
FSTRINGVALUE(Com::tSpaceBAtColon," B@:")
FSTRINGVALUE(Com::tSpaceRaw," RAW")
FSTRINGVALUE(Com::tColon,":")
FSTRINGVALUE(Com::tSlash,"/")
FSTRINGVALUE(Com::tSpaceSlash," /")
FSTRINGVALUE(Com::tSpeedMultiply,"SpeedMultiply:")
FSTRINGVALUE(Com::tFlowMultiply,"FlowMultiply:")
FSTRINGVALUE(Com::tHorizontalRadius,"H. Radius:")
FSTRINGVALUE(Com::tFanspeed,"Fanspeed:")
FSTRINGVALUE(Com::tPrintedFilament,"Printed filament:")
FSTRINGVALUE(Com::tPrintingTime,"Printing time:")
FSTRINGVALUE(Com::tSpacem,"m ")
FSTRINGVALUE(Com::tSpaceDaysSpace," days ")
FSTRINGVALUE(Com::tSpaceHoursSpace," hours ")
FSTRINGVALUE(Com::tSpaceMin," min")
FSTRINGVALUE(Com::tInvalidArc,"Invalid arc")
FSTRINGVALUE(Com::tComma,",")
FSTRINGVALUE(Com::tSpace," ")
FSTRINGVALUE(Com::tYColon,"Y:")
FSTRINGVALUE(Com::tZColon,"Z:")
FSTRINGVALUE(Com::tE0Colon,"E0:")
FSTRINGVALUE(Com::tE1Colon,"E1:")
FSTRINGVALUE(Com::tMS1MS2Pins,"MS1,MS2 Pins")
FSTRINGVALUE(Com::tSetOutputSpace,"Set output: ")
FSTRINGVALUE(Com::tGetInputSpace,"Get Input: ")
FSTRINGVALUE(Com::tSpaceToSpace," to ")
FSTRINGVALUE(Com::tSpaceIsSpace," is ")
FSTRINGVALUE(Com::tHSpace,"H ")
FSTRINGVALUE(Com::tLSpace,"L ")
FSTRINGVALUE(Com::tXMinColon,"x_min:")
FSTRINGVALUE(Com::tXMaxColon,"x_max:")
FSTRINGVALUE(Com::tYMinColon,"y_min:")
FSTRINGVALUE(Com::tYMaxColon,"y_max:")
FSTRINGVALUE(Com::tZMinColon,"z_min:")
FSTRINGVALUE(Com::tZMaxColon,"z_max:")
FSTRINGVALUE(Com::tJerkColon,"Jerk:")
FSTRINGVALUE(Com::tZJerkColon," ZJerk:")
FSTRINGVALUE(Com::tLinearStepsColon," linear steps:")
FSTRINGVALUE(Com::tQuadraticStepsColon," quadratic steps:")
FSTRINGVALUE(Com::tCommaSpeedEqual,", speed=")
FSTRINGVALUE(Com::tEEPROMUpdated,"EEPROM updated")
FSTRINGVALUE(Com::tLinearLColon,"linear L:")
FSTRINGVALUE(Com::tQuadraticKColon," quadratic K:")
#if DRIVE_SYSTEM==DELTA
FSTRINGVALUE(Com::tMeasurementReset,"Measurement reset.")
FSTRINGVALUE(Com::tMeasureDeltaSteps,"Measure/delta (Steps) =")
FSTRINGVALUE(Com::tMeasureDelta,"Measure/delta =")
FSTRINGVALUE(Com::tMeasureOriginReset,"Measured origin set. Measurement reset.")
FSTRINGVALUE(Com::tMeasurementAbortedOrigin,"Origin measurement cannot be set. Use only Z-Cartesian (straight up and down) movements and try again.")
FSTRINGVALUE(Com::tInvalidDeltaCoordinate,"Invalid delta coordinate - move ignored")
FSTRINGVALUE(Com::tLevelingCalc,"Leveling calc:")
FSTRINGVALUE(Com::tTower1,"Tower 1:")
FSTRINGVALUE(Com::tTower2,"Tower 2:")
FSTRINGVALUE(Com::tTower3,"Tower 3:")
FSTRINGVALUE(Com::tDeltaAlphaA,"Alpha A(210):")
FSTRINGVALUE(Com::tDeltaAlphaB,"Alpha B(330):")
FSTRINGVALUE(Com::tDeltaAlphaC,"Alpha C(90):")
FSTRINGVALUE(Com::tDeltaRadiusCorrectionA,"Delta Radius A(0):")
FSTRINGVALUE(Com::tDeltaRadiusCorrectionB,"Delta Radius B(0):")
FSTRINGVALUE(Com::tDeltaRadiusCorrectionC,"Delta Radius C(0):")
FSTRINGVALUE(Com::tDBGDeltaNoMoveinDSegment,"No move in delta segment with > 1 segment. This should never happen and may cause a problem!")
#endif // DRIVE_SYSTEM
#if DRIVE_SYSTEM==TUGA
FSTRINGVALUE(Com::tInvalidDeltaCoordinate,"Invalid coordinate - move ignored")
FSTRINGVALUE(Com::tDBGDeltaNoMoveinDSegment,"No move in delta segment with > 1 segment. This should never happen and may cause a problem!")
FSTRINGVALUE(Com::tEPRDiagonalRodLength,"Long arm length [mm]")
#endif // DRIVE_SYSTEM
#ifdef DEBUG_GENERIC
FSTRINGVALUE(Com::tGenTemp,"GenTemp:")
#endif // DEBUG_GENERICFSTRINGVALUE(Com::,"")
FSTRINGVALUE(Com::tTargetExtr,"TargetExtr")
FSTRINGVALUE(Com::tTargetBedColon,"TargetBed:")
FSTRINGVALUE(Com::tPIDAutotuneStart,"PID Autotune start")
FSTRINGVALUE(Com::tAPIDBias," bias: ")
FSTRINGVALUE(Com::tAPIDD," d: ")
FSTRINGVALUE(Com::tAPIDMin," min: ")
FSTRINGVALUE(Com::tAPIDMax," max: ")
FSTRINGVALUE(Com::tAPIDKu," Ku: ")
FSTRINGVALUE(Com::tAPIDTu," Tu: ")
FSTRINGVALUE(Com::tAPIDClassic," Classic PID")
FSTRINGVALUE(Com::tAPIDKp," Kp: ")
FSTRINGVALUE(Com::tAPIDKi," Ki: ")
FSTRINGVALUE(Com::tAPIDKd," Kd: ")
FSTRINGVALUE(Com::tAPIDFailedHigh,"PID Autotune failed! Temperature to high")
FSTRINGVALUE(Com::tAPIDFailedTimeout,"PID Autotune failed! timeout")
FSTRINGVALUE(Com::tAPIDFinished,"PID Autotune finished ! Place the Kp, Ki and Kd constants in the Configuration.h or EEPROM")
FSTRINGVALUE(Com::tMTEMPColon,"MTEMP:")
FSTRINGVALUE(Com::tHeatedBed,"heated bed")
FSTRINGVALUE(Com::tExtruderSpace,"extruder ")
FSTRINGVALUE(Com::tTempSensorDefect,": temp sensor defect")
FSTRINGVALUE(Com::tTempSensorWorking,": working")
FSTRINGVALUE(Com::tDryModeUntilRestart,"Printer set into dry run mode until restart!")
#ifdef DEBUG_QUEUE_MOVE
FSTRINGVALUE(Com::tDBGId,"ID:")
FSTRINGVALUE(Com::tDBGVStartEnd,"vStart/End:")
FSTRINGVALUE(Com::tDBAccelSteps,"accel/decel steps:")
FSTRINGVALUE(Com::tDBGStartEndSpeed,"st./end speed:")
FSTRINGVALUE(Com::tDBGFlags,"Flags:")
FSTRINGVALUE(Com::tDBGJoinFlags,"joinFlags:")
FSTRINGVALUE(Com::tDBGDelta,"Delta")
FSTRINGVALUE(Com::tDBGDir,"Dir:")
FSTRINGVALUE(Com::tDBGFullSpeed,"fullSpeed:")
FSTRINGVALUE(Com::tDBGVMax,"vMax:")
FSTRINGVALUE(Com::tDBGAcceleration,"Acceleration:")
FSTRINGVALUE(Com::tDBGAccelerationPrim,"Acceleration Prim:")
FSTRINGVALUE(Com::tDBGRemainingSteps,"Remaining steps:")
FSTRINGVALUE(Com::tDBGAdvanceFull,"advanceFull:")
FSTRINGVALUE(Com::tDBGAdvanceRate,"advanceRate:")
FSTRINGVALUE(Com::tDBGLimitInterval,"LimitInterval:")
FSTRINGVALUE(Com::tDBGMoveDistance,"Move distance on the XYZ space:")
FSTRINGVALUE(Com::tDBGCommandedFeedrate,"Commanded feedrate:")
FSTRINGVALUE(Com::tDBGConstFullSpeedMoveTime,"Constant full speed move time:")
#endif // DEBUG_QUEUE_MOVEFSTRINGVALUE(Com::,"")
#ifdef DEBUG_DELTA_OVERFLOW
FSTRINGVALUE(Com::tDBGDeltaOverflow,"Delta overflow:")
#endif // DEBUG_DELTA_OVERFLOW
#ifdef DEBUG_SPLIT
FSTRINGVALUE(Com::tDBGDeltaSeconds,"Seconds:")
FSTRINGVALUE(Com::tDBGDeltaZDelta,"Z delta:")
FSTRINGVALUE(Com::tDBGDeltaSegments,"Segments:")
FSTRINGVALUE(Com::tDBGDeltaNumLines,"Num lines:")
FSTRINGVALUE(Com::tDBGDeltaSegmentsPerLine,"segments_per_line:")
FSTRINGVALUE(Com::tDBGDeltaMaxDS,"Max DS:")
FSTRINGVALUE(Com::tDBGDeltaStepsPerSegment,"Steps Per Segment:")
FSTRINGVALUE(Com::tDBGDeltaVirtualAxisSteps,"Virtual axis steps:")
#endif
#ifdef DEBUG_STEPCOUNT
FSTRINGVALUE(Com::tDBGMissedSteps,"Missed steps:")
#endif // DEBUG_STEPCOUNT
#if FEATURE_Z_PROBE
FSTRINGVALUE(Com::tZProbe,"Z-probe:")
FSTRINGVALUE(Com::tZProbeSteps," Step Variation from Probe to bed Distance:")
FSTRINGVALUE(Com::tZProbeAverage,"Z-probe average height:")
FSTRINGVALUE(Com::tZProbeZReset,"Reset Z height")
FSTRINGVALUE(Com::tZProbeState,"Z-probe state:")
FSTRINGVALUE(Com::tZProbeStartScript,Z_PROBE_START_SCRIPT)
FSTRINGVALUE(Com::tZProbeEndScript,Z_PROBE_FINISHED_SCRIPT)
FSTRINGVALUE(Com::tHitZProbe,"Hit z-probe")
#endif
FSTRINGVALUE(Com::tAutolevelReset,"Autolevel matrix reset")
FSTRINGVALUE(Com::tAutolevelEnabled,"Autoleveling enabled")
FSTRINGVALUE(Com::tAutolevelDisabled,"Autoleveling disabled")
FSTRINGVALUE(Com::tTransformationMatrix,"Transformation matrix:")
FSTRINGVALUE(Com::tZProbeFailed,"Z-probe failed")
FSTRINGVALUE(Com::tZProbeMax,"Z-probe max:")
FSTRINGVALUE(Com::tZProbePrinterHeight,"Printer height:")
//FSTRINGVALUE(Com::,"")
#ifdef WAITING_IDENTIFIER
FSTRINGVALUE(Com::tWait,WAITING_IDENTIFIER)
#endif // WAITING_IDENTIFIER
#if EEPROM_MODE == 0
FSTRINGVALUE(Com::tNoEEPROMSupport,"No EEPROM support compiled.\r\n")
#else
#if FEATURE_Z_PROBE
FSTRINGVALUE(Com::tZProbeHeight,"Z-probe height [mm]")
FSTRINGVALUE(Com::tZProbeBedDitance,"Max. z-probe - bed dist. [mm]")
FSTRINGVALUE(Com::tZProbeOffsetX,"Z-probe offset x [mm]")
FSTRINGVALUE(Com::tZProbeOffsetY,"Z-probe offset y [mm]")
FSTRINGVALUE(Com::tZProbeSpeed,"Z-probe speed [mm/s]")
FSTRINGVALUE(Com::tZProbeSpeedXY,"Z-probe x-y-speed [mm/s]")
FSTRINGVALUE(Com::tZProbeX1,"Z-probe X1")
FSTRINGVALUE(Com::tZProbeY1,"Z-probe Y1")
FSTRINGVALUE(Com::tZProbeX2,"Z-probe X2")
FSTRINGVALUE(Com::tZProbeY2,"Z-probe Y2")
FSTRINGVALUE(Com::tZProbeX3,"Z-probe X3")
FSTRINGVALUE(Com::tZProbeY3,"Z-probe Y3")
#endif
#if FEATURE_AXISCOMP
FSTRINGVALUE(Com::tAxisCompTanXY,"tanXY Axis Compensation")
FSTRINGVALUE(Com::tAxisCompTanYZ,"tanYZ Axis Compensation")
FSTRINGVALUE(Com::tAxisCompTanXZ,"tanXZ Axis Compensation")
#endif
#if FEATURE_AUTOLEVEL
FSTRINGVALUE(Com::tAutolevelActive,"Autolevel active (1/0)")
#endif
FSTRINGVALUE(Com::tConfigStoredEEPROM,"Configuration stored to EEPROM.")
FSTRINGVALUE(Com::tConfigLoadedEEPROM,"Configuration loaded from EEPROM.")
FSTRINGVALUE(Com::tEPRConfigResetDefaults,"Configuration reset to defaults.")
FSTRINGVALUE(Com::tEPRProtocolChanged,"Protocol version changed, upgrading")
FSTRINGVALUE(Com::tEPR0,"EPR:0 ")
FSTRINGVALUE(Com::tEPR1,"EPR:1 ")
FSTRINGVALUE(Com::tEPR2,"EPR:2 ")
FSTRINGVALUE(Com::tEPR3,"EPR:3 ")
FSTRINGVALUE(Com::tEPRBaudrate,"Baudrate")
FSTRINGVALUE(Com::tEPRAdvancedUser, "Advanced User")
FSTRINGVALUE(Com::tEPRFilamentPrinted,"Filament printed [m]")
FSTRINGVALUE(Com::tEPRPrinterActive,"Printer active [s]")
FSTRINGVALUE(Com::tEPRMaxInactiveTime,"Max. inactive time [ms,0=off]")
FSTRINGVALUE(Com::tEPRStopAfterInactivty,"Stop stepper after inactivity [ms,0=off]")
FSTRINGVALUE(Com::tEPRXHomePos,"X home pos [mm]")
FSTRINGVALUE(Com::tEPRYHomePos,"Y home pos [mm]")
FSTRINGVALUE(Com::tEPRZHomePos,"Z home pos [mm]")
FSTRINGVALUE(Com::tEPRXMaxLength,"X max length [mm]")
FSTRINGVALUE(Com::tEPRYMaxLength,"Y max length [mm]")
FSTRINGVALUE(Com::tEPRZMaxLength,"Z max length [mm]")
FSTRINGVALUE(Com::tEPRXBacklash,"X backlash [mm]")
FSTRINGVALUE(Com::tEPRYBacklash,"Y backlash [mm]")
FSTRINGVALUE(Com::tEPRZBacklash,"Z backlash [mm]")
FSTRINGVALUE(Com::tEPRMaxJerk,"Max. jerk [mm/s]")
#if DRIVE_SYSTEM==DELTA
FSTRINGVALUE(Com::tEPRZAcceleration,"Acceleration [mm/s^2]")
FSTRINGVALUE(Com::tEPRZTravelAcceleration,"Travel acceleration [mm/s^2]")
FSTRINGVALUE(Com::tEPRZStepsPerMM,"Steps per mm")
FSTRINGVALUE(Com::tEPRZMaxFeedrate,"Max. feedrate [mm/s]")
FSTRINGVALUE(Com::tEPRZHomingFeedrate,"Homing feedrate [mm/s]")
FSTRINGVALUE(Com::tEPRDiagonalRodLength,"Diagonal rod length [mm]")
FSTRINGVALUE(Com::tEPRHorizontalRadius,"Horizontal rod radius at 0,0 [mm]")
FSTRINGVALUE(Com::tEPRSegmentsPerSecondPrint,"Segments/s for printing")
FSTRINGVALUE(Com::tEPRSegmentsPerSecondTravel,"Segments/s for travel")
FSTRINGVALUE(Com::tEPRTowerXOffset,"Tower X endstop offset [steps]")
FSTRINGVALUE(Com::tEPRTowerYOffset,"Tower Y endstop offset [steps]")
FSTRINGVALUE(Com::tEPRTowerZOffset,"Tower Z endstop offset [steps]")
FSTRINGVALUE(Com::tEPRDeltaMaxRadius,"Max printable radius [mm]")
FSTRINGVALUE(Com::tDeltaDiagonalCorrectionA,"Corr. diagonal A [mm]")
FSTRINGVALUE(Com::tDeltaDiagonalCorrectionB,"Corr. diagonal B [mm]")
FSTRINGVALUE(Com::tDeltaDiagonalCorrectionC,"Corr. diagonal C [mm]")
#else
FSTRINGVALUE(Com::tEPRMaxZJerk,"Max. Z-jerk [mm/s]")
FSTRINGVALUE(Com::tEPRXStepsPerMM,"X-axis steps per mm")
FSTRINGVALUE(Com::tEPRYStepsPerMM,"Y-axis steps per mm")
FSTRINGVALUE(Com::tEPRZStepsPerMM,"Z-axis steps per mm")
FSTRINGVALUE(Com::tEPRXMaxFeedrate,"X-axis max. feedrate [mm/s]")
FSTRINGVALUE(Com::tEPRYMaxFeedrate,"Y-axis max. feedrate [mm/s]")
FSTRINGVALUE(Com::tEPRZMaxFeedrate,"Z-axis max. feedrate [mm/s]")
FSTRINGVALUE(Com::tEPRXHomingFeedrate,"X-axis homing feedrate [mm/s]")
FSTRINGVALUE(Com::tEPRYHomingFeedrate,"Y-axis homing feedrate [mm/s]")
FSTRINGVALUE(Com::tEPRZHomingFeedrate,"Z-axis homing feedrate [mm/s]")
FSTRINGVALUE(Com::tEPRXAcceleration,"X-axis acceleration [mm/s^2]")
FSTRINGVALUE(Com::tEPRYAcceleration,"Y-axis acceleration [mm/s^2]")
FSTRINGVALUE(Com::tEPRZAcceleration,"Z-axis acceleration [mm/s^2]")
FSTRINGVALUE(Com::tEPRXTravelAcceleration,"X-axis travel acceleration [mm/s^2]")
FSTRINGVALUE(Com::tEPRYTravelAcceleration,"Y-axis travel acceleration [mm/s^2]")
FSTRINGVALUE(Com::tEPRZTravelAcceleration,"Z-axis travel acceleration [mm/s^2]")
#endif
FSTRINGVALUE(Com::tEPROPSMode,"OPS operation mode [0=Off,1=Classic,2=Fast]")
FSTRINGVALUE(Com::tEPROPSMoveAfter,"OPS move after x% retract [%]")
FSTRINGVALUE(Com::tEPROPSMinDistance,"OPS min. distance for fil. retraction [mm]")
FSTRINGVALUE(Com::tEPROPSRetractionLength,"OPS retraction length [mm]")
FSTRINGVALUE(Com::tEPROPSRetractionBacklash,"OPS retraction backlash [mm]")
FSTRINGVALUE(Com::tEPRBedHeatManager,"Bed Heat Manager [0-3]")
FSTRINGVALUE(Com::tEPRBedPIDDriveMax,"Bed PID drive max")
FSTRINGVALUE(Com::tEPRBedPIDDriveMin,"Bed PID drive min")
FSTRINGVALUE(Com::tEPRBedPGain,"Bed PID P-gain")
FSTRINGVALUE(Com::tEPRBedIGain,"Bed PID I-gain")
FSTRINGVALUE(Com::tEPRBedDGain,"Bed PID D-gain")
FSTRINGVALUE(Com::tEPRBedPISMaxValue,"Bed PID max value [0-255]")
FSTRINGVALUE(Com::tEPRStepsPerMM,"steps per mm")
FSTRINGVALUE(Com::tEPRMaxFeedrate,"max. feedrate [mm/s]")
FSTRINGVALUE(Com::tEPRStartFeedrate,"start feedrate [mm/s]")
FSTRINGVALUE(Com::tEPRAcceleration,"acceleration [mm/s^2]")
FSTRINGVALUE(Com::tEPRHeatManager,"heat manager [0-3]")
FSTRINGVALUE(Com::tEPRDriveMax,"PID drive max")
FSTRINGVALUE(Com::tEPRDriveMin,"PID drive min")
FSTRINGVALUE(Com::tEPRPGain,"PID P-gain/dead-time")
FSTRINGVALUE(Com::tEPRDead,"Heater dead-time")
FSTRINGVALUE(Com::tEPRUnused,"na for dead time ctrl")
FSTRINGVALUE(Com::tEPRIGain,"PID I-gain")
FSTRINGVALUE(Com::tEPRDGain,"PID D-gain")
FSTRINGVALUE(Com::tEPRPIDMaxValue,"PID max value [0-255]")
FSTRINGVALUE(Com::tEPRXOffset,"X-offset [steps]")
FSTRINGVALUE(Com::tEPRYOffset,"Y-offset [steps]")
FSTRINGVALUE(Com::tEPRStabilizeTime,"temp. stabilize time [s]")
FSTRINGVALUE(Com::tEPRRetractionWhenHeating,"temp. for retraction when heating [C]")
FSTRINGVALUE(Com::tEPRDistanceRetractHeating,"distance to retract when heating [mm]")
FSTRINGVALUE(Com::tEPRExtruderCoolerSpeed,"extruder cooler speed [0-255]")
FSTRINGVALUE(Com::tEPRAdvanceK,"advance K [0=off]")
FSTRINGVALUE(Com::tEPRAdvanceL,"advance L [0=off]")
#endif
#if SDSUPPORT
FSTRINGVALUE(Com::tSDRemoved,UI_TEXT_SD_REMOVED)
FSTRINGVALUE(Com::tSDInserted,UI_TEXT_SD_INSERTED)
FSTRINGVALUE(Com::tSDInitFail,"SD init fail")
FSTRINGVALUE(Com::tErrorWritingToFile,"error writing to file")
FSTRINGVALUE(Com::tBeginFileList,"Begin file list")
FSTRINGVALUE(Com::tEndFileList,"End file list")
FSTRINGVALUE(Com::tFileOpened,"File opened:")
FSTRINGVALUE(Com::tSpaceSizeColon," Size:")
FSTRINGVALUE(Com::tFileSelected,"File selected")
FSTRINGVALUE(Com::tFileOpenFailed,"file.open failed")
FSTRINGVALUE(Com::tSDPrintingByte,"SD printing byte ")
FSTRINGVALUE(Com::tNotSDPrinting,"Not SD printing")
FSTRINGVALUE(Com::tOpenFailedFile,"open failed, File: ")
FSTRINGVALUE(Com::tWritingToFile,"Writing to file: ")
FSTRINGVALUE(Com::tDoneSavingFile,"Done saving file.")
FSTRINGVALUE(Com::tFileDeleted,"File deleted")
FSTRINGVALUE(Com::tDeletionFailed,"Deletion failed")
FSTRINGVALUE(Com::tDirectoryCreated,"Directory created")
FSTRINGVALUE(Com::tCreationFailed,"Creation failed")
FSTRINGVALUE(Com::tSDErrorCode,"SD errorCode:")
#endif // SDSUPPORT
FSTRINGVALUE(Com::tHeaterDecoupled,"Heater decoupled")
FSTRINGVALUE(Com::tHeaterDecoupledWarning,"One heater seems decoupled from thermistor - disabling all for safety!")
#if DISTORTION_CORRECTION
FSTRINGVALUE(Com::tZCorrectionEnabled,"Z correction enabled")
FSTRINGVALUE(Com::tZCorrectionDisabled,"Z correction disabled")
#endif
#if FEATURE_RETRACTION
FSTRINGVALUE(Com::tEPRAutoretractEnabled,"Enable retraction conversion [0/1]")
FSTRINGVALUE(Com::tEPRRetractionLength,"Retraction length [mm]")
FSTRINGVALUE(Com::tEPRRetractionLongLength,"Retraction length extruder switch [mm]")
FSTRINGVALUE(Com::tEPRRetractionSpeed,"Retraction speed [mm/s]")
FSTRINGVALUE(Com::tEPRRetractionZLift,"Retraction z-lift [mm]")
FSTRINGVALUE(Com::tEPRRetractionUndoExtraLength,"Extra extrusion on undo retract [mm]")
FSTRINGVALUE(Com::tEPRRetractionUndoExtraLongLength,"Extra extrusion on undo switch retract [mm]")
FSTRINGVALUE(Com::tEPRRetractionUndoSpeed,"Retraction undo speed")
#endif
FSTRINGVALUE(Com::tConfig,"Config:")
FSTRINGVALUE(Com::tExtrDot,"Extr.")
void Com::config(FSTRINGPARAM(text)) {
printF(tConfig);
printFLN(text);
}
void Com::config(FSTRINGPARAM(text),int value) {
printF(tConfig);
printFLN(text,value);
}
void Com::config(FSTRINGPARAM(text),const char *msg) {
printF(tConfig);
printF(text);
print(msg);
println();
}
void Com::config(FSTRINGPARAM(text),int32_t value){
printF(tConfig);
printFLN(text,value);
}
void Com::config(FSTRINGPARAM(text),uint32_t value){
printF(tConfig);
printFLN(text,value);
}
void Com::config(FSTRINGPARAM(text),float value,uint8_t digits){
printF(tConfig);
printFLN(text,value,digits);
}
void Com::printWarningF(FSTRINGPARAM(text)) {
printF(tWarning);
printF(text);
}
void Com::printWarningFLN(FSTRINGPARAM(text)) {
printF(tWarning);
printFLN(text);
}
void Com::printInfoF(FSTRINGPARAM(text)) {
printF(tInfo);
printF(text);
}
void Com::printInfoFLN(FSTRINGPARAM(text)) {
printF(tInfo);
printFLN(text);
}
void Com::printErrorF(FSTRINGPARAM(text)) {
printF(tError);
printF(text);
}
void Com::printErrorFLN(FSTRINGPARAM(text)) {
printF(tError);
printFLN(text);
}
void Com::printFLN(FSTRINGPARAM(text)) {
printF(text);
println();
}
void Com::printFLN(FSTRINGPARAM(text),const char *msg) {
printF(text);
print(msg);
println();
}
void Com::printF(FSTRINGPARAM(ptr)) {
char c;
while ((c=HAL::readFlashByte(ptr++)) != 0)
HAL::serialWriteByte(c);
}
void Com::printF(FSTRINGPARAM(text),const char *msg) {
printF(text);
print(msg);
}
void Com::printF(FSTRINGPARAM(text),int value) {
printF(text);
print(value);
}
void Com::printF(FSTRINGPARAM(text),int32_t value) {
printF(text);
print(value);
}
void Com::printF(FSTRINGPARAM(text),uint32_t value) {
printF(text);
printNumber(value);
}
void Com::printFLN(FSTRINGPARAM(text),int value) {
printF(text);
print(value);
println();
}
void Com::printFLN(FSTRINGPARAM(text),int32_t value) {
printF(text);
print(value);
println();
}
void Com::printFLN(FSTRINGPARAM(text),uint32_t value) {
printF(text);
printNumber(value);
println();
}
void Com::printFLN(FSTRINGPARAM(text),float value,uint8_t digits) {
printF(text);
printFloat(value,digits);
println();
}
void Com::printF(FSTRINGPARAM(text),float value,uint8_t digits) {
printF(text);
printFloat(value,digits);
}
void Com::print(const char *text) {
while(*text) {
HAL::serialWriteByte(*text++);
}
}
void Com::print(long value) {
if(value<0) {
HAL::serialWriteByte('-');
value = -value;
}
printNumber(value);
}
void Com::printNumber(uint32_t n) {
char buf[11]; // Assumes 8-bit chars plus zero byte.
char *str = &buf[10];
*str = '\0';
do {
unsigned long m = n;
n /= 10;
*--str = '0'+(m - 10 * n);
} while(n);
print(str);
}
void Com::printArrayFLN(FSTRINGPARAM(text),float *arr,uint8_t n,uint8_t digits) {
printF(text);
for(uint8_t i=0; i<n; i++)
printF(Com::tSpace,arr[i],digits);
println();
}
void Com::printArrayFLN(FSTRINGPARAM(text),int32_t *arr,uint8_t n) {
printF(text);
for(uint8_t i=0; i<n; i++)
printF(Com::tSpace,arr[i]);
println();
}
void Com::printFloat(float number, uint8_t digits)
{
if (isnan(number)) {
printF(tNAN);
return;
}
if (isinf(number)) {
printF(tINF);
return;
}
// Handle negative numbers
if (number < 0.0)
{
print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
float rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding /= 10.0;
number += rounding;
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
float remainder = number - (float)int_part;
printNumber(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0)
print('.');
// Extract digits from the remainder one at a time
while (digits-- > 0)
{
remainder *= 10.0;
int toPrint = int(remainder);
print(toPrint);
remainder -= toPrint;
}
}

View File

@ -0,0 +1,439 @@
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Repetier-Firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
This firmware is a nearly complete rewrite of the sprinter firmware
by kliment (https://github.com/kliment/Sprinter)
which based on Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
*/
#ifndef COMMUNICATION_H
#define COMMUNICATION_H
class Com
{
public:
FSTRINGVAR(tDebug)
FSTRINGVAR(tFirmware)
FSTRINGVAR(tOk)
FSTRINGVAR(tNewline)
FSTRINGVAR(tNAN)
FSTRINGVAR(tINF)
FSTRINGVAR(tError)
FSTRINGVAR(tInfo)
FSTRINGVAR(tWarning)
FSTRINGVAR(tResend)
FSTRINGVAR(tEcho)
FSTRINGVAR(tOkSpace)
FSTRINGVAR(tWrongChecksum)
FSTRINGVAR(tMissingChecksum)
FSTRINGVAR(tFormatError)
FSTRINGVAR(tDonePrinting)
FSTRINGVAR(tX)
FSTRINGVAR(tY)
FSTRINGVAR(tZ)
FSTRINGVAR(tE)
FSTRINGVAR(tF)
FSTRINGVAR(tS)
FSTRINGVAR(tP)
FSTRINGVAR(tI)
FSTRINGVAR(tJ)
FSTRINGVAR(tR)
FSTRINGVAR(tSDReadError)
FSTRINGVAR(tExpectedLine)
FSTRINGVAR(tGot)
FSTRINGVAR(tSkip)
FSTRINGVAR(tBLK)
FSTRINGVAR(tStart)
FSTRINGVAR(tPowerUp)
FSTRINGVAR(tExternalReset)
FSTRINGVAR(tBrownOut)
FSTRINGVAR(tWatchdog)
FSTRINGVAR(tSoftwareReset)
FSTRINGVAR(tUnknownCommand)
FSTRINGVAR(tFreeRAM)
FSTRINGVAR(tXColon)
FSTRINGVAR(tSlash)
FSTRINGVAR(tSpaceSlash)
FSTRINGVAR(tSpaceXColon)
FSTRINGVAR(tSpaceYColon)
FSTRINGVAR(tSpaceZColon)
FSTRINGVAR(tSpaceEColon)
FSTRINGVAR(tTColon)
FSTRINGVAR(tSpaceBColon)
FSTRINGVAR(tSpaceAtColon)
FSTRINGVAR(tSpaceT)
FSTRINGVAR(tSpaceRaw)
FSTRINGVAR(tSpaceAt)
FSTRINGVAR(tSpaceBAtColon)
FSTRINGVAR(tColon)
FSTRINGVAR(tSpeedMultiply)
FSTRINGVAR(tFlowMultiply)
FSTRINGVAR(tHorizontalRadius)
FSTRINGVAR(tFanspeed)
FSTRINGVAR(tPrintedFilament)
FSTRINGVAR(tPrintingTime)
FSTRINGVAR(tSpacem)
FSTRINGVAR(tSpaceDaysSpace)
FSTRINGVAR(tSpaceHoursSpace)
FSTRINGVAR(tSpaceMin)
FSTRINGVAR(tInvalidArc)
FSTRINGVAR(tComma)
FSTRINGVAR(tSpace)
FSTRINGVAR(tYColon)
FSTRINGVAR(tZColon)
FSTRINGVAR(tE0Colon)
FSTRINGVAR(tE1Colon)
FSTRINGVAR(tMS1MS2Pins)
FSTRINGVAR(tSetOutputSpace)
FSTRINGVAR(tGetInputSpace)
FSTRINGVAR(tSpaceToSpace)
FSTRINGVAR(tSpaceIsSpace)
FSTRINGVAR(tHSpace)
FSTRINGVAR(tLSpace)
FSTRINGVAR(tXMinColon)
FSTRINGVAR(tXMaxColon)
FSTRINGVAR(tYMinColon)
FSTRINGVAR(tYMaxColon)
FSTRINGVAR(tZMinColon)
FSTRINGVAR(tZMaxColon)
FSTRINGVAR(tJerkColon)
FSTRINGVAR(tZJerkColon)
FSTRINGVAR(tLinearStepsColon)
FSTRINGVAR(tQuadraticStepsColon)
FSTRINGVAR(tCommaSpeedEqual)
FSTRINGVAR(tLinearLColon)
FSTRINGVAR(tQuadraticKColon)
FSTRINGVAR(tEEPROMUpdated)
#if DRIVE_SYSTEM==DELTA
FSTRINGVAR(tMeasurementReset)
FSTRINGVAR(tMeasureDeltaSteps)
FSTRINGVAR(tMeasureDelta)
FSTRINGVAR(tMeasureOriginReset)
FSTRINGVAR(tMeasurementAbortedOrigin)
FSTRINGVAR(tInvalidDeltaCoordinate)
FSTRINGVAR(tLevelingCalc)
FSTRINGVAR(tTower1)
FSTRINGVAR(tTower2)
FSTRINGVAR(tTower3)
FSTRINGVAR(tDeltaAlphaA)
FSTRINGVAR(tDeltaAlphaB)
FSTRINGVAR(tDeltaAlphaC)
FSTRINGVAR(tDeltaRadiusCorrectionA)
FSTRINGVAR(tDeltaRadiusCorrectionB)
FSTRINGVAR(tDeltaRadiusCorrectionC)
FSTRINGVAR(tDeltaDiagonalCorrectionA)
FSTRINGVAR(tDeltaDiagonalCorrectionB)
FSTRINGVAR(tDeltaDiagonalCorrectionC)
FSTRINGVAR(tDBGDeltaNoMoveinDSegment)
FSTRINGVAR(tEPRDeltaMaxRadius)
#endif // DRIVE_SYSTEM
#if DRIVE_SYSTEM==TUGA
FSTRINGVAR(tInvalidDeltaCoordinate)
FSTRINGVAR(tDBGDeltaNoMoveinDSegment)
FSTRINGVAR(tEPRDiagonalRodLength)
#endif
#ifdef DEBUG_GENERIC
FSTRINGVAR(tGenTemp)
#endif // DEBUG_GENERICFSTRINGVALUE(Com::,"")
FSTRINGVAR(tTargetExtr)
FSTRINGVAR(tTargetBedColon)
FSTRINGVAR(tPIDAutotuneStart)
FSTRINGVAR(tAPIDBias)
FSTRINGVAR(tAPIDD)
FSTRINGVAR(tAPIDMin)
FSTRINGVAR(tAPIDMax)
FSTRINGVAR(tAPIDKu)
FSTRINGVAR(tAPIDTu)
FSTRINGVAR(tAPIDClassic)
FSTRINGVAR(tAPIDKp)
FSTRINGVAR(tAPIDKi)
FSTRINGVAR(tAPIDKd)
FSTRINGVAR(tAPIDFailedHigh)
FSTRINGVAR(tAPIDFailedTimeout)
FSTRINGVAR(tAPIDFinished)
FSTRINGVAR(tMTEMPColon)
FSTRINGVAR(tHeatedBed)
FSTRINGVAR(tExtruderSpace)
FSTRINGVAR(tTempSensorDefect)
FSTRINGVAR(tTempSensorWorking)
FSTRINGVAR(tDryModeUntilRestart)
#ifdef DEBUG_QUEUE_MOVE
FSTRINGVAR(tDBGId)
FSTRINGVAR(tDBGVStartEnd)
FSTRINGVAR(tDBAccelSteps)
FSTRINGVAR(tDBGStartEndSpeed)
FSTRINGVAR(tDBGFlags)
FSTRINGVAR(tDBGJoinFlags)
FSTRINGVAR(tDBGDelta)
FSTRINGVAR(tDBGDir)
FSTRINGVAR(tDBGFullSpeed)
FSTRINGVAR(tDBGVMax)
FSTRINGVAR(tDBGAcceleration)
FSTRINGVAR(tDBGAccelerationPrim)
FSTRINGVAR(tDBGRemainingSteps)
FSTRINGVAR(tDBGAdvanceFull)
FSTRINGVAR(tDBGAdvanceRate)
FSTRINGVAR(tDBGLimitInterval)
FSTRINGVAR(tDBGMoveDistance)
FSTRINGVAR(tDBGCommandedFeedrate)
FSTRINGVAR(tDBGConstFullSpeedMoveTime)
#endif // DEBUG_QUEUE_MOVEFSTRINGVALUE(Com::,"")
#ifdef DEBUG_DELTA_OVERFLOW
FSTRINGVAR(tDBGDeltaOverflow)
#endif // DEBUG_DELTA_OVERFLOW
#ifdef DEBUG_SPLIT
FSTRINGVAR(tDBGDeltaSeconds)
FSTRINGVAR(tDBGDeltaZDelta)
FSTRINGVAR(tDBGDeltaSegments)
FSTRINGVAR(tDBGDeltaNumLines)
FSTRINGVAR(tDBGDeltaSegmentsPerLine)
FSTRINGVAR(tDBGDeltaMaxDS)
FSTRINGVAR(tDBGDeltaStepsPerSegment)
FSTRINGVAR(tDBGDeltaVirtualAxisSteps)
#endif
#ifdef DEBUG_STEPCOUNT
FSTRINGVAR(tDBGMissedSteps)
#endif
#if FEATURE_Z_PROBE
FSTRINGVAR(tZProbe)
FSTRINGVAR(tZProbeSteps)
FSTRINGVAR(tZProbeState)
FSTRINGVAR(tZProbeStartScript)
FSTRINGVAR(tZProbeEndScript)
FSTRINGVAR(tHitZProbe)
FSTRINGVAR(tZProbeAverage)
FSTRINGVAR(tZProbeZReset)
FSTRINGVAR(tZProbeBedDitance)
#endif
FSTRINGVAR(tAutolevelReset)
FSTRINGVAR(tAutolevelEnabled)
FSTRINGVAR(tAutolevelDisabled)
FSTRINGVAR(tTransformationMatrix)
FSTRINGVAR(tZProbeFailed)
FSTRINGVAR(tZProbeMax)
FSTRINGVAR(tZProbePrinterHeight)
#ifdef WAITING_IDENTIFIER
FSTRINGVAR(tWait)
#endif // WAITING_IDENTIFIER
#if EEPROM_MODE==0
FSTRINGVAR(tNoEEPROMSupport)
#else
#if FEATURE_Z_PROBE
FSTRINGVAR(tZProbeHeight)
FSTRINGVAR(tZProbeOffsetX)
FSTRINGVAR(tZProbeOffsetY)
FSTRINGVAR(tZProbeSpeed)
FSTRINGVAR(tZProbeSpeedXY)
FSTRINGVAR(tZProbeX1)
FSTRINGVAR(tZProbeY1)
FSTRINGVAR(tZProbeX2)
FSTRINGVAR(tZProbeY2)
FSTRINGVAR(tZProbeX3)
FSTRINGVAR(tZProbeY3)
#endif
#if FEATURE_AUTOLEVEL
FSTRINGVAR(tAutolevelActive)
#endif
#if FEATURE_AXISCOMP
FSTRINGVAR(tAxisCompTanXY)
FSTRINGVAR(tAxisCompTanYZ)
FSTRINGVAR(tAxisCompTanXZ)
#endif
FSTRINGVAR(tConfigStoredEEPROM)
FSTRINGVAR(tConfigLoadedEEPROM)
FSTRINGVAR(tEPRConfigResetDefaults)
FSTRINGVAR(tEPRProtocolChanged)
FSTRINGVAR(tEPR0)
FSTRINGVAR(tEPR1)
FSTRINGVAR(tEPR2)
FSTRINGVAR(tEPR3)
FSTRINGVAR(tEPRBaudrate)
FSTRINGVAR(tEPRAdvancedUser)
FSTRINGVAR(tEPRFilamentPrinted)
FSTRINGVAR(tEPRPrinterActive)
FSTRINGVAR(tEPRMaxInactiveTime)
FSTRINGVAR(tEPRStopAfterInactivty)
FSTRINGVAR(tEPRMaxJerk)
FSTRINGVAR(tEPRXHomePos)
FSTRINGVAR(tEPRYHomePos)
FSTRINGVAR(tEPRZHomePos)
FSTRINGVAR(tEPRXMaxLength)
FSTRINGVAR(tEPRYMaxLength)
FSTRINGVAR(tEPRZMaxLength)
FSTRINGVAR(tEPRXBacklash)
FSTRINGVAR(tEPRYBacklash)
FSTRINGVAR(tEPRZBacklash)
FSTRINGVAR(tEPRZAcceleration)
FSTRINGVAR(tEPRZTravelAcceleration)
FSTRINGVAR(tEPRZStepsPerMM)
FSTRINGVAR(tEPRZMaxFeedrate)
FSTRINGVAR(tEPRZHomingFeedrate)
#if DRIVE_SYSTEM!=DELTA
FSTRINGVAR(tEPRMaxZJerk)
FSTRINGVAR(tEPRXStepsPerMM)
FSTRINGVAR(tEPRYStepsPerMM)
FSTRINGVAR(tEPRXMaxFeedrate)
FSTRINGVAR(tEPRYMaxFeedrate)
FSTRINGVAR(tEPRXHomingFeedrate)
FSTRINGVAR(tEPRYHomingFeedrate)
FSTRINGVAR(tEPRXAcceleration)
FSTRINGVAR(tEPRYAcceleration)
FSTRINGVAR(tEPRXTravelAcceleration)
FSTRINGVAR(tEPRYTravelAcceleration)
#else
FSTRINGVAR(tEPRDiagonalRodLength)
FSTRINGVAR(tEPRHorizontalRadius)
FSTRINGVAR(tEPRSegmentsPerSecondPrint)
FSTRINGVAR(tEPRSegmentsPerSecondTravel)
FSTRINGVAR(tEPRTowerXOffset)
FSTRINGVAR(tEPRTowerYOffset)
FSTRINGVAR(tEPRTowerZOffset)
#endif
FSTRINGVAR(tEPROPSMode)
FSTRINGVAR(tEPROPSMoveAfter)
FSTRINGVAR(tEPROPSMinDistance)
FSTRINGVAR(tEPROPSRetractionLength)
FSTRINGVAR(tEPROPSRetractionBacklash)
FSTRINGVAR(tEPRBedHeatManager)
FSTRINGVAR(tEPRBedPIDDriveMax)
FSTRINGVAR(tEPRBedPIDDriveMin)
FSTRINGVAR(tEPRBedPGain)
FSTRINGVAR(tEPRBedIGain)
FSTRINGVAR(tEPRBedDGain)
FSTRINGVAR(tEPRBedPISMaxValue)
FSTRINGVAR(tEPRStepsPerMM)
FSTRINGVAR(tEPRMaxFeedrate)
FSTRINGVAR(tEPRStartFeedrate)
FSTRINGVAR(tEPRAcceleration)
FSTRINGVAR(tEPRHeatManager)
FSTRINGVAR(tEPRDriveMax)
FSTRINGVAR(tEPRDriveMin)
FSTRINGVAR(tEPRPGain)
FSTRINGVAR(tEPRDead)
FSTRINGVAR(tEPRUnused)
FSTRINGVAR(tEPRIGain)
FSTRINGVAR(tEPRDGain)
FSTRINGVAR(tEPRPIDMaxValue)
FSTRINGVAR(tEPRXOffset)
FSTRINGVAR(tEPRYOffset)
FSTRINGVAR(tEPRStabilizeTime)
FSTRINGVAR(tEPRRetractionWhenHeating)
FSTRINGVAR(tEPRDistanceRetractHeating)
FSTRINGVAR(tEPRExtruderCoolerSpeed)
FSTRINGVAR(tEPRAdvanceK)
FSTRINGVAR(tEPRAdvanceL)
#endif
#if SDSUPPORT
FSTRINGVAR(tSDRemoved)
FSTRINGVAR(tSDInserted)
FSTRINGVAR(tSDInitFail)
FSTRINGVAR(tErrorWritingToFile)
FSTRINGVAR(tBeginFileList)
FSTRINGVAR(tEndFileList)
FSTRINGVAR(tFileOpened)
FSTRINGVAR(tSpaceSizeColon)
FSTRINGVAR(tFileSelected)
FSTRINGVAR(tFileOpenFailed)
FSTRINGVAR(tSDPrintingByte)
FSTRINGVAR(tNotSDPrinting)
FSTRINGVAR(tOpenFailedFile)
FSTRINGVAR(tWritingToFile)
FSTRINGVAR(tDoneSavingFile)
FSTRINGVAR(tFileDeleted)
FSTRINGVAR(tDeletionFailed)
FSTRINGVAR(tDirectoryCreated)
FSTRINGVAR(tCreationFailed)
FSTRINGVAR(tSDErrorCode)
#endif // SDSUPPORT
FSTRINGVAR(tHeaterDecoupled)
FSTRINGVAR(tHeaterDecoupledWarning)
#if DISTORTION_CORRECTION
FSTRINGVAR(tZCorrectionEnabled)
FSTRINGVAR(tZCorrectionDisabled)
#endif
#if FEATURE_RETRACTION
FSTRINGVAR(tEPRAutoretractEnabled)
FSTRINGVAR(tEPRRetractionLength)
FSTRINGVAR(tEPRRetractionLongLength)
FSTRINGVAR(tEPRRetractionSpeed)
FSTRINGVAR(tEPRRetractionZLift)
FSTRINGVAR(tEPRRetractionUndoExtraLength)
FSTRINGVAR(tEPRRetractionUndoExtraLongLength)
FSTRINGVAR(tEPRRetractionUndoSpeed)
#endif
FSTRINGVAR(tConfig)
FSTRINGVAR(tExtrDot)
static void config(FSTRINGPARAM(text));
static void config(FSTRINGPARAM(text),int value);
static void config(FSTRINGPARAM(text),const char *msg);
static void config(FSTRINGPARAM(text),int32_t value);
static void config(FSTRINGPARAM(text),uint32_t value);
static void config(FSTRINGPARAM(text),float value,uint8_t digits=2);
static void printNumber(uint32_t n);
static void printWarningF(FSTRINGPARAM(text));
static void printInfoF(FSTRINGPARAM(text));
static void printErrorF(FSTRINGPARAM(text));
static void printWarningFLN(FSTRINGPARAM(text));
static void printInfoFLN(FSTRINGPARAM(text));
static void printErrorFLN(FSTRINGPARAM(text));
static void printFLN(FSTRINGPARAM(text));
static void printF(FSTRINGPARAM(text));
static void printF(FSTRINGPARAM(text),int value);
static void printF(FSTRINGPARAM(text),const char *msg);
static void printF(FSTRINGPARAM(text),int32_t value);
static void printF(FSTRINGPARAM(text),uint32_t value);
static void printF(FSTRINGPARAM(text),float value,uint8_t digits=2);
static void printFLN(FSTRINGPARAM(text),int value);
static void printFLN(FSTRINGPARAM(text),int32_t value);
static void printFLN(FSTRINGPARAM(text),uint32_t value);
static void printFLN(FSTRINGPARAM(text),const char *msg);
static void printFLN(FSTRINGPARAM(text),float value,uint8_t digits=2);
static void printArrayFLN(FSTRINGPARAM(text),float *arr,uint8_t n=4,uint8_t digits=2);
static void printArrayFLN(FSTRINGPARAM(text),long *arr,uint8_t n=4);
static void print(long value);
static inline void print(uint32_t value) {printNumber(value);}
static inline void print(int value) {print((int32_t)value);}
static void print(const char *text);
static inline void print(char c) {HAL::serialWriteByte(c);}
static void printFloat(float number, uint8_t digits);
static inline void print(float number) {printFloat(number, 6);}
static inline void println() {HAL::serialWriteByte('\r');HAL::serialWriteByte('\n');}
protected:
private:
};
#ifdef DEBUG
#define SHOW(x) {Com::printF(PSTR(" " #x "=")); Com::print(x); Com::println();}
#define SHOWS(x) {Com::printF(PSTR(" " #x "=")); Com::print(x); Com::print(" steps "); Com::print(x/80); Com::printFLN(PSTR(" mm"));}
#define SHOWM(x) {Com::printF(PSTR(" " #x "=")); Com::print((long)x*80); Com::print(" steps "); Com::print(x); Com::printFLN(PSTR(" mm"));}
#define SHOT(x) Com::printF(PSTR(x " "))
#define SHOWA(t,a,n) {SHOT(t); for (int i=0;i<n;i++) SHOWS(a[i]);}
#define SHOWAM(t,a,n) {SHOT(t); for (int i=0;i<n;i++) SHOWM(a[i]);}
#else
#define SHOW(x)
#define SHOT(x)
#define SHOWS(x)
#define SHOWM(x)
#define SHOWA(t,a,n)
#define SHOWAM(t,a,n)
#endif
#endif // COMMUNICATION_H

View File

@ -0,0 +1,816 @@
/*
Printer Model List as used throughout this firmware
Orion = 1
Rostock Max V2 = 2
ERIS = 3
Rostock MAX v3 = 5
Hacker H2 = 6
*/
// ### Define your Printer Model here! ###
#define PRINTER 5
// SeeMeCNC Bowden w/PEEK barrel = 1
// HE240 on ERIS w/accel probe = 2
// HE280 w/accel probe = 3
#define HOTEND 3
// ### Define your motherboard here! ###
// 301 = RAMBo 302 = MINI RAMBo
#define MOTHERBOARD 301
// ##### Older Orions w/ATX had Y inverted and NEW PSU on orions needs opposite ###
// 1 = ATX on older machines 2 = Rail style PSU on newer machines ############################
#define POWER_SUPPLY 2
// ### Number of active extruders
// 1 is standard, 2 is with the Y coupler for dual filament input
//
// WARNING: There is a known bug in Repetier that causes random tool changes when using dual
// extrusion if you have the USB cable connected. In order to avoid this, only print from
// the SD card if you are running two extruders.
#define NUM_EXTRUDER 1
// ############################################################################################
// ################# BASIC CONFIGURATION IS ALL DONE ABOVE HERE ###############################
// ########### ONLY ADVANCCED USERS SHOULD MODIFY ANYTHING BELOW THIS LINE ####################
// ############################################################################################
// ############################################################################################
// ############ FW version info and build date for LCD and M115 string! #######################
// ############################################################################################
#define REPETIER_VERSION "0.92.2"
#define FIRMWARE_DATE "20171204" // in date format yyyymmdd
#ifndef CONFIGURATION_H
#define CONFIGURATION_H
#define ADVANCED_USER 1 // Change to 1 to unlock full menus
#include "pins.h"
// Microstepping mode of your stepper drivers
#define MICROSTEP_MODES {16,16,16,16,16} // 1,2,4,8,16
#if MOTHERBOARD == 301 // RAMBo
#define STEPPER_CURRENT_CONTROL CURRENT_CONTROL_DIGIPOT
#elif MOTHERBOARD == 302 // Mini RAMBo
#define STEPPER_CURRENT_CONTROL CURRENT_CONTROL_PWM
#define MOTOR_CURRENT_PWM_RANGE 2000
#endif
#define Z_LIFT_ON_PAUSE 20 // Amount to lift the head (mm) when pausing from the LCD screen
#define MIN_DEFECT_TEMPERATURE 16 // this is the min temp that will allow the hotend to start heating. Below this it will show as defective to help identify bad thermistors
#define MAX_DEFECT_TEMPERATURE 300 // this is the max temp that wthe printer will throw errors about defective thermistors
#define MIXING_EXTRUDER 0
#define DRIVE_SYSTEM 3
#define BELT_PITCH 2
#define PULLEY_TEETH 20
#define PULLEY_CIRCUMFERENCE (BELT_PITCH * PULLEY_TEETH)
#define PULLEY_DIAMETER 10
//#define PULLEY_CIRCUMFERENCE (PULLEY_DIAMETER * 3.1415927)
#define STEPS_PER_ROTATION 200
#define MICRO_STEPS 16
#define AXIS_STEPS_PER_MM ((float)(MICRO_STEPS * STEPS_PER_ROTATION) / PULLEY_CIRCUMFERENCE) // for deltas with 1.8 deg. steppers and 20 tooth GT2 pulleys
#define XAXIS_STEPS_PER_MM AXIS_STEPS_PER_MM
#define YAXIS_STEPS_PER_MM AXIS_STEPS_PER_MM
#define ZAXIS_STEPS_PER_MM AXIS_STEPS_PER_MM
// ### Hotend and Extruder configuration
#define MIN_EXTRUDER_TEMP 150
#if HOTEND == 1
#define MAXTEMP 240
#define UI_SET_MAX_EXTRUDER_TEMP 240
#define EXT0_PID_INTEGRAL_DRIVE_MAX 180
#define EXT0_PID_INTEGRAL_DRIVE_MIN 80
#define EXT0_PID_PGAIN_OR_DEAD_TIME 14.50
#define EXT0_PID_I 0.73
#define EXT0_PID_D 53.41
#define EXT0_PID_MAX 235
#define EXT1_PID_INTEGRAL_DRIVE_MAX 180
#define EXT1_PID_INTEGRAL_DRIVE_MIN 80
#define EXT1_PID_PGAIN_OR_DEAD_TIME 14.50
#define EXT1_PID_I 0.73
#define EXT1_PID_D 53.41
#define EXT1_PID_MAX 235
#elif HOTEND == 2
#define MAXTEMP 240
#define UI_SET_MAX_EXTRUDER_TEMP 240
#define EXT0_PID_INTEGRAL_DRIVE_MAX 200
#define EXT0_PID_INTEGRAL_DRIVE_MIN 120
#define EXT0_PID_PGAIN_OR_DEAD_TIME 25.0
#define EXT0_PID_I 0.85
#define EXT0_PID_D 176.0
#define EXT0_PID_MAX 210
#elif HOTEND == 3
#define MAXTEMP 290
#define UI_SET_MAX_EXTRUDER_TEMP 280
#define EXT0_PID_INTEGRAL_DRIVE_MAX 230
#define EXT0_PID_INTEGRAL_DRIVE_MIN 80
#define EXT0_PID_PGAIN_OR_DEAD_TIME 48.3
#define EXT0_PID_I 9.7
#define EXT0_PID_D 60.0
#define EXT0_PID_MAX 255
#define EXT1_PID_INTEGRAL_DRIVE_MAX 230
#define EXT1_PID_INTEGRAL_DRIVE_MIN 80
#define EXT1_PID_PGAIN_OR_DEAD_TIME 48.3
#define EXT1_PID_I 9.7
#define EXT1_PID_D 60.0
#define EXT1_PID_MAX 255
#endif
// using PWM not PDM
#define PDM_FOR_EXTRUDER 0
#define PDM_FOR_COOLER 0
#define FEATURE_WATCHDOG 1
#define DECOUPLING_TEST_MAX_HOLD_VARIANCE 20
#define DECOUPLING_TEST_MIN_TEMP_RISE 1
#define RETRACT_ON_PAUSE 2
#define PAUSE_START_COMMANDS "G91/nG1 Z10.0 E-5.0 F1500/nG90/n"
#define PAUSE_END_COMMANDS "G91/nG1 Z-10.0 E5.1 F1500/nG90/n"
// ### EXT0 Setup ###
#define EXT0_X_OFFSET 0
#define EXT0_Y_OFFSET 0
#define EXT0_STEPS_PER_MM 92.4
#define EXT0_TEMPSENSOR_TYPE 97 //97
#define EXT0_TEMPSENSOR_PIN TEMP_0_PIN
#define EXT0_HEATER_PIN HEATER_0_PIN
#define EXT0_STEP_PIN ORIG_E0_STEP_PIN
#define EXT0_DIR_PIN ORIG_E0_DIR_PIN
#define EXT0_INVERSE 1
#define EXT0_ENABLE_PIN E0_ENABLE_PIN
#define EXT0_ENABLE_ON 0
#define EXT0_MAX_FEEDRATE 100
#define EXT0_MAX_START_FEEDRATE 45
#define EXT0_MAX_ACCELERATION 6500
#define EXT0_HEAT_MANAGER 1
#define EXT0_WATCHPERIOD 3
#define EXT0_ADVANCE_K 0
#define EXT0_ADVANCE_L 0
#define EXT0_ADVANCE_BACKLASH_STEPS 0
#define EXT0_WAIT_RETRACT_TEMP 150
#define EXT0_WAIT_RETRACT_UNITS 0
#define EXT0_SELECT_COMMANDS "M117 Extruder 0\nT0\nM84 P4\nG91\nG1E172F6000\nG1E5F500\nG90"
#define EXT0_DESELECT_COMMANDS "G91\nG1E-180F6000\nG90"
#if MOTHERBOARD == 301
#define EXT0_EXTRUDER_COOLER_PIN 7
#elif MOTHERBOARD == 302
#define EXT0_EXTRUDER_COOLER_PIN -1
#endif
#define EXTRUDER_FAN_COOL_TEMP 40
#define EXT0_EXTRUDER_COOLER_SPEED 200
#define EXT0_DECOUPLE_TEST_PERIOD 45000
// ### EXT1 Setup ###
#define EXT1_X_OFFSET 0
#define EXT1_Y_OFFSET 0
#define EXT1_STEPS_PER_MM 92.4
#define EXT1_TEMPSENSOR_TYPE 97 //97
#define EXT1_TEMPSENSOR_PIN TEMP_1_PIN
#define EXT1_HEATER_PIN HEATER_1_PIN
#define EXT1_STEP_PIN ORIG_E1_STEP_PIN
#define EXT1_DIR_PIN ORIG_E1_DIR_PIN
#define EXT1_INVERSE 1
#define EXT1_ENABLE_PIN E1_ENABLE_PIN
#define EXT1_ENABLE_ON 0
#define EXT1_MAX_FEEDRATE 100
#define EXT1_MAX_START_FEEDRATE 45
#define EXT1_MAX_ACCELERATION 6500
#define EXT1_HEAT_MANAGER 1
#define EXT1_WATCHPERIOD 3
#define EXT1_ADVANCE_K 0
#define EXT1_ADVANCE_L 0
#define EXT1_ADVANCE_BACKLASH_STEPS 0
#define EXT1_WAIT_RETRACT_TEMP 150
#define EXT1_WAIT_RETRACT_UNITS 0
#define EXT1_SELECT_COMMANDS "M117 Extruder 1\nT1\nM84 P4\nG91\nG1E172F6000\nG1E5F500\nG90"
#define EXT1_DESELECT_COMMANDS "G91\nG1E-180F6000\nG90"
#if MOTHERBOARD == 301
#define EXT1_EXTRUDER_COOLER_PIN 7
#elif MOTHERBOARD == 302
#define EXT1_EXTRUDER_COOLER_PIN -1
#endif
#define EXTRUDER_FAN_COOL_TEMP 40
#define EXT1_EXTRUDER_COOLER_SPEED 200
#define EXT1_DECOUPLE_TEST_PERIOD 45000
// ############# Heated bed configuration ########################
#define HEATED_BED_MAX_TEMP 120
#define SKIP_M190_IF_WITHIN 5
#define HEATED_BED_SENSOR_TYPE 97 //97
#define HEATED_BED_SENSOR_PIN TEMP_BED_PIN
#define HEATED_BED_HEATER_PIN HEATER_BED_PIN
#define HEATED_BED_SET_INTERVAL 5000
#define HEATED_BED_HEAT_MANAGER 1
#define HEATED_BED_PID_INTEGRAL_DRIVE_MAX 255
#define HEATED_BED_PID_INTEGRAL_DRIVE_MIN 80
#define HEATED_BED_PID_PGAIN_OR_DEAD_TIME 87.86
#define HEATED_BED_PID_IGAIN 3.01
#define HEATED_BED_PID_DGAIN 641.82
#define HEATED_BED_PID_MAX 255
#define HEATED_BED_DECOUPLE_TEST_PERIOD 300000
// #################################
// ### PRINTER SPECIFIC SETTINGS ###
// #################################
#if PRINTER == 1 // Orion Delta
#if MOTHERBOARD == 301
#if NUM_EXTRUDER == 1
#define MOTOR_CURRENT {140,140,140,130,0}
#elif NUM_EXTRUDER == 2
#define MOTOR_CURRENT {140,140,140,145,145}
#endif
#elif MOTHERBOARD == 302
#define MOTOR_CURRENT_PWM {60, 60, 130}
#endif
#define HAVE_HEATED_BED 1
#define INVERT_X_DIR 1
#if POWER_SUPPLY == 2
#define INVERT_Y_DIR 1
#else
#define INVERT_Y_DIR 0
#endif
#define INVERT_Z_DIR 1
#define DELTA_DIAGONAL_ROD 178.0 // ball cup arms
#define DELTA_MAX_RADIUS 90.0
#define PRINTER_RADIUS 145.7
#define Z_MAX_LENGTH 230.0
#define END_EFFECTOR_HORIZONTAL_OFFSET 30.22
#define CARRIAGE_HORIZONTAL_OFFSET 26.5 // molded cheapskates
#define DELTASEGMENTS_PER_PRINTLINE 22
#define STEPPER_INACTIVE_TIME 600L
#define MAX_INACTIVE_TIME 900L
#define MAX_FEEDRATE_X 250
#define MAX_FEEDRATE_Y 250
#define MAX_FEEDRATE_Z 250
#define HOMING_FEEDRATE_X 80
#define HOMING_FEEDRATE_Y 80
#define HOMING_FEEDRATE_Z 80
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_X 1650
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_Y 1650
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_Z 1650
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_X 2800
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_Y 2800
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_Z 2800
#define MAX_JERK 28
#define MAX_ZJERK 28
#if HOTEND == 3
#define FEATURE_Z_PROBE 1
#else
#define FEATURE_Z_PROBE 0
#endif
#define Z_PROBE_SENSITIVITY 20 // 0-126 7 bit value
#define Z_PROBE_BED_DISTANCE 20
#define Z_PROBE_PULLUP 1 //0
#define Z_PROBE_ON_HIGH 0 //1
#define Z_PROBE_X_OFFSET 0
#define Z_PROBE_Y_OFFSET 0
#define Z_PROBE_WAIT_BEFORE_TEST 0
#define Z_PROBE_SPEED 60
#define Z_PROBE_XY_SPEED 50
#define Z_PROBE_SWITCHING_DISTANCE 10
#define Z_PROBE_REPETITIONS 1
#define Z_PROBE_HEIGHT -0.1
#define Z_PROBE_START_SCRIPT "G28/nG1Z25/n"
//#define Z_PROBE_START_SCRIPT "M117 Probe Started/n"
#define Z_PROBE_FINISHED_SCRIPT ""
#define FEATURE_AUTOLEVEL 1
#define Z_PROBE_X1 -75.933
#define Z_PROBE_Y1 -43.84
#define Z_PROBE_X2 75.933
#define Z_PROBE_Y2 -43.84
#define Z_PROBE_X3 0
#define Z_PROBE_Y3 87.69
#define SDSUPPORT 1
#define SDCARDDETECT 81
#define SDCARDDETECTINVERTED 0
#define FEATURE_CONTROLLER 13
#define UI_PRINTER_NAME "ORION Delta"
#define SDSUPPORT 1
#define SDCARDDETECT 81
#define SDCARDDETECTINVERTED 0
#elif PRINTER == 2 // Rostock MAX v2
#if NUM_EXTRUDER == 1
#define MOTOR_CURRENT {140,140,140,130,0}
#elif NUM_EXTRUDER == 2
#define MOTOR_CURRENT {140,140,140,130,130}
#endif
#define HAVE_HEATED_BED 1
#define INVERT_X_DIR 1
#define INVERT_Y_DIR 0
#define INVERT_Z_DIR 1
#define DELTA_DIAGONAL_ROD 291.06 // ball cup arms
#define DELTA_MAX_RADIUS 145.0
#define PRINTER_RADIUS 200.0
#define Z_MAX_LENGTH 350
#define END_EFFECTOR_HORIZONTAL_OFFSET 30.22
#define CARRIAGE_HORIZONTAL_OFFSET 26.5 // molded cheapskates
#define DELTASEGMENTS_PER_PRINTLINE 22
#define STEPPER_INACTIVE_TIME 600L
#define MAX_INACTIVE_TIME 900L
#define MAX_FEEDRATE_X 250
#define MAX_FEEDRATE_Y 250
#define MAX_FEEDRATE_Z 250
#define HOMING_FEEDRATE_X 80
#define HOMING_FEEDRATE_Y 80
#define HOMING_FEEDRATE_Z 80
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_X 1850
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_Y 1850
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_Z 1850
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_X 3000
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_Y 3000
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_Z 3000
#define MAX_JERK 32
#define MAX_ZJERK 32
#if HOTEND == 3
#define FEATURE_Z_PROBE 1
#else
#define FEATURE_Z_PROBE 0
#endif
#define Z_PROBE_SENSITIVITY 20 // 0-126 7 bit value
#define Z_PROBE_BED_DISTANCE 20
#define Z_PROBE_PULLUP 1
#define Z_PROBE_ON_HIGH 0
#define Z_PROBE_X_OFFSET 0
#define Z_PROBE_Y_OFFSET 0
#define Z_PROBE_WAIT_BEFORE_TEST 0
#define Z_PROBE_SPEED 60
#define Z_PROBE_XY_SPEED 50
#define Z_PROBE_SWITCHING_DISTANCE 10
#define Z_PROBE_REPETITIONS 1
#define Z_PROBE_HEIGHT -0.1
#define Z_PROBE_START_SCRIPT "G28/nG1Z25/n"
#define Z_PROBE_FINISHED_SCRIPT ""
#define FEATURE_AUTOLEVEL 1
#define Z_PROBE_X1 -123.565
#define Z_PROBE_Y1 -71.34
#define Z_PROBE_X2 123.565
#define Z_PROBE_Y2 -71.340
#define Z_PROBE_X3 0
#define Z_PROBE_Y3 142.68
#define SDSUPPORT 1
#define SDCARDDETECT 81
#define SDCARDDETECTINVERTED 0
#define FEATURE_CONTROLLER 13
#define UI_PRINTER_NAME "RostockMAXv2"
#elif PRINTER == 3 // ERIS Delta
#define MOTOR_CURRENT_PWM {20, 20, 130}
#define INVERT_X_DIR 0
#define INVERT_Y_DIR 0
#define INVERT_Z_DIR 0
#define DELTA_DIAGONAL_ROD 134.9 // 134.58 early measurement
#define DELTA_MAX_RADIUS 65 // max printable area allowed by firmware
#define PRINTER_RADIUS 98.38 //PRINTER_RADIUS-END_EFFECTOR_HORIZONTAL_OFFSET-CARRIAGE_HORIZONTAL_OFFSET
#define Z_MAX_LENGTH 175.0
#define END_EFFECTOR_HORIZONTAL_OFFSET 23.38
#define CARRIAGE_HORIZONTAL_OFFSET 10
#define DELTASEGMENTS_PER_PRINTLINE 22
#define STEPPER_INACTIVE_TIME 600L
#define MAX_INACTIVE_TIME 900L
#define MAX_FEEDRATE_X 125
#define MAX_FEEDRATE_Y 125
#define MAX_FEEDRATE_Z 125
#define HOMING_FEEDRATE_X 80
#define HOMING_FEEDRATE_Y 80
#define HOMING_FEEDRATE_Z 80
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_X 250
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_Y 250
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_Z 250
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_X 400
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_Y 400
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_Z 400
#define MAX_JERK 12
#define MAX_ZJERK 12
#define FEATURE_Z_PROBE 1
#define Z_PROBE_SENSITIVITY 25 // 0-126 7 bit value
#define Z_PROBE_BED_DISTANCE 20
#define Z_PROBE_PULLUP 1 //0
#define Z_PROBE_ON_HIGH 0 //1
#define Z_PROBE_X_OFFSET 0
#define Z_PROBE_Y_OFFSET 0
#define Z_PROBE_WAIT_BEFORE_TEST 0
#define Z_PROBE_SPEED 90
#define Z_PROBE_XY_SPEED 50
#define Z_PROBE_SWITCHING_DISTANCE 10
#define Z_PROBE_REPETITIONS 1
#define Z_PROBE_HEIGHT -0.2
#define Z_PROBE_START_SCRIPT "G28/nG1Z25/n"
#define Z_PROBE_FINISHED_SCRIPT ""
#define FEATURE_AUTOLEVEL 1
#define Z_PROBE_X1 -54
#define Z_PROBE_Y1 -31
#define Z_PROBE_X2 54
#define Z_PROBE_Y2 -31
#define Z_PROBE_X3 0
#define Z_PROBE_Y3 65
#define UI_PRINTER_NAME "ERIS Delta"
#define FEATURE_CONTROLLER 0
#define HAVE_HEATED_BED 0
#define FAN_BOARD_PIN 6 //Cooling fan on RAMBo board
#elif PRINTER == 5 // Rostock MAX v3
#if NUM_EXTRUDER == 1
#define MOTOR_CURRENT {140,140,140,130,0}
#elif NUM_EXTRUDER == 2
#define MOTOR_CURRENT {140,140,140,130,130}
#endif
#define HAVE_HEATED_BED 1
#define INVERT_X_DIR 1
#define INVERT_Y_DIR 1
#define INVERT_Z_DIR 1
#define DELTA_DIAGONAL_ROD 291.06 // ball cup arms
#define DELTA_MAX_RADIUS 145.0
#define PRINTER_RADIUS 200.0
#define Z_MAX_LENGTH 395
#define END_EFFECTOR_HORIZONTAL_OFFSET 30.22
#define CARRIAGE_HORIZONTAL_OFFSET 26.5 // molded cheapskates
#define DELTASEGMENTS_PER_PRINTLINE 22
#define STEPPER_INACTIVE_TIME 600L
#define MAX_INACTIVE_TIME 900L
#define MAX_FEEDRATE_X 250
#define MAX_FEEDRATE_Y 250
#define MAX_FEEDRATE_Z 250
#define HOMING_FEEDRATE_X 80
#define HOMING_FEEDRATE_Y 80
#define HOMING_FEEDRATE_Z 80
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_X 1850
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_Y 1850
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_Z 1850
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_X 3000
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_Y 3000
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_Z 3000
#define MAX_JERK 32
#define MAX_ZJERK 32
#define FEATURE_Z_PROBE 1
#define Z_PROBE_SENSITIVITY 20 // 0-126 7 bit value
#define Z_PROBE_BED_DISTANCE 20
#define Z_PROBE_PULLUP 1
#define Z_PROBE_ON_HIGH 0
#define Z_PROBE_X_OFFSET 0
#define Z_PROBE_Y_OFFSET 0
#define Z_PROBE_WAIT_BEFORE_TEST 0
#define Z_PROBE_SPEED 80
#define Z_PROBE_XY_SPEED 50
#define Z_PROBE_SWITCHING_DISTANCE 10
#define Z_PROBE_REPETITIONS 1
#define Z_PROBE_HEIGHT -0.1
#define Z_PROBE_START_SCRIPT "G28/nG1Z25/n"
#define Z_PROBE_FINISHED_SCRIPT ""
#define FEATURE_AUTOLEVEL 1
#define Z_PROBE_X1 -123.565
#define Z_PROBE_Y1 -71.34
#define Z_PROBE_X2 123.565
#define Z_PROBE_Y2 -71.340
#define Z_PROBE_X3 0
#define Z_PROBE_Y3 142.68
#define SDSUPPORT 1
#define SDCARDDETECT 81
#define SDCARDDETECTINVERTED 0
#define FEATURE_CONTROLLER 13
#define UI_PRINTER_NAME "RostockMAXv3"
#elif PRINTER == 6 // Hacker H2
#if MOTHERBOARD == 301
#if NUM_EXTRUDER == 1
#define MOTOR_CURRENT {140,140,140,130,0}
#elif NUM_EXTRUDER == 2
#define MOTOR_CURRENT {140,140,140,130,130}
#endif
#elif MOTHERBOARD == 302
#define MOTOR_CURRENT_PWM {100, 100, 130}
#endif
#define INVERT_X_DIR 1
#define INVERT_Y_DIR 1
#define INVERT_Z_DIR 1
#define DELTA_DIAGONAL_ROD 178.0 // ball cup arms
#define DELTA_MAX_RADIUS 72.0
#define PRINTER_RADIUS 155.0
#define Z_MAX_LENGTH 295.0
#define END_EFFECTOR_HORIZONTAL_OFFSET 30.22
#define CARRIAGE_HORIZONTAL_OFFSET 26.5 // molded cheapskates
#define DELTASEGMENTS_PER_PRINTLINE 22
#define STEPPER_INACTIVE_TIME 600L
#define MAX_INACTIVE_TIME 900L
#define MAX_FEEDRATE_X 250
#define MAX_FEEDRATE_Y 250
#define MAX_FEEDRATE_Z 250
#define HOMING_FEEDRATE_X 80
#define HOMING_FEEDRATE_Y 80
#define HOMING_FEEDRATE_Z 80
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_X 1850
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_Y 1850
#define MAX_ACCELERATION_UNITS_PER_SQ_SECOND_Z 1850
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_X 3000
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_Y 3000
#define MAX_TRAVEL_ACCELERATION_UNITS_PER_SQ_SECOND_Z 3000
#define MAX_JERK 32
#define MAX_ZJERK 32
#define FEATURE_Z_PROBE 1
#define Z_PROBE_SENSITIVITY 20 // 0-126 7 bit value
#define Z_PROBE_BED_DISTANCE 20
#define Z_PROBE_PULLUP 1
#define Z_PROBE_ON_HIGH 0
#define Z_PROBE_X_OFFSET 0
#define Z_PROBE_Y_OFFSET 0
#define Z_PROBE_WAIT_BEFORE_TEST 0
#define Z_PROBE_SPEED 80
#define Z_PROBE_XY_SPEED 50
#define Z_PROBE_SWITCHING_DISTANCE 10
#define Z_PROBE_REPETITIONS 1
#define Z_PROBE_HEIGHT -0.1
#define Z_PROBE_START_SCRIPT "G28/nG1Z25/n"
#define Z_PROBE_FINISHED_SCRIPT ""
#define FEATURE_AUTOLEVEL 1
#define Z_PROBE_X1 -75.933
#define Z_PROBE_Y1 -43.84
#define Z_PROBE_X2 75.933
#define Z_PROBE_Y2 -43.84
#define Z_PROBE_X3 0
#define Z_PROBE_Y3 87.69
#define SDSUPPORT 1
#define SDCARDDETECT 81
#define SDCARDDETECTINVERTED 0
#define UI_PRINTER_NAME "Hacker H2"
#define HAVE_HEATED_BED 0
#define FEATURE_CONTROLLER 13
#endif
#define FEATURE_RETRACTION 0
#define AUTORETRACT_ENABLED 0
#define RETRACTION_LENGTH 3
#define RETRACTION_LONG_LENGTH 13
#define RETRACTION_SPEED 40
#define RETRACTION_Z_LIFT 0
#define RETRACTION_UNDO_EXTRA_LENGTH 0
#define RETRACTION_UNDO_EXTRA_LONG_LENGTH 0
#define RETRACTION_UNDO_SPEED 20
#define FILAMENTCHANGE_X_POS 0
#define FILAMENTCHANGE_Y_POS 0
#define FILAMENTCHANGE_Z_ADD 2
#define FILAMENTCHANGE_REHOME 1
#define FILAMENTCHANGE_SHORTRETRACT 5
#define FILAMENTCHANGE_LONGRETRACT 50
#define RETRACT_DURING_HEATUP true
#define PID_CONTROL_RANGE 20
#define SKIP_M109_IF_WITHIN 5
#define SCALE_PID_TO_MAX 0
#define TEMP_HYSTERESIS 0
#define EXTRUDE_MAXLENGTH 1000
#define NUM_TEMPS_USERTHERMISTOR0 0
#define USER_THERMISTORTABLE0 {}
#define NUM_TEMPS_USERTHERMISTOR1 0
#define USER_THERMISTORTABLE1 {}
#define NUM_TEMPS_USERTHERMISTOR2 0
#define USER_THERMISTORTABLE2 {}
#define USE_GENERIC_THERMISTORTABLE_1
#define GENERIC_THERM1_T0 25
#define GENERIC_THERM1_R0 100000
#define GENERIC_THERM1_BETA 4450 //4267
#define GENERIC_THERM1_MIN_TEMP -50
#define GENERIC_THERM1_MAX_TEMP 300
#define GENERIC_THERM1_R1 0
#define GENERIC_THERM1_R2 4700
#define USE_GENERIC_THERMISTORTABLE_2
#define GENERIC_THERM2_T0 25
#define GENERIC_THERM2_R0 100000
#define GENERIC_THERM2_BETA 4367
#define GENERIC_THERM2_MIN_TEMP -20
#define GENERIC_THERM2_MAX_TEMP 300
#define GENERIC_THERM2_R1 0
#define GENERIC_THERM2_R2 4700
#define GENERIC_THERM_VREF 5
#define GENERIC_THERM_NUM_ENTRIES 33
#define HEATER_PWM_SPEED 0
// ################ Endstop configuration #####################
#define ENDSTOP_PULLUP_X_MIN true
#define ENDSTOP_X_MIN_INVERTING false
#define MIN_HARDWARE_ENDSTOP_X false
#define ENDSTOP_PULLUP_Y_MIN true
#define ENDSTOP_Y_MIN_INVERTING false
#define MIN_HARDWARE_ENDSTOP_Y false
#define ENDSTOP_PULLUP_Z_MIN true
#define ENDSTOP_Z_MIN_INVERTING true
#define MIN_HARDWARE_ENDSTOP_Z false
#define ENDSTOP_PULLUP_X_MAX true
#define ENDSTOP_X_MAX_INVERTING false
#define MAX_HARDWARE_ENDSTOP_X true
#define ENDSTOP_PULLUP_Y_MAX true
#define ENDSTOP_Y_MAX_INVERTING false
#define MAX_HARDWARE_ENDSTOP_Y true
#define ENDSTOP_PULLUP_Z_MAX true
#define ENDSTOP_Z_MAX_INVERTING false
#define MAX_HARDWARE_ENDSTOP_Z true
#define max_software_endstop_r true
#define min_software_endstop_x false
#define min_software_endstop_y false
#define min_software_endstop_z false
#define max_software_endstop_x true
#define max_software_endstop_y true
#define max_software_endstop_z true
#define ENDSTOP_X_BACK_MOVE 5
#define ENDSTOP_Y_BACK_MOVE 5
#define ENDSTOP_Z_BACK_MOVE 5
#define ENDSTOP_X_RETEST_REDUCTION_FACTOR 2
#define ENDSTOP_Y_RETEST_REDUCTION_FACTOR 2
#define ENDSTOP_Z_RETEST_REDUCTION_FACTOR 2
#define ENDSTOP_X_BACK_ON_HOME 5
#define ENDSTOP_Y_BACK_ON_HOME 5
#define ENDSTOP_Z_BACK_ON_HOME 5
#define ALWAYS_CHECK_ENDSTOPS 1
// ################# XYZ movements ###################
#define X_ENABLE_ON 0
#define Y_ENABLE_ON 0
#define Z_ENABLE_ON 0
#define DISABLE_X 0
#define DISABLE_Y 0
#define DISABLE_Z 0
#define DISABLE_E 0
// ###### Inverting Axis Settings for Orion/Rostock MAX v2/DropLit
#define X_HOME_DIR 1
#define Y_HOME_DIR 1
#define Z_HOME_DIR 1
#define X_MAX_LENGTH 250
#define Y_MAX_LENGTH 250
#define X_MIN_POS 0
#define Y_MIN_POS 0
#define Z_MIN_POS 0
// ### Distortion correction for bed mapping ###
#define DISTORTION_CORRECTION 0
#define DISTORTION_CORRECTION_POINTS 5
#define DISTORTION_CORRECTION_R 100
#define DISTORTION_PERMANENT 1
#define DISTORTION_UPDATE_FREQUENCY 15
#define DISTORTION_START_DEGRADE 0.5
#define DISTORTION_END_HEIGHT 1
#define DISTORTION_EXTRAPOLATE_CORNERS 0
// ##########################################################################################
// ## Movement settings ##
// ##########################################################################################
#define FEATURE_BABYSTEPPING 1
#define BABYSTEP_MULTIPLICATOR 1
#define DELTA_SEGMENTS_PER_SECOND_PRINT 200 // Move accurate setting for print moves
#define DELTA_SEGMENTS_PER_SECOND_MOVE 80 // Less accurate setting for other moves
#define DELTA_ALPHA_A 210
#define DELTA_ALPHA_B 330
#define DELTA_ALPHA_C 90
#define DELTA_RADIUS_CORRECTION_A 0
#define DELTA_RADIUS_CORRECTION_B 0
#define DELTA_RADIUS_CORRECTION_C 0
#define DELTA_DIAGONAL_CORRECTION_A 0
#define DELTA_DIAGONAL_CORRECTION_B 0
#define DELTA_DIAGONAL_CORRECTION_C 0
#define DELTA_HOME_ON_POWER 0
#define STEP_COUNTER
#define DELTA_X_ENDSTOP_OFFSET_STEPS 0
#define DELTA_Y_ENDSTOP_OFFSET_STEPS 0
#define DELTA_Z_ENDSTOP_OFFSET_STEPS 0
#define DELTA_FLOOR_SAFETY_MARGIN_MM 15
#define HOMING_ORDER HOME_ORDER_ZXY
#define ENABLE_BACKLASH_COMPENSATION 0
#define X_BACKLASH 0
#define Y_BACKLASH 0
#define Z_BACKLASH 0
#define RAMP_ACCELERATION 1
#define STEPPER_HIGH_DELAY 0
#define DIRECTION_DELAY 0
#define STEP_DOUBLER_FREQUENCY 12000
#define ALLOW_QUADSTEPPING 1
#define DOUBLE_STEP_DELAY 1 // time in microseconds
#define MAX_HALFSTEP_INTERVAL 1999
#define PRINTLINE_CACHE_SIZE 16
#define MOVE_CACHE_LOW 10
#define LOW_TICKS_PER_MOVE 250000
#define FEATURE_TWO_XSTEPPER 0
#define X2_STEP_PIN ORIG_E1_STEP_PIN
#define X2_DIR_PIN ORIG_E1_DIR_PIN
#define X2_ENABLE_PIN ORIG_E1_ENABLE_PIN
#define FEATURE_TWO_YSTEPPER 0
#define Y2_STEP_PIN ORIG_E1_STEP_PIN
#define Y2_DIR_PIN ORIG_E1_DIR_PIN
#define Y2_ENABLE_PIN ORIG_E1_ENABLE_PIN
#define FEATURE_TWO_ZSTEPPER 0
#define Z2_STEP_PIN ORIG_E1_STEP_PIN
#define Z2_DIR_PIN ORIG_E1_DIR_PIN
#define Z2_ENABLE_PIN ORIG_E1_ENABLE_PIN
#define FEATURE_DITTO_PRINTING 0
#define USE_ADVANCE 1
#define ENABLE_QUADRATIC_ADVANCE 0
// ################# Misc. settings ##################
#define BAUDRATE 250000
#define ENABLE_POWER_ON_STARTUP 1
#define POWER_INVERTING 0
#define KILL_METHOD 1
#define GCODE_BUFFER_SIZE 2
#define ACK_WITH_LINENUMBER 0
#define WAITING_IDENTIFIER "wait"
#define ECHO_ON_EXECUTE 1
#define EEPROM_MODE 1
/* ======== Servos =======
Control the servos with
M340 P<servoId> S<pulseInUS> / ServoID = 0..3 pulseInUs = 500..2500
Servos are controlled by a pulse width normally between 500 and 2500 with 1500ms in center position. 0 turns servo off.
WARNING: Servos can draw a considerable amount of current. Make sure your system can handle this or you may risk your hardware!
*/
#define FEATURE_SERVO 0
#define SERVO0_PIN -1
#define SERVO1_PIN -1
#define SERVO2_PIN -1
#define SERVO3_PIN -1
/* #################### Z-Probe configuration and Settings #####################
These will change machine to machine, be sure to have the correct machine selected in the top of this config file
*/
// 301 = RAMBO 302 = MINI_RAMBO
#if MOTHERBOARD == 301
#define Z_PROBE_PIN 4
#elif MOTHERBOARD == 302
#define Z_PROBE_PIN 16
#endif
#define Z_PROBE_TOLERANCE .1
#define Z_PROBE_MAX_SENSITIVITY 40
#define FEATURE_AXISCOMP 0
#define AXISCOMP_TANXY 0
#define AXISCOMP_TANYZ 0
#define AXISCOMP_TANXZ 0
// ############## SD Card Settings #########################
#define SD_EXTENDED_DIR 1 /** Show extended directory including file length. Don't use this with Pronterface! */
#define SD_RUN_ON_STOP ""
#define SD_STOP_HEATER_AND_MOTORS_ON_STOP 1
#define ARC_SUPPORT 0
#define FEATURE_MEMORY_POSITION 1
#define FEATURE_CHECKSUM_FORCED 0
#define FEATURE_FAN_CONTROL 1
#define UI_LANGUAGE 1000 // 1000 = User defined language in v92+
#define UI_PRINTER_COMPANY "SeeMeCNC"
#define UI_ENCODER_DIR 1 // 0 normal 1 inverts encoder direction
#define UI_PAGES_DURATION 4000
#define UI_ANIMATION 0
#define UI_SPEEDDEPENDENT_POSITIONING 1
#define UI_DISABLE_AUTO_PAGESWITCH 1
#define UI_AUTORETURN_TO_MENU_AFTER 600000
#define FEATURE_UI_KEYS 0
#define UI_ENCODER_SPEED 2
#define UI_KEY_BOUNCETIME 10
#define UI_KEY_FIRST_REPEAT 500
#define UI_KEY_REDUCE_REPEAT 50
#define UI_KEY_MIN_REPEAT 50
#define FEATURE_BEEPER 1
#define CASE_LIGHTS_PIN -1
#define CASE_LIGHT_DEFAULT_ON 1
#define UI_START_SCREEN_DELAY 1000
/**
Beeper sound definitions for short beeps during key actions
and longer beeps for important actions.
Parameter is delay in microseconds and the secons is the number of repetitions.
Values must be in range 1..255
*/
#define BEEPER_SHORT_SEQUENCE 1,1
#define BEEPER_LONG_SEQUENCE 32,4
#define UI_SET_PRESET_HEATED_BED_TEMP_PLA 60
#define UI_SET_PRESET_EXTRUDER_TEMP_PLA 180
#define UI_SET_PRESET_HEATED_BED_TEMP_ABS 80
#define UI_SET_PRESET_EXTRUDER_TEMP_ABS 200
#define UI_SET_MIN_HEATED_BED_TEMP 30
#define UI_SET_MAX_HEATED_BED_TEMP 120
#define UI_SET_MIN_EXTRUDER_TEMP 150
#define UI_SET_EXTRUDER_FEEDRATE 2
#define UI_SET_EXTRUDER_RETRACT_DISTANCE 3
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,537 @@
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Repetier-Firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _EEPROM_H
#define _EEPROM_H
// Id to distinguish version changes
#define EEPROM_PROTOCOL_VERSION 12
/** Where to start with our datablock in memory. Can be moved if you
have problems with other modules using the eeprom */
#define EPR_MAGIC_BYTE 0
#define EPR_ACCELERATION_TYPE 1
#define EPR_XAXIS_STEPS_PER_MM 3
#define EPR_YAXIS_STEPS_PER_MM 7
#define EPR_ZAXIS_STEPS_PER_MM 11
#define EPR_X_MAX_FEEDRATE 15
#define EPR_Y_MAX_FEEDRATE 19
#define EPR_Z_MAX_FEEDRATE 23
#define EPR_X_HOMING_FEEDRATE 27
#define EPR_Y_HOMING_FEEDRATE 31
#define EPR_Z_HOMING_FEEDRATE 35
#define EPR_MAX_JERK 39
//#define EPR_OPS_MIN_DISTANCE 43
#define EPR_ADVANCED_USER 43
#define EPR_MAX_ZJERK 47
#define EPR_X_MAX_ACCEL 51
#define EPR_Y_MAX_ACCEL 55
#define EPR_Z_MAX_ACCEL 59
#define EPR_X_MAX_TRAVEL_ACCEL 63
#define EPR_Y_MAX_TRAVEL_ACCEL 67
#define EPR_Z_MAX_TRAVEL_ACCEL 71
#define EPR_BAUDRATE 75
#define EPR_MAX_INACTIVE_TIME 79
#define EPR_STEPPER_INACTIVE_TIME 83
//#define EPR_OPS_RETRACT_DISTANCE 87
//#define EPR_OPS_RETRACT_BACKLASH 91
#define EPR_EXTRUDER_SPEED 95
//#define EPR_OPS_MOVE_AFTER 99
//#define EPR_OPS_MODE 103
#define EPR_INTEGRITY_BYTE 104 // Here the xored sum over eeprom is stored
#define EPR_VERSION 105 // Version id for updates in EEPROM storage
#define EPR_BED_HEAT_MANAGER 106
#define EPR_BED_DRIVE_MAX 107
#define EPR_BED_PID_PGAIN 108
#define EPR_BED_PID_IGAIN 112
#define EPR_BED_PID_DGAIN 116
#define EPR_BED_PID_MAX 120
#define EPR_BED_DRIVE_MIN 124
#define EPR_PRINTING_TIME 125 // Time in seconds printing
#define EPR_PRINTING_DISTANCE 129 // Filament length printed
#define EPR_X_HOME_OFFSET 133
#define EPR_Y_HOME_OFFSET 137
#define EPR_Z_HOME_OFFSET 141
#define EPR_X_LENGTH 145
#define EPR_Y_LENGTH 149
#define EPR_Z_LENGTH 153
#define EPR_BACKLASH_X 157
#define EPR_BACKLASH_Y 161
#define EPR_BACKLASH_Z 165
#define EPR_Z_PROBE_X_OFFSET 800
#define EPR_Z_PROBE_Y_OFFSET 804
#define EPR_Z_PROBE_HEIGHT 808
#define EPR_Z_PROBE_SPEED 812
#define EPR_Z_PROBE_X1 816
#define EPR_Z_PROBE_Y1 820
#define EPR_Z_PROBE_X2 824
#define EPR_Z_PROBE_Y2 828
#define EPR_Z_PROBE_X3 832
#define EPR_Z_PROBE_Y3 836
#define EPR_Z_PROBE_XY_SPEED 840
#define EPR_AUTOLEVEL_MATRIX 844
#define EPR_AUTOLEVEL_ACTIVE 880
#define EPR_DELTA_DIAGONAL_ROD_LENGTH 881
#define EPR_DELTA_HORIZONTAL_RADIUS 885
#define EPR_DELTA_SEGMENTS_PER_SECOND_PRINT 889
#define EPR_DELTA_SEGMENTS_PER_SECOND_MOVE 891
#define EPR_DELTA_TOWERX_OFFSET_STEPS 893
#define EPR_DELTA_TOWERY_OFFSET_STEPS 895
#define EPR_DELTA_TOWERZ_OFFSET_STEPS 897
#define EPR_DELTA_ALPHA_A 901
#define EPR_DELTA_ALPHA_B 905
#define EPR_DELTA_ALPHA_C 909
#define EPR_DELTA_RADIUS_CORR_A 913
#define EPR_DELTA_RADIUS_CORR_B 917
#define EPR_DELTA_RADIUS_CORR_C 921
#define EPR_DELTA_MAX_RADIUS 925
#define EPR_Z_PROBE_BED_DISTANCE 929
#define EPR_DELTA_DIAGONAL_CORRECTION_A 933
#define EPR_DELTA_DIAGONAL_CORRECTION_B 937
#define EPR_DELTA_DIAGONAL_CORRECTION_C 941
#define EPR_TOUCHSCREEN 946 // - 975 = 30 byte for touchscreen calibration data
// Axis compensation
#define EPR_AXISCOMP_TANXY 976
#define EPR_AXISCOMP_TANYZ 980
#define EPR_AXISCOMP_TANXZ 984
#define EPR_DISTORTION_CORRECTION_ENABLED 988
#define EPR_RETRACTION_LENGTH 992
#define EPR_RETRACTION_LONG_LENGTH 996
#define EPR_RETRACTION_SPEED 1000
#define EPR_RETRACTION_Z_LIFT 1004
#define EPR_RETRACTION_UNDO_EXTRA_LENGTH 1008
#define EPR_RETRACTION_UNDO_EXTRA_LONG_LENGTH 1012
#define EPR_RETRACTION_UNDO_SPEED 1016
#define EPR_AUTORETRACT_ENABLED 1018
#if EEPROM_MODE != 0
#define EEPROM_FLOAT(x) HAL::eprGetFloat(EPR_##x)
#define EEPROM_INT32(x) HAL::eprGetInt32(EPR_##x)
#define EEPROM_BYTE(x) HAL::eprGetByte(EPR_##x)
#define EEPROM_SET_BYTE(x,val) HAL::eprSetByte(EPR_##x,val)
#else
#define EEPROM_FLOAT(x) (x)
#define EEPROM_INT32(x) (x)
#define EEPROM_BYTE(x) (x)
#define EEPROM_SET_BYTE(x,val)
#endif
#define EEPROM_EXTRUDER_OFFSET 200
// bytes per extruder needed, leave some space for future development
#define EEPROM_EXTRUDER_LENGTH 100
// Extruder positions relative to extruder start
#define EPR_EXTRUDER_STEPS_PER_MM 0
#define EPR_EXTRUDER_MAX_FEEDRATE 4
// Feedrate from halted extruder in mm/s
#define EPR_EXTRUDER_MAX_START_FEEDRATE 8
// Acceleration in mm/s^2
#define EPR_EXTRUDER_MAX_ACCELERATION 12
#define EPR_EXTRUDER_HEAT_MANAGER 16
#define EPR_EXTRUDER_DRIVE_MAX 17
#define EPR_EXTRUDER_PID_PGAIN 18
#define EPR_EXTRUDER_PID_IGAIN 22
#define EPR_EXTRUDER_PID_DGAIN 26
#define EPR_EXTRUDER_DEADTIME EPR_EXTRUDER_PID_PGAIN
#define EPR_EXTRUDER_PID_MAX 30
#define EPR_EXTRUDER_X_OFFSET 31
#define EPR_EXTRUDER_Y_OFFSET 35
#define EPR_EXTRUDER_WATCH_PERIOD 39
#define EPR_EXTRUDER_ADVANCE_K 41
#define EPR_EXTRUDER_DRIVE_MIN 45
#define EPR_EXTRUDER_ADVANCE_L 46
#define EPR_EXTRUDER_WAIT_RETRACT_TEMP 50
#define EPR_EXTRUDER_WAIT_RETRACT_UNITS 52
#define EPR_EXTRUDER_COOLER_SPEED 54
// 55-57 free for byte sized parameter
#define EPR_EXTRUDER_MIXING_RATIOS 58 // 16*2 byte ratios = 32 byte -> end = 89
#ifndef Z_PROBE_BED_DISTANCE
#define Z_PROBE_BED_DISTANCE 5.0
#endif
class EEPROM
{
#if EEPROM_MODE != 0
static void writeExtruderPrefix(uint pos);
static void writeFloat(uint pos,PGM_P text,uint8_t digits=3);
static void writeLong(uint pos,PGM_P text);
static void writeInt(uint pos,PGM_P text);
static void writeByte(uint pos,PGM_P text);
public:
static uint8_t computeChecksum();
static void updateChecksum();
#endif
public:
static void init();
static void initBaudrate();
static void storeDataIntoEEPROM(uint8_t corrupted=0);
static void readDataFromEEPROM();
static void restoreEEPROMSettingsFromConfiguration();
static void writeSettings();
static void update(GCode *com);
static void updatePrinterUsage();
static inline float zProbeSpeed() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_Z_PROBE_SPEED);
#else
return Z_PROBE_SPEED;
#endif
}
static inline float zProbeXYSpeed() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_Z_PROBE_XY_SPEED);
#else
return Z_PROBE_XY_SPEED;
#endif
}
static inline float zProbeXOffset() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_Z_PROBE_X_OFFSET);
#else
return Z_PROBE_X_OFFSET;
#endif
}
static inline float zProbeYOffset() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_Z_PROBE_Y_OFFSET);
#else
return Z_PROBE_Y_OFFSET;
#endif
}
static inline float zProbeHeight() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_Z_PROBE_HEIGHT);
#else
return Z_PROBE_HEIGHT;
#endif
}
static inline float zProbeX1() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_Z_PROBE_X1);
#else
return Z_PROBE_X1;
#endif
}
static inline float zProbeY1() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_Z_PROBE_Y1);
#else
return Z_PROBE_Y1;
#endif
}
static inline float zProbeX2() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_Z_PROBE_X2);
#else
return Z_PROBE_X2;
#endif
}
static inline float zProbeY2() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_Z_PROBE_Y2);
#else
return Z_PROBE_Y2;
#endif
}
static inline float zProbeX3() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_Z_PROBE_X3);
#else
return Z_PROBE_X3;
#endif
}
static inline float zProbeY3() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_Z_PROBE_Y3);
#else
return Z_PROBE_Y3;
#endif
}
static inline float zProbeBedDistance() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_Z_PROBE_BED_DISTANCE);
#else
return Z_PROBE_BED_DISTANCE;
#endif
}
static inline float axisCompTanXY() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_AXISCOMP_TANXY);
#else
return AXISCOMP_TANXY;
#endif
}
static inline float axisCompTanYZ() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_AXISCOMP_TANYZ);
#else
return AXISCOMP_TANYZ;
#endif
}
static inline float axisCompTanXZ() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_AXISCOMP_TANXZ);
#else
return AXISCOMP_TANXZ;
#endif
}
#if NONLINEAR_SYSTEM
static inline int16_t deltaSegmentsPerSecondMove() {
#if EEPROM_MODE != 0
return HAL::eprGetInt16(EPR_DELTA_SEGMENTS_PER_SECOND_MOVE);
#else
return DELTA_SEGMENTS_PER_SECOND_MOVE;
#endif
}
static inline float deltaDiagonalRodLength() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_DELTA_DIAGONAL_ROD_LENGTH);
#else
return DELTA_DIAGONAL_ROD;
#endif
}
static inline int16_t deltaSegmentsPerSecondPrint() {
#if EEPROM_MODE != 0
return HAL::eprGetInt16(EPR_DELTA_SEGMENTS_PER_SECOND_PRINT);
#else
return DELTA_SEGMENTS_PER_SECOND_PRINT;
#endif
}
#endif
#if DRIVE_SYSTEM == DELTA
static inline float deltaHorizontalRadius() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_DELTA_HORIZONTAL_RADIUS);
#else
return ROD_RADIUS;
#endif
}
// Advanced Menu
static inline int16_t isAdvanced(){
#if EEPROM_MODE !=0
return HAL::eprGetInt16(EPR_ADVANCED_USER);
#else
return ADVANCED_USER;
#endif
}
static inline void setIsAdvanced(int16_t advmenu) {
#if EEPROM_MODE != 0
HAL::eprSetInt16(EPR_ADVANCED_USER,advmenu);
uint8_t newcheck = computeChecksum();
if(newcheck != HAL::eprGetByte(EPR_INTEGRITY_BYTE))
HAL::eprSetByte(EPR_INTEGRITY_BYTE,newcheck);
#endif
}
static inline int16_t deltaTowerXOffsetSteps() {
#if EEPROM_MODE != 0
return HAL::eprGetInt16(EPR_DELTA_TOWERX_OFFSET_STEPS);
#else
return DELTA_X_ENDSTOP_OFFSET_STEPS;
#endif
}
static inline int16_t deltaTowerYOffsetSteps() {
#if EEPROM_MODE != 0
return HAL::eprGetInt16(EPR_DELTA_TOWERY_OFFSET_STEPS);
#else
return DELTA_Y_ENDSTOP_OFFSET_STEPS;
#endif
}
static inline int16_t deltaTowerZOffsetSteps() {
#if EEPROM_MODE != 0
return HAL::eprGetInt16(EPR_DELTA_TOWERZ_OFFSET_STEPS);
#else
return DELTA_Z_ENDSTOP_OFFSET_STEPS;
#endif
}
static inline void setRodRadius(float mm) {
#if DRIVE_SYSTEM == DELTA
Printer::radius0=mm;
Printer::updateDerivedParameter();
#if EEPROM_MODE != 0
//This is an odd situation, the radius can only be changed if eeprom is on.
// The radius is not saved to printer variablke now, it is all derived parameters of
// fetching the radius, which if EEProm is off returns the Configuration constant.
HAL::eprSetFloat(EPR_DELTA_HORIZONTAL_RADIUS, mm);
Com::printFLN(PSTR("Rod Radius set to: "),mm,3);
uint8_t newcheck = computeChecksum();
if(newcheck!=HAL::eprGetByte(EPR_INTEGRITY_BYTE))
HAL::eprSetByte(EPR_INTEGRITY_BYTE,newcheck);
#endif
#endif
}
static inline void incrementRodRadius(float mm) {
setRodRadius(mm + deltaHorizontalRadius());
}
static inline void setTowerXFloor(float newZ) {
#if DRIVE_SYSTEM == DELTA
Printer::xMin = newZ;
Printer::updateDerivedParameter();
Com::printFLN(PSTR("X (A) tower floor set to: "),Printer::xMin,3);
#if EEPROM_MODE != 0
HAL::eprSetFloat(EPR_X_HOME_OFFSET,Printer::xMin);
uint8_t newcheck = computeChecksum();
if(newcheck!=HAL::eprGetByte(EPR_INTEGRITY_BYTE))
HAL::eprSetByte(EPR_INTEGRITY_BYTE,newcheck);
#endif
#endif
}
static inline void setTowerYFloor(float newZ) {
#if DRIVE_SYSTEM == DELTA
Printer::yMin = newZ;
Printer::updateDerivedParameter();
Com::printFLN(PSTR("Y (B) tower floor set to: "), Printer::yMin, 3);
#if EEPROM_MODE != 0
HAL::eprSetFloat(EPR_Y_HOME_OFFSET,Printer::yMin);
uint8_t newcheck = computeChecksum();
if(newcheck != HAL::eprGetByte(EPR_INTEGRITY_BYTE))
HAL::eprSetByte(EPR_INTEGRITY_BYTE,newcheck);
#endif
#endif
}
static inline void setTowerZFloor(float newZ) {
#if DRIVE_SYSTEM == DELTA
Printer::zMin = newZ;
Printer::updateDerivedParameter();
Com::printFLN(PSTR("Z (C) tower floor set to: "), Printer::zMin, 3);
#if EEPROM_MODE != 0
HAL::eprSetFloat(EPR_Z_HOME_OFFSET,Printer::zMin);
uint8_t newcheck = computeChecksum();
if(newcheck != HAL::eprGetByte(EPR_INTEGRITY_BYTE))
HAL::eprSetByte(EPR_INTEGRITY_BYTE,newcheck);
#endif
#endif
}
static inline void setDeltaTowerXOffsetSteps(int16_t steps) {
#if EEPROM_MODE != 0
HAL::eprSetInt16(EPR_DELTA_TOWERX_OFFSET_STEPS,steps);
uint8_t newcheck = computeChecksum();
if(newcheck != HAL::eprGetByte(EPR_INTEGRITY_BYTE))
HAL::eprSetByte(EPR_INTEGRITY_BYTE,newcheck);
#endif
}
static inline void setDeltaTowerYOffsetSteps(int16_t steps) {
#if EEPROM_MODE != 0
HAL::eprSetInt16(EPR_DELTA_TOWERY_OFFSET_STEPS,steps);
uint8_t newcheck = computeChecksum();
if(newcheck != HAL::eprGetByte(EPR_INTEGRITY_BYTE))
HAL::eprSetByte(EPR_INTEGRITY_BYTE,newcheck);
#endif
}
static inline void setDeltaTowerZOffsetSteps(int16_t steps) {
#if EEPROM_MODE != 0
HAL::eprSetInt16(EPR_DELTA_TOWERZ_OFFSET_STEPS,steps);
uint8_t newcheck = computeChecksum();
if(newcheck != HAL::eprGetByte(EPR_INTEGRITY_BYTE))
HAL::eprSetByte(EPR_INTEGRITY_BYTE,newcheck);
#endif
}
static inline float deltaAlphaA() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_DELTA_ALPHA_A);
#else
return DELTA_ALPHA_A;
#endif
}
static inline float deltaAlphaB() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_DELTA_ALPHA_B);
#else
return DELTA_ALPHA_B;
#endif
}
static inline float deltaAlphaC() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_DELTA_ALPHA_C);
#else
return DELTA_ALPHA_C;
#endif
}
static inline float deltaRadiusCorrectionA() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_DELTA_RADIUS_CORR_A);
#else
return DELTA_RADIUS_CORRECTION_A;
#endif
}
static inline float deltaRadiusCorrectionB() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_DELTA_RADIUS_CORR_B);
#else
return DELTA_RADIUS_CORRECTION_B;
#endif
}
static inline float deltaRadiusCorrectionC() {
#if EEPROM_MODE != 0
return HAL::eprGetFloat(EPR_DELTA_RADIUS_CORR_C);
#else
return DELTA_RADIUS_CORRECTION_C;
#endif
}
static inline float deltaDiagonalCorrectionA() {
return EEPROM_FLOAT(DELTA_DIAGONAL_CORRECTION_A);
}
static inline float deltaDiagonalCorrectionB() {
return EEPROM_FLOAT(DELTA_DIAGONAL_CORRECTION_B);
}
static inline float deltaDiagonalCorrectionC() {
return EEPROM_FLOAT(DELTA_DIAGONAL_CORRECTION_C);
}
static inline float deltaMaxRadius() {
return EEPROM_FLOAT(DELTA_MAX_RADIUS);
}
#endif
static void initalizeUncached();
#if MIXING_EXTRUDER
static void storeMixingRatios(bool updateChecksums = true);
static void readMixingRatios();
static void restoreMixingRatios();
#endif
static void setZCorrection(int32_t c,int index);
static inline int32_t getZCorrection(int index) {
return HAL::eprGetInt32(2048 + (index << 2));
}
static inline void setZCorrectionEnabled(int8_t on) {
#if EEPROM_MODE != 0
if(isZCorrectionEnabled() == on) return;
HAL::eprSetInt16(EPR_DISTORTION_CORRECTION_ENABLED, on);
uint8_t newcheck = computeChecksum();
if(newcheck != HAL::eprGetByte(EPR_INTEGRITY_BYTE))
HAL::eprSetByte(EPR_INTEGRITY_BYTE, newcheck);
#endif
}
static inline int8_t isZCorrectionEnabled() {
#if EEPROM_MODE != 0
return HAL::eprGetByte(EPR_DISTORTION_CORRECTION_ENABLED);
#else
return 0;
#endif
}
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,459 @@
#ifndef EXTRUDER_H_INCLUDED
#define EXTRUDER_H_INCLUDED
#define CELSIUS_EXTRA_BITS 3
#define VIRTUAL_EXTRUDER 16 // don't change this to more then 16 without modifying the eeprom positions
//#if TEMP_PID
//extern uint8_t current_extruder_out;
//#endif
// Updates the temperature of all extruders and heated bed if it's time.
// Toggels the heater power if necessary.
extern bool reportTempsensorError(); ///< Report defect sensors
extern uint8_t manageMonitor;
#define HTR_OFF 0
#define HTR_PID 1
#define HTR_SLOWBANG 2
#define HTR_DEADTIME 3
#define TEMPERATURE_CONTROLLER_FLAG_ALARM 1
#define TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_FULL 2 //< Full heating enabled
#define TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_HOLD 4 //< Holding target temperature
/** TemperatureController manages one heater-temperature sensore loop. You can have up to
4 loops allowing pid/bang bang for up to 3 extruder and the heated bed.
*/
class TemperatureController
{
public:
uint8_t pwmIndex; ///< pwm index for output control. 0-2 = Extruder, 3 = Fan, 4 = Heated Bed
uint8_t sensorType; ///< Type of temperature sensor.
uint8_t sensorPin; ///< Pin to read extruder temperature.
int16_t currentTemperature; ///< Currenttemperature value read from sensor.
int16_t targetTemperature; ///< Target temperature value in units of sensor.
float currentTemperatureC; ///< Current temperature in degC.
float targetTemperatureC; ///< Target temperature in degC.
uint32_t lastTemperatureUpdate; ///< Time in millis of the last temperature update.
int8_t heatManager; ///< How is temperature controled. 0 = on/off, 1 = PID-Control, 3 = deat time control
#if TEMP_PID
float tempIState; ///< Temp. var. for PID computation.
uint8_t pidDriveMax; ///< Used for windup in PID calculation.
uint8_t pidDriveMin; ///< Used for windup in PID calculation.
#define deadTime pidPGain
// deadTime is logically different value but physically overlays pidPGain for saving space
float pidPGain; ///< Pgain (proportional gain) for PID temperature control [0,01 Units].
float pidIGain; ///< Igain (integral) for PID temperature control [0,01 Units].
float pidDGain; ///< Dgain (damping) for PID temperature control [0,01 Units].
uint8_t pidMax; ///< Maximum PWM value, the heater should be set.
float tempIStateLimitMax;
float tempIStateLimitMin;
uint8_t tempPointer;
float tempArray[4];
#endif
uint8_t flags;
millis_t lastDecoupleTest; ///< Last time of decoupling sensor-heater test
float lastDecoupleTemp; ///< Temperature on last test
millis_t decoupleTestPeriod; ///< Time between setting and testing decoupling.
void setTargetTemperature(float target);
void updateCurrentTemperature();
void updateTempControlVars();
inline bool isAlarm()
{
return flags & TEMPERATURE_CONTROLLER_FLAG_ALARM;
}
inline void setAlarm(bool on)
{
if(on) flags |= TEMPERATURE_CONTROLLER_FLAG_ALARM;
else flags &= ~TEMPERATURE_CONTROLLER_FLAG_ALARM;
}
inline bool isDecoupleFull()
{
return flags & TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_FULL;
}
inline bool isDecoupleFullOrHold()
{
return flags & (TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_FULL | TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_HOLD);
}
inline void setDecoupleFull(bool on)
{
flags &= ~(TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_FULL | TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_HOLD);
if(on) flags |= TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_FULL;
}
inline bool isDecoupleHold()
{
return flags & TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_HOLD;
}
inline void setDecoupleHold(bool on)
{
flags &= ~(TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_FULL | TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_HOLD);
if(on) flags |= TEMPERATURE_CONTROLLER_FLAG_DECOUPLE_HOLD;
}
inline void startFullDecouple(millis_t &t)
{
if(isDecoupleFull()) return;
lastDecoupleTest = t;
lastDecoupleTemp = currentTemperatureC;
setDecoupleFull(true);
}
inline void startHoldDecouple(millis_t &t)
{
if(isDecoupleHold()) return;
if(fabs(currentTemperatureC - targetTemperatureC) + 1 > DECOUPLING_TEST_MAX_HOLD_VARIANCE) return;
lastDecoupleTest = t;
lastDecoupleTemp = targetTemperatureC;
setDecoupleHold(true);
}
inline void stopDecouple()
{
setDecoupleFull(false);
}
#if TEMP_PID
void autotunePID(float temp,uint8_t controllerId,bool storeResult);
#endif
};
class Extruder;
extern Extruder extruder[];
#define EXTRUDER_FLAG_RETRACTED 1
/** \brief Data to drive one extruder.
This structure contains all definitions for an extruder and all
current state variables, like current temperature, feeder position etc.
*/
class Extruder // Size: 12*1 Byte+12*4 Byte+4*2Byte = 68 Byte
{
public:
static Extruder *current;
#if FEATURE_DITTO_PRINTING
static uint8_t dittoMode;
#endif
#if MIXING_EXTRUDER > 0
static int mixingS; ///< Sum of all weights
static uint8_t mixingDir; ///< Direction flag
#endif
uint8_t id;
int32_t xOffset;
int32_t yOffset;
float stepsPerMM; ///< Steps per mm.
int8_t enablePin; ///< Pin to enable extruder stepper motor.
// uint8_t directionPin; ///< Pin number to assign the direction.
// uint8_t stepPin; ///< Pin number for a step.
uint8_t enableOn;
// uint8_t invertDir; ///< 1 if the direction of the extruder should be inverted.
float maxFeedrate; ///< Maximum feedrate in mm/s.
float maxAcceleration; ///< Maximum acceleration in mm/s^2.
float maxStartFeedrate; ///< Maximum start feedrate in mm/s.
int32_t extrudePosition; ///< Current extruder position in steps.
int16_t watchPeriod; ///< Time in seconds, a M109 command will wait to stabalize temperature
int16_t waitRetractTemperature; ///< Temperature to retract the filament when waiting for heatup
int16_t waitRetractUnits; ///< Units to retract the filament when waiting for heatup
#if USE_ADVANCE
#if ENABLE_QUADRATIC_ADVANCE
float advanceK; ///< Koefficient for advance algorithm. 0 = off
#endif
float advanceL;
int16_t advanceBacklash;
#endif // USE_ADVANCE
#if MIXING_EXTRUDER > 0
int mixingW; ///< Weight for this extruder when mixing steps
int mixingE; ///< Cumulated error for this step.
int virtualWeights[VIRTUAL_EXTRUDER]; // Virtual extruder weights
#endif // MIXING_EXTRUDER > 0
TemperatureController tempControl;
const char * PROGMEM selectCommands;
const char * PROGMEM deselectCommands;
uint8_t coolerSpeed; ///< Speed to use when enabled
uint8_t coolerPWM; ///< current PWM setting
float diameter;
uint8_t flags;
#if MIXING_EXTRUDER > 0
static void setMixingWeight(uint8_t extr,int weight);
static void step();
static void unstep();
static void setDirection(uint8_t dir);
static void enable();
#else
/** \brief Sends the high-signal to the stepper for next extruder step.
Call this function only, if interrupts are disabled.
*/
static inline void step()
{
#if NUM_EXTRUDER==1
WRITE(EXT0_STEP_PIN,HIGH);
#else
switch(Extruder::current->id)
{
case 0:
#if NUM_EXTRUDER>0
WRITE(EXT0_STEP_PIN,HIGH);
#if FEATURE_DITTO_PRINTING
if(Extruder::dittoMode)
{
WRITE(EXT1_STEP_PIN,HIGH);
#if NUM_EXTRUDER > 2
if(Extruder::dittoMode > 1)
{
WRITE(EXT2_STEP_PIN,HIGH);
}
#endif
#if NUM_EXTRUDER > 3
if(Extruder::dittoMode > 2)
{
WRITE(EXT3_STEP_PIN,HIGH);
}
#endif
}
#endif
#endif
break;
#if defined(EXT1_STEP_PIN) && NUM_EXTRUDER>1
case 1:
WRITE(EXT1_STEP_PIN,HIGH);
break;
#endif
#if defined(EXT2_STEP_PIN) && NUM_EXTRUDER>2
case 2:
WRITE(EXT2_STEP_PIN,HIGH);
break;
#endif
#if defined(EXT3_STEP_PIN) && NUM_EXTRUDER>3
case 3:
WRITE(EXT3_STEP_PIN,HIGH);
break;
#endif
#if defined(EXT4_STEP_PIN) && NUM_EXTRUDER>4
case 4:
WRITE(EXT4_STEP_PIN,HIGH);
break;
#endif
#if defined(EXT5_STEP_PIN) && NUM_EXTRUDER>5
case 5:
WRITE(EXT5_STEP_PIN,HIGH);
break;
#endif
}
#endif
}
/** \brief Sets stepper signal to low for current extruder.
Call this function only, if interrupts are disabled.
*/
static inline void unstep()
{
#if NUM_EXTRUDER == 1
WRITE(EXT0_STEP_PIN,LOW);
#else
switch(Extruder::current->id)
{
case 0:
#if NUM_EXTRUDER > 0
WRITE(EXT0_STEP_PIN,LOW);
#if FEATURE_DITTO_PRINTING
if(Extruder::dittoMode)
{
WRITE(EXT1_STEP_PIN,LOW);
#if NUM_EXTRUDER > 2
if(Extruder::dittoMode > 1)
{
WRITE(EXT2_STEP_PIN,LOW);
}
#endif
#if NUM_EXTRUDER > 3
if(Extruder::dittoMode > 2)
{
WRITE(EXT3_STEP_PIN,LOW);
}
#endif // NUM_EXTRUDER > 3
}
#endif // FEATURE_DITTO_PRINTING
#endif // NUM_EXTRUDER > 0
break;
#if defined(EXT1_STEP_PIN) && NUM_EXTRUDER > 1
case 1:
WRITE(EXT1_STEP_PIN,LOW);
break;
#endif
#if defined(EXT2_STEP_PIN) && NUM_EXTRUDER > 2
case 2:
WRITE(EXT2_STEP_PIN,LOW);
break;
#endif
#if defined(EXT3_STEP_PIN) && NUM_EXTRUDER > 3
case 3:
WRITE(EXT3_STEP_PIN,LOW);
break;
#endif
#if defined(EXT4_STEP_PIN) && NUM_EXTRUDER > 4
case 4:
WRITE(EXT4_STEP_PIN,LOW);
break;
#endif
#if defined(EXT5_STEP_PIN) && NUM_EXTRUDER > 5
case 5:
WRITE(EXT5_STEP_PIN,LOW);
break;
#endif
}
#endif
}
/** \brief Activates the extruder stepper and sets the direction. */
static inline void setDirection(uint8_t dir)
{
#if MIXING_EXTRUDER > 0
mixingDir = dir;
#endif
#if NUM_EXTRUDER == 1
if(dir)
WRITE(EXT0_DIR_PIN, !EXT0_INVERSE);
else
WRITE(EXT0_DIR_PIN, EXT0_INVERSE);
#else
switch(Extruder::current->id)
{
#if NUM_EXTRUDER > 0
case 0:
if(dir)
WRITE(EXT0_DIR_PIN,!EXT0_INVERSE);
else
WRITE(EXT0_DIR_PIN,EXT0_INVERSE);
#if FEATURE_DITTO_PRINTING
if(Extruder::dittoMode)
{
if(dir)
WRITE(EXT1_DIR_PIN,!EXT1_INVERSE);
else
WRITE(EXT1_DIR_PIN,EXT1_INVERSE);
#if NUM_EXTRUDER > 2
if(Extruder::dittoMode > 1)
{
if(dir)
WRITE(EXT2_DIR_PIN,!EXT2_INVERSE);
else
WRITE(EXT2_DIR_PIN,EXT2_INVERSE);
}
#endif
#if NUM_EXTRUDER > 3
if(Extruder::dittoMode > 2)
{
if(dir)
WRITE(EXT3_DIR_PIN,!EXT3_INVERSE);
else
WRITE(EXT3_DIR_PIN,EXT3_INVERSE);
}
#endif
}
#endif
break;
#endif
#if defined(EXT1_DIR_PIN) && NUM_EXTRUDER > 1
case 1:
if(dir)
WRITE(EXT1_DIR_PIN,!EXT1_INVERSE);
else
WRITE(EXT1_DIR_PIN,EXT1_INVERSE);
break;
#endif
#if defined(EXT2_DIR_PIN) && NUM_EXTRUDER > 2
case 2:
if(dir)
WRITE(EXT2_DIR_PIN,!EXT2_INVERSE);
else
WRITE(EXT2_DIR_PIN,EXT2_INVERSE);
break;
#endif
#if defined(EXT3_DIR_PIN) && NUM_EXTRUDER > 3
case 3:
if(dir)
WRITE(EXT3_DIR_PIN,!EXT3_INVERSE);
else
WRITE(EXT3_DIR_PIN,EXT3_INVERSE);
break;
#endif
#if defined(EXT4_DIR_PIN) && NUM_EXTRUDER > 4
case 4:
if(dir)
WRITE(EXT4_DIR_PIN,!EXT4_INVERSE);
else
WRITE(EXT4_DIR_PIN,EXT4_INVERSE);
break;
#endif
#if defined(EXT5_DIR_PIN) && NUM_EXTRUDER > 5
case 5:
if(dir)
WRITE(EXT5_DIR_PIN,!EXT5_INVERSE);
else
WRITE(EXT5_DIR_PIN,EXT5_INVERSE);
break;
#endif
}
#endif
}
static inline void enable()
{
#if NUM_EXTRUDER == 1
#if EXT0_ENABLE_PIN > -1
WRITE(EXT0_ENABLE_PIN,EXT0_ENABLE_ON );
#endif
#else
if(Extruder::current->enablePin > -1)
digitalWrite(Extruder::current->enablePin,Extruder::current->enableOn);
#if FEATURE_DITTO_PRINTING
if(Extruder::dittoMode)
{
if(extruder[1].enablePin > -1)
digitalWrite(extruder[1].enablePin,extruder[1].enableOn);
#if NUM_EXTRUDER > 2
if(Extruder::dittoMode > 1 && extruder[2].enablePin > -1)
digitalWrite(extruder[2].enablePin,extruder[2].enableOn);
#endif
#if NUM_EXTRUDER > 3
if(Extruder::dittoMode > 2 && extruder[3].enablePin > -1)
digitalWrite(extruder[3].enablePin,extruder[3].enableOn);
#endif
}
#endif
#endif
}
#endif
#if FEATURE_RETRACTION
inline bool isRetracted() {return (flags & EXTRUDER_FLAG_RETRACTED) != 0;}
inline void setRetracted(bool on) {
flags = (flags & (255 - EXTRUDER_FLAG_RETRACTED)) | (on ? EXTRUDER_FLAG_RETRACTED : 0);
}
void retract(bool isRetract,bool isLong);
void retractDistance(float dist);
#endif
static void manageTemperatures();
static void disableCurrentExtruderMotor();
static void disableAllExtruderMotors();
static void selectExtruderById(uint8_t extruderId);
static void disableAllHeater();
static void initExtruder();
static void initHeatedBed();
static void setHeatedBedTemperature(float temp_celsius,bool beep = false);
static float getHeatedBedTemperature();
static void setTemperatureForExtruder(float temp_celsius,uint8_t extr,bool beep = false);
};
#if HAVE_HEATED_BED
#define NUM_TEMPERATURE_LOOPS NUM_EXTRUDER+1
extern TemperatureController heatedBedController;
#else
#define NUM_TEMPERATURE_LOOPS NUM_EXTRUDER
#endif
#define TEMP_INT_TO_FLOAT(temp) ((float)(temp)/(float)(1<<CELSIUS_EXTRA_BITS))
#define TEMP_FLOAT_TO_INT(temp) ((int)((temp)*(1<<CELSIUS_EXTRA_BITS)))
//extern Extruder *Extruder::current;
extern TemperatureController *tempController[NUM_TEMPERATURE_LOOPS];
extern uint8_t autotuneIndex;
#endif // EXTRUDER_H_INCLUDED

View File

@ -0,0 +1,418 @@
/* Arduino SdFat Library
* Copyright (C) 2009 by William Greiman
*
* This file is part of the Arduino SdFat Library
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the Arduino SdFat Library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef FatStructs_h
#define FatStructs_h
/**
* \file
* FAT file structures
*/
/*
* mostly from Microsoft document fatgen103.doc
* http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx
*/
//------------------------------------------------------------------------------
/** Value for byte 510 of boot block or MBR */
uint8_t const BOOTSIG0 = 0X55;
/** Value for byte 511 of boot block or MBR */
uint8_t const BOOTSIG1 = 0XAA;
//------------------------------------------------------------------------------
/**
* \struct partitionTable
* \brief MBR partition table entry
*
* A partition table entry for a MBR formatted storage device.
* The MBR partition table has four entries.
*/
struct partitionTable {
/**
* Boot Indicator . Indicates whether the volume is the active
* partition. Legal values include: 0X00. Do not use for booting.
* 0X80 Active partition.
*/
uint8_t boot;
/**
* Head part of Cylinder-head-sector address of the first block in
* the partition. Legal values are 0-255. Only used in old PC BIOS.
*/
uint8_t beginHead;
/**
* Sector part of Cylinder-head-sector address of the first block in
* the partition. Legal values are 1-63. Only used in old PC BIOS.
*/
unsigned beginSector : 6;
/** High bits cylinder for first block in partition. */
unsigned beginCylinderHigh : 2;
/**
* Combine beginCylinderLow with beginCylinderHigh. Legal values
* are 0-1023. Only used in old PC BIOS.
*/
uint8_t beginCylinderLow;
/**
* Partition type. See defines that begin with PART_TYPE_ for
* some Microsoft partition types.
*/
uint8_t type;
/**
* head part of cylinder-head-sector address of the last sector in the
* partition. Legal values are 0-255. Only used in old PC BIOS.
*/
uint8_t endHead;
/**
* Sector part of cylinder-head-sector address of the last sector in
* the partition. Legal values are 1-63. Only used in old PC BIOS.
*/
unsigned endSector : 6;
/** High bits of end cylinder */
unsigned endCylinderHigh : 2;
/**
* Combine endCylinderLow with endCylinderHigh. Legal values
* are 0-1023. Only used in old PC BIOS.
*/
uint8_t endCylinderLow;
/** Logical block address of the first block in the partition. */
uint32_t firstSector;
/** Length of the partition, in blocks. */
uint32_t totalSectors;
};
/** Type name for partitionTable */
typedef struct partitionTable part_t;
//------------------------------------------------------------------------------
/**
* \struct masterBootRecord
*
* \brief Master Boot Record
*
* The first block of a storage device that is formatted with a MBR.
*/
struct masterBootRecord {
/** Code Area for master boot program. */
uint8_t codeArea[440];
/** Optional WindowsNT disk signature. May contain more boot code. */
uint32_t diskSignature;
/** Usually zero but may be more boot code. */
uint16_t usuallyZero;
/** Partition tables. */
part_t part[4];
/** First MBR signature byte. Must be 0X55 */
uint8_t mbrSig0;
/** Second MBR signature byte. Must be 0XAA */
uint8_t mbrSig1;
};
/** Type name for masterBootRecord */
typedef struct masterBootRecord mbr_t;
//------------------------------------------------------------------------------
/**
* \struct biosParmBlock
*
* \brief BIOS parameter block
*
* The BIOS parameter block describes the physical layout of a FAT volume.
*/
struct biosParmBlock {
/**
* Count of bytes per sector. This value may take on only the
* following values: 512, 1024, 2048 or 4096
*/
uint16_t bytesPerSector;
/**
* Number of sectors per allocation unit. This value must be a
* power of 2 that is greater than 0. The legal values are
* 1, 2, 4, 8, 16, 32, 64, and 128.
*/
uint8_t sectorsPerCluster;
/**
* Number of sectors before the first FAT.
* This value must not be zero.
*/
uint16_t reservedSectorCount;
/** The count of FAT data structures on the volume. This field should
* always contain the value 2 for any FAT volume of any type.
*/
uint8_t fatCount;
/**
* For FAT12 and FAT16 volumes, this field contains the count of
* 32-byte directory entries in the root directory. For FAT32 volumes,
* this field must be set to 0. For FAT12 and FAT16 volumes, this
* value should always specify a count that when multiplied by 32
* results in a multiple of bytesPerSector. FAT16 volumes should
* use the value 512.
*/
uint16_t rootDirEntryCount;
/**
* This field is the old 16-bit total count of sectors on the volume.
* This count includes the count of all sectors in all four regions
* of the volume. This field can be 0; if it is 0, then totalSectors32
* must be non-zero. For FAT32 volumes, this field must be 0. For
* FAT12 and FAT16 volumes, this field contains the sector count, and
* totalSectors32 is 0 if the total sector count fits
* (is less than 0x10000).
*/
uint16_t totalSectors16;
/**
* This dates back to the old MS-DOS 1.x media determination and is
* no longer usually used for anything. 0xF8 is the standard value
* for fixed (non-removable) media. For removable media, 0xF0 is
* frequently used. Legal values are 0xF0 or 0xF8-0xFF.
*/
uint8_t mediaType;
/**
* Count of sectors occupied by one FAT on FAT12/FAT16 volumes.
* On FAT32 volumes this field must be 0, and sectorsPerFat32
* contains the FAT size count.
*/
uint16_t sectorsPerFat16;
/** Sectors per track for interrupt 0x13. Not used otherwise. */
uint16_t sectorsPerTrtack;
/** Number of heads for interrupt 0x13. Not used otherwise. */
uint16_t headCount;
/**
* Count of hidden sectors preceding the partition that contains this
* FAT volume. This field is generally only relevant for media
* visible on interrupt 0x13.
*/
uint32_t hidddenSectors;
/**
* This field is the new 32-bit total count of sectors on the volume.
* This count includes the count of all sectors in all four regions
* of the volume. This field can be 0; if it is 0, then
* totalSectors16 must be non-zero.
*/
uint32_t totalSectors32;
/**
* Count of sectors occupied by one FAT on FAT32 volumes.
*/
uint32_t sectorsPerFat32;
/**
* This field is only defined for FAT32 media and does not exist on
* FAT12 and FAT16 media.
* Bits 0-3 -- Zero-based number of active FAT.
* Only valid if mirroring is disabled.
* Bits 4-6 -- Reserved.
* Bit 7 -- 0 means the FAT is mirrored at runtime into all FATs.
* -- 1 means only one FAT is active; it is the one referenced in bits 0-3.
* Bits 8-15 -- Reserved.
*/
uint16_t fat32Flags;
/**
* FAT32 version. High byte is major revision number.
* Low byte is minor revision number. Only 0.0 define.
*/
uint16_t fat32Version;
/**
* Cluster number of the first cluster of the root directory for FAT32.
* This usually 2 but not required to be 2.
*/
uint32_t fat32RootCluster;
/**
* Sector number of FSINFO structure in the reserved area of the
* FAT32 volume. Usually 1.
*/
uint16_t fat32FSInfo;
/**
* If non-zero, indicates the sector number in the reserved area
* of the volume of a copy of the boot record. Usually 6.
* No value other than 6 is recommended.
*/
uint16_t fat32BackBootBlock;
/**
* Reserved for future expansion. Code that formats FAT32 volumes
* should always set all of the bytes of this field to 0.
*/
uint8_t fat32Reserved[12];
};
/** Type name for biosParmBlock */
typedef struct biosParmBlock bpb_t;
//------------------------------------------------------------------------------
/**
* \struct fat32BootSector
*
* \brief Boot sector for a FAT16 or FAT32 volume.
*
*/
struct fat32BootSector {
/** X86 jmp to boot program */
uint8_t jmpToBootCode[3];
/** informational only - don't depend on it */
char oemName[8];
/** BIOS Parameter Block */
bpb_t bpb;
/** for int0x13 use value 0X80 for hard drive */
uint8_t driveNumber;
/** used by Windows NT - should be zero for FAT */
uint8_t reserved1;
/** 0X29 if next three fields are valid */
uint8_t bootSignature;
/** usually generated by combining date and time */
uint32_t volumeSerialNumber;
/** should match volume label in root dir */
char volumeLabel[11];
/** informational only - don't depend on it */
char fileSystemType[8];
/** X86 boot code */
uint8_t bootCode[420];
/** must be 0X55 */
uint8_t bootSectorSig0;
/** must be 0XAA */
uint8_t bootSectorSig1;
};
//------------------------------------------------------------------------------
// End Of Chain values for FAT entries
/** FAT16 end of chain value used by Microsoft. */
uint16_t const FAT16EOC = 0XFFFF;
/** Minimum value for FAT16 EOC. Use to test for EOC. */
uint16_t const FAT16EOC_MIN = 0XFFF8;
/** FAT32 end of chain value used by Microsoft. */
uint32_t const FAT32EOC = 0X0FFFFFFF;
/** Minimum value for FAT32 EOC. Use to test for EOC. */
uint32_t const FAT32EOC_MIN = 0X0FFFFFF8;
/** Mask a for FAT32 entry. Entries are 28 bits. */
uint32_t const FAT32MASK = 0X0FFFFFFF;
/** Type name for fat32BootSector */
typedef struct fat32BootSector fbs_t;
//------------------------------------------------------------------------------
/**
* \struct directoryEntry
* \brief FAT short directory entry
*
* Short means short 8.3 name, not the entry size.
*
* Date Format. A FAT directory entry date stamp is a 16-bit field that is
* basically a date relative to the MS-DOS epoch of 01/01/1980. Here is the
* format (bit 0 is the LSB of the 16-bit word, bit 15 is the MSB of the
* 16-bit word):
*
* Bits 9-15: Count of years from 1980, valid value range 0-127
* inclusive (1980-2107).
*
* Bits 5-8: Month of year, 1 = January, valid value range 1-12 inclusive.
*
* Bits 0-4: Day of month, valid value range 1-31 inclusive.
*
* Time Format. A FAT directory entry time stamp is a 16-bit field that has
* a granularity of 2 seconds. Here is the format (bit 0 is the LSB of the
* 16-bit word, bit 15 is the MSB of the 16-bit word).
*
* Bits 11-15: Hours, valid value range 0-23 inclusive.
*
* Bits 5-10: Minutes, valid value range 0-59 inclusive.
*
* Bits 0-4: 2-second count, valid value range 0-29 inclusive (0 - 58 seconds).
*
* The valid time range is from Midnight 00:00:00 to 23:59:58.
*/
struct directoryEntry {
/**
* Short 8.3 name.
* The first eight bytes contain the file name with blank fill.
* The last three bytes contain the file extension with blank fill.
*/
uint8_t name[11];
/** Entry attributes.
*
* The upper two bits of the attribute byte are reserved and should
* always be set to 0 when a file is created and never modified or
* looked at after that. See defines that begin with DIR_ATT_.
*/
uint8_t attributes;
/**
* Reserved for use by Windows NT. Set value to 0 when a file is
* created and never modify or look at it after that.
*/
uint8_t reservedNT;
/**
* The granularity of the seconds part of creationTime is 2 seconds
* so this field is a count of tenths of a second and its valid
* value range is 0-199 inclusive. (WHG note - seems to be hundredths)
*/
uint8_t creationTimeTenths;
/** Time file was created. */
uint16_t creationTime;
/** Date file was created. */
uint16_t creationDate;
/**
* Last access date. Note that there is no last access time, only
* a date. This is the date of last read or write. In the case of
* a write, this should be set to the same date as lastWriteDate.
*/
uint16_t lastAccessDate;
/**
* High word of this entry's first cluster number (always 0 for a
* FAT12 or FAT16 volume).
*/
uint16_t firstClusterHigh;
/** Time of last write. File creation is considered a write. */
uint16_t lastWriteTime;
/** Date of last write. File creation is considered a write. */
uint16_t lastWriteDate;
/** Low word of this entry's first cluster number. */
uint16_t firstClusterLow;
/** 32-bit unsigned holding this file's size in bytes. */
uint32_t fileSize;
};
//------------------------------------------------------------------------------
// Definitions for directory entries
//
/** Type name for directoryEntry */
typedef struct directoryEntry dir_t;
/** escape for name[0] = 0XE5 */
uint8_t const DIR_NAME_0XE5 = 0X05;
/** name[0] value for entry that is free after being "deleted" */
uint8_t const DIR_NAME_DELETED = 0XE5;
/** name[0] value for entry that is free and no allocated entries follow */
uint8_t const DIR_NAME_FREE = 0X00;
/** file is read-only */
uint8_t const DIR_ATT_READ_ONLY = 0X01;
/** File should hidden in directory listings */
uint8_t const DIR_ATT_HIDDEN = 0X02;
/** Entry is for a system file */
uint8_t const DIR_ATT_SYSTEM = 0X04;
/** Directory entry contains the volume label */
uint8_t const DIR_ATT_VOLUME_ID = 0X08;
/** Entry is for a directory */
uint8_t const DIR_ATT_DIRECTORY = 0X10;
/** Old DOS archive bit for backup support */
uint8_t const DIR_ATT_ARCHIVE = 0X20;
/** Test value for long name entry. Test is
(d->attributes & DIR_ATT_LONG_NAME_MASK) == DIR_ATT_LONG_NAME. */
uint8_t const DIR_ATT_LONG_NAME = 0X0F;
/** Test mask for long name entry */
uint8_t const DIR_ATT_LONG_NAME_MASK = 0X3F;
/** defined attribute bits */
uint8_t const DIR_ATT_DEFINED_BITS = 0X3F;
/** Directory entry is part of a long name */
static inline uint8_t DIR_IS_LONG_NAME(const dir_t* dir) {
return (dir->attributes & DIR_ATT_LONG_NAME_MASK) == DIR_ATT_LONG_NAME;
}
/** Mask for file/subdirectory tests */
uint8_t const DIR_ATT_FILE_TYPE_MASK = (DIR_ATT_VOLUME_ID | DIR_ATT_DIRECTORY);
/** Directory entry is for a file */
static inline uint8_t DIR_IS_FILE(const dir_t* dir) {
return (dir->attributes & DIR_ATT_FILE_TYPE_MASK) == 0;
}
/** Directory entry is for a subdirectory */
static inline uint8_t DIR_IS_SUBDIR(const dir_t* dir) {
return (dir->attributes & DIR_ATT_FILE_TYPE_MASK) == DIR_ATT_DIRECTORY;
}
/** Directory entry is for a file or subdirectory */
static inline uint8_t DIR_IS_FILE_OR_SUBDIR(const dir_t* dir) {
return (dir->attributes & DIR_ATT_VOLUME_ID) == 0;
}
#endif // FatStructs_h

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,743 @@
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Repetier-Firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
This firmware is a nearly complete rewrite of the sprinter firmware
by kliment (https://github.com/kliment/Sprinter)
which based on Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
Functions in this file are used to communicate using ascii or repetier protocol.
*/
#ifndef HAL_H
#define HAL_H
/**
This is the main Hardware Abstraction Layer (HAL).
To make the firmware work with different processors and toolchains,
all hardware related code should be packed into the hal files.
*/
#include <avr/pgmspace.h>
#include <avr/io.h>
#if CPU_ARCH == ARCH_AVR
#include <avr/io.h>
#else
#define PROGMEM
#define PGM_P const char *
#define PSTR(s) s
#define pgm_read_byte_near(x) (*(char*)x)
#define pgm_read_byte(x) (*(char*)x)
#endif
#define PACK
#define FSTRINGVALUE(var,value) const char var[] PROGMEM = value;
#define FSTRINGVAR(var) static const char var[] PROGMEM;
#define FSTRINGPARAM(var) PGM_P var
#include <avr/eeprom.h>
#include <avr/wdt.h>
/** \brief Prescale factor, timer0 runs at.
All known arduino boards use 64. This value is needed for the extruder timing. */
#define TIMER0_PRESCALE 64
#define ANALOG_PRESCALER _BV(ADPS0)|_BV(ADPS1)|_BV(ADPS2)
#if MOTHERBOARD==8 || MOTHERBOARD==88 || MOTHERBOARD==9 || CPU_ARCH!=ARCH_AVR
#define EXTERNALSERIAL
#endif
//#define EXTERNALSERIAL // Force using arduino serial
#ifndef EXTERNALSERIAL
#define HardwareSerial_h // Don't use standard serial console
#endif
#include <inttypes.h>
#include "Print.h"
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#define COMPAT_PRE1
#endif
#if CPU_ARCH==ARCH_AVR
#include "fastio.h"
#else
#define READ(IO) digitalRead(IO)
#define WRITE(IO, v) digitalWrite(IO, v)
#define SET_INPUT(IO) pinMode(IO, INPUT)
#define SET_OUTPUT(IO) pinMode(IO, OUTPUT)
#endif
class InterruptProtectedBlock
{
uint8_t sreg;
public:
inline void protect()
{
cli();
}
inline void unprotect()
{
SREG = sreg;
}
inline InterruptProtectedBlock(bool later = false)
{
sreg = SREG;
if(!later)
cli();
}
inline ~InterruptProtectedBlock()
{
SREG = sreg;
}
};
#define EEPROM_OFFSET 0
#define SECONDS_TO_TICKS(s) (unsigned long)(s*(float)F_CPU)
#define ANALOG_REDUCE_BITS 0
#define ANALOG_REDUCE_FACTOR 1
#define MAX_RAM 32767
#define bit_clear(x,y) x&= ~(1<<y) //cbi(x,y)
#define bit_set(x,y) x|= (1<<y)//sbi(x,y)
/** defines the data direction (reading from I2C device) in i2cStart(),i2cRepStart() */
#define I2C_READ 1
/** defines the data direction (writing to I2C device) in i2cStart(),i2cRepStart() */
#define I2C_WRITE 0
#if NONLINEAR_SYSTEM
// Maximum speed with 100% inerrupt utilization is 27000 hz at 16MHz cpu
// leave some margin for all the extra transformations. So we keep inside clean timings.
#define LIMIT_INTERVAL ((F_CPU/30000)+1)
#else
#define LIMIT_INTERVAL ((F_CPU/40000)+1)
#endif
typedef uint16_t speed_t;
typedef uint32_t ticks_t;
typedef uint32_t millis_t;
typedef uint8_t flag8_t;
typedef int8_t fast8_t;
#define FAST_INTEGER_SQRT
#ifndef EXTERNALSERIAL
// Implement serial communication for one stream only!
/*
HardwareSerial.h - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Modified 28 September 2010 by Mark Sproul
Modified to use only 1 queue with fixed length by Repetier
*/
#define SERIAL_BUFFER_SIZE 128
#define SERIAL_BUFFER_MASK 127
#define SERIAL_TX_BUFFER_SIZE 64
#define SERIAL_TX_BUFFER_MASK 63
struct ring_buffer
{
unsigned char buffer[SERIAL_BUFFER_SIZE];
volatile uint8_t head;
volatile uint8_t tail;
};
struct ring_buffer_tx
{
unsigned char buffer[SERIAL_TX_BUFFER_SIZE];
volatile uint8_t head;
volatile uint8_t tail;
};
class RFHardwareSerial : public Print
{
public:
ring_buffer *_rx_buffer;
ring_buffer_tx *_tx_buffer;
volatile uint8_t *_ubrrh;
volatile uint8_t *_ubrrl;
volatile uint8_t *_ucsra;
volatile uint8_t *_ucsrb;
volatile uint8_t *_udr;
uint8_t _rxen;
uint8_t _txen;
uint8_t _rxcie;
uint8_t _udrie;
uint8_t _u2x;
public:
RFHardwareSerial(ring_buffer *rx_buffer, ring_buffer_tx *tx_buffer,
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *udr,
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x);
void begin(unsigned long);
void end();
virtual int available(void);
virtual int peek(void);
virtual int read(void);
virtual void flush(void);
#ifdef COMPAT_PRE1
virtual void write(uint8_t);
#else
virtual size_t write(uint8_t);
#endif
using Print::write; // pull in write(str) and write(buf, size) from Print
operator bool();
int outputUnused(void); // Used for output in interrupts
};
extern RFHardwareSerial RFSerial;
#define RFSERIAL RFSerial
//extern ring_buffer tx_buffer;
#define WAIT_OUT_EMPTY while(tx_buffer.head != tx_buffer.tail) {}
#else
#define RFSERIAL Serial
#endif
#define OUT_P_I(p,i) Com::printF(PSTR(p),(int)(i))
#define OUT_P_I_LN(p,i) Com::printFLN(PSTR(p),(int)(i))
#define OUT_P_L(p,i) Com::printF(PSTR(p),(long)(i))
#define OUT_P_L_LN(p,i) Com::printFLN(PSTR(p),(long)(i))
#define OUT_P_F(p,i) Com::printF(PSTR(p),(float)(i))
#define OUT_P_F_LN(p,i) Com::printFLN(PSTR(p),(float)(i))
#define OUT_P_FX(p,i,x) Com::printF(PSTR(p),(float)(i),x)
#define OUT_P_FX_LN(p,i,x) Com::printFLN(PSTR(p),(float)(i),x)
#define OUT_P(p) Com::printF(PSTR(p))
#define OUT_P_LN(p) Com::printFLN(PSTR(p))
#define OUT_ERROR_P(p) Com::printErrorF(PSTR(p))
#define OUT_ERROR_P_LN(p) {Com::printErrorF(PSTR(p));Com::println();}
#define OUT(v) Com::print(v)
#define OUT_LN Com::println()
class HAL
{
public:
HAL();
virtual ~HAL();
static inline void hwSetup(void)
{}
// return val'val
static uint16_t integerSqrt(uint32_t a);
/** \brief Optimized division
Normally the C compiler will compute a long/long division, which takes ~670 Ticks.
This version is optimized for a 16 bit dividend and recognises the special cases
of a 24 bit and 16 bit dividend, which offen, but not always occur in updating the
interval.
*/
static inline int32_t Div4U2U(uint32_t a,uint16_t b)
{
#if CPU_ARCH==ARCH_AVR
// r14/r15 remainder
// r16 counter
__asm__ __volatile__ (
"clr r14 \n\t"
"sub r15,r15 \n\t"
"tst %D0 \n\t"
"brne do32%= \n\t"
"tst %C0 \n\t"
"breq donot24%= \n\t"
"rjmp do24%= \n\t"
"donot24%=:" "ldi r16,17 \n\t" // 16 Bit divide
"d16u_1%=:" "rol %A0 \n\t"
"rol %B0 \n\t"
"dec r16 \n\t"
"brne d16u_2%= \n\t"
"rjmp end%= \n\t"
"d16u_2%=:" "rol r14 \n\t"
"rol r15 \n\t"
"sub r14,%A2 \n\t"
"sbc r15,%B2 \n\t"
"brcc d16u_3%= \n\t"
"add r14,%A2 \n\t"
"adc r15,%B2 \n\t"
"clc \n\t"
"rjmp d16u_1%= \n\t"
"d16u_3%=:" "sec \n\t"
"rjmp d16u_1%= \n\t"
"do32%=:" // divide full 32 bit
"rjmp do32B%= \n\t"
"do24%=:" // divide 24 bit
"ldi r16,25 \n\t" // 24 Bit divide
"d24u_1%=:" "rol %A0 \n\t"
"rol %B0 \n\t"
"rol %C0 \n\t"
"dec r16 \n\t"
"brne d24u_2%= \n\t"
"rjmp end%= \n\t"
"d24u_2%=:" "rol r14 \n\t"
"rol r15 \n\t"
"sub r14,%A2 \n\t"
"sbc r15,%B2 \n\t"
"brcc d24u_3%= \n\t"
"add r14,%A2 \n\t"
"adc r15,%B2 \n\t"
"clc \n\t"
"rjmp d24u_1%= \n\t"
"d24u_3%=:" "sec \n\t"
"rjmp d24u_1%= \n\t"
"do32B%=:" // divide full 32 bit
"ldi r16,33 \n\t" // 32 Bit divide
"d32u_1%=:" "rol %A0 \n\t"
"rol %B0 \n\t"
"rol %C0 \n\t"
"rol %D0 \n\t"
"dec r16 \n\t"
"brne d32u_2%= \n\t"
"rjmp end%= \n\t"
"d32u_2%=:" "rol r14 \n\t"
"rol r15 \n\t"
"sub r14,%A2 \n\t"
"sbc r15,%B2 \n\t"
"brcc d32u_3%= \n\t"
"add r14,%A2 \n\t"
"adc r15,%B2 \n\t"
"clc \n\t"
"rjmp d32u_1%= \n\t"
"d32u_3%=:" "sec \n\t"
"rjmp d32u_1%= \n\t"
"end%=:" // end
:"=&r"(a)
:"0"(a),"r"(b)
:"r14","r15","r16"
);
return a;
#else
return a/b;
#endif
}
static inline unsigned long U16SquaredToU32(unsigned int val)
{
long res;
__asm__ __volatile__ ( // 15 Ticks
"mul %A1,%A1 \n\t"
"movw %A0,r0 \n\t"
"mul %B1,%B1 \n\t"
"movw %C0,r0 \n\t"
"mul %A1,%B1 \n\t"
"clr %A1 \n\t"
"add %B0,r0 \n\t"
"adc %C0,r1 \n\t"
"adc %D0,%A1 \n\t"
"add %B0,r0 \n\t"
"adc %C0,r1 \n\t"
"adc %D0,%A1 \n\t"
"clr r1 \n\t"
: "=&r"(res),"=r"(val)
: "1"(val)
);
return res;
}
static inline unsigned int ComputeV(long timer,long accel)
{
#if CPU_ARCH==ARCH_AVR
unsigned int res;
// 38 Ticks
__asm__ __volatile__ ( // 0 = res, 1 = timer, 2 = accel %D2=0 ,%A1 are unused is free
// Result LSB first: %A0, %B0, %A1
"mul %B1,%A2 \n\t"
"mov %A0,r1 \n\t"
"mul %B1,%C2 \n\t"
"mov %B0,r0 \n\t"
"mov %A1,r1 \n\t"
"mul %B1,%B2 \n\t"
"add %A0,r0 \n\t"
"adc %B0,r1 \n\t"
"adc %A1,%D2 \n\t"
"mul %C1,%A2 \n\t"
"add %A0,r0 \n\t"
"adc %B0,r1 \n\t"
"adc %A1,%D2 \n\t"
"mul %C1,%B2 \n\t"
"add %B0,r0 \n\t"
"adc %A1,r1 \n\t"
"mul %D1,%A2 \n\t"
"add %B0,r0 \n\t"
"adc %A1,r1 \n\t"
"mul %C1,%C2 \n\t"
"add %A1,r0 \n\t"
"mul %D1,%B2 \n\t"
"add %A1,r0 \n\t"
"lsr %A1 \n\t"
"ror %B0 \n\t"
"ror %A0 \n\t"
"lsr %A1 \n\t"
"ror %B0 \n\t"
"ror %A0 \n\t"
"clr r1 \n\t"
:"=&r"(res),"=r"(timer),"=r"(accel)
:"1"(timer),"2"(accel)
: );
// unsigned int v = ((timer>>8)*cur->accel)>>10;
return res;
#else
return ((timer>>8)*accel)>>10;
#endif
}
// Multiply two 16 bit values and return 32 bit result
static inline uint32_t mulu16xu16to32(unsigned int a,unsigned int b)
{
uint32_t res;
// 18 Ticks = 1.125 us
__asm__ __volatile__ ( // 0 = res, 1 = timer, 2 = accel %D2=0 ,%A1 are unused is free
// Result LSB first: %A0, %B0, %A1
"clr r18 \n\t"
"mul %B2,%B1 \n\t" // mul hig bytes
"movw %C0,r0 \n\t"
"mul %A1,%A2 \n\t" // mul low bytes
"movw %A0,r0 \n\t"
"mul %A1,%B2 \n\t"
"add %B0,r0 \n\t"
"adc %C0,r1 \n\t"
"adc %D0,r18 \n\t"
"mul %B1,%A2 \n\t"
"add %B0,r0 \n\t"
"adc %C0,r1 \n\t"
"adc %D0,r18 \n\t"
"clr r1 \n\t"
:"=&r"(res),"=r"(a),"=r"(b)
:"1"(a),"2"(b)
:"r18" );
// return (long)a*b;
return res;
}
// Multiply two 16 bit values and return 32 bit result
static inline unsigned int mulu6xu16shift16(unsigned int a,unsigned int b)
{
#if CPU_ARCH==ARCH_AVR
unsigned int res;
// 18 Ticks = 1.125 us
__asm__ __volatile__ ( // 0 = res, 1 = timer, 2 = accel %D2=0 ,%A1 are unused is free
// Result LSB first: %A0, %B0, %A1
"clr r18 \n\t"
"mul %B2,%B1 \n\t" // mul hig bytes
"movw %A0,r0 \n\t"
"mul %A1,%A2 \n\t" // mul low bytes
"mov r19,r1 \n\t"
"mul %A1,%B2 \n\t"
"add r19,r0 \n\t"
"adc %A0,r1 \n\t"
"adc %B0,r18 \n\t"
"mul %B1,%A2 \n\t"
"add r19,r0 \n\t"
"adc %A0,r1 \n\t"
"adc %B0,r18 \n\t"
"clr r1 \n\t"
:"=&r"(res),"=r"(a),"=r"(b)
:"1"(a),"2"(b)
:"r18","r19" );
return res;
#else
return ((int32_t)a*b)>>16;
#endif
}
static inline void digitalWrite(uint8_t pin,uint8_t value)
{
::digitalWrite(pin,value);
}
static inline uint8_t digitalRead(uint8_t pin)
{
return ::digitalRead(pin);
}
static inline void pinMode(uint8_t pin,uint8_t mode)
{
::pinMode(pin,mode);
}
static int32_t CPUDivU2(unsigned int divisor);
static inline void delayMicroseconds(unsigned int delayUs)
{
::delayMicroseconds(delayUs);
}
static inline void delayMilliseconds(unsigned int delayMs)
{
::delay(delayMs);
}
static inline void tone(uint8_t pin,int duration)
{
::tone(pin,duration);
}
static inline void noTone(uint8_t pin)
{
::noTone(pin);
}
static inline void eprSetByte(unsigned int pos,uint8_t value)
{
eeprom_write_byte((unsigned char *)(EEPROM_OFFSET+pos), value);
}
static inline void eprSetInt16(unsigned int pos,int16_t value)
{
eeprom_write_word((unsigned int*)(EEPROM_OFFSET+pos),value);
}
static inline void eprSetInt32(unsigned int pos,int32_t value)
{
eeprom_write_dword((uint32_t*)(EEPROM_OFFSET+pos),value);
}
static inline void eprSetFloat(unsigned int pos,float value)
{
eeprom_write_block(&value,(void*)(EEPROM_OFFSET+pos), 4);
}
static inline uint8_t eprGetByte(unsigned int pos)
{
return eeprom_read_byte ((unsigned char *)(EEPROM_OFFSET+pos));
}
static inline int16_t eprGetInt16(unsigned int pos)
{
return eeprom_read_word((uint16_t *)(EEPROM_OFFSET+pos));
}
static inline int32_t eprGetInt32(unsigned int pos)
{
return eeprom_read_dword((uint32_t*)(EEPROM_OFFSET+pos));
}
static inline float eprGetFloat(unsigned int pos)
{
float v;
eeprom_read_block(&v,(void *)(EEPROM_OFFSET+pos),4); // newer gcc have eeprom_read_block but not arduino 22
return v;
}
// Faster version of InterruptProtectedBlock.
// For safety it ma yonly be called from within an
// interrupt handler.
static inline void allowInterrupts()
{
sei();
}
// Faster version of InterruptProtectedBlock.
// For safety it ma yonly be called from within an
// interrupt handler.
static inline void forbidInterrupts()
{
cli();
}
static inline unsigned long timeInMilliseconds()
{
return millis();
}
static inline char readFlashByte(PGM_P ptr)
{
return pgm_read_byte(ptr);
}
static inline void serialSetBaudrate(long baud)
{
RFSERIAL.begin(baud);
}
static inline bool serialByteAvailable()
{
return RFSERIAL.available()>0;
}
static inline uint8_t serialReadByte()
{
return RFSERIAL.read();
}
static inline void serialWriteByte(char b)
{
RFSERIAL.write(b);
}
static inline void serialFlush()
{
RFSERIAL.flush();
}
static void setupTimer();
static void showStartReason();
static int getFreeRam();
static void resetHardware();
// SPI related functions
static void spiBegin()
{
#if SDSS>=0
SET_INPUT(MISO_PIN);
SET_OUTPUT(MOSI_PIN);
SET_OUTPUT(SCK_PIN);
// SS must be in output mode even it is not chip select
SET_OUTPUT(SDSS);
#if SDSSORIG >- 1
SET_OUTPUT(SDSSORIG);
#endif
// set SS high - may be chip select for another SPI device
#if SET_SPI_SS_HIGH
WRITE(SDSS, HIGH);
#endif // SET_SPI_SS_HIGH
#endif
}
static inline void spiInit(uint8_t spiRate)
{
uint8_t r = 0;
for (uint8_t b = 2; spiRate > b && r < 6; b <<= 1, r++);
SET_OUTPUT(SS);
WRITE(SS,HIGH);
SET_OUTPUT(SCK);
SET_OUTPUT(MOSI_PIN);
SET_INPUT(MISO_PIN);
#ifdef PRR
PRR &= ~(1<<PRSPI);
#elif defined PRR0
PRR0 &= ~(1<<PRSPI);
#endif
// See avr processor documentation
SPCR = (1 << SPE) | (1 << MSTR) | (r >> 1);
SPSR = (r & 1 || r == 6 ? 0 : 1) << SPI2X;
}
static inline uint8_t spiReceive(uint8_t send=0xff)
{
SPDR = send;
while (!(SPSR & (1 << SPIF))) {}
return SPDR;
}
static inline void spiReadBlock(uint8_t*buf,size_t nbyte)
{
if (nbyte-- == 0) return;
SPDR = 0XFF;
for (size_t i = 0; i < nbyte; i++)
{
while (!(SPSR & (1 << SPIF))) {}
buf[i] = SPDR;
SPDR = 0XFF;
}
while (!(SPSR & (1 << SPIF))) {}
buf[nbyte] = SPDR;
}
static inline void spiSend(uint8_t b)
{
SPDR = b;
while (!(SPSR & (1 << SPIF))) {}
}
static inline void spiSend(const uint8_t* buf , size_t n)
{
if (n == 0) return;
SPDR = buf[0];
if (n > 1)
{
uint8_t b = buf[1];
size_t i = 2;
while (1)
{
while (!(SPSR & (1 << SPIF))) {}
SPDR = b;
if (i == n) break;
b = buf[i++];
}
}
while (!(SPSR & (1 << SPIF))) {}
}
static inline __attribute__((always_inline))
void spiSendBlock(uint8_t token, const uint8_t* buf)
{
SPDR = token;
for (uint16_t i = 0; i < 512; i += 2)
{
while (!(SPSR & (1 << SPIF))) {}
SPDR = buf[i];
while (!(SPSR & (1 << SPIF))) {}
SPDR = buf[i + 1];
}
while (!(SPSR & (1 << SPIF))) {}
}
// I2C Support
static void i2cInit(unsigned long clockSpeedHz);
static unsigned char i2cStart(unsigned char address);
static void i2cStartWait(unsigned char address);
static void i2cStop(void);
static unsigned char i2cWrite( unsigned char data );
static unsigned char i2cReadAck(void);
static unsigned char i2cReadNak(void);
// Watchdog support
inline static void startWatchdog()
{
wdt_enable(WDTO_1S);
};
inline static void stopWatchdog()
{
wdt_disable();
}
inline static void pingWatchdog()
{
wdt_reset();
};
inline static float maxExtruderTimerFrequency()
{
return (float)F_CPU/TIMER0_PRESCALE;
}
#if FEATURE_SERVO
static unsigned int servoTimings[4];
static void servoMicroseconds(uint8_t servo,int ms);
#endif
static void analogStart();
#if USE_ADVANCE
static void resetExtruderDirection();
#endif
protected:
private:
};
/*#if MOTHERBOARD==6 || MOTHERBOARD==62 || MOTHERBOARD==7
#if MOTHERBOARD!=7
#define SIMULATE_PWM
#endif
#define EXTRUDER_TIMER_VECTOR TIMER2_COMPA_vect
#define EXTRUDER_OCR OCR2A
#define EXTRUDER_TCCR TCCR2A
#define EXTRUDER_TIMSK TIMSK2
#define EXTRUDER_OCIE OCIE2A
#define PWM_TIMER_VECTOR TIMER2_COMPB_vect
#define PWM_OCR OCR2B
#define PWM_TCCR TCCR2B
#define PWM_TIMSK TIMSK2
#define PWM_OCIE OCIE2B
#else*/
#define EXTRUDER_TIMER_VECTOR TIMER0_COMPA_vect
#define EXTRUDER_OCR OCR0A
#define EXTRUDER_TCCR TCCR0A
#define EXTRUDER_TIMSK TIMSK0
#define EXTRUDER_OCIE OCIE0A
#define PWM_TIMER_VECTOR TIMER0_COMPB_vect
#define PWM_OCR OCR0B
#define PWM_TCCR TCCR0A
#define PWM_TIMSK TIMSK0
#define PWM_OCIE OCIE0B
//#endif
#endif // HAL_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,874 @@
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Repetier-Firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
This firmware is a nearly complete rewrite of the sprinter firmware
by kliment (https://github.com/kliment/Sprinter)
which based on Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
*/
/**
Coordinate system transformations:
Level 1: G-code => Coordinates like send via g-codes.
Level 2: Real coordinates => Coordinates corrected by coordinate shift via G92
currentPosition and lastCmdPos are from this level.
Level 3: Transformed and shifter => Include extruder offset and bed rotation.
These variables are only stored temporary.
Level 4: Step position => Level 3 converted into steps for motor position
currentPositionSteps and destinationPositionSteps are from this level.
Level 5: Nonlinear motor step position, only for nonlinear drive systems
destinationDeltaSteps
*/
#ifndef PRINTER_H_INCLUDED
#define PRINTER_H_INCLUDED
union floatLong
{
float f;
uint32_t l;
#ifdef SUPPORT_64_BIT_MATH
uint64_t L;
#endif
};
union wizardVar {
float f;
int32_t l;
uint32_t ul;
int16_t i;
uint16_t ui;
int8_t c;
uint8_t uc;
wizardVar():i(0) {}
wizardVar(float _f):f(_f) {}
wizardVar(int32_t _f):l(_f) {}
wizardVar(uint32_t _f):ul(_f) {}
wizardVar(int16_t _f):i(_f) {}
wizardVar(uint16_t _f):ui(_f) {}
wizardVar(int8_t _f):c(_f) {}
wizardVar(uint8_t _f):uc(_f) {}
};
#define PRINTER_FLAG0_STEPPER_DISABLED 1
#define PRINTER_FLAG0_SEPERATE_EXTRUDER_INT 2
#define PRINTER_FLAG0_TEMPSENSOR_DEFECT 4
#define PRINTER_FLAG0_FORCE_CHECKSUM 8
#define PRINTER_FLAG0_MANUAL_MOVE_MODE 16
#define PRINTER_FLAG0_AUTOLEVEL_ACTIVE 32
#define PRINTER_FLAG0_ZPROBEING 64
#define PRINTER_FLAG0_LARGE_MACHINE 128
#define PRINTER_FLAG1_HOMED 1
#define PRINTER_FLAG1_AUTOMOUNT 2
#define PRINTER_FLAG1_ANIMATION 4
#define PRINTER_FLAG1_ALLKILLED 8
#define PRINTER_FLAG1_UI_ERROR_MESSAGE 16
#define PRINTER_FLAG1_NO_DESTINATION_CHECK 32
#define PRINTER_FLAG1_POWER_ON 64
#define PRINTER_FLAG1_ALLOW_COLD_EXTRUSION 128
#define PRINTER_FLAG2_BLOCK_RECEIVING 1
#define PRINTER_FLAG2_AUTORETRACT 2
// define an integer number of steps more than large enough to get to endstop from anywhere
#define HOME_DISTANCE_STEPS (Printer::zMaxSteps-Printer::zMinSteps+1000)
#define HOME_DISTANCE_MM (HOME_DISTANCE_STEPS * invAxisStepsPerMM[Z_AXIS])
// Some dfines to make clearer reading, as we overload these cartesion memory locations for delta
#define towerAMaxSteps Printer::xMaxSteps
#define towerBMaxSteps Printer::yMaxSteps
#define towerCMaxSteps Printer::zMaxSteps
#define towerAMinSteps Printer::xMinSteps
#define towerBMinSteps Printer::yMinSteps
#define towerCMinSteps Printer::zMinSteps
#if DISTORTION_CORRECTION
class Distortion
{
public:
Distortion();
void init();
void enable(bool permanent = true);
void disable(bool permanent = true);
void measure(void);
int32_t correct(int32_t x, int32_t y, int32_t z) const;
void updateDerived();
void reportStatus();
private:
inline int matrixIndex(fast8_t x, fast8_t y) const;
inline int32_t getMatrix(int index) const;
inline void setMatrix(int32_t val, int index);
bool isCorner(fast8_t i, fast8_t j) const;
inline int32_t extrapolatePoint(fast8_t x1, fast8_t y1, fast8_t x2, fast8_t y2) const;
void extrapolateCorner(fast8_t x, fast8_t y, fast8_t dx, fast8_t dy);
void extrapolateCorners();
void resetCorrection();
// attributes
int32_t step;
int32_t radiusCorrectionSteps;
int32_t zStart,zEnd;
#if !DISTORTION_PERMANENT
int32_t matrix[DISTORTION_CORRECTION_POINTS * DISTORTION_CORRECTION_POINTS];
#endif
bool enabled;
};
#endif //DISTORTION_CORRECTION
class Printer
{
public:
#if USE_ADVANCE
static volatile int extruderStepsNeeded; ///< This many extruder steps are still needed, <0 = reverse steps needed.
static uint8_t minExtruderSpeed; ///< Timer delay for start extruder speed
static uint8_t maxExtruderSpeed; ///< Timer delay for end extruder speed
//static uint8_t extruderAccelerateDelay; ///< delay between 2 speec increases
static int advanceStepsSet;
#if ENABLE_QUADRATIC_ADVANCE
static long advanceExecuted; ///< Executed advance steps
#endif
#endif
static uint8_t menuMode;
static float axisStepsPerMM[];
static float invAxisStepsPerMM[];
static float maxFeedrate[];
static float homingFeedrate[];
static float maxAccelerationMMPerSquareSecond[];
static float maxTravelAccelerationMMPerSquareSecond[];
static unsigned long maxPrintAccelerationStepsPerSquareSecond[];
static unsigned long maxTravelAccelerationStepsPerSquareSecond[];
static uint8_t relativeCoordinateMode; ///< Determines absolute (false) or relative Coordinates (true).
static uint8_t relativeExtruderCoordinateMode; ///< Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.
static uint8_t unitIsInches;
static uint8_t debugLevel;
static uint8_t flag0,flag1; // 1 = stepper disabled, 2 = use external extruder interrupt, 4 = temp Sensor defect, 8 = homed
static uint8_t flag2;
static uint8_t stepsPerTimerCall;
static uint32_t interval; ///< Last step duration in ticks.
static uint32_t timer; ///< used for acceleration/deceleration timing
static uint32_t stepNumber; ///< Step number in current move.
static float coordinateOffset[Z_AXIS_ARRAY];
static int32_t currentPositionSteps[E_AXIS_ARRAY]; ///< Position in steps from origin.
static float currentPosition[Z_AXIS_ARRAY];
static float lastCmdPos[Z_AXIS_ARRAY]; ///< Last coordinates send by gcodes
static int32_t destinationSteps[E_AXIS_ARRAY]; ///< Target position in steps.
static float extrudeMultiplyError; ///< Accumulated error during extrusion
static float extrusionFactor; ///< Extrusion multiply factor
#if NONLINEAR_SYSTEM
static int32_t maxDeltaPositionSteps;
static int32_t currentDeltaPositionSteps[E_TOWER_ARRAY];
static floatLong deltaDiagonalStepsSquaredA;
static floatLong deltaDiagonalStepsSquaredB;
static floatLong deltaDiagonalStepsSquaredC;
static float deltaMaxRadiusSquared;
static int32_t deltaFloorSafetyMarginSteps;
static int32_t deltaAPosXSteps;
static int32_t deltaAPosYSteps;
static int32_t deltaBPosXSteps;
static int32_t deltaBPosYSteps;
static int32_t deltaCPosXSteps;
static int32_t deltaCPosYSteps;
static int32_t realDeltaPositionSteps[TOWER_ARRAY];
static int16_t travelMovesPerSecond;
static int16_t printMovesPerSecond;
static float radius0;
#endif
#if FEATURE_Z_PROBE || MAX_HARDWARE_ENDSTOP_Z || NONLINEAR_SYSTEM
static int32_t stepsRemainingAtZHit;
#endif
#if DRIVE_SYSTEM==DELTA
static int32_t stepsRemainingAtXHit;
static int32_t stepsRemainingAtYHit;
#endif
#if SOFTWARE_LEVELING
static int32_t levelingP1[3];
static int32_t levelingP2[3];
static int32_t levelingP3[3];
#endif
#if FEATURE_AUTOLEVEL
static float autolevelTransformation[9]; ///< Transformation matrix
#endif
static signed char zBabystepsMissing;
static float minimumSpeed; ///< lowest allowed speed to keep integration error small
static float minimumZSpeed; ///< lowest allowed speed to keep integration error small
static int32_t xMaxSteps; ///< For software endstops, limit of move in positive direction.
static int32_t yMaxSteps; ///< For software endstops, limit of move in positive direction.
static int32_t zMaxSteps; ///< For software endstops, limit of move in positive direction.
static int32_t xMinSteps; ///< For software endstops, limit of move in negative direction.
static int32_t yMinSteps; ///< For software endstops, limit of move in negative direction.
static int32_t zMinSteps; ///< For software endstops, limit of move in negative direction.
static float xLength;
static float xMin;
static float yLength;
static float yMin;
static float zLength;
static float zMin;
static float feedrate; ///< Last requested feedrate.
static int feedrateMultiply; ///< Multiplier for feedrate in percent (factor 1 = 100)
static unsigned int extrudeMultiply; ///< Flow multiplier in percdent (factor 1 = 100)
static float maxJerk; ///< Maximum allowed jerk in mm/s
#if DRIVE_SYSTEM!=DELTA
static float maxZJerk; ///< Maximum allowed jerk in z direction in mm/s
#endif
static float offsetX; ///< X-offset for different extruder positions.
static float offsetY; ///< Y-offset for different extruder positions.
static speed_t vMaxReached; ///< Maximumu reached speed
static uint32_t msecondsPrinting; ///< Milliseconds of printing time (means time with heated extruder)
static float filamentPrinted; ///< mm of filament printed since counting started
static uint8_t wasLastHalfstepping; ///< Indicates if last move had halfstepping enabled
#if ENABLE_BACKLASH_COMPENSATION
static float backlashX;
static float backlashY;
static float backlashZ;
static uint8_t backlashDir;
#endif
#ifdef DEBUG_STEPCOUNT
static long totalStepsRemaining;
#endif
static float memoryX;
static float memoryY;
static float memoryZ;
static float memoryE;
static float memoryF;
#if GANTRY
static int8_t motorX;
static int8_t motorYorZ;
#endif
#ifdef DEBUG_SEGMENT_LENGTH
static float maxRealSegmentLength;
#endif
#ifdef DEBUG_REAL_JERK
static float maxRealJerk;
#endif
static fast8_t wizardStackPos;
static wizardVar wizardStack[WIZARD_STACK_SIZE];
static inline void setMenuMode(uint8_t mode,bool on)
{
if(on)
menuMode |= mode;
else
menuMode &= ~mode;
}
static inline bool isMenuMode(uint8_t mode)
{
return (menuMode & mode)==mode;
}
static inline bool debugEcho()
{
return ((debugLevel & 1)!=0);
}
static inline bool debugInfo()
{
return ((debugLevel & 2)!=0);
}
static inline bool debugErrors()
{
return ((debugLevel & 4)!=0);
}
static inline bool debugDryrun()
{
return ((debugLevel & 8)!=0);
}
static inline bool debugCommunication()
{
return ((debugLevel & 16)!=0);
}
static inline bool debugNoMoves()
{
return ((debugLevel & 32)!=0);
}
static inline bool debugFlag(unsigned long flags)
{
return (debugLevel & flags);
}
static inline void debugSet(unsigned long flags)
{
debugLevel |= flags;
}
static inline void debugReset(unsigned long flags)
{
debugLevel &= ~flags;
}
/** \brief Disable stepper motor for x direction. */
static inline void disableXStepper()
{
#if (X_ENABLE_PIN > -1)
WRITE(X_ENABLE_PIN,!X_ENABLE_ON);
#endif
#if FEATURE_TWO_XSTEPPER && (X2_ENABLE_PIN > -1)
WRITE(X2_ENABLE_PIN,!X_ENABLE_ON);
#endif
}
/** \brief Disable stepper motor for y direction. */
static inline void disableYStepper()
{
#if (Y_ENABLE_PIN > -1)
WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON);
#endif
#if FEATURE_TWO_YSTEPPER && (Y2_ENABLE_PIN > -1)
WRITE(Y2_ENABLE_PIN,!Y_ENABLE_ON);
#endif
}
/** \brief Disable stepper motor for z direction. */
static inline void disableZStepper()
{
#if (Z_ENABLE_PIN > -1)
WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON);
#endif
#if FEATURE_TWO_ZSTEPPER && (Z2_ENABLE_PIN > -1)
WRITE(Z2_ENABLE_PIN,!Z_ENABLE_ON);
#endif
}
/** \brief Enable stepper motor for x direction. */
static inline void enableXStepper()
{
#if (X_ENABLE_PIN > -1)
WRITE(X_ENABLE_PIN, X_ENABLE_ON);
#endif
#if FEATURE_TWO_XSTEPPER && (X2_ENABLE_PIN > -1)
WRITE(X2_ENABLE_PIN,X_ENABLE_ON);
#endif
}
/** \brief Enable stepper motor for y direction. */
static inline void enableYStepper()
{
#if (Y_ENABLE_PIN > -1)
WRITE(Y_ENABLE_PIN, Y_ENABLE_ON);
#endif
#if FEATURE_TWO_YSTEPPER && (Y2_ENABLE_PIN > -1)
WRITE(Y2_ENABLE_PIN,Y_ENABLE_ON);
#endif
}
/** \brief Enable stepper motor for z direction. */
static inline void enableZStepper()
{
#if (Z_ENABLE_PIN > -1)
WRITE(Z_ENABLE_PIN, Z_ENABLE_ON);
#endif
#if FEATURE_TWO_ZSTEPPER && (Z2_ENABLE_PIN > -1)
WRITE(Z2_ENABLE_PIN,Z_ENABLE_ON);
#endif
}
static inline void setXDirection(bool positive)
{
if(positive)
{
WRITE(X_DIR_PIN,!INVERT_X_DIR);
#if FEATURE_TWO_XSTEPPER
WRITE(X2_DIR_PIN,!INVERT_X_DIR);
#endif
}
else
{
WRITE(X_DIR_PIN,INVERT_X_DIR);
#if FEATURE_TWO_XSTEPPER
WRITE(X2_DIR_PIN,INVERT_X_DIR);
#endif
}
}
static inline void setYDirection(bool positive)
{
if(positive)
{
WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
#if FEATURE_TWO_YSTEPPER
WRITE(Y2_DIR_PIN,!INVERT_Y_DIR);
#endif
}
else
{
WRITE(Y_DIR_PIN,INVERT_Y_DIR);
#if FEATURE_TWO_YSTEPPER
WRITE(Y2_DIR_PIN,INVERT_Y_DIR);
#endif
}
}
static inline void setZDirection(bool positive)
{
if(positive)
{
WRITE(Z_DIR_PIN,!INVERT_Z_DIR);
#if FEATURE_TWO_ZSTEPPER
WRITE(Z2_DIR_PIN,!INVERT_Z_DIR);
#endif
}
else
{
WRITE(Z_DIR_PIN,INVERT_Z_DIR);
#if FEATURE_TWO_ZSTEPPER
WRITE(Z2_DIR_PIN,INVERT_Z_DIR);
#endif
}
}
static inline bool getZDirection()
{
return ((READ(Z_DIR_PIN)!=0) ^ INVERT_Z_DIR);
}
static inline bool getYDirection()
{
return((READ(Y_DIR_PIN)!=0) ^ INVERT_Y_DIR);
}
static inline bool getXDirection()
{
return((READ(X_DIR_PIN)!=0) ^ INVERT_X_DIR);
}
static inline uint8_t isLargeMachine()
{
return flag0 & PRINTER_FLAG0_LARGE_MACHINE;
}
static inline void setLargeMachine(uint8_t b)
{
flag0 = (b ? flag0 | PRINTER_FLAG0_LARGE_MACHINE : flag0 & ~PRINTER_FLAG0_LARGE_MACHINE);
}
static inline uint8_t isAdvanceActivated()
{
return flag0 & PRINTER_FLAG0_SEPERATE_EXTRUDER_INT;
}
static inline void setAdvanceActivated(uint8_t b)
{
flag0 = (b ? flag0 | PRINTER_FLAG0_SEPERATE_EXTRUDER_INT : flag0 & ~PRINTER_FLAG0_SEPERATE_EXTRUDER_INT);
}
static inline uint8_t isHomed()
{
return flag1 & PRINTER_FLAG1_HOMED;
}
static inline void setHomed(uint8_t b)
{
flag1 = (b ? flag1 | PRINTER_FLAG1_HOMED : flag1 & ~PRINTER_FLAG1_HOMED);
}
static inline uint8_t isAllKilled()
{
return flag1 & PRINTER_FLAG1_ALLKILLED;
}
static inline void setAllKilled(uint8_t b)
{
flag1 = (b ? flag1 | PRINTER_FLAG1_ALLKILLED : flag1 & ~PRINTER_FLAG1_ALLKILLED);
}
static inline uint8_t isAutomount()
{
return flag1 & PRINTER_FLAG1_AUTOMOUNT;
}
static inline void setAutomount(uint8_t b)
{
flag1 = (b ? flag1 | PRINTER_FLAG1_AUTOMOUNT : flag1 & ~PRINTER_FLAG1_AUTOMOUNT);
}
static inline uint8_t isAnimation()
{
return flag1 & PRINTER_FLAG1_ANIMATION;
}
static inline void setAnimation(uint8_t b)
{
flag1 = (b ? flag1 | PRINTER_FLAG1_ANIMATION : flag1 & ~PRINTER_FLAG1_ANIMATION);
}
static inline uint8_t isUIErrorMessage()
{
return flag1 & PRINTER_FLAG1_UI_ERROR_MESSAGE;
}
static inline void setUIErrorMessage(uint8_t b)
{
flag1 = (b ? flag1 | PRINTER_FLAG1_UI_ERROR_MESSAGE : flag1 & ~PRINTER_FLAG1_UI_ERROR_MESSAGE);
}
static inline uint8_t isNoDestinationCheck()
{
return flag1 & PRINTER_FLAG1_NO_DESTINATION_CHECK;
}
static inline void setNoDestinationCheck(uint8_t b)
{
flag1 = (b ? flag1 | PRINTER_FLAG1_NO_DESTINATION_CHECK : flag1 & ~PRINTER_FLAG1_NO_DESTINATION_CHECK);
}
static inline uint8_t isPowerOn()
{
return flag1 & PRINTER_FLAG1_POWER_ON;
}
static inline void setPowerOn(uint8_t b)
{
flag1 = (b ? flag1 | PRINTER_FLAG1_POWER_ON : flag1 & ~PRINTER_FLAG1_POWER_ON);
}
static inline uint8_t isColdExtrusionAllowed()
{
return flag1 & PRINTER_FLAG1_ALLOW_COLD_EXTRUSION;
}
static inline void setColdExtrusionAllowed(uint8_t b)
{
flag1 = (b ? flag1 | PRINTER_FLAG1_ALLOW_COLD_EXTRUSION : flag1 & ~PRINTER_FLAG1_ALLOW_COLD_EXTRUSION);
if(b)
Com::printFLN(PSTR("Cold extrusion allowed"));
else
Com::printFLN(PSTR("Cold extrusion disallowed"));
}
static inline uint8_t isBlockingReceive()
{
return flag2 & PRINTER_FLAG2_BLOCK_RECEIVING;
}
static inline void setBlockingReceive(uint8_t b)
{
flag2 = (b ? flag2 | PRINTER_FLAG2_BLOCK_RECEIVING : flag2 & ~PRINTER_FLAG2_BLOCK_RECEIVING);
}
static inline uint8_t isAutoretract()
{
return flag2 & PRINTER_FLAG2_AUTORETRACT;
}
static inline void setAutoretract(uint8_t b)
{
flag2 = (b ? flag2 | PRINTER_FLAG2_AUTORETRACT : flag2 & ~PRINTER_FLAG2_AUTORETRACT);
Com::printFLN(PSTR("Autoretract:"),b);
}
static inline void toggleAnimation()
{
setAnimation(!isAnimation());
}
static inline float convertToMM(float x)
{
return (unitIsInches ? x*25.4 : x);
}
static inline bool isXMinEndstopHit()
{
#if X_MIN_PIN>-1 && MIN_HARDWARE_ENDSTOP_X
return READ(X_MIN_PIN) != ENDSTOP_X_MIN_INVERTING;
#else
return false;
#endif
}
static inline bool isYMinEndstopHit()
{
#if Y_MIN_PIN>-1 && MIN_HARDWARE_ENDSTOP_Y
return READ(Y_MIN_PIN) != ENDSTOP_Y_MIN_INVERTING;
#else
return false;
#endif
}
static inline bool isZMinEndstopHit()
{
#if Z_MIN_PIN>-1 && MIN_HARDWARE_ENDSTOP_Z
return READ(Z_MIN_PIN) != ENDSTOP_Z_MIN_INVERTING;
#else
return false;
#endif
}
static inline bool isXMaxEndstopHit()
{
#if X_MAX_PIN>-1 && MAX_HARDWARE_ENDSTOP_X
return READ(X_MAX_PIN) != ENDSTOP_X_MAX_INVERTING;
#else
return false;
#endif
}
static inline bool isYMaxEndstopHit()
{
#if Y_MAX_PIN>-1 && MAX_HARDWARE_ENDSTOP_Y
return READ(Y_MAX_PIN) != ENDSTOP_Y_MAX_INVERTING;
#else
return false;
#endif
}
static inline bool isZMaxEndstopHit()
{
#if Z_MAX_PIN>-1 && MAX_HARDWARE_ENDSTOP_Z
return READ(Z_MAX_PIN) != ENDSTOP_Z_MAX_INVERTING;
#else
return false;
#endif
}
static inline bool areAllSteppersDisabled()
{
return flag0 & PRINTER_FLAG0_STEPPER_DISABLED;
}
static inline void setAllSteppersDiabled()
{
flag0 |= PRINTER_FLAG0_STEPPER_DISABLED;
}
static inline void unsetAllSteppersDisabled()
{
flag0 &= ~PRINTER_FLAG0_STEPPER_DISABLED;
#if FAN_BOARD_PIN>-1
pwm_pos[NUM_EXTRUDER + 1] = 255;
#endif // FAN_BOARD_PIN
}
static inline bool isAnyTempsensorDefect()
{
return (flag0 & PRINTER_FLAG0_TEMPSENSOR_DEFECT);
}
static inline void setAnyTempsensorDefect()
{
flag0 |= PRINTER_FLAG0_TEMPSENSOR_DEFECT;
}
static inline bool isManualMoveMode()
{
return (flag0 & PRINTER_FLAG0_MANUAL_MOVE_MODE);
}
static inline void setManualMoveMode(bool on)
{
flag0 = (on ? flag0 | PRINTER_FLAG0_MANUAL_MOVE_MODE : flag0 & ~PRINTER_FLAG0_MANUAL_MOVE_MODE);
}
static inline bool isAutolevelActive()
{
return (flag0 & PRINTER_FLAG0_AUTOLEVEL_ACTIVE)!=0;
}
static void setAutolevelActive(bool on);
static inline void setZProbingActive(bool on)
{
flag0 = (on ? flag0 | PRINTER_FLAG0_ZPROBEING : flag0 & ~PRINTER_FLAG0_ZPROBEING);
}
static inline bool isZProbingActive()
{
return (flag0 & PRINTER_FLAG0_ZPROBEING);
}
static inline bool isZProbeHit()
{
#if FEATURE_Z_PROBE
return (Z_PROBE_ON_HIGH ? READ(Z_PROBE_PIN) : !READ(Z_PROBE_PIN));
#else
return false;
#endif
}
static inline void executeXYGantrySteps()
{
#if (GANTRY)
if(motorX <= -2)
{
WRITE(X_STEP_PIN,HIGH);
#if FEATURE_TWO_XSTEPPER
WRITE(X2_STEP_PIN,HIGH);
#endif
motorX += 2;
}
else if(motorX >= 2)
{
WRITE(X_STEP_PIN,HIGH);
#if FEATURE_TWO_XSTEPPER
WRITE(X2_STEP_PIN,HIGH);
#endif
motorX -= 2;
}
if(motorYorZ <= -2)
{
WRITE(Y_STEP_PIN,HIGH);
#if FEATURE_TWO_YSTEPPER
WRITE(Y2_STEP_PIN,HIGH);
#endif
motorYorZ += 2;
}
else if(motorYorZ >= 2)
{
WRITE(Y_STEP_PIN,HIGH);
#if FEATURE_TWO_YSTEPPER
WRITE(Y2_STEP_PIN,HIGH);
#endif
motorYorZ -= 2;
}
#endif
}
static inline void executeXZGantrySteps()
{
#if (GANTRY)
if(motorX <= -2)
{
WRITE(X_STEP_PIN,HIGH);
#if FEATURE_TWO_XSTEPPER
WRITE(X2_STEP_PIN,HIGH);
#endif
motorX += 2;
}
else if(motorX >= 2)
{
WRITE(X_STEP_PIN,HIGH);
#if FEATURE_TWO_XSTEPPER
WRITE(X2_STEP_PIN,HIGH);
#endif
motorX -= 2;
}
if(motorYorZ <= -2)
{
//ANALYZER_ON(ANALYZER_CH3); // I dont think i can use these as they are for the y - possible bug area though
WRITE(Z_STEP_PIN,HIGH);
#if FEATURE_TWO_ZSTEPPER
WRITE(Z2_STEP_PIN,HIGH);
#endif
motorYorZ += 2;
}
else if(motorYorZ >= 2)
{
//ANALYZER_ON(ANALYZER_CH3); // I dont think i can use these as they are for the y - possible bug area though
WRITE(Z_STEP_PIN,HIGH);
#if FEATURE_TWO_ZSTEPPER
WRITE(Z2_STEP_PIN,HIGH);
#endif
motorYorZ -= 2;
}
#endif
}
static inline void endXYZSteps()
{
WRITE(X_STEP_PIN,LOW);
WRITE(Y_STEP_PIN,LOW);
WRITE(Z_STEP_PIN,LOW);
#if FEATURE_TWO_XSTEPPER
WRITE(X2_STEP_PIN,LOW);
#endif
#if FEATURE_TWO_YSTEPPER
WRITE(Y2_STEP_PIN,LOW);
#endif
#if FEATURE_TWO_ZSTEPPER
WRITE(Z2_STEP_PIN,LOW);
#endif
}
static inline speed_t updateStepsPerTimerCall(speed_t vbase)
{
if(vbase>STEP_DOUBLER_FREQUENCY)
{
#if ALLOW_QUADSTEPPING
if(vbase>STEP_DOUBLER_FREQUENCY*2)
{
Printer::stepsPerTimerCall = 4;
return vbase>>2;
}
else
{
Printer::stepsPerTimerCall = 2;
return vbase>>1;
}
#else
Printer::stepsPerTimerCall = 2;
return vbase>>1;
#endif
}
else
{
Printer::stepsPerTimerCall = 1;
}
return vbase;
}
static inline void disableAllowedStepper()
{
#if DRIVE_SYSTEM == XZ_GANTRY || DRIVE_SYSTEM == ZX_GANTRY
if(DISABLE_X && DISABLE_Z)
{
disableXStepper();
disableZStepper();
}
if(DISABLE_Y) disableYStepper();
#else
#if GANTRY
if(DISABLE_X && DISABLE_Y)
{
disableXStepper();
disableYStepper();
}
#else
if(DISABLE_X) disableXStepper();
if(DISABLE_Y) disableYStepper();
#endif
if(DISABLE_Z) disableZStepper();
#endif
}
static inline float realXPosition()
{
return currentPosition[X_AXIS];
}
static inline float realYPosition()
{
return currentPosition[Y_AXIS];
}
static inline float realZPosition()
{
return currentPosition[Z_AXIS];
}
static inline void realPosition(float &xp, float &yp, float &zp)
{
xp = currentPosition[X_AXIS];
yp = currentPosition[Y_AXIS];
zp = currentPosition[Z_AXIS];
}
static inline void insertStepperHighDelay()
{
#if STEPPER_HIGH_DELAY>0
HAL::delayMicroseconds(STEPPER_HIGH_DELAY);
#endif
}
static void constrainDestinationCoords();
static void updateDerivedParameter();
static void updateCurrentPosition(bool copyLastCmd = false);
static void kill(uint8_t only_steppers);
static void updateAdvanceFlags();
static void setup();
static void defaultLoopActions();
static uint8_t setDestinationStepsFromGCode(GCode *com);
static uint8_t moveTo(float x,float y,float z,float e,float f);
static uint8_t moveToReal(float x,float y,float z,float e,float f);
static void homeAxis(bool xaxis,bool yaxis,bool zaxis); /// Home axis
static void setOrigin(float xOff,float yOff,float zOff);
static bool isPositionAllowed(float x,float y,float z);
static inline int getFanSpeed()
{
return (int)pwm_pos[NUM_EXTRUDER + 2];
}
#if NONLINEAR_SYSTEM
static inline void setDeltaPositions(long xaxis, long yaxis, long zaxis)
{
currentDeltaPositionSteps[A_TOWER] = xaxis;
currentDeltaPositionSteps[B_TOWER] = yaxis;
currentDeltaPositionSteps[C_TOWER] = zaxis;
}
static void deltaMoveToTopEndstops(float feedrate);
#endif
#if MAX_HARDWARE_ENDSTOP_Z
static float runZMaxProbe();
#endif
#if FEATURE_Z_PROBE
static float runZProbe(bool first,bool last,uint8_t repeat = Z_PROBE_REPETITIONS,bool runStartScript = true);
static void waitForZProbeStart();
#endif
// Moved outside FEATURE_Z_PROBE to allow auto-level functional test on
// system without Z-probe
#if FEATURE_AUTOLEVEL
static void transformToPrinter(float x,float y,float z,float &transX,float &transY,float &transZ);
static void transformFromPrinter(float x,float y,float z,float &transX,float &transY,float &transZ);
static void resetTransformationMatrix(bool silent);
static void buildTransformationMatrix(float h1,float h2,float h3);
#endif
#if DISTORTION_CORRECTION
static void measureDistortion(void);
static Distortion distortion;
#endif
static void MemoryPosition();
static void GoToMemoryPosition(bool x,bool y,bool z,bool e,float feed);
static void zBabystep();
static inline void resetWizardStack() {wizardStackPos = 0;}
static inline void pushWizardVar(wizardVar v) {wizardStack[wizardStackPos++] = v;}
static inline wizardVar popWizardVar() {return wizardStack[--wizardStackPos];}
static void showConfiguration();
static void setCaseLight(bool on);
static void reportCaseLightStatus();
private:
static void homeXAxis();
static void homeYAxis();
static void homeZAxis();
};
#endif // PRINTER_H_INCLUDED

View File

@ -0,0 +1,595 @@
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Repetier-Firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
This firmware is a nearly complete rewrite of the sprinter firmware
by kliment (https://github.com/kliment/Sprinter)
which based on Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
*/
#ifndef _REPETIER_H
#define _REPETIER_H
//#define REPETIER_VERSION "0.92.2"
// ##########################################################################################
// ## Debug configuration ##
// ##########################################################################################
// These are run time sqitchable debug flags
enum debugFlags {DEB_ECHO= 0x1, DEB_INFO=0x2, DEB_ERROR =0x4,DEB_DRYRUN=0x8,
DEB_COMMUNICATION=0x10, DEB_NOMOVES=0x20, DEB_DEBUG=0x40};
/** Uncomment, to see detailed data for every move. Only for debugging purposes! */
//#define DEBUG_QUEUE_MOVE
/** Allows M111 to set bit 5 (16) which disables all commands except M111. This can be used
to test your data througput or search for communication problems. */
#define INCLUDE_DEBUG_COMMUNICATION 1
/** Allows M111 so set bit 6 (32) which disables moves, at the first tried step. In combination
with a dry run, you can test the speed of path computations, which are still performed. */
#define INCLUDE_DEBUG_NO_MOVE 1
/** Writes the free RAM to output, if it is less then at the last test. Should always return
values >500 for safety, since it doesn't catch every function call. Nice to tweak cache
usage or for seraching for memory induced errors. Switch it off for production, it costs execution time. */
//#define DEBUG_FREE_MEMORY
//#define DEBUG_ADVANCE
/** If enabled, writes the created generic table to serial port at startup. */
//#define DEBUG_GENERIC
/** If enabled, steps to move and moved steps are compared. */
//#define DEBUG_STEPCOUNT
/** This enables code to make M666 drop an ok, so you get problems with communication. It is to test host robustness. */
#define DEBUG_COM_ERRORS
/** Adds a menu point in quick settings to write debg informations to the host in case of hangs where the ui still works. */
//#define DEBUG_PRINT
//#define DEBUG_DELTA_OVERFLOW
//#define DEBUG_DELTA_REALPOS
//#define DEBUG_SPLIT
// Find the longest segment length during a print
//#define DEBUG_SEGMENT_LENGTH
// Find the maximum real jerk during a print
//#define DEBUG_REAL_JERK
// Uncomment the following line to enable debugging. You can better control debugging below the following line
//#define DEBUG
#define CARTESIAN 0
#define XY_GANTRY 1
#define YX_GANTRY 2
#define DELTA 3
#define TUGA 4
#define BIPOD 5
#define XZ_GANTRY 8
#define ZX_GANTRY 9
#define WIZARD_STACK_SIZE 8
// Uncomment if no analyzer is connected
//#define ANALYZER
// Channel->pin assignments
#define ANALYZER_CH0 63 // New move
#define ANALYZER_CH1 40 // Step loop
#define ANALYZER_CH2 53 // X Step
#define ANALYZER_CH3 65 // Y Step
#define ANALYZER_CH4 59 // X Direction
#define ANALYZER_CH5 64 // Y Direction
#define ANALYZER_CH6 58 // xsig
#define ANALYZER_CH7 57 // ysig
#ifdef ANALYZER
#define ANALYZER_ON(a) {WRITE(a,HIGH);}
#define ANALYZER_OFF(a) {WRITE(a,LOW);}
#else
#define ANALYZER_ON(a)
#define ANALYZER_OFF(a)
#endif
#define X_AXIS 0
#define Y_AXIS 1
#define Z_AXIS 2
#define E_AXIS 3
#define VIRTUAL_AXIS 4
// How big an array to hold X_AXIS..<MAX_AXIS>
#define Z_AXIS_ARRAY 3
#define E_AXIS_ARRAY 4
#define VIRTUAL_AXIS_ARRAY 5
#define A_TOWER 0
#define B_TOWER 1
#define C_TOWER 2
#define TOWER_ARRAY 3
#define E_TOWER_ARRAY 4
// Bits of the ADC converter
#define ANALOG_INPUT_BITS 10
// Build median from 2^ANALOG_INPUT_SAMPLE samples
#if CPU_ARCH == ARCH_AVR
#define ANALOG_INPUT_SAMPLE 5
#else
#define ANALOG_INPUT_SAMPLE 4
#endif
#define ANALOG_REF_AREF 0
#define ANALOG_REF_AVCC _BV(REFS0)
#define ANALOG_REF_INT_1_1 _BV(REFS1)
#define ANALOG_REF_INT_2_56 _BV(REFS0) | _BV(REFS1)
#define ANALOG_REF ANALOG_REF_AVCC
// MS1 MS2 Stepper Driver Microstepping mode table
#define MICROSTEP1 LOW,LOW
#define MICROSTEP2 HIGH,LOW
#define MICROSTEP4 LOW,HIGH
#define MICROSTEP8 HIGH,HIGH
#define MICROSTEP16 HIGH,HIGH
#define HOME_ORDER_XYZ 1
#define HOME_ORDER_XZY 2
#define HOME_ORDER_YXZ 3
#define HOME_ORDER_YZX 4
#define HOME_ORDER_ZXY 5
#define HOME_ORDER_ZYX 6
#define NO_CONTROLLER 0
#define UICONFIG_CONTROLLER 1
#define CONTROLLER_SMARTRAMPS 2
#define CONTROLLER_ADAFRUIT 3
#define CONTROLLER_FOLTYN 4
#define CONTROLLER_VIKI 5
#define CONTROLLER_MEGATRONIC 6
#define CONTROLLER_RADDS 7
#define CONTROLLER_PIBOT20X4 8
#define CONTROLLER_PIBOT16X2 9
#define CONTROLLER_GADGETS3D_SHIELD 10
#define CONTROLLER_REPRAPDISCOUNT_GLCD 11
#define CONTROLLER_FELIX 12
#define CONTROLLER_RAMBO 13
#define CONTROLLER_OPENHARDWARE_LCD2004 14
#define CONTROLLER_SANGUINOLOLU_PANELOLU2 15
#define CONTROLLER_GAMEDUINO2 16
#define CONTROLLER_MIREGLI 17
//direction flags
#define X_DIRPOS 1
#define Y_DIRPOS 2
#define Z_DIRPOS 4
#define E_DIRPOS 8
#define XYZ_DIRPOS 7
//step flags
#define XSTEP 16
#define YSTEP 32
#define ZSTEP 64
#define ESTEP 128
//combo's
#define XYZ_STEP 112
#define XY_STEP 48
#define XYZE_STEP 240
#define E_STEP_DIRPOS 136
#define Y_STEP_DIRPOS 34
#define X_STEP_DIRPOS 17
#define Z_STEP_DIRPOS 68
// add pid control
#define TEMP_PID 1
#include "Configuration.h"
#define GCODE_BUFFER_SIZE 1
#ifndef FEATURE_BABYSTEPPING
#define FEATURE_BABYSTEPPING 0
#define BABYSTEP_MULTIPLICATOR 1
#endif
#if !defined(Z_PROBE_REPETITIONS) || Z_PROBE_REPETITIONS < 1
#define Z_PROBE_SWITCHING_DISTANCE 0.5 // Distance to safely untrigger probe
#define Z_PROBE_REPETITIONS 1
#endif
#define SPEED_MIN_MILLIS 300
#define SPEED_MAX_MILLIS 50
#define SPEED_MAGNIFICATION 100.0f
//#define SOFTWARE_LEVELING (FEATURE_SOFTWARE_LEVELING && (DRIVE_SYSTEM==DELTA))
/** \brief Horizontal distance bridged by the diagonal push rod when the end effector is in the center. It is pretty close to 50% of the push rod length (250 mm).
*/
#if PRINTER == 5
#define ROD_RADIUS 144.0
#else
#define ROD_RADIUS (PRINTER_RADIUS-END_EFFECTOR_HORIZONTAL_OFFSET-CARRIAGE_HORIZONTAL_OFFSET)
#endif
#ifndef UI_SPEEDDEPENDENT_POSITIONING
#define UI_SPEEDDEPENDENT_POSITIONING true
#endif
#if DRIVE_SYSTEM==DELTA || DRIVE_SYSTEM==TUGA || DRIVE_SYSTEM==BIPOD
#define NONLINEAR_SYSTEM 1
#else
#define NONLINEAR_SYSTEM 0
#endif
#ifdef FEATURE_Z_PROBE
#define MANUAL_CONTROL 1
#endif
#define GANTRY ( DRIVE_SYSTEM==XY_GANTRY || DRIVE_SYSTEM==YX_GANTRY || DRIVE_SYSTEM==XZ_GANTRY || DRIVE_SYSTEM==ZX_GANTRY)
//Step to split a cirrcle in small Lines
#ifndef MM_PER_ARC_SEGMENT
#define MM_PER_ARC_SEGMENT 1
#define MM_PER_ARC_SEGMENT_BIG 3
#else
#define MM_PER_ARC_SEGMENT_BIG MM_PER_ARC_SEGMENT
#endif
//After this count of steps a new SIN / COS caluclation is startet to correct the circle interpolation
#define N_ARC_CORRECTION 25
// Test for shared cooler
#if NUM_EXTRUDER == 6 && EXT0_EXTRUDER_COOLER_PIN > -1 && EXT0_EXTRUDER_COOLER_PIN == EXT1_EXTRUDER_COOLER_PIN && EXT2_EXTRUDER_COOLER_PIN == EXT3_EXTRUDER_COOLER_PIN && EXT4_EXTRUDER_COOLER_PIN == EXT5_EXTRUDER_COOLER_PIN && EXT0_EXTRUDER_COOLER_PIN == EXT2_EXTRUDER_COOLER_PIN && EXT0_EXTRUDER_COOLER_PIN == EXT4_EXTRUDER_COOLER_PIN
#define SHARED_COOLER 1
#elif NUM_EXTRUDER == 5 && EXT0_EXTRUDER_COOLER_PIN > -1 && EXT0_EXTRUDER_COOLER_PIN == EXT1_EXTRUDER_COOLER_PIN && EXT2_EXTRUDER_COOLER_PIN == EXT3_EXTRUDER_COOLER_PIN && EXT3_EXTRUDER_COOLER_PIN == EXT5_EXTRUDER_COOLER_PIN && EXT0_EXTRUDER_COOLER_PIN == EXT2_EXTRUDER_COOLER_PIN
#define SHARED_COOLER 1
#elif NUM_EXTRUDER == 4 && EXT0_EXTRUDER_COOLER_PIN > -1 && EXT0_EXTRUDER_COOLER_PIN == EXT1_EXTRUDER_COOLER_PIN && EXT2_EXTRUDER_COOLER_PIN == EXT3_EXTRUDER_COOLER_PIN && EXT0_EXTRUDER_COOLER_PIN == EXT2_EXTRUDER_COOLER_PIN
#define SHARED_COOLER 1
#elif NUM_EXTRUDER == 3 && EXT0_EXTRUDER_COOLER_PIN > -1 && EXT0_EXTRUDER_COOLER_PIN == EXT1_EXTRUDER_COOLER_PIN && EXT2_EXTRUDER_COOLER_PIN == EXT0_EXTRUDER_COOLER_PIN
#define SHARED_COOLER 1
#elif NUM_EXTRUDER == 2 && EXT0_EXTRUDER_COOLER_PIN > -1 && EXT0_EXTRUDER_COOLER_PIN == EXT1_EXTRUDER_COOLER_PIN
#define SHARED_COOLER 1
#else
#define SHARED_COOLER 0
#endif
#if NUM_EXTRUDER>0 && EXT0_TEMPSENSOR_TYPE<101
#define EXT0_ANALOG_INPUTS 1
#define EXT0_SENSOR_INDEX 0
#define EXT0_ANALOG_CHANNEL EXT0_TEMPSENSOR_PIN
#define ACCOMMA0 ,
#else
#define ACCOMMA0
#define EXT0_ANALOG_INPUTS 0
#define EXT0_SENSOR_INDEX EXT0_TEMPSENSOR_PIN
#define EXT0_ANALOG_CHANNEL
#endif
#if NUM_EXTRUDER>1 && EXT1_TEMPSENSOR_TYPE<101
#define EXT1_ANALOG_INPUTS 1
#define EXT1_SENSOR_INDEX EXT0_ANALOG_INPUTS
#define EXT1_ANALOG_CHANNEL ACCOMMA0 EXT1_TEMPSENSOR_PIN
#define ACCOMMA1 ,
#else
#define ACCOMMA1 ACCOMMA0
#define EXT1_ANALOG_INPUTS 0
#define EXT1_SENSOR_INDEX EXT1_TEMPSENSOR_PIN
#define EXT1_ANALOG_CHANNEL
#endif
#if NUM_EXTRUDER>2 && EXT2_TEMPSENSOR_TYPE<101
#define EXT2_ANALOG_INPUTS 1
#define EXT2_SENSOR_INDEX EXT0_ANALOG_INPUTS+EXT1_ANALOG_INPUTS
#define EXT2_ANALOG_CHANNEL ACCOMMA1 EXT2_TEMPSENSOR_PIN
#define ACCOMMA2 ,
#else
#define ACCOMMA2 ACCOMMA1
#define EXT2_ANALOG_INPUTS 0
#define EXT2_SENSOR_INDEX EXT2_TEMPSENSOR_PIN
#define EXT2_ANALOG_CHANNEL
#endif
#if NUM_EXTRUDER > 3 && EXT3_TEMPSENSOR_TYPE < 101
#define EXT3_ANALOG_INPUTS 1
#define EXT3_SENSOR_INDEX EXT0_ANALOG_INPUTS+EXT1_ANALOG_INPUTS+EXT2_ANALOG_INPUTS
#define EXT3_ANALOG_CHANNEL ACCOMMA2 EXT3_TEMPSENSOR_PIN
#define ACCOMMA3 ,
#else
#define ACCOMMA3 ACCOMMA2
#define EXT3_ANALOG_INPUTS 0
#define EXT3_SENSOR_INDEX EXT3_TEMPSENSOR_PIN
#define EXT3_ANALOG_CHANNEL
#endif
#if NUM_EXTRUDER > 4 && EXT4_TEMPSENSOR_TYPE < 101
#define EXT4_ANALOG_INPUTS 1
#define EXT4_SENSOR_INDEX EXT0_ANALOG_INPUTS+EXT1_ANALOG_INPUTS+EXT2_ANALOG_INPUTS+EXT3_ANALOG_INPUTS
#define EXT4_ANALOG_CHANNEL ACCOMMA3 EXT4_TEMPSENSOR_PIN
#define ACCOMMA4 ,
#else
#define ACCOMMA4 ACCOMMA3
#define EXT4_ANALOG_INPUTS 0
#define EXT4_SENSOR_INDEX EXT4_TEMPSENSOR_PIN
#define EXT4_ANALOG_CHANNEL
#endif
#if NUM_EXTRUDER>5 && EXT5_TEMPSENSOR_TYPE<101
#define EXT5_ANALOG_INPUTS 1
#define EXT5_SENSOR_INDEX EXT0_ANALOG_INPUTS+EXT1_ANALOG_INPUTS+EXT2_ANALOG_INPUTS+EXT3_ANALOG_INPUTS+EXT4_ANALOG_INPUTS
#define EXT5_ANALOG_CHANNEL ACCOMMA4 EXT5_TEMPSENSOR_PIN
#define ACCOMMA5 ,
#else
#define ACCOMMA5 ACCOMMA4
#define EXT5_ANALOG_INPUTS 0
#define EXT5_SENSOR_INDEX EXT5_TEMPSENSOR_PIN
#define EXT5_ANALOG_CHANNEL
#endif
#if HAVE_HEATED_BED && HEATED_BED_SENSOR_TYPE<101
#define BED_ANALOG_INPUTS 1
#define BED_SENSOR_INDEX EXT0_ANALOG_INPUTS+EXT1_ANALOG_INPUTS+EXT2_ANALOG_INPUTS+EXT3_ANALOG_INPUTS+EXT4_ANALOG_INPUTS+EXT5_ANALOG_INPUTS
#define BED_ANALOG_CHANNEL ACCOMMA5 HEATED_BED_SENSOR_PIN
#undef KOMMA
#define KOMMA ,
#else
#define BED_ANALOG_INPUTS 0
#define BED_SENSOR_INDEX HEATED_BED_SENSOR_PIN
#define BED_ANALOG_CHANNEL
#endif
#ifndef DEBUG_FREE_MEMORY
#define DEBUG_MEMORY
#else
#define DEBUG_MEMORY Commands::checkFreeMemory();
#endif
/** \brief number of analog input signals. Normally 1 for each temperature sensor */
#define ANALOG_INPUTS (EXT0_ANALOG_INPUTS+EXT1_ANALOG_INPUTS+EXT2_ANALOG_INPUTS+EXT3_ANALOG_INPUTS+EXT4_ANALOG_INPUTS+EXT5_ANALOG_INPUTS+BED_ANALOG_INPUTS)
#if ANALOG_INPUTS>0
/** Channels are the MUX-part of ADMUX register */
#define ANALOG_INPUT_CHANNELS {EXT0_ANALOG_CHANNEL EXT1_ANALOG_CHANNEL EXT2_ANALOG_CHANNEL EXT3_ANALOG_CHANNEL EXT4_ANALOG_CHANNEL EXT5_ANALOG_CHANNEL BED_ANALOG_CHANNEL}
#endif
#define MENU_MODE_SD_MOUNTED 1
#define MENU_MODE_SD_PRINTING 2
#define MENU_MODE_SD_PAUSED 4
#define MENU_MODE_FAN_RUNNING 8
#define MENU_MODE_PRINTING 16
#include "HAL.h"
#include "gcode.h"
#define MAX_VFAT_ENTRIES (2)
/** Total size of the buffer used to store the long filenames */
#define LONG_FILENAME_LENGTH (13*MAX_VFAT_ENTRIES+1)
#define SD_MAX_FOLDER_DEPTH 2
#include "ui.h"
#include "Communication.h"
#ifndef SDCARDDETECT
#define SDCARDDETECT -1
#endif
#ifndef SDSUPPORT
#define SDSUPPORT 0
#endif
#if SDSUPPORT
#include "SdFat.h"
#endif
#if ENABLE_BACKLASH_COMPENSATION && DRIVE_SYSTEM!=CARTESIAN
#undef ENABLE_BACKLASH_COMPENSATION
#define ENABLE_BACKLASH_COMPENSATION false
#endif
#define uint uint16_t
#define uint8 uint8_t
#define int8 int8_t
#define uint32 uint32_t
#define int32 int32_t
#define IGNORE_COORDINATE 999999
#undef min
#undef max
class RMath {
public:
static inline float min(float a,float b) {
if(a<b) return a;
return b;
}
static inline float max(float a,float b) {
if(a<b) return b;
return a;
}
static inline int32_t min(int32_t a,int32_t b) {
if(a<b) return a;
return b;
}
static inline int32_t min(int32_t a,int32_t b, int32_t c) {
if(a<b) return a<c ? a : c;
return b<c ? b : c;
}
static inline float min(float a,float b, float c) {
if(a<b) return a<c ? a : c;
return b<c ? b : c;
}
static inline int32_t max(int32_t a,int32_t b) {
if(a<b) return b;
return a;
}
static inline int min(int a,int b) {
if(a<b) return a;
return b;
}
static inline uint16_t min(uint16_t a,uint16_t b) {
if(a<b) return a;
return b;
}
static inline int16_t max(int16_t a,int16_t b) {
if(a<b) return b;
return a;
}
static inline uint16_t max(uint16_t a,uint16_t b) {
if(a<b) return b;
return a;
}
static inline unsigned long absLong(long a) {return a >= 0 ? a : -a;}
static inline int32_t sqr(int32_t a) {return a*a;}
static inline uint32_t sqr(uint32_t a) {return a*a;}
#ifdef SUPPORT_64_BIT_MATH
static inline int64_t sqr(int64_t a) {return a*a;}
static inline uint64_t sqr(uint64_t a) {return a*a;}
#endif
static inline float sqr(float a) {return a*a;}
};
extern const uint8 osAnalogInputChannels[] PROGMEM;
extern uint8 osAnalogInputCounter[ANALOG_INPUTS];
extern uint osAnalogInputBuildup[ANALOG_INPUTS];
extern uint8 osAnalogInputPos; // Current sampling position
extern volatile uint osAnalogInputValues[ANALOG_INPUTS];
extern uint8_t pwm_pos[NUM_EXTRUDER+3]; // 0-NUM_EXTRUDER = Heater 0-NUM_EXTRUDER of extruder, NUM_EXTRUDER = Heated bed, NUM_EXTRUDER+1 Board fan, NUM_EXTRUDER+2 = Fan
#if USE_ADVANCE
#if ENABLE_QUADRATIC_ADVANCE
extern int maxadv;
#endif
extern int maxadv2;
extern float maxadvspeed;
#endif
#include "Extruder.h"
void manage_inactivity(uint8_t debug);
extern void finishNextSegment();
#if NONLINEAR_SYSTEM
extern uint8_t transformCartesianStepsToDeltaSteps(long cartesianPosSteps[], long deltaPosSteps[]);
#if SOFTWARE_LEVELING
extern void calculatePlane(long factors[], long p1[], long p2[], long p3[]);
extern float calcZOffset(long factors[], long pointX, long pointY);
#endif
#endif
extern void linear_move(long steps_remaining[]);
#ifndef FEATURE_DITTO_PRINTING
#define FEATURE_DITTO_PRINTING false
#endif
#if FEATURE_DITTO_PRINTING && (NUM_EXTRUDER > 4 || NUM_EXTRUDER < 2)
#error Ditto printing requires 2 - 4 extruder.
#endif
extern millis_t previousMillisCmd;
extern millis_t maxInactiveTime;
extern millis_t stepperInactiveTime;
extern void setupTimerInterrupt();
extern void motorCurrentControlInit();
extern void microstepInit();
#include "Printer.h"
#include "motion.h"
extern long baudrate;
#if OS_ANALOG_INPUTS>0
// Get last result for pin x
extern volatile uint osAnalogInputValues[OS_ANALOG_INPUTS];
#endif
#include "HAL.h"
extern unsigned int counterPeriodical;
extern volatile uint8_t executePeriodical;
extern uint8_t counter250ms;
extern void writeMonitor();
#if SDSUPPORT
extern char tempLongFilename[LONG_FILENAME_LENGTH+1];
extern char fullName[LONG_FILENAME_LENGTH*SD_MAX_FOLDER_DEPTH+SD_MAX_FOLDER_DEPTH+1];
#define SHORT_FILENAME_LENGTH 14
#include "SdFat.h"
enum LsAction {LS_SerialPrint,LS_Count,LS_GetFilename};
class SDCard {
public:
SdFat fat;
//Sd2Card card; // ~14 Byte
//SdVolume volume;
//SdFile root;
//SdFile dir[SD_MAX_FOLDER_DEPTH+1];
SdFile file;
uint32_t filesize;
uint32_t sdpos;
//char fullName[13*SD_MAX_FOLDER_DEPTH+13]; // Fill name
char *shortname; // Pointer to start of filename itself
char *pathend; // File to char where pathname in fullname ends
uint8_t sdmode; // true if we are printing from sd card, 2 = stop accepting new commands
bool sdactive;
//int16_t n;
bool savetosd;
SdBaseFile parentFound;
SDCard();
void initsd();
void writeCommand(GCode *code);
bool selectFile(const char *filename,bool silent=false);
void mount();
void unmount();
void startPrint();
void pausePrint(bool intern = false);
void continuePrint(bool intern=false);
void stopPrint();
inline void setIndex(uint32_t newpos) { if(!sdactive) return; sdpos = newpos;file.seekSet(sdpos);}
void printStatus();
void ls();
void startWrite(char *filename);
void deleteFile(char *filename);
void finishWrite();
char *createFilename(char *buffer,const dir_t &p);
void makeDirectory(char *filename);
bool showFilename(const uint8_t *name);
void automount();
#ifdef GLENN_DEBUG
void writeToFile();
#endif
private:
uint8_t lsRecursive(SdBaseFile *parent,uint8_t level,char *findFilename);
// SdFile *getDirectory(char* name);
};
extern SDCard sd;
#endif
extern volatile int waitRelax; // Delay filament relax at the end of print, could be a simple timeout
extern void updateStepsParameter(PrintLine *p/*,uint8_t caller*/);
#ifdef DEBUG_PRINT
extern int debugWaitLoop;
#endif
#if NONLINEAR_SYSTEM
#define NUM_AXIS 4
#endif
#define STR(s) #s
#define XSTR(s) STR(s)
#include "Commands.h"
#include "Eeprom.h"
#if CPU_ARCH == ARCH_AVR
#define DELAY1MICROSECOND __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t")
#define DELAY2MICROSECOND __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\tnop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t")
#else
#define DELAY1MICROSECOND HAL::delayMicroseconds(1);
#define DELAY2MICROSECOND HAL::delayMicroseconds(2);
#endif
#ifdef FAST_INTEGER_SQRT
#define SQRT(x) ( HAL::integerSqrt(x) )
#else
#define SQRT(x) sqrt(x)
#endif
#endif

View File

@ -0,0 +1,171 @@
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Repetier-Firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
This firmware is a nearly complete rewrite of the sprinter firmware
by kliment (https://github.com/kliment/Sprinter)
which based on Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
Main author: repetier
*/
/**
\mainpage Repetier-Firmware for Arduino based RepRaps
<CENTER>Copyright &copy; 2011-2013 by repetier
</CENTER>
\section Intro Introduction
\section GCodes Implemented GCodes
look here for descriptions of gcodes: http://linuxcnc.org/handbook/gcode/g-code.html
and http://objects.reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes
Implemented Codes
- G0 -> G1
- G1 - Coordinated Movement X Y Z E, S1 disables boundary check, S0 enables it
- G4 - Dwell S<seconds> or P<milliseconds>
- G10 S<1 = long retract, 0 = short retract = default> retracts filament accoridng to stored setting
- G11 S<1 = long retract, 0 = short retract = default> = Undo retraction according to stored setting
- G20 - Units for G0/G1 are inches.
- G21 - Units for G0/G1 are mm.
- G28 - Home all axis or named axis.
- G29 - SeeMeCNC modded probing code to execute endstop offset>z height>printer radius autocal routine
- G30 - Single z-probe at center S2 stores new z height
- G31 - Write signal of probe sensor
- G32 S<1 or 2> Autolevel print bed. S = 1 measure zLength, S = 2 Measue and store new zLength NOT USED ON ERIS
- G68 - Horizontal Radius calibration NO S1 or S2 needed at all
- G69 - S<1 or 2> Endstop offset probing S1 displays and S2 stores
- G90 - Use absolute coordinates
- G91 - Use relative coordinates
- G92 - Set current position to cordinates given
- G131 - set extruder offset position to 0 - needed for calibration with G132
- G132 - calibrate endstop positions. Call this, after calling G131 and after centering the extruder holder.
RepRap M Codes
- M104 - Set extruder target temp
- M105 - Read current temp
- M106 - Fan on
- M107 - Fan off
- M109 - Wait for extruder current temp to reach target temp.
- M114 - Display current position
Custom M Codes
- M20 - List SD card
- M21 - Init SD card
- M22 - Release SD card
- M23 - Select SD file (M23 filename.g)
- M24 - Start/resume SD print
- M25 - Pause SD print
- M26 - Set SD position in bytes (M26 S12345)
- M27 - Report SD print status
- M28 - Start SD write (M28 filename.g)
- M29 - Stop SD write
- M30 <filename> - Delete file on sd card
- M32 <dirname> create subdirectory
- M42 P<pin number> S<value 0..255> - Change output of pin P to S. Does not work on most important pins.
- M80 - Turn on power supply
- M81 - Turn off power supply
- M82 - Set E codes absolute (default)
- M83 - Set E codes relative while in Absolute Coordinates (G90) mode
- M84 - Disable steppers until next move,
or use S<seconds> to specify an inactivity timeout, after which the steppers will be disabled. S0 to disable the timeout.
- M85 - Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default)
- M92 - Set axisStepsPerMM - same syntax as G92
- M99 S<delayInSec> X0 Y0 Z0 - Disable motors for S seconds (default 10) for given axis.
- M104 S<temp> T<extruder> P1 F1 - Set temperature without wait. P1 = wait for moves to finish, F1 = beep when temp. reached first time
- M105 X0 - Get temperatures. If X0 is added, the raw analog values are also written.
- M112 - Emergency kill
- M115- Capabilities string
- M116 - Wait for all temperatures in a +/- 1 degree range
- M117 <message> - Write message in status row on lcd
- M119 - Report endstop status
- M140 S<temp> F1 - Set bed target temp, F1 makes a beep when temperature is reached the first time
- M163 S<extruderNum> P<weight> - Set weight for this mixing extruder drive
- M164 S<virtNum> P<0 = dont store eeprom,1 = store to eeprom> - Store weights as virtual extruder S
- M190 - Wait for bed current temp to reach target temp.
- M200 T<extruder> D<diameter> - Use volumetric extrusion. Set D0 or omit D to disable volumetric extr. Omit T for current extruder.
- M201 - Set max acceleration in units/s^2 for print moves (M201 X1000 Y1000)
- M202 - Set max acceleration in units/s^2 for travel moves (M202 X1000 Y1000)
- M203 - Set temperture monitor to Sx
- M204 - Set PID parameter X => Kp Y => Ki Z => Kd S<extruder> Default is current extruder. NUM_EXTRUDER=Heated bed
- M205 - Output EEPROM settings
- M206 - Set EEPROM value
- M207 X<XY jerk> Z<Z Jerk> E<ExtruderJerk> - Changes current jerk values, but do not store them in eeprom.
- M209 S<0/1> - Enable/disable autoretraction
- M220 S<Feedrate multiplier in percent> - Increase/decrease given feedrate
- M221 S<Extrusion flow multiplier in percent> - Increase/decrease given flow rate
- M231 S<OPS_MODE> X<Min_Distance> Y<Retract> Z<Backlash> F<ReatrctMove> - Set OPS parameter
- M232 - Read and reset max. advance values
- M233 X<AdvanceK> Y<AdvanceL> - Set temporary advance K-value to X and linear term advanceL to Y
- M251 Measure Z steps from homing stop (Delta printers). S0 - Reset, S1 - Print, S2 - Store to Z length (also EEPROM if enabled)
- M261 read status of interrupt PROBE pin
- M262 read threshold for probe i2c pin if you add S and a value that sets a new value for the interrupt (0-126 7 bit value)
- M280 S<mode> - Set ditto printing mode. mode: 0 = off, 1 = 1 extra extruder, 2 = 2 extra extruder, 3 = 3 extra extruders
- M281 Test if watchdog is running and working.
- M300 S<Frequency> P<DurationMillis> play frequency
- M302 S<0 or 1> - allow cold extrusion. Without S parameter it will allow. S1 will disallow.
- M303 P<extruder/bed> S<printTemerature> X0 - Autodetect pid values. Use P<NUM_EXTRUDER> for heated bed. X0 saves result in EEPROM.
- M320 - Activate autolevel
- M321 - Deactivate autolevel
- M322 - Reset autolevel matrix
- M323 S0/S1 enable disable distortion correction P0 = not permanent, P1 = permanent = default
- M340 P<servoId> S<pulseInUS> : servoID = 0..3, Servos are controlled by a pulse with normally between 500 and 2500 with 1500ms in center position. 0 turns servo off.
- M350 S<mstepsAll> X<mstepsX> Y<mstepsY> Z<mstepsZ> E<mstepsE0> P<mstespE1> : Set microstepping on RAMBO board
- M355 S<0/1> - Turn case light on/off, no S = report status
- M360 - show configuration
- M400 - Wait until move buffers empty.
- M401 - Store x, y and z position.
- M402 - Go to stored position. If X, Y or Z is specified, only these coordinates are used. F changes feedrate fo rthat move.
- M500 Store settings to EEPROM
- M501 Load settings from EEPROM
- M502 Reset settings to the one in configuration.h. Does not store values in EEPROM!
- M600 Change filament
- M908 P<address> S<value> : Set stepper current for digipot (RAMBO board)
*/
#include "Repetier.h"
#include <SPI.h>
#include <Wire.h>
#if UI_DISPLAY_TYPE == DISPLAY_ARDUINO_LIB
//#include <LiquidCrystal.h> // Uncomment this if you are using liquid crystal library
#endif
void accelerometer_init();
void setup()
{
Printer::setup();
accelerometer_init();
}
void loop()
{
Commands::commandLoop();
}

View File

@ -0,0 +1,462 @@
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Repetier-Firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
This firmware is a nearly complete rewrite of the sprinter firmware
by kliment (https://github.com/kliment/Sprinter)
which based on Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
*/
#include "Repetier.h"
#include "ui.h"
#if SDSUPPORT
char tempLongFilename[LONG_FILENAME_LENGTH + 1];
char fullName[LONG_FILENAME_LENGTH * SD_MAX_FOLDER_DEPTH + SD_MAX_FOLDER_DEPTH + 1];
SDCard sd;
SDCard::SDCard()
{
sdmode = 0;
sdactive = false;
savetosd = false;
Printer::setAutomount(false);
}
void SDCard::automount()
{
#if SDCARDDETECT>-1
if(READ(SDCARDDETECT) != SDCARDDETECTINVERTED)
{
if(sdactive) // Card removed
{
Com::printFLN(PSTR("SD card removed"));
#if UI_DISPLAY_TYPE != NO_DISPLAY
uid.executeAction(UI_ACTION_TOP_MENU, true);
#endif
unmount();
UI_STATUS(UI_TEXT_SD_REMOVED);
}
}
else
{
if(!sdactive)
{
UI_STATUS(UI_TEXT_SD_INSERTED);
Com::printFLN(PSTR("SD card inserted")); // Not translateable or host will not understand signal
initsd();
#if UI_DISPLAY_TYPE != NO_DISPLAY
if(sdactive) {
Printer::setAutomount(true);
uid.executeAction(UI_ACTION_SD_PRINT + UI_ACTION_TOPMENU, true);
}
#endif
}
}
#endif
}
void SDCard::initsd()
{
sdactive = false;
#if SDSS >- 1
#if SDCARDDETECT>-1
if(READ(SDCARDDETECT) != SDCARDDETECTINVERTED)
return;
#endif
if(!fat.begin(SDSS, SPI_FULL_SPEED))
{
Com::printFLN(Com::tSDInitFail);
return;
}
sdactive = true;
Printer::setMenuMode(MENU_MODE_SD_MOUNTED, true);
fat.chdir();
#endif
}
void SDCard::mount()
{
sdmode = 0;
initsd();
}
void SDCard::unmount()
{
sdmode = 0;
sdactive = false;
savetosd = false;
Printer::setAutomount(false);
Printer::setMenuMode(MENU_MODE_SD_MOUNTED + MENU_MODE_SD_PAUSED + MENU_MODE_SD_PRINTING, false);
#if UI_DISPLAY_TYPE != NO_DISPLAY && SDSUPPORT
uid.cwd[0] = '/';
uid.cwd[1] = 0;
uid.folderLevel = 0;
#endif
}
void SDCard::startPrint()
{
if(!sdactive) return;
sdmode = 1;
Printer::setMenuMode(MENU_MODE_SD_PRINTING, true);
Printer::setMenuMode(MENU_MODE_SD_PAUSED, false);
}
void SDCard::pausePrint(bool intern)
{
if(!sd.sdactive) return;
sdmode = 2; // finish running line
Printer::setMenuMode(MENU_MODE_SD_PAUSED, true);
/*
if(intern) {
Commands::waitUntilEndOfAllBuffers();
sdmode = 0;
Printer::MemoryPosition();
Printer::moveToReal(IGNORE_COORDINATE, IGNORE_COORDINATE, IGNORE_COORDINATE,
Printer::memoryE - RETRACT_ON_PAUSE,
Printer::maxFeedrate[E_AXIS] / 2);
Printer::moveToReal(0,0, IGNORE_COORDINATE, IGNORE_COORDINATE, Printer::homingFeedrate[Z_AXIS]);
Printer::moveToReal(IGNORE_COORDINATE,IGNORE_COORDINATE, Printer::memoryZ + Z_LIFT_ON_PAUSE, IGNORE_COORDINATE, Printer::homingFeedrate[Z_AXIS]);
Printer::lastCmdPos[X_AXIS] = Printer::currentPosition[X_AXIS];
Printer::lastCmdPos[Y_AXIS] = Printer::currentPosition[Y_AXIS];
Printer::lastCmdPos[Z_AXIS] = Printer::currentPosition[Z_AXIS];
GCode::executeFString(PSTR(PAUSE_START_COMMANDS));
}
*/
}
void SDCard::continuePrint(bool intern)
{
if(!sd.sdactive) return;
/*
if(intern) {
//GCode::executeFString(PSTR(PAUSE_END_COMMANDS));
Printer::GoToMemoryPosition(true, true, false, false, Printer::homingFeedrate[Z_AXIS]);
Printer::GoToMemoryPosition(false, false, true, false, Printer::homingFeedrate[Z_AXIS] / 2.0f);
Printer::GoToMemoryPosition(false, false, false, true, Printer::maxFeedrate[E_AXIS] / 2.0f);
}
*/
Printer::setMenuMode(MENU_MODE_SD_PAUSED, false);
sdmode = 1;
}
void SDCard::stopPrint()
{
if(!sd.sdactive) return;
sdmode = 0;
Printer::setMenuMode(MENU_MODE_SD_PRINTING,false);
Printer::setMenuMode(MENU_MODE_SD_PAUSED,false);
Com::printFLN(PSTR("SD print stopped by user."));
GCode::executeFString(PSTR(SD_RUN_ON_STOP));
if(SD_STOP_HEATER_AND_MOTORS_ON_STOP) {
Commands::waitUntilEndOfAllMoves();
Printer::kill(true);
}
}
void SDCard::writeCommand(GCode *code)
{
unsigned int sum1=0,sum2=0; // for fletcher-16 checksum
uint8_t buf[100];
uint8_t p=2;
file.writeError = false;
int params = 128 | (code->params & ~1);
*(int*)buf = params;
if(code->isV2()) // Read G,M as 16 bit value
{
*(int*)&buf[p] = code->params2;
p+=2;
if(code->hasString())
buf[p++] = strlen(code->text);
if(code->hasM())
{
*(int*)&buf[p] = code->M;
p+=2;
}
if(code->hasG())
{
*(int*)&buf[p]= code->G;
p+=2;
}
}
else
{
if(code->hasM())
{
buf[p++] = (uint8_t)code->M;
}
if(code->hasG())
{
buf[p++] = (uint8_t)code->G;
}
}
if(code->hasX())
{
*(float*)&buf[p] = code->X;
p+=4;
}
if(code->hasY())
{
*(float*)&buf[p] = code->Y;
p+=4;
}
if(code->hasZ())
{
*(float*)&buf[p] = code->Z;
p+=4;
}
if(code->hasE())
{
*(float*)&buf[p] = code->E;
p+=4;
}
if(code->hasF())
{
*(float*)&buf[p] = code->F;
p+=4;
}
if(code->hasT())
{
buf[p++] = code->T;
}
if(code->hasS())
{
*(long int*)&buf[p] = code->S;
p+=4;
}
if(code->hasP())
{
*(long int*)&buf[p] = code->P;
p+=4;
}
if(code->hasI())
{
*(float*)&buf[p] = code->I;
p+=4;
}
if(code->hasJ())
{
*(float*)&buf[p] = code->J;
p+=4;
}
if(code->hasString()) // read 16 uint8_t into string
{
char *sp = code->text;
if(code->isV2())
{
uint8_t i = strlen(code->text);
for(; i; i--) buf[p++] = *sp++;
}
else
{
for(uint8_t i=0; i<16; ++i) buf[p++] = *sp++;
}
}
uint8_t *ptr = buf;
uint8_t len = p;
while (len)
{
uint8_t tlen = len > 21 ? 21 : len;
len -= tlen;
do
{
sum1 += *ptr++;
if(sum1>=255) sum1-=255;
sum2 += sum1;
if(sum2>=255) sum2-=255;
}
while (--tlen);
}
buf[p++] = sum1;
buf[p++] = sum2;
if(params == 128)
{
Com::printErrorFLN(Com::tAPIDFinished);
}
else
file.write(buf,p);
if (file.writeError)
{
Com::printFLN(Com::tErrorWritingToFile);
}
}
char *SDCard::createFilename(char *buffer,const dir_t &p)
{
char *pos = buffer,*src = (char*)p.name;
for (uint8_t i = 0; i < 11; i++,src++)
{
if (*src == ' ') continue;
if (i == 8)
*pos++ = '.';
*pos++ = *src;
}
*pos = 0;
return pos;
}
bool SDCard::showFilename(const uint8_t *name)
{
if (*name == DIR_NAME_DELETED || *name == '.') return false;
return true;
}
int8_t RFstricmp(const char* s1, const char* s2)
{
while(*s1 && (tolower(*s1) == tolower(*s2)))
s1++,s2++;
return (const uint8_t)tolower(*s1)-(const uint8_t)tolower(*s2);
}
int8_t RFstrnicmp(const char* s1, const char* s2, size_t n)
{
while(n--)
{
if(tolower(*s1)!=tolower(*s2))
return (uint8_t)tolower(*s1) - (uint8_t)tolower(*s2);
s1++;
s2++;
}
return 0;
}
void SDCard::ls()
{
SdBaseFile file;
Com::printFLN(Com::tBeginFileList);
fat.chdir();
file.openRoot(fat.vol());
file.ls(0, 0);
Com::printFLN(Com::tEndFileList);
}
bool SDCard::selectFile(const char *filename, bool silent)
{
SdBaseFile parent;
const char *oldP = filename;
boolean bFound;
if(!sdactive) return false;
sdmode = 0;
file.close();
parent = *fat.vwd();
if (file.open(&parent, filename, O_READ))
{
if ((oldP = strrchr(filename, '/')) != NULL)
oldP++;
else
oldP = filename;
if(!silent)
{
Com::printF(Com::tFileOpened, oldP);
Com::printFLN(Com::tSpaceSizeColon,file.fileSize());
}
sdpos = 0;
filesize = file.fileSize();
Com::printFLN(Com::tFileSelected);
return true;
}
else
{
if(!silent)
Com::printFLN(Com::tFileOpenFailed);
return false;
}
}
void SDCard::printStatus()
{
if(sdactive)
{
Com::printF(Com::tSDPrintingByte, sdpos);
Com::printFLN(Com::tSlash, filesize);
}
else
{
Com::printFLN(Com::tNotSDPrinting);
}
}
void SDCard::startWrite(char *filename)
{
if(!sdactive) return;
file.close();
sdmode = 0;
fat.chdir();
if(!file.open(filename, O_CREAT | O_APPEND | O_WRITE | O_TRUNC))
{
Com::printFLN(Com::tOpenFailedFile,filename);
}
else
{
UI_STATUS(UI_TEXT_UPLOADING);
savetosd = true;
Com::printFLN(Com::tWritingToFile,filename);
}
}
void SDCard::finishWrite()
{
if(!savetosd) return; // already closed or never opened
file.sync();
file.close();
savetosd = false;
Com::printFLN(Com::tDoneSavingFile);
UI_CLEAR_STATUS;
}
void SDCard::deleteFile(char *filename)
{
if(!sdactive) return;
sdmode = 0;
file.close();
if(fat.remove(filename))
{
Com::printFLN(Com::tFileDeleted);
}
else
{
if(fat.rmdir(filename))
Com::printFLN(Com::tFileDeleted);
else
Com::printFLN(Com::tDeletionFailed);
}
}
void SDCard::makeDirectory(char *filename)
{
if(!sdactive) return;
sdmode = 0;
file.close();
if(fat.mkdir(filename))
{
Com::printFLN(Com::tDirectoryCreated);
}
else
{
Com::printFLN(Com::tCreationFailed);
}
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,947 @@
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Repetier-Firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
This firmware is a nearly complete rewrite of the sprinter firmware
by kliment (https://github.com/kliment/Sprinter)
which based on Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
Functions in this file are used to communicate using ascii or repetier protocol.
*/
#include "Repetier.h"
#ifndef FEATURE_CHECKSUM_FORCED
#define FEATURE_CHECKSUM_FORCED false
#endif
GCode GCode::commandsBuffered[GCODE_BUFFER_SIZE]; ///< Buffer for received commands.
uint8_t GCode::bufferReadIndex = 0; ///< Read position in gcode_buffer.
uint8_t GCode::bufferWriteIndex = 0; ///< Write position in gcode_buffer.
uint8_t GCode::commandReceiving[MAX_CMD_SIZE]; ///< Current received command.
uint8_t GCode::commandsReceivingWritePosition = 0; ///< Writing position in gcode_transbuffer.
uint8_t GCode::sendAsBinary; ///< Flags the command as binary input.
uint8_t GCode::wasLastCommandReceivedAsBinary = 0; ///< Was the last successful command in binary mode?
uint8_t GCode::commentDetected = false; ///< Flags true if we are reading the comment part of a command.
uint8_t GCode::binaryCommandSize; ///< Expected size of the incoming binary command.
bool GCode::waitUntilAllCommandsAreParsed = false; ///< Don't read until all commands are parsed. Needed if gcode_buffer is misused as storage for strings.
uint32_t GCode::lastLineNumber = 0; ///< Last line number received.
uint32_t GCode::actLineNumber; ///< Line number of current command.
int8_t GCode::waitingForResend = -1; ///< Waiting for line to be resend. -1 = no wait.
volatile uint8_t GCode::bufferLength = 0; ///< Number of commands stored in gcode_buffer
millis_t GCode::timeOfLastDataPacket = 0; ///< Time, when we got the last data packet. Used to detect missing uint8_ts.
uint8_t GCode::formatErrors = 0;
/** \page Repetier-protocol
\section Introduction
The repetier-protocol was developed, to overcome some shortcommings in the standard
RepRap communication method, while remaining backward compatible. To use the improved
features of this protocal, you need a host which speaks it. On Windows the recommended
host software is Repetier-Host. It is developed in parallel to this firmware and supports
all implemented features.
\subsection Improvements
- With higher speeds, the serial connection is more likely to produce communication failures.
The standard method is to transfer a checksum at the end of the line. This checksum is the
XORd value of all characters send. The value is limited to a range between 0 and 127. It can
not detect two identical missing characters or a wrong order. Therefore the new protocol
uses Fletchers checksum, which overcomes these shortcommings.
- The new protocol send data in binary format. This reduces the data size to less then 50% and
it speeds up decoding the command. No slow conversion from string to floats are needed.
*/
/** \brief Computes size of binary data from bitfield.
In the repetier-protocol in binary mode, the first 2 uint8_ts define the
data. From this bitfield, this function computes the size of the command
including the 2 uint8_ts of the bitfield and the 2 uint8_ts for the checksum.
Gcode Letter to Bit and Datatype:
- N : Bit 0 : 16-Bit Integer
- M : Bit 1 : 8-Bit unsigned uint8_t
- G : Bit 2 : 8-Bit unsigned uint8_t
- X : Bit 3 : 32-Bit Float
- Y : Bit 4 : 32-Bit Float
- Z : Bit 5 : 32-Bit Float
- E : Bit 6 : 32-Bit Float
- : Bit 7 : always set to distinguish binary from ASCII line.
- F : Bit 8 : 32-Bit Float
- T : Bit 9 : 8 Bit Integer
- S : Bit 10 : 32 Bit Value
- P : Bit 11 : 32 Bit Integer
- V2 : Bit 12 : Version 2 command for additional commands/sizes
- Ext : Bit 13 : There are 2 more uint8_ts following with Bits, only for future versions
- Int :Bit 14 : Marks it as internal command,
- Text : Bit 15 : 16 Byte ASCII String terminated with 0
Second word if V2:
- I : Bit 0 : 32-Bit float
- J : Bit 1 : 32-Bit float
- R : Bit 2 : 32-Bit float
- D : Bit 3 : 32-Bit float
- C : Bit 4 : 32-Bit float
- H : Bit 5 : 32-Bit float
- A : Bit 6 : 32-Bit float
- B : Bit 7 : 32-Bit float
- K : Bit 8 : 32-Bit float
- L : Bit 9 : 32-Bit float
- O : Bit 0 : 32-Bit float
*/
uint8_t GCode::computeBinarySize(char *ptr) // unsigned int bitfield) {
{
uint8_t s = 4; // include checksum and bitfield
uint16_t bitfield = *(uint16_t*)ptr;
if(bitfield & 1) s += 2;
if(bitfield & 8) s += 4;
if(bitfield & 16) s += 4;
if(bitfield & 32) s += 4;
if(bitfield & 64) s += 4;
if(bitfield & 256) s += 4;
if(bitfield & 512) s += 1;
if(bitfield & 1024) s += 4;
if(bitfield & 2048) s += 4;
if(bitfield & 4096) // Version 2 or later
{
s += 2; // for bitfield 2
uint16_t bitfield2 = *(uint16_t*)(ptr + 2);
if(bitfield & 2) s += 2;
if(bitfield & 4) s += 2;
if(bitfield2 & 1) s += 4;
if(bitfield2 & 2) s += 4;
if(bitfield2 & 4) s += 4;
if(bitfield2 & 8) s += 4;
if(bitfield2 & 16) s += 4;
if(bitfield2 & 32) s += 4;
if(bitfield2 & 64) s += 4;
if(bitfield2 & 128) s += 4;
if(bitfield2 & 256) s += 4;
if(bitfield2 & 512) s += 4;
if(bitfield2 & 1024) s += 4;
if(bitfield2 & 2048) s += 4;
if(bitfield2 & 4096) s += 4;
if(bitfield2 & 8192) s += 4;
if(bitfield2 & 16384) s += 4;
if(bitfield2 & 32768) s += 4;
if(bitfield & 32768) s += RMath::min(80,(uint8_t)ptr[4] + 1);
}
else
{
if(bitfield & 2) s += 1;
if(bitfield & 4) s += 1;
if(bitfield & 32768) s += 16;
}
return s;
}
void GCode::requestResend()
{
HAL::serialFlush();
commandsReceivingWritePosition = 0;
if(sendAsBinary)
waitingForResend = 30;
else
waitingForResend = 14;
Com::println();
Com::printFLN(Com::tResend,lastLineNumber + 1);
Com::printFLN(Com::tOk);
}
/**
Check if result is plausible. If it is, an ok is send and the command is stored in queue.
If not, a resend and ok is send.
*/
void GCode::checkAndPushCommand()
{
if(hasM())
{
if(M == 110) // Reset line number
{
lastLineNumber = actLineNumber;
Com::printFLN(Com::tOk);
waitingForResend = -1;
return;
}
if(M == 112) // Emergency kill - freeze printer
{
Commands::emergencyStop();
}
#ifdef DEBUG_COM_ERRORS
if(M == 666) // force an communication error
{
lastLineNumber++;
return;
}
#endif // DEBUG_COM_ERRORS
}
if(hasN())
{
if((((lastLineNumber + 1) & 0xffff) != (actLineNumber & 0xffff)))
{
if(static_cast<uint16_t>(lastLineNumber - actLineNumber) < 40)
{
// we have seen that line already. So we assume it is a repeated resend and we ignore it
commandsReceivingWritePosition = 0;
Com::printFLN(Com::tSkip,actLineNumber);
Com::printFLN(Com::tOk);
}
else if(waitingForResend < 0) // after a resend, we have to skip the garbage in buffers, no message for this
{
if(Printer::debugErrors())
{
Com::printF(Com::tExpectedLine, lastLineNumber + 1);
Com::printFLN(Com::tGot, actLineNumber);
}
requestResend(); // Line missing, force resend
}
else
{
--waitingForResend;
commandsReceivingWritePosition = 0;
Com::printFLN(Com::tSkip, actLineNumber);
Com::printFLN(Com::tOk);
}
return;
}
lastLineNumber = actLineNumber;
}
pushCommand();
#if ACK_WITH_LINENUMBER
Com::printFLN(Com::tOkSpace, actLineNumber);
#else
Com::printFLN(Com::tOk);
#endif
wasLastCommandReceivedAsBinary = sendAsBinary;
waitingForResend = -1; // everything is ok.
}
void GCode::pushCommand()
{
#if !ECHO_ON_EXECUTE
commandsBuffered[bufferWriteIndex].echoCommand();
#endif
if(++bufferWriteIndex >= GCODE_BUFFER_SIZE) bufferWriteIndex = 0;
bufferLength++;
}
/**
Get the next buffered command. Returns 0 if no more commands are buffered. For each
returned command, the gcode_command_finished() function must be called.
*/
GCode *GCode::peekCurrentCommand()
{
if(bufferLength == 0) return NULL; // No more data
return &commandsBuffered[bufferReadIndex];
}
/** \brief Removes the last returned command from cache. */
void GCode::popCurrentCommand()
{
if(!bufferLength) return; // Should not happen, but safety first
#if ECHO_ON_EXECUTE
echoCommand();
#endif
if(++bufferReadIndex == GCODE_BUFFER_SIZE) bufferReadIndex = 0;
bufferLength--;
}
void GCode::echoCommand()
{
if(Printer::debugEcho())
{
Com::printF(Com::tEcho);
printCommand();
}
}
void GCode::debugCommandBuffer()
{
Com::printF(PSTR("CommandBuffer"));
for(int i = 0; i < commandsReceivingWritePosition; i++)
Com::printF(Com::tColon,(int)commandReceiving[i]);
Com::println();
Com::printFLN(PSTR("Binary:"), (int)sendAsBinary);
if(!sendAsBinary)
{
Com::print((char*)commandReceiving);
Com::println();
}
}
/** \brief Execute commands in progmem stored string. Multiple commands are seperated by \n */
void GCode::executeFString(FSTRINGPARAM(cmd))
{
char buf[80];
uint8_t buflen;
char c;
GCode code;
do
{
// Wait for a free place in command buffer
// Scan next command from string
uint8_t comment = 0;
buflen = 0;
do
{
c = HAL::readFlashByte(cmd++);
if(c == 0 || c == '\n') break;
if(c == ';') comment = 1;
if(comment) continue;
buf[buflen++] = c;
}
while(buflen < 79);
if(buflen == 0) // empty line ignore
continue;
buf[buflen] = 0;
// Send command into command buffer
if(code.parseAscii((char *)buf,false) && (code.params & 518)) // Success
{
#ifdef DEBUG_PRINT
debugWaitLoop = 7;
#endif
Commands::executeGCode(&code);
Printer::defaultLoopActions();
}
}
while(c);
}
/** \brief Read from serial console or sdcard.
This function is the main function to read the commands from serial console or from sdcard.
It must be called frequently to empty the incoming buffer.
*/
void GCode::readFromSerial()
{
if(bufferLength >= GCODE_BUFFER_SIZE) return; // all buffers full
if(waitUntilAllCommandsAreParsed && bufferLength) return;
waitUntilAllCommandsAreParsed = false;
millis_t time = HAL::timeInMilliseconds();
if(!HAL::serialByteAvailable())
{
if((waitingForResend >= 0 || commandsReceivingWritePosition > 0) && time - timeOfLastDataPacket > 200)
{
requestResend(); // Something is wrong, a started line was not continued in the last second
timeOfLastDataPacket = time;
}
#ifdef WAITING_IDENTIFIER
else if(bufferLength == 0 && time - timeOfLastDataPacket > 1000) // Don't do it if buffer is not empty. It may be a slow executing command.
{
Com::printFLN(Com::tWait); // Unblock communication in case the last ok was not received correct.
timeOfLastDataPacket = time;
}
#endif
}
while(HAL::serialByteAvailable() && commandsReceivingWritePosition < MAX_CMD_SIZE) // consume data until no data or buffer full
{
timeOfLastDataPacket = time; //HAL::timeInMilliseconds();
commandReceiving[commandsReceivingWritePosition++] = HAL::serialReadByte();
// first lets detect, if we got an old type ascii command
if(commandsReceivingWritePosition == 1)
{
if(waitingForResend >= 0 && wasLastCommandReceivedAsBinary)
{
if(!commandReceiving[0])
waitingForResend--; // Skip 30 zeros to get in sync
else
waitingForResend = 30;
commandsReceivingWritePosition = 0;
continue;
}
if(!commandReceiving[0]) // Ignore zeros
{
commandsReceivingWritePosition = 0;
continue;
}
sendAsBinary = (commandReceiving[0] & 128) != 0;
}
if(sendAsBinary)
{
if(commandsReceivingWritePosition < 2 ) continue;
if(commandsReceivingWritePosition == 5 || commandsReceivingWritePosition == 4)
binaryCommandSize = computeBinarySize((char*)commandReceiving);
if(commandsReceivingWritePosition == binaryCommandSize)
{
GCode *act = &commandsBuffered[bufferWriteIndex];
if(act->parseBinary(commandReceiving, true)) // Success
act->checkAndPushCommand();
else
requestResend();
commandsReceivingWritePosition = 0;
return;
}
}
else // Ascii command
{
char ch = commandReceiving[commandsReceivingWritePosition - 1];
if(ch == 0 || ch == '\n' || ch == '\r' || (!commentDetected && ch == ':')) // complete line read
{
//Com::printF(PSTR("Parse ascii"));Com::print((char*)commandReceiving);Com::println();
commandReceiving[commandsReceivingWritePosition - 1] = 0;
commentDetected = false;
if(commandsReceivingWritePosition == 1) // empty line ignore
{
commandsReceivingWritePosition = 0;
continue;
}
GCode *act = &commandsBuffered[bufferWriteIndex];
if(act->parseAscii((char *)commandReceiving, true)) // Success
act->checkAndPushCommand();
else
requestResend();
commandsReceivingWritePosition = 0;
return;
}
else
{
if(ch == ';') commentDetected = true; // ignore new data until lineend
if(commentDetected) commandsReceivingWritePosition--;
}
}
if(commandsReceivingWritePosition == MAX_CMD_SIZE)
{
requestResend();
return;
}
}
#if SDSUPPORT
if(sd.sdmode == 0 || commandsReceivingWritePosition != 0) // not reading or incoming serial command
return;
while( sd.filesize > sd.sdpos && commandsReceivingWritePosition < MAX_CMD_SIZE) // consume data until no data or buffer full
{
timeOfLastDataPacket = HAL::timeInMilliseconds();
int n = sd.file.read();
if(n == -1)
{
Com::printFLN(Com::tSDReadError);
UI_ERROR("SD Read Error");
// Second try in case of recoverable errors
sd.file.seekSet(sd.sdpos);
n = sd.file.read();
if(n == -1)
{
Com::printErrorFLN(PSTR("SD error did not recover!"));
sd.sdmode = 0;
break;
}
UI_ERROR("SD error fixed");
}
sd.sdpos++; // = file.curPosition();
commandReceiving[commandsReceivingWritePosition++] = (uint8_t)n;
// first lets detect, if we got an old type ascii command
if(commandsReceivingWritePosition == 1)
{
sendAsBinary = (commandReceiving[0] & 128) != 0;
}
if(sendAsBinary)
{
if(commandsReceivingWritePosition < 2 ) continue;
if(commandsReceivingWritePosition == 4 || commandsReceivingWritePosition == 5)
binaryCommandSize = computeBinarySize((char*)commandReceiving);
if(commandsReceivingWritePosition == binaryCommandSize)
{
GCode *act = &commandsBuffered[bufferWriteIndex];
if(act->parseBinary(commandReceiving, false)) // Success, silently ignore illegal commands
pushCommand();
commandsReceivingWritePosition = 0;
if(sd.sdmode == 2)
sd.sdmode = 0;
return;
}
}
else
{
char ch = commandReceiving[commandsReceivingWritePosition-1];
bool returnChar = ch == '\n' || ch == '\r';
if(returnChar || sd.filesize == sd.sdpos || (!commentDetected && ch == ':') || commandsReceivingWritePosition >= (MAX_CMD_SIZE - 1) ) // complete line read
{
if(returnChar || ch == ':')
commandReceiving[commandsReceivingWritePosition - 1] = 0;
else
commandReceiving[commandsReceivingWritePosition] = 0;
commentDetected = false;
if(commandsReceivingWritePosition == 1) // empty line ignore
{
commandsReceivingWritePosition = 0;
continue;
}
GCode *act = &commandsBuffered[bufferWriteIndex];
if(act->parseAscii((char *)commandReceiving, false)) // Success
pushCommand();
commandsReceivingWritePosition = 0;
if(sd.sdmode == 2)
sd.sdmode = 0;
return;
}
else
{
if(ch == ';') commentDetected = true; // ignore new data until lineend
if(commentDetected) commandsReceivingWritePosition--;
}
}
}
sd.sdmode = 0;
Com::printFLN(Com::tDonePrinting);
commandsReceivingWritePosition = 0;
commentDetected = false;
Printer::setMenuMode(MENU_MODE_SD_PRINTING, false);
#endif
}
/**
Converts a binary uint8_tfield containing one GCode line into a GCode structure.
Returns true if checksum was correct.
*/
bool GCode::parseBinary(uint8_t *buffer,bool fromSerial)
{
internalCommand = !fromSerial;
unsigned int sum1 = 0,sum2 = 0; // for fletcher-16 checksum
// first do fletcher-16 checksum tests see
// http://en.wikipedia.org/wiki/Fletcher's_checksum
uint8_t *p = buffer;
uint8_t len = binaryCommandSize - 2;
while (len)
{
uint8_t tlen = len > 21 ? 21 : len;
len -= tlen;
do
{
sum1 += *p++;
if(sum1 >= 255) sum1 -= 255;
sum2 += sum1;
if(sum2 >= 255) sum2 -= 255;
}
while (--tlen);
}
sum1 -= *p++;
sum2 -= *p;
if(sum1 | sum2)
{
if(Printer::debugErrors())
{
Com::printErrorFLN(Com::tWrongChecksum);
}
return false;
}
p = buffer;
params = *(unsigned int *)p;
p += 2;
uint8_t textlen = 16;
if(isV2())
{
params2 = *(unsigned int *)p;
p+=2;
if(hasString())
textlen = *p++;
}
else params2 = 0;
if(params & 1)
{
actLineNumber = N = *(uint16_t *)p;
p+=2;
}
if(isV2()) // Read G,M as 16 bit value
{
if(params & 2)
{
M = *(uint16_t *)p;
p += 2;
}
if(params & 4)
{
G = *(uint16_t *)p;
p += 2;
}
}
else
{
if(params & 2)
{
M = *p++;
}
if(params & 4)
{
G = *p++;
}
}
//if(code->params & 8) {memcpy(&code->X,p,4);p+=4;}
if(params & 8)
{
X = *(float *)p;
p += 4;
}
if(params & 16)
{
Y = *(float *)p;
p += 4;
}
if(params & 32)
{
Z = *(float *)p;
p += 4;
}
if(params & 64)
{
E = *(float *)p;
p += 4;
}
if(params & 256)
{
F = *(float *)p;
p += 4;
}
if(params & 512)
{
T = *p++;
}
if(params & 1024)
{
S = *(int32_t*)p;
p += 4;
}
if(params & 2048)
{
P = *(int32_t*)p;
p += 4;
}
if(hasI())
{
I = *(float *)p;
p += 4;
}
if(hasJ())
{
J = *(float *)p;
p += 4;
}
if(hasR())
{
R = *(float *)p;
p += 4;
}
if(hasD())
{
D = *(float *)p;
p += 4;
}
if(hasC())
{
C = *(float *)p;
p += 4;
}
if(hasH())
{
H = *(float *)p;
p += 4;
}
if(hasA())
{
A = *(float *)p;
p += 4;
}
if(hasB())
{
B = *(float *)p;
p += 4;
}
if(hasK())
{
K = *(float *)p;
p += 4;
}
if(hasL())
{
L = *(float *)p;
p += 4;
}
if(hasO())
{
O = *(float *)p;
p += 4;
}
if(hasString()) // set text pointer to string
{
text = (char*)p;
text[textlen] = 0; // Terminate string overwriting checksum
waitUntilAllCommandsAreParsed=true; // Don't destroy string until executed
}
formatErrors = 0;
return true;
}
/**
Converts a ascii GCode line into a GCode structure.
*/
bool GCode::parseAscii(char *line,bool fromSerial)
{
char *pos = line;
params = 0;
params2 = 0;
internalCommand = !fromSerial;
char c;
while ( (c = *(pos++)) )
{
switch(c)
{
case 'N':
case 'n':
{
actLineNumber = parseLongValue(pos);
params |=1;
N = actLineNumber;
break;
}
case 'G':
case 'g':
{
G = parseLongValue(pos) & 0xffff;
params |= 4;
if(G > 255) params |= 4096;
break;
}
case 'M':
case 'm':
{
M = parseLongValue(pos) & 0xffff;
params |=2;
if(M > 255) params |= 4096;
// handle non standard text arguments that some M codes have
if (M == 23 || M == 28 || M == 29 || M == 30 || M == 32 || M == 117)
{
// after M command we got a filename or text
char digit;
while( (digit = *pos) )
{
if (digit < '0' || digit > '9') break;
pos++;
}
while( (digit = *pos) )
{
if (digit != ' ') break;
pos++;
// skip leading whitespaces (may be no white space)
}
text = pos;
while (*pos)
{
if((M != 117 && *pos==' ') || *pos=='*') break;
pos++; // find a space as file name end
}
*pos = 0; // truncate filename by erasing space with nul, also skips checksum
waitUntilAllCommandsAreParsed = true; // don't risk string be deleted
params |= 32768;
}
break;
}
case 'X':
case 'x':
{
X = parseFloatValue(pos);
params |= 8;
break;
}
case 'Y':
case 'y':
{
Y = parseFloatValue(pos);
params |= 16;
break;
}
case 'Z':
case 'z':
{
Z = parseFloatValue(pos);
params |= 32;
break;
}
case 'E':
case 'e':
{
E = parseFloatValue(pos);
params |= 64;
break;
}
case 'F':
case 'f':
{
F = parseFloatValue(pos);
params |= 256;
break;
}
case 'T':
case 't':
{
T = parseLongValue(pos) & 0xff;
params |= 512;
break;
}
case 'S':
case 's':
{
S = parseLongValue(pos);
params |= 1024;
break;
}
case 'P':
case 'p':
{
P = parseLongValue(pos);
params |= 2048;
break;
}
case 'I':
case 'i':
{
I = parseFloatValue(pos);
params2 |= 1;
params |= 4096; // Needs V2 for saving
break;
}
case 'J':
case 'j':
{
J = parseFloatValue(pos);
params2 |= 2;
params |= 4096; // Needs V2 for saving
break;
}
case 'R':
case 'r':
{
R = parseFloatValue(pos);
params2 |= 4;
params |= 4096; // Needs V2 for saving
break;
}
case 'D':
case 'd':
{
D = parseFloatValue(pos);
params2 |= 8;
params |= 4096; // Needs V2 for saving
break;
}
case '*' : //checksum
{
uint8_t checksum_given = parseLongValue(pos);
uint8_t checksum = 0;
while(line != (pos-1)) checksum ^= *line++;
#if FEATURE_CHECKSUM_FORCED
Printer::flag0 |= PRINTER_FLAG0_FORCE_CHECKSUM;
#endif
if(checksum != checksum_given)
{
if(Printer::debugErrors())
{
Com::printErrorFLN(Com::tWrongChecksum);
}
return false; // mismatch
}
break;
}
default:
break;
}// end switch
}// end while
if(hasFormatError() || (params & 518)==0) // Must contain G, M or T command and parameter need to have variables!
{
formatErrors++;
if(Printer::debugErrors())
Com::printErrorFLN(Com::tFormatError);
if(formatErrors<3) return false;
}
else formatErrors = 0;
return true;
}
/** \brief Print command on serial console */
void GCode::printCommand()
{
if(hasN()) {
Com::print('N');
Com::print((long)N);
Com::print(' ');
}
if(hasM())
{
Com::print('M');
Com::print((int)M);
Com::print(' ');
}
if(hasG())
{
Com::print('G');
Com::print((int)G);
Com::print(' ');
}
if(hasT())
{
Com::print('T');
Com::print((int)T);
Com::print(' ');
}
if(hasX())
{
Com::printF(Com::tX,X);
}
if(hasY())
{
Com::printF(Com::tY,Y);
}
if(hasZ())
{
Com::printF(Com::tZ,Z);
}
if(hasE())
{
Com::printF(Com::tE,E,4);
}
if(hasF())
{
Com::printF(Com::tF,F);
}
if(hasS())
{
Com::printF(Com::tS,S);
}
if(hasP())
{
Com::printF(Com::tP,P);
}
if(hasI())
{
Com::printF(Com::tI,I);
}
if(hasJ())
{
Com::printF(Com::tJ,J);
}
if(hasR())
{
Com::printF(Com::tR,R);
}
if(hasString())
{
Com::print(text);
}
Com::println();
}

View File

@ -0,0 +1,226 @@
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Repetier-Firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _GCODE_H
#define _GCODE_H
#define MAX_CMD_SIZE 96
class SDCard;
class GCode // 52 uint8_ts per command needed
{
unsigned int params;
unsigned int params2;
public:
unsigned int N; // Line number
unsigned int M;
unsigned int G;
float X;
float Y;
float Z;
float E;
float F;
long S;
long P;
float I;
float J;
float R;
float D;
float C;
float H;
float A;
float B;
float K;
float L;
float O;
char *text; //text[17];
//moved the byte to the end and aligned ints on short boundary
// Old habit from PC, which require alignments for data types such as int and long to be on 2 or 4 byte boundary
// Otherwise, the compiler adds padding, wasted space.
uint8_t T; // This may not matter on any of these controllers, but it can't hurt
// True if origin did not come from serial console. That way we can send status messages to
// a host only if he would normally not know about the mode switch.
bool internalCommand;
inline bool hasM()
{
return ((params & 2)!=0);
}
inline bool hasN()
{
return ((params & 1)!=0);
}
inline bool hasG()
{
return ((params & 4)!=0);
}
inline bool hasX()
{
return ((params & 8)!=0);
}
inline bool hasY()
{
return ((params & 16)!=0);
}
inline bool hasZ()
{
return ((params & 32)!=0);
}
inline bool hasNoXYZ()
{
return ((params & 56)==0);
}
inline bool hasE()
{
return ((params & 64)!=0);
}
inline bool hasF()
{
return ((params & 256)!=0);
}
inline bool hasT()
{
return ((params & 512)!=0);
}
inline bool hasS()
{
return ((params & 1024)!=0);
}
inline bool hasP()
{
return ((params & 2048)!=0);
}
inline bool isV2()
{
return ((params & 4096)!=0);
}
inline bool hasString()
{
return ((params & 32768)!=0);
}
inline bool hasI()
{
return ((params2 & 1)!=0);
}
inline bool hasJ()
{
return ((params2 & 2)!=0);
}
inline bool hasR()
{
return ((params2 & 4)!=0);
}
inline bool hasD()
{
return ((params2 & 8)!=0);
}
inline bool hasC()
{
return ((params2 & 16)!=0);
}
inline bool hasH()
{
return ((params2 & 32)!=0);
}
inline bool hasA()
{
return ((params2 & 64)!=0);
}
inline bool hasB()
{
return ((params2 & 128)!=0);
}
inline bool hasK()
{
return ((params2 & 256)!=0);
}
inline bool hasL()
{
return ((params2 & 512)!=0);
}
inline bool hasO()
{
return ((params2 & 1024)!=0);
}
inline long getS(long def)
{
return (hasS() ? S : def);
}
inline long getP(long def)
{
return (hasP() ? P : def);
}
inline void setFormatError() {
params2 |= 32768;
}
inline bool hasFormatError() {
return ((params2 & 32768)!=0);
}
void printCommand();
bool parseBinary(uint8_t *buffer,bool fromSerial);
bool parseAscii(char *line,bool fromSerial);
void popCurrentCommand();
void echoCommand();
/** Get next command in command buffer. After the command is processed, call gcode_command_finished() */
static GCode *peekCurrentCommand();
/** Frees the cache used by the last command fetched. */
static void readFromSerial();
static void pushCommand();
static void executeFString(FSTRINGPARAM(cmd));
static uint8_t computeBinarySize(char *ptr);
friend class SDCard;
friend class UIDisplay;
private:
void debugCommandBuffer();
void checkAndPushCommand();
static void requestResend();
inline float parseFloatValue(char *s)
{
char *endPtr;
float f = (strtod(s, &endPtr));
if(s == endPtr) f=0.0; // treat empty string "x " as "x0"
return f;
}
inline long parseLongValue(char *s)
{
char *endPtr;
long l = (strtol(s, &endPtr, 10));
if(s == endPtr) l=0; // treat empty string argument "p " as "p0"
return l;
}
static GCode commandsBuffered[GCODE_BUFFER_SIZE]; ///< Buffer for received commands.
static uint8_t bufferReadIndex; ///< Read position in gcode_buffer.
static uint8_t bufferWriteIndex; ///< Write position in gcode_buffer.
static uint8_t commandReceiving[MAX_CMD_SIZE]; ///< Current received command.
static uint8_t commandsReceivingWritePosition; ///< Writing position in gcode_transbuffer.
static uint8_t sendAsBinary; ///< Flags the command as binary input.
static uint8_t wasLastCommandReceivedAsBinary; ///< Was the last successful command in binary mode?
static uint8_t commentDetected; ///< Flags true if we are reading the comment part of a command.
static uint8_t binaryCommandSize; ///< Expected size of the incoming binary command.
static bool waitUntilAllCommandsAreParsed; ///< Don't read until all commands are parsed. Needed if gcode_buffer is misused as storage for strings.
static uint32_t lastLineNumber; ///< Last line number received.
static uint32_t actLineNumber; ///< Line number of current command.
static int8_t waitingForResend; ///< Waiting for line to be resend. -1 = no wait.
static volatile uint8_t bufferLength; ///< Number of commands stored in gcode_buffer
static millis_t timeOfLastDataPacket; ///< Time, when we got the last data packet. Used to detect missing uint8_ts.
static uint8_t formatErrors; ///< Number of sequential format errors
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,705 @@
/*
This file is part of Repetier-Firmware.
Repetier-Firmware is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Repetier-Firmware is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>.
This firmware is a nearly complete rewrite of the sprinter firmware
by kliment (https://github.com/kliment/Sprinter)
which based on Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
#
Functions in this file are used to communicate using ascii or repetier protocol.
*/
#ifndef MOTION_H_INCLUDED
#define MOTION_H_INCLUDED
/** Marks the first step of a new move */
#define FLAG_WARMUP 1
#define FLAG_NOMINAL 2
#define FLAG_DECELERATING 4
#define FLAG_ACCELERATION_ENABLED 8
#define FLAG_CHECK_ENDSTOPS 16
#define FLAG_SKIP_ACCELERATING 32
#define FLAG_SKIP_DEACCELERATING 64
#define FLAG_BLOCKED 128
/** Are the step parameter computed */
#define FLAG_JOIN_STEPPARAMS_COMPUTED 1
/** The right speed is fixed. Don't check this block or any block to the left. */
#define FLAG_JOIN_END_FIXED 2
/** The left speed is fixed. Don't check left block. */
#define FLAG_JOIN_START_FIXED 4
/** Start filament retraction at move start */
#define FLAG_JOIN_START_RETRACT 8
/** Wait for filament pushback, before ending move */
#define FLAG_JOIN_END_RETRACT 16
/** Disable retract for this line */
#define FLAG_JOIN_NO_RETRACT 32
/** Wait for the extruder to finish it's up movement */
#define FLAG_JOIN_WAIT_EXTRUDER_UP 64
/** Wait for the extruder to finish it's down movement */
#define FLAG_JOIN_WAIT_EXTRUDER_DOWN 128
// Printing related data
#if NONLINEAR_SYSTEM
// Allow the delta cache to store segments for every line in line cache. Beware this gets big ... fast.
// DELTASEGMENTS_PER_PRINTLINE *
#define DELTA_CACHE_SIZE (DELTASEGMENTS_PER_PRINTLINE * PRINTLINE_CACHE_SIZE)
class PrintLine;
typedef struct
{
flag8_t dir; ///< Direction of delta movement.
uint16_t deltaSteps[TOWER_ARRAY]; ///< Number of steps in move.
inline void checkEndstops(PrintLine *cur,bool checkall);
inline void setXMoveFinished()
{
dir &= ~XSTEP;
}
inline void setYMoveFinished()
{
dir &= ~YSTEP;
}
inline void setZMoveFinished()
{
dir &= ~ZSTEP;
}
inline void setXYMoveFinished()
{
dir &= ~XY_STEP;
}
inline bool isXPositiveMove()
{
return (dir & X_STEP_DIRPOS) == X_STEP_DIRPOS;
}
inline bool isXNegativeMove()
{
return (dir & X_STEP_DIRPOS) == XSTEP;
}
inline bool isYPositiveMove()
{
return (dir & Y_STEP_DIRPOS) == Y_STEP_DIRPOS;
}
inline bool isYNegativeMove()
{
return (dir & Y_STEP_DIRPOS) == YSTEP;
}
inline bool isZPositiveMove()
{
return (dir & Z_STEP_DIRPOS) == Z_STEP_DIRPOS;
}
inline bool isZNegativeMove()
{
return (dir & Z_STEP_DIRPOS) == ZSTEP;
}
inline bool isEPositiveMove()
{
return (dir & E_STEP_DIRPOS) == E_STEP_DIRPOS;
}
inline bool isENegativeMove()
{
return (dir & E_STEP_DIRPOS) == ESTEP;
}
inline bool isXMove()
{
return (dir & XSTEP);
}
inline bool isYMove()
{
return (dir & YSTEP);
}
inline bool isXOrYMove()
{
return dir & XY_STEP;
}
inline bool isZMove()
{
return (dir & ZSTEP);
}
inline bool isEMove()
{
return (dir & ESTEP);
}
inline bool isEOnlyMove()
{
return (dir & XYZE_STEP)==ESTEP;
}
inline bool isNoMove()
{
return (dir & XYZE_STEP)==0;
}
inline bool isXYZMove()
{
return dir & XYZ_STEP;
}
inline bool isMoveOfAxis(uint8_t axis)
{
return (dir & (XSTEP<<axis));
}
inline void setMoveOfAxis(uint8_t axis)
{
dir |= XSTEP<<axis;
}
inline void setPositiveMoveOfAxis(uint8_t axis)
{
dir |= X_STEP_DIRPOS<<axis;
}
inline void setPositiveDirectionForAxis(uint8_t axis)
{
dir |= X_DIRPOS<<axis;
}
} DeltaSegment;
extern uint8_t lastMoveID;
#endif
class UIDisplay;
class PrintLine // RAM usage: 24*4+15 = 113 Byte
{
friend class UIDisplay;
#if CPU_ARCH==ARCH_ARM
static volatile bool nlFlag;
#endif
public:
static uint8_t linesPos; // Position for executing line movement
static PrintLine lines[];
static uint8_t linesWritePos; // Position where we write the next cached line move
flag8_t joinFlags;
volatile flag8_t flags;
private:
flag8_t primaryAxis;
int32_t timeInTicks;
flag8_t halfStep; ///< 4 = disabled, 1 = halfstep, 2 = fulstep
flag8_t dir; ///< Direction of movement. 1 = X+, 2 = Y+, 4= Z+, values can be combined.
int32_t delta[E_AXIS_ARRAY]; ///< Steps we want to move.
int32_t error[E_AXIS_ARRAY]; ///< Error calculation for Bresenham algorithm
float speedX; ///< Speed in x direction at fullInterval in mm/s
float speedY; ///< Speed in y direction at fullInterval in mm/s
float speedZ; ///< Speed in z direction at fullInterval in mm/s
float speedE; ///< Speed in E direction at fullInterval in mm/s
float fullSpeed; ///< Desired speed mm/s
float invFullSpeed; ///< 1.0/fullSpeed for fatser computation
float accelerationDistance2; ///< Real 2.0*distanceÜacceleration mm²/s²
float maxJunctionSpeed; ///< Max. junction speed between this and next segment
float startSpeed; ///< Staring speed in mm/s
float endSpeed; ///< Exit speed in mm/s
float minSpeed;
float distance;
#if NONLINEAR_SYSTEM
uint8_t numDeltaSegments; ///< Number of delta segments left in line. Decremented by stepper timer.
uint8_t moveID; ///< ID used to identify moves which are all part of the same line
int32_t numPrimaryStepPerSegment; ///< Number of primary bresenham axis steps in each delta segment
DeltaSegment segments[DELTASEGMENTS_PER_PRINTLINE];
#endif
ticks_t fullInterval; ///< interval at full speed in ticks/step.
uint16_t accelSteps; ///< How much steps does it take, to reach the plateau.
uint16_t decelSteps; ///< How much steps does it take, to reach the end speed.
uint32_t accelerationPrim; ///< Acceleration along primary axis
uint32_t fAcceleration; ///< accelerationPrim*262144/F_CPU
speed_t vMax; ///< Maximum reached speed in steps/s.
speed_t vStart; ///< Starting speed in steps/s.
speed_t vEnd; ///< End speed in steps/s
#if USE_ADVANCE
#if ENABLE_QUADRATIC_ADVANCE
int32_t advanceRate; ///< Advance steps at full speed
int32_t advanceFull; ///< Maximum advance at fullInterval [steps*65536]
int32_t advanceStart;
int32_t advanceEnd;
#endif
uint16_t advanceL; ///< Recomputated L value
#endif
#ifdef DEBUG_STEPCOUNT
int32_t totalStepsRemaining;
#endif
public:
int32_t stepsRemaining; ///< Remaining steps, until move is finished
static PrintLine *cur;
static volatile uint8_t linesCount; // Number of lines cached 0 = nothing to do
inline bool areParameterUpToDate()
{
return joinFlags & FLAG_JOIN_STEPPARAMS_COMPUTED;
}
inline void invalidateParameter()
{
joinFlags &= ~FLAG_JOIN_STEPPARAMS_COMPUTED;
}
inline void setParameterUpToDate()
{
joinFlags |= FLAG_JOIN_STEPPARAMS_COMPUTED;
}
inline bool isStartSpeedFixed()
{
return joinFlags & FLAG_JOIN_START_FIXED;
}
inline void setStartSpeedFixed(bool newState)
{
joinFlags = (newState ? joinFlags | FLAG_JOIN_START_FIXED : joinFlags & ~FLAG_JOIN_START_FIXED);
}
inline void fixStartAndEndSpeed()
{
joinFlags |= FLAG_JOIN_END_FIXED | FLAG_JOIN_START_FIXED;
}
inline bool isEndSpeedFixed()
{
return joinFlags & FLAG_JOIN_END_FIXED;
}
inline void setEndSpeedFixed(bool newState)
{
joinFlags = (newState ? joinFlags | FLAG_JOIN_END_FIXED : joinFlags & ~FLAG_JOIN_END_FIXED);
}
inline bool isWarmUp()
{
return flags & FLAG_WARMUP;
}
inline uint8_t getWaitForXLinesFilled()
{
return primaryAxis;
}
inline void setWaitForXLinesFilled(uint8_t b)
{
primaryAxis = b;
}
inline bool isExtruderForwardMove()
{
return (dir & E_STEP_DIRPOS)==E_STEP_DIRPOS;
}
inline void block()
{
flags |= FLAG_BLOCKED;
}
inline void unblock()
{
flags &= ~FLAG_BLOCKED;
}
inline bool isBlocked()
{
return flags & FLAG_BLOCKED;
}
inline bool isCheckEndstops()
{
return flags & FLAG_CHECK_ENDSTOPS;
}
inline bool isNominalMove()
{
return flags & FLAG_NOMINAL;
}
inline void setNominalMove()
{
flags |= FLAG_NOMINAL;
}
inline void checkEndstops()
{
if(isCheckEndstops())
{
if(isXNegativeMove() && Printer::isXMinEndstopHit())
setXMoveFinished();
if(isYNegativeMove() && Printer::isYMinEndstopHit())
setYMoveFinished();
if(isXPositiveMove() && Printer::isXMaxEndstopHit())
setXMoveFinished();
if(isYPositiveMove() && Printer::isYMaxEndstopHit())
setYMoveFinished();
}
#if FEATURE_Z_PROBE
if(Printer::isZProbingActive() && isZNegativeMove() && Printer::isZProbeHit())
{
setZMoveFinished();
Printer::stepsRemainingAtZHit = stepsRemaining;
}
else
#endif
// Test Z-Axis every step if necessary, otherwise it could easyly ruin your printer!
if(isZNegativeMove() && Printer::isZMinEndstopHit())
setZMoveFinished();
if(isZPositiveMove() && Printer::isZMaxEndstopHit())
{
#if MAX_HARDWARE_ENDSTOP_Z
Printer::stepsRemainingAtZHit = stepsRemaining;
#endif
setZMoveFinished();
}
if(isZPositiveMove() && Printer::isZMaxEndstopHit())
setZMoveFinished();
}
inline void setXMoveFinished()
{
#if DRIVE_SYSTEM==CARTESIAN || NONLINEAR_SYSTEM
dir&=~16;
#else
dir&=~48;
#endif
}
inline void setYMoveFinished()
{
#if DRIVE_SYSTEM==CARTESIAN || NONLINEAR_SYSTEM
dir&=~32;
#else
dir&=~48;
#endif
}
inline void setZMoveFinished()
{
dir&=~64;
}
inline void setXYMoveFinished()
{
dir&=~48;
}
inline bool isXPositiveMove()
{
return (dir & X_STEP_DIRPOS)==X_STEP_DIRPOS;
}
inline bool isXNegativeMove()
{
return (dir & X_STEP_DIRPOS)==XSTEP;
}
inline bool isYPositiveMove()
{
return (dir & Y_STEP_DIRPOS)==Y_STEP_DIRPOS;
}
inline bool isYNegativeMove()
{
return (dir & Y_STEP_DIRPOS)==YSTEP;
}
inline bool isZPositiveMove()
{
return (dir & Z_STEP_DIRPOS)==Z_STEP_DIRPOS;
}
inline bool isZNegativeMove()
{
return (dir & Z_STEP_DIRPOS)==ZSTEP;
}
inline bool isEPositiveMove()
{
return (dir & E_STEP_DIRPOS)==E_STEP_DIRPOS;
}
inline bool isENegativeMove()
{
return (dir & E_STEP_DIRPOS)==ESTEP;
}
inline bool isXMove()
{
return (dir & XSTEP);
}
inline bool isYMove()
{
return (dir & YSTEP);
}
inline bool isXOrYMove()
{
return dir & XY_STEP;
}
inline bool isXOrZMove()
{
return dir & (XSTEP | YSTEP);
}
inline bool isZMove()
{
return (dir & ZSTEP);
}
inline bool isEMove()
{
return (dir & ESTEP);
}
inline bool isEOnlyMove()
{
return (dir & XYZE_STEP)==ESTEP;
}
inline bool isNoMove()
{
return (dir & XYZE_STEP)==0;
}
inline bool isXYZMove()
{
return dir & XYZ_STEP;
}
inline bool isMoveOfAxis(uint8_t axis)
{
return (dir & (XSTEP<<axis));
}
inline void setMoveOfAxis(uint8_t axis)
{
dir |= XSTEP<<axis;
}
inline void setPositiveDirectionForAxis(uint8_t axis)
{
dir |= X_DIRPOS<<axis;
}
inline static void resetPathPlanner()
{
linesCount = 0;
linesPos = linesWritePos;
Printer::setMenuMode(MENU_MODE_PRINTING,false);
}
// Only called from bresenham -> inside interrupt handle
inline void updateAdvanceSteps(speed_t v,uint8_t max_loops,bool accelerate)
{
#if USE_ADVANCE
if(!Printer::isAdvanceActivated()) return;
#if ENABLE_QUADRATIC_ADVANCE
long advanceTarget = Printer::advanceExecuted;
if(accelerate)
{
for(uint8_t loop = 0; loop<max_loops; loop++) advanceTarget += advanceRate;
if(advanceTarget>advanceFull)
advanceTarget = advanceFull;
}
else
{
for(uint8_t loop = 0; loop<max_loops; loop++) advanceTarget -= advanceRate;
if(advanceTarget<advanceEnd)
advanceTarget = advanceEnd;
}
long h = HAL::mulu16xu16to32(v, advanceL);
int tred = ((advanceTarget + h) >> 16);
HAL::forbidInterrupts();
Printer::extruderStepsNeeded += tred-Printer::advanceStepsSet;
if(tred > 0 && Printer::advanceStepsSet <= 0)
Printer::extruderStepsNeeded += Extruder::current->advanceBacklash;
else if(tred < 0 && Printer::advanceStepsSet >= 0)
Printer::extruderStepsNeeded -= Extruder::current->advanceBacklash;
Printer::advanceStepsSet = tred;
HAL::allowInterrupts();
Printer