static'ified Marlin.pde.
This commit is contained in:
parent
79d1bfb5c0
commit
87aaf0f70a
2 changed files with 127 additions and 110 deletions
|
@ -65,7 +65,7 @@ const bool ENDSTOPS_INVERTING = true; // set to true to invert the logic of the
|
||||||
#define SDSUPPORT
|
#define SDSUPPORT
|
||||||
#define ULTRA_LCD
|
#define ULTRA_LCD
|
||||||
#define LCD_WIDTH 20
|
#define LCD_WIDTH 20
|
||||||
#define LCD_HEIGHT 4
|
#define LCD_HEIGHT 4
|
||||||
#else //no panel but just lcd
|
#else //no panel but just lcd
|
||||||
#ifdef ULTRA_LCD
|
#ifdef ULTRA_LCD
|
||||||
#define LCD_WIDTH 16
|
#define LCD_WIDTH 16
|
||||||
|
@ -251,4 +251,8 @@ const int dropsegments=5; //everything with this number of steps will be ignore
|
||||||
#define BLOCK_BUFFER_SIZE 16 // maximize block buffer
|
#define BLOCK_BUFFER_SIZE 16 // maximize block buffer
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//The ASCII buffer for recieving from the serial:
|
||||||
|
#define MAX_CMD_SIZE 96
|
||||||
|
#define BUFSIZE 4
|
||||||
|
|
||||||
#endif //__CONFIGURATION_H
|
#endif //__CONFIGURATION_H
|
||||||
|
|
|
@ -107,68 +107,82 @@ char version_string[] = "1.0.0 Alpha 1";
|
||||||
|
|
||||||
//Stepper Movement Variables
|
//Stepper Movement Variables
|
||||||
|
|
||||||
const char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
|
//===========================================================================
|
||||||
float destination[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
|
//=============================imported variables============================
|
||||||
float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
|
//===========================================================================
|
||||||
float offset[3] = {0.0, 0.0, 0.0};
|
extern float HeaterPower;
|
||||||
bool home_all_axis = true;
|
|
||||||
float feedrate = 1500.0, next_feedrate, saved_feedrate;
|
|
||||||
long gcode_N, gcode_LastN;
|
|
||||||
|
|
||||||
|
//public variables
|
||||||
float homing_feedrate[] = HOMING_FEEDRATE;
|
float homing_feedrate[] = HOMING_FEEDRATE;
|
||||||
bool axis_relative_modes[] = AXIS_RELATIVE_MODES;
|
bool axis_relative_modes[] = AXIS_RELATIVE_MODES;
|
||||||
|
|
||||||
bool relative_mode = false; //Determines Absolute or Relative Coordinates
|
|
||||||
bool relative_mode_e = false; //Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.
|
|
||||||
|
|
||||||
uint8_t fanpwm=0;
|
|
||||||
|
|
||||||
volatile int feedmultiply=100; //100->1 200->2
|
volatile int feedmultiply=100; //100->1 200->2
|
||||||
int saved_feedmultiply;
|
int saved_feedmultiply;
|
||||||
volatile bool feedmultiplychanged=false;
|
volatile bool feedmultiplychanged=false;
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
//=============================private variables=============================
|
||||||
|
//===========================================================================
|
||||||
|
const char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
|
||||||
|
static float destination[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
|
||||||
|
static float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
|
||||||
|
static float offset[3] = {0.0, 0.0, 0.0};
|
||||||
|
static bool home_all_axis = true;
|
||||||
|
static float feedrate = 1500.0, next_feedrate, saved_feedrate;
|
||||||
|
static long gcode_N, gcode_LastN;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static bool relative_mode = false; //Determines Absolute or Relative Coordinates
|
||||||
|
static bool relative_mode_e = false; //Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.
|
||||||
|
|
||||||
|
static uint8_t fanpwm=0;
|
||||||
|
|
||||||
|
|
||||||
// comm variables
|
// comm variables
|
||||||
#define MAX_CMD_SIZE 96
|
|
||||||
#define BUFSIZE 4
|
static char cmdbuffer[BUFSIZE][MAX_CMD_SIZE];
|
||||||
char cmdbuffer[BUFSIZE][MAX_CMD_SIZE];
|
static bool fromsd[BUFSIZE];
|
||||||
bool fromsd[BUFSIZE];
|
static int bufindr = 0;
|
||||||
int bufindr = 0;
|
static int bufindw = 0;
|
||||||
int bufindw = 0;
|
static int buflen = 0;
|
||||||
int buflen = 0;
|
static int i = 0;
|
||||||
int i = 0;
|
static char serial_char;
|
||||||
char serial_char;
|
static int serial_count = 0;
|
||||||
int serial_count = 0;
|
static boolean comment_mode = false;
|
||||||
boolean comment_mode = false;
|
static char *strchr_pointer; // just a pointer to find chars in the cmd string like X, Y, Z, E, etc
|
||||||
char *strchr_pointer; // just a pointer to find chars in the cmd string like X, Y, Z, E, etc
|
|
||||||
extern float HeaterPower;
|
|
||||||
|
|
||||||
const int sensitive_pins[] = SENSITIVE_PINS; // Sensitive pin list for M42
|
const int sensitive_pins[] = SENSITIVE_PINS; // Sensitive pin list for M42
|
||||||
|
|
||||||
float tt = 0, bt = 0;
|
static float tt = 0, bt = 0;
|
||||||
|
|
||||||
//Inactivity shutdown variables
|
//Inactivity shutdown variables
|
||||||
unsigned long previous_millis_cmd = 0;
|
static unsigned long previous_millis_cmd = 0;
|
||||||
unsigned long max_inactive_time = 0;
|
static unsigned long max_inactive_time = 0;
|
||||||
unsigned long stepper_inactive_time = 0;
|
static unsigned long stepper_inactive_time = 0;
|
||||||
|
|
||||||
|
static unsigned long starttime=0;
|
||||||
|
static unsigned long stoptime=0;
|
||||||
|
|
||||||
unsigned long starttime=0;
|
|
||||||
unsigned long stoptime=0;
|
|
||||||
#ifdef SDSUPPORT
|
#ifdef SDSUPPORT
|
||||||
Sd2Card card;
|
static Sd2Card card;
|
||||||
SdVolume volume;
|
static SdVolume volume;
|
||||||
SdFile root;
|
static SdFile root;
|
||||||
SdFile file;
|
static SdFile file;
|
||||||
uint32_t filesize = 0;
|
static uint32_t filesize = 0;
|
||||||
uint32_t sdpos = 0;
|
static uint32_t sdpos = 0;
|
||||||
bool sdmode = false;
|
static bool sdmode = false;
|
||||||
bool sdactive = false;
|
static bool sdactive = false;
|
||||||
bool savetosd = false;
|
static bool savetosd = false;
|
||||||
int16_t n;
|
static int16_t n;
|
||||||
unsigned long autostart_atmillis=0;
|
static unsigned long autostart_atmillis=0;
|
||||||
|
|
||||||
bool autostart_stilltocheck=true; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
|
|
||||||
|
|
||||||
|
static bool autostart_stilltocheck=true; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
|
||||||
|
#endif //SDSUPPORT
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
//=============================ROUTINES=============================
|
||||||
|
//===========================================================================
|
||||||
|
#ifdef SDSUPPORT
|
||||||
void initsd()
|
void initsd()
|
||||||
{
|
{
|
||||||
sdactive = false;
|
sdactive = false;
|
||||||
|
@ -223,60 +237,11 @@ unsigned long stoptime=0;
|
||||||
SERIAL_ERRORLN("error writing to file");
|
SERIAL_ERRORLN("error writing to file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif //SDSUPPORT
|
|
||||||
|
|
||||||
|
|
||||||
//adds an command to the main command buffer
|
void checkautostart(bool force)
|
||||||
//thats really done in a non-safe way.
|
|
||||||
//needs overworking someday
|
|
||||||
void enquecommand(const char *cmd)
|
|
||||||
{
|
|
||||||
if(buflen < BUFSIZE)
|
|
||||||
{
|
{
|
||||||
//this is dangerous if a mixing of serial and this happsens
|
//this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
|
||||||
strcpy(&(cmdbuffer[bufindw][0]),cmd);
|
|
||||||
SERIAL_ECHOLN("enqueing \""<<cmdbuffer[bufindw]<<"\"");
|
|
||||||
bufindw= (bufindw + 1)%BUFSIZE;
|
|
||||||
buflen += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
Serial.begin(BAUDRATE);
|
|
||||||
SERIAL_ECHOLN("Marlin "<<version_string);
|
|
||||||
Serial.println("start");
|
|
||||||
for(int i = 0; i < BUFSIZE; i++)
|
|
||||||
{
|
|
||||||
fromsd[i] = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
RetrieveSettings(); // loads data from EEPROM if available
|
|
||||||
|
|
||||||
for(int i=0; i < NUM_AXIS; i++)
|
|
||||||
{
|
|
||||||
axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SDSUPPORT
|
|
||||||
//power to SD reader
|
|
||||||
#if SDPOWER > -1
|
|
||||||
SET_OUTPUT(SDPOWER);
|
|
||||||
WRITE(SDPOWER,HIGH);
|
|
||||||
#endif //SDPOWER
|
|
||||||
quickinitsd();
|
|
||||||
#endif //SDSUPPORT
|
|
||||||
|
|
||||||
plan_init(); // Initialize planner;
|
|
||||||
st_init(); // Initialize stepper;
|
|
||||||
tp_init(); // Initialize temperature loop
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef SDSUPPORT
|
|
||||||
|
|
||||||
void checkautostart(bool force)
|
|
||||||
{
|
|
||||||
//this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
|
|
||||||
if(!force)
|
if(!force)
|
||||||
{
|
{
|
||||||
if(!autostart_stilltocheck)
|
if(!autostart_stilltocheck)
|
||||||
|
@ -327,10 +292,58 @@ void checkautostart(bool force)
|
||||||
lastnr=-1;
|
lastnr=-1;
|
||||||
else
|
else
|
||||||
lastnr++;
|
lastnr++;
|
||||||
}
|
}
|
||||||
#else //NO SD SUPORT
|
#else //NO SD SUPORT
|
||||||
inline void checkautostart(bool x){}
|
inline void checkautostart(bool x){};
|
||||||
#endif
|
|
||||||
|
#endif //SDSUPPORT
|
||||||
|
|
||||||
|
|
||||||
|
//adds an command to the main command buffer
|
||||||
|
//thats really done in a non-safe way.
|
||||||
|
//needs overworking someday
|
||||||
|
void enquecommand(const char *cmd)
|
||||||
|
{
|
||||||
|
if(buflen < BUFSIZE)
|
||||||
|
{
|
||||||
|
//this is dangerous if a mixing of serial and this happsens
|
||||||
|
strcpy(&(cmdbuffer[bufindw][0]),cmd);
|
||||||
|
SERIAL_ECHOLN("enqueing \""<<cmdbuffer[bufindw]<<"\"");
|
||||||
|
bufindw= (bufindw + 1)%BUFSIZE;
|
||||||
|
buflen += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(BAUDRATE);
|
||||||
|
SERIAL_ECHOLN("Marlin "<<version_string);
|
||||||
|
Serial.println("start");
|
||||||
|
for(int i = 0; i < BUFSIZE; i++)
|
||||||
|
{
|
||||||
|
fromsd[i] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
RetrieveSettings(); // loads data from EEPROM if available
|
||||||
|
|
||||||
|
for(int i=0; i < NUM_AXIS; i++)
|
||||||
|
{
|
||||||
|
axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef SDSUPPORT
|
||||||
|
//power to SD reader
|
||||||
|
#if SDPOWER > -1
|
||||||
|
SET_OUTPUT(SDPOWER);
|
||||||
|
WRITE(SDPOWER,HIGH);
|
||||||
|
#endif //SDPOWER
|
||||||
|
quickinitsd();
|
||||||
|
#endif //SDSUPPORT
|
||||||
|
|
||||||
|
plan_init(); // Initialize planner;
|
||||||
|
st_init(); // Initialize stepper;
|
||||||
|
tp_init(); // Initialize temperature loop
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
|
Reference in a new issue