ultralcd.cpp 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881
  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 "util.h"
  12. //#include "Configuration.h"
  13. #define _STRINGIFY(s) #s
  14. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  15. extern int lcd_change_fil_state;
  16. //Function pointer to menu functions.
  17. typedef void (*menuFunc_t)();
  18. struct EditMenuParentState
  19. {
  20. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  21. menuFunc_t prevMenu;
  22. uint16_t prevEncoderPosition;
  23. //Variables used when editing values.
  24. const char* editLabel;
  25. void* editValue;
  26. int32_t minEditValue, maxEditValue;
  27. // menuFunc_t callbackFunc;
  28. };
  29. union MenuData
  30. {
  31. struct BabyStep
  32. {
  33. // 29B total
  34. int8_t status;
  35. int babystepMem[3];
  36. float babystepMemMM[3];
  37. } babyStep;
  38. struct SupportMenu
  39. {
  40. // 6B+16B=22B total
  41. int8_t status;
  42. bool is_flash_air;
  43. uint8_t ip[4];
  44. char ip_str[3*4+3+1];
  45. } supportMenu;
  46. struct AdjustBed
  47. {
  48. // 6+13+16=35B
  49. // editMenuParentState is used when an edit menu is entered, so it knows
  50. // the return menu and encoder state.
  51. struct EditMenuParentState editMenuParentState;
  52. int8_t status;
  53. int8_t left;
  54. int8_t right;
  55. int8_t front;
  56. int8_t rear;
  57. int left2;
  58. int right2;
  59. int front2;
  60. int rear2;
  61. } adjustBed;
  62. // editMenuParentState is used when an edit menu is entered, so it knows
  63. // the return menu and encoder state.
  64. struct EditMenuParentState editMenuParentState;
  65. };
  66. // State of the currently active menu.
  67. // C Union manages sharing of the static memory by all the menus.
  68. union MenuData menuData = { 0 };
  69. union Data
  70. {
  71. byte b[2];
  72. int value;
  73. };
  74. int8_t ReInitLCD = 0;
  75. int8_t SDscrool = 0;
  76. int8_t SilentModeMenu = 0;
  77. int lcd_commands_type=LCD_COMMAND_IDLE;
  78. int lcd_commands_step=0;
  79. bool isPrintPaused = false;
  80. bool farm_mode = false;
  81. int farm_no = 0;
  82. int farm_timer = 30;
  83. int farm_status = 0;
  84. bool menuExiting = false;
  85. #ifdef FILAMENT_LCD_DISPLAY
  86. unsigned long message_millis = 0;
  87. #endif
  88. #ifdef ULTIPANEL
  89. static float manual_feedrate[] = MANUAL_FEEDRATE;
  90. #endif // ULTIPANEL
  91. /* !Configuration settings */
  92. uint8_t lcd_status_message_level;
  93. char lcd_status_message[LCD_WIDTH + 1] = ""; //////WELCOME!
  94. unsigned char firstrun = 1;
  95. #ifdef DOGLCD
  96. #include "dogm_lcd_implementation.h"
  97. #else
  98. #include "ultralcd_implementation_hitachi_HD44780.h"
  99. #endif
  100. /** forward declarations **/
  101. // void copy_and_scalePID_i();
  102. // void copy_and_scalePID_d();
  103. /* Different menus */
  104. static void lcd_status_screen();
  105. #ifdef ULTIPANEL
  106. extern bool powersupply;
  107. static void lcd_main_menu();
  108. static void lcd_tune_menu();
  109. static void lcd_prepare_menu();
  110. static void lcd_move_menu();
  111. static void lcd_settings_menu();
  112. static void lcd_calibration_menu();
  113. static void lcd_language_menu();
  114. static void lcd_control_temperature_menu();
  115. static void lcd_control_temperature_preheat_pla_settings_menu();
  116. static void lcd_control_temperature_preheat_abs_settings_menu();
  117. static void lcd_control_motion_menu();
  118. static void lcd_control_volumetric_menu();
  119. static void prusa_stat_printerstatus(int _status);
  120. static void prusa_stat_temperatures();
  121. static void prusa_stat_printinfo();
  122. static void lcd_farm_no();
  123. #ifdef DOGLCD
  124. static void lcd_set_contrast();
  125. #endif
  126. static void lcd_control_retract_menu();
  127. static void lcd_sdcard_menu();
  128. #ifdef DELTA_CALIBRATION_MENU
  129. static void lcd_delta_calibrate_menu();
  130. #endif // DELTA_CALIBRATION_MENU
  131. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
  132. /* Different types of actions that can be used in menu items. */
  133. static void menu_action_back(menuFunc_t data);
  134. #define menu_action_back_RAM menu_action_back
  135. static void menu_action_submenu(menuFunc_t data);
  136. static void menu_action_gcode(const char* pgcode);
  137. static void menu_action_function(menuFunc_t data);
  138. static void menu_action_setlang(unsigned char lang);
  139. static void menu_action_sdfile(const char* filename, char* longFilename);
  140. static void menu_action_sddirectory(const char* filename, char* longFilename);
  141. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  142. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  143. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  144. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  145. static void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  146. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  147. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  148. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  149. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  150. /*
  151. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
  152. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
  153. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  154. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  155. static void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  156. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  157. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  158. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  159. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
  160. */
  161. #define ENCODER_FEEDRATE_DEADZONE 10
  162. #if !defined(LCD_I2C_VIKI)
  163. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  164. #define ENCODER_STEPS_PER_MENU_ITEM 5
  165. #endif
  166. #ifndef ENCODER_PULSES_PER_STEP
  167. #define ENCODER_PULSES_PER_STEP 1
  168. #endif
  169. #else
  170. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  171. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  172. #endif
  173. #ifndef ENCODER_PULSES_PER_STEP
  174. #define ENCODER_PULSES_PER_STEP 1
  175. #endif
  176. #endif
  177. /* Helper macros for menus */
  178. #define START_MENU() do { \
  179. if (encoderPosition > 0x8000) encoderPosition = 0; \
  180. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset) currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;\
  181. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  182. bool wasClicked = LCD_CLICKED;\
  183. for(uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  184. _menuItemNr = 0;
  185. #define MENU_ITEM(type, label, args...) do { \
  186. if (_menuItemNr == _lineNr) { \
  187. if (lcdDrawUpdate) { \
  188. const char* _label_pstr = (label); \
  189. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  190. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  191. }else{\
  192. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  193. }\
  194. }\
  195. if (wasClicked && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  196. lcd_quick_feedback(); \
  197. menu_action_ ## type ( args ); \
  198. return;\
  199. }\
  200. }\
  201. _menuItemNr++;\
  202. } while(0)
  203. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  204. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, (label) , ## args )
  205. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, (label) , ## args )
  206. #define END_MENU() \
  207. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
  208. 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; } \
  209. } } while(0)
  210. /** Used variables to keep track of the menu */
  211. #ifndef REPRAPWORLD_KEYPAD
  212. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  213. #else
  214. volatile uint8_t buttons_reprapworld_keypad; // to store the reprapworld_keypad shift register values
  215. #endif
  216. #ifdef LCD_HAS_SLOW_BUTTONS
  217. volatile uint8_t slow_buttons;//Contains the bits of the currently pressed buttons.
  218. #endif
  219. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  220. uint32_t blocking_enc;
  221. uint8_t lastEncoderBits;
  222. uint32_t encoderPosition;
  223. #if (SDCARDDETECT > 0)
  224. bool lcd_oldcardstatus;
  225. #endif
  226. #endif //ULTIPANEL
  227. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  228. uint32_t lcd_next_update_millis;
  229. uint8_t lcd_status_update_delay;
  230. bool ignore_click = false;
  231. bool wait_for_unclick;
  232. 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) */
  233. // place-holders for Ki and Kd edits
  234. #ifdef PIDTEMP
  235. // float raw_Ki, raw_Kd;
  236. #endif
  237. static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder = 0, const bool feedback = true, bool reset_menu_state = true) {
  238. if (currentMenu != menu) {
  239. currentMenu = menu;
  240. encoderPosition = encoder;
  241. if (reset_menu_state) {
  242. // Resets the global shared C union.
  243. // This ensures, that the menu entered will find out, that it shall initialize itself.
  244. memset(&menuData, 0, sizeof(menuData));
  245. }
  246. if (feedback) lcd_quick_feedback();
  247. // For LCD_PROGRESS_BAR re-initialize the custom characters
  248. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  249. lcd_set_custom_characters(menu == lcd_status_screen);
  250. #endif
  251. }
  252. }
  253. /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */
  254. // Language selection dialog not active.
  255. #define LANGSEL_OFF 0
  256. // Language selection dialog modal, entered from the info screen. This is the case on firmware boot up,
  257. // if the language index stored in the EEPROM is not valid.
  258. #define LANGSEL_MODAL 1
  259. // Language selection dialog entered from the Setup menu.
  260. #define LANGSEL_ACTIVE 2
  261. // Language selection dialog status
  262. unsigned char langsel = LANGSEL_OFF;
  263. void set_language_from_EEPROM() {
  264. unsigned char eep = eeprom_read_byte((unsigned char*)EEPROM_LANG);
  265. if (eep < LANG_NUM)
  266. {
  267. lang_selected = eep;
  268. // Language is valid, no need to enter the language selection screen.
  269. langsel = LANGSEL_OFF;
  270. }
  271. else
  272. {
  273. lang_selected = LANG_ID_DEFAULT;
  274. // Invalid language, enter the language selection screen in a modal mode.
  275. langsel = LANGSEL_MODAL;
  276. }
  277. }
  278. void lcd_mylang();
  279. static void lcd_status_screen()
  280. {
  281. if (firstrun == 1)
  282. {
  283. firstrun = 0;
  284. set_language_from_EEPROM();
  285. if(lcd_status_message_level == 0){
  286. strncpy_P(lcd_status_message, WELCOME_MSG, LCD_WIDTH);
  287. }
  288. 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)
  289. {
  290. eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0);
  291. eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0);
  292. }
  293. if (langsel) {
  294. //strncpy_P(lcd_status_message, PSTR(">>>>>>>>>>>> PRESS v"), LCD_WIDTH);
  295. // Entering the language selection screen in a modal mode.
  296. lcd_mylang();
  297. }
  298. }
  299. if (lcd_status_update_delay)
  300. lcd_status_update_delay--;
  301. else
  302. lcdDrawUpdate = 1;
  303. if (lcdDrawUpdate)
  304. {
  305. ReInitLCD++;
  306. if (ReInitLCD == 30) {
  307. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  308. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  309. currentMenu == lcd_status_screen
  310. #endif
  311. );
  312. ReInitLCD = 0 ;
  313. } else {
  314. if ((ReInitLCD % 10) == 0) {
  315. //lcd_implementation_nodisplay();
  316. lcd_implementation_init_noclear( // to maybe revive the LCD if static electricity killed it.
  317. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  318. currentMenu == lcd_status_screen
  319. #endif
  320. );
  321. }
  322. }
  323. //lcd_implementation_display();
  324. lcd_implementation_status_screen();
  325. //lcd_implementation_clear();
  326. if (farm_mode)
  327. {
  328. farm_timer--;
  329. if (farm_timer < 1)
  330. {
  331. farm_timer = 90;
  332. prusa_statistics(0);
  333. }
  334. switch (farm_timer)
  335. {
  336. case 45:
  337. prusa_statistics(21);
  338. break;
  339. case 10:
  340. if (IS_SD_PRINTING)
  341. {
  342. prusa_statistics(20);
  343. }
  344. break;
  345. }
  346. } // end of farm_mode
  347. 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 */
  348. if (lcd_commands_type != LCD_COMMAND_IDLE)
  349. {
  350. lcd_commands();
  351. }
  352. } // end of lcdDrawUpdate
  353. #ifdef ULTIPANEL
  354. bool current_click = LCD_CLICKED;
  355. if (ignore_click) {
  356. if (wait_for_unclick) {
  357. if (!current_click) {
  358. ignore_click = wait_for_unclick = false;
  359. }
  360. else {
  361. current_click = false;
  362. }
  363. }
  364. else if (current_click) {
  365. lcd_quick_feedback();
  366. wait_for_unclick = true;
  367. current_click = false;
  368. }
  369. }
  370. //if (--langsel ==0) {langsel=1;current_click=true;}
  371. if (current_click)
  372. {
  373. lcd_goto_menu(lcd_main_menu);
  374. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  375. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  376. currentMenu == lcd_status_screen
  377. #endif
  378. );
  379. #ifdef FILAMENT_LCD_DISPLAY
  380. message_millis = millis(); // get status message to show up for a while
  381. #endif
  382. }
  383. #ifdef ULTIPANEL_FEEDMULTIPLY
  384. // Dead zone at 100% feedrate
  385. if ((feedmultiply < 100 && (feedmultiply + int(encoderPosition)) > 100) ||
  386. (feedmultiply > 100 && (feedmultiply + int(encoderPosition)) < 100))
  387. {
  388. encoderPosition = 0;
  389. feedmultiply = 100;
  390. }
  391. if (feedmultiply == 100 && int(encoderPosition) > ENCODER_FEEDRATE_DEADZONE)
  392. {
  393. feedmultiply += int(encoderPosition) - ENCODER_FEEDRATE_DEADZONE;
  394. encoderPosition = 0;
  395. }
  396. else if (feedmultiply == 100 && int(encoderPosition) < -ENCODER_FEEDRATE_DEADZONE)
  397. {
  398. feedmultiply += int(encoderPosition) + ENCODER_FEEDRATE_DEADZONE;
  399. encoderPosition = 0;
  400. }
  401. else if (feedmultiply != 100)
  402. {
  403. feedmultiply += int(encoderPosition);
  404. encoderPosition = 0;
  405. }
  406. #endif //ULTIPANEL_FEEDMULTIPLY
  407. if (feedmultiply < 10)
  408. feedmultiply = 10;
  409. else if (feedmultiply > 999)
  410. feedmultiply = 999;
  411. #endif //ULTIPANEL
  412. }
  413. #ifdef ULTIPANEL
  414. void lcd_commands()
  415. {
  416. if (lcd_commands_type == LCD_COMMAND_LOAD_FILAMENT) //// load filament sequence
  417. {
  418. if (lcd_commands_step == 0) { lcd_commands_step = 5; custom_message = true; }
  419. if (lcd_commands_step == 1 && !blocks_queued())
  420. {
  421. lcd_commands_step = 0;
  422. lcd_commands_type = 0;
  423. lcd_setstatuspgm(WELCOME_MSG);
  424. disable_z();
  425. custom_message = false;
  426. custom_message_type = 0;
  427. }
  428. if (lcd_commands_step == 2 && !blocks_queued())
  429. {
  430. lcd_setstatuspgm(MSG_LOADING_FILAMENT);
  431. enquecommand_P(PSTR(LOAD_FILAMENT_2));
  432. lcd_commands_step = 1;
  433. }
  434. if (lcd_commands_step == 3 && !blocks_queued())
  435. {
  436. enquecommand_P(PSTR(LOAD_FILAMENT_1));
  437. enquecommand_P(PSTR("G4"));
  438. st_synchronize();
  439. lcd_commands_step = 2;
  440. }
  441. if (lcd_commands_step == 4 && !blocks_queued())
  442. {
  443. lcd_setstatuspgm(MSG_INSERT_FILAMENT);
  444. enquecommand_P(PSTR(LOAD_FILAMENT_0));
  445. enquecommand_P(PSTR("G1 E0.1 F400"));
  446. lcd_commands_step = 3;
  447. st_synchronize();
  448. }
  449. if (lcd_commands_step == 5 && !blocks_queued())
  450. {
  451. lcd_setstatuspgm(MSG_PLEASE_WAIT);
  452. enable_z();
  453. custom_message = true;
  454. custom_message_type = 2;
  455. lcd_commands_step = 4;
  456. }
  457. }
  458. if (lcd_commands_type == LCD_COMMAND_STOP_PRINT) /// stop print
  459. {
  460. if (lcd_commands_step == 0) { lcd_commands_step = 6; custom_message = true; }
  461. if (lcd_commands_step == 1 && !blocks_queued())
  462. {
  463. lcd_commands_step = 0;
  464. lcd_commands_type = 0;
  465. lcd_setstatuspgm(WELCOME_MSG);
  466. custom_message = false;
  467. }
  468. if (lcd_commands_step == 2 && !blocks_queued())
  469. {
  470. setTargetBed(0);
  471. setTargetHotend(0, 0);
  472. setTargetHotend(0, 1);
  473. setTargetHotend(0, 2);
  474. manage_heater();
  475. lcd_setstatuspgm(WELCOME_MSG);
  476. cancel_heatup = false;
  477. lcd_commands_step = 1;
  478. }
  479. if (lcd_commands_step == 3 && !blocks_queued())
  480. {
  481. // M84: Disable steppers.
  482. enquecommand_P(PSTR("M84"));
  483. autotempShutdown();
  484. lcd_commands_step = 2;
  485. }
  486. if (lcd_commands_step == 4 && !blocks_queued())
  487. {
  488. // G90: Absolute positioning.
  489. enquecommand_P(PSTR("G90"));
  490. // M83: Set extruder to relative mode.
  491. enquecommand_P(PSTR("M83"));
  492. #ifdef X_CANCEL_POS
  493. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  494. #else
  495. enquecommand_P(PSTR("G1 X50 Y" STRINGIFY(Y_MAX_POS) " E0 F7000"));
  496. #endif
  497. lcd_ignore_click(false);
  498. lcd_commands_step = 3;
  499. }
  500. if (lcd_commands_step == 5 && !blocks_queued())
  501. {
  502. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  503. // G91: Set to relative positioning.
  504. enquecommand_P(PSTR("G91"));
  505. // Lift up.
  506. enquecommand_P(PSTR("G1 Z15 F1500"));
  507. lcd_commands_step = 4;
  508. }
  509. if (lcd_commands_step == 6 && !blocks_queued())
  510. {
  511. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  512. cancel_heatup = true;
  513. setTargetBed(0);
  514. setTargetHotend(0, 0);
  515. setTargetHotend(0, 1);
  516. setTargetHotend(0, 2);
  517. manage_heater();
  518. lcd_commands_step = 5;
  519. }
  520. }
  521. if (lcd_commands_type == 3)
  522. {
  523. lcd_commands_type = 0;
  524. }
  525. if (lcd_commands_type == LCD_COMMAND_FARM_MODE_CONFIRM) /// farm mode confirm
  526. {
  527. if (lcd_commands_step == 0) { lcd_commands_step = 6; custom_message = true; }
  528. if (lcd_commands_step == 1 && !blocks_queued())
  529. {
  530. lcd_confirm_print();
  531. lcd_commands_step = 0;
  532. lcd_commands_type = 0;
  533. }
  534. if (lcd_commands_step == 2 && !blocks_queued())
  535. {
  536. lcd_commands_step = 1;
  537. }
  538. if (lcd_commands_step == 3 && !blocks_queued())
  539. {
  540. lcd_commands_step = 2;
  541. }
  542. if (lcd_commands_step == 4 && !blocks_queued())
  543. {
  544. enquecommand_P(PSTR("G90"));
  545. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  546. lcd_commands_step = 3;
  547. }
  548. if (lcd_commands_step == 5 && !blocks_queued())
  549. {
  550. lcd_commands_step = 4;
  551. }
  552. if (lcd_commands_step == 6 && !blocks_queued())
  553. {
  554. enquecommand_P(PSTR("G91"));
  555. enquecommand_P(PSTR("G1 Z15 F1500"));
  556. st_synchronize();
  557. lcd_commands_step = 5;
  558. }
  559. }
  560. }
  561. static void lcd_return_to_status() {
  562. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  563. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  564. currentMenu == lcd_status_screen
  565. #endif
  566. );
  567. lcd_goto_menu(lcd_status_screen, 0, false);
  568. }
  569. static void lcd_sdcard_pause() {
  570. card.pauseSDPrint();
  571. isPrintPaused = true;
  572. lcdDrawUpdate = 3;
  573. }
  574. static void lcd_sdcard_resume() {
  575. card.startFileprint();
  576. isPrintPaused = false;
  577. lcdDrawUpdate = 3;
  578. }
  579. float move_menu_scale;
  580. static void lcd_move_menu_axis();
  581. /* Menu implementation */
  582. void lcd_preheat_pla()
  583. {
  584. setTargetHotend0(PLA_PREHEAT_HOTEND_TEMP);
  585. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  586. fanSpeed = 0;
  587. lcd_return_to_status();
  588. setWatch(); // heater sanity check timer
  589. }
  590. void lcd_preheat_abs()
  591. {
  592. setTargetHotend0(ABS_PREHEAT_HOTEND_TEMP);
  593. setTargetBed(ABS_PREHEAT_HPB_TEMP);
  594. fanSpeed = 0;
  595. lcd_return_to_status();
  596. setWatch(); // heater sanity check timer
  597. }
  598. void lcd_preheat_pp()
  599. {
  600. setTargetHotend0(PP_PREHEAT_HOTEND_TEMP);
  601. setTargetBed(PP_PREHEAT_HPB_TEMP);
  602. fanSpeed = 0;
  603. lcd_return_to_status();
  604. setWatch(); // heater sanity check timer
  605. }
  606. void lcd_preheat_pet()
  607. {
  608. setTargetHotend0(PET_PREHEAT_HOTEND_TEMP);
  609. setTargetBed(PET_PREHEAT_HPB_TEMP);
  610. fanSpeed = 0;
  611. lcd_return_to_status();
  612. setWatch(); // heater sanity check timer
  613. }
  614. void lcd_preheat_hips()
  615. {
  616. setTargetHotend0(HIPS_PREHEAT_HOTEND_TEMP);
  617. setTargetBed(HIPS_PREHEAT_HPB_TEMP);
  618. fanSpeed = 0;
  619. lcd_return_to_status();
  620. setWatch(); // heater sanity check timer
  621. }
  622. void lcd_preheat_flex()
  623. {
  624. setTargetHotend0(FLEX_PREHEAT_HOTEND_TEMP);
  625. setTargetBed(FLEX_PREHEAT_HPB_TEMP);
  626. fanSpeed = 0;
  627. lcd_return_to_status();
  628. setWatch(); // heater sanity check timer
  629. }
  630. void lcd_cooldown()
  631. {
  632. setTargetHotend0(0);
  633. setTargetHotend1(0);
  634. setTargetHotend2(0);
  635. setTargetBed(0);
  636. fanSpeed = 0;
  637. lcd_return_to_status();
  638. }
  639. static void lcd_preheat_menu()
  640. {
  641. START_MENU();
  642. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  643. MENU_ITEM(function, PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)), lcd_preheat_abs);
  644. MENU_ITEM(function, PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)), lcd_preheat_pla);
  645. MENU_ITEM(function, PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)), lcd_preheat_pet);
  646. MENU_ITEM(function, PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)), lcd_preheat_hips);
  647. MENU_ITEM(function, PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)), lcd_preheat_pp);
  648. MENU_ITEM(function, PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)), lcd_preheat_flex);
  649. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  650. END_MENU();
  651. }
  652. static void lcd_support_menu()
  653. {
  654. if (menuData.supportMenu.status == 0 || lcdDrawUpdate == 2) {
  655. // Menu was entered or SD card status has changed (plugged in or removed).
  656. // Initialize its status.
  657. menuData.supportMenu.status = 1;
  658. menuData.supportMenu.is_flash_air = card.ToshibaFlashAir_isEnabled() && card.ToshibaFlashAir_GetIP(menuData.supportMenu.ip);
  659. if (menuData.supportMenu.is_flash_air)
  660. sprintf_P(menuData.supportMenu.ip_str, PSTR("%d.%d.%d.%d"),
  661. menuData.supportMenu.ip[0], menuData.supportMenu.ip[1],
  662. menuData.supportMenu.ip[2], menuData.supportMenu.ip[3]);
  663. } else if (menuData.supportMenu.is_flash_air &&
  664. menuData.supportMenu.ip[0] == 0 && menuData.supportMenu.ip[1] == 0 &&
  665. menuData.supportMenu.ip[2] == 0 && menuData.supportMenu.ip[3] == 0 &&
  666. ++ menuData.supportMenu.status == 16) {
  667. // Waiting for the FlashAir card to get an IP address from a router. Force an update.
  668. menuData.supportMenu.status = 0;
  669. }
  670. START_MENU();
  671. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  672. // Ideally this block would be optimized out by the compiler.
  673. const uint8_t fw_string_len = strlen_P(FW_VERSION_STR_P());
  674. if (fw_string_len < 6) {
  675. MENU_ITEM(back, PSTR(MSG_FW_VERSION " - " FW_version), lcd_main_menu);
  676. } else {
  677. MENU_ITEM(back, PSTR("FW - " FW_version), lcd_main_menu);
  678. }
  679. MENU_ITEM(back, MSG_PRUSA3D, lcd_main_menu);
  680. MENU_ITEM(back, MSG_PRUSA3D_FORUM, lcd_main_menu);
  681. MENU_ITEM(back, MSG_PRUSA3D_HOWTO, lcd_main_menu);
  682. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  683. MENU_ITEM(back, PSTR(FILAMENT_SIZE), lcd_main_menu);
  684. MENU_ITEM(back, PSTR(ELECTRONICS),lcd_main_menu);
  685. MENU_ITEM(back, PSTR(NOZZLE_TYPE),lcd_main_menu);
  686. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  687. MENU_ITEM(back, PSTR("Date: "), lcd_main_menu);
  688. MENU_ITEM(back, PSTR(__DATE__), lcd_main_menu);
  689. // Show the FlashAir IP address, if the card is available.
  690. if (menuData.supportMenu.is_flash_air) {
  691. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  692. MENU_ITEM(back, PSTR("FlashAir IP Addr:"), lcd_main_menu);
  693. MENU_ITEM(back_RAM, menuData.supportMenu.ip_str, lcd_main_menu);
  694. }
  695. END_MENU();
  696. }
  697. void lcd_unLoadFilament()
  698. {
  699. if (degHotend0() > EXTRUDE_MINTEMP) {
  700. enquecommand_P(PSTR(UNLOAD_FILAMENT_0));
  701. enquecommand_P(PSTR(UNLOAD_FILAMENT_1));
  702. } else {
  703. lcd_implementation_clear();
  704. lcd.setCursor(0, 0);
  705. lcd_printPGM(MSG_ERROR);
  706. lcd.setCursor(0, 2);
  707. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  708. delay(2000);
  709. lcd_implementation_clear();
  710. }
  711. lcd_return_to_status();
  712. }
  713. void lcd_change_filament() {
  714. lcd_implementation_clear();
  715. lcd.setCursor(0, 1);
  716. lcd_printPGM(MSG_CHANGING_FILAMENT);
  717. }
  718. void lcd_wait_interact() {
  719. lcd_implementation_clear();
  720. lcd.setCursor(0, 1);
  721. lcd_printPGM(MSG_INSERT_FILAMENT);
  722. lcd.setCursor(0, 2);
  723. lcd_printPGM(MSG_PRESS);
  724. }
  725. void lcd_change_success() {
  726. lcd_implementation_clear();
  727. lcd.setCursor(0, 2);
  728. lcd_printPGM(MSG_CHANGE_SUCCESS);
  729. }
  730. void lcd_loading_color() {
  731. lcd_implementation_clear();
  732. lcd.setCursor(0, 0);
  733. lcd_printPGM(MSG_LOADING_COLOR);
  734. lcd.setCursor(0, 2);
  735. lcd_printPGM(MSG_PLEASE_WAIT);
  736. for (int i = 0; i < 20; i++) {
  737. lcd.setCursor(i, 3);
  738. lcd.print(".");
  739. for (int j = 0; j < 10 ; j++) {
  740. manage_heater();
  741. manage_inactivity(true);
  742. delay(85);
  743. }
  744. }
  745. }
  746. void lcd_loading_filament() {
  747. lcd_implementation_clear();
  748. lcd.setCursor(0, 0);
  749. lcd_printPGM(MSG_LOADING_FILAMENT);
  750. lcd.setCursor(0, 2);
  751. lcd_printPGM(MSG_PLEASE_WAIT);
  752. for (int i = 0; i < 20; i++) {
  753. lcd.setCursor(i, 3);
  754. lcd.print(".");
  755. for (int j = 0; j < 10 ; j++) {
  756. manage_heater();
  757. manage_inactivity(true);
  758. delay(110);
  759. }
  760. }
  761. }
  762. void lcd_alright() {
  763. int enc_dif = 0;
  764. int cursor_pos = 1;
  765. lcd_implementation_clear();
  766. lcd.setCursor(0, 0);
  767. lcd_printPGM(MSG_CORRECTLY);
  768. lcd.setCursor(1, 1);
  769. lcd_printPGM(MSG_YES);
  770. lcd.setCursor(1, 2);
  771. lcd_printPGM(MSG_NOT_LOADED);
  772. lcd.setCursor(1, 3);
  773. lcd_printPGM(MSG_NOT_COLOR);
  774. lcd.setCursor(0, 1);
  775. lcd.print(">");
  776. enc_dif = encoderDiff;
  777. while (lcd_change_fil_state == 0) {
  778. manage_heater();
  779. manage_inactivity(true);
  780. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  781. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  782. if (enc_dif > encoderDiff ) {
  783. cursor_pos --;
  784. }
  785. if (enc_dif < encoderDiff ) {
  786. cursor_pos ++;
  787. }
  788. if (cursor_pos > 3) {
  789. cursor_pos = 3;
  790. }
  791. if (cursor_pos < 1) {
  792. cursor_pos = 1;
  793. }
  794. lcd.setCursor(0, 1);
  795. lcd.print(" ");
  796. lcd.setCursor(0, 2);
  797. lcd.print(" ");
  798. lcd.setCursor(0, 3);
  799. lcd.print(" ");
  800. lcd.setCursor(0, cursor_pos);
  801. lcd.print(">");
  802. enc_dif = encoderDiff;
  803. delay(100);
  804. }
  805. }
  806. if (lcd_clicked()) {
  807. lcd_change_fil_state = cursor_pos;
  808. delay(500);
  809. }
  810. };
  811. lcd_implementation_clear();
  812. lcd_return_to_status();
  813. }
  814. void lcd_LoadFilament()
  815. {
  816. if (degHotend0() > EXTRUDE_MINTEMP)
  817. {
  818. custom_message = true;
  819. lcd_commands_type = LCD_COMMAND_LOAD_FILAMENT;
  820. SERIAL_ECHOLN("Loading filament");
  821. // commands() will handle the rest
  822. }
  823. else
  824. {
  825. lcd_implementation_clear();
  826. lcd.setCursor(0, 0);
  827. lcd_printPGM(MSG_ERROR);
  828. lcd.setCursor(0, 2);
  829. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  830. delay(2000);
  831. lcd_implementation_clear();
  832. }
  833. lcd_return_to_status();
  834. }
  835. static void lcd_menu_statistics()
  836. {
  837. if (IS_SD_PRINTING)
  838. {
  839. int _met = total_filament_used / 100000;
  840. int _cm = (total_filament_used - (_met * 100000))/10;
  841. int _t = (millis() - starttime) / 1000;
  842. int _h = _t / 3600;
  843. int _m = (_t - (_h * 3600)) / 60;
  844. int _s = _t - ((_h * 3600) + (_m * 60));
  845. lcd.setCursor(0, 0);
  846. lcd_printPGM(MSG_STATS_FILAMENTUSED);
  847. lcd.setCursor(6, 1);
  848. lcd.print(itostr3(_met));
  849. lcd.print("m ");
  850. lcd.print(ftostr32ns(_cm));
  851. lcd.print("cm");
  852. lcd.setCursor(0, 2);
  853. lcd_printPGM(MSG_STATS_PRINTTIME);
  854. lcd.setCursor(8, 3);
  855. lcd.print(itostr2(_h));
  856. lcd.print("h ");
  857. lcd.print(itostr2(_m));
  858. lcd.print("m ");
  859. lcd.print(itostr2(_s));
  860. lcd.print("s");
  861. if (lcd_clicked())
  862. {
  863. lcd_quick_feedback();
  864. lcd_return_to_status();
  865. }
  866. }
  867. else
  868. {
  869. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  870. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME);
  871. uint8_t _days, _hours, _minutes;
  872. float _filament_m = (float)_filament;
  873. int _filament_km = (_filament >= 100000) ? _filament / 100000 : 0;
  874. if (_filament_km > 0) _filament_m = _filament - (_filament_km * 100000);
  875. _days = _time / 1440;
  876. _hours = (_time - (_days * 1440)) / 60;
  877. _minutes = _time - ((_days * 1440) + (_hours * 60));
  878. lcd_implementation_clear();
  879. lcd.setCursor(0, 0);
  880. lcd_printPGM(MSG_STATS_TOTALFILAMENT);
  881. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)), 1);
  882. lcd.print(ftostr32ns(_filament_m));
  883. if (_filament_km > 0)
  884. {
  885. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)) - 3, 1);
  886. lcd.print("km");
  887. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)) - 8, 1);
  888. lcd.print(itostr4(_filament_km));
  889. }
  890. lcd.setCursor(18, 1);
  891. lcd.print("m");
  892. lcd.setCursor(0, 2);
  893. lcd_printPGM(MSG_STATS_TOTALPRINTTIME);;
  894. lcd.setCursor(18, 3);
  895. lcd.print("m");
  896. lcd.setCursor(14, 3);
  897. lcd.print(itostr3(_minutes));
  898. lcd.setCursor(14, 3);
  899. lcd.print(":");
  900. lcd.setCursor(12, 3);
  901. lcd.print("h");
  902. lcd.setCursor(9, 3);
  903. lcd.print(itostr3(_hours));
  904. lcd.setCursor(9, 3);
  905. lcd.print(":");
  906. lcd.setCursor(7, 3);
  907. lcd.print("d");
  908. lcd.setCursor(4, 3);
  909. lcd.print(itostr3(_days));
  910. while (!lcd_clicked())
  911. {
  912. manage_heater();
  913. manage_inactivity(true);
  914. delay(100);
  915. }
  916. lcd_quick_feedback();
  917. lcd_return_to_status();
  918. }
  919. }
  920. static void _lcd_move(const char *name, int axis, int min, int max) {
  921. if (encoderPosition != 0) {
  922. refresh_cmd_timeout();
  923. if (! planner_queue_full()) {
  924. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  925. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  926. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  927. encoderPosition = 0;
  928. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  929. 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);
  930. lcdDrawUpdate = 1;
  931. }
  932. }
  933. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  934. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  935. }
  936. static void lcd_move_e()
  937. {
  938. if (encoderPosition != 0)
  939. {
  940. refresh_cmd_timeout();
  941. if (! planner_queue_full()) {
  942. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  943. encoderPosition = 0;
  944. 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);
  945. lcdDrawUpdate = 1;
  946. }
  947. }
  948. if (lcdDrawUpdate)
  949. {
  950. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  951. }
  952. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  953. }
  954. // Save a single axis babystep value.
  955. void EEPROM_save_B(int pos, int* value)
  956. {
  957. union Data data;
  958. data.value = *value;
  959. eeprom_update_byte((unsigned char*)pos, data.b[0]);
  960. eeprom_update_byte((unsigned char*)pos + 1, data.b[1]);
  961. }
  962. // Read a single axis babystep value.
  963. void EEPROM_read_B(int pos, int* value)
  964. {
  965. union Data data;
  966. data.b[0] = eeprom_read_byte((unsigned char*)pos);
  967. data.b[1] = eeprom_read_byte((unsigned char*)pos + 1);
  968. *value = data.value;
  969. }
  970. static void lcd_move_x() {
  971. _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS);
  972. }
  973. static void lcd_move_y() {
  974. _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  975. }
  976. static void lcd_move_z() {
  977. _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  978. }
  979. static void _lcd_babystep(int axis, const char *msg)
  980. {
  981. if (menuData.babyStep.status == 0) {
  982. // Menu was entered.
  983. // Initialize its status.
  984. menuData.babyStep.status = 1;
  985. EEPROM_read_B(EEPROM_BABYSTEP_X, &menuData.babyStep.babystepMem[0]);
  986. EEPROM_read_B(EEPROM_BABYSTEP_Y, &menuData.babyStep.babystepMem[1]);
  987. EEPROM_read_B(EEPROM_BABYSTEP_Z, &menuData.babyStep.babystepMem[2]);
  988. menuData.babyStep.babystepMemMM[0] = menuData.babyStep.babystepMem[0]/axis_steps_per_unit[X_AXIS];
  989. menuData.babyStep.babystepMemMM[1] = menuData.babyStep.babystepMem[1]/axis_steps_per_unit[Y_AXIS];
  990. menuData.babyStep.babystepMemMM[2] = menuData.babyStep.babystepMem[2]/axis_steps_per_unit[Z_AXIS];
  991. lcdDrawUpdate = 1;
  992. }
  993. if (encoderPosition != 0)
  994. {
  995. CRITICAL_SECTION_START
  996. babystepsTodo[axis] += (int)encoderPosition;
  997. CRITICAL_SECTION_END
  998. menuData.babyStep.babystepMem[axis] += (int)encoderPosition;
  999. menuData.babyStep.babystepMemMM[axis] = menuData.babyStep.babystepMem[axis]/axis_steps_per_unit[Z_AXIS];
  1000. delay(50);
  1001. encoderPosition = 0;
  1002. lcdDrawUpdate = 1;
  1003. }
  1004. if (lcdDrawUpdate)
  1005. lcd_implementation_drawedit_2(msg, ftostr13ns(menuData.babyStep.babystepMemMM[axis]));
  1006. if (LCD_CLICKED || menuExiting) {
  1007. // Only update the EEPROM when leaving the menu.
  1008. EEPROM_save_B(
  1009. (axis == 0) ? EEPROM_BABYSTEP_X : ((axis == 1) ? EEPROM_BABYSTEP_Y : EEPROM_BABYSTEP_Z),
  1010. &menuData.babyStep.babystepMem[axis]);
  1011. }
  1012. if (LCD_CLICKED) lcd_goto_menu(lcd_main_menu);
  1013. }
  1014. static void lcd_babystep_x() {
  1015. _lcd_babystep(X_AXIS, (MSG_BABYSTEPPING_X));
  1016. }
  1017. static void lcd_babystep_y() {
  1018. _lcd_babystep(Y_AXIS, (MSG_BABYSTEPPING_Y));
  1019. }
  1020. static void lcd_babystep_z() {
  1021. _lcd_babystep(Z_AXIS, (MSG_BABYSTEPPING_Z));
  1022. }
  1023. static void lcd_adjust_bed();
  1024. static void lcd_adjust_bed_reset()
  1025. {
  1026. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  1027. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  1028. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  1029. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  1030. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  1031. lcd_goto_menu(lcd_adjust_bed, 0, false);
  1032. // Because we did not leave the menu, the menuData did not reset.
  1033. // Force refresh of the bed leveling data.
  1034. menuData.adjustBed.status = 0;
  1035. }
  1036. #define BED_ADJUSTMENT_UM_MAX 50
  1037. static void lcd_adjust_bed()
  1038. {
  1039. if (menuData.adjustBed.status == 0) {
  1040. // Menu was entered.
  1041. // Initialize its status.
  1042. menuData.adjustBed.status = 1;
  1043. bool valid = false;
  1044. menuData.adjustBed.left = menuData.adjustBed.left2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT);
  1045. menuData.adjustBed.right = menuData.adjustBed.right2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT);
  1046. menuData.adjustBed.front = menuData.adjustBed.front2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT);
  1047. menuData.adjustBed.rear = menuData.adjustBed.rear2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR);
  1048. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1 &&
  1049. menuData.adjustBed.left >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.left < BED_ADJUSTMENT_UM_MAX &&
  1050. menuData.adjustBed.right >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.right < BED_ADJUSTMENT_UM_MAX &&
  1051. menuData.adjustBed.front >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.front < BED_ADJUSTMENT_UM_MAX &&
  1052. menuData.adjustBed.rear >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.rear < BED_ADJUSTMENT_UM_MAX)
  1053. valid = true;
  1054. if (! valid) {
  1055. // Reset the values: simulate an edit.
  1056. menuData.adjustBed.left2 = 0;
  1057. menuData.adjustBed.right2 = 0;
  1058. menuData.adjustBed.front2 = 0;
  1059. menuData.adjustBed.rear2 = 0;
  1060. }
  1061. lcdDrawUpdate = 1;
  1062. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  1063. }
  1064. if (menuData.adjustBed.left != menuData.adjustBed.left2)
  1065. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, menuData.adjustBed.left = menuData.adjustBed.left2);
  1066. if (menuData.adjustBed.right != menuData.adjustBed.right2)
  1067. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, menuData.adjustBed.right = menuData.adjustBed.right2);
  1068. if (menuData.adjustBed.front != menuData.adjustBed.front2)
  1069. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, menuData.adjustBed.front = menuData.adjustBed.front2);
  1070. if (menuData.adjustBed.rear != menuData.adjustBed.rear2)
  1071. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, menuData.adjustBed.rear = menuData.adjustBed.rear2);
  1072. START_MENU();
  1073. MENU_ITEM(back, MSG_SETTINGS, lcd_calibration_menu);
  1074. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_LEFT, &menuData.adjustBed.left2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1075. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_RIGHT, &menuData.adjustBed.right2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1076. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_FRONT, &menuData.adjustBed.front2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1077. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_REAR, &menuData.adjustBed.rear2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1078. MENU_ITEM(function, MSG_BED_CORRECTION_RESET, lcd_adjust_bed_reset);
  1079. END_MENU();
  1080. }
  1081. void lcd_adjust_z() {
  1082. int enc_dif = 0;
  1083. int cursor_pos = 1;
  1084. int fsm = 0;
  1085. lcd_implementation_clear();
  1086. lcd.setCursor(0, 0);
  1087. lcd_printPGM(MSG_ADJUSTZ);
  1088. lcd.setCursor(1, 1);
  1089. lcd_printPGM(MSG_YES);
  1090. lcd.setCursor(1, 2);
  1091. lcd_printPGM(MSG_NO);
  1092. lcd.setCursor(0, 1);
  1093. lcd.print(">");
  1094. enc_dif = encoderDiff;
  1095. while (fsm == 0) {
  1096. manage_heater();
  1097. manage_inactivity(true);
  1098. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1099. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1100. if (enc_dif > encoderDiff ) {
  1101. cursor_pos --;
  1102. }
  1103. if (enc_dif < encoderDiff ) {
  1104. cursor_pos ++;
  1105. }
  1106. if (cursor_pos > 2) {
  1107. cursor_pos = 2;
  1108. }
  1109. if (cursor_pos < 1) {
  1110. cursor_pos = 1;
  1111. }
  1112. lcd.setCursor(0, 1);
  1113. lcd.print(" ");
  1114. lcd.setCursor(0, 2);
  1115. lcd.print(" ");
  1116. lcd.setCursor(0, cursor_pos);
  1117. lcd.print(">");
  1118. enc_dif = encoderDiff;
  1119. delay(100);
  1120. }
  1121. }
  1122. if (lcd_clicked()) {
  1123. fsm = cursor_pos;
  1124. if (fsm == 1) {
  1125. int babystepLoadZ = 0;
  1126. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ);
  1127. CRITICAL_SECTION_START
  1128. babystepsTodo[Z_AXIS] = babystepLoadZ;
  1129. CRITICAL_SECTION_END
  1130. } else {
  1131. int zero = 0;
  1132. EEPROM_save_B(EEPROM_BABYSTEP_X, &zero);
  1133. EEPROM_save_B(EEPROM_BABYSTEP_Y, &zero);
  1134. EEPROM_save_B(EEPROM_BABYSTEP_Z, &zero);
  1135. }
  1136. delay(500);
  1137. }
  1138. };
  1139. lcd_implementation_clear();
  1140. lcd_return_to_status();
  1141. }
  1142. // Lets the user move the Z carriage up to the end stoppers.
  1143. // When done, it sets the current Z to Z_MAX_POS and returns true.
  1144. // Otherwise the Z calibration is not changed and false is returned.
  1145. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  1146. {
  1147. bool clean_nozzle_asked = false;
  1148. // Don't know where we are. Let's claim we are Z=0, so the soft end stops will not be triggered when moving up.
  1149. current_position[Z_AXIS] = 0;
  1150. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  1151. // Until confirmed by the confirmation dialog.
  1152. for (;;) {
  1153. unsigned long previous_millis_cmd = millis();
  1154. if (only_z) {
  1155. lcd_display_message_fullscreen_P(MSG_MOVE_CARRIAGE_TO_THE_TOP_Z);
  1156. }else{
  1157. lcd_display_message_fullscreen_P(MSG_MOVE_CARRIAGE_TO_THE_TOP);
  1158. }
  1159. // Until the user finishes the z up movement.
  1160. encoderDiff = 0;
  1161. encoderPosition = 0;
  1162. for (;;) {
  1163. if (millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  1164. goto canceled;
  1165. manage_heater();
  1166. manage_inactivity(true);
  1167. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) {
  1168. delay(50);
  1169. previous_millis_cmd = millis();
  1170. encoderPosition += abs(encoderDiff / ENCODER_PULSES_PER_STEP);
  1171. encoderDiff = 0;
  1172. if (! planner_queue_full()) {
  1173. // Only move up, whatever direction the user rotates the encoder.
  1174. current_position[Z_AXIS] += fabs(encoderPosition);
  1175. encoderPosition = 0;
  1176. 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);
  1177. }
  1178. }
  1179. if (lcd_clicked()) {
  1180. // Abort a move if in progress.
  1181. planner_abort_hard();
  1182. while (lcd_clicked()) ;
  1183. delay(10);
  1184. while (lcd_clicked()) ;
  1185. break;
  1186. }
  1187. }
  1188. if (! clean_nozzle_asked) {
  1189. lcd_show_fullscreen_message_and_wait_P(MSG_CONFIRM_NOZZLE_CLEAN);
  1190. clean_nozzle_asked = true;
  1191. }
  1192. // Let the user confirm, that the Z carriage is at the top end stoppers.
  1193. int8_t result = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_CONFIRM_CARRIAGE_AT_THE_TOP);
  1194. if (result == -1)
  1195. goto canceled;
  1196. else if (result == 1)
  1197. goto calibrated;
  1198. // otherwise perform another round of the Z up dialog.
  1199. }
  1200. calibrated:
  1201. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  1202. // during the search for the induction points.
  1203. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  1204. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  1205. return true;
  1206. canceled:
  1207. return false;
  1208. }
  1209. static inline bool pgm_is_whitespace(const char *c_addr)
  1210. {
  1211. const char c = pgm_read_byte(c_addr);
  1212. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  1213. }
  1214. static inline bool pgm_is_interpunction(const char *c_addr)
  1215. {
  1216. const char c = pgm_read_byte(c_addr);
  1217. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  1218. }
  1219. const char* lcd_display_message_fullscreen_P(const char *msg)
  1220. {
  1221. // Disable update of the screen by the usual lcd_update() routine.
  1222. lcd_update_enable(false);
  1223. lcd_implementation_clear();
  1224. lcd.setCursor(0, 0);
  1225. const char *msgend = msg;
  1226. for (int8_t row = 0; row < 4; ++ row) {
  1227. while (pgm_is_whitespace(msg))
  1228. ++ msg;
  1229. if (pgm_read_byte(msg) == 0)
  1230. // End of the message.
  1231. break;
  1232. lcd.setCursor(0, row);
  1233. const char *msgend2 = msg + min(strlen_P(msg), 20);
  1234. msgend = msgend2;
  1235. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  1236. // Splitting a word. Find the start of the current word.
  1237. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  1238. -- msgend;
  1239. if (msgend == msg)
  1240. // Found a single long word, which cannot be split. Just cut it.
  1241. msgend = msgend2;
  1242. }
  1243. for (; msg < msgend; ++ msg) {
  1244. char c = char(pgm_read_byte(msg));
  1245. if (c == '~')
  1246. c = ' ';
  1247. lcd.print(c);
  1248. }
  1249. }
  1250. return (pgm_read_byte(msgend) == 0) ? NULL : msgend;
  1251. }
  1252. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  1253. {
  1254. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  1255. bool multi_screen = msg_next != NULL;
  1256. // Until confirmed by a button click.
  1257. for (;;) {
  1258. // Wait for 5 seconds before displaying the next text.
  1259. for (uint8_t i = 0; i < 100; ++ i) {
  1260. delay_keep_alive(50);
  1261. if (lcd_clicked()) {
  1262. while (lcd_clicked()) ;
  1263. delay(10);
  1264. while (lcd_clicked()) ;
  1265. return;
  1266. }
  1267. }
  1268. if (multi_screen) {
  1269. if (msg_next == NULL)
  1270. msg_next = msg;
  1271. msg_next = lcd_display_message_fullscreen_P(msg_next);
  1272. }
  1273. }
  1274. }
  1275. void lcd_wait_for_click()
  1276. {
  1277. for (;;) {
  1278. manage_heater();
  1279. manage_inactivity(true);
  1280. if (lcd_clicked()) {
  1281. while (lcd_clicked()) ;
  1282. delay(10);
  1283. while (lcd_clicked()) ;
  1284. return;
  1285. }
  1286. }
  1287. }
  1288. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting)
  1289. {
  1290. lcd_display_message_fullscreen_P(msg);
  1291. lcd.setCursor(1, 2);
  1292. lcd_printPGM(MSG_YES);
  1293. lcd.setCursor(0, 3);
  1294. lcd_printPGM(PSTR(">"));
  1295. lcd_printPGM(MSG_NO);
  1296. bool yes = false;
  1297. // Wait for user confirmation or a timeout.
  1298. unsigned long previous_millis_cmd = millis();
  1299. int8_t enc_dif = encoderDiff;
  1300. for (;;) {
  1301. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  1302. return -1;
  1303. manage_heater();
  1304. manage_inactivity(true);
  1305. if (abs((enc_dif - encoderDiff)) > 4) {
  1306. if (abs(enc_dif - encoderDiff) > 1) {
  1307. lcd.setCursor(0, 2);
  1308. if (enc_dif > encoderDiff && yes) {
  1309. lcd_printPGM((PSTR(" ")));
  1310. lcd.setCursor(0, 3);
  1311. lcd_printPGM((PSTR(">")));
  1312. yes = false;
  1313. } else if (enc_dif < encoderDiff && ! yes) {
  1314. lcd_printPGM((PSTR(">")));
  1315. lcd.setCursor(0, 3);
  1316. lcd_printPGM((PSTR(" ")));
  1317. yes = true;
  1318. }
  1319. enc_dif = encoderDiff;
  1320. }
  1321. }
  1322. if (lcd_clicked()) {
  1323. while (lcd_clicked()) ;
  1324. delay(10);
  1325. while (lcd_clicked()) ;
  1326. return yes;
  1327. }
  1328. }
  1329. }
  1330. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  1331. {
  1332. const char *msg = NULL;
  1333. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  1334. lcd_show_fullscreen_message_and_wait_P(MSG_BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND);
  1335. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  1336. if (point_too_far_mask == 0)
  1337. msg = MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
  1338. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  1339. // Only the center point or all the three front points.
  1340. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR;
  1341. else if (point_too_far_mask & 1 == 0)
  1342. // The right and maybe the center point out of reach.
  1343. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR;
  1344. else
  1345. // The left and maybe the center point out of reach.
  1346. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR;
  1347. lcd_show_fullscreen_message_and_wait_P(msg);
  1348. } else {
  1349. if (point_too_far_mask != 0) {
  1350. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  1351. // Only the center point or all the three front points.
  1352. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR;
  1353. else if (point_too_far_mask & 1 == 0)
  1354. // The right and maybe the center point out of reach.
  1355. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR;
  1356. else
  1357. // The left and maybe the center point out of reach.
  1358. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR;
  1359. lcd_show_fullscreen_message_and_wait_P(msg);
  1360. }
  1361. if (point_too_far_mask == 0 || result > 0) {
  1362. switch (result) {
  1363. default:
  1364. // should not happen
  1365. msg = MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
  1366. break;
  1367. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  1368. msg = MSG_BED_SKEW_OFFSET_DETECTION_PERFECT;
  1369. break;
  1370. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  1371. msg = MSG_BED_SKEW_OFFSET_DETECTION_SKEW_MILD;
  1372. break;
  1373. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  1374. msg = MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME;
  1375. break;
  1376. }
  1377. lcd_show_fullscreen_message_and_wait_P(msg);
  1378. }
  1379. }
  1380. }
  1381. static void lcd_show_end_stops() {
  1382. lcd.setCursor(0, 0);
  1383. lcd_printPGM((PSTR("End stops diag")));
  1384. lcd.setCursor(0, 1);
  1385. lcd_printPGM((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("X1")) : (PSTR("X0")));
  1386. lcd.setCursor(0, 2);
  1387. lcd_printPGM((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Y1")) : (PSTR("Y0")));
  1388. lcd.setCursor(0, 3);
  1389. lcd_printPGM((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Z1")) : (PSTR("Z0")));
  1390. }
  1391. static void menu_show_end_stops() {
  1392. lcd_show_end_stops();
  1393. if (LCD_CLICKED) lcd_goto_menu(lcd_calibration_menu);
  1394. }
  1395. // Lets the user move the Z carriage up to the end stoppers.
  1396. // When done, it sets the current Z to Z_MAX_POS and returns true.
  1397. // Otherwise the Z calibration is not changed and false is returned.
  1398. void lcd_diag_show_end_stops()
  1399. {
  1400. int enc_dif = encoderDiff;
  1401. lcd_implementation_clear();
  1402. for (;;) {
  1403. manage_heater();
  1404. manage_inactivity(true);
  1405. lcd_show_end_stops();
  1406. if (lcd_clicked()) {
  1407. while (lcd_clicked()) ;
  1408. delay(10);
  1409. while (lcd_clicked()) ;
  1410. break;
  1411. }
  1412. }
  1413. lcd_implementation_clear();
  1414. lcd_return_to_status();
  1415. }
  1416. void prusa_statistics(int _message) {
  1417. switch (_message)
  1418. {
  1419. case 0: // default message
  1420. if (IS_SD_PRINTING)
  1421. {
  1422. SERIAL_ECHO("{");
  1423. prusa_stat_printerstatus(4);
  1424. prusa_stat_printinfo();
  1425. SERIAL_ECHOLN("}");
  1426. }
  1427. else
  1428. {
  1429. SERIAL_ECHO("{");
  1430. prusa_stat_printerstatus(1);
  1431. SERIAL_ECHOLN("}");
  1432. }
  1433. break;
  1434. case 1: // 1 heating
  1435. farm_status = 2;
  1436. SERIAL_ECHO("{");
  1437. prusa_stat_printerstatus(2);
  1438. SERIAL_ECHOLN("}");
  1439. farm_timer = 1;
  1440. break;
  1441. case 2: // heating done
  1442. farm_status = 3;
  1443. SERIAL_ECHO("{");
  1444. prusa_stat_printerstatus(3);
  1445. SERIAL_ECHOLN("}");
  1446. farm_timer = 1;
  1447. if (IS_SD_PRINTING)
  1448. {
  1449. farm_status = 4;
  1450. SERIAL_ECHO("{");
  1451. prusa_stat_printerstatus(4);
  1452. SERIAL_ECHOLN("}");
  1453. }
  1454. else
  1455. {
  1456. SERIAL_ECHO("{");
  1457. prusa_stat_printerstatus(3);
  1458. SERIAL_ECHOLN("}");;
  1459. }
  1460. farm_timer = 1;
  1461. break;
  1462. case 3: // filament change
  1463. break;
  1464. case 4: // print succesfull
  1465. SERIAL_ECHOLN("{[RES:1]}");
  1466. farm_timer = 2;
  1467. break;
  1468. case 5: // print not succesfull
  1469. SERIAL_ECHOLN("{[RES:0]}");
  1470. farm_timer = 2;
  1471. break;
  1472. case 6: // print done
  1473. SERIAL_ECHOLN("{[PRN:8]}");
  1474. farm_timer = 2;
  1475. break;
  1476. case 7: // print done - stopped
  1477. SERIAL_ECHOLN("{[PRN:9]}");
  1478. farm_timer = 2;
  1479. break;
  1480. case 8: // printer started
  1481. SERIAL_ECHO("{[PRN:0][PFN:");
  1482. SERIAL_ECHO(farm_no);
  1483. SERIAL_ECHOLN("]}");
  1484. farm_timer = 2;
  1485. break;
  1486. case 20: // echo farm no
  1487. SERIAL_ECHO("{[PFN:");
  1488. SERIAL_ECHO(farm_no);
  1489. SERIAL_ECHOLN("]}");
  1490. farm_timer = 5;
  1491. break;
  1492. case 21: // temperatures
  1493. SERIAL_ECHO("{");
  1494. prusa_stat_temperatures();
  1495. SERIAL_ECHOLN("}");
  1496. break;
  1497. case 99: // heartbeat
  1498. SERIAL_ECHOLN("{[PRN:99]}");
  1499. break;
  1500. }
  1501. }
  1502. static void prusa_stat_printerstatus(int _status)
  1503. {
  1504. SERIAL_ECHO("[PRN:");
  1505. SERIAL_ECHO(_status);
  1506. SERIAL_ECHO("]");
  1507. }
  1508. static void prusa_stat_temperatures()
  1509. {
  1510. SERIAL_ECHO("[ST0:");
  1511. SERIAL_ECHO(target_temperature[0]);
  1512. SERIAL_ECHO("][STB:");
  1513. SERIAL_ECHO(target_temperature_bed);
  1514. SERIAL_ECHO("][AT0:");
  1515. SERIAL_ECHO(current_temperature[0]);
  1516. SERIAL_ECHO("][ATB:");
  1517. SERIAL_ECHO(current_temperature_bed);
  1518. SERIAL_ECHO("]");
  1519. }
  1520. static void prusa_stat_printinfo()
  1521. {
  1522. SERIAL_ECHO("[TFU:");
  1523. SERIAL_ECHO(total_filament_used);
  1524. SERIAL_ECHO("][PCD:");
  1525. SERIAL_ECHO(itostr3(card.percentDone()));
  1526. SERIAL_ECHO("][FEM:");
  1527. SERIAL_ECHO(itostr3(feedmultiply));
  1528. SERIAL_ECHO("][FNM:");
  1529. SERIAL_ECHO(longFilenameOLD);
  1530. SERIAL_ECHO("][TIM:");
  1531. if (starttime != 0)
  1532. {
  1533. SERIAL_ECHO(millis() / 1000 - starttime / 1000);
  1534. }
  1535. else
  1536. {
  1537. SERIAL_ECHO(0);
  1538. }
  1539. SERIAL_ECHO("][FWR:");
  1540. SERIAL_ECHO(FW_version);
  1541. SERIAL_ECHO("]");
  1542. }
  1543. void lcd_pick_babystep(){
  1544. int enc_dif = 0;
  1545. int cursor_pos = 1;
  1546. int fsm = 0;
  1547. lcd_implementation_clear();
  1548. lcd.setCursor(0, 0);
  1549. lcd_printPGM(MSG_PICK_Z);
  1550. lcd.setCursor(3, 2);
  1551. lcd.print("1");
  1552. lcd.setCursor(3, 3);
  1553. lcd.print("2");
  1554. lcd.setCursor(12, 2);
  1555. lcd.print("3");
  1556. lcd.setCursor(12, 3);
  1557. lcd.print("4");
  1558. lcd.setCursor(1, 2);
  1559. lcd.print(">");
  1560. enc_dif = encoderDiff;
  1561. while (fsm == 0) {
  1562. manage_heater();
  1563. manage_inactivity(true);
  1564. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1565. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1566. if (enc_dif > encoderDiff ) {
  1567. cursor_pos --;
  1568. }
  1569. if (enc_dif < encoderDiff ) {
  1570. cursor_pos ++;
  1571. }
  1572. if (cursor_pos > 4) {
  1573. cursor_pos = 4;
  1574. }
  1575. if (cursor_pos < 1) {
  1576. cursor_pos = 1;
  1577. }
  1578. lcd.setCursor(1, 2);
  1579. lcd.print(" ");
  1580. lcd.setCursor(1, 3);
  1581. lcd.print(" ");
  1582. lcd.setCursor(10, 2);
  1583. lcd.print(" ");
  1584. lcd.setCursor(10, 3);
  1585. lcd.print(" ");
  1586. if (cursor_pos < 3) {
  1587. lcd.setCursor(1, cursor_pos+1);
  1588. lcd.print(">");
  1589. }else{
  1590. lcd.setCursor(10, cursor_pos-1);
  1591. lcd.print(">");
  1592. }
  1593. enc_dif = encoderDiff;
  1594. delay(100);
  1595. }
  1596. }
  1597. if (lcd_clicked()) {
  1598. fsm = cursor_pos;
  1599. int babyStepZ;
  1600. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babyStepZ);
  1601. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babyStepZ);
  1602. eeprom_write_byte((unsigned char*)EEPROM_BABYSTEP_Z_SET, 0x01);
  1603. delay(500);
  1604. }
  1605. };
  1606. lcd_implementation_clear();
  1607. lcd_return_to_status();
  1608. }
  1609. void lcd_move_menu_axis()
  1610. {
  1611. START_MENU();
  1612. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  1613. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  1614. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  1615. if (move_menu_scale < 10.0)
  1616. {
  1617. if (!isPrintPaused)
  1618. {
  1619. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  1620. }
  1621. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  1622. }
  1623. END_MENU();
  1624. }
  1625. static void lcd_move_menu_1mm()
  1626. {
  1627. move_menu_scale = 1.0;
  1628. lcd_move_menu_axis();
  1629. }
  1630. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  1631. {
  1632. do
  1633. {
  1634. eeprom_write_byte((unsigned char*)pos, *value);
  1635. pos++;
  1636. value++;
  1637. } while (--size);
  1638. }
  1639. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  1640. {
  1641. do
  1642. {
  1643. *value = eeprom_read_byte((unsigned char*)pos);
  1644. pos++;
  1645. value++;
  1646. } while (--size);
  1647. }
  1648. static void lcd_silent_mode_set() {
  1649. SilentModeMenu = !SilentModeMenu;
  1650. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  1651. digipot_init();
  1652. lcd_goto_menu(lcd_settings_menu, 7);
  1653. }
  1654. static void lcd_set_lang(unsigned char lang) {
  1655. lang_selected = lang;
  1656. firstrun = 1;
  1657. eeprom_update_byte((unsigned char *)EEPROM_LANG, lang);
  1658. /*langsel=0;*/
  1659. if (langsel == LANGSEL_MODAL)
  1660. // From modal mode to an active mode? This forces the menu to return to the setup menu.
  1661. langsel = LANGSEL_ACTIVE;
  1662. }
  1663. void lcd_force_language_selection() {
  1664. eeprom_update_byte((unsigned char *)EEPROM_LANG, LANG_ID_FORCE_SELECTION);
  1665. }
  1666. static void lcd_language_menu()
  1667. {
  1668. START_MENU();
  1669. if (langsel == LANGSEL_OFF) {
  1670. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  1671. } else if (langsel == LANGSEL_ACTIVE) {
  1672. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  1673. }
  1674. for (int i=0;i<LANG_NUM;i++){
  1675. MENU_ITEM(setlang, MSG_LANGUAGE_NAME_EXPLICIT(i), i);
  1676. }
  1677. END_MENU();
  1678. }
  1679. void lcd_mesh_bedleveling()
  1680. {
  1681. enquecommand_P(PSTR("G80"));
  1682. lcd_return_to_status();
  1683. }
  1684. void lcd_mesh_calibration()
  1685. {
  1686. enquecommand_P(PSTR("M45"));
  1687. lcd_return_to_status();
  1688. }
  1689. void lcd_mesh_calibration_z()
  1690. {
  1691. enquecommand_P(PSTR("M45 Z"));
  1692. lcd_return_to_status();
  1693. }
  1694. void lcd_toshiba_flash_air_compatibility_toggle()
  1695. {
  1696. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  1697. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  1698. }
  1699. static void lcd_settings_menu()
  1700. {
  1701. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  1702. START_MENU();
  1703. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1704. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1705. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu_1mm);
  1706. if (!isPrintPaused)
  1707. {
  1708. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  1709. }
  1710. if (SilentModeMenu == 0) {
  1711. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  1712. } else {
  1713. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  1714. }
  1715. if (!isPrintPaused)
  1716. {
  1717. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  1718. }
  1719. MENU_ITEM(submenu, MSG_LANGUAGE_SELECT, lcd_language_menu);
  1720. if (card.ToshibaFlashAir_isEnabled()) {
  1721. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON, lcd_toshiba_flash_air_compatibility_toggle);
  1722. } else {
  1723. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF, lcd_toshiba_flash_air_compatibility_toggle);
  1724. }
  1725. if (farm_mode)
  1726. {
  1727. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  1728. }
  1729. END_MENU();
  1730. }
  1731. static void lcd_calibration_menu()
  1732. {
  1733. START_MENU();
  1734. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1735. if (!isPrintPaused)
  1736. {
  1737. MENU_ITEM(submenu, MSG_SELFTEST, lcd_selftest);
  1738. #ifndef MESH_BED_LEVELING
  1739. // MK1
  1740. // "Calibrate Z"
  1741. MENU_ITEM(gcode, MSG_HOMEYZ, PSTR("G28 Z"));
  1742. #else
  1743. // MK2
  1744. MENU_ITEM(submenu, MSG_CALIBRATE_BED, lcd_mesh_calibration);
  1745. // "Calibrate Z" with storing the reference values to EEPROM.
  1746. MENU_ITEM(submenu, MSG_HOMEYZ, lcd_mesh_calibration_z);
  1747. // "Mesh Bed Leveling"
  1748. MENU_ITEM(submenu, MSG_MESH_BED_LEVELING, lcd_mesh_bedleveling);
  1749. #endif
  1750. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28 W"));
  1751. MENU_ITEM(submenu, MSG_BED_CORRECTION_MENU, lcd_adjust_bed);
  1752. MENU_ITEM(submenu, MSG_SHOW_END_STOPS, menu_show_end_stops);
  1753. MENU_ITEM(gcode, MSG_CALIBRATE_BED_RESET, PSTR("M44"));
  1754. }
  1755. END_MENU();
  1756. }
  1757. /*
  1758. void lcd_mylang_top(int hlaska) {
  1759. lcd.setCursor(0,0);
  1760. lcd.print(" ");
  1761. lcd.setCursor(0,0);
  1762. lcd_printPGM(MSG_ALL[hlaska-1][LANGUAGE_SELECT]);
  1763. }
  1764. void lcd_mylang_drawmenu(int cursor) {
  1765. int first = 0;
  1766. if (cursor>2) first = cursor-2;
  1767. if (cursor==LANG_NUM) first = LANG_NUM-3;
  1768. lcd.setCursor(0, 1);
  1769. lcd.print(" ");
  1770. lcd.setCursor(1, 1);
  1771. lcd_printPGM(MSG_ALL[first][LANGUAGE_NAME]);
  1772. lcd.setCursor(0, 2);
  1773. lcd.print(" ");
  1774. lcd.setCursor(1, 2);
  1775. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  1776. lcd.setCursor(0, 3);
  1777. lcd.print(" ");
  1778. lcd.setCursor(1, 3);
  1779. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  1780. if (cursor==1) lcd.setCursor(0, 1);
  1781. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  1782. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  1783. lcd.print(">");
  1784. if (cursor<LANG_NUM-1) {
  1785. lcd.setCursor(19,3);
  1786. lcd.print("\x01");
  1787. }
  1788. if (cursor>2) {
  1789. lcd.setCursor(19,1);
  1790. lcd.print("^");
  1791. }
  1792. }
  1793. */
  1794. void lcd_mylang_drawmenu(int cursor) {
  1795. int first = 0;
  1796. if (cursor>3) first = cursor-3;
  1797. if (cursor==LANG_NUM && LANG_NUM>4) first = LANG_NUM-4;
  1798. if (cursor==LANG_NUM && LANG_NUM==4) first = LANG_NUM-4;
  1799. lcd.setCursor(0, 0);
  1800. lcd.print(" ");
  1801. lcd.setCursor(1, 0);
  1802. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+0));
  1803. lcd.setCursor(0, 1);
  1804. lcd.print(" ");
  1805. lcd.setCursor(1, 1);
  1806. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+1));
  1807. lcd.setCursor(0, 2);
  1808. lcd.print(" ");
  1809. if (LANG_NUM > 2){
  1810. lcd.setCursor(1, 2);
  1811. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+2));
  1812. }
  1813. lcd.setCursor(0, 3);
  1814. lcd.print(" ");
  1815. if (LANG_NUM>3) {
  1816. lcd.setCursor(1, 3);
  1817. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+3));
  1818. }
  1819. if (cursor==1) lcd.setCursor(0, 0);
  1820. if (cursor==2) lcd.setCursor(0, 1);
  1821. if (cursor>2) lcd.setCursor(0, 2);
  1822. if (cursor==LANG_NUM && LANG_NUM>3) lcd.setCursor(0, 3);
  1823. lcd.print(">");
  1824. if (cursor<LANG_NUM-1 && LANG_NUM>4) {
  1825. lcd.setCursor(19,3);
  1826. lcd.print("\x01");
  1827. }
  1828. if (cursor>3 && LANG_NUM>4) {
  1829. lcd.setCursor(19,0);
  1830. lcd.print("^");
  1831. }
  1832. }
  1833. void lcd_set_custom_characters_arrows();
  1834. void lcd_set_custom_characters_degree();
  1835. void lcd_mylang_drawcursor(int cursor) {
  1836. if (cursor==1) lcd.setCursor(0, 1);
  1837. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  1838. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  1839. lcd.print(">");
  1840. }
  1841. void lcd_mylang() {
  1842. int enc_dif = 0;
  1843. int cursor_pos = 1;
  1844. lang_selected=255;
  1845. int hlaska=1;
  1846. int counter=0;
  1847. lcd_set_custom_characters_arrows();
  1848. lcd_implementation_clear();
  1849. //lcd_mylang_top(hlaska);
  1850. lcd_mylang_drawmenu(cursor_pos);
  1851. enc_dif = encoderDiff;
  1852. while ( (lang_selected == 255) && (MYSERIAL.available() < 2) ) {
  1853. manage_heater();
  1854. manage_inactivity(true);
  1855. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1856. //if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1857. if (enc_dif > encoderDiff ) {
  1858. cursor_pos --;
  1859. }
  1860. if (enc_dif < encoderDiff ) {
  1861. cursor_pos ++;
  1862. }
  1863. if (cursor_pos > LANG_NUM) {
  1864. cursor_pos = LANG_NUM;
  1865. }
  1866. if (cursor_pos < 1) {
  1867. cursor_pos = 1;
  1868. }
  1869. lcd_mylang_drawmenu(cursor_pos);
  1870. enc_dif = encoderDiff;
  1871. delay(100);
  1872. //}
  1873. } else delay(20);
  1874. if (lcd_clicked()) {
  1875. lcd_set_lang(cursor_pos-1);
  1876. delay(500);
  1877. }
  1878. /*
  1879. if (++counter == 80) {
  1880. hlaska++;
  1881. if(hlaska>LANG_NUM) hlaska=1;
  1882. lcd_mylang_top(hlaska);
  1883. lcd_mylang_drawcursor(cursor_pos);
  1884. counter=0;
  1885. }
  1886. */
  1887. };
  1888. if(MYSERIAL.available() > 1){
  1889. lang_selected = 0;
  1890. firstrun = 0;
  1891. }
  1892. lcd_set_custom_characters_degree();
  1893. lcd_implementation_clear();
  1894. lcd_return_to_status();
  1895. }
  1896. static void lcd_farm_no()
  1897. {
  1898. int enc_dif = 0;
  1899. int _farmno = farm_no;
  1900. int _ret = 0;
  1901. lcd_implementation_clear();
  1902. lcd.setCursor(0, 0);
  1903. lcd.print("Farm no");
  1904. do
  1905. {
  1906. if (abs((enc_dif - encoderDiff)) > 2) {
  1907. if (enc_dif > encoderDiff) {
  1908. _farmno--;
  1909. }
  1910. if (enc_dif < encoderDiff) {
  1911. _farmno++;
  1912. }
  1913. enc_dif = 0;
  1914. encoderDiff = 0;
  1915. }
  1916. if (_farmno > 254) { _farmno = 1; }
  1917. if (_farmno < 1) { _farmno = 254; }
  1918. lcd.setCursor(0, 2);
  1919. lcd.print(_farmno);
  1920. lcd.print(" ");
  1921. delay(100);
  1922. if (lcd_clicked())
  1923. {
  1924. _ret = 1;
  1925. farm_no = _farmno;
  1926. EEPROM_save_B(EEPROM_FARM_MODE, &farm_no);
  1927. prusa_statistics(20);
  1928. lcd_return_to_status();
  1929. }
  1930. manage_heater();
  1931. } while (_ret == 0);
  1932. }
  1933. void lcd_confirm_print()
  1934. {
  1935. int enc_dif = 0;
  1936. int cursor_pos = 1;
  1937. int _ret = 0;
  1938. int _t = 0;
  1939. lcd_implementation_clear();
  1940. lcd.setCursor(0, 0);
  1941. lcd.print("Print ok ?");
  1942. do
  1943. {
  1944. if (abs((enc_dif - encoderDiff)) > 2) {
  1945. if (enc_dif > encoderDiff) {
  1946. cursor_pos--;
  1947. }
  1948. if (enc_dif < encoderDiff) {
  1949. cursor_pos++;
  1950. }
  1951. }
  1952. if (cursor_pos > 2) { cursor_pos = 2; }
  1953. if (cursor_pos < 1) { cursor_pos = 1; }
  1954. lcd.setCursor(0, 2); lcd.print(" ");
  1955. lcd.setCursor(0, 3); lcd.print(" ");
  1956. lcd.setCursor(2, 2);
  1957. lcd_printPGM(MSG_YES);
  1958. lcd.setCursor(2, 3);
  1959. lcd_printPGM(MSG_NO);
  1960. lcd.setCursor(0, 1 + cursor_pos);
  1961. lcd.print(">");
  1962. delay(100);
  1963. _t = _t + 1;
  1964. if (_t>100)
  1965. {
  1966. prusa_statistics(99);
  1967. _t = 0;
  1968. }
  1969. if (lcd_clicked())
  1970. {
  1971. if (cursor_pos == 1)
  1972. {
  1973. _ret = 1;
  1974. prusa_statistics(20);
  1975. prusa_statistics(4);
  1976. }
  1977. if (cursor_pos == 2)
  1978. {
  1979. _ret = 2;
  1980. prusa_statistics(20);
  1981. prusa_statistics(5);
  1982. }
  1983. }
  1984. manage_heater();
  1985. manage_inactivity();
  1986. } while (_ret == 0);
  1987. }
  1988. static void lcd_main_menu()
  1989. {
  1990. SDscrool = 0;
  1991. START_MENU();
  1992. // Majkl superawesome menu
  1993. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  1994. if ( ( IS_SD_PRINTING || is_usb_printing ) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) )
  1995. {
  1996. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  1997. }
  1998. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing )
  1999. {
  2000. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  2001. } else
  2002. {
  2003. MENU_ITEM(submenu, MSG_PREHEAT, lcd_preheat_menu);
  2004. }
  2005. #ifdef SDSUPPORT
  2006. if (card.cardOK)
  2007. {
  2008. if (card.isFileOpen())
  2009. {
  2010. if (card.sdprinting)
  2011. {
  2012. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  2013. }
  2014. else
  2015. {
  2016. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  2017. }
  2018. MENU_ITEM(submenu, MSG_STOP_PRINT, lcd_sdcard_stop);
  2019. }
  2020. else
  2021. {
  2022. if (!is_usb_printing)
  2023. {
  2024. MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  2025. }
  2026. #if SDCARDDETECT < 1
  2027. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  2028. #endif
  2029. }
  2030. } else
  2031. {
  2032. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  2033. #if SDCARDDETECT < 1
  2034. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  2035. #endif
  2036. }
  2037. #endif
  2038. if (IS_SD_PRINTING || is_usb_printing)
  2039. {
  2040. }
  2041. else
  2042. {
  2043. MENU_ITEM(function, MSG_LOAD_FILAMENT, lcd_LoadFilament);
  2044. MENU_ITEM(function, MSG_UNLOAD_FILAMENT, lcd_unLoadFilament);
  2045. MENU_ITEM(submenu, MSG_SETTINGS, lcd_settings_menu);
  2046. MENU_ITEM(submenu, MSG_MENU_CALIBRATION, lcd_calibration_menu);
  2047. }
  2048. if (!is_usb_printing)
  2049. {
  2050. MENU_ITEM(submenu, MSG_STATISTICS, lcd_menu_statistics);
  2051. }
  2052. MENU_ITEM(submenu, MSG_SUPPORT, lcd_support_menu);
  2053. END_MENU();
  2054. }
  2055. #ifdef SDSUPPORT
  2056. static void lcd_autostart_sd()
  2057. {
  2058. card.lastnr = 0;
  2059. card.setroot();
  2060. card.checkautostart(true);
  2061. }
  2062. #endif
  2063. static void lcd_silent_mode_set_tune() {
  2064. SilentModeMenu = !SilentModeMenu;
  2065. eeprom_update_byte((unsigned char*)EEPROM_SILENT, SilentModeMenu);
  2066. digipot_init();
  2067. lcd_goto_menu(lcd_tune_menu, 9);
  2068. }
  2069. static void lcd_tune_menu()
  2070. {
  2071. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  2072. START_MENU();
  2073. MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1
  2074. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2
  2075. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  2076. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  2077. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5
  2078. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6
  2079. #ifdef FILAMENTCHANGEENABLE
  2080. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));//7
  2081. #endif
  2082. if (SilentModeMenu == 0) {
  2083. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set_tune);
  2084. } else {
  2085. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set_tune);
  2086. }
  2087. END_MENU();
  2088. }
  2089. static void lcd_move_menu_01mm()
  2090. {
  2091. move_menu_scale = 0.1;
  2092. lcd_move_menu_axis();
  2093. }
  2094. static void lcd_control_temperature_menu()
  2095. {
  2096. #ifdef PIDTEMP
  2097. // set up temp variables - undo the default scaling
  2098. // raw_Ki = unscalePID_i(Ki);
  2099. // raw_Kd = unscalePID_d(Kd);
  2100. #endif
  2101. START_MENU();
  2102. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  2103. #if TEMP_SENSOR_0 != 0
  2104. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  2105. #endif
  2106. #if TEMP_SENSOR_1 != 0
  2107. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  2108. #endif
  2109. #if TEMP_SENSOR_2 != 0
  2110. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  2111. #endif
  2112. #if TEMP_SENSOR_BED != 0
  2113. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 3);
  2114. #endif
  2115. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  2116. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  2117. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  2118. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  2119. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  2120. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  2121. #endif
  2122. END_MENU();
  2123. }
  2124. #if SDCARDDETECT == -1
  2125. static void lcd_sd_refresh()
  2126. {
  2127. card.initsd();
  2128. currentMenuViewOffset = 0;
  2129. }
  2130. #endif
  2131. static void lcd_sd_updir()
  2132. {
  2133. SDscrool = 0;
  2134. card.updir();
  2135. currentMenuViewOffset = 0;
  2136. }
  2137. void lcd_sdcard_stop()
  2138. {
  2139. lcd.setCursor(0, 0);
  2140. lcd_printPGM(MSG_STOP_PRINT);
  2141. lcd.setCursor(2, 2);
  2142. lcd_printPGM(MSG_NO);
  2143. lcd.setCursor(2, 3);
  2144. lcd_printPGM(MSG_YES);
  2145. lcd.setCursor(0, 2); lcd.print(" ");
  2146. lcd.setCursor(0, 3); lcd.print(" ");
  2147. if ((int32_t)encoderPosition > 2) { encoderPosition = 2; }
  2148. if ((int32_t)encoderPosition < 1) { encoderPosition = 1; }
  2149. lcd.setCursor(0, 1 + encoderPosition);
  2150. lcd.print(">");
  2151. if (lcd_clicked())
  2152. {
  2153. if ((int32_t)encoderPosition == 1)
  2154. {
  2155. lcd_return_to_status();
  2156. }
  2157. if ((int32_t)encoderPosition == 2)
  2158. {
  2159. cancel_heatup = true;
  2160. // Stop the stoppers, update the position from the stoppers.
  2161. planner_abort_hard();
  2162. // Clean the input command queue.
  2163. cmdqueue_reset();
  2164. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  2165. card.sdprinting = false;
  2166. card.closefile();
  2167. stoptime = millis();
  2168. unsigned long t = (stoptime - starttime) / 1000;
  2169. save_statistics(total_filament_used, t);
  2170. lcd_return_to_status();
  2171. lcd_ignore_click(true);
  2172. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  2173. }
  2174. }
  2175. }
  2176. void lcd_sdcard_menu()
  2177. {
  2178. int tempScrool = 0;
  2179. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  2180. //delay(100);
  2181. return; // nothing to do (so don't thrash the SD card)
  2182. uint16_t fileCnt = card.getnrfilenames();
  2183. START_MENU();
  2184. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2185. card.getWorkDirName();
  2186. if (card.filename[0] == '/')
  2187. {
  2188. #if SDCARDDETECT == -1
  2189. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  2190. #endif
  2191. } else {
  2192. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  2193. }
  2194. for (uint16_t i = 0; i < fileCnt; i++)
  2195. {
  2196. if (_menuItemNr == _lineNr)
  2197. {
  2198. #ifndef SDCARD_RATHERRECENTFIRST
  2199. card.getfilename(i);
  2200. #else
  2201. card.getfilename(fileCnt - 1 - i);
  2202. #endif
  2203. if (card.filenameIsDir)
  2204. {
  2205. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  2206. } else {
  2207. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  2208. }
  2209. } else {
  2210. MENU_ITEM_DUMMY();
  2211. }
  2212. }
  2213. END_MENU();
  2214. }
  2215. #define menu_edit_type(_type, _name, _strFunc, scale) \
  2216. void menu_edit_ ## _name () \
  2217. { \
  2218. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  2219. if ((int32_t)encoderPosition > menuData.editMenuParentState.maxEditValue) encoderPosition = menuData.editMenuParentState.maxEditValue; \
  2220. if (lcdDrawUpdate) \
  2221. lcd_implementation_drawedit(menuData.editMenuParentState.editLabel, _strFunc(((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale)); \
  2222. if (LCD_CLICKED) \
  2223. { \
  2224. *((_type*)menuData.editMenuParentState.editValue) = ((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale; \
  2225. lcd_goto_menu(menuData.editMenuParentState.prevMenu, menuData.editMenuParentState.prevEncoderPosition, true, false); \
  2226. } \
  2227. } \
  2228. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  2229. { \
  2230. menuData.editMenuParentState.prevMenu = currentMenu; \
  2231. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  2232. \
  2233. lcdDrawUpdate = 2; \
  2234. menuData.editMenuParentState.editLabel = pstr; \
  2235. menuData.editMenuParentState.editValue = ptr; \
  2236. menuData.editMenuParentState.minEditValue = minValue * scale; \
  2237. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  2238. lcd_goto_menu(menu_edit_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  2239. \
  2240. }\
  2241. /*
  2242. void menu_edit_callback_ ## _name () { \
  2243. menu_edit_ ## _name (); \
  2244. if (LCD_CLICKED) (*callbackFunc)(); \
  2245. } \
  2246. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  2247. { \
  2248. menuData.editMenuParentState.prevMenu = currentMenu; \
  2249. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  2250. \
  2251. lcdDrawUpdate = 2; \
  2252. lcd_goto_menu(menu_edit_callback_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  2253. \
  2254. menuData.editMenuParentState.editLabel = pstr; \
  2255. menuData.editMenuParentState.editValue = ptr; \
  2256. menuData.editMenuParentState.minEditValue = minValue * scale; \
  2257. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  2258. callbackFunc = callback;\
  2259. }
  2260. */
  2261. menu_edit_type(int, int3, itostr3, 1)
  2262. menu_edit_type(float, float3, ftostr3, 1)
  2263. menu_edit_type(float, float32, ftostr32, 100)
  2264. menu_edit_type(float, float43, ftostr43, 1000)
  2265. menu_edit_type(float, float5, ftostr5, 0.01)
  2266. menu_edit_type(float, float51, ftostr51, 10)
  2267. menu_edit_type(float, float52, ftostr52, 100)
  2268. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  2269. static void lcd_selftest()
  2270. {
  2271. int _progress = 0;
  2272. bool _result = false;
  2273. _progress = lcd_selftest_screen(-1, _progress, 4, true, 2000);
  2274. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  2275. _result = lcd_selfcheck_endstops();
  2276. if (_result)
  2277. {
  2278. _progress = lcd_selftest_screen(1, _progress, 3, true, 1000);
  2279. _result = lcd_selfcheck_check_heater(false);
  2280. }
  2281. if (_result)
  2282. {
  2283. _progress = lcd_selftest_screen(2, _progress, 3, true, 2000);
  2284. _result = lcd_selfcheck_axis(0, X_MAX_POS);
  2285. }
  2286. if (_result)
  2287. {
  2288. _progress = lcd_selftest_screen(3, _progress, 3, true, 1500);
  2289. _result = lcd_selfcheck_axis(1, Y_MAX_POS);
  2290. }
  2291. if (_result)
  2292. {
  2293. current_position[X_AXIS] = current_position[X_AXIS] - 3;
  2294. current_position[Y_AXIS] = current_position[Y_AXIS] - 14;
  2295. _progress = lcd_selftest_screen(4, _progress, 3, true, 1500);
  2296. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  2297. }
  2298. if (_result)
  2299. {
  2300. _progress = lcd_selftest_screen(5, _progress, 3, true, 2000);
  2301. _result = lcd_selfcheck_check_heater(true);
  2302. }
  2303. if (_result)
  2304. {
  2305. _progress = lcd_selftest_screen(6, _progress, 3, true, 5000);
  2306. }
  2307. else
  2308. {
  2309. _progress = lcd_selftest_screen(7, _progress, 3, true, 5000);
  2310. }
  2311. lcd_implementation_clear();
  2312. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  2313. if (_result)
  2314. {
  2315. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_OK);
  2316. }
  2317. else
  2318. {
  2319. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  2320. }
  2321. }
  2322. static bool lcd_selfcheck_endstops()
  2323. {
  2324. bool _result = true;
  2325. 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)
  2326. {
  2327. current_position[0] = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? current_position[0] = current_position[0] + 10 : current_position[0];
  2328. current_position[1] = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? current_position[1] = current_position[1] + 10 : current_position[1];
  2329. current_position[2] = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? current_position[2] = current_position[2] + 10 : current_position[2];
  2330. }
  2331. 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);
  2332. delay(500);
  2333. 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)
  2334. {
  2335. _result = false;
  2336. String _error = String((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? "X" : "") +
  2337. String((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? "Y" : "") +
  2338. String((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? "Z" : "");
  2339. lcd_selftest_error(3, _error.c_str(), "");
  2340. }
  2341. manage_heater();
  2342. manage_inactivity();
  2343. return _result;
  2344. }
  2345. static bool lcd_selfcheck_axis(int _axis, int _travel)
  2346. {
  2347. bool _stepdone = false;
  2348. bool _stepresult = false;
  2349. int _progress = 0;
  2350. int _travel_done = 0;
  2351. int _err_endstop = 0;
  2352. int _lcd_refresh = 0;
  2353. _travel = _travel + (_travel / 10);
  2354. do {
  2355. if (_axis == 2)
  2356. {
  2357. current_position[_axis] = current_position[_axis] - 1;
  2358. }
  2359. else
  2360. {
  2361. current_position[_axis] = current_position[_axis] - 3;
  2362. }
  2363. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  2364. st_synchronize();
  2365. 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)
  2366. {
  2367. if (_axis == 0)
  2368. {
  2369. _stepresult = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  2370. _err_endstop = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? 1 : 2;
  2371. disable_x();
  2372. }
  2373. if (_axis == 1)
  2374. {
  2375. _stepresult = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  2376. _err_endstop = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? 0 : 2;
  2377. disable_y();
  2378. }
  2379. if (_axis == 2)
  2380. {
  2381. _stepresult = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  2382. _err_endstop = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? 0 : 1;
  2383. disable_z();
  2384. }
  2385. _stepdone = true;
  2386. }
  2387. if (_lcd_refresh < 6)
  2388. {
  2389. _lcd_refresh++;
  2390. }
  2391. else
  2392. {
  2393. _progress = lcd_selftest_screen(2 + _axis, _progress, 3, false, 0);
  2394. _lcd_refresh = 0;
  2395. }
  2396. manage_heater();
  2397. manage_inactivity();
  2398. delay(100);
  2399. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  2400. } while (!_stepdone);
  2401. current_position[_axis] = current_position[_axis] + 15;
  2402. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  2403. if (!_stepresult)
  2404. {
  2405. const char *_error_1;
  2406. const char *_error_2;
  2407. if (_axis == X_AXIS) _error_1 = "X";
  2408. if (_axis == Y_AXIS) _error_1 = "Y";
  2409. if (_axis == Z_AXIS) _error_1 = "Z";
  2410. if (_err_endstop == 0) _error_2 = "X";
  2411. if (_err_endstop == 1) _error_2 = "Y";
  2412. if (_err_endstop == 2) _error_2 = "Z";
  2413. if (_travel_done >= _travel)
  2414. {
  2415. lcd_selftest_error(5, _error_1, _error_2);
  2416. }
  2417. else
  2418. {
  2419. lcd_selftest_error(4, _error_1, _error_2);
  2420. }
  2421. }
  2422. return _stepresult;
  2423. }
  2424. static bool lcd_selfcheck_check_heater(bool _isbed)
  2425. {
  2426. int _counter = 0;
  2427. int _progress = 0;
  2428. bool _stepresult = false;
  2429. bool _docycle = true;
  2430. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  2431. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  2432. int _cycles = (_isbed) ? 120 : 30;
  2433. target_temperature[0] = (_isbed) ? 0 : 100;
  2434. target_temperature_bed = (_isbed) ? 100 : 0;
  2435. manage_heater();
  2436. manage_inactivity();
  2437. do {
  2438. _counter++;
  2439. (_counter < _cycles) ? _docycle = true : _docycle = false;
  2440. manage_heater();
  2441. manage_inactivity();
  2442. _progress = (_isbed) ? lcd_selftest_screen(5, _progress, 2, false, 400) : lcd_selftest_screen(1, _progress, 2, false, 400);
  2443. } while (_docycle);
  2444. target_temperature[0] = 0;
  2445. target_temperature_bed = 0;
  2446. manage_heater();
  2447. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  2448. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  2449. if (_opposite_result < (_isbed) ? 10 : 3)
  2450. {
  2451. if (_checked_result >= (_isbed) ? 3 : 10)
  2452. {
  2453. _stepresult = true;
  2454. }
  2455. else
  2456. {
  2457. lcd_selftest_error(1, "", "");
  2458. }
  2459. }
  2460. else
  2461. {
  2462. lcd_selftest_error(2, "", "");
  2463. }
  2464. manage_heater();
  2465. manage_inactivity();
  2466. return _stepresult;
  2467. }
  2468. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  2469. {
  2470. lcd_implementation_quick_feedback();
  2471. target_temperature[0] = 0;
  2472. target_temperature_bed = 0;
  2473. manage_heater();
  2474. manage_inactivity();
  2475. lcd_implementation_clear();
  2476. lcd.setCursor(0, 0);
  2477. lcd_printPGM(MSG_SELFTEST_ERROR);
  2478. lcd.setCursor(0, 1);
  2479. lcd_printPGM(MSG_SELFTEST_PLEASECHECK);
  2480. switch (_error_no)
  2481. {
  2482. case 1:
  2483. lcd.setCursor(0, 2);
  2484. lcd_printPGM(MSG_SELFTEST_HEATERTHERMISTOR);
  2485. lcd.setCursor(0, 3);
  2486. lcd_printPGM(MSG_SELFTEST_NOTCONNECTED);
  2487. break;
  2488. case 2:
  2489. lcd.setCursor(0, 2);
  2490. lcd_printPGM(MSG_SELFTEST_BEDHEATER);
  2491. lcd.setCursor(0, 3);
  2492. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  2493. break;
  2494. case 3:
  2495. lcd.setCursor(0, 2);
  2496. lcd_printPGM(MSG_SELFTEST_ENDSTOPS);
  2497. lcd.setCursor(0, 3);
  2498. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  2499. lcd.setCursor(17, 3);
  2500. lcd.print(_error_1);
  2501. break;
  2502. case 4:
  2503. lcd.setCursor(0, 2);
  2504. lcd_printPGM(MSG_SELFTEST_MOTOR);
  2505. lcd.setCursor(18, 2);
  2506. lcd.print(_error_1);
  2507. lcd.setCursor(0, 3);
  2508. lcd_printPGM(MSG_SELFTEST_ENDSTOP);
  2509. lcd.setCursor(18, 3);
  2510. lcd.print(_error_2);
  2511. break;
  2512. case 5:
  2513. lcd.setCursor(0, 2);
  2514. lcd_printPGM(MSG_SELFTEST_ENDSTOP_NOTHIT);
  2515. lcd.setCursor(0, 3);
  2516. lcd_printPGM(MSG_SELFTEST_MOTOR);
  2517. lcd.setCursor(18, 3);
  2518. lcd.print(_error_1);
  2519. break;
  2520. }
  2521. delay(1000);
  2522. lcd_implementation_quick_feedback();
  2523. do {
  2524. delay(100);
  2525. manage_heater();
  2526. manage_inactivity();
  2527. } while (!lcd_clicked());
  2528. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  2529. lcd_return_to_status();
  2530. }
  2531. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  2532. {
  2533. lcd_next_update_millis = millis() + (LCD_UPDATE_INTERVAL * 10000);
  2534. int _step_block = 0;
  2535. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  2536. if (_clear) lcd_implementation_clear();
  2537. lcd.setCursor(0, 0);
  2538. if (_step == -1) lcd_printPGM(MSG_SELFTEST_START);
  2539. if (_step == 0) lcd_printPGM(MSG_SELFTEST_CHECK_ENDSTOPS);
  2540. if (_step == 1) lcd_printPGM(MSG_SELFTEST_CHECK_HOTEND);
  2541. if (_step == 2) lcd_printPGM(MSG_SELFTEST_CHECK_X);
  2542. if (_step == 3) lcd_printPGM(MSG_SELFTEST_CHECK_Y);
  2543. if (_step == 4) lcd_printPGM(MSG_SELFTEST_CHECK_Z);
  2544. if (_step == 5) lcd_printPGM(MSG_SELFTEST_CHECK_BED);
  2545. if (_step == 6) lcd_printPGM(MSG_SELFTEST_CHECK_ALLCORRECT);
  2546. if (_step == 7) lcd_printPGM(MSG_SELFTEST_FAILED);
  2547. lcd.setCursor(0, 1);
  2548. lcd.print("--------------------");
  2549. _step_block = 1;
  2550. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  2551. _step_block = 2;
  2552. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  2553. _step_block = 3;
  2554. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  2555. _step_block = 4;
  2556. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  2557. _step_block = 5;
  2558. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  2559. if (_delay > 0) delay(_delay);
  2560. _progress++;
  2561. return (_progress > _progress_scale * 2) ? 0 : _progress;
  2562. }
  2563. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  2564. {
  2565. lcd.setCursor(_col, _row);
  2566. switch (_state)
  2567. {
  2568. case 1:
  2569. lcd.print(_name);
  2570. lcd.setCursor(_col + strlen(_name), _row);
  2571. lcd.print(":");
  2572. lcd.setCursor(_col + strlen(_name) + 1, _row);
  2573. lcd.print(_indicator);
  2574. break;
  2575. case 2:
  2576. lcd.print(_name);
  2577. lcd.setCursor(_col + strlen(_name), _row);
  2578. lcd.print(":");
  2579. lcd.setCursor(_col + strlen(_name) + 1, _row);
  2580. lcd.print("OK");
  2581. break;
  2582. default:
  2583. lcd.print(_name);
  2584. }
  2585. }
  2586. /** End of menus **/
  2587. static void lcd_quick_feedback()
  2588. {
  2589. lcdDrawUpdate = 2;
  2590. blocking_enc = millis() + 500;
  2591. lcd_implementation_quick_feedback();
  2592. }
  2593. /** Menu action functions **/
  2594. static void menu_action_back(menuFunc_t data) {
  2595. lcd_goto_menu(data);
  2596. }
  2597. static void menu_action_submenu(menuFunc_t data) {
  2598. lcd_goto_menu(data);
  2599. }
  2600. static void menu_action_gcode(const char* pgcode) {
  2601. enquecommand_P(pgcode);
  2602. }
  2603. static void menu_action_setlang(unsigned char lang) {
  2604. lcd_set_lang(lang);
  2605. }
  2606. static void menu_action_function(menuFunc_t data) {
  2607. (*data)();
  2608. }
  2609. static void menu_action_sdfile(const char* filename, char* longFilename)
  2610. {
  2611. char cmd[30];
  2612. char* c;
  2613. sprintf_P(cmd, PSTR("M23 %s"), filename);
  2614. for (c = &cmd[4]; *c; c++)
  2615. *c = tolower(*c);
  2616. enquecommand(cmd);
  2617. enquecommand_P(PSTR("M24"));
  2618. lcd_return_to_status();
  2619. }
  2620. static void menu_action_sddirectory(const char* filename, char* longFilename)
  2621. {
  2622. card.chdir(filename);
  2623. encoderPosition = 0;
  2624. }
  2625. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  2626. {
  2627. *ptr = !(*ptr);
  2628. }
  2629. /*
  2630. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  2631. {
  2632. menu_action_setting_edit_bool(pstr, ptr);
  2633. (*callback)();
  2634. }
  2635. */
  2636. #endif//ULTIPANEL
  2637. /** LCD API **/
  2638. void lcd_init()
  2639. {
  2640. lcd_implementation_init();
  2641. #ifdef NEWPANEL
  2642. SET_INPUT(BTN_EN1);
  2643. SET_INPUT(BTN_EN2);
  2644. WRITE(BTN_EN1, HIGH);
  2645. WRITE(BTN_EN2, HIGH);
  2646. #if BTN_ENC > 0
  2647. SET_INPUT(BTN_ENC);
  2648. WRITE(BTN_ENC, HIGH);
  2649. #endif
  2650. #ifdef REPRAPWORLD_KEYPAD
  2651. pinMode(SHIFT_CLK, OUTPUT);
  2652. pinMode(SHIFT_LD, OUTPUT);
  2653. pinMode(SHIFT_OUT, INPUT);
  2654. WRITE(SHIFT_OUT, HIGH);
  2655. WRITE(SHIFT_LD, HIGH);
  2656. #endif
  2657. #else // Not NEWPANEL
  2658. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  2659. pinMode (SR_DATA_PIN, OUTPUT);
  2660. pinMode (SR_CLK_PIN, OUTPUT);
  2661. #elif defined(SHIFT_CLK)
  2662. pinMode(SHIFT_CLK, OUTPUT);
  2663. pinMode(SHIFT_LD, OUTPUT);
  2664. pinMode(SHIFT_EN, OUTPUT);
  2665. pinMode(SHIFT_OUT, INPUT);
  2666. WRITE(SHIFT_OUT, HIGH);
  2667. WRITE(SHIFT_LD, HIGH);
  2668. WRITE(SHIFT_EN, LOW);
  2669. #else
  2670. #ifdef ULTIPANEL
  2671. #error ULTIPANEL requires an encoder
  2672. #endif
  2673. #endif // SR_LCD_2W_NL
  2674. #endif//!NEWPANEL
  2675. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  2676. pinMode(SDCARDDETECT, INPUT);
  2677. WRITE(SDCARDDETECT, HIGH);
  2678. lcd_oldcardstatus = IS_SD_INSERTED;
  2679. #endif//(SDCARDDETECT > 0)
  2680. #ifdef LCD_HAS_SLOW_BUTTONS
  2681. slow_buttons = 0;
  2682. #endif
  2683. lcd_buttons_update();
  2684. #ifdef ULTIPANEL
  2685. encoderDiff = 0;
  2686. #endif
  2687. }
  2688. //#include <avr/pgmspace.h>
  2689. static volatile bool lcd_update_enabled = true;
  2690. void lcd_update_enable(bool enabled)
  2691. {
  2692. lcd_update_enabled = enabled;
  2693. }
  2694. void lcd_update(uint8_t lcdDrawUpdateOverride)
  2695. {
  2696. if (lcdDrawUpdate < lcdDrawUpdateOverride)
  2697. lcdDrawUpdate = lcdDrawUpdateOverride;
  2698. static unsigned long timeoutToStatus = 0;
  2699. if (! lcd_update_enabled)
  2700. return;
  2701. #ifdef LCD_HAS_SLOW_BUTTONS
  2702. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  2703. #endif
  2704. lcd_buttons_update();
  2705. #if (SDCARDDETECT > 0)
  2706. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  2707. {
  2708. lcdDrawUpdate = 2;
  2709. lcd_oldcardstatus = IS_SD_INSERTED;
  2710. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  2711. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  2712. currentMenu == lcd_status_screen
  2713. #endif
  2714. );
  2715. if (lcd_oldcardstatus)
  2716. {
  2717. card.initsd();
  2718. LCD_MESSAGERPGM(MSG_SD_INSERTED);
  2719. }
  2720. else
  2721. {
  2722. card.release();
  2723. LCD_MESSAGERPGM(MSG_SD_REMOVED);
  2724. }
  2725. }
  2726. #endif//CARDINSERTED
  2727. if (lcd_next_update_millis < millis())
  2728. {
  2729. #ifdef ULTIPANEL
  2730. #ifdef REPRAPWORLD_KEYPAD
  2731. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  2732. reprapworld_keypad_move_z_up();
  2733. }
  2734. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  2735. reprapworld_keypad_move_z_down();
  2736. }
  2737. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  2738. reprapworld_keypad_move_x_left();
  2739. }
  2740. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  2741. reprapworld_keypad_move_x_right();
  2742. }
  2743. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  2744. reprapworld_keypad_move_y_down();
  2745. }
  2746. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  2747. reprapworld_keypad_move_y_up();
  2748. }
  2749. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  2750. reprapworld_keypad_move_home();
  2751. }
  2752. #endif
  2753. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  2754. {
  2755. lcdDrawUpdate = 1;
  2756. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  2757. encoderDiff = 0;
  2758. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  2759. }
  2760. if (LCD_CLICKED)
  2761. timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  2762. #endif//ULTIPANEL
  2763. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  2764. blink++; // Variable for fan animation and alive dot
  2765. u8g.firstPage();
  2766. do
  2767. {
  2768. u8g.setFont(u8g_font_6x10_marlin);
  2769. u8g.setPrintPos(125, 0);
  2770. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  2771. u8g.drawPixel(127, 63); // draw alive dot
  2772. u8g.setColorIndex(1); // black on white
  2773. (*currentMenu)();
  2774. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  2775. } while (u8g.nextPage());
  2776. #else
  2777. (*currentMenu)();
  2778. #endif
  2779. #ifdef LCD_HAS_STATUS_INDICATORS
  2780. lcd_implementation_update_indicators();
  2781. #endif
  2782. #ifdef ULTIPANEL
  2783. if (timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  2784. {
  2785. // Exiting a menu. Let's call the menu function the last time with menuExiting flag set to true
  2786. // to give it a chance to save its state.
  2787. // This is useful for example, when the babystep value has to be written into EEPROM.
  2788. if (currentMenu != NULL) {
  2789. menuExiting = true;
  2790. (*currentMenu)();
  2791. menuExiting = false;
  2792. }
  2793. lcd_return_to_status();
  2794. lcdDrawUpdate = 2;
  2795. }
  2796. #endif//ULTIPANEL
  2797. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  2798. if (lcdDrawUpdate) lcdDrawUpdate--;
  2799. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  2800. }
  2801. }
  2802. void lcd_ignore_click(bool b)
  2803. {
  2804. ignore_click = b;
  2805. wait_for_unclick = false;
  2806. }
  2807. void lcd_finishstatus() {
  2808. int len = strlen(lcd_status_message);
  2809. if (len > 0) {
  2810. while (len < LCD_WIDTH) {
  2811. lcd_status_message[len++] = ' ';
  2812. }
  2813. }
  2814. lcd_status_message[LCD_WIDTH] = '\0';
  2815. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  2816. #if PROGRESS_MSG_EXPIRE > 0
  2817. messageTick =
  2818. #endif
  2819. progressBarTick = millis();
  2820. #endif
  2821. lcdDrawUpdate = 2;
  2822. #ifdef FILAMENT_LCD_DISPLAY
  2823. message_millis = millis(); //get status message to show up for a while
  2824. #endif
  2825. }
  2826. void lcd_setstatus(const char* message)
  2827. {
  2828. if (lcd_status_message_level > 0)
  2829. return;
  2830. strncpy(lcd_status_message, message, LCD_WIDTH);
  2831. lcd_finishstatus();
  2832. }
  2833. void lcd_setstatuspgm(const char* message)
  2834. {
  2835. if (lcd_status_message_level > 0)
  2836. return;
  2837. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  2838. lcd_finishstatus();
  2839. }
  2840. void lcd_setalertstatuspgm(const char* message)
  2841. {
  2842. lcd_setstatuspgm(message);
  2843. lcd_status_message_level = 1;
  2844. #ifdef ULTIPANEL
  2845. lcd_return_to_status();
  2846. #endif//ULTIPANEL
  2847. }
  2848. void lcd_reset_alert_level()
  2849. {
  2850. lcd_status_message_level = 0;
  2851. }
  2852. #ifdef DOGLCD
  2853. void lcd_setcontrast(uint8_t value)
  2854. {
  2855. lcd_contrast = value & 63;
  2856. u8g.setContrast(lcd_contrast);
  2857. }
  2858. #endif
  2859. #ifdef ULTIPANEL
  2860. /* Warning: This function is called from interrupt context */
  2861. void lcd_buttons_update()
  2862. {
  2863. #ifdef NEWPANEL
  2864. uint8_t newbutton = 0;
  2865. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  2866. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  2867. #if BTN_ENC > 0
  2868. if ((blocking_enc < millis()) && (READ(BTN_ENC) == 0))
  2869. newbutton |= EN_C;
  2870. #endif
  2871. buttons = newbutton;
  2872. #ifdef LCD_HAS_SLOW_BUTTONS
  2873. buttons |= slow_buttons;
  2874. #endif
  2875. #ifdef REPRAPWORLD_KEYPAD
  2876. // for the reprapworld_keypad
  2877. uint8_t newbutton_reprapworld_keypad = 0;
  2878. WRITE(SHIFT_LD, LOW);
  2879. WRITE(SHIFT_LD, HIGH);
  2880. for (int8_t i = 0; i < 8; i++) {
  2881. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  2882. if (READ(SHIFT_OUT))
  2883. newbutton_reprapworld_keypad |= (1 << 7);
  2884. WRITE(SHIFT_CLK, HIGH);
  2885. WRITE(SHIFT_CLK, LOW);
  2886. }
  2887. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  2888. #endif
  2889. #else //read it from the shift register
  2890. uint8_t newbutton = 0;
  2891. WRITE(SHIFT_LD, LOW);
  2892. WRITE(SHIFT_LD, HIGH);
  2893. unsigned char tmp_buttons = 0;
  2894. for (int8_t i = 0; i < 8; i++)
  2895. {
  2896. newbutton = newbutton >> 1;
  2897. if (READ(SHIFT_OUT))
  2898. newbutton |= (1 << 7);
  2899. WRITE(SHIFT_CLK, HIGH);
  2900. WRITE(SHIFT_CLK, LOW);
  2901. }
  2902. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  2903. #endif//!NEWPANEL
  2904. //manage encoder rotation
  2905. uint8_t enc = 0;
  2906. if (buttons & EN_A) enc |= B01;
  2907. if (buttons & EN_B) enc |= B10;
  2908. if (enc != lastEncoderBits)
  2909. {
  2910. switch (enc)
  2911. {
  2912. case encrot0:
  2913. if (lastEncoderBits == encrot3)
  2914. encoderDiff++;
  2915. else if (lastEncoderBits == encrot1)
  2916. encoderDiff--;
  2917. break;
  2918. case encrot1:
  2919. if (lastEncoderBits == encrot0)
  2920. encoderDiff++;
  2921. else if (lastEncoderBits == encrot2)
  2922. encoderDiff--;
  2923. break;
  2924. case encrot2:
  2925. if (lastEncoderBits == encrot1)
  2926. encoderDiff++;
  2927. else if (lastEncoderBits == encrot3)
  2928. encoderDiff--;
  2929. break;
  2930. case encrot3:
  2931. if (lastEncoderBits == encrot2)
  2932. encoderDiff++;
  2933. else if (lastEncoderBits == encrot0)
  2934. encoderDiff--;
  2935. break;
  2936. }
  2937. }
  2938. lastEncoderBits = enc;
  2939. }
  2940. bool lcd_detected(void)
  2941. {
  2942. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  2943. return lcd.LcdDetected() == 1;
  2944. #else
  2945. return true;
  2946. #endif
  2947. }
  2948. void lcd_buzz(long duration, uint16_t freq)
  2949. {
  2950. #ifdef LCD_USE_I2C_BUZZER
  2951. lcd.buzz(duration, freq);
  2952. #endif
  2953. }
  2954. bool lcd_clicked()
  2955. {
  2956. return LCD_CLICKED;
  2957. }
  2958. #endif//ULTIPANEL
  2959. /********************************/
  2960. /** Float conversion utilities **/
  2961. /********************************/
  2962. // convert float to string with +123.4 format
  2963. char conv[8];
  2964. char *ftostr3(const float &x)
  2965. {
  2966. return itostr3((int)x);
  2967. }
  2968. char *itostr2(const uint8_t &x)
  2969. {
  2970. //sprintf(conv,"%5.1f",x);
  2971. int xx = x;
  2972. conv[0] = (xx / 10) % 10 + '0';
  2973. conv[1] = (xx) % 10 + '0';
  2974. conv[2] = 0;
  2975. return conv;
  2976. }
  2977. // Convert float to string with 123.4 format, dropping sign
  2978. char *ftostr31(const float &x)
  2979. {
  2980. int xx = x * 10;
  2981. conv[0] = (xx >= 0) ? '+' : '-';
  2982. xx = abs(xx);
  2983. conv[1] = (xx / 1000) % 10 + '0';
  2984. conv[2] = (xx / 100) % 10 + '0';
  2985. conv[3] = (xx / 10) % 10 + '0';
  2986. conv[4] = '.';
  2987. conv[5] = (xx) % 10 + '0';
  2988. conv[6] = 0;
  2989. return conv;
  2990. }
  2991. // Convert float to string with 123.4 format
  2992. char *ftostr31ns(const float &x)
  2993. {
  2994. int xx = x * 10;
  2995. //conv[0]=(xx>=0)?'+':'-';
  2996. xx = abs(xx);
  2997. conv[0] = (xx / 1000) % 10 + '0';
  2998. conv[1] = (xx / 100) % 10 + '0';
  2999. conv[2] = (xx / 10) % 10 + '0';
  3000. conv[3] = '.';
  3001. conv[4] = (xx) % 10 + '0';
  3002. conv[5] = 0;
  3003. return conv;
  3004. }
  3005. char *ftostr32(const float &x)
  3006. {
  3007. long xx = x * 100;
  3008. if (xx >= 0)
  3009. conv[0] = (xx / 10000) % 10 + '0';
  3010. else
  3011. conv[0] = '-';
  3012. xx = abs(xx);
  3013. conv[1] = (xx / 1000) % 10 + '0';
  3014. conv[2] = (xx / 100) % 10 + '0';
  3015. conv[3] = '.';
  3016. conv[4] = (xx / 10) % 10 + '0';
  3017. conv[5] = (xx) % 10 + '0';
  3018. conv[6] = 0;
  3019. return conv;
  3020. }
  3021. //// Convert float to rj string with 123.45 format
  3022. char *ftostr32ns(const float &x) {
  3023. long xx = abs(x);
  3024. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  3025. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  3026. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : '0';
  3027. conv[3] = '.';
  3028. conv[4] = (xx / 10) % 10 + '0';
  3029. conv[5] = xx % 10 + '0';
  3030. return conv;
  3031. }
  3032. // Convert float to string with 1.234 format
  3033. char *ftostr43(const float &x)
  3034. {
  3035. long xx = x * 1000;
  3036. if (xx >= 0)
  3037. conv[0] = (xx / 1000) % 10 + '0';
  3038. else
  3039. conv[0] = '-';
  3040. xx = abs(xx);
  3041. conv[1] = '.';
  3042. conv[2] = (xx / 100) % 10 + '0';
  3043. conv[3] = (xx / 10) % 10 + '0';
  3044. conv[4] = (xx) % 10 + '0';
  3045. conv[5] = 0;
  3046. return conv;
  3047. }
  3048. //Float to string with 1.23 format
  3049. char *ftostr12ns(const float &x)
  3050. {
  3051. long xx = x * 100;
  3052. xx = abs(xx);
  3053. conv[0] = (xx / 100) % 10 + '0';
  3054. conv[1] = '.';
  3055. conv[2] = (xx / 10) % 10 + '0';
  3056. conv[3] = (xx) % 10 + '0';
  3057. conv[4] = 0;
  3058. return conv;
  3059. }
  3060. //Float to string with 1.234 format
  3061. char *ftostr13ns(const float &x)
  3062. {
  3063. long xx = x * 1000;
  3064. if (xx >= 0)
  3065. conv[0] = ' ';
  3066. else
  3067. conv[0] = '-';
  3068. xx = abs(xx);
  3069. conv[1] = (xx / 1000) % 10 + '0';
  3070. conv[2] = '.';
  3071. conv[3] = (xx / 100) % 10 + '0';
  3072. conv[4] = (xx / 10) % 10 + '0';
  3073. conv[5] = (xx) % 10 + '0';
  3074. conv[6] = 0;
  3075. return conv;
  3076. }
  3077. // convert float to space-padded string with -_23.4_ format
  3078. char *ftostr32sp(const float &x) {
  3079. long xx = abs(x * 100);
  3080. uint8_t dig;
  3081. if (x < 0) { // negative val = -_0
  3082. conv[0] = '-';
  3083. dig = (xx / 1000) % 10;
  3084. conv[1] = dig ? '0' + dig : ' ';
  3085. }
  3086. else { // positive val = __0
  3087. dig = (xx / 10000) % 10;
  3088. if (dig) {
  3089. conv[0] = '0' + dig;
  3090. conv[1] = '0' + (xx / 1000) % 10;
  3091. }
  3092. else {
  3093. conv[0] = ' ';
  3094. dig = (xx / 1000) % 10;
  3095. conv[1] = dig ? '0' + dig : ' ';
  3096. }
  3097. }
  3098. conv[2] = '0' + (xx / 100) % 10; // lsd always
  3099. dig = xx % 10;
  3100. if (dig) { // 2 decimal places
  3101. conv[5] = '0' + dig;
  3102. conv[4] = '0' + (xx / 10) % 10;
  3103. conv[3] = '.';
  3104. }
  3105. else { // 1 or 0 decimal place
  3106. dig = (xx / 10) % 10;
  3107. if (dig) {
  3108. conv[4] = '0' + dig;
  3109. conv[3] = '.';
  3110. }
  3111. else {
  3112. conv[3] = conv[4] = ' ';
  3113. }
  3114. conv[5] = ' ';
  3115. }
  3116. conv[6] = '\0';
  3117. return conv;
  3118. }
  3119. char *itostr31(const int &xx)
  3120. {
  3121. conv[0] = (xx >= 0) ? '+' : '-';
  3122. conv[1] = (xx / 1000) % 10 + '0';
  3123. conv[2] = (xx / 100) % 10 + '0';
  3124. conv[3] = (xx / 10) % 10 + '0';
  3125. conv[4] = '.';
  3126. conv[5] = (xx) % 10 + '0';
  3127. conv[6] = 0;
  3128. return conv;
  3129. }
  3130. // Convert int to rj string with 123 or -12 format
  3131. char *itostr3(const int &x)
  3132. {
  3133. int xx = x;
  3134. if (xx < 0) {
  3135. conv[0] = '-';
  3136. xx = -xx;
  3137. } else if (xx >= 100)
  3138. conv[0] = (xx / 100) % 10 + '0';
  3139. else
  3140. conv[0] = ' ';
  3141. if (xx >= 10)
  3142. conv[1] = (xx / 10) % 10 + '0';
  3143. else
  3144. conv[1] = ' ';
  3145. conv[2] = (xx) % 10 + '0';
  3146. conv[3] = 0;
  3147. return conv;
  3148. }
  3149. // Convert int to lj string with 123 format
  3150. char *itostr3left(const int &xx)
  3151. {
  3152. if (xx >= 100)
  3153. {
  3154. conv[0] = (xx / 100) % 10 + '0';
  3155. conv[1] = (xx / 10) % 10 + '0';
  3156. conv[2] = (xx) % 10 + '0';
  3157. conv[3] = 0;
  3158. }
  3159. else if (xx >= 10)
  3160. {
  3161. conv[0] = (xx / 10) % 10 + '0';
  3162. conv[1] = (xx) % 10 + '0';
  3163. conv[2] = 0;
  3164. }
  3165. else
  3166. {
  3167. conv[0] = (xx) % 10 + '0';
  3168. conv[1] = 0;
  3169. }
  3170. return conv;
  3171. }
  3172. // Convert int to rj string with 1234 format
  3173. char *itostr4(const int &xx) {
  3174. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  3175. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  3176. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  3177. conv[3] = xx % 10 + '0';
  3178. conv[4] = 0;
  3179. return conv;
  3180. }
  3181. // Convert float to rj string with 12345 format
  3182. char *ftostr5(const float &x) {
  3183. long xx = abs(x);
  3184. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  3185. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  3186. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  3187. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  3188. conv[4] = xx % 10 + '0';
  3189. conv[5] = 0;
  3190. return conv;
  3191. }
  3192. // Convert float to string with +1234.5 format
  3193. char *ftostr51(const float &x)
  3194. {
  3195. long xx = x * 10;
  3196. conv[0] = (xx >= 0) ? '+' : '-';
  3197. xx = abs(xx);
  3198. conv[1] = (xx / 10000) % 10 + '0';
  3199. conv[2] = (xx / 1000) % 10 + '0';
  3200. conv[3] = (xx / 100) % 10 + '0';
  3201. conv[4] = (xx / 10) % 10 + '0';
  3202. conv[5] = '.';
  3203. conv[6] = (xx) % 10 + '0';
  3204. conv[7] = 0;
  3205. return conv;
  3206. }
  3207. // Convert float to string with +123.45 format
  3208. char *ftostr52(const float &x)
  3209. {
  3210. long xx = x * 100;
  3211. conv[0] = (xx >= 0) ? '+' : '-';
  3212. xx = abs(xx);
  3213. conv[1] = (xx / 10000) % 10 + '0';
  3214. conv[2] = (xx / 1000) % 10 + '0';
  3215. conv[3] = (xx / 100) % 10 + '0';
  3216. conv[4] = '.';
  3217. conv[5] = (xx / 10) % 10 + '0';
  3218. conv[6] = (xx) % 10 + '0';
  3219. conv[7] = 0;
  3220. return conv;
  3221. }
  3222. /*
  3223. // Callback for after editing PID i value
  3224. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  3225. void copy_and_scalePID_i()
  3226. {
  3227. #ifdef PIDTEMP
  3228. Ki = scalePID_i(raw_Ki);
  3229. updatePID();
  3230. #endif
  3231. }
  3232. // Callback for after editing PID d value
  3233. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  3234. void copy_and_scalePID_d()
  3235. {
  3236. #ifdef PIDTEMP
  3237. Kd = scalePID_d(raw_Kd);
  3238. updatePID();
  3239. #endif
  3240. }
  3241. */
  3242. #endif //ULTRA_LCD