From: Erik van der Zalm Date: Mon, 12 Dec 2011 19:35:46 +0000 (+0100) Subject: merging X-Git-Tag: iwj-success-2012-07-29~142^2~2 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=84d9cf7339efef8c79143bf5496b9e063253933b;p=marlin.git merging --- 84d9cf7339efef8c79143bf5496b9e063253933b diff --cc Marlin/Configuration.h index d4e23bd,dc8c799..58f5bca --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@@ -65,15 -58,15 +62,15 @@@ #define BED_CHECK_INTERVAL 5000 //ms - //// Experimental watchdog and minimal temp - // The watchdog waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature - // If the temperature has not increased at the end of that period, the target temperature is set to zero. It can be reset with another M104/M109 - /// CURRENTLY NOT IMPLEMENTED AND UNUSEABLE - //#define WATCHPERIOD 5000 //5 seconds + //// Heating sanity check: + // This waits for the watchperiod in milliseconds whenever an M104 or M109 increases the target temperature + // If the temperature has not increased at the end of that period, the target temperature is set to zero. + // It can be reset with another M104/M109 + //#define WATCHPERIOD 20000 //20 seconds // Actual temperature must be close to target for this long before M109 returns success -//#define TEMP_RESIDENCY_TIME 20 // (seconds) -//#define TEMP_HYSTERESIS 5 // (C°) range of +/- temperatures considered "close" to the target one +#define TEMP_RESIDENCY_TIME 30 // (seconds) +#define TEMP_HYSTERESIS 3 // (C°) range of +/- temperatures considered "close" to the target one //// The minimal temperature defines the temperature below which the heater will not be enabled #define HEATER_0_MINTEMP 5 @@@ -303,8 -302,9 +313,9 @@@ const bool Z_ENDSTOPS_INVERTING = true //#define ULTRA_LCD //general lcd support, also 16x2 //#define SDSUPPORT // Enable SD Card Support in Hardware Console #define SD_FINISHED_STEPPERRELEASE true //if sd support and the file is finished: disable steppers? + #define SD_FINISHED_RELEASECOMMAND "M84 X Y E" // no z because of layer shift. -//#define ULTIPANEL +#define ULTIPANEL #ifdef ULTIPANEL //#define NEWPANEL //enable this if you have a click-encoder panel #define SDSUPPORT diff --cc Marlin/Marlin.h index d4654a3,8f98244..f8ded92 --- a/Marlin/Marlin.h +++ b/Marlin/Marlin.h @@@ -147,8 -131,6 +148,9 @@@ extern float homing_feedrate[] extern bool axis_relative_modes[]; extern float current_position[NUM_AXIS] ; extern float add_homeing[3]; + extern bool stop_heating_wait; +// Handling multiple extruders pins +extern uint8_t active_extruder; + #endif diff --cc Marlin/Marlin.pde index 183002f,4d031ea..79707e8 --- a/Marlin/Marlin.pde +++ b/Marlin/Marlin.pde @@@ -132,11 -136,9 +135,11 @@@ bool axis_relative_modes[] = AXIS_RELAT volatile int feedmultiply=100; //100->1 200->2 int saved_feedmultiply; volatile bool feedmultiplychanged=false; -float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0}; +float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0 }; float add_homeing[3]={0,0,0}; +uint8_t active_extruder = 0; - + bool stop_heating_wait=false; + //=========================================================================== //=============================private variables============================= //=========================================================================== @@@ -540,16 -542,24 +543,25 @@@ FORCE_INLINE void process_commands( #ifdef QUICK_HOME if( code_seen(axis_codes[0]) && code_seen(axis_codes[1]) ) //first diagonal move { - current_position[X_AXIS] = 0; current_position[Y_AXIS] = 0; + current_position[X_AXIS] = 0;current_position[Y_AXIS] = 0; + plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); - destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR; - destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR; - feedrate =homing_feedrate[X_AXIS]; + destination[X_AXIS] = 1.5 * X_MAX_LENGTH * X_HOME_DIR;destination[Y_AXIS] = 1.5 * Y_MAX_LENGTH * Y_HOME_DIR; + feedrate = homing_feedrate[X_AXIS]; if(homing_feedrate[Y_AXIS] 1000 ) - { //Print Temp Reading every 1 second while heating up/cooling down - SERIAL_PROTOCOLPGM("T:"); - SERIAL_PROTOCOLLN( degHotend(tmp_extruder) ); - codenum = millis(); - } - manage_heater(); - LCD_STATUS; + if( (millis() - codenum) > 1000 ) + { //Print Temp Reading and remaining time every 1 second while heating up/cooling down + SERIAL_PROTOCOLPGM("T:"); + SERIAL_PROTOCOL( degHotend(tmp_extruder) ); + SERIAL_PROTOCOLPGM(" E:"); + SERIAL_PROTOCOLLN( (int)tmp_extruder ); + #ifdef TEMP_RESIDENCY_TIME + SERIAL_PROTOCOLPGM(" W:"); + if(residencyStart > -1) + { + codenum = TEMP_RESIDENCY_TIME - ((millis() - residencyStart) / 1000); + SERIAL_PROTOCOLLN( codenum ); + } + else + { + SERIAL_PROTOCOLLN( "?" ); + } + #endif + codenum = millis(); + } + manage_heater(); + LCD_STATUS; + if(stop_heating_wait) break; #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 */ @@@ -830,10 -839,11 +853,11 @@@ } LCD_MESSAGEPGM("Heating done."); starttime=millis(); + previous_millis_cmd = millis(); } break; - case 190: // M190 - Wait bed for heater to reach target. - #if TEMP_1_PIN > -1 + case 190: // M190 - Wait for bed heater to reach target. + #if TEMP_BED_PIN > -1 LCD_MESSAGEPGM("Bed Heating."); if (code_seen('S')) setTargetBed(code_value()); codenum = millis(); @@@ -896,20 -907,22 +921,25 @@@ } else { - #if ((E_ENABLE_PIN != X_ENABLE_PIN) && (E_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS - if(code_seen('E')) { - st_synchronize(); - LCD_MESSAGEPGM("Free Move"); + bool all_axis = !((code_seen(axis_codes[0])) || (code_seen(axis_codes[1])) || (code_seen(axis_codes[2]))|| (code_seen(axis_codes[3]))); + if(all_axis) + { + disable_e0(); + disable_e1(); + disable_e2(); - } - else { finishAndDisableSteppers(); } - #else - finishAndDisableSteppers(); - #endif + else + { + st_synchronize(); + if(code_seen('X')) disable_x(); + if(code_seen('Y')) disable_y(); + if(code_seen('Z')) disable_z(); + #if ((E_ENABLE_PIN != X_ENABLE_PIN) && (E_ENABLE_PIN != Y_ENABLE_PIN)) // Only enable on boards that have seperate ENABLE_PINS + if(code_seen('E')) disable_e(); + #endif + LCD_MESSAGEPGM("Partial Release"); + } } break; case 85: // M85 diff --cc Marlin/planner.cpp index afe2f3e,df25544..1d66dad --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@@ -778,3 -804,9 +796,9 @@@ uint8_t movesplanned( return (block_buffer_head-block_buffer_tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1); } + void allow_cold_extrudes(bool allow) + { + #ifdef PREVENT_DANGEROUS_EXTRUDE + allow_cold_extrude=allow; + #endif -} ++} diff --cc Marlin/stepper.cpp index 586ea7c,51a9fe0..cffa25f --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@@ -800,7 -750,14 +801,16 @@@ void finishAndDisableSteppers( disable_x(); disable_y(); disable_z(); - disable_e(); + disable_e0(); + disable_e1(); + disable_e2(); } + + void quickStop() + { + DISABLE_STEPPER_DRIVER_INTERRUPT(); + while(blocks_queued()) + plan_discard_current_block(); + ENABLE_STEPPER_DRIVER_INTERRUPT(); + } + diff --cc Marlin/temperature.cpp index 761e136,785da6c..ba116c7 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@@ -68,23 -72,23 +68,24 @@@ static unsigned long previous_millis_b #ifdef PIDTEMP //static cannot be external: - static float temp_iState = 0; - static float temp_dState = 0; - static float pTerm; - static float iTerm; - static float dTerm; + static float temp_iState[EXTRUDERS] = { 0 }; + static float temp_dState[EXTRUDERS] = { 0 }; + static float pTerm[EXTRUDERS]; + static float iTerm[EXTRUDERS]; + static float dTerm[EXTRUDERS]; //int output; - static float pid_error; - static float temp_iState_min; - static float temp_iState_max; - // static float pid_input; - // static float pid_output; - static bool pid_reset; - + static float pid_error[EXTRUDERS]; + static float temp_iState_min[EXTRUDERS]; + static float temp_iState_max[EXTRUDERS]; + // static float pid_input[EXTRUDERS]; + // static float pid_output[EXTRUDERS]; + static bool pid_reset[EXTRUDERS]; #endif //PIDTEMP + static unsigned char soft_pwm[EXTRUDERS]; #ifdef WATCHPERIOD + static int watch_raw[EXTRUDERS] = { -1000 }; // the first value used for all + static int watch_oldtemp[3] = {0,0,0}; static unsigned long watchmillis = 0; #endif //WATCHPERIOD @@@ -193,27 -160,46 +194,40 @@@ void manage_heater( } #endif //PID_OPENLOOP #ifdef PID_DEBUG - //SERIAL_ECHOLN(" PIDDEBUG Input "< minttemp_0) && (current_raw[TEMPSENSOR_HOTEND_0] < maxttemp_0)) { - analogWrite(HEATER_0_PIN, pid_output); + #else /* PID off */ + pid_output = 0; + if(current_raw[e] < target_raw[e]) { + pid_output = PID_MAX; } - else { - analogWrite(HEATER_0_PIN, 0); - } - #endif //PIDTEMP + #endif - #ifndef PIDTEMP // Check if temperature is within the correct range - if((current_raw[TEMPSENSOR_HOTEND_0] > minttemp_0) && (current_raw[TEMPSENSOR_HOTEND_0] < maxttemp_0)) { - if(current_raw[TEMPSENSOR_HOTEND_0] >= target_raw[TEMPSENSOR_HOTEND_0]) { - WRITE(HEATER_0_PIN,LOW); - } - else { - WRITE(HEATER_0_PIN,HIGH); - } + if((current_raw[e] > minttemp[e]) && (current_raw[e] < maxttemp[e])) + { + //analogWrite(heater_pin_map[e], pid_output); + soft_pwm[e] = (int)pid_output >> 1; } else { - WRITE(HEATER_0_PIN,LOW); - } - #endif + //analogWrite(heater_pin_map[e], 0); + soft_pwm[e] = 0; + } + } // End extruder for loop - + + #ifdef WATCHPERIOD + if(watchmillis && millis() - watchmillis > WATCHPERIOD){ + if(watch_oldtemp[TEMPSENSOR_HOTEND_0] >= degHotend(active_extruder)){ + setTargetHotend(0,active_extruder); + LCD_MESSAGEPGM("Heating failed"); + SERIAL_ECHO_START; + SERIAL_ECHOLN("Heating failed"); + }else{ + watchmillis = 0; + } + } + #endif + if(millis() - previous_millis_bed_heater < BED_CHECK_INTERVAL) return; previous_millis_bed_heater = millis(); @@@ -489,16 -436,15 +503,17 @@@ void tp_init( void setWatch() { #ifdef WATCHPERIOD - if(isHeatingHotend0()) + int t = 0; + for (int e = 0; e < EXTRUDERS; e++) { - watchmillis = max(1,millis()); + if(isHeatingHotend(e)) + watch_oldtemp[TEMPSENSOR_HOTEND_0] = degHotend(0); + { + t = max(t,millis()); + watch_raw[e] = current_raw[e]; + } } - else - { - watchmillis = 0; - } + watchmillis = t; #endif } diff --cc Marlin/temperature.h index aa0d6c4,2580947..f8b0964 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@@ -1,144 -1,129 +1,145 @@@ - /* - temperature.h - temperature controller - Part of Marlin - - Copyright (c) 2011 Erik van der Zalm - - Grbl 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. - - Grbl 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 Grbl. If not, see . - */ - - #ifndef temperature_h - #define temperature_h - - #include "Marlin.h" - #include "fastio.h" - #ifdef PID_ADD_EXTRUSION_RATE - #include "stepper.h" - #endif - - // public functions - void tp_init(); //initialise the heating - void manage_heater(); //it is critical that this is called periodically. - - //low leven conversion routines - // do not use this routines and variables outsie of temperature.cpp - int temp2analog(int celsius, uint8_t e); - int temp2analogBed(int celsius); - float analog2temp(int raw, uint8_t e); - float analog2tempBed(int raw); - extern int target_raw[EXTRUDERS]; - extern int heatingtarget_raw[EXTRUDERS]; - extern int current_raw[EXTRUDERS]; - extern int target_raw_bed; - extern int current_raw_bed; - extern float Kp,Ki,Kd,Kc; - - #ifdef PIDTEMP - extern float pid_setpoint[EXTRUDERS]; - #endif - - #ifdef WATCHPERIOD - extern int watch_raw[EXTRUDERS] ; - extern unsigned long watchmillis; - #endif - - - //high level conversion routines, for use outside of temperature.cpp - //inline so that there is no performance decrease. - //deg=degreeCelsius - - FORCE_INLINE float degHotend(uint8_t extruder) { - return analog2temp(current_raw[extruder], extruder); - }; - - FORCE_INLINE float degBed() { - return analog2tempBed(current_raw_bed); - }; - - FORCE_INLINE float degTargetHotend(uint8_t extruder) { - return analog2temp(target_raw[extruder], extruder); - }; - - FORCE_INLINE float degTargetBed() { - return analog2tempBed(target_raw_bed); - }; - - FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) { - target_raw[extruder] = temp2analog(celsius, extruder); - #ifdef PIDTEMP - pid_setpoint[extruder] = celsius; - #endif //PIDTEMP - }; - - FORCE_INLINE void setTargetBed(const float &celsius) { - target_raw_bed = temp2analogBed(celsius); - }; - - FORCE_INLINE bool isHeatingHotend(uint8_t extruder){ - return target_raw[extruder] > current_raw[extruder]; - }; - - FORCE_INLINE bool isHeatingBed() { - return target_raw_bed > current_raw_bed; - }; - - FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { - return target_raw[extruder] < current_raw[extruder]; - }; - - FORCE_INLINE bool isCoolingBed() { - return target_raw_bed < current_raw_bed; - }; - - #define degHotend0() degHotend(0) - #define degTargetHotend0() degTargetHotend(0) - #define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0) - #define isHeatingHotend0() isHeatingHotend(0) - #define isCoolingHotend0() isCoolingHotend(0) - #if EXTRUDERS > 1 - #define degHotend1() degHotend(1) - #define degTargetHotend1() degTargetHotend(1) - #define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1) - #define isHeatingHotend1() isHeatingHotend(1) - #define isCoolingHotend1() isCoolingHotend(1) - #endif - #if EXTRUDERS > 2 - #define degHotend2() degHotend(2) - #define degTargetHotend2() degTargetHotend(2) - #define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2) - #define isHeatingHotend2() isHeatingHotend(2) - #define isCoolingHotend2() isCoolingHotend(2) - #endif - #if EXTRUDERS > 3 - #error Invalid number of extruders - #endif - - FORCE_INLINE void autotempShutdown(){ - #ifdef AUTOTEMP - if(autotemp_enabled) - { - autotemp_enabled=false; - if(degTargetHotend(ACTIVE_EXTRUDER)>autotemp_min) - setTargetHotend(0,ACTIVE_EXTRUDER); - } - #endif - } - - int getHeaterPower(int heater); - void disable_heater(); - void setWatch(); - void updatePID(); - - #endif + /* + temperature.h - temperature controller + Part of Marlin + + Copyright (c) 2011 Erik van der Zalm + + Grbl 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. + + Grbl 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 Grbl. If not, see . + */ + + #ifndef temperature_h + #define temperature_h + + #include "Marlin.h" + #include "fastio.h" + #include "planner.h" + #ifdef PID_ADD_EXTRUSION_RATE + #include "stepper.h" + #endif + + // public functions + void tp_init(); //initialise the heating + void manage_heater(); //it is critical that this is called periodically. + - -enum TempSensor {TEMPSENSOR_HOTEND_0=0,TEMPSENSOR_BED=1, TEMPSENSOR_HOTEND_1=2}; - + //low leven conversion routines + // do not use this routines and variables outsie of temperature.cpp -int temp2analog(int celsius); ++int temp2analog(int celsius, uint8_t e); + int temp2analogBed(int celsius); -float analog2temp(int raw); ++float analog2temp(int raw, uint8_t e); + float analog2tempBed(int raw); -extern int target_raw[3]; -extern int heatingtarget_raw[3]; -extern int current_raw[3]; ++extern int target_raw[EXTRUDERS]; ++extern int heatingtarget_raw[EXTRUDERS]; ++extern int current_raw[EXTRUDERS]; ++extern int target_raw_bed; ++extern int current_raw_bed; + extern float Kp,Ki,Kd,Kc; + + #ifdef PIDTEMP - extern float pid_setpoint ; ++ extern float pid_setpoint[EXTRUDERS]; + #endif + + // #ifdef WATCHPERIOD -// extern int watch_raw[3] ; ++ extern int watch_raw[EXTRUDERS] ; + // extern unsigned long watchmillis; + // #endif + + - + //high level conversion routines, for use outside of temperature.cpp + //inline so that there is no performance decrease. + //deg=degreeCelsius + -FORCE_INLINE float degHotend0(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_0]);}; -FORCE_INLINE float degHotend1(){ return analog2temp(current_raw[TEMPSENSOR_HOTEND_1]);}; -FORCE_INLINE float degBed() { return analog2tempBed(current_raw[TEMPSENSOR_BED]);}; -FORCE_INLINE float degHotend(uint8_t extruder){ - if(extruder == 0) return analog2temp(current_raw[TEMPSENSOR_HOTEND_0]); - if(extruder == 1) return analog2temp(current_raw[TEMPSENSOR_HOTEND_1]); ++FORCE_INLINE float degHotend(uint8_t extruder) { ++ return analog2temp(current_raw[extruder], extruder); + }; + -FORCE_INLINE float degTargetHotend0() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_0]);}; -FORCE_INLINE float degTargetHotend1() { return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]);}; -FORCE_INLINE float degTargetHotend(uint8_t extruder){ - if(extruder == 0) return analog2temp(target_raw[TEMPSENSOR_HOTEND_0]); - if(extruder == 1) return analog2temp(target_raw[TEMPSENSOR_HOTEND_1]); ++FORCE_INLINE float degBed() { ++ return analog2tempBed(current_raw_bed); + }; + -FORCE_INLINE float degTargetBed() { return analog2tempBed(target_raw[TEMPSENSOR_BED]);}; ++FORCE_INLINE float degTargetHotend(uint8_t extruder) { ++ return analog2temp(target_raw[extruder], extruder); ++}; + -FORCE_INLINE void setTargetHotend0(const float &celsius) -{ - target_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius); - heatingtarget_raw[TEMPSENSOR_HOTEND_0]=temp2analog(celsius-HEATING_EARLY_FINISH_DEG_OFFSET); - #ifdef PIDTEMP - pid_setpoint = celsius; - #endif //PIDTEMP ++FORCE_INLINE float degTargetBed() { ++ return analog2tempBed(target_raw_bed); + }; -FORCE_INLINE void setTargetHotend1(const float &celsius) { target_raw[TEMPSENSOR_HOTEND_1]=temp2analog(celsius);}; -FORCE_INLINE void setTargetHotend(const float &celcius, uint8_t extruder){ - if(extruder == 0) setTargetHotend0(celcius); - if(extruder == 1) setTargetHotend1(celcius); ++ ++FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) { ++ target_raw[extruder] = temp2analog(celsius, extruder); ++#ifdef PIDTEMP ++ pid_setpoint[extruder] = celsius; ++#endif //PIDTEMP ++}; ++ ++FORCE_INLINE void setTargetBed(const float &celsius) { ++ target_raw_bed = temp2analogBed(celsius); + }; -FORCE_INLINE void setTargetBed(const float &celsius) { target_raw[TEMPSENSOR_BED ]=temp2analogBed(celsius);}; + -FORCE_INLINE bool isHeatingHotend0() {return heatingtarget_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0];}; -FORCE_INLINE bool isHeatingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1];}; + FORCE_INLINE bool isHeatingHotend(uint8_t extruder){ - if(extruder == 0) return heatingtarget_raw[TEMPSENSOR_HOTEND_0] > current_raw[TEMPSENSOR_HOTEND_0]; - if(extruder == 1) return target_raw[TEMPSENSOR_HOTEND_1] > current_raw[TEMPSENSOR_HOTEND_1]; - return false; ++ return target_raw[extruder] > current_raw[extruder]; ++}; ++ ++FORCE_INLINE bool isHeatingBed() { ++ return target_raw_bed > current_raw_bed; + }; -FORCE_INLINE bool isHeatingBed() {return target_raw[TEMPSENSOR_BED] > current_raw[TEMPSENSOR_BED];}; - -FORCE_INLINE bool isCoolingHotend0() {return target_raw[TEMPSENSOR_HOTEND_0] < current_raw[TEMPSENSOR_HOTEND_0];}; -FORCE_INLINE bool isCoolingHotend1() {return target_raw[TEMPSENSOR_HOTEND_1] < current_raw[TEMPSENSOR_HOTEND_1];}; -FORCE_INLINE bool isCoolingHotend(uint8_t extruder){ - if(extruder == 0) return target_raw[TEMPSENSOR_HOTEND_0] < current_raw[TEMPSENSOR_HOTEND_0]; - if(extruder == 1) return target_raw[TEMPSENSOR_HOTEND_1] < current_raw[TEMPSENSOR_HOTEND_1]; - return false; ++ ++FORCE_INLINE bool isCoolingHotend(uint8_t extruder) { ++ return target_raw[extruder] < current_raw[extruder]; + }; -FORCE_INLINE bool isCoolingBed() {return target_raw[TEMPSENSOR_BED] < current_raw[TEMPSENSOR_BED];}; ++ ++FORCE_INLINE bool isCoolingBed() { ++ return target_raw_bed < current_raw_bed; ++}; ++ ++#define degHotend0() degHotend(0) ++#define degTargetHotend0() degTargetHotend(0) ++#define setTargetHotend0(_celsius) setTargetHotend((_celsius), 0) ++#define isHeatingHotend0() isHeatingHotend(0) ++#define isCoolingHotend0() isCoolingHotend(0) ++#if EXTRUDERS > 1 ++#define degHotend1() degHotend(1) ++#define degTargetHotend1() degTargetHotend(1) ++#define setTargetHotend1(_celsius) setTargetHotend((_celsius), 1) ++#define isHeatingHotend1() isHeatingHotend(1) ++#define isCoolingHotend1() isCoolingHotend(1) ++#endif ++#if EXTRUDERS > 2 ++#define degHotend2() degHotend(2) ++#define degTargetHotend2() degTargetHotend(2) ++#define setTargetHotend2(_celsius) setTargetHotend((_celsius), 2) ++#define isHeatingHotend2() isHeatingHotend(2) ++#define isCoolingHotend2() isCoolingHotend(2) ++#endif ++#if EXTRUDERS > 3 ++#error Invalid number of extruders ++#endif + + FORCE_INLINE void autotempShutdown(){ + #ifdef AUTOTEMP + if(autotemp_enabled) + { + autotemp_enabled=false; - if(degTargetHotend0()>autotemp_min) - setTargetHotend0(0); ++ if(degTargetHotend(ACTIVE_EXTRUDER)>autotemp_min) ++ setTargetHotend(0,ACTIVE_EXTRUDER); + } + #endif + } ++ ++int getHeaterPower(int heater); + void disable_heater(); + void setWatch(); + void updatePID(); + + #endif diff --cc Marlin/ultralcd.pde index d577275,e89474e..3b7663b --- a/Marlin/ultralcd.pde +++ b/Marlin/ultralcd.pde @@@ -1,1843 -1,1844 +1,1848 @@@ -#include "ultralcd.h" -#ifdef ULTRA_LCD - -//=========================================================================== -//=============================imported variables============================ -//=========================================================================== - -extern volatile int feedmultiply; -extern volatile bool feedmultiplychanged; - -extern long position[4]; -extern CardReader card; - -//=========================================================================== -//=============================public variables============================ -//=========================================================================== -volatile char buttons=0; //the last checked buttons in a bit array. -int encoderpos=0; -short lastenc=0; - - -//=========================================================================== -//=============================private variables============================ -//=========================================================================== -static char messagetext[LCD_WIDTH]=""; - -//return for string conversion routines -static char conv[8]; - -#include -LiquidCrystal lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7 - -static unsigned long previous_millis_lcd=0; -static long previous_millis_buttons=0; - - -#ifdef NEWPANEL - static long blocking=0; -#else - static long blocking[8]={0,0,0,0,0,0,0,0}; -#endif - -static MainMenu menu; - -#include - -void lcdProgMemprint(const char *str) -{ - char ch=pgm_read_byte(str); - while(ch) - { - lcd.print(ch); - ch=pgm_read_byte(++str); - } -} -#define lcdprintPGM(x) lcdProgMemprint(MYPGM(x)) - - -//=========================================================================== -//=============================functions ============================ -//=========================================================================== - -FORCE_INLINE int intround(const float &x){return int(0.5+x);} - -void lcd_status(const char* message) -{ - strncpy(messagetext,message,LCD_WIDTH); - messagetext[strlen(message)]=0; -} - -void lcd_statuspgm(const char* message) -{ - char ch=pgm_read_byte(message); - char *target=messagetext; - uint8_t cnt=0; - while(ch &&cnt>1; - if(READ(SHIFT_OUT)) - newbutton|=(1<<7); - WRITE(SHIFT_CLK,HIGH); - WRITE(SHIFT_CLK,LOW); - } - buttons=~newbutton; //invert it, because a pressed switch produces a logical 0 - #endif - - //manage encoder rotation - char enc=0; - if(buttons&EN_A) - enc|=(1<<0); - if(buttons&EN_B) - enc|=(1<<1); - if(enc!=lastenc) - { - switch(enc) - { - case encrot0: - if(lastenc==encrot3) - encoderpos++; - else if(lastenc==encrot1) - encoderpos--; - break; - case encrot1: - if(lastenc==encrot0) - encoderpos++; - else if(lastenc==encrot2) - encoderpos--; - break; - case encrot2: - if(lastenc==encrot1) - encoderpos++; - else if(lastenc==encrot3) - encoderpos--; - break; - case encrot3: - if(lastenc==encrot2) - encoderpos++; - else if(lastenc==encrot0) - encoderpos--; - break; - default: - ; - } - } - lastenc=enc; -} - -#endif - -MainMenu::MainMenu() -{ - status=Main_Status; - displayStartingRow=0; - activeline=0; - force_lcd_update=true; - #ifdef ULTIPANEL - buttons_init(); - #endif - lcd_init(); - linechanging=false; - tune=false; -} - -void MainMenu::showStatus() -{ -#if LCD_HEIGHT==4 - static int olddegHotEnd0=-1; - static int oldtargetHotEnd0=-1; - //force_lcd_update=true; - if(force_lcd_update||feedmultiplychanged) //initial display of content - { - feedmultiplychanged=false; - encoderpos=feedmultiply; - clear(); - lcd.setCursor(0,0);lcdprintPGM("\002123/567\001 "); - #if defined BED_USES_THERMISTOR || defined BED_USES_AD595 - lcd.setCursor(10,0);lcdprintPGM("B123/567\001 "); - #endif - } - - int tHotEnd0=intround(degHotend0()); - if((abs(tHotEnd0-olddegHotEnd0)>1)||force_lcd_update) //>1 because otherwise the lcd is refreshed to often. - { - lcd.setCursor(1,0); - lcd.print(ftostr3(tHotEnd0)); - olddegHotEnd0=tHotEnd0; - } - int ttHotEnd0=intround(degTargetHotend0()); - if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update) - { - lcd.setCursor(5,0); - lcd.print(ftostr3(ttHotEnd0)); - oldtargetHotEnd0=ttHotEnd0; - } - #if defined BED_USES_THERMISTOR || defined BED_USES_AD595 - static int oldtBed=-1; - static int oldtargetBed=-1; - int tBed=intround(degBed()); - if((tBed!=oldtBed)||force_lcd_update) - { - lcd.setCursor(1,0); - lcd.print(ftostr3(tBed)); - oldtBed=tBed; - } - int targetBed=intround(degTargetBed()); - if((targetBed!=oldtargetBed)||force_lcd_update) - { - lcd.setCursor(5,0); - lcd.print(ftostr3(targetBed)); - oldtargetBed=targetBed; - } - #endif - //starttime=2; - static uint16_t oldtime=0; - if(starttime!=0) - { - lcd.setCursor(0,1); - uint16_t time=millis()/60000-starttime/60000; - - if(starttime!=oldtime) - { - lcd.print(itostr2(time/60));lcdprintPGM("h ");lcd.print(itostr2(time%60));lcdprintPGM("m"); - oldtime=time; - } - } - static int oldzpos=0; - int currentz=current_position[2]*10; - if((currentz!=oldzpos)||force_lcd_update) - { - lcd.setCursor(10,1); - lcdprintPGM("Z:");lcd.print(itostr31(currentz)); - oldzpos=currentz; - } - static int oldfeedmultiply=0; - int curfeedmultiply=feedmultiply; - if(encoderpos!=curfeedmultiply||force_lcd_update) - { - curfeedmultiply=encoderpos; - if(curfeedmultiply<10) - curfeedmultiply=10; - if(curfeedmultiply>999) - curfeedmultiply=999; - feedmultiply=curfeedmultiply; - encoderpos=curfeedmultiply; - } - if((curfeedmultiply!=oldfeedmultiply)||force_lcd_update) - { - oldfeedmultiply=curfeedmultiply; - lcd.setCursor(0,2); - lcd.print(itostr3(curfeedmultiply));lcdprintPGM("% "); - } - if(messagetext[0]!='\0') - { - lcd.setCursor(0,LCD_HEIGHT-1); - lcd.print(messagetext); - uint8_t n=strlen(messagetext); - for(int8_t i=0;i1)||force_lcd_update) - { - lcd.setCursor(1,0); - lcd.print(ftostr3(tHotEnd0)); - olddegHotEnd0=tHotEnd0; - } - if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update) - { - lcd.setCursor(5,0); - lcd.print(ftostr3(ttHotEnd0)); - oldtargetHotEnd0=ttHotEnd0; - } - - if(messagetext[0]!='\0') - { - lcd.setCursor(0,LCD_HEIGHT-1); - lcd.print(messagetext); - uint8_t n=strlen(messagetext); - for(int8_t i=0;i400) encoderpos=400; - feedmultiply = encoderpos; - feedmultiplychanged=true; - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); - } - - }break; - case ItemT_nozzle: - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" \002Nozzle:"); - lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0()))); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=intround(degTargetHotend0()); - } - else - { - setTargetHotend0(encoderpos); - encoderpos=activeline*lcdslow; - beepshort(); - } - BLOCK; - } - if(linechanging) - { - if(encoderpos<0) encoderpos=0; - if(encoderpos>260) encoderpos=260; - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); - } - }break; - - case ItemT_fan: - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" Fan speed:"); - lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm)); - } - - if((activeline!=line) ) - break; - - if(CLICKED) //nalogWrite(FAN_PIN, fanpwm); - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=fanpwm; - } - else - { - encoderpos=activeline*lcdslow; - beepshort(); - } - BLOCK; - } - if(linechanging) - { - if(encoderpos<0) encoderpos=0; - if(encoderpos>255) encoderpos=255; - fanpwm=encoderpos; - analogWrite(FAN_PIN, fanpwm); - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); - } - - }break; - case ItemT_flow://axis_steps_per_unit[i] = code_value(); - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" Flow:"); - lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3])); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=(int)axis_steps_per_unit[3]; - } - else - { - float factor=float(encoderpos)/float(axis_steps_per_unit[3]); - position[E_AXIS]=lround(position[E_AXIS]*factor); - //current_position[3]*=factor; - axis_steps_per_unit[E_AXIS]= encoderpos; - encoderpos=activeline*lcdslow; - - } - BLOCK; - beepshort(); - } - if(linechanging) - { - if(encoderpos<5) encoderpos=5; - if(encoderpos>9999) encoderpos=9999; - lcd.setCursor(13,line);lcd.print(itostr4(encoderpos)); - } - - }break; - default: - break; - } - line++; - } - updateActiveLines(ItemT_fan,encoderpos); -} - -//does not work -// #define MENUCHANGEITEM(repaint_action, enter_action, accept_action, change_action) \ -// {\ -// if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \ -// if(activeline==line) \ -// { \ -// if(CLICKED) \ -// { \ -// linechanging=!linechanging; \ -// if(linechanging) {enter_action;} \ -// else {accept_action;} \ -// } \ -// else \ -// if(linechanging) {change_action};}\ -// } -// - -enum { - ItemCT_exit,ItemCT_nozzle, -#ifdef AUTOTEMP - ItemCT_autotempactive, - ItemCT_autotempmin,ItemCT_autotempmax,ItemCT_autotempfact, -#endif - ItemCT_fan, - ItemCT_PID_P,ItemCT_PID_I,ItemCT_PID_D,ItemCT_PID_C -}; - -void MainMenu::showControlTemp() -{ - uint8_t line=0; - clearIfNecessary(); - for(int8_t i=lineoffset;i260) encoderpos=260; - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); - } - - }break; - #ifdef AUTOTEMP - case ItemCT_autotempmin: - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" \002 Min:"); - lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_min)); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=intround(autotemp_min); - } - else - { - autotemp_min=encoderpos; - encoderpos=activeline*lcdslow; - beepshort(); - } - BLOCK; - } - if(linechanging) - { - if(encoderpos<0) encoderpos=0; - if(encoderpos>260) encoderpos=260; - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); - } - - }break; - case ItemCT_autotempmax: - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" \002 Max:"); - lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_max)); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=intround(autotemp_max); - } - else - { - autotemp_max=encoderpos; - encoderpos=activeline*lcdslow; - beepshort(); - } - BLOCK; - } - if(linechanging) - { - if(encoderpos<0) encoderpos=0; - if(encoderpos>260) encoderpos=260; - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); - } - - }break; - case ItemCT_autotempfact: - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" \002 Fact:"); - lcd.setCursor(13,line);lcd.print(ftostr32(autotemp_factor)); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=intround(autotemp_factor*100); - } - else - { - autotemp_max=encoderpos; - encoderpos=activeline*lcdslow; - beepshort(); - } - BLOCK; - } - if(linechanging) - { - if(encoderpos<0) encoderpos=0; - if(encoderpos>99) encoderpos=99; - lcd.setCursor(13,line);lcd.print(ftostr32(encoderpos/100.)); - } - - }break; - case ItemCT_autotempactive: - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" Autotemp:"); - lcd.setCursor(13,line); - if(autotemp_enabled) - lcdprintPGM("On"); - else - lcdprintPGM("Off"); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - autotemp_enabled=!autotemp_enabled; - lcd.setCursor(13,line); - if(autotemp_enabled) - lcdprintPGM("On "); - else - lcdprintPGM("Off"); - BLOCK; - } - - }break; - #endif //autotemp - case ItemCT_fan: - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" Fan speed:"); - lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm)); - } - - if((activeline!=line) ) - break; - - if(CLICKED) //nalogWrite(FAN_PIN, fanpwm); - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=fanpwm; - } - else - { - encoderpos=activeline*lcdslow; - beepshort(); - } - BLOCK; - } - if(linechanging) - { - if(encoderpos<0) encoderpos=0; - if(encoderpos>255) encoderpos=255; - fanpwm=encoderpos; - analogWrite(FAN_PIN, fanpwm); - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); - } - - }break; - case ItemCT_PID_P: - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" PID-P: "); - lcd.setCursor(13,line);lcd.print(itostr4(Kp)); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=(int)Kp; - } - else - { - Kp= encoderpos; - encoderpos=activeline*lcdslow; - - } - BLOCK; - beepshort(); - } - if(linechanging) - { - if(encoderpos<1) encoderpos=1; - if(encoderpos>9990) encoderpos=9990; - lcd.setCursor(13,line);lcd.print(itostr4(encoderpos)); - } - - }break; - case ItemCT_PID_I: - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" PID-I: "); - lcd.setCursor(13,line);lcd.print(ftostr51(Ki/PID_dT)); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=(int)(Ki*10/PID_dT); - } - else - { - Ki= encoderpos/10.*PID_dT; - encoderpos=activeline*lcdslow; - - } - BLOCK; - beepshort(); - } - if(linechanging) - { - if(encoderpos<0) encoderpos=0; - if(encoderpos>9990) encoderpos=9990; - lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.)); - } - - }break; - case ItemCT_PID_D: - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" PID-D: "); - lcd.setCursor(13,line);lcd.print(itostr4(Kd*PID_dT)); - } - - if((activeline!=line) ) - break; - - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=(int)(Kd/5./PID_dT); - } - else - { - Kd= encoderpos; - encoderpos=activeline*lcdslow; - - } - BLOCK; - beepshort(); - } - if(linechanging) - { - if(encoderpos<0) encoderpos=0; - if(encoderpos>9990) encoderpos=9990; - lcd.setCursor(13,line);lcd.print(itostr4(encoderpos)); - } - - }break; - case ItemCT_PID_C: - #ifdef PID_ADD_EXTRUSION_RATE - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" PID-C: "); - lcd.setCursor(13,line);lcd.print(itostr3(Kc)); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=(int)Kc; - } - else - { - Kc= encoderpos; - encoderpos=activeline*lcdslow; - - } - BLOCK; - beepshort(); - } - if(linechanging) - { - if(encoderpos<0) encoderpos=0; - if(encoderpos>990) encoderpos=990; - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); - } - - } - #endif - break; - default: - break; - } - line++; - } - #ifdef PID_ADD_EXTRUSION_RATE - updateActiveLines(ItemCT_PID_C,encoderpos); - #else - updateActiveLines(ItemCT_PID_D,encoderpos); - #endif -} - - -enum { - ItemCM_exit, - ItemCM_acc, ItemCM_xyjerk, - ItemCM_vmaxx, ItemCM_vmaxy, ItemCM_vmaxz, ItemCM_vmaxe, - ItemCM_vtravmin,ItemCM_vmin, - ItemCM_amaxx, ItemCM_amaxy, ItemCM_amaxz, ItemCM_amaxe, - ItemCM_aret,ItemCM_esteps -}; - - - -void MainMenu::showControlMotion() -{ - uint8_t line=0; - clearIfNecessary(); - for(int8_t i=lineoffset;i990) encoderpos=990; - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00"); - } - - }break; - case ItemCM_xyjerk: //max_xy_jerk - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" Vxy-jerk: "); - lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk)); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=(int)max_xy_jerk; - } - else - { - max_xy_jerk= encoderpos; - encoderpos=activeline*lcdslow; - - } - BLOCK; - beepshort(); - } - if(linechanging) - { - if(encoderpos<1) encoderpos=1; - if(encoderpos>990) encoderpos=990; - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); - } - - }break; - - case ItemCM_vmaxx: - case ItemCM_vmaxy: - case ItemCM_vmaxz: - case ItemCM_vmaxe: - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" Vmax "); - if(i==ItemCM_vmaxx)lcdprintPGM("x:"); - if(i==ItemCM_vmaxy)lcdprintPGM("y:"); - if(i==ItemCM_vmaxz)lcdprintPGM("z:"); - if(i==ItemCM_vmaxe)lcdprintPGM("e:"); - lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemCM_vmaxx])); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=(int)max_feedrate[i-ItemCM_vmaxx]; - } - else - { - max_feedrate[i-ItemCM_vmaxx]= encoderpos; - encoderpos=activeline*lcdslow; - - } - BLOCK; - beepshort(); - } - if(linechanging) - { - if(encoderpos<1) encoderpos=1; - if(encoderpos>990) encoderpos=990; - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); - } - - }break; - - case ItemCM_vmin: - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" Vmin:"); - lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate)); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=(int)(minimumfeedrate); - } - else - { - minimumfeedrate= encoderpos; - encoderpos=activeline*lcdslow; - - } - BLOCK; - beepshort(); - } - if(linechanging) - { - if(encoderpos<0) encoderpos=0; - if(encoderpos>990) encoderpos=990; - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); - } - - }break; - case ItemCM_vtravmin: - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" VTrav min:"); - lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate)); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=(int)mintravelfeedrate; - } - else - { - mintravelfeedrate= encoderpos; - encoderpos=activeline*lcdslow; - - } - BLOCK; - beepshort(); - } - if(linechanging) - { - if(encoderpos<0) encoderpos=0; - if(encoderpos>990) encoderpos=990; - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); - } - - }break; - - case ItemCM_amaxx: - case ItemCM_amaxy: - case ItemCM_amaxz: - case ItemCM_amaxe: - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" Amax "); - if(i==ItemCM_amaxx)lcdprintPGM("x:"); - if(i==ItemCM_amaxy)lcdprintPGM("y:"); - if(i==ItemCM_amaxz)lcdprintPGM("z:"); - if(i==ItemCM_amaxe)lcdprintPGM("e:"); - lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100));lcdprintPGM("00"); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=(int)max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100; - } - else - { - max_acceleration_units_per_sq_second[i-ItemCM_amaxx]= encoderpos*100; - encoderpos=activeline*lcdslow; - } - BLOCK; - beepshort(); - } - if(linechanging) - { - if(encoderpos<1) encoderpos=1; - if(encoderpos>990) encoderpos=990; - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00"); - } - - }break; - case ItemCM_aret://float retract_acceleration = 7000; - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" A-retract:"); - lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcdprintPGM("00"); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=(int)retract_acceleration/100; - } - else - { - retract_acceleration= encoderpos*100; - encoderpos=activeline*lcdslow; - - } - BLOCK; - beepshort(); - } - if(linechanging) - { - if(encoderpos<10) encoderpos=10; - if(encoderpos>990) encoderpos=990; - lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00"); - } - - }break; - case ItemCM_esteps://axis_steps_per_unit[i] = code_value(); - { - if(force_lcd_update) - { - lcd.setCursor(0,line);lcdprintPGM(" Esteps/mm:"); - lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3])); - } - - if((activeline!=line) ) - break; - - if(CLICKED) - { - linechanging=!linechanging; - if(linechanging) - { - encoderpos=(int)axis_steps_per_unit[3]; - } - else - { - float factor=float(encoderpos)/float(axis_steps_per_unit[3]); - position[E_AXIS]=lround(position[E_AXIS]*factor); - //current_position[3]*=factor; - axis_steps_per_unit[E_AXIS]= encoderpos; - encoderpos=activeline*lcdslow; - - } - BLOCK; - beepshort(); - } - if(linechanging) - { - if(encoderpos<5) encoderpos=5; - if(encoderpos>9999) encoderpos=9999; - lcd.setCursor(13,line);lcd.print(itostr4(encoderpos)); - } - - }break; - default: - break; - } - line++; - } - updateActiveLines(ItemCM_esteps,encoderpos); -} - - -enum { - ItemC_exit,ItemC_temp,ItemC_move, - ItemC_store, ItemC_load,ItemC_failsafe -}; - -void MainMenu::showControl() -{ - uint8_t line=0; - clearIfNecessary(); - for(int8_t i=lineoffset;i=0)?'+':'-'; - xx=abs(xx); - conv[1]=(xx/1000)%10+'0'; - conv[2]=(xx/100)%10+'0'; - conv[3]=(xx/10)%10+'0'; - conv[4]='.'; - conv[5]=(xx)%10+'0'; - conv[6]=0; - return conv; -} - -char *ftostr32(const float &x) -{ - int xx=x*100; - conv[0]=(xx>=0)?'+':'-'; - xx=abs(xx); - conv[1]=(xx/100)%10+'0'; - conv[2]='.'; - conv[3]=(xx/10)%10+'0'; - conv[4]=(xx)%10+'0'; - conv[6]=0; - return conv; -} - -char *itostr31(const int &xx) -{ - conv[0]=(xx>=0)?'+':'-'; - conv[1]=(xx/1000)%10+'0'; - conv[2]=(xx/100)%10+'0'; - conv[3]=(xx/10)%10+'0'; - conv[4]='.'; - conv[5]=(xx)%10+'0'; - conv[6]=0; - return conv; -} - -char *itostr3(const int &xx) -{ - conv[0]=(xx/100)%10+'0'; - conv[1]=(xx/10)%10+'0'; - conv[2]=(xx)%10+'0'; - conv[3]=0; - return conv; -} - -char *itostr4(const int &xx) -{ - conv[0]=(xx/1000)%10+'0'; - conv[1]=(xx/100)%10+'0'; - conv[2]=(xx/10)%10+'0'; - conv[3]=(xx)%10+'0'; - conv[4]=0; - return conv; -} - -// convert float to string with +1234.5 format -char *ftostr51(const float &x) -{ - int xx=x*10; - conv[0]=(xx>=0)?'+':'-'; - xx=abs(xx); - conv[1]=(xx/10000)%10+'0'; - conv[2]=(xx/1000)%10+'0'; - conv[3]=(xx/100)%10+'0'; - conv[4]=(xx/10)%10+'0'; - conv[5]='.'; - conv[6]=(xx)%10+'0'; - conv[7]=0; - return conv; -} - - -#endif //ULTRA_LCD - - +#include "ultralcd.h" +#ifdef ULTRA_LCD + +//=========================================================================== +//=============================imported variables============================ +//=========================================================================== + +extern volatile int feedmultiply; +extern volatile bool feedmultiplychanged; + +extern long position[4]; +extern CardReader card; + +//=========================================================================== +//=============================public variables============================ +//=========================================================================== +volatile char buttons=0; //the last checked buttons in a bit array. +int encoderpos=0; +short lastenc=0; + + +//=========================================================================== +//=============================private variables============================ +//=========================================================================== +static char messagetext[LCD_WIDTH]=""; + +//return for string conversion routines +static char conv[8]; + +#include +LiquidCrystal lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7 + +static unsigned long previous_millis_lcd=0; +static long previous_millis_buttons=0; + + +#ifdef NEWPANEL + static long blocking=0; +#else + static long blocking[8]={0,0,0,0,0,0,0,0}; +#endif + +static MainMenu menu; + +#include + +void lcdProgMemprint(const char *str) +{ + char ch=pgm_read_byte(str); + while(ch) + { + lcd.print(ch); + ch=pgm_read_byte(++str); + } +} +#define lcdprintPGM(x) lcdProgMemprint(MYPGM(x)) + + +//=========================================================================== +//=============================functions ============================ +//=========================================================================== + +FORCE_INLINE int intround(const float &x){return int(0.5+x);} + +void lcd_status(const char* message) +{ + strncpy(messagetext,message,LCD_WIDTH); + messagetext[strlen(message)]=0; +} + +void lcd_statuspgm(const char* message) +{ + char ch=pgm_read_byte(message); + char *target=messagetext; + uint8_t cnt=0; + while(ch &&cntms)) + buttons &= ~(1<>1; + if(READ(SHIFT_OUT)) + newbutton|=(1<<7); + WRITE(SHIFT_CLK,HIGH); + WRITE(SHIFT_CLK,LOW); + } + buttons=~newbutton; //invert it, because a pressed switch produces a logical 0 + #endif + + //manage encoder rotation + char enc=0; + if(buttons&EN_A) + enc|=(1<<0); + if(buttons&EN_B) + enc|=(1<<1); + if(enc!=lastenc) + { + switch(enc) + { + case encrot0: + if(lastenc==encrot3) + encoderpos++; + else if(lastenc==encrot1) + encoderpos--; + break; + case encrot1: + if(lastenc==encrot0) + encoderpos++; + else if(lastenc==encrot2) + encoderpos--; + break; + case encrot2: + if(lastenc==encrot1) + encoderpos++; + else if(lastenc==encrot3) + encoderpos--; + break; + case encrot3: + if(lastenc==encrot2) + encoderpos++; + else if(lastenc==encrot0) + encoderpos--; + break; + default: + ; + } + } + lastenc=enc; +} + +#endif + +MainMenu::MainMenu() +{ + status=Main_Status; + displayStartingRow=0; + activeline=0; + force_lcd_update=true; + #ifdef ULTIPANEL + buttons_init(); + #endif + lcd_init(); + linechanging=false; + tune=false; +} + +void MainMenu::showStatus() +{ +#if LCD_HEIGHT==4 + static int olddegHotEnd0=-1; + static int oldtargetHotEnd0=-1; + //force_lcd_update=true; + if(force_lcd_update||feedmultiplychanged) //initial display of content + { + feedmultiplychanged=false; + encoderpos=feedmultiply; + clear(); + lcd.setCursor(0,0);lcdprintPGM("\002123/567\001 "); + #if defined BED_USES_THERMISTOR || defined BED_USES_AD595 + lcd.setCursor(10,0);lcdprintPGM("B123/567\001 "); + #endif + } + + int tHotEnd0=intround(degHotend0()); + if((abs(tHotEnd0-olddegHotEnd0)>1)||force_lcd_update) //>1 because otherwise the lcd is refreshed to often. + { + lcd.setCursor(1,0); + lcd.print(ftostr3(tHotEnd0)); + olddegHotEnd0=tHotEnd0; + } + int ttHotEnd0=intround(degTargetHotend0()); + if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update) + { + lcd.setCursor(5,0); + lcd.print(ftostr3(ttHotEnd0)); + oldtargetHotEnd0=ttHotEnd0; + } + #if defined BED_USES_THERMISTOR || defined BED_USES_AD595 + static int oldtBed=-1; + static int oldtargetBed=-1; + int tBed=intround(degBed()); + if((tBed!=oldtBed)||force_lcd_update) + { + lcd.setCursor(1,0); + lcd.print(ftostr3(tBed)); + oldtBed=tBed; + } + int targetBed=intround(degTargetBed()); + if((targetBed!=oldtargetBed)||force_lcd_update) + { + lcd.setCursor(5,0); + lcd.print(ftostr3(targetBed)); + oldtargetBed=targetBed; + } + #endif + //starttime=2; + static uint16_t oldtime=0; + if(starttime!=0) + { + lcd.setCursor(0,1); + uint16_t time=millis()/60000-starttime/60000; + + if(starttime!=oldtime) + { + lcd.print(itostr2(time/60));lcdprintPGM("h ");lcd.print(itostr2(time%60));lcdprintPGM("m"); + oldtime=time; + } + } + static int oldzpos=0; + int currentz=current_position[2]*10; + if((currentz!=oldzpos)||force_lcd_update) + { + lcd.setCursor(10,1); + lcdprintPGM("Z:");lcd.print(itostr31(currentz)); + oldzpos=currentz; + } + static int oldfeedmultiply=0; + int curfeedmultiply=feedmultiply; + if(encoderpos!=curfeedmultiply||force_lcd_update) + { + curfeedmultiply=encoderpos; + if(curfeedmultiply<10) + curfeedmultiply=10; + if(curfeedmultiply>999) + curfeedmultiply=999; + feedmultiply=curfeedmultiply; + encoderpos=curfeedmultiply; + } + if((curfeedmultiply!=oldfeedmultiply)||force_lcd_update) + { + oldfeedmultiply=curfeedmultiply; + lcd.setCursor(0,2); + lcd.print(itostr3(curfeedmultiply));lcdprintPGM("% "); + } + if(messagetext[0]!='\0') + { + lcd.setCursor(0,LCD_HEIGHT-1); + lcd.print(messagetext); + uint8_t n=strlen(messagetext); + for(int8_t i=0;i1)||force_lcd_update) + { + lcd.setCursor(1,0); + lcd.print(ftostr3(tHotEnd0)); + olddegHotEnd0=tHotEnd0; + } + if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update) + { + lcd.setCursor(5,0); + lcd.print(ftostr3(ttHotEnd0)); + oldtargetHotEnd0=ttHotEnd0; + } + + if(messagetext[0]!='\0') + { + lcd.setCursor(0,LCD_HEIGHT-1); + lcd.print(messagetext); + uint8_t n=strlen(messagetext); + for(int8_t i=0;i400) encoderpos=400; + feedmultiply = encoderpos; + feedmultiplychanged=true; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); + } + + }break; + case ItemT_nozzle: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" \002Nozzle:"); + lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0()))); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=intround(degTargetHotend0()); + } + else + { + setTargetHotend0(encoderpos); + encoderpos=activeline*lcdslow; + beepshort(); + } + BLOCK; + } + if(linechanging) + { + if(encoderpos<0) encoderpos=0; + if(encoderpos>260) encoderpos=260; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); + } + }break; + + case ItemT_fan: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" Fan speed:"); + lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm)); + } + + if((activeline!=line) ) + break; + + if(CLICKED) //nalogWrite(FAN_PIN, fanpwm); + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=fanpwm; + } + else + { + encoderpos=activeline*lcdslow; + beepshort(); + } + BLOCK; + } + if(linechanging) + { + if(encoderpos<0) encoderpos=0; + if(encoderpos>255) encoderpos=255; + fanpwm=encoderpos; + analogWrite(FAN_PIN, fanpwm); + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); + } + + }break; + case ItemT_flow://axis_steps_per_unit[i] = code_value(); + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" Flow:"); + lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3])); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=(int)axis_steps_per_unit[3]; + } + else + { + float factor=float(encoderpos)/float(axis_steps_per_unit[3]); + position[E_AXIS]=lround(position[E_AXIS]*factor); + //current_position[3]*=factor; + axis_steps_per_unit[E_AXIS]= encoderpos; + encoderpos=activeline*lcdslow; + + } + BLOCK; + beepshort(); + } + if(linechanging) + { + if(encoderpos<5) encoderpos=5; + if(encoderpos>9999) encoderpos=9999; + lcd.setCursor(13,line);lcd.print(itostr4(encoderpos)); + } + + }break; + default: + break; + } + line++; + } + updateActiveLines(ItemT_fan,encoderpos); +} + +//does not work +// #define MENUCHANGEITEM(repaint_action, enter_action, accept_action, change_action) \ +// {\ +// if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \ +// if(activeline==line) \ +// { \ +// if(CLICKED) \ +// { \ +// linechanging=!linechanging; \ +// if(linechanging) {enter_action;} \ +// else {accept_action;} \ +// } \ +// else \ +// if(linechanging) {change_action};}\ +// } +// + +enum { + ItemCT_exit,ItemCT_nozzle, +#ifdef AUTOTEMP + ItemCT_autotempactive, + ItemCT_autotempmin,ItemCT_autotempmax,ItemCT_autotempfact, +#endif + ItemCT_fan, + ItemCT_PID_P,ItemCT_PID_I,ItemCT_PID_D,ItemCT_PID_C +}; + +void MainMenu::showControlTemp() +{ + uint8_t line=0; + clearIfNecessary(); + for(int8_t i=lineoffset;i260) encoderpos=260; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); + } + + }break; + #ifdef AUTOTEMP + case ItemCT_autotempmin: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" \002 Min:"); + lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_min)); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=intround(autotemp_min); + } + else + { + autotemp_min=encoderpos; + encoderpos=activeline*lcdslow; + beepshort(); + } + BLOCK; + } + if(linechanging) + { + if(encoderpos<0) encoderpos=0; + if(encoderpos>260) encoderpos=260; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); + } + + }break; + case ItemCT_autotempmax: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" \002 Max:"); + lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_max)); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=intround(autotemp_max); + } + else + { + autotemp_max=encoderpos; + encoderpos=activeline*lcdslow; + beepshort(); + } + BLOCK; + } + if(linechanging) + { + if(encoderpos<0) encoderpos=0; + if(encoderpos>260) encoderpos=260; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); + } + + }break; + case ItemCT_autotempfact: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" \002 Fact:"); + lcd.setCursor(13,line);lcd.print(ftostr32(autotemp_factor)); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=intround(autotemp_factor*100); + } + else + { + autotemp_max=encoderpos; + encoderpos=activeline*lcdslow; + beepshort(); + } + BLOCK; + } + if(linechanging) + { + if(encoderpos<0) encoderpos=0; + if(encoderpos>99) encoderpos=99; + lcd.setCursor(13,line);lcd.print(ftostr32(encoderpos/100.)); + } + + }break; + case ItemCT_autotempactive: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" Autotemp:"); + lcd.setCursor(13,line); + if(autotemp_enabled) + lcdprintPGM("On"); + else + lcdprintPGM("Off"); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + autotemp_enabled=!autotemp_enabled; + lcd.setCursor(13,line); + if(autotemp_enabled) + lcdprintPGM("On "); + else + lcdprintPGM("Off"); + BLOCK; + } + + }break; + #endif //autotemp + case ItemCT_fan: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" Fan speed:"); + lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm)); + } + + if((activeline!=line) ) + break; + + if(CLICKED) //nalogWrite(FAN_PIN, fanpwm); + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=fanpwm; + } + else + { + encoderpos=activeline*lcdslow; + beepshort(); + } + BLOCK; + } + if(linechanging) + { + if(encoderpos<0) encoderpos=0; + if(encoderpos>255) encoderpos=255; + fanpwm=encoderpos; + analogWrite(FAN_PIN, fanpwm); + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); + } + + }break; + case ItemCT_PID_P: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" PID-P: "); + lcd.setCursor(13,line);lcd.print(itostr4(Kp)); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=(int)Kp; + } + else + { + Kp= encoderpos; + encoderpos=activeline*lcdslow; + + } + BLOCK; + beepshort(); + } + if(linechanging) + { + if(encoderpos<1) encoderpos=1; + if(encoderpos>9990) encoderpos=9990; + lcd.setCursor(13,line);lcd.print(itostr4(encoderpos)); + } + + }break; + case ItemCT_PID_I: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" PID-I: "); + lcd.setCursor(13,line);lcd.print(ftostr51(Ki/PID_dT)); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=(int)(Ki*10/PID_dT); + } + else + { + Ki= encoderpos/10.*PID_dT; + encoderpos=activeline*lcdslow; + + } + BLOCK; + beepshort(); + } + if(linechanging) + { + if(encoderpos<0) encoderpos=0; + if(encoderpos>9990) encoderpos=9990; + lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.)); + } + + }break; + case ItemCT_PID_D: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" PID-D: "); + lcd.setCursor(13,line);lcd.print(itostr4(Kd*PID_dT)); + } + + if((activeline!=line) ) + break; + + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=(int)(Kd/5./PID_dT); + } + else + { + Kd= encoderpos; + encoderpos=activeline*lcdslow; + + } + BLOCK; + beepshort(); + } + if(linechanging) + { + if(encoderpos<0) encoderpos=0; + if(encoderpos>9990) encoderpos=9990; + lcd.setCursor(13,line);lcd.print(itostr4(encoderpos)); + } + + }break; + case ItemCT_PID_C: + #ifdef PID_ADD_EXTRUSION_RATE + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" PID-C: "); + lcd.setCursor(13,line);lcd.print(itostr3(Kc)); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=(int)Kc; + } + else + { + Kc= encoderpos; + encoderpos=activeline*lcdslow; + + } + BLOCK; + beepshort(); + } + if(linechanging) + { + if(encoderpos<0) encoderpos=0; + if(encoderpos>990) encoderpos=990; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); + } + + } + #endif + break; + default: + break; + } + line++; + } + #ifdef PID_ADD_EXTRUSION_RATE + updateActiveLines(ItemCT_PID_C,encoderpos); + #else + updateActiveLines(ItemCT_PID_D,encoderpos); + #endif +} + + +enum { + ItemCM_exit, + ItemCM_acc, ItemCM_xyjerk, + ItemCM_vmaxx, ItemCM_vmaxy, ItemCM_vmaxz, ItemCM_vmaxe, + ItemCM_vtravmin,ItemCM_vmin, + ItemCM_amaxx, ItemCM_amaxy, ItemCM_amaxz, ItemCM_amaxe, + ItemCM_aret,ItemCM_esteps +}; + + + +void MainMenu::showControlMotion() +{ + uint8_t line=0; + clearIfNecessary(); + for(int8_t i=lineoffset;i990) encoderpos=990; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00"); + } + + }break; + case ItemCM_xyjerk: //max_xy_jerk + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" Vxy-jerk: "); + lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk)); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=(int)max_xy_jerk; + } + else + { + max_xy_jerk= encoderpos; + encoderpos=activeline*lcdslow; + + } + BLOCK; + beepshort(); + } + if(linechanging) + { + if(encoderpos<1) encoderpos=1; + if(encoderpos>990) encoderpos=990; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); + } + + }break; + + case ItemCM_vmaxx: + case ItemCM_vmaxy: + case ItemCM_vmaxz: + case ItemCM_vmaxe: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" Vmax "); + if(i==ItemCM_vmaxx)lcdprintPGM("x:"); + if(i==ItemCM_vmaxy)lcdprintPGM("y:"); + if(i==ItemCM_vmaxz)lcdprintPGM("z:"); + if(i==ItemCM_vmaxe)lcdprintPGM("e:"); + lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemCM_vmaxx])); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=(int)max_feedrate[i-ItemCM_vmaxx]; + } + else + { + max_feedrate[i-ItemCM_vmaxx]= encoderpos; + encoderpos=activeline*lcdslow; + + } + BLOCK; + beepshort(); + } + if(linechanging) + { + if(encoderpos<1) encoderpos=1; + if(encoderpos>990) encoderpos=990; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); + } + + }break; + + case ItemCM_vmin: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" Vmin:"); + lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate)); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=(int)(minimumfeedrate); + } + else + { + minimumfeedrate= encoderpos; + encoderpos=activeline*lcdslow; + + } + BLOCK; + beepshort(); + } + if(linechanging) + { + if(encoderpos<0) encoderpos=0; + if(encoderpos>990) encoderpos=990; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); + } + + }break; + case ItemCM_vtravmin: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" VTrav min:"); + lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate)); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=(int)mintravelfeedrate; + } + else + { + mintravelfeedrate= encoderpos; + encoderpos=activeline*lcdslow; + + } + BLOCK; + beepshort(); + } + if(linechanging) + { + if(encoderpos<0) encoderpos=0; + if(encoderpos>990) encoderpos=990; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos)); + } + + }break; + + case ItemCM_amaxx: + case ItemCM_amaxy: + case ItemCM_amaxz: + case ItemCM_amaxe: + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" Amax "); + if(i==ItemCM_amaxx)lcdprintPGM("x:"); + if(i==ItemCM_amaxy)lcdprintPGM("y:"); + if(i==ItemCM_amaxz)lcdprintPGM("z:"); + if(i==ItemCM_amaxe)lcdprintPGM("e:"); + lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100));lcdprintPGM("00"); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=(int)max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100; + } + else + { + max_acceleration_units_per_sq_second[i-ItemCM_amaxx]= encoderpos*100; + encoderpos=activeline*lcdslow; + } + BLOCK; + beepshort(); + } + if(linechanging) + { + if(encoderpos<1) encoderpos=1; + if(encoderpos>990) encoderpos=990; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00"); + } + + }break; + case ItemCM_aret://float retract_acceleration = 7000; + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" A-retract:"); + lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcdprintPGM("00"); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=(int)retract_acceleration/100; + } + else + { + retract_acceleration= encoderpos*100; + encoderpos=activeline*lcdslow; + + } + BLOCK; + beepshort(); + } + if(linechanging) + { + if(encoderpos<10) encoderpos=10; + if(encoderpos>990) encoderpos=990; + lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00"); + } + + }break; + case ItemCM_esteps://axis_steps_per_unit[i] = code_value(); + { + if(force_lcd_update) + { + lcd.setCursor(0,line);lcdprintPGM(" Esteps/mm:"); + lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3])); + } + + if((activeline!=line) ) + break; + + if(CLICKED) + { + linechanging=!linechanging; + if(linechanging) + { + encoderpos=(int)axis_steps_per_unit[3]; + } + else + { + float factor=float(encoderpos)/float(axis_steps_per_unit[3]); + position[E_AXIS]=lround(position[E_AXIS]*factor); + //current_position[3]*=factor; + axis_steps_per_unit[E_AXIS]= encoderpos; + encoderpos=activeline*lcdslow; + + } + BLOCK; + beepshort(); + } + if(linechanging) + { + if(encoderpos<5) encoderpos=5; + if(encoderpos>9999) encoderpos=9999; + lcd.setCursor(13,line);lcd.print(itostr4(encoderpos)); + } + + }break; + default: + break; + } + line++; + } + updateActiveLines(ItemCM_esteps,encoderpos); +} + + +enum { + ItemC_exit,ItemC_temp,ItemC_move, + ItemC_store, ItemC_load,ItemC_failsafe +}; + +void MainMenu::showControl() +{ + uint8_t line=0; + clearIfNecessary(); + for(int8_t i=lineoffset;i=0)?'+':'-'; + xx=abs(xx); + conv[1]=(xx/1000)%10+'0'; + conv[2]=(xx/100)%10+'0'; + conv[3]=(xx/10)%10+'0'; + conv[4]='.'; + conv[5]=(xx)%10+'0'; + conv[6]=0; + return conv; +} + +char *ftostr32(const float &x) +{ + int xx=x*100; + conv[0]=(xx>=0)?'+':'-'; + xx=abs(xx); + conv[1]=(xx/100)%10+'0'; + conv[2]='.'; + conv[3]=(xx/10)%10+'0'; + conv[4]=(xx)%10+'0'; + conv[6]=0; + return conv; +} + +char *itostr31(const int &xx) +{ + conv[0]=(xx>=0)?'+':'-'; + conv[1]=(xx/1000)%10+'0'; + conv[2]=(xx/100)%10+'0'; + conv[3]=(xx/10)%10+'0'; + conv[4]='.'; + conv[5]=(xx)%10+'0'; + conv[6]=0; + return conv; +} + +char *itostr3(const int &xx) +{ + conv[0]=(xx/100)%10+'0'; + conv[1]=(xx/10)%10+'0'; + conv[2]=(xx)%10+'0'; + conv[3]=0; + return conv; +} + +char *itostr4(const int &xx) +{ + conv[0]=(xx/1000)%10+'0'; + conv[1]=(xx/100)%10+'0'; + conv[2]=(xx/10)%10+'0'; + conv[3]=(xx)%10+'0'; + conv[4]=0; + return conv; +} + +// convert float to string with +1234.5 format +char *ftostr51(const float &x) +{ + int xx=x*10; + conv[0]=(xx>=0)?'+':'-'; + xx=abs(xx); + conv[1]=(xx/10000)%10+'0'; + conv[2]=(xx/1000)%10+'0'; + conv[3]=(xx/100)%10+'0'; + conv[4]=(xx/10)%10+'0'; + conv[5]='.'; + conv[6]=(xx)%10+'0'; + conv[7]=0; + return conv; +} + + +#endif //ULTRA_LCD + - ++