@ -25,6 +25,7 @@
http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
http://reprap.org/pipermail/reprap-dev/2011-May/003323.html
*/
*/
#include <EEPROM.h>
#include "EEPROMwrite.h"
#include "EEPROMwrite.h"
#include "fastio.h"
#include "fastio.h"
#include "Configuration.h"
#include "Configuration.h"
@ -37,14 +38,11 @@
#include "temperature.h"
#include "temperature.h"
#include "motion_control.h"
#include "motion_control.h"
#ifdef SIMPLE_LCD
#include "Simplelcd.h"
#endif
char version_string[] = "1.0.0 Alpha 1";
char version_string[] = "1.0.0 Alpha 1";
#ifdef SDSUPPORT
#ifdef SDSUPPORT
#include "SdFat.h"
#include "SdFat.h"
#endif //SDSUPPORT
#endif //SDSUPPORT
@ -109,12 +107,9 @@ char version_string[] = "1.0.0 Alpha 1";
//Stepper Movement Variables
//Stepper Movement Variables
char axis_codes[NUM_AXIS] = {
const char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
'X', 'Y', 'Z', 'E'};
float destination[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
float destination[NUM_AXIS] = {
float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
0.0, 0.0, 0.0, 0.0};
float current_position[NUM_AXIS] = {
0.0, 0.0, 0.0, 0.0};
float offset[3] = {0.0, 0.0, 0.0};
float offset[3] = {0.0, 0.0, 0.0};
bool home_all_axis = true;
bool home_all_axis = true;
float feedrate = 1500.0, next_feedrate, saved_feedrate;
float feedrate = 1500.0, next_feedrate, saved_feedrate;
@ -131,6 +126,7 @@ 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;
// comm variables
// comm variables
#define MAX_CMD_SIZE 96
#define MAX_CMD_SIZE 96
#define BUFSIZE 4
#define BUFSIZE 4
@ -146,13 +142,10 @@ boolean comment_mode = false;
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;
extern float HeaterPower;
#include "EEPROM.h"
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;
float tt = 0, bt = 0;
//Inactivity shutdown variables
//Inactivity shutdown variables
unsigned long previous_millis_cmd = 0;
unsigned long previous_millis_cmd = 0;
unsigned long max_inactive_time = 0;
unsigned long max_inactive_time = 0;
@ -161,73 +154,81 @@ unsigned long stepper_inactive_time = 0;
unsigned long starttime=0;
unsigned long starttime=0;
unsigned long stoptime=0;
unsigned long stoptime=0;
#ifdef SDSUPPORT
#ifdef SDSUPPORT
Sd2Card card;
Sd2Card card;
SdVolume volume;
SdVolume volume;
SdFile root;
SdFile root;
SdFile file;
SdFile file;
uint32_t filesize = 0;
uint32_t filesize = 0;
uint32_t sdpos = 0;
uint32_t sdpos = 0;
bool sdmode = false;
bool sdmode = false;
bool sdactive = false;
bool sdactive = false;
bool savetosd = false;
bool savetosd = false;
int16_t n;
int16_t n;
unsigned long autostart_atmillis=0;
unsigned long autostart_atmillis=0;
void initsd()
bool autostart_stilltocheck=true; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
{
sdactive = false;
#if SDSS >- 1
void initsd()
if(root.isOpen())
root.close();
if (!card.init(SPI_FULL_SPEED,SDSS))
{
//if (!card.init(SPI_HALF_SPEED,SDSS))
SERIAL_ECHOLN("SD init fail");
}
else if (!volume.init(&card))
{
SERIAL_ERRORLN("volume.init failed");
}
else if (!root.openRoot(&volume))
{
{
SERIAL_ERRORLN("openRoot failed");
sdactive = false;
#if SDSS >- 1
if(root.isOpen())
root.close();
if (!card.init(SPI_FULL_SPEED,SDSS))
{
//if (!card.init(SPI_HALF_SPEED,SDSS))
SERIAL_ECHOLN("SD init fail");
}
else if (!volume.init(&card))
{
SERIAL_ERRORLN("volume.init failed");
}
else if (!root.openRoot(&volume))
{
SERIAL_ERRORLN("openRoot failed");
}
else
{
sdactive = true;
SERIAL_ECHOLN("SD card ok");
}
#endif //SDSS
}
}
else
void quickinitsd()
{
{
sdactive = true;
sdactive=fals e;
SERIAL_ECHOLN("SD card ok");
autostart_atmillis=millis()+5000 ;
}
}
#endif //SDSS
}
void quickinitsd(){
sdactive=false;
autostart_atmillis=millis()+5000;
}
inline void write_command(char *buf){
inline void write_command(char *buf)
char* begin = buf;
{
char* npos = 0;
char* begin = buf;
char* end = buf + strlen(buf) - 1;
char* npos = 0;
char* end = buf + strlen(buf) - 1;
file.writeError = false;
file.writeError = false;
if((npos = strchr(buf, 'N')) != NULL){
if((npos = strchr(buf, 'N')) != NULL)
begin = strchr(npos, ' ') + 1;
{
end = strchr(npos, '*') - 1;
begin = strchr(npos, ' ') + 1;
}
end = strchr(npos, '*') - 1;
end[1] = '\r';
}
end[2] = '\n';
end[1] = '\r';
end[3] = '\0';
end[2] = '\n';
//Serial.println(begin);
end[3] = '\0';
file.write(begin);
file.write(begin);
if (file.writeError){
if (file.writeError)
SERIAL_ERRORLN("error writing to file");
{
SERIAL_ERRORLN("error writing to file");
}
}
}
}
#endif //SDSUPPORT
#endif //SDSUPPORT
///adds an command to the main command buffer
//adds an command to the main command buffer
//thats really done in a non-safe way.
//needs overworking someday
void enquecommand(const char *cmd)
void enquecommand(const char *cmd)
{
{
if(buflen < BUFSIZE)
if(buflen < BUFSIZE)
@ -242,106 +243,93 @@ void enquecommand(const char *cmd)
void setup()
void setup()
{
{
Serial.begin(BAUDRATE);
Serial.begin(BAUDRATE);
SERIAL_ECHOLN("Marlin "<<version_string);
SERIAL_ECHOLN("Marlin "<<version_string);
Serial.println("start");
Serial.println("start");
#if defined FANCY_LCD || defined SIMPLE_LCD
for(int i = 0; i < BUFSIZE; i++)
lcd_init();
{
#endif
for(int i = 0; i < BUFSIZE; i++){
fromsd[i] = false;
fromsd[i] = false;
}
}
RetrieveSettings(); // loads data from EEPROM if available
RetrieveSettings(); // loads data from EEPROM if available
for(int i=0; i < NUM_AXIS; i++)
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];
axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
}
}
#ifdef SDSUPPORT
#ifdef SDSUPPORT
//power to SD reader
//power to SD reader
#if SDPOWER > -1
#if SDPOWER > -1
SET_OUTPUT(SDPOWER);
SET_OUTPUT(SDPOWER);
WRITE(SDPOWER,HIGH);
WRITE(SDPOWER,HIGH);
#endif //SDPOWER
#endif //SDPOWER
quickinitsd();
quickinitsd();
#endif //SDSUPPORT
#endif //SDSUPPORT
plan_init(); // Initialize planner;
plan_init(); // Initialize planner;
st_init(); // Initialize stepper;
st_init(); // Initialize stepper;
tp_init(); // Initialize temperature loop
tp_init(); // Initialize temperature loop
//checkautostart();
}
}
#ifdef SDSUPPORT
#ifdef SDSUPPORT
bool autostart_stilltocheck=true;
void checkautostart(bool force)
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
//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)
return;
return;
if(autostart_atmillis<millis())
if(autostart_atmillis<millis())
return;
return;
}
}
autostart_stilltocheck=false;
autostart_stilltocheck=false;
if(!sdactive)
if(!sdactive)
{
{
initsd();
initsd();
if(!sdactive) //fail
if(!sdactive) //fail
return;
return;
}
}
static int lastnr=0;
static int lastnr=0;
char autoname[30];
char autoname[30];
sprintf(autoname,"auto%i.g",lastnr);
sprintf(autoname,"auto%i.g",lastnr);
for(int i=0;i<(int)strlen(autoname);i++)
for(int i=0;i<(int)strlen(autoname);i++)
autoname[i]=tolower(autoname[i]);
autoname[i]=tolower(autoname[i]);
dir_t p;
dir_t p;
root.rewind();
//char filename[11];
//int cnt=0;
bool found=false;
while (root.readDir(p) > 0)
{
for(int i=0;i<(int)strlen((char*)p.name);i++)
p.name[i]=tolower(p.name[i]);
//Serial.print((char*)p.name);
//Serial.print(" ");
//Serial.println(autoname);
if(p.name[9]!='~') //skip safety copies
if(strncmp((char*)p.name,autoname,5)==0)
{
char cmd[30];
sprintf(cmd,"M23 %s",autoname);
//sprintf(cmd,"M115");
//enquecommand("G92 Z0");
//enquecommand("G1 Z10 F2000");
//enquecommand("G28 X-105 Y-105");
enquecommand(cmd);
enquecommand("M24");
found=true;
}
}
if(!found)
lastnr=-1;
else
lastnr++;
}
root.rewind();
#else
inline void checkautostart(bool x)
bool found=false;
{
while (root.readDir(p) > 0)
{
for(int i=0;i<(int)strlen((char*)p.name);i++)
p.name[i]=tolower(p.name[i]);
//Serial.print((char*)p.name);
//Serial.print(" ");
//Serial.println(autoname);
if(p.name[9]!='~') //skip safety copies
if(strncmp((char*)p.name,autoname,5)==0)
{
char cmd[30];
sprintf(cmd,"M23 %s",autoname);
//sprintf(cmd,"M115");
//enquecommand("G92 Z0");
//enquecommand("G1 Z10 F2000");
//enquecommand("G28 X-105 Y-105");
enquecommand(cmd);
enquecommand("M24");
found=true;
}
}
if(!found)
lastnr=-1;
else
lastnr++;
}
}
#else //NO SD SUPORT
inline void checkautostart(bool x){}
#endif
#endif
@ -349,28 +337,32 @@ void loop()
{
{
if(buflen<3)
if(buflen<3)
get_command();
get_command();
checkautostart(false);
checkautostart(false);
if(buflen)
if(buflen)
{
{
#ifdef SDSUPPORT
#ifdef SDSUPPORT
if(savetosd){
if(savetosd)
if(strstr(cmdbuffer[bufindr],"M29") == NULL){
{
write_command(cmdbuffer[bufindr]);
if(strstr(cmdbuffer[bufindr],"M29") == NULL)
Serial.println("ok");
{
write_command(cmdbuffer[bufindr]);
Serial.println("ok");
}
else
{
file.sync();
file.close();
savetosd = false;
Serial.println("Done saving file.");
}
}
}
else{
else
file.sync();
{
file.close();
process_commands();
savetosd = false;
Serial.println("Done saving file.");
}
}
}
#else
else{
process_commands();
process_commands();
}
#endif //SDSUPPORT
#else
process_commands();
#endif //SDSUPPORT
buflen = (buflen-1);
buflen = (buflen-1);
bufindr = (bufindr + 1)%BUFSIZE;
bufindr = (bufindr + 1)%BUFSIZE;
}
}
@ -449,10 +441,10 @@ inline void get_command()
case 1:
case 1:
case 2:
case 2:
case 3:
case 3:
#ifdef SDSUPPORT
#ifdef SDSUPPORT
if(savetosd)
if(savetosd)
break;
break;
#endif //SDSUPPORT
#endif //SDSUPPORT
Serial.println("ok");
Serial.println("ok");
break;
break;
default:
default:
@ -473,7 +465,7 @@ inline void get_command()
if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
}
}
}
}
#ifdef SDSUPPORT
#ifdef SDSUPPORT
if(!sdmode || serial_count!=0){
if(!sdmode || serial_count!=0){
return;
return;
}
}
@ -486,18 +478,19 @@ inline void get_command()
if(sdpos >= filesize){
if(sdpos >= filesize){
sdmode = false;
sdmode = false;
Serial.println("echo: Done printing file");
Serial.println("echo: Done printing file");
stoptime=millis();
stoptime=millis();
char time[30];
char time[30];
unsigned long t=(stoptime-starttime)/1000;
unsigned long t=(stoptime-starttime)/1000;
int sec,min;
int sec,min;
min=t/60;
min=t/60;
sec=t%60;
sec=t%60;
sprintf(time,"echo: %i min, %i sec",min,sec);
sprintf(time,"echo: %i min, %i sec",min,sec);
Serial.println(time);
Serial.println(time);
LCD_MESSAGE(time);
LCD_MESSAGE(time);
checkautostart(true);
checkautostart(true);
}
}
if(!serial_count) return; //if empty line
if(!serial_count)
return; //if empty line
cmdbuffer[bufindw][serial_count] = 0; //terminate string
cmdbuffer[bufindw][serial_count] = 0; //terminate string
if(!comment_mode){
if(!comment_mode){
fromsd[bufindw] = true;
fromsd[bufindw] = true;
@ -513,20 +506,23 @@ inline void get_command()
if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
if(!comment_mode) cmdbuffer[bufindw][serial_count++] = serial_char;
}
}
}
}
#endif //SDSUPPORT
#endif //SDSUPPORT
}
}
inline float code_value() {
inline float code_value()
{
return (strtod(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL));
return (strtod(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL));
}
}
inline long code_value_long() {
inline long code_value_long()
{
return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10));
return (strtol(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL, 10));
}
}
inline bool code_seen(char code_string[]) {
inline bool code_seen(char code_string[]) //Return True if the string was found
{
return (strstr(cmdbuffer[bufindr], code_string) != NULL);
return (strstr(cmdbuffer[bufindr], code_string) != NULL);
} //Return True if the string was found
}
inline bool code_seen(char code)
inline bool code_seen(char code)
{
{
@ -579,10 +575,10 @@ inline void process_commands()
destination[i] = current_position[i];
destination[i] = current_position[i];
}
}
feedrate = 0.0;
feedrate = 0.0;
home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2])));
home_all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2])));
if((home_all_axis) || (code_seen(axis_codes[X_AXIS]))) {
if((home_all_axis) || (code_seen(axis_codes[X_AXIS])))
{
if ((X_MIN_PIN > -1 && X_HOME_DIR==-1) || (X_MAX_PIN > -1 && X_HOME_DIR==1)){
if ((X_MIN_PIN > -1 && X_HOME_DIR==-1) || (X_MAX_PIN > -1 && X_HOME_DIR==1)){
// st_synchronize();
// st_synchronize();
current_position[X_AXIS] = 0;
current_position[X_AXIS] = 0;
@ -689,7 +685,7 @@ inline void process_commands()
switch( (int)code_value() )
switch( (int)code_value() )
{
{
#ifdef SDSUPPORT
#ifdef SDSUPPORT
case 20: // M20 - list SD card
case 20: // M20 - list SD card
Serial.println("Begin file list");
Serial.println("Begin file list");
@ -781,6 +777,8 @@ inline void process_commands()
//processed in write to file routine above
//processed in write to file routine above
//savetosd = false;
//savetosd = false;
break;
break;
#endif //SDSUPPORT
case 30: //M30 take time since the start of the SD print or an M109 command
case 30: //M30 take time since the start of the SD print or an M109 command
{
{
stoptime=millis();
stoptime=millis();
@ -794,133 +792,134 @@ inline void process_commands()
LCD_MESSAGE(time);
LCD_MESSAGE(time);
}
}
break;
break;
#endif //SDSUPPORT
case 42: //M42 -Change pin status via gcode
case 42: //M42 -Change pin status via gcode
if (code_seen('S'))
if (code_seen('S'))
{
int pin_status = code_value();
if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
{
{
int pin_status = code_value();
int pin_number = code_value();
if (code_seen('P') && pin_status >= 0 && pin_status <= 255 )
for(int i = 0; i < (int)sizeof(sensitive_pins); i++ )
{
{
int pin_number = code_value();
if (sensitive_pins[i] == pin_number)
for(int i = 0; i < (int)sizeof(sensitive_pins); i++)
{
{
if (sensitive_pins[i] == pin_number)
pin_number = -1;
{
break;
pin_number = -1;
break;
}
}
}
}
if (pin_number > -1)
if (pin_number > -1)
{
{
pinMode(pin_number, OUTPUT);
pinMode(pin_number, OUTPUT);
digitalWrite(pin_number, pin_status);
digitalWrite(pin_number, pin_status);
analogWrite(pin_number, pin_status);
analogWrite(pin_number, pin_status);
}
}
}
}
}
break;
}
case 104: // M104
break;
if (code_seen('S')) setTargetHotend0(code_value());
case 104: // M104
setWatch();
if (code_seen('S')) setTargetHotend0(code_value());
break;
setWatch();
case 140: // M140 set bed temp
break;
if (code_seen('S')) setTargetBed(code_value());
case 140: // M140 set bed temp
break;
if (code_seen('S')) setTargetBed(code_value());
case 105: // M105
break;
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
case 105: // M105
tt = degHotend0();
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
#endif
tt = degHotend0();
#endif
#if TEMP_1_PIN > -1
bt = degBed();
#endif
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
Serial.print("ok T:");
Serial.print(tt);
#if TEMP_1_PIN > -1
#if TEMP_1_PIN > -1
bt = degBed();
#ifdef PIDTEMP
#endif
#if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
Serial.print("ok T:");
Serial.print(tt);
// Serial.print(", raw:");
// Serial.print(current_raw);
#if TEMP_1_PIN > -1
#ifdef PIDTEMP
Serial.print(" B:");
Serial.print(" B:");
#if TEMP_1_PIN > -1
#if TEMP_1_PIN > -1
Serial.println(bt);
Serial.println(bt);
#else
#else
Serial.println(HeaterPower);
Serial.println(HeaterPower);
#endif
#endif
#else
#else //not PIDTEMP
Serial.println();
Serial.println();
#endif
#endif //PIDTEMP
#else
#else
Serial.println();
Serial.println();
#endif
#endif //TEMP_1_PIN
#else
#else
Serial.println("echo: No thermistors - no temp");
Serial.println("echo: No thermistors - no temp");
#endif
#endif
return;
return;
//break;
break;
case 109: {// M109 - Wait for extruder heater to reach target.
case 109:
LCD_MESSAGE("Heating...");
{// M109 - Wait for extruder heater to reach target.
if (code_seen('S')) setTargetHotend0(code_value());
LCD_MESSAGE("Heating...");
if (code_seen('S')) setTargetHotend0(code_value());
setWatch();
codenum = millis();
/* See if we are heating up or cooling down */
bool target_direction = isHeatingHotend0(); // true if heating, false if cooling
#ifdef TEMP_RESIDENCY_TIME
setWatch();
long residencyStart;
codenum = millis();
residencyStart = -1;
/* continue to loop until we have reached the target temp
/* See if we are heating up or cooling down */
_and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
bool target_direction = isHeatingHotend0(); // true if heating, false if cooling
while((target_direction ? (isHeatingHotend0()) : (isCoolingHotend0()) ||
(residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
#ifdef TEMP_RESIDENCY_TIME
#else
long residencyStart;
while ( target_direction ? (isHeatingHotend0()) : (isCoolingHotend0()) ) {
residencyStart = -1;
#endif //TEMP_RESIDENCY_TIME
/* continue to loop until we have reached the target temp
if( (millis() - codenum) > 1000 ) { //Print Temp Reading every 1 second while heating up/cooling down
_and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
Serial.print("T:");
while((target_direction ? (isHeatingHotend0()) : (isCoolingHotend0()) ||
Serial.println( degHotend0() );
(residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
codenum = millis();
#else
}
while ( target_direction ? (isHeatingHotend0()) : (isCoolingHotend0()) ) {
manage_heater();
#endif //TEMP_RESIDENCY_TIME
LCD_STATUS;
if( (millis() - codenum) > 1000 )
#ifdef TEMP_RESIDENCY_TIME
{ //Print Temp Reading every 1 second while heating up/cooling down
/* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
Serial.print("T:");
or when current temp falls outside the hysteresis after target temp was reached */
Serial.println( degHotend0() );
if ((residencyStart == -1 && target_direction && !isHeatingHotend0()) ||
codenum = millis();
(residencyStart == -1 && !target_direction && !isCoolingHotend0()) ||
}
(residencyStart > -1 && labs(degHotend0() - degTargetHotend0()) > TEMP_HYSTERESIS) ) {
manage_heater();
residencyStart = millis();
LCD_STATUS;
}
#ifdef TEMP_RESIDENCY_TIME
#endif //TEMP_RESIDENCY_TIME
/* start/restart the TEMP_RESIDENCY_TIME timer whenever we reach target temp for the first time
}
or when current temp falls outside the hysteresis after target temp was reached */
LCD_MESSAGE("Heating done.");
if ((residencyStart == -1 && target_direction && !isHeatingHotend0()) ||
starttime=millis();
(residencyStart == -1 && !target_direction && !isCoolingHotend0()) ||
}
(residencyStart > -1 && labs(degHotend0() - degTargetHotend0()) > TEMP_HYSTERESIS) )
break;
case 190: // M190 - Wait bed for heater to reach target.
#if TEMP_1_PIN > -1
if (code_seen('S')) setTargetBed(code_value());
codenum = millis();
while(isHeatingBed())
{
{
if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
residencyStart = millis();
{
}
float tt=degHotend0();
#endif //TEMP_RESIDENCY_TIME
Serial.print("T:");
}
Serial.println( tt );
LCD_MESSAGE("Heating done.");
Serial.print("ok T:");
starttime=millis();
Serial.print( tt );
}
Serial.print(" B:");
Serial.println( degBed() );
codenum = millis();
}
manage_heater();
}
#endif
break;
break;
#if FAN_PIN > -1
case 190: // M190 - Wait bed for heater to reach target.
#if TEMP_1_PIN > -1
if (code_seen('S')) setTargetBed(code_value());
codenum = millis();
while(isHeatingBed())
{
if( (millis()-codenum) > 1000 ) //Print Temp Reading every 1 second while heating up.
{
float tt=degHotend0();
Serial.print("T:");
Serial.println( tt );
Serial.print("ok T:");
Serial.print( tt );
Serial.print(" B:");
Serial.println( degBed() );
codenum = millis();
}
manage_heater();
}
#endif
break;
#if FAN_PIN > -1
case 106: //M106 Fan On
case 106: //M106 Fan On
if (code_seen('S')){
if (code_seen('S')){
WRITE(FAN_PIN,HIGH);
WRITE(FAN_PIN,HIGH);
@ -937,27 +936,29 @@ inline void process_commands()
WRITE(FAN_PIN,LOW);
WRITE(FAN_PIN,LOW);
analogWrite(FAN_PIN, 0);
analogWrite(FAN_PIN, 0);
break;
break;
#endif
#endif //FAN_PIN
#if (PS_ON_PIN > -1)
#if (PS_ON_PIN > -1)
case 80: // M80 - ATX Power On
case 80: // M80 - ATX Power On
SET_OUTPUT(PS_ON_PIN); //GND
SET_OUTPUT(PS_ON_PIN); //GND
break;
break;
case 81: // M81 - ATX Power Off
case 81: // M81 - ATX Power Off
SET_INPUT(PS_ON_PIN); //Floating
SET_INPUT(PS_ON_PIN); //Floating
break;
break;
#endif
#endif
case 82:
case 82:
axis_relative_modes[3] = false;
axis_relative_modes[3] = false;
break;
break;
case 83:
case 83:
axis_relative_modes[3] = true;
axis_relative_modes[3] = true;
break;
break;
case 18:
case 18: //compatibility
case 84:
case 84:
if(code_seen('S')){
if(code_seen('S')){
stepper_inactive_time = code_value() * 1000;
stepper_inactive_time = code_value() * 1000;
}
}
else{
else
{
st_synchronize();
st_synchronize();
disable_x();
disable_x();
disable_y();
disable_y();
@ -970,13 +971,14 @@ inline void process_commands()
max_inactive_time = code_value() * 1000;
max_inactive_time = code_value() * 1000;
break;
break;
case 92: // M92
case 92: // M92
for(int i=0; i < NUM_AXIS; i++) {
for(int i=0; i < NUM_AXIS; i++)
if(code_seen(axis_codes[i])) axis_steps_per_unit[i] = code_value();
{
if(code_seen(axis_codes[i]))
axis_steps_per_unit[i] = code_value();
}
}
break;
break;
case 115: // M115
case 115: // M115
Serial.println("FIRMWARE_NAME:Sprinter/grbl mashup for gen6 FIRMWARE_URL:http://www.mendel-parts.com PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1");
Serial.println("FIRMWARE_NAME:Marlin; Sprinter/grbl mashup for gen6 FIRMWARE_URL:http://www.mendel-parts.com PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1");
break;
break;
case 114: // M114
case 114: // M114
Serial.print("X:");
Serial.print("X:");
@ -998,45 +1000,46 @@ inline void process_commands()
Serial.println("");
Serial.println("");
break;
break;
case 119: // M119
case 119: // M119
#if (X_MIN_PIN > -1)
#if (X_MIN_PIN > -1)
Serial.print("x_min:");
Serial.print("x_min:");
Serial.print((READ(X_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
Serial.print((READ(X_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
#endif
#endif
#if (X_MAX_PIN > -1)
#if (X_MAX_PIN > -1)
Serial.print("x_max:");
Serial.print("x_max:");
Serial.print((READ(X_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
Serial.print((READ(X_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
#endif
#endif
#if (Y_MIN_PIN > -1)
#if (Y_MIN_PIN > -1)
Serial.print("y_min:");
Serial.print("y_min:");
Serial.print((READ(Y_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
Serial.print((READ(Y_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
#endif
#endif
#if (Y_MAX_PIN > -1)
#if (Y_MAX_PIN > -1)
Serial.print("y_max:");
Serial.print("y_max:");
Serial.print((READ(Y_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
Serial.print((READ(Y_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
#endif
#endif
#if (Z_MIN_PIN > -1)
#if (Z_MIN_PIN > -1)
Serial.print("z_min:");
Serial.print("z_min:");
Serial.print((READ(Z_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
Serial.print((READ(Z_MIN_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
#endif
#endif
#if (Z_MAX_PIN > -1)
#if (Z_MAX_PIN > -1)
Serial.print("z_max:");
Serial.print("z_max:");
Serial.print((READ(Z_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
Serial.print((READ(Z_MAX_PIN)^ENDSTOPS_INVERTING)?"H ":"L ");
#endif
#endif
Serial.println("");
Serial.println("");
break;
break;
//TODO: update for all axis, use for loop
//TODO: update for all axis, use for loop
case 201: // M201
case 201: // M201
for(int i=0; i < NUM_AXIS; i++) {
for(int i=0; i < NUM_AXIS; i++)
{
if(code_seen(axis_codes[i])) axis_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
if(code_seen(axis_codes[i])) axis_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
}
}
break;
break;
#if 0 // Not used for Sprinter/grbl gen6
#if 0 // Not used for Sprinter/grbl gen6
case 202: // M202
case 202: // M202
for(int i=0; i < NUM_AXIS; i++) {
for(int i=0; i < NUM_AXIS; i++) {
if(code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
if(code_seen(axis_codes[i])) axis_travel_steps_per_sqr_second[i] = code_value() * axis_steps_per_unit[i];
}
}
break;
break;
#endif
#endif
case 203: // M203 max feedrate mm/sec
case 203: // M203 max feedrate mm/sec
for(int i=0; i < NUM_AXIS; i++) {
for(int i=0; i < NUM_AXIS; i++) {
if(code_seen(axis_codes[i])) max_feedrate[i] = code_value()*60 ;
if(code_seen(axis_codes[i])) max_feedrate[i] = code_value()*60 ;
@ -1048,59 +1051,52 @@ inline void process_commands()
if(code_seen('T')) retract_acceleration = code_value() ;
if(code_seen('T')) retract_acceleration = code_value() ;
}
}
break;
break;
case 205: //M205 advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk
case 205: //M205 advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk
{
{
if(code_seen('S')) minimumfeedrate = code_value()*60 ;
if(code_seen('S')) minimumfeedrate = code_value()*60 ;
if(code_seen('T')) mintravelfeedrate = code_value()*60 ;
if(code_seen('T')) mintravelfeedrate = code_value()*60 ;
if(code_seen('B')) minsegmenttime = code_value() ;
if(code_seen('B')) minsegmenttime = code_value() ;
if(code_seen('X')) max_xy_jerk = code_value()*60 ;
if(code_seen('X')) max_xy_jerk = code_value()*60 ;
if(code_seen('Z')) max_z_jerk = code_value()*60 ;
if(code_seen('Z')) max_z_jerk = code_value()*60 ;
}
}
break;
break;
case 220: // M220 S<factor in percent>- set speed factor override percentage
case 220: // M220 S<factor in percent>- set speed factor override percentage
{
if(code_seen('S'))
{
{
if(code_seen('S'))
feedmultiply = code_value() ;
{
feedmultiplychanged=true;
feedmultiply = code_value() ;
feedmultiplychanged=true;
}
}
}
break;
}
#ifdef PIDTEMP
break;
#ifdef PIDTEMP
case 301: // M301
case 301: // M301
if(code_seen('P')) Kp = code_value();
if(code_seen('P')) Kp = code_value();
if(code_seen('I')) Ki = code_value()*PID_dT;
if(code_seen('I')) Ki = code_value()*PID_dT;
if(code_seen('D')) Kd = code_value()/PID_dT;
if(code_seen('D')) Kd = code_value()/PID_dT;
// SERIAL_ECHOLN("Kp "<<_FLOAT(Kp,2));
// SERIAL_ECHOLN("Ki "<<_FLOAT(Ki/PID_dT,2));
// SERIAL_ECHOLN("Kd "<<_FLOAT(Kd*PID_dT,2));
// temp_iState_min = 0.0;
// if (Ki!=0) {
// temp_iState_max = PID_INTEGRAL_DRIVE_MAX / (Ki/100.0);
// }
// else temp_iState_max = 1.0e10;
break;
#endif //PIDTEMP
case 500: // Store settings in EEPROM
{
StoreSettings();
}
break;
case 501: // Read settings from EEPROM
{
RetrieveSettings();
}
break;
case 502: // Revert to default settings
{
RetrieveSettings(true);
}
break;
break;
#endif //PIDTEMP
case 500: // Store settings in EEPROM
{
StoreSettings();
}
break;
case 501: // Read settings from EEPROM
{
RetrieveSettings();
}
break;
case 502: // Revert to default settings
{
RetrieveSettings(true);
}
break;
}
}
}
}
else{
else
{
Serial.print("echo: Unknown command:\"");
Serial.print("echo: Unknown command:\"");
Serial.print(cmdbuffer[bufindr]);
Serial.print(cmdbuffer[bufindr]);
Serial.println("\"");
Serial.println("\"");
@ -1121,10 +1117,10 @@ void FlushSerialRequestResend()
void ClearToSend()
void ClearToSend()
{
{
previous_millis_cmd = millis();
previous_millis_cmd = millis();
#ifdef SDSUPPORT
#ifdef SDSUPPORT
if(fromsd[bufindr])
if(fromsd[bufindr])
return;
return;
#endif //SDSUPPORT
#endif //SDSUPPORT
Serial.println("ok");
Serial.println("ok");
}
}
@ -1132,7 +1128,7 @@ inline void get_coordinates()
{
{
for(int i=0; i < NUM_AXIS; i++) {
for(int i=0; i < NUM_AXIS; i++) {
if(code_seen(axis_codes[i])) destination[i] = (float)code_value() + (axis_relative_modes[i] || relative_mode)*current_position[i];
if(code_seen(axis_codes[i])) destination[i] = (float)code_value() + (axis_relative_modes[i] || relative_mode)*current_position[i];
else destination[i] = current_position[i]; //Are these else lines really needed?
else destination[i] = current_position[i]; //Are these else lines really needed?
}
}
if(code_seen('F')) {
if(code_seen('F')) {
next_feedrate = code_value();
next_feedrate = code_value();
@ -1276,14 +1272,19 @@ void prepare_arc_move(char isclockwise) {
void manage_inactivity(byte debug) {
void manage_inactivity(byte debug)
if( (millis()-previous_millis_cmd) > max_inactive_time ) if(max_inactive_time) kill();
{
if( (millis()-previous_millis_cmd) > stepper_inactive_time ) if(stepper_inactive_time) {
if( (millis()-previous_millis_cmd) > max_inactive_time )
disable_x();
if(max_inactive_time)
disable_y();
kill();
disable_z();
if( (millis()-previous_millis_cmd) > stepper_inactive_time )
disable_e();
if(stepper_inactive_time)
}
{
disable_x();
disable_y();
disable_z();
disable_e();
}
check_axes_activity();
check_axes_activity();
}
}