ultralcd.cpp 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053
  1. #include "temperature.h"
  2. #include "ultralcd.h"
  3. #ifdef ULTRA_LCD
  4. #include "Marlin.h"
  5. #include "language.h"
  6. #include "cardreader.h"
  7. #include "temperature.h"
  8. #include "stepper.h"
  9. #include "ConfigurationStore.h"
  10. #include <string.h>
  11. //#include "Configuration.h"
  12. #define _STRINGIFY(s) #s
  13. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  14. extern int lcd_change_fil_state;
  15. int babystepMem[3];
  16. float babystepMemMM[3];
  17. union Data
  18. {
  19. byte b[2];
  20. int value;
  21. };
  22. int8_t ReInitLCD = 0;
  23. int8_t SDscrool = 0;
  24. int8_t SilentModeMenu = 0;
  25. int lcd_commands_type=0;
  26. int lcd_commands_step=0;
  27. bool isPrintPaused = false;
  28. /* Configuration settings */
  29. int plaPreheatHotendTemp;
  30. int plaPreheatHPBTemp;
  31. int plaPreheatFanSpeed;
  32. int absPreheatHotendTemp;
  33. int absPreheatHPBTemp;
  34. int absPreheatFanSpeed;
  35. int ppPreheatHotendTemp = PP_PREHEAT_HOTEND_TEMP;
  36. int ppPreheatHPBTemp = PP_PREHEAT_HPB_TEMP;
  37. int ppPreheatFanSpeed = PP_PREHEAT_FAN_SPEED;
  38. int petPreheatHotendTemp = PET_PREHEAT_HOTEND_TEMP;
  39. int petPreheatHPBTemp = PET_PREHEAT_HPB_TEMP;
  40. int petPreheatFanSpeed = PET_PREHEAT_FAN_SPEED;
  41. int hipsPreheatHotendTemp = HIPS_PREHEAT_HOTEND_TEMP;
  42. int hipsPreheatHPBTemp = HIPS_PREHEAT_HPB_TEMP;
  43. int hipsPreheatFanSpeed = HIPS_PREHEAT_FAN_SPEED;
  44. int flexPreheatHotendTemp = FLEX_PREHEAT_HOTEND_TEMP;
  45. int flexPreheatHPBTemp = FLEX_PREHEAT_HPB_TEMP;
  46. int flexPreheatFanSpeed = FLEX_PREHEAT_FAN_SPEED;
  47. #ifdef FILAMENT_LCD_DISPLAY
  48. unsigned long message_millis = 0;
  49. #endif
  50. #ifdef ULTIPANEL
  51. static float manual_feedrate[] = MANUAL_FEEDRATE;
  52. #endif // ULTIPANEL
  53. /* !Configuration settings */
  54. //Function pointer to menu functions.
  55. typedef void (*menuFunc_t)();
  56. uint8_t lcd_status_message_level;
  57. char lcd_status_message[LCD_WIDTH + 1] = ""; //////WELCOME!
  58. unsigned char firstrun = 1;
  59. #ifdef DOGLCD
  60. #include "dogm_lcd_implementation.h"
  61. #else
  62. #include "ultralcd_implementation_hitachi_HD44780.h"
  63. #endif
  64. /** forward declarations **/
  65. void copy_and_scalePID_i();
  66. void copy_and_scalePID_d();
  67. /* Different menus */
  68. static void lcd_status_screen();
  69. #ifdef ULTIPANEL
  70. extern bool powersupply;
  71. static void lcd_main_menu();
  72. static void lcd_tune_menu();
  73. static void lcd_prepare_menu();
  74. static void lcd_move_menu();
  75. static void lcd_control_menu();
  76. static void lcd_settings_menu();
  77. static void lcd_language_menu();
  78. static void lcd_control_temperature_menu();
  79. static void lcd_control_temperature_preheat_pla_settings_menu();
  80. static void lcd_control_temperature_preheat_abs_settings_menu();
  81. static void lcd_control_motion_menu();
  82. static void lcd_control_volumetric_menu();
  83. #ifdef DOGLCD
  84. static void lcd_set_contrast();
  85. #endif
  86. static void lcd_control_retract_menu();
  87. static void lcd_sdcard_menu();
  88. #ifdef DELTA_CALIBRATION_MENU
  89. static void lcd_delta_calibrate_menu();
  90. #endif // DELTA_CALIBRATION_MENU
  91. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
  92. /* Different types of actions that can be used in menu items. */
  93. static void menu_action_back(menuFunc_t data);
  94. static void menu_action_submenu(menuFunc_t data);
  95. static void menu_action_gcode(const char* pgcode);
  96. static void menu_action_function(menuFunc_t data);
  97. static void menu_action_setlang(unsigned char lang);
  98. static void menu_action_sdfile(const char* filename, char* longFilename);
  99. static void menu_action_sddirectory(const char* filename, char* longFilename);
  100. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  101. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  102. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  103. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  104. static void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  105. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  106. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  107. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  108. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  109. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
  110. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
  111. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  112. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  113. static void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  114. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  115. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  116. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  117. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
  118. #define ENCODER_FEEDRATE_DEADZONE 10
  119. #if !defined(LCD_I2C_VIKI)
  120. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  121. #define ENCODER_STEPS_PER_MENU_ITEM 5
  122. #endif
  123. #ifndef ENCODER_PULSES_PER_STEP
  124. #define ENCODER_PULSES_PER_STEP 1
  125. #endif
  126. #else
  127. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  128. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  129. #endif
  130. #ifndef ENCODER_PULSES_PER_STEP
  131. #define ENCODER_PULSES_PER_STEP 1
  132. #endif
  133. #endif
  134. /* Helper macros for menus */
  135. #define START_MENU() do { \
  136. if (encoderPosition > 0x8000) encoderPosition = 0; \
  137. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset) currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;\
  138. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  139. bool wasClicked = LCD_CLICKED;\
  140. for(uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  141. _menuItemNr = 0;
  142. #define MENU_ITEM(type, label, args...) do { \
  143. if (_menuItemNr == _lineNr) { \
  144. if (lcdDrawUpdate) { \
  145. const char* _label_pstr = (label); \
  146. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  147. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  148. }else{\
  149. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  150. }\
  151. }\
  152. if (wasClicked && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  153. lcd_quick_feedback(); \
  154. menu_action_ ## type ( args ); \
  155. return;\
  156. }\
  157. }\
  158. _menuItemNr++;\
  159. } while(0)
  160. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  161. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, (label) , ## args )
  162. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, (label) , ## args )
  163. #define END_MENU() \
  164. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
  165. if ((uint8_t)(encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) >= currentMenuViewOffset + LCD_HEIGHT) { currentMenuViewOffset = (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) - LCD_HEIGHT + 1; lcdDrawUpdate = 1; _lineNr = currentMenuViewOffset - 1; _drawLineNr = -1; } \
  166. } } while(0)
  167. /** Used variables to keep track of the menu */
  168. #ifndef REPRAPWORLD_KEYPAD
  169. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  170. #else
  171. volatile uint8_t buttons_reprapworld_keypad; // to store the reprapworld_keypad shift register values
  172. #endif
  173. #ifdef LCD_HAS_SLOW_BUTTONS
  174. volatile uint8_t slow_buttons;//Contains the bits of the currently pressed buttons.
  175. #endif
  176. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  177. uint32_t blocking_enc;
  178. uint8_t lastEncoderBits;
  179. uint32_t encoderPosition;
  180. #if (SDCARDDETECT > 0)
  181. bool lcd_oldcardstatus;
  182. #endif
  183. #endif //ULTIPANEL
  184. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  185. uint32_t lcd_next_update_millis;
  186. uint8_t lcd_status_update_delay;
  187. bool ignore_click = false;
  188. bool wait_for_unclick;
  189. uint8_t lcdDrawUpdate = 2; /* Set to none-zero when the LCD needs to draw, decreased after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial) */
  190. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  191. menuFunc_t prevMenu = NULL;
  192. uint16_t prevEncoderPosition;
  193. //Variables used when editing values.
  194. const char* editLabel;
  195. void* editValue;
  196. int32_t minEditValue, maxEditValue;
  197. menuFunc_t callbackFunc;
  198. // place-holders for Ki and Kd edits
  199. float raw_Ki, raw_Kd;
  200. static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder = 0, const bool feedback = true) {
  201. if (currentMenu != menu) {
  202. currentMenu = menu;
  203. encoderPosition = encoder;
  204. if (feedback) lcd_quick_feedback();
  205. // For LCD_PROGRESS_BAR re-initialize the custom characters
  206. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  207. lcd_set_custom_characters(menu == lcd_status_screen);
  208. #endif
  209. }
  210. }
  211. /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */
  212. /*
  213. extern char langbuffer[];
  214. void lcd_printPGM(const char *s1) {
  215. strncpy_P(langbuffer,s1,LCD_WIDTH);
  216. lcd.print(langbuffer);
  217. }
  218. */
  219. unsigned char langsel;
  220. void set_language_from_EEPROM() {
  221. unsigned char eep = eeprom_read_byte((unsigned char*)EEPROM_LANG);
  222. if (eep < LANG_NUM)
  223. {
  224. lang_selected = eep;
  225. langsel = 0;
  226. }
  227. else
  228. {
  229. lang_selected = 1;
  230. langsel = 1;
  231. }
  232. }
  233. void lcd_mylang();
  234. static void lcd_status_screen()
  235. {
  236. if (firstrun == 1)
  237. {
  238. firstrun = 0;
  239. set_language_from_EEPROM();
  240. strncpy_P(lcd_status_message, WELCOME_MSG, LCD_WIDTH);
  241. if (eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 1) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 2) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 3) == 255)
  242. {
  243. eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0);
  244. eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0);
  245. }
  246. if (langsel) {
  247. //strncpy_P(lcd_status_message, PSTR(">>>>>>>>>>>> PRESS v"), LCD_WIDTH);
  248. lcd_mylang();
  249. }
  250. }
  251. if (lcd_status_update_delay)
  252. lcd_status_update_delay--;
  253. else
  254. lcdDrawUpdate = 1;
  255. if (lcdDrawUpdate)
  256. {
  257. ReInitLCD++;
  258. if (ReInitLCD == 30) {
  259. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  260. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  261. currentMenu == lcd_status_screen
  262. #endif
  263. );
  264. ReInitLCD = 0 ;
  265. } else {
  266. if ((ReInitLCD % 10) == 0) {
  267. //lcd_implementation_nodisplay();
  268. lcd_implementation_init_noclear( // to maybe revive the LCD if static electricity killed it.
  269. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  270. currentMenu == lcd_status_screen
  271. #endif
  272. );
  273. }
  274. }
  275. //lcd_implementation_display();
  276. lcd_implementation_status_screen();
  277. //lcd_implementation_clear();
  278. lcd_status_update_delay = 10; /* redraw the main screen every second. This is easier then trying keep track of all things that change on the screen */
  279. if (lcd_commands_type != 0)
  280. {
  281. lcd_commands();
  282. }
  283. }
  284. #ifdef ULTIPANEL
  285. bool current_click = LCD_CLICKED;
  286. if (ignore_click) {
  287. if (wait_for_unclick) {
  288. if (!current_click) {
  289. ignore_click = wait_for_unclick = false;
  290. }
  291. else {
  292. current_click = false;
  293. }
  294. }
  295. else if (current_click) {
  296. lcd_quick_feedback();
  297. wait_for_unclick = true;
  298. current_click = false;
  299. }
  300. }
  301. //if (--langsel ==0) {langsel=1;current_click=true;}
  302. if (current_click)
  303. {
  304. lcd_goto_menu(lcd_main_menu);
  305. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  306. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  307. currentMenu == lcd_status_screen
  308. #endif
  309. );
  310. #ifdef FILAMENT_LCD_DISPLAY
  311. message_millis = millis(); // get status message to show up for a while
  312. #endif
  313. }
  314. #ifdef ULTIPANEL_FEEDMULTIPLY
  315. // Dead zone at 100% feedrate
  316. if ((feedmultiply < 100 && (feedmultiply + int(encoderPosition)) > 100) ||
  317. (feedmultiply > 100 && (feedmultiply + int(encoderPosition)) < 100))
  318. {
  319. encoderPosition = 0;
  320. feedmultiply = 100;
  321. }
  322. if (feedmultiply == 100 && int(encoderPosition) > ENCODER_FEEDRATE_DEADZONE)
  323. {
  324. feedmultiply += int(encoderPosition) - ENCODER_FEEDRATE_DEADZONE;
  325. encoderPosition = 0;
  326. }
  327. else if (feedmultiply == 100 && int(encoderPosition) < -ENCODER_FEEDRATE_DEADZONE)
  328. {
  329. feedmultiply += int(encoderPosition) + ENCODER_FEEDRATE_DEADZONE;
  330. encoderPosition = 0;
  331. }
  332. else if (feedmultiply != 100)
  333. {
  334. feedmultiply += int(encoderPosition);
  335. encoderPosition = 0;
  336. }
  337. #endif //ULTIPANEL_FEEDMULTIPLY
  338. if (feedmultiply < 10)
  339. feedmultiply = 10;
  340. else if (feedmultiply > 999)
  341. feedmultiply = 999;
  342. #endif //ULTIPANEL
  343. }
  344. #ifdef ULTIPANEL
  345. void lcd_commands()
  346. {
  347. if (lcd_commands_type == 1) //// load filament sequence
  348. {
  349. if (lcd_commands_step == 0) { lcd_commands_step = 5; custom_message = true; }
  350. if (lcd_commands_step == 1 && !blocks_queued())
  351. {
  352. lcd_commands_step = 0;
  353. lcd_commands_type = 0;
  354. lcd_setstatuspgm(WELCOME_MSG);
  355. disable_z();
  356. custom_message = false;
  357. custom_message_type = 0;
  358. }
  359. if (lcd_commands_step == 2 && !blocks_queued())
  360. {
  361. lcd_setstatuspgm(MSG_LOADING_FILAMENT);
  362. enquecommand_P(PSTR(LOAD_FILAMENT_2));
  363. lcd_commands_step = 1;
  364. }
  365. if (lcd_commands_step == 3 && !blocks_queued())
  366. {
  367. enquecommand_P(PSTR(LOAD_FILAMENT_1));
  368. lcd_commands_step = 2;
  369. }
  370. if (lcd_commands_step == 4 && !blocks_queued())
  371. {
  372. lcd_setstatuspgm(MSG_INSERT_FILAMENT);
  373. enquecommand_P(PSTR(LOAD_FILAMENT_0));
  374. lcd_commands_step = 3;
  375. }
  376. if (lcd_commands_step == 5 && !blocks_queued())
  377. {
  378. lcd_setstatuspgm(MSG_PLEASE_WAIT);
  379. enable_z();
  380. custom_message = true;
  381. custom_message_type = 2;
  382. lcd_commands_step = 4;
  383. }
  384. }
  385. if (lcd_commands_type == 2) /// stop print
  386. {
  387. if (lcd_commands_step == 0) { lcd_commands_step = 6; custom_message = true; }
  388. if (lcd_commands_step == 1 && !blocks_queued())
  389. {
  390. lcd_commands_step = 0;
  391. lcd_commands_type = 0;
  392. lcd_setstatuspgm(WELCOME_MSG);
  393. custom_message = false;
  394. }
  395. if (lcd_commands_step == 2 && !blocks_queued())
  396. {
  397. setTargetBed(0);
  398. setTargetHotend(0, 0);
  399. setTargetHotend(0, 1);
  400. setTargetHotend(0, 2);
  401. manage_heater();
  402. lcd_setstatuspgm(WELCOME_MSG);
  403. cancel_heatup = false;
  404. lcd_commands_step = 1;
  405. }
  406. if (lcd_commands_step == 3 && !blocks_queued())
  407. {
  408. enquecommand_P(PSTR("M84"));
  409. autotempShutdown();
  410. lcd_commands_step = 2;
  411. }
  412. if (lcd_commands_step == 4 && !blocks_queued())
  413. {
  414. enquecommand_P(PSTR("G90"));
  415. #ifdef X_CANCEL_POS
  416. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  417. #else
  418. enquecommand_P(PSTR("G1 X50 Y" STRINGIFY(Y_MAX_POS) " E0 F7000"));
  419. #endif
  420. lcd_ignore_click(false);
  421. lcd_commands_step = 3;
  422. }
  423. if (lcd_commands_step == 5 && !blocks_queued())
  424. {
  425. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  426. enquecommand_P(PSTR("G91"));
  427. enquecommand_P(PSTR("G1 Z15 F1500"));
  428. lcd_commands_step = 4;
  429. }
  430. if (lcd_commands_step == 6 && !blocks_queued())
  431. {
  432. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  433. cancel_heatup = true;
  434. setTargetBed(0);
  435. setTargetHotend(0, 0);
  436. setTargetHotend(0, 1);
  437. setTargetHotend(0, 2);
  438. manage_heater();
  439. lcd_commands_step = 5;
  440. }
  441. }
  442. if (lcd_commands_type == 3)
  443. {
  444. lcd_commands_type = 0;
  445. }
  446. }
  447. static void lcd_return_to_status() {
  448. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  449. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  450. currentMenu == lcd_status_screen
  451. #endif
  452. );
  453. lcd_goto_menu(lcd_status_screen, 0, false);
  454. }
  455. static void lcd_sdcard_pause() {
  456. card.pauseSDPrint();
  457. isPrintPaused = true;
  458. lcdDrawUpdate = 3;
  459. }
  460. static void lcd_sdcard_resume() {
  461. card.startFileprint();
  462. isPrintPaused = false;
  463. lcdDrawUpdate = 3;
  464. }
  465. float move_menu_scale;
  466. static void lcd_move_menu_axis();
  467. /* Menu implementation */
  468. void lcd_preheat_pla()
  469. {
  470. setTargetHotend0(plaPreheatHotendTemp);
  471. setTargetBed(plaPreheatHPBTemp);
  472. fanSpeed = 0;
  473. lcd_return_to_status();
  474. setWatch(); // heater sanity check timer
  475. }
  476. void lcd_preheat_abs()
  477. {
  478. setTargetHotend0(absPreheatHotendTemp);
  479. setTargetBed(absPreheatHPBTemp);
  480. fanSpeed = 0;
  481. lcd_return_to_status();
  482. setWatch(); // heater sanity check timer
  483. }
  484. void lcd_preheat_pp()
  485. {
  486. setTargetHotend0(ppPreheatHotendTemp);
  487. setTargetBed(ppPreheatHPBTemp);
  488. fanSpeed = 0;
  489. lcd_return_to_status();
  490. setWatch(); // heater sanity check timer
  491. }
  492. void lcd_preheat_pet()
  493. {
  494. setTargetHotend0(petPreheatHotendTemp);
  495. setTargetBed(petPreheatHPBTemp);
  496. fanSpeed = 0;
  497. lcd_return_to_status();
  498. setWatch(); // heater sanity check timer
  499. }
  500. void lcd_preheat_hips()
  501. {
  502. setTargetHotend0(hipsPreheatHotendTemp);
  503. setTargetBed(hipsPreheatHPBTemp);
  504. fanSpeed = 0;
  505. lcd_return_to_status();
  506. setWatch(); // heater sanity check timer
  507. }
  508. void lcd_preheat_flex()
  509. {
  510. setTargetHotend0(flexPreheatHotendTemp);
  511. setTargetBed(flexPreheatHPBTemp);
  512. fanSpeed = 0;
  513. lcd_return_to_status();
  514. setWatch(); // heater sanity check timer
  515. }
  516. void lcd_cooldown()
  517. {
  518. setTargetHotend0(0);
  519. setTargetHotend1(0);
  520. setTargetHotend2(0);
  521. setTargetBed(0);
  522. fanSpeed = 0;
  523. lcd_return_to_status();
  524. }
  525. static void lcd_preheat_menu()
  526. {
  527. START_MENU();
  528. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  529. MENU_ITEM(function, PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)), lcd_preheat_abs);
  530. MENU_ITEM(function, PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)), lcd_preheat_pla);
  531. MENU_ITEM(function, PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)), lcd_preheat_pet);
  532. MENU_ITEM(function, PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)), lcd_preheat_hips);
  533. MENU_ITEM(function, PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)), lcd_preheat_pp);
  534. MENU_ITEM(function, PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)), lcd_preheat_flex);
  535. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  536. END_MENU();
  537. }
  538. static void lcd_support_menu()
  539. {
  540. START_MENU();
  541. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  542. MENU_ITEM(back, PSTR(MSG_FW_VERSION " - " FW_version), lcd_main_menu);
  543. MENU_ITEM(back, MSG_PRUSA3D, lcd_main_menu);
  544. MENU_ITEM(back, MSG_PRUSA3D_FORUM, lcd_main_menu);
  545. MENU_ITEM(back, MSG_PRUSA3D_HOWTO, lcd_main_menu);
  546. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  547. MENU_ITEM(back, PSTR(FILAMENT_SIZE), lcd_main_menu);
  548. MENU_ITEM(back, PSTR(ELECTRONICS),lcd_main_menu);
  549. MENU_ITEM(back, PSTR(NOZZLE_TYPE),lcd_main_menu);
  550. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  551. MENU_ITEM(back, PSTR("Date: "), lcd_main_menu);
  552. MENU_ITEM(back, PSTR(__DATE__), lcd_main_menu);
  553. END_MENU();
  554. }
  555. void lcd_unLoadFilament()
  556. {
  557. if (degHotend0() > EXTRUDE_MINTEMP) {
  558. enquecommand_P(PSTR(UNLOAD_FILAMENT_0));
  559. enquecommand_P(PSTR(UNLOAD_FILAMENT_1));
  560. } else {
  561. lcd_implementation_clear();
  562. lcd.setCursor(0, 0);
  563. lcd_printPGM(MSG_ERROR);
  564. lcd.setCursor(0, 2);
  565. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  566. delay(2000);
  567. lcd_implementation_clear();
  568. }
  569. lcd_return_to_status();
  570. }
  571. void lcd_change_filament() {
  572. lcd_implementation_clear();
  573. lcd.setCursor(0, 1);
  574. lcd_printPGM(MSG_CHANGING_FILAMENT);
  575. }
  576. void lcd_wait_interact() {
  577. lcd_implementation_clear();
  578. lcd.setCursor(0, 1);
  579. lcd_printPGM(MSG_INSERT_FILAMENT);
  580. lcd.setCursor(0, 2);
  581. lcd_printPGM(MSG_PRESS);
  582. }
  583. void lcd_change_success() {
  584. lcd_implementation_clear();
  585. lcd.setCursor(0, 2);
  586. lcd_printPGM(MSG_CHANGE_SUCCESS);
  587. }
  588. void lcd_loading_color() {
  589. lcd_implementation_clear();
  590. lcd.setCursor(0, 0);
  591. lcd_printPGM(MSG_LOADING_COLOR);
  592. lcd.setCursor(0, 2);
  593. lcd_printPGM(MSG_PLEASE_WAIT);
  594. for (int i = 0; i < 20; i++) {
  595. lcd.setCursor(i, 3);
  596. lcd.print(".");
  597. for (int j = 0; j < 10 ; j++) {
  598. manage_heater();
  599. manage_inactivity(true);
  600. delay(85);
  601. }
  602. }
  603. }
  604. void lcd_loading_filament() {
  605. lcd_implementation_clear();
  606. lcd.setCursor(0, 0);
  607. lcd_printPGM(MSG_LOADING_FILAMENT);
  608. lcd.setCursor(0, 2);
  609. lcd_printPGM(MSG_PLEASE_WAIT);
  610. for (int i = 0; i < 20; i++) {
  611. lcd.setCursor(i, 3);
  612. lcd.print(".");
  613. for (int j = 0; j < 10 ; j++) {
  614. manage_heater();
  615. manage_inactivity(true);
  616. delay(110);
  617. }
  618. }
  619. }
  620. void lcd_alright() {
  621. int enc_dif = 0;
  622. int cursor_pos = 1;
  623. lcd_implementation_clear();
  624. lcd.setCursor(0, 0);
  625. lcd_printPGM(MSG_CORRECTLY);
  626. lcd.setCursor(1, 1);
  627. lcd_printPGM(MSG_YES);
  628. lcd.setCursor(1, 2);
  629. lcd_printPGM(MSG_NOT_LOADED);
  630. lcd.setCursor(1, 3);
  631. lcd_printPGM(MSG_NOT_COLOR);
  632. lcd.setCursor(0, 1);
  633. lcd.print(">");
  634. enc_dif = encoderDiff;
  635. while (lcd_change_fil_state == 0) {
  636. manage_heater();
  637. manage_inactivity(true);
  638. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  639. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  640. if (enc_dif > encoderDiff ) {
  641. cursor_pos --;
  642. }
  643. if (enc_dif < encoderDiff ) {
  644. cursor_pos ++;
  645. }
  646. if (cursor_pos > 3) {
  647. cursor_pos = 3;
  648. }
  649. if (cursor_pos < 1) {
  650. cursor_pos = 1;
  651. }
  652. lcd.setCursor(0, 1);
  653. lcd.print(" ");
  654. lcd.setCursor(0, 2);
  655. lcd.print(" ");
  656. lcd.setCursor(0, 3);
  657. lcd.print(" ");
  658. lcd.setCursor(0, cursor_pos);
  659. lcd.print(">");
  660. enc_dif = encoderDiff;
  661. delay(100);
  662. }
  663. }
  664. if (lcd_clicked()) {
  665. lcd_change_fil_state = cursor_pos;
  666. delay(500);
  667. }
  668. };
  669. lcd_implementation_clear();
  670. lcd_return_to_status();
  671. }
  672. void lcd_LoadFilament()
  673. {
  674. if (degHotend0() > EXTRUDE_MINTEMP)
  675. {
  676. custom_message = true;
  677. lcd_commands_type = 1;
  678. SERIAL_ECHOLN("Loading filament");
  679. // commands() will handle the rest
  680. }
  681. else
  682. {
  683. lcd_implementation_clear();
  684. lcd.setCursor(0, 0);
  685. lcd_printPGM(MSG_ERROR);
  686. lcd.setCursor(0, 2);
  687. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  688. delay(2000);
  689. lcd_implementation_clear();
  690. }
  691. lcd_return_to_status();
  692. }
  693. static void lcd_menu_statistics()
  694. {
  695. if (IS_SD_PRINTING)
  696. {
  697. int _met = total_filament_used / 100000;
  698. int _cm = (total_filament_used - (_met * 100000))/10;
  699. int _t = (millis() - starttime) / 1000;
  700. int _h = _t / 3600;
  701. int _m = (_t - (_h * 60)) / 60;
  702. int _s = _t - ((_h * 3600) + (_m * 60));
  703. lcd.setCursor(0, 0);
  704. lcd_printPGM(MSG_STATS_FILAMENTUSED);
  705. lcd.setCursor(6, 1);
  706. lcd.print(itostr3(_met));
  707. lcd.print("m ");
  708. lcd.print(ftostr32ns(_cm));
  709. lcd.print("cm");
  710. lcd.setCursor(0, 2);
  711. lcd_printPGM(MSG_STATS_PRINTTIME);
  712. lcd.setCursor(8, 3);
  713. lcd.print(itostr2(_h));
  714. lcd.print("h ");
  715. lcd.print(itostr2(_m));
  716. lcd.print("m ");
  717. lcd.print(itostr2(_s));
  718. lcd.print("s");
  719. if (lcd_clicked())
  720. {
  721. lcd_quick_feedback();
  722. lcd_return_to_status();
  723. }
  724. }
  725. else
  726. {
  727. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  728. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME);
  729. uint8_t _days, _hours, _minutes;
  730. float _filament_m = (float)_filament;
  731. int _filament_km = (_filament >= 100000) ? _filament / 100000 : 0;
  732. if (_filament_km > 0) _filament_m = _filament - (_filament_km * 100000);
  733. _days = _time / 1440;
  734. _hours = (_time - (_days * 1440)) / 60;
  735. _minutes = _time - ((_days * 1440) + (_hours * 60));
  736. lcd_implementation_clear();
  737. lcd.setCursor(0, 0);
  738. lcd_printPGM(MSG_STATS_TOTALFILAMENT);
  739. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)), 1);
  740. lcd.print(ftostr32ns(_filament_m));
  741. if (_filament_km > 0)
  742. {
  743. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)) - 3, 1);
  744. lcd.print("km");
  745. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)) - 8, 1);
  746. lcd.print(itostr4(_filament_km));
  747. }
  748. lcd.setCursor(18, 1);
  749. lcd.print("m");
  750. lcd.setCursor(0, 2);
  751. lcd_printPGM(MSG_STATS_TOTALPRINTTIME);;
  752. lcd.setCursor(18, 3);
  753. lcd.print("m");
  754. lcd.setCursor(14, 3);
  755. lcd.print(itostr3(_minutes));
  756. lcd.setCursor(14, 3);
  757. lcd.print(":");
  758. lcd.setCursor(12, 3);
  759. lcd.print("h");
  760. lcd.setCursor(9, 3);
  761. lcd.print(itostr3(_hours));
  762. lcd.setCursor(9, 3);
  763. lcd.print(":");
  764. lcd.setCursor(7, 3);
  765. lcd.print("d");
  766. lcd.setCursor(4, 3);
  767. lcd.print(itostr3(_days));
  768. while (!lcd_clicked())
  769. {
  770. manage_heater();
  771. manage_inactivity(true);
  772. delay(100);
  773. }
  774. lcd_quick_feedback();
  775. lcd_return_to_status();
  776. }
  777. }
  778. static void _lcd_move(const char *name, int axis, int min, int max) {
  779. if (encoderPosition != 0) {
  780. refresh_cmd_timeout();
  781. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  782. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  783. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  784. encoderPosition = 0;
  785. #ifdef DELTA
  786. calculate_delta(current_position);
  787. plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis] / 60, active_extruder);
  788. #else
  789. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[axis] / 60, active_extruder);
  790. #endif
  791. lcdDrawUpdate = 1;
  792. }
  793. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  794. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  795. }
  796. static void lcd_move_e()
  797. {
  798. if (encoderPosition != 0)
  799. {
  800. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  801. encoderPosition = 0;
  802. #ifdef DELTA
  803. calculate_delta(current_position);
  804. plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS], manual_feedrate[E_AXIS] / 60, active_extruder);
  805. #else
  806. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[E_AXIS] / 60, active_extruder);
  807. #endif
  808. lcdDrawUpdate = 1;
  809. }
  810. if (lcdDrawUpdate)
  811. {
  812. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  813. }
  814. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  815. }
  816. void EEPROM_save_B(int pos, int* value)
  817. {
  818. union Data data;
  819. data.value = *value;
  820. eeprom_write_byte((unsigned char*)pos, data.b[0]);
  821. eeprom_write_byte((unsigned char*)pos + 1, data.b[1]);
  822. }
  823. void EEPROM_read_B(int pos, int* value)
  824. {
  825. union Data data;
  826. data.b[0] = eeprom_read_byte((unsigned char*)pos);
  827. data.b[1] = eeprom_read_byte((unsigned char*)pos + 1);
  828. *value = data.value;
  829. }
  830. static void lcd_move_x() {
  831. _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS);
  832. }
  833. static void lcd_move_y() {
  834. _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  835. }
  836. static void lcd_move_z() {
  837. _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  838. }
  839. static void _lcd_babystep(int axis, const char *msg) {
  840. if (encoderPosition != 0)
  841. {
  842. babystepsTodo[axis] += (int)encoderPosition;
  843. babystepMem[axis] += (int)encoderPosition;
  844. babystepMemMM[axis] = babystepMem[axis]/axis_steps_per_unit[Z_AXIS];
  845. delay(50);
  846. encoderPosition = 0;
  847. lcdDrawUpdate = 1;
  848. }
  849. if (lcdDrawUpdate) lcd_implementation_drawedit_2(msg, ftostr13ns(babystepMemMM[axis]));
  850. if (LCD_CLICKED) lcd_goto_menu(lcd_main_menu);
  851. EEPROM_save_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  852. EEPROM_save_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  853. EEPROM_save_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  854. }
  855. static void lcd_babystep_x() {
  856. _lcd_babystep(X_AXIS, (MSG_BABYSTEPPING_X));
  857. }
  858. static void lcd_babystep_y() {
  859. _lcd_babystep(Y_AXIS, (MSG_BABYSTEPPING_Y));
  860. }
  861. static void lcd_babystep_z() {
  862. _lcd_babystep(Z_AXIS, (MSG_BABYSTEPPING_Z));
  863. }
  864. void lcd_adjust_z() {
  865. int enc_dif = 0;
  866. int cursor_pos = 1;
  867. int fsm = 0;
  868. lcd_implementation_clear();
  869. lcd.setCursor(0, 0);
  870. lcd_printPGM(MSG_ADJUSTZ);
  871. lcd.setCursor(1, 1);
  872. lcd_printPGM(MSG_YES);
  873. lcd.setCursor(1, 2);
  874. lcd_printPGM(MSG_NO);
  875. lcd.setCursor(0, 1);
  876. lcd.print(">");
  877. enc_dif = encoderDiff;
  878. while (fsm == 0) {
  879. manage_heater();
  880. manage_inactivity(true);
  881. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  882. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  883. if (enc_dif > encoderDiff ) {
  884. cursor_pos --;
  885. }
  886. if (enc_dif < encoderDiff ) {
  887. cursor_pos ++;
  888. }
  889. if (cursor_pos > 2) {
  890. cursor_pos = 2;
  891. }
  892. if (cursor_pos < 1) {
  893. cursor_pos = 1;
  894. }
  895. lcd.setCursor(0, 1);
  896. lcd.print(" ");
  897. lcd.setCursor(0, 2);
  898. lcd.print(" ");
  899. lcd.setCursor(0, cursor_pos);
  900. lcd.print(">");
  901. enc_dif = encoderDiff;
  902. delay(100);
  903. }
  904. }
  905. if (lcd_clicked()) {
  906. fsm = cursor_pos;
  907. if (fsm == 1) {
  908. EEPROM_read_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  909. EEPROM_read_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  910. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  911. babystepsTodo[Z_AXIS] = babystepMem[2];
  912. } else {
  913. babystepMem[0] = 0;
  914. babystepMem[1] = 0;
  915. babystepMem[2] = 0;
  916. EEPROM_save_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  917. EEPROM_save_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  918. EEPROM_save_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  919. }
  920. delay(500);
  921. }
  922. };
  923. lcd_implementation_clear();
  924. lcd_return_to_status();
  925. }
  926. void lcd_calibration() {
  927. }
  928. void lcd_pick_babystep(){
  929. int enc_dif = 0;
  930. int cursor_pos = 1;
  931. int fsm = 0;
  932. lcd_implementation_clear();
  933. lcd.setCursor(0, 0);
  934. lcd_printPGM(MSG_PICK_Z);
  935. lcd.setCursor(3, 2);
  936. lcd.print("1");
  937. lcd.setCursor(3, 3);
  938. lcd.print("2");
  939. lcd.setCursor(12, 2);
  940. lcd.print("3");
  941. lcd.setCursor(12, 3);
  942. lcd.print("4");
  943. lcd.setCursor(1, 2);
  944. lcd.print(">");
  945. enc_dif = encoderDiff;
  946. while (fsm == 0) {
  947. manage_heater();
  948. manage_inactivity(true);
  949. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  950. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  951. if (enc_dif > encoderDiff ) {
  952. cursor_pos --;
  953. }
  954. if (enc_dif < encoderDiff ) {
  955. cursor_pos ++;
  956. }
  957. if (cursor_pos > 4) {
  958. cursor_pos = 4;
  959. }
  960. if (cursor_pos < 1) {
  961. cursor_pos = 1;
  962. }
  963. lcd.setCursor(1, 2);
  964. lcd.print(" ");
  965. lcd.setCursor(1, 3);
  966. lcd.print(" ");
  967. lcd.setCursor(10, 2);
  968. lcd.print(" ");
  969. lcd.setCursor(10, 3);
  970. lcd.print(" ");
  971. if (cursor_pos < 3) {
  972. lcd.setCursor(1, cursor_pos+1);
  973. lcd.print(">");
  974. }else{
  975. lcd.setCursor(10, cursor_pos-1);
  976. lcd.print(">");
  977. }
  978. enc_dif = encoderDiff;
  979. delay(100);
  980. }
  981. }
  982. if (lcd_clicked()) {
  983. fsm = cursor_pos;
  984. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babystepMem[2]);
  985. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babystepMem[2]);
  986. eeprom_write_byte((unsigned char*)EEPROM_BABYSTEP_Z_SET, 0x01);
  987. delay(500);
  988. }
  989. };
  990. lcd_implementation_clear();
  991. lcd_return_to_status();
  992. }
  993. void lcd_move_menu_axis()
  994. {
  995. START_MENU();
  996. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  997. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  998. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  999. if (move_menu_scale < 10.0)
  1000. {
  1001. if (!isPrintPaused)
  1002. {
  1003. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  1004. }
  1005. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  1006. }
  1007. END_MENU();
  1008. }
  1009. static void lcd_move_menu_1mm()
  1010. {
  1011. move_menu_scale = 1.0;
  1012. lcd_move_menu_axis();
  1013. }
  1014. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  1015. {
  1016. do
  1017. {
  1018. eeprom_write_byte((unsigned char*)pos, *value);
  1019. pos++;
  1020. value++;
  1021. } while (--size);
  1022. }
  1023. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  1024. {
  1025. do
  1026. {
  1027. *value = eeprom_read_byte((unsigned char*)pos);
  1028. pos++;
  1029. value++;
  1030. } while (--size);
  1031. }
  1032. static void lcd_silent_mode_set() {
  1033. SilentModeMenu = !SilentModeMenu;
  1034. EEPROM_save(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  1035. digipot_init();
  1036. lcd_goto_menu(lcd_settings_menu, 7);
  1037. }
  1038. static void lcd_set_lang(unsigned char lang) {
  1039. lang_selected = lang;
  1040. firstrun = 1;
  1041. eeprom_write_byte((unsigned char *)EEPROM_LANG, lang);/*langsel=0;*/if (langsel == 1)langsel = 2;
  1042. }
  1043. void lcd_force_language_selection() {
  1044. eeprom_write_byte((unsigned char *)EEPROM_LANG, 255);
  1045. }
  1046. static void lcd_language_menu()
  1047. {
  1048. START_MENU();
  1049. if (!langsel) {
  1050. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  1051. }
  1052. if (langsel == 2) {
  1053. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  1054. }
  1055. for (int i=0;i<LANG_NUM;i++){
  1056. MENU_ITEM(setlang, MSG_ALL[i][LANGUAGE_NAME], i);
  1057. }
  1058. //MENU_ITEM(setlang, MSG_ALL[1][LANGUAGE_NAME], 1);
  1059. END_MENU();
  1060. }
  1061. void lcd_mesh_bedleveling()
  1062. {
  1063. enquecommand_P(PSTR("G80"));
  1064. lcd_return_to_status();
  1065. }
  1066. static void lcd_settings_menu()
  1067. {
  1068. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  1069. START_MENU();
  1070. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1071. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1072. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu_1mm);
  1073. if (!isPrintPaused)
  1074. {
  1075. #ifndef MESH_BED_LEVELING
  1076. MENU_ITEM(gcode, MSG_HOMEYZ, PSTR("G28 Z"));
  1077. #else
  1078. MENU_ITEM(submenu, MSG_HOMEYZ, lcd_mesh_bedleveling);
  1079. #endif
  1080. }
  1081. if (!isPrintPaused)
  1082. {
  1083. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  1084. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  1085. }
  1086. if (SilentModeMenu == 0) {
  1087. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  1088. } else {
  1089. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  1090. }
  1091. EEPROM_read_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  1092. EEPROM_read_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  1093. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  1094. babystepMemMM[2] = babystepMem[2]/axis_steps_per_unit[Z_AXIS];
  1095. if (!isPrintPaused)
  1096. {
  1097. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  1098. }
  1099. MENU_ITEM(submenu, MSG_LANGUAGE_SELECT, lcd_language_menu);
  1100. if (!isPrintPaused)
  1101. {
  1102. MENU_ITEM(submenu, MSG_SELFTEST, lcd_selftest);
  1103. }
  1104. END_MENU();
  1105. }
  1106. /*
  1107. void lcd_mylang_top(int hlaska) {
  1108. lcd.setCursor(0,0);
  1109. lcd.print(" ");
  1110. lcd.setCursor(0,0);
  1111. lcd_printPGM(MSG_ALL[hlaska-1][LANGUAGE_SELECT]);
  1112. }
  1113. void lcd_mylang_drawmenu(int cursor) {
  1114. int first = 0;
  1115. if (cursor>2) first = cursor-2;
  1116. if (cursor==LANG_NUM) first = LANG_NUM-3;
  1117. lcd.setCursor(0, 1);
  1118. lcd.print(" ");
  1119. lcd.setCursor(1, 1);
  1120. lcd_printPGM(MSG_ALL[first][LANGUAGE_NAME]);
  1121. lcd.setCursor(0, 2);
  1122. lcd.print(" ");
  1123. lcd.setCursor(1, 2);
  1124. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  1125. lcd.setCursor(0, 3);
  1126. lcd.print(" ");
  1127. lcd.setCursor(1, 3);
  1128. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  1129. if (cursor==1) lcd.setCursor(0, 1);
  1130. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  1131. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  1132. lcd.print(">");
  1133. if (cursor<LANG_NUM-1) {
  1134. lcd.setCursor(19,3);
  1135. lcd.print("\x01");
  1136. }
  1137. if (cursor>2) {
  1138. lcd.setCursor(19,1);
  1139. lcd.print("^");
  1140. }
  1141. }
  1142. */
  1143. void lcd_mylang_drawmenu(int cursor) {
  1144. int first = 0;
  1145. if (cursor>3) first = cursor-3;
  1146. if (cursor==LANG_NUM && LANG_NUM>4) first = LANG_NUM-4;
  1147. if (cursor==LANG_NUM && LANG_NUM==4) first = LANG_NUM-4;
  1148. lcd.setCursor(0, 0);
  1149. lcd.print(" ");
  1150. lcd.setCursor(1, 0);
  1151. lcd_printPGM(MSG_ALL[first+0][LANGUAGE_NAME]);
  1152. lcd.setCursor(0, 1);
  1153. lcd.print(" ");
  1154. lcd.setCursor(1, 1);
  1155. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  1156. lcd.setCursor(0, 2);
  1157. lcd.print(" ");
  1158. if (LANG_NUM > 2){
  1159. lcd.setCursor(1, 2);
  1160. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  1161. }
  1162. lcd.setCursor(0, 3);
  1163. lcd.print(" ");
  1164. if (LANG_NUM>3) {
  1165. lcd.setCursor(1, 3);
  1166. lcd_printPGM(MSG_ALL[first+3][LANGUAGE_NAME]);
  1167. }
  1168. if (cursor==1) lcd.setCursor(0, 0);
  1169. if (cursor==2) lcd.setCursor(0, 1);
  1170. if (cursor>2) lcd.setCursor(0, 2);
  1171. if (cursor==LANG_NUM && LANG_NUM>3) lcd.setCursor(0, 3);
  1172. lcd.print(">");
  1173. if (cursor<LANG_NUM-1 && LANG_NUM>4) {
  1174. lcd.setCursor(19,3);
  1175. lcd.print("\x01");
  1176. }
  1177. if (cursor>3 && LANG_NUM>4) {
  1178. lcd.setCursor(19,0);
  1179. lcd.print("^");
  1180. }
  1181. }
  1182. void lcd_set_custom_characters_arrows();
  1183. void lcd_set_custom_characters_degree();
  1184. void lcd_mylang_drawcursor(int cursor) {
  1185. if (cursor==1) lcd.setCursor(0, 1);
  1186. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  1187. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  1188. lcd.print(">");
  1189. }
  1190. void lcd_mylang() {
  1191. int enc_dif = 0;
  1192. int cursor_pos = 1;
  1193. lang_selected=255;
  1194. int hlaska=1;
  1195. int counter=0;
  1196. lcd_set_custom_characters_arrows();
  1197. lcd_implementation_clear();
  1198. //lcd_mylang_top(hlaska);
  1199. lcd_mylang_drawmenu(cursor_pos);
  1200. enc_dif = encoderDiff;
  1201. while ( (lang_selected == 255) && (MYSERIAL.available() < 2) ) {
  1202. manage_heater();
  1203. manage_inactivity(true);
  1204. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1205. //if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1206. if (enc_dif > encoderDiff ) {
  1207. cursor_pos --;
  1208. }
  1209. if (enc_dif < encoderDiff ) {
  1210. cursor_pos ++;
  1211. }
  1212. if (cursor_pos > LANG_NUM) {
  1213. cursor_pos = LANG_NUM;
  1214. }
  1215. if (cursor_pos < 1) {
  1216. cursor_pos = 1;
  1217. }
  1218. lcd_mylang_drawmenu(cursor_pos);
  1219. enc_dif = encoderDiff;
  1220. delay(100);
  1221. //}
  1222. } else delay(20);
  1223. if (lcd_clicked()) {
  1224. lcd_set_lang(cursor_pos-1);
  1225. delay(500);
  1226. }
  1227. /*
  1228. if (++counter == 80) {
  1229. hlaska++;
  1230. if(hlaska>LANG_NUM) hlaska=1;
  1231. lcd_mylang_top(hlaska);
  1232. lcd_mylang_drawcursor(cursor_pos);
  1233. counter=0;
  1234. }
  1235. */
  1236. };
  1237. if(MYSERIAL.available() > 1){
  1238. lang_selected = 0;
  1239. firstrun = 0;
  1240. }
  1241. lcd_set_custom_characters_degree();
  1242. lcd_implementation_clear();
  1243. lcd_return_to_status();
  1244. }
  1245. static void lcd_main_menu()
  1246. {
  1247. SDscrool = 0;
  1248. /*
  1249. if (langsel == 1)
  1250. {
  1251. lcd_goto_menu(lcd_language_menu);
  1252. }
  1253. */
  1254. START_MENU();
  1255. // Majkl superawesome menu
  1256. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  1257. if ( ( IS_SD_PRINTING || is_usb_printing ) && (current_position[Z_AXIS] < 0.5) )
  1258. {
  1259. EEPROM_read_B(EEPROM_BABYSTEP_X, &babystepMem[0]);
  1260. EEPROM_read_B(EEPROM_BABYSTEP_Y, &babystepMem[1]);
  1261. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepMem[2]);
  1262. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  1263. }
  1264. if ( movesplanned() || IS_SD_PRINTING || is_usb_printing )
  1265. {
  1266. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  1267. } else
  1268. {
  1269. MENU_ITEM(submenu, MSG_PREHEAT, lcd_preheat_menu);
  1270. }
  1271. #ifdef SDSUPPORT
  1272. if (card.cardOK)
  1273. {
  1274. if (card.isFileOpen())
  1275. {
  1276. if (card.sdprinting)
  1277. {
  1278. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  1279. }
  1280. else
  1281. {
  1282. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  1283. }
  1284. MENU_ITEM(submenu, MSG_STOP_PRINT, lcd_sdcard_stop);
  1285. }
  1286. else
  1287. {
  1288. if (!is_usb_printing)
  1289. {
  1290. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  1291. }
  1292. #if SDCARDDETECT < 1
  1293. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  1294. #endif
  1295. }
  1296. } else
  1297. {
  1298. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  1299. #if SDCARDDETECT < 1
  1300. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  1301. #endif
  1302. }
  1303. #endif
  1304. if (IS_SD_PRINTING || is_usb_printing)
  1305. {
  1306. }
  1307. else
  1308. {
  1309. MENU_ITEM(function, MSG_LOAD_FILAMENT, lcd_LoadFilament);
  1310. MENU_ITEM(function, MSG_UNLOAD_FILAMENT, lcd_unLoadFilament);
  1311. MENU_ITEM(submenu, MSG_SETTINGS, lcd_settings_menu);
  1312. }
  1313. if (!is_usb_printing)
  1314. {
  1315. MENU_ITEM(submenu, MSG_STATISTICS, lcd_menu_statistics);
  1316. }
  1317. MENU_ITEM(submenu, MSG_SUPPORT, lcd_support_menu);
  1318. END_MENU();
  1319. }
  1320. #ifdef SDSUPPORT
  1321. static void lcd_autostart_sd()
  1322. {
  1323. card.lastnr = 0;
  1324. card.setroot();
  1325. card.checkautostart(true);
  1326. }
  1327. #endif
  1328. static void lcd_silent_mode_set_tune() {
  1329. SilentModeMenu = !SilentModeMenu;
  1330. EEPROM_save(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  1331. digipot_init();
  1332. lcd_goto_menu(lcd_tune_menu, 9);
  1333. }
  1334. static void lcd_tune_menu()
  1335. {
  1336. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  1337. START_MENU();
  1338. MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1
  1339. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2
  1340. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  1341. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  1342. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5
  1343. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6
  1344. #ifdef FILAMENTCHANGEENABLE
  1345. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));//7
  1346. #endif
  1347. if (SilentModeMenu == 0) {
  1348. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set_tune);
  1349. } else {
  1350. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set_tune);
  1351. }
  1352. END_MENU();
  1353. }
  1354. static void lcd_move_menu_01mm()
  1355. {
  1356. move_menu_scale = 0.1;
  1357. lcd_move_menu_axis();
  1358. }
  1359. static void lcd_control_temperature_menu()
  1360. {
  1361. #ifdef PIDTEMP
  1362. // set up temp variables - undo the default scaling
  1363. raw_Ki = unscalePID_i(Ki);
  1364. raw_Kd = unscalePID_d(Kd);
  1365. #endif
  1366. START_MENU();
  1367. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  1368. //MENU_ITEM(back, MSG_CONTROL, lcd_control_menu);
  1369. #if TEMP_SENSOR_0 != 0
  1370. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  1371. #endif
  1372. #if TEMP_SENSOR_1 != 0
  1373. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  1374. #endif
  1375. #if TEMP_SENSOR_2 != 0
  1376. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  1377. #endif
  1378. #if TEMP_SENSOR_BED != 0
  1379. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 3);
  1380. #endif
  1381. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  1382. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  1383. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  1384. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  1385. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  1386. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  1387. #endif
  1388. END_MENU();
  1389. }
  1390. #if SDCARDDETECT == -1
  1391. static void lcd_sd_refresh()
  1392. {
  1393. card.initsd();
  1394. currentMenuViewOffset = 0;
  1395. }
  1396. #endif
  1397. static void lcd_sd_updir()
  1398. {
  1399. SDscrool = 0;
  1400. card.updir();
  1401. currentMenuViewOffset = 0;
  1402. }
  1403. void lcd_sdcard_stop()
  1404. {
  1405. lcd.setCursor(0, 0);
  1406. lcd_printPGM(MSG_STOP_PRINT);
  1407. lcd.setCursor(2, 2);
  1408. lcd_printPGM(MSG_NO);
  1409. lcd.setCursor(2, 3);
  1410. lcd_printPGM(MSG_YES);
  1411. lcd.setCursor(0, 2); lcd.print(" ");
  1412. lcd.setCursor(0, 3); lcd.print(" ");
  1413. if ((int32_t)encoderPosition > 2) { encoderPosition = 2; }
  1414. if ((int32_t)encoderPosition < 1) { encoderPosition = 1; }
  1415. lcd.setCursor(0, 1 + encoderPosition);
  1416. lcd.print(">");
  1417. if (lcd_clicked())
  1418. {
  1419. if ((int32_t)encoderPosition == 1)
  1420. {
  1421. lcd_return_to_status();
  1422. }
  1423. if ((int32_t)encoderPosition == 2)
  1424. {
  1425. cancel_heatup = true;
  1426. quickStop();
  1427. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  1428. card.sdprinting = false;
  1429. card.closefile();
  1430. stoptime = millis();
  1431. unsigned long t = (stoptime - starttime) / 1000;
  1432. save_statistics(total_filament_used, t);
  1433. lcd_return_to_status();
  1434. lcd_ignore_click(true);
  1435. lcd_commands_type = 2;
  1436. }
  1437. }
  1438. }
  1439. void lcd_sdcard_menu()
  1440. {
  1441. int tempScrool = 0;
  1442. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  1443. //delay(100);
  1444. return; // nothing to do (so don't thrash the SD card)
  1445. uint16_t fileCnt = card.getnrfilenames();
  1446. START_MENU();
  1447. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1448. card.getWorkDirName();
  1449. if (card.filename[0] == '/')
  1450. {
  1451. #if SDCARDDETECT == -1
  1452. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  1453. #endif
  1454. } else {
  1455. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  1456. }
  1457. for (uint16_t i = 0; i < fileCnt; i++)
  1458. {
  1459. if (_menuItemNr == _lineNr)
  1460. {
  1461. #ifndef SDCARD_RATHERRECENTFIRST
  1462. card.getfilename(i);
  1463. #else
  1464. card.getfilename(fileCnt - 1 - i);
  1465. #endif
  1466. if (card.filenameIsDir)
  1467. {
  1468. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  1469. } else {
  1470. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  1471. }
  1472. } else {
  1473. MENU_ITEM_DUMMY();
  1474. }
  1475. }
  1476. END_MENU();
  1477. }
  1478. #define menu_edit_type(_type, _name, _strFunc, scale) \
  1479. void menu_edit_ ## _name () \
  1480. { \
  1481. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  1482. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  1483. if (lcdDrawUpdate) \
  1484. lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) / scale)); \
  1485. if (LCD_CLICKED) \
  1486. { \
  1487. *((_type*)editValue) = ((_type)((int32_t)encoderPosition + minEditValue)) / scale; \
  1488. lcd_goto_menu(prevMenu, prevEncoderPosition); \
  1489. } \
  1490. } \
  1491. void menu_edit_callback_ ## _name () { \
  1492. menu_edit_ ## _name (); \
  1493. if (LCD_CLICKED) (*callbackFunc)(); \
  1494. } \
  1495. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  1496. { \
  1497. prevMenu = currentMenu; \
  1498. prevEncoderPosition = encoderPosition; \
  1499. \
  1500. lcdDrawUpdate = 2; \
  1501. currentMenu = menu_edit_ ## _name; \
  1502. \
  1503. editLabel = pstr; \
  1504. editValue = ptr; \
  1505. minEditValue = minValue * scale; \
  1506. maxEditValue = maxValue * scale - minEditValue; \
  1507. encoderPosition = (*ptr) * scale - minEditValue; \
  1508. }\
  1509. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  1510. { \
  1511. prevMenu = currentMenu; \
  1512. prevEncoderPosition = encoderPosition; \
  1513. \
  1514. lcdDrawUpdate = 2; \
  1515. currentMenu = menu_edit_callback_ ## _name; \
  1516. \
  1517. editLabel = pstr; \
  1518. editValue = ptr; \
  1519. minEditValue = minValue * scale; \
  1520. maxEditValue = maxValue * scale - minEditValue; \
  1521. encoderPosition = (*ptr) * scale - minEditValue; \
  1522. callbackFunc = callback;\
  1523. }
  1524. menu_edit_type(int, int3, itostr3, 1)
  1525. menu_edit_type(float, float3, ftostr3, 1)
  1526. menu_edit_type(float, float32, ftostr32, 100)
  1527. menu_edit_type(float, float43, ftostr43, 1000)
  1528. menu_edit_type(float, float5, ftostr5, 0.01)
  1529. menu_edit_type(float, float51, ftostr51, 10)
  1530. menu_edit_type(float, float52, ftostr52, 100)
  1531. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  1532. static void lcd_selftest()
  1533. {
  1534. int _progress = 0;
  1535. bool _result = false;
  1536. _progress = lcd_selftest_screen(-1, _progress, 4, true, 2000);
  1537. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  1538. _result = lcd_selfcheck_endstops();
  1539. if (_result)
  1540. {
  1541. _progress = lcd_selftest_screen(1, _progress, 3, true, 1000);
  1542. _result = lcd_selfcheck_check_heater(false);
  1543. }
  1544. if (_result)
  1545. {
  1546. _progress = lcd_selftest_screen(2, _progress, 3, true, 2000);
  1547. _result = lcd_selfcheck_axis(0, X_MAX_POS);
  1548. }
  1549. if (_result)
  1550. {
  1551. _progress = lcd_selftest_screen(3, _progress, 3, true, 1500);
  1552. _result = lcd_selfcheck_axis(1, Y_MAX_POS);
  1553. }
  1554. if (_result)
  1555. {
  1556. current_position[X_AXIS] = current_position[X_AXIS] - 3;
  1557. current_position[Y_AXIS] = current_position[Y_AXIS] - 14;
  1558. _progress = lcd_selftest_screen(4, _progress, 3, true, 1500);
  1559. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  1560. }
  1561. if (_result)
  1562. {
  1563. _progress = lcd_selftest_screen(5, _progress, 3, true, 2000);
  1564. _result = lcd_selfcheck_check_heater(true);
  1565. }
  1566. if (_result)
  1567. {
  1568. _progress = lcd_selftest_screen(6, _progress, 3, true, 5000);
  1569. }
  1570. else
  1571. {
  1572. _progress = lcd_selftest_screen(7, _progress, 3, true, 5000);
  1573. }
  1574. lcd_implementation_clear();
  1575. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  1576. if (_result)
  1577. {
  1578. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_OK);
  1579. }
  1580. else
  1581. {
  1582. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  1583. }
  1584. }
  1585. static bool lcd_selfcheck_endstops()
  1586. {
  1587. bool _result = true;
  1588. if (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1 || READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1 || READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1)
  1589. {
  1590. current_position[0] = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? current_position[0] = current_position[0] + 10 : current_position[0];
  1591. current_position[1] = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? current_position[1] = current_position[1] + 10 : current_position[1];
  1592. current_position[2] = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? current_position[2] = current_position[2] + 10 : current_position[2];
  1593. }
  1594. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], manual_feedrate[0] / 60, active_extruder);
  1595. delay(500);
  1596. if (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1 || READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1 || READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1)
  1597. {
  1598. _result = false;
  1599. String _error = String((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? "X" : "") +
  1600. String((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? "Y" : "") +
  1601. String((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? "Z" : "");
  1602. lcd_selftest_error(3, _error.c_str(), "");
  1603. }
  1604. manage_heater();
  1605. manage_inactivity();
  1606. return _result;
  1607. }
  1608. static bool lcd_selfcheck_axis(int _axis, int _travel)
  1609. {
  1610. bool _stepdone = false;
  1611. bool _stepresult = false;
  1612. int _progress = 0;
  1613. int _travel_done = 0;
  1614. int _err_endstop = 0;
  1615. int _lcd_refresh = 0;
  1616. _travel = _travel + (_travel / 10);
  1617. do {
  1618. if (_axis == 2)
  1619. {
  1620. current_position[_axis] = current_position[_axis] - 1;
  1621. }
  1622. else
  1623. {
  1624. current_position[_axis] = current_position[_axis] - 3;
  1625. }
  1626. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  1627. st_synchronize();
  1628. if (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1 || READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1 || READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1)
  1629. {
  1630. if (_axis == 0)
  1631. {
  1632. _stepresult = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  1633. _err_endstop = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? 1 : 2;
  1634. disable_x();
  1635. }
  1636. if (_axis == 1)
  1637. {
  1638. _stepresult = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  1639. _err_endstop = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? 0 : 2;
  1640. disable_y();
  1641. }
  1642. if (_axis == 2)
  1643. {
  1644. _stepresult = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  1645. _err_endstop = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? 0 : 1;
  1646. disable_z();
  1647. }
  1648. _stepdone = true;
  1649. }
  1650. if (_lcd_refresh < 6)
  1651. {
  1652. _lcd_refresh++;
  1653. }
  1654. else
  1655. {
  1656. _progress = lcd_selftest_screen(2 + _axis, _progress, 3, false, 0);
  1657. _lcd_refresh = 0;
  1658. }
  1659. manage_heater();
  1660. manage_inactivity();
  1661. delay(100);
  1662. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  1663. } while (!_stepdone);
  1664. current_position[_axis] = current_position[_axis] + 15;
  1665. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  1666. if (!_stepresult)
  1667. {
  1668. const char *_error_1;
  1669. const char *_error_2;
  1670. if (_axis == X_AXIS) _error_1 = "X";
  1671. if (_axis == Y_AXIS) _error_1 = "Y";
  1672. if (_axis == Z_AXIS) _error_1 = "Z";
  1673. if (_err_endstop == 0) _error_2 = "X";
  1674. if (_err_endstop == 1) _error_2 = "Y";
  1675. if (_err_endstop == 2) _error_2 = "Z";
  1676. if (_travel_done >= _travel)
  1677. {
  1678. lcd_selftest_error(5, _error_1, _error_2);
  1679. }
  1680. else
  1681. {
  1682. lcd_selftest_error(4, _error_1, _error_2);
  1683. }
  1684. }
  1685. return _stepresult;
  1686. }
  1687. static bool lcd_selfcheck_check_heater(bool _isbed)
  1688. {
  1689. int _counter = 0;
  1690. int _progress = 0;
  1691. bool _stepresult = false;
  1692. bool _docycle = true;
  1693. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  1694. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  1695. int _cycles = (_isbed) ? 120 : 30;
  1696. target_temperature[0] = (_isbed) ? 0 : 100;
  1697. target_temperature_bed = (_isbed) ? 100 : 0;
  1698. manage_heater();
  1699. manage_inactivity();
  1700. do {
  1701. _counter++;
  1702. (_counter < _cycles) ? _docycle = true : _docycle = false;
  1703. manage_heater();
  1704. manage_inactivity();
  1705. _progress = (_isbed) ? lcd_selftest_screen(5, _progress, 2, false, 400) : lcd_selftest_screen(1, _progress, 2, false, 400);
  1706. } while (_docycle);
  1707. target_temperature[0] = 0;
  1708. target_temperature_bed = 0;
  1709. manage_heater();
  1710. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  1711. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  1712. if (_opposite_result < (_isbed) ? 10 : 3)
  1713. {
  1714. if (_checked_result >= (_isbed) ? 3 : 10)
  1715. {
  1716. _stepresult = true;
  1717. }
  1718. else
  1719. {
  1720. lcd_selftest_error(1, "", "");
  1721. }
  1722. }
  1723. else
  1724. {
  1725. lcd_selftest_error(2, "", "");
  1726. }
  1727. manage_heater();
  1728. manage_inactivity();
  1729. return _stepresult;
  1730. }
  1731. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  1732. {
  1733. lcd_implementation_quick_feedback();
  1734. target_temperature[0] = 0;
  1735. target_temperature_bed = 0;
  1736. manage_heater();
  1737. manage_inactivity();
  1738. lcd_implementation_clear();
  1739. lcd.setCursor(0, 0);
  1740. lcd_printPGM(MSG_SELFTEST_ERROR);
  1741. lcd.setCursor(0, 1);
  1742. lcd_printPGM(MSG_SELFTEST_PLEASECHECK);
  1743. switch (_error_no)
  1744. {
  1745. case 1:
  1746. lcd.setCursor(0, 2);
  1747. lcd_printPGM(MSG_SELFTEST_HEATERTHERMISTOR);
  1748. lcd.setCursor(0, 3);
  1749. lcd_printPGM(MSG_SELFTEST_NOTCONNECTED);
  1750. break;
  1751. case 2:
  1752. lcd.setCursor(0, 2);
  1753. lcd_printPGM(MSG_SELFTEST_BEDHEATER);
  1754. lcd.setCursor(0, 3);
  1755. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  1756. break;
  1757. case 3:
  1758. lcd.setCursor(0, 2);
  1759. lcd_printPGM(MSG_SELFTEST_ENDSTOPS);
  1760. lcd.setCursor(0, 3);
  1761. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  1762. lcd.setCursor(17, 3);
  1763. lcd.print(_error_1);
  1764. break;
  1765. case 4:
  1766. lcd.setCursor(0, 2);
  1767. lcd_printPGM(MSG_SELFTEST_MOTOR);
  1768. lcd.setCursor(18, 2);
  1769. lcd.print(_error_1);
  1770. lcd.setCursor(0, 3);
  1771. lcd_printPGM(MSG_SELFTEST_ENDSTOP);
  1772. lcd.setCursor(18, 3);
  1773. lcd.print(_error_2);
  1774. break;
  1775. case 5:
  1776. lcd.setCursor(0, 2);
  1777. lcd_printPGM(MSG_SELFTEST_ENDSTOP_NOTHIT);
  1778. lcd.setCursor(0, 3);
  1779. lcd_printPGM(MSG_SELFTEST_MOTOR);
  1780. lcd.setCursor(18, 3);
  1781. lcd.print(_error_1);
  1782. break;
  1783. }
  1784. delay(1000);
  1785. lcd_implementation_quick_feedback();
  1786. do {
  1787. delay(100);
  1788. manage_heater();
  1789. manage_inactivity();
  1790. } while (!lcd_clicked());
  1791. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  1792. lcd_return_to_status();
  1793. }
  1794. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  1795. {
  1796. lcd_next_update_millis = millis() + (LCD_UPDATE_INTERVAL * 10000);
  1797. int _step_block = 0;
  1798. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  1799. if (_clear) lcd_implementation_clear();
  1800. lcd.setCursor(0, 0);
  1801. if (_step == -1) lcd_printPGM(MSG_SELFTEST_START);
  1802. if (_step == 0) lcd_printPGM(MSG_SELFTEST_CHECK_ENDSTOPS);
  1803. if (_step == 1) lcd_printPGM(MSG_SELFTEST_CHECK_HOTEND);
  1804. if (_step == 2) lcd_printPGM(MSG_SELFTEST_CHECK_X);
  1805. if (_step == 3) lcd_printPGM(MSG_SELFTEST_CHECK_Y);
  1806. if (_step == 4) lcd_printPGM(MSG_SELFTEST_CHECK_Z);
  1807. if (_step == 5) lcd_printPGM(MSG_SELFTEST_CHECK_BED);
  1808. if (_step == 6) lcd_printPGM(MSG_SELFTEST_CHECK_ALLCORRECT);
  1809. if (_step == 7) lcd_printPGM(MSG_SELFTEST_FAILED);
  1810. lcd.setCursor(0, 1);
  1811. lcd.print("--------------------");
  1812. _step_block = 1;
  1813. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  1814. _step_block = 2;
  1815. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  1816. _step_block = 3;
  1817. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  1818. _step_block = 4;
  1819. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  1820. _step_block = 5;
  1821. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  1822. if (_delay > 0) delay(_delay);
  1823. _progress++;
  1824. return (_progress > _progress_scale * 2) ? 0 : _progress;
  1825. }
  1826. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  1827. {
  1828. lcd.setCursor(_col, _row);
  1829. switch (_state)
  1830. {
  1831. case 1:
  1832. lcd.print(_name);
  1833. lcd.setCursor(_col + strlen(_name), _row);
  1834. lcd.print(":");
  1835. lcd.setCursor(_col + strlen(_name) + 1, _row);
  1836. lcd.print(_indicator);
  1837. break;
  1838. case 2:
  1839. lcd.print(_name);
  1840. lcd.setCursor(_col + strlen(_name), _row);
  1841. lcd.print(":");
  1842. lcd.setCursor(_col + strlen(_name) + 1, _row);
  1843. lcd.print("OK");
  1844. break;
  1845. default:
  1846. lcd.print(_name);
  1847. }
  1848. }
  1849. /** End of menus **/
  1850. static void lcd_quick_feedback()
  1851. {
  1852. lcdDrawUpdate = 2;
  1853. blocking_enc = millis() + 500;
  1854. lcd_implementation_quick_feedback();
  1855. }
  1856. /** Menu action functions **/
  1857. static void menu_action_back(menuFunc_t data) {
  1858. lcd_goto_menu(data);
  1859. }
  1860. static void menu_action_submenu(menuFunc_t data) {
  1861. lcd_goto_menu(data);
  1862. }
  1863. static void menu_action_gcode(const char* pgcode) {
  1864. enquecommand_P(pgcode);
  1865. }
  1866. static void menu_action_setlang(unsigned char lang) {
  1867. lcd_set_lang(lang);
  1868. }
  1869. static void menu_action_function(menuFunc_t data) {
  1870. (*data)();
  1871. }
  1872. static void menu_action_sdfile(const char* filename, char* longFilename)
  1873. {
  1874. char cmd[30];
  1875. char* c;
  1876. sprintf_P(cmd, PSTR("M23 %s"), filename);
  1877. for (c = &cmd[4]; *c; c++)
  1878. *c = tolower(*c);
  1879. enquecommand(cmd);
  1880. enquecommand_P(PSTR("M24"));
  1881. lcd_return_to_status();
  1882. }
  1883. static void menu_action_sddirectory(const char* filename, char* longFilename)
  1884. {
  1885. card.chdir(filename);
  1886. encoderPosition = 0;
  1887. }
  1888. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  1889. {
  1890. *ptr = !(*ptr);
  1891. }
  1892. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  1893. {
  1894. menu_action_setting_edit_bool(pstr, ptr);
  1895. (*callback)();
  1896. }
  1897. #endif//ULTIPANEL
  1898. /** LCD API **/
  1899. void lcd_init()
  1900. {
  1901. lcd_implementation_init();
  1902. #ifdef NEWPANEL
  1903. SET_INPUT(BTN_EN1);
  1904. SET_INPUT(BTN_EN2);
  1905. WRITE(BTN_EN1, HIGH);
  1906. WRITE(BTN_EN2, HIGH);
  1907. #if BTN_ENC > 0
  1908. SET_INPUT(BTN_ENC);
  1909. WRITE(BTN_ENC, HIGH);
  1910. #endif
  1911. #ifdef REPRAPWORLD_KEYPAD
  1912. pinMode(SHIFT_CLK, OUTPUT);
  1913. pinMode(SHIFT_LD, OUTPUT);
  1914. pinMode(SHIFT_OUT, INPUT);
  1915. WRITE(SHIFT_OUT, HIGH);
  1916. WRITE(SHIFT_LD, HIGH);
  1917. #endif
  1918. #else // Not NEWPANEL
  1919. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  1920. pinMode (SR_DATA_PIN, OUTPUT);
  1921. pinMode (SR_CLK_PIN, OUTPUT);
  1922. #elif defined(SHIFT_CLK)
  1923. pinMode(SHIFT_CLK, OUTPUT);
  1924. pinMode(SHIFT_LD, OUTPUT);
  1925. pinMode(SHIFT_EN, OUTPUT);
  1926. pinMode(SHIFT_OUT, INPUT);
  1927. WRITE(SHIFT_OUT, HIGH);
  1928. WRITE(SHIFT_LD, HIGH);
  1929. WRITE(SHIFT_EN, LOW);
  1930. #else
  1931. #ifdef ULTIPANEL
  1932. #error ULTIPANEL requires an encoder
  1933. #endif
  1934. #endif // SR_LCD_2W_NL
  1935. #endif//!NEWPANEL
  1936. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  1937. pinMode(SDCARDDETECT, INPUT);
  1938. WRITE(SDCARDDETECT, HIGH);
  1939. lcd_oldcardstatus = IS_SD_INSERTED;
  1940. #endif//(SDCARDDETECT > 0)
  1941. #ifdef LCD_HAS_SLOW_BUTTONS
  1942. slow_buttons = 0;
  1943. #endif
  1944. lcd_buttons_update();
  1945. #ifdef ULTIPANEL
  1946. encoderDiff = 0;
  1947. #endif
  1948. }
  1949. //#include <avr/pgmspace.h>
  1950. void lcd_update()
  1951. {
  1952. static unsigned long timeoutToStatus = 0;
  1953. #ifdef LCD_HAS_SLOW_BUTTONS
  1954. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  1955. #endif
  1956. lcd_buttons_update();
  1957. #if (SDCARDDETECT > 0)
  1958. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  1959. {
  1960. lcdDrawUpdate = 2;
  1961. lcd_oldcardstatus = IS_SD_INSERTED;
  1962. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  1963. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  1964. currentMenu == lcd_status_screen
  1965. #endif
  1966. );
  1967. if (lcd_oldcardstatus)
  1968. {
  1969. card.initsd();
  1970. LCD_MESSAGERPGM(MSG_SD_INSERTED);
  1971. }
  1972. else
  1973. {
  1974. card.release();
  1975. LCD_MESSAGERPGM(MSG_SD_REMOVED);
  1976. }
  1977. }
  1978. #endif//CARDINSERTED
  1979. if (lcd_next_update_millis < millis())
  1980. {
  1981. #ifdef ULTIPANEL
  1982. #ifdef REPRAPWORLD_KEYPAD
  1983. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  1984. reprapworld_keypad_move_z_up();
  1985. }
  1986. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  1987. reprapworld_keypad_move_z_down();
  1988. }
  1989. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  1990. reprapworld_keypad_move_x_left();
  1991. }
  1992. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  1993. reprapworld_keypad_move_x_right();
  1994. }
  1995. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  1996. reprapworld_keypad_move_y_down();
  1997. }
  1998. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  1999. reprapworld_keypad_move_y_up();
  2000. }
  2001. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  2002. reprapworld_keypad_move_home();
  2003. }
  2004. #endif
  2005. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  2006. {
  2007. lcdDrawUpdate = 1;
  2008. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  2009. encoderDiff = 0;
  2010. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  2011. }
  2012. if (LCD_CLICKED)
  2013. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  2014. #endif//ULTIPANEL
  2015. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  2016. blink++; // Variable for fan animation and alive dot
  2017. u8g.firstPage();
  2018. do
  2019. {
  2020. u8g.setFont(u8g_font_6x10_marlin);
  2021. u8g.setPrintPos(125, 0);
  2022. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  2023. u8g.drawPixel(127, 63); // draw alive dot
  2024. u8g.setColorIndex(1); // black on white
  2025. (*currentMenu)();
  2026. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  2027. } while (u8g.nextPage());
  2028. #else
  2029. (*currentMenu)();
  2030. #endif
  2031. #ifdef LCD_HAS_STATUS_INDICATORS
  2032. lcd_implementation_update_indicators();
  2033. #endif
  2034. #ifdef ULTIPANEL
  2035. if (timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  2036. {
  2037. lcd_return_to_status();
  2038. lcdDrawUpdate = 2;
  2039. }
  2040. #endif//ULTIPANEL
  2041. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  2042. if (lcdDrawUpdate) lcdDrawUpdate--;
  2043. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  2044. }
  2045. }
  2046. void lcd_ignore_click(bool b)
  2047. {
  2048. ignore_click = b;
  2049. wait_for_unclick = false;
  2050. }
  2051. void lcd_finishstatus() {
  2052. int len = strlen(lcd_status_message);
  2053. if (len > 0) {
  2054. while (len < LCD_WIDTH) {
  2055. lcd_status_message[len++] = ' ';
  2056. }
  2057. }
  2058. lcd_status_message[LCD_WIDTH] = '\0';
  2059. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  2060. #if PROGRESS_MSG_EXPIRE > 0
  2061. messageTick =
  2062. #endif
  2063. progressBarTick = millis();
  2064. #endif
  2065. lcdDrawUpdate = 2;
  2066. #ifdef FILAMENT_LCD_DISPLAY
  2067. message_millis = millis(); //get status message to show up for a while
  2068. #endif
  2069. }
  2070. void lcd_setstatus(const char* message)
  2071. {
  2072. if (lcd_status_message_level > 0)
  2073. return;
  2074. strncpy(lcd_status_message, message, LCD_WIDTH);
  2075. lcd_finishstatus();
  2076. }
  2077. void lcd_setstatuspgm(const char* message)
  2078. {
  2079. if (lcd_status_message_level > 0)
  2080. return;
  2081. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  2082. lcd_finishstatus();
  2083. }
  2084. void lcd_setalertstatuspgm(const char* message)
  2085. {
  2086. lcd_setstatuspgm(message);
  2087. lcd_status_message_level = 1;
  2088. #ifdef ULTIPANEL
  2089. lcd_return_to_status();
  2090. #endif//ULTIPANEL
  2091. }
  2092. void lcd_reset_alert_level()
  2093. {
  2094. lcd_status_message_level = 0;
  2095. }
  2096. #ifdef DOGLCD
  2097. void lcd_setcontrast(uint8_t value)
  2098. {
  2099. lcd_contrast = value & 63;
  2100. u8g.setContrast(lcd_contrast);
  2101. }
  2102. #endif
  2103. #ifdef ULTIPANEL
  2104. /* Warning: This function is called from interrupt context */
  2105. void lcd_buttons_update()
  2106. {
  2107. #ifdef NEWPANEL
  2108. uint8_t newbutton = 0;
  2109. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  2110. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  2111. #if BTN_ENC > 0
  2112. if ((blocking_enc < millis()) && (READ(BTN_ENC) == 0))
  2113. newbutton |= EN_C;
  2114. #endif
  2115. buttons = newbutton;
  2116. #ifdef LCD_HAS_SLOW_BUTTONS
  2117. buttons |= slow_buttons;
  2118. #endif
  2119. #ifdef REPRAPWORLD_KEYPAD
  2120. // for the reprapworld_keypad
  2121. uint8_t newbutton_reprapworld_keypad = 0;
  2122. WRITE(SHIFT_LD, LOW);
  2123. WRITE(SHIFT_LD, HIGH);
  2124. for (int8_t i = 0; i < 8; i++) {
  2125. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  2126. if (READ(SHIFT_OUT))
  2127. newbutton_reprapworld_keypad |= (1 << 7);
  2128. WRITE(SHIFT_CLK, HIGH);
  2129. WRITE(SHIFT_CLK, LOW);
  2130. }
  2131. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  2132. #endif
  2133. #else //read it from the shift register
  2134. uint8_t newbutton = 0;
  2135. WRITE(SHIFT_LD, LOW);
  2136. WRITE(SHIFT_LD, HIGH);
  2137. unsigned char tmp_buttons = 0;
  2138. for (int8_t i = 0; i < 8; i++)
  2139. {
  2140. newbutton = newbutton >> 1;
  2141. if (READ(SHIFT_OUT))
  2142. newbutton |= (1 << 7);
  2143. WRITE(SHIFT_CLK, HIGH);
  2144. WRITE(SHIFT_CLK, LOW);
  2145. }
  2146. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  2147. #endif//!NEWPANEL
  2148. //manage encoder rotation
  2149. uint8_t enc = 0;
  2150. if (buttons & EN_A) enc |= B01;
  2151. if (buttons & EN_B) enc |= B10;
  2152. if (enc != lastEncoderBits)
  2153. {
  2154. switch (enc)
  2155. {
  2156. case encrot0:
  2157. if (lastEncoderBits == encrot3)
  2158. encoderDiff++;
  2159. else if (lastEncoderBits == encrot1)
  2160. encoderDiff--;
  2161. break;
  2162. case encrot1:
  2163. if (lastEncoderBits == encrot0)
  2164. encoderDiff++;
  2165. else if (lastEncoderBits == encrot2)
  2166. encoderDiff--;
  2167. break;
  2168. case encrot2:
  2169. if (lastEncoderBits == encrot1)
  2170. encoderDiff++;
  2171. else if (lastEncoderBits == encrot3)
  2172. encoderDiff--;
  2173. break;
  2174. case encrot3:
  2175. if (lastEncoderBits == encrot2)
  2176. encoderDiff++;
  2177. else if (lastEncoderBits == encrot0)
  2178. encoderDiff--;
  2179. break;
  2180. }
  2181. }
  2182. lastEncoderBits = enc;
  2183. }
  2184. bool lcd_detected(void)
  2185. {
  2186. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  2187. return lcd.LcdDetected() == 1;
  2188. #else
  2189. return true;
  2190. #endif
  2191. }
  2192. void lcd_buzz(long duration, uint16_t freq)
  2193. {
  2194. #ifdef LCD_USE_I2C_BUZZER
  2195. lcd.buzz(duration, freq);
  2196. #endif
  2197. }
  2198. bool lcd_clicked()
  2199. {
  2200. return LCD_CLICKED;
  2201. }
  2202. #endif//ULTIPANEL
  2203. /********************************/
  2204. /** Float conversion utilities **/
  2205. /********************************/
  2206. // convert float to string with +123.4 format
  2207. char conv[8];
  2208. char *ftostr3(const float &x)
  2209. {
  2210. return itostr3((int)x);
  2211. }
  2212. char *itostr2(const uint8_t &x)
  2213. {
  2214. //sprintf(conv,"%5.1f",x);
  2215. int xx = x;
  2216. conv[0] = (xx / 10) % 10 + '0';
  2217. conv[1] = (xx) % 10 + '0';
  2218. conv[2] = 0;
  2219. return conv;
  2220. }
  2221. // Convert float to string with 123.4 format, dropping sign
  2222. char *ftostr31(const float &x)
  2223. {
  2224. int xx = x * 10;
  2225. conv[0] = (xx >= 0) ? '+' : '-';
  2226. xx = abs(xx);
  2227. conv[1] = (xx / 1000) % 10 + '0';
  2228. conv[2] = (xx / 100) % 10 + '0';
  2229. conv[3] = (xx / 10) % 10 + '0';
  2230. conv[4] = '.';
  2231. conv[5] = (xx) % 10 + '0';
  2232. conv[6] = 0;
  2233. return conv;
  2234. }
  2235. // Convert float to string with 123.4 format
  2236. char *ftostr31ns(const float &x)
  2237. {
  2238. int xx = x * 10;
  2239. //conv[0]=(xx>=0)?'+':'-';
  2240. xx = abs(xx);
  2241. conv[0] = (xx / 1000) % 10 + '0';
  2242. conv[1] = (xx / 100) % 10 + '0';
  2243. conv[2] = (xx / 10) % 10 + '0';
  2244. conv[3] = '.';
  2245. conv[4] = (xx) % 10 + '0';
  2246. conv[5] = 0;
  2247. return conv;
  2248. }
  2249. char *ftostr32(const float &x)
  2250. {
  2251. long xx = x * 100;
  2252. if (xx >= 0)
  2253. conv[0] = (xx / 10000) % 10 + '0';
  2254. else
  2255. conv[0] = '-';
  2256. xx = abs(xx);
  2257. conv[1] = (xx / 1000) % 10 + '0';
  2258. conv[2] = (xx / 100) % 10 + '0';
  2259. conv[3] = '.';
  2260. conv[4] = (xx / 10) % 10 + '0';
  2261. conv[5] = (xx) % 10 + '0';
  2262. conv[6] = 0;
  2263. return conv;
  2264. }
  2265. //// Convert float to rj string with 123.45 format
  2266. char *ftostr32ns(const float &x) {
  2267. long xx = abs(x);
  2268. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  2269. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  2270. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : '0';
  2271. conv[3] = '.';
  2272. conv[4] = (xx / 10) % 10 + '0';
  2273. conv[5] = xx % 10 + '0';
  2274. return conv;
  2275. }
  2276. // Convert float to string with 1.234 format
  2277. char *ftostr43(const float &x)
  2278. {
  2279. long xx = x * 1000;
  2280. if (xx >= 0)
  2281. conv[0] = (xx / 1000) % 10 + '0';
  2282. else
  2283. conv[0] = '-';
  2284. xx = abs(xx);
  2285. conv[1] = '.';
  2286. conv[2] = (xx / 100) % 10 + '0';
  2287. conv[3] = (xx / 10) % 10 + '0';
  2288. conv[4] = (xx) % 10 + '0';
  2289. conv[5] = 0;
  2290. return conv;
  2291. }
  2292. //Float to string with 1.23 format
  2293. char *ftostr12ns(const float &x)
  2294. {
  2295. long xx = x * 100;
  2296. xx = abs(xx);
  2297. conv[0] = (xx / 100) % 10 + '0';
  2298. conv[1] = '.';
  2299. conv[2] = (xx / 10) % 10 + '0';
  2300. conv[3] = (xx) % 10 + '0';
  2301. conv[4] = 0;
  2302. return conv;
  2303. }
  2304. //Float to string with 1.234 format
  2305. char *ftostr13ns(const float &x)
  2306. {
  2307. long xx = x * 1000;
  2308. if (xx >= 0)
  2309. conv[0] = ' ';
  2310. else
  2311. conv[0] = '-';
  2312. xx = abs(xx);
  2313. conv[1] = (xx / 1000) % 10 + '0';
  2314. conv[2] = '.';
  2315. conv[3] = (xx / 100) % 10 + '0';
  2316. conv[4] = (xx / 10) % 10 + '0';
  2317. conv[5] = (xx) % 10 + '0';
  2318. conv[6] = 0;
  2319. return conv;
  2320. }
  2321. // convert float to space-padded string with -_23.4_ format
  2322. char *ftostr32sp(const float &x) {
  2323. long xx = abs(x * 100);
  2324. uint8_t dig;
  2325. if (x < 0) { // negative val = -_0
  2326. conv[0] = '-';
  2327. dig = (xx / 1000) % 10;
  2328. conv[1] = dig ? '0' + dig : ' ';
  2329. }
  2330. else { // positive val = __0
  2331. dig = (xx / 10000) % 10;
  2332. if (dig) {
  2333. conv[0] = '0' + dig;
  2334. conv[1] = '0' + (xx / 1000) % 10;
  2335. }
  2336. else {
  2337. conv[0] = ' ';
  2338. dig = (xx / 1000) % 10;
  2339. conv[1] = dig ? '0' + dig : ' ';
  2340. }
  2341. }
  2342. conv[2] = '0' + (xx / 100) % 10; // lsd always
  2343. dig = xx % 10;
  2344. if (dig) { // 2 decimal places
  2345. conv[5] = '0' + dig;
  2346. conv[4] = '0' + (xx / 10) % 10;
  2347. conv[3] = '.';
  2348. }
  2349. else { // 1 or 0 decimal place
  2350. dig = (xx / 10) % 10;
  2351. if (dig) {
  2352. conv[4] = '0' + dig;
  2353. conv[3] = '.';
  2354. }
  2355. else {
  2356. conv[3] = conv[4] = ' ';
  2357. }
  2358. conv[5] = ' ';
  2359. }
  2360. conv[6] = '\0';
  2361. return conv;
  2362. }
  2363. char *itostr31(const int &xx)
  2364. {
  2365. conv[0] = (xx >= 0) ? '+' : '-';
  2366. conv[1] = (xx / 1000) % 10 + '0';
  2367. conv[2] = (xx / 100) % 10 + '0';
  2368. conv[3] = (xx / 10) % 10 + '0';
  2369. conv[4] = '.';
  2370. conv[5] = (xx) % 10 + '0';
  2371. conv[6] = 0;
  2372. return conv;
  2373. }
  2374. // Convert int to rj string with 123 or -12 format
  2375. char *itostr3(const int &x)
  2376. {
  2377. int xx = x;
  2378. if (xx < 0) {
  2379. conv[0] = '-';
  2380. xx = -xx;
  2381. } else if (xx >= 100)
  2382. conv[0] = (xx / 100) % 10 + '0';
  2383. else
  2384. conv[0] = ' ';
  2385. if (xx >= 10)
  2386. conv[1] = (xx / 10) % 10 + '0';
  2387. else
  2388. conv[1] = ' ';
  2389. conv[2] = (xx) % 10 + '0';
  2390. conv[3] = 0;
  2391. return conv;
  2392. }
  2393. // Convert int to lj string with 123 format
  2394. char *itostr3left(const int &xx)
  2395. {
  2396. if (xx >= 100)
  2397. {
  2398. conv[0] = (xx / 100) % 10 + '0';
  2399. conv[1] = (xx / 10) % 10 + '0';
  2400. conv[2] = (xx) % 10 + '0';
  2401. conv[3] = 0;
  2402. }
  2403. else if (xx >= 10)
  2404. {
  2405. conv[0] = (xx / 10) % 10 + '0';
  2406. conv[1] = (xx) % 10 + '0';
  2407. conv[2] = 0;
  2408. }
  2409. else
  2410. {
  2411. conv[0] = (xx) % 10 + '0';
  2412. conv[1] = 0;
  2413. }
  2414. return conv;
  2415. }
  2416. // Convert int to rj string with 1234 format
  2417. char *itostr4(const int &xx) {
  2418. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  2419. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  2420. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  2421. conv[3] = xx % 10 + '0';
  2422. conv[4] = 0;
  2423. return conv;
  2424. }
  2425. // Convert float to rj string with 12345 format
  2426. char *ftostr5(const float &x) {
  2427. long xx = abs(x);
  2428. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  2429. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  2430. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  2431. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  2432. conv[4] = xx % 10 + '0';
  2433. conv[5] = 0;
  2434. return conv;
  2435. }
  2436. // Convert float to string with +1234.5 format
  2437. char *ftostr51(const float &x)
  2438. {
  2439. long xx = x * 10;
  2440. conv[0] = (xx >= 0) ? '+' : '-';
  2441. xx = abs(xx);
  2442. conv[1] = (xx / 10000) % 10 + '0';
  2443. conv[2] = (xx / 1000) % 10 + '0';
  2444. conv[3] = (xx / 100) % 10 + '0';
  2445. conv[4] = (xx / 10) % 10 + '0';
  2446. conv[5] = '.';
  2447. conv[6] = (xx) % 10 + '0';
  2448. conv[7] = 0;
  2449. return conv;
  2450. }
  2451. // Convert float to string with +123.45 format
  2452. char *ftostr52(const float &x)
  2453. {
  2454. long xx = x * 100;
  2455. conv[0] = (xx >= 0) ? '+' : '-';
  2456. xx = abs(xx);
  2457. conv[1] = (xx / 10000) % 10 + '0';
  2458. conv[2] = (xx / 1000) % 10 + '0';
  2459. conv[3] = (xx / 100) % 10 + '0';
  2460. conv[4] = '.';
  2461. conv[5] = (xx / 10) % 10 + '0';
  2462. conv[6] = (xx) % 10 + '0';
  2463. conv[7] = 0;
  2464. return conv;
  2465. }
  2466. // Callback for after editing PID i value
  2467. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  2468. void copy_and_scalePID_i()
  2469. {
  2470. #ifdef PIDTEMP
  2471. Ki = scalePID_i(raw_Ki);
  2472. updatePID();
  2473. #endif
  2474. }
  2475. // Callback for after editing PID d value
  2476. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  2477. void copy_and_scalePID_d()
  2478. {
  2479. #ifdef PIDTEMP
  2480. Kd = scalePID_d(raw_Kd);
  2481. updatePID();
  2482. #endif
  2483. }
  2484. #endif //ULTRA_LCD