static unsigned long starttime=0;
static unsigned long stoptime=0;
-
+static uint8_t tmp_extruder;
//===========================================================================
//=============================ROUTINES=============================
//processed in write to file routine above
//card,saving = false;
break;
-
#endif //SDSUPPORT
case 30: //M30 take time since the start of the SD print or an M109 command
}
break;
case 104: // M104
- if (code_seen('S')) setTargetHotend0(code_value());
+ tmp_extruder = active_extruder;
+ if(code_seen('T')) {
+ tmp_extruder = code_value();
+ if(tmp_extruder >= EXTRUDERS) {
+ SERIAL_ECHO_START;
+ SERIAL_ECHO("M104 Invalid extruder ");
+ SERIAL_ECHOLN(tmp_extruder);
+ break;
+ }
+ }
+ if (code_seen('S')) setTargetHotend(code_value(), tmp_extruder);
setWatch();
break;
case 140: // M140 set bed temp
if (code_seen('S')) setTargetBed(code_value());
break;
case 105 : // M105
- //SERIAL_ECHOLN(freeMemory());
- //test watchdog:
- //delay(20000);
- #if (TEMP_0_PIN > -1) || defined (HEATER_USES_AD595)
+ tmp_extruder = active_extruder;
+ if(code_seen('T')) {
+ tmp_extruder = code_value();
+ if(tmp_extruder >= EXTRUDERS) {
+ SERIAL_ECHO_START;
+ SERIAL_ECHO("M105 Invalid extruder ");
+ SERIAL_ECHOLN(tmp_extruder);
+ break;
+ }
+ }
+ #if (TEMP_0_PIN > -1) || (TEMP_2_PIN > -1)
SERIAL_PROTOCOLPGM("ok T:");
- SERIAL_PROTOCOL( degHotend0());
+ SERIAL_PROTOCOL( degHotend(tmp_extruder));
#if TEMP_1_PIN > -1
SERIAL_PROTOCOLPGM(" B:");
SERIAL_PROTOCOL(degBed());
break;
case 109:
{// M109 - Wait for extruder heater to reach target.
- LCD_MESSAGEPGM("Heating...");
- #ifdef AUTOTEMP
- autotemp_enabled=false;
- #endif
- if (code_seen('S')) setTargetHotend0(code_value());
- #ifdef AUTOTEMP
- if (code_seen('S')) autotemp_min=code_value();
- if (code_seen('T')) autotemp_max=code_value();
- if (code_seen('F'))
- {
- autotemp_factor=code_value();
- autotemp_enabled=true;
- }
- #endif
-
- 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
- long residencyStart;
- residencyStart = -1;
- /* continue to loop until we have reached the target temp
- _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
- while((target_direction ? (isHeatingHotend0()) : (isCoolingHotend0())) ||
- (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
- #else
- while ( target_direction ? (isHeatingHotend0()) : (isCoolingHotend0()&&(CooldownNoWait==false)) ) {
- #endif //TEMP_RESIDENCY_TIME
+ tmp_extruder = active_extruder;
+ if(code_seen('T')) {
+ tmp_extruder = code_value();
+ if(tmp_extruder >= EXTRUDERS) {
+ SERIAL_ECHO_START;
+ SERIAL_ECHO("M109 Invalid extruder ");
+ SERIAL_ECHOLN(tmp_extruder);
+ break;
+ }
+ }
+ LCD_MESSAGEPGM("Heating...");
+ #ifdef AUTOTEMP
+ autotemp_enabled=false;
+ #endif
+ if (code_seen('S')) setTargetHotend(code_value(), tmp_extruder);
+ #ifdef AUTOTEMP
+ if (code_seen('S')) autotemp_min=code_value();
+ if (code_seen('G')) autotemp_max=code_value();
+ if (code_seen('F'))
+ {
+ autotemp_factor=code_value();
+ autotemp_enabled=true;
+ }
+ #endif
+
+ setWatch();
+ codenum = millis();
+
+ /* See if we are heating up or cooling down */
+ bool target_direction = isHeatingHotend(tmp_extruder); // true if heating, false if cooling
+
+ #ifdef TEMP_RESIDENCY_TIME
+ long residencyStart;
+ residencyStart = -1;
+ /* continue to loop until we have reached the target temp
+ _and_ until TEMP_RESIDENCY_TIME hasn't passed since we reached it */
+ while((target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder))) ||
+ (residencyStart > -1 && (millis() - residencyStart) < TEMP_RESIDENCY_TIME*1000) ) {
+ #else
+ while ( target_direction ? (isHeatingHotend(tmp_extruder)) : (isCoolingHotend(tmp_extruder)&&(CooldownNoWait==false)) ) {
+ #endif //TEMP_RESIDENCY_TIME
if( (millis() - codenum) > 1000 )
{ //Print Temp Reading every 1 second while heating up/cooling down
SERIAL_PROTOCOLPGM("T:");
- SERIAL_PROTOCOLLN( degHotend0() );
+ SERIAL_PROTOCOLLN( degHotend(tmp_extruder) );
codenum = millis();
}
manage_heater();
#ifdef 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 */
- if ((residencyStart == -1 && target_direction && !isHeatingHotend0()) ||
- (residencyStart == -1 && !target_direction && !isCoolingHotend0()) ||
- (residencyStart > -1 && labs(degHotend0() - degTargetHotend0()) > TEMP_HYSTERESIS) )
+ if ((residencyStart == -1 && target_direction && !isHeatingHotend(tmp_extruder)) ||
+ (residencyStart == -1 && !target_direction && !isCoolingHotend(tmp_extruder)) ||
+ (residencyStart > -1 && labs(degHotend(tmp_extruder) - degTargetHotend(tmp_extruder)) > TEMP_HYSTERESIS) )
{
residencyStart = millis();
}
#ifdef PIDTEMP
case 301: // M301
{
-
-
if(code_seen('P')) Kp = code_value();
if(code_seen('I')) Ki = code_value()*PID_dT;
if(code_seen('D')) Kd = code_value()/PID_dT;
}
}
+ else if(code_seen('T')) {
+ tmp_extruder = code_value();
+ if(tmp_extruder >= EXTRUDERS) {
+ SERIAL_ECHO_START;
+ SERIAL_ECHO("T");
+ SERIAL_ECHO(tmp_extruder);
+ SERIAL_ECHOLN("Invalid extruder");
+ }
+ else {
+ active_extruder = tmp_extruder;
+ }
+ }
else
{
SERIAL_ECHO_START;
inline float degHotend0(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);};\r
inline float degHotend1(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_1]);};\r
inline float degBed() { return analog2tempBed(current_raw[TEMPSENSOR_BED]);};\r
+inline float degHotend(uint8_t extruder){ \r
+ if(extruder == 0) return analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);\r
+ if(extruder == 1) return analog2temp(current_raw[TEMPSENSOR_HOTEND_1]);\r
+};\r
\r
inline float degTargetHotend0() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);};\r
inline float degTargetHotend1() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);};\r
+inline float degTargetHotend(uint8_t extruder){ \r
+ if(extruder == 0) return analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);\r
+ if(extruder == 1) return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);\r
+};\r
+\r
inline float degTargetBed() { return analog2tempBed(target_raw[TEMPSENSOR_BED]);};\r
\r
inline void setTargetHotend0(const float &celsius) \r
#endif //PIDTEMP\r
};\r
inline void setTargetHotend1(const float &celsius) { target_raw[TEMPSENSOR_HOTEND_1]=temp2analog(celsius);};\r
+inline float setTargetHotend(const float &celcius, uint8_t extruder){ \r
+ if(extruder == 0) setTargetHotend0(celcius);\r
+ if(extruder == 1) setTargetHotend1(celcius);\r
+};\r
inline void setTargetBed(const float &celsius) { target_raw[TEMPSENSOR_BED ]=temp2analogBed(celsius);};\r
\r
inline bool isHeatingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];};\r
inline bool isHeatingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];};\r
+inline float isHeatingHotend(uint8_t extruder){ \r
+ if(extruder == 0) return target_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];\r
+ if(extruder == 1) return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];\r
+};\r
inline bool isHeatingBed() {return target_raw[TEMPSENSOR_BED] > current_raw[TEMPSENSOR_BED];};\r
\r
inline bool isCoolingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] < current_raw[TEMPSENSOR_HOTEND_0];};\r
inline bool isCoolingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] < current_raw[TEMPSENSOR_HOTEND_1];};\r
+inline float isCoolingHotend(uint8_t extruder){ \r
+ if(extruder == 0) return target_raw[TEMPSENSOR_HOTEND_0] < current_raw[TEMPSENSOR_HOTEND_0];\r
+ if(extruder == 1) return target_raw[TEMPSENSOR_HOTEND_1] < current_raw[TEMPSENSOR_HOTEND_1];\r
+};\r
inline bool isCoolingBed() {return target_raw[TEMPSENSOR_BED] < current_raw[TEMPSENSOR_BED];};\r
\r
void disable_heater();\r