ultralcd.cpp 78 KB

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