ultralcd.cpp 134 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036
  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 "mesh_bed_leveling.h"
  13. //#include "Configuration.h"
  14. #include "SdFatUtil.h"
  15. #define _STRINGIFY(s) #s
  16. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  17. extern int lcd_change_fil_state;
  18. //Function pointer to menu functions.
  19. typedef void (*menuFunc_t)();
  20. static void lcd_sd_updir();
  21. struct EditMenuParentState
  22. {
  23. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  24. menuFunc_t prevMenu;
  25. uint16_t prevEncoderPosition;
  26. //Variables used when editing values.
  27. const char* editLabel;
  28. void* editValue;
  29. int32_t minEditValue, maxEditValue;
  30. // menuFunc_t callbackFunc;
  31. };
  32. union MenuData
  33. {
  34. struct BabyStep
  35. {
  36. // 29B total
  37. int8_t status;
  38. int babystepMem[3];
  39. float babystepMemMM[3];
  40. } babyStep;
  41. struct SupportMenu
  42. {
  43. // 6B+16B=22B total
  44. int8_t status;
  45. bool is_flash_air;
  46. uint8_t ip[4];
  47. char ip_str[3*4+3+1];
  48. } supportMenu;
  49. struct AdjustBed
  50. {
  51. // 6+13+16=35B
  52. // editMenuParentState is used when an edit menu is entered, so it knows
  53. // the return menu and encoder state.
  54. struct EditMenuParentState editMenuParentState;
  55. int8_t status;
  56. int8_t left;
  57. int8_t right;
  58. int8_t front;
  59. int8_t rear;
  60. int left2;
  61. int right2;
  62. int front2;
  63. int rear2;
  64. } adjustBed;
  65. // editMenuParentState is used when an edit menu is entered, so it knows
  66. // the return menu and encoder state.
  67. struct EditMenuParentState editMenuParentState;
  68. };
  69. // State of the currently active menu.
  70. // C Union manages sharing of the static memory by all the menus.
  71. union MenuData menuData = { 0 };
  72. union Data
  73. {
  74. byte b[2];
  75. int value;
  76. };
  77. int8_t ReInitLCD = 0;
  78. int8_t SDscrool = 0;
  79. int8_t SilentModeMenu = 0;
  80. int lcd_commands_type=LCD_COMMAND_IDLE;
  81. int lcd_commands_step=0;
  82. bool isPrintPaused = false;
  83. bool farm_mode = false;
  84. int farm_no = 0;
  85. int farm_timer = 30;
  86. int farm_status = 0;
  87. bool menuExiting = false;
  88. #ifdef FILAMENT_LCD_DISPLAY
  89. unsigned long message_millis = 0;
  90. #endif
  91. #ifdef ULTIPANEL
  92. static float manual_feedrate[] = MANUAL_FEEDRATE;
  93. #endif // ULTIPANEL
  94. /* !Configuration settings */
  95. uint8_t lcd_status_message_level;
  96. char lcd_status_message[LCD_WIDTH + 1] = ""; //////WELCOME!
  97. unsigned char firstrun = 1;
  98. #ifdef DOGLCD
  99. #include "dogm_lcd_implementation.h"
  100. #else
  101. #include "ultralcd_implementation_hitachi_HD44780.h"
  102. #endif
  103. /** forward declarations **/
  104. // void copy_and_scalePID_i();
  105. // void copy_and_scalePID_d();
  106. /* Different menus */
  107. static void lcd_status_screen();
  108. #ifdef ULTIPANEL
  109. extern bool powersupply;
  110. static void lcd_main_menu();
  111. static void lcd_tune_menu();
  112. static void lcd_prepare_menu();
  113. static void lcd_move_menu();
  114. static void lcd_settings_menu();
  115. static void lcd_calibration_menu();
  116. static void lcd_language_menu();
  117. static void lcd_control_temperature_menu();
  118. static void lcd_control_temperature_preheat_pla_settings_menu();
  119. static void lcd_control_temperature_preheat_abs_settings_menu();
  120. static void lcd_control_motion_menu();
  121. static void lcd_control_volumetric_menu();
  122. static void prusa_stat_printerstatus(int _status);
  123. static void prusa_stat_temperatures();
  124. static void prusa_stat_printinfo();
  125. static void lcd_farm_no();
  126. #ifdef DOGLCD
  127. static void lcd_set_contrast();
  128. #endif
  129. static void lcd_control_retract_menu();
  130. static void lcd_sdcard_menu();
  131. #ifdef DELTA_CALIBRATION_MENU
  132. static void lcd_delta_calibrate_menu();
  133. #endif // DELTA_CALIBRATION_MENU
  134. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
  135. /* Different types of actions that can be used in menu items. */
  136. static void menu_action_back(menuFunc_t data);
  137. #define menu_action_back_RAM menu_action_back
  138. static void menu_action_submenu(menuFunc_t data);
  139. static void menu_action_gcode(const char* pgcode);
  140. static void menu_action_function(menuFunc_t data);
  141. static void menu_action_setlang(unsigned char lang);
  142. static void menu_action_sdfile(const char* filename, char* longFilename);
  143. static void menu_action_sddirectory(const char* filename, char* longFilename);
  144. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  145. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  146. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  147. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  148. static void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  149. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  150. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  151. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  152. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  153. /*
  154. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callbackFunc);
  155. static void menu_action_setting_edit_callback_int3(const char* pstr, int* ptr, int minValue, int maxValue, menuFunc_t callbackFunc);
  156. static void menu_action_setting_edit_callback_float3(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  157. static void menu_action_setting_edit_callback_float32(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  158. static void menu_action_setting_edit_callback_float43(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  159. static void menu_action_setting_edit_callback_float5(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  160. static void menu_action_setting_edit_callback_float51(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  161. static void menu_action_setting_edit_callback_float52(const char* pstr, float* ptr, float minValue, float maxValue, menuFunc_t callbackFunc);
  162. static void menu_action_setting_edit_callback_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue, menuFunc_t callbackFunc);
  163. */
  164. #define ENCODER_FEEDRATE_DEADZONE 10
  165. #if !defined(LCD_I2C_VIKI)
  166. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  167. #define ENCODER_STEPS_PER_MENU_ITEM 5
  168. #endif
  169. #ifndef ENCODER_PULSES_PER_STEP
  170. #define ENCODER_PULSES_PER_STEP 1
  171. #endif
  172. #else
  173. #ifndef ENCODER_STEPS_PER_MENU_ITEM
  174. #define ENCODER_STEPS_PER_MENU_ITEM 2 // VIKI LCD rotary encoder uses a different number of steps per rotation
  175. #endif
  176. #ifndef ENCODER_PULSES_PER_STEP
  177. #define ENCODER_PULSES_PER_STEP 1
  178. #endif
  179. #endif
  180. /* Helper macros for menus */
  181. #define START_MENU() do { \
  182. if (encoderPosition > 0x8000) encoderPosition = 0; \
  183. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM < currentMenuViewOffset) currentMenuViewOffset = encoderPosition / ENCODER_STEPS_PER_MENU_ITEM;\
  184. uint8_t _lineNr = currentMenuViewOffset, _menuItemNr; \
  185. bool wasClicked = LCD_CLICKED;\
  186. for(uint8_t _drawLineNr = 0; _drawLineNr < LCD_HEIGHT; _drawLineNr++, _lineNr++) { \
  187. _menuItemNr = 0;
  188. #define MENU_ITEM(type, label, args...) do { \
  189. if (_menuItemNr == _lineNr) { \
  190. if (lcdDrawUpdate) { \
  191. const char* _label_pstr = (label); \
  192. if ((encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) { \
  193. lcd_implementation_drawmenu_ ## type ## _selected (_drawLineNr, _label_pstr , ## args ); \
  194. }else{\
  195. lcd_implementation_drawmenu_ ## type (_drawLineNr, _label_pstr , ## args ); \
  196. }\
  197. }\
  198. if (wasClicked && (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM) == _menuItemNr) {\
  199. lcd_quick_feedback(); \
  200. menu_action_ ## type ( args ); \
  201. return;\
  202. }\
  203. }\
  204. _menuItemNr++;\
  205. } while(0)
  206. #define MENU_ITEM_DUMMY() do { _menuItemNr++; } while(0)
  207. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, (label) , ## args )
  208. #define MENU_ITEM_EDIT_CALLBACK(type, label, args...) MENU_ITEM(setting_edit_callback_ ## type, label, (label) , ## args )
  209. #define END_MENU() \
  210. if (encoderPosition / ENCODER_STEPS_PER_MENU_ITEM >= _menuItemNr) encoderPosition = _menuItemNr * ENCODER_STEPS_PER_MENU_ITEM - 1; \
  211. 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; } \
  212. } } while(0)
  213. /** Used variables to keep track of the menu */
  214. #ifndef REPRAPWORLD_KEYPAD
  215. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  216. #else
  217. volatile uint8_t buttons_reprapworld_keypad; // to store the reprapworld_keypad shift register values
  218. #endif
  219. #ifdef LCD_HAS_SLOW_BUTTONS
  220. volatile uint8_t slow_buttons;//Contains the bits of the currently pressed buttons.
  221. #endif
  222. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  223. uint32_t blocking_enc;
  224. uint8_t lastEncoderBits;
  225. uint32_t encoderPosition;
  226. #if (SDCARDDETECT > 0)
  227. bool lcd_oldcardstatus;
  228. #endif
  229. #endif //ULTIPANEL
  230. menuFunc_t currentMenu = lcd_status_screen; /* function pointer to the currently active menu */
  231. uint32_t lcd_next_update_millis;
  232. uint8_t lcd_status_update_delay;
  233. bool ignore_click = false;
  234. bool wait_for_unclick;
  235. 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) */
  236. // place-holders for Ki and Kd edits
  237. #ifdef PIDTEMP
  238. // float raw_Ki, raw_Kd;
  239. #endif
  240. static void lcd_goto_menu(menuFunc_t menu, const uint32_t encoder = 0, const bool feedback = true, bool reset_menu_state = true) {
  241. if (currentMenu != menu) {
  242. currentMenu = menu;
  243. encoderPosition = encoder;
  244. if (reset_menu_state) {
  245. // Resets the global shared C union.
  246. // This ensures, that the menu entered will find out, that it shall initialize itself.
  247. memset(&menuData, 0, sizeof(menuData));
  248. }
  249. if (feedback) lcd_quick_feedback();
  250. // For LCD_PROGRESS_BAR re-initialize the custom characters
  251. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  252. lcd_set_custom_characters(menu == lcd_status_screen);
  253. #endif
  254. }
  255. }
  256. /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */
  257. // Language selection dialog not active.
  258. #define LANGSEL_OFF 0
  259. // Language selection dialog modal, entered from the info screen. This is the case on firmware boot up,
  260. // if the language index stored in the EEPROM is not valid.
  261. #define LANGSEL_MODAL 1
  262. // Language selection dialog entered from the Setup menu.
  263. #define LANGSEL_ACTIVE 2
  264. // Language selection dialog status
  265. unsigned char langsel = LANGSEL_OFF;
  266. void set_language_from_EEPROM() {
  267. unsigned char eep = eeprom_read_byte((unsigned char*)EEPROM_LANG);
  268. if (eep < LANG_NUM)
  269. {
  270. lang_selected = eep;
  271. // Language is valid, no need to enter the language selection screen.
  272. langsel = LANGSEL_OFF;
  273. }
  274. else
  275. {
  276. lang_selected = LANG_ID_DEFAULT;
  277. // Invalid language, enter the language selection screen in a modal mode.
  278. langsel = LANGSEL_MODAL;
  279. }
  280. }
  281. static void lcd_status_screen()
  282. {
  283. if (firstrun == 1)
  284. {
  285. firstrun = 0;
  286. set_language_from_EEPROM();
  287. if(lcd_status_message_level == 0){
  288. strncpy_P(lcd_status_message, WELCOME_MSG, LCD_WIDTH);
  289. }
  290. 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)
  291. {
  292. eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0);
  293. eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0);
  294. }
  295. if (langsel) {
  296. //strncpy_P(lcd_status_message, PSTR(">>>>>>>>>>>> PRESS v"), LCD_WIDTH);
  297. // Entering the language selection screen in a modal mode.
  298. }
  299. }
  300. if (lcd_status_update_delay)
  301. lcd_status_update_delay--;
  302. else
  303. lcdDrawUpdate = 1;
  304. if (lcdDrawUpdate)
  305. {
  306. ReInitLCD++;
  307. if (ReInitLCD == 30) {
  308. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  309. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  310. currentMenu == lcd_status_screen
  311. #endif
  312. );
  313. ReInitLCD = 0 ;
  314. } else {
  315. if ((ReInitLCD % 10) == 0) {
  316. //lcd_implementation_nodisplay();
  317. lcd_implementation_init_noclear( // to maybe revive the LCD if static electricity killed it.
  318. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  319. currentMenu == lcd_status_screen
  320. #endif
  321. );
  322. }
  323. }
  324. //lcd_implementation_display();
  325. lcd_implementation_status_screen();
  326. //lcd_implementation_clear();
  327. if (farm_mode)
  328. {
  329. farm_timer--;
  330. if (farm_timer < 1)
  331. {
  332. farm_timer = 180;
  333. prusa_statistics(0);
  334. }
  335. switch (farm_timer)
  336. {
  337. case 45:
  338. prusa_statistics(21);
  339. break;
  340. case 10:
  341. if (IS_SD_PRINTING)
  342. {
  343. prusa_statistics(20);
  344. }
  345. break;
  346. }
  347. } // end of farm_mode
  348. 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 */
  349. if (lcd_commands_type != LCD_COMMAND_IDLE)
  350. {
  351. lcd_commands();
  352. }
  353. } // end of lcdDrawUpdate
  354. #ifdef ULTIPANEL
  355. bool current_click = LCD_CLICKED;
  356. if (ignore_click) {
  357. if (wait_for_unclick) {
  358. if (!current_click) {
  359. ignore_click = wait_for_unclick = false;
  360. }
  361. else {
  362. current_click = false;
  363. }
  364. }
  365. else if (current_click) {
  366. lcd_quick_feedback();
  367. wait_for_unclick = true;
  368. current_click = false;
  369. }
  370. }
  371. //if (--langsel ==0) {langsel=1;current_click=true;}
  372. if (current_click && (lcd_commands_type != LCD_COMMAND_STOP_PRINT)) //click is aborted unless stop print finishes
  373. {
  374. lcd_goto_menu(lcd_main_menu);
  375. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  376. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  377. currentMenu == lcd_status_screen
  378. #endif
  379. );
  380. #ifdef FILAMENT_LCD_DISPLAY
  381. message_millis = millis(); // get status message to show up for a while
  382. #endif
  383. }
  384. #ifdef ULTIPANEL_FEEDMULTIPLY
  385. // Dead zone at 100% feedrate
  386. if ((feedmultiply < 100 && (feedmultiply + int(encoderPosition)) > 100) ||
  387. (feedmultiply > 100 && (feedmultiply + int(encoderPosition)) < 100))
  388. {
  389. encoderPosition = 0;
  390. feedmultiply = 100;
  391. }
  392. if (feedmultiply == 100 && int(encoderPosition) > ENCODER_FEEDRATE_DEADZONE)
  393. {
  394. feedmultiply += int(encoderPosition) - ENCODER_FEEDRATE_DEADZONE;
  395. encoderPosition = 0;
  396. }
  397. else if (feedmultiply == 100 && int(encoderPosition) < -ENCODER_FEEDRATE_DEADZONE)
  398. {
  399. feedmultiply += int(encoderPosition) + ENCODER_FEEDRATE_DEADZONE;
  400. encoderPosition = 0;
  401. }
  402. else if (feedmultiply != 100)
  403. {
  404. feedmultiply += int(encoderPosition);
  405. encoderPosition = 0;
  406. }
  407. #endif //ULTIPANEL_FEEDMULTIPLY
  408. if (feedmultiply < 10)
  409. feedmultiply = 10;
  410. else if (feedmultiply > 999)
  411. feedmultiply = 999;
  412. #endif //ULTIPANEL
  413. }
  414. #ifdef ULTIPANEL
  415. void lcd_commands()
  416. {
  417. if (lcd_commands_type == LCD_COMMAND_LOAD_FILAMENT) //// load filament sequence
  418. {
  419. if (lcd_commands_step == 0) { lcd_commands_step = 7; custom_message = true;}
  420. if (lcd_commands_step == 1 && !blocks_queued())
  421. {
  422. lcd_commands_step = 0;
  423. lcd_commands_type = 0;
  424. lcd_setstatuspgm(WELCOME_MSG);
  425. disable_z();
  426. custom_message = false;
  427. custom_message_type = 0;
  428. }
  429. if (lcd_commands_step == 2 && !blocks_queued())
  430. {
  431. lcd_commands_step = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FILAMENT_CLEAN) ? 1 : 4;
  432. lcd_update_enable(true);
  433. lcdDrawUpdate = 2;
  434. }
  435. if (lcd_commands_step == 3 && !blocks_queued()) {
  436. lcd_commands_step = farm_mode ? 1:2; //don't show question about clear color if we are in farm mode
  437. }
  438. if (lcd_commands_step == 4 && !blocks_queued())
  439. {
  440. //lcd_setstatuspgm(MSG_LOADING_FILAMENT);
  441. enquecommand_P(PSTR(LOAD_FILAMENT_2)); //slow_sequence
  442. lcd_commands_step = 3;
  443. }
  444. if (lcd_commands_step == 5 && !blocks_queued())
  445. {
  446. enquecommand_P(PSTR(LOAD_FILAMENT_1)); //fast sequence
  447. lcd_setstatuspgm(MSG_LOADING_FILAMENT);
  448. //enquecommand_P(PSTR("G4")); //dwell
  449. lcd_commands_step = 4;
  450. }
  451. if (lcd_commands_step == 6 && !blocks_queued())
  452. {
  453. lcd_setstatuspgm(MSG_INSERT_FILAMENT);
  454. enquecommand_P(PSTR(LOAD_FILAMENT_0)); //set E relative
  455. enquecommand_P(PSTR("G1 E0.1 F400"));
  456. lcd_commands_step = 5;
  457. }
  458. if (lcd_commands_step == 7 && !blocks_queued())
  459. {
  460. lcd_setstatuspgm(MSG_PLEASE_WAIT);
  461. enable_z();
  462. custom_message = true;
  463. custom_message_type = 2;
  464. lcd_commands_step = 6;
  465. }
  466. }
  467. if (lcd_commands_type == LCD_COMMAND_STOP_PRINT) /// stop print
  468. {
  469. if (lcd_commands_step == 0) { lcd_commands_step = 6; custom_message = true; }
  470. if (lcd_commands_step == 1 && !blocks_queued())
  471. {
  472. lcd_commands_step = 0;
  473. lcd_commands_type = 0;
  474. lcd_setstatuspgm(WELCOME_MSG);
  475. custom_message_type = 0;
  476. custom_message = false;
  477. isPrintPaused = false;
  478. }
  479. if (lcd_commands_step == 2 && !blocks_queued())
  480. {
  481. setTargetBed(0);
  482. setTargetHotend(0, 0);
  483. setTargetHotend(0, 1);
  484. setTargetHotend(0, 2);
  485. manage_heater();
  486. lcd_setstatuspgm(WELCOME_MSG);
  487. cancel_heatup = false;
  488. lcd_commands_step = 1;
  489. }
  490. if (lcd_commands_step == 3 && !blocks_queued())
  491. {
  492. // M84: Disable steppers.
  493. enquecommand_P(PSTR("M84"));
  494. autotempShutdown();
  495. lcd_commands_step = 2;
  496. }
  497. if (lcd_commands_step == 4 && !blocks_queued())
  498. {
  499. lcd_setstatuspgm(MSG_PLEASE_WAIT);
  500. // G90: Absolute positioning.
  501. enquecommand_P(PSTR("G90"));
  502. // M83: Set extruder to relative mode.
  503. enquecommand_P(PSTR("M83"));
  504. #ifdef X_CANCEL_POS
  505. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  506. #else
  507. enquecommand_P(PSTR("G1 X50 Y" STRINGIFY(Y_MAX_POS) " E0 F7000"));
  508. #endif
  509. lcd_ignore_click(false);
  510. #ifdef SNMM
  511. lcd_commands_step = 7;
  512. #else
  513. lcd_commands_step = 3;
  514. #endif
  515. }
  516. if (lcd_commands_step == 5 && !blocks_queued())
  517. {
  518. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  519. // G91: Set to relative positioning.
  520. enquecommand_P(PSTR("G91"));
  521. // Lift up.
  522. enquecommand_P(PSTR("G1 Z15 F1500"));
  523. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) lcd_commands_step = 4;
  524. else lcd_commands_step = 3;
  525. }
  526. if (lcd_commands_step == 6 && !blocks_queued())
  527. {
  528. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  529. cancel_heatup = true;
  530. setTargetBed(0);
  531. #ifndef SNMM
  532. setTargetHotend(0, 0); //to heating when changing filament for multicolor
  533. setTargetHotend(0, 1);
  534. setTargetHotend(0, 2);
  535. #endif
  536. manage_heater();
  537. custom_message = true;
  538. custom_message_type = 2;
  539. lcd_commands_step = 5;
  540. }
  541. if (lcd_commands_step == 7 && !blocks_queued()) {
  542. /*ramming();
  543. st_synchronize();
  544. change_extr(0);*/
  545. st_synchronize();
  546. enquecommand_P(PSTR("M907 E700")); //set extruder current higher
  547. enquecommand_P(PSTR("M203 E50"));
  548. st_synchronize();
  549. if (current_temperature[0] < 230) {
  550. // PLA
  551. //enquecommand_P(PSTR("G1 E-8 F2100.000000"));
  552. //enquecommand_P(PSTR("G1 E8 F2100.000000"));
  553. enquecommand_P(PSTR("G1 E5.4 F2800.000000"));
  554. enquecommand_P(PSTR("G1 E3.2 F3000.000000"));
  555. enquecommand_P(PSTR("G1 E3 F3400.000000"));
  556. enquecommand_P(PSTR("M203 E80"));
  557. st_synchronize();
  558. enquecommand_P(PSTR("G1 E-82 F9500.000000"));
  559. enquecommand_P(PSTR("M203 E50"));
  560. enquecommand_P(PSTR("G1 E-20 F1200.000000"));
  561. enquecommand_P(PSTR("G1 E5 F400.000000"));
  562. enquecommand_P(PSTR("G1 E5 F600.000000"));
  563. st_synchronize();
  564. enquecommand_P(PSTR("G1 E-10 F600.000000"));
  565. enquecommand_P(PSTR("G1 E+10 F600.000000"));
  566. enquecommand_P(PSTR("G1 E-10 F800.000000"));
  567. enquecommand_P(PSTR("G1 E+10 F800.000000"));
  568. enquecommand_P(PSTR("G1 E-10 F800.000000"));
  569. st_synchronize();
  570. }else {
  571. // ABS
  572. //enquecommand_P(PSTR("G1 E-8 F2100.000000"));
  573. //enquecommand_P(PSTR("G1 E8 F2100.000000"));
  574. enquecommand_P(PSTR("G1 E3.1 F2000.000000"));
  575. enquecommand_P(PSTR("G1 E3.1 F2500.000000"));
  576. enquecommand_P(PSTR("G1 E4 F3000.000000"));
  577. st_synchronize();
  578. enquecommand_P(PSTR("G4 P4700"));
  579. enquecommand_P(PSTR("M203 E80"));
  580. enquecommand_P(PSTR("G1 E-92 F9900.000000"));
  581. enquecommand_P(PSTR("M203 E50"));
  582. enquecommand_P(PSTR("G1 E-5 F800.000000"));
  583. enquecommand_P(PSTR("G1 E5 F400.000000"));
  584. st_synchronize();
  585. enquecommand_P(PSTR("G1 E-5 F600.000000"));
  586. enquecommand_P(PSTR("G1 E5 F600.000000"));
  587. enquecommand_P(PSTR("G1 E-5 F600.000000"));
  588. enquecommand_P(PSTR("G1 E5 F600.000000"));
  589. enquecommand_P(PSTR("G1 E5 F600.000000"));
  590. st_synchronize();
  591. }
  592. enquecommand_P(PSTR("T0"));
  593. enquecommand_P(PSTR("M907 E550")); //set extruder current to 500
  594. //digipot_init();
  595. lcd_commands_step = 3;
  596. }
  597. }
  598. if (lcd_commands_type == 3)
  599. {
  600. lcd_commands_type = 0;
  601. }
  602. if (lcd_commands_type == LCD_COMMAND_FARM_MODE_CONFIRM) /// farm mode confirm
  603. {
  604. if (lcd_commands_step == 0) { lcd_commands_step = 6; custom_message = true; }
  605. if (lcd_commands_step == 1 && !blocks_queued())
  606. {
  607. lcd_confirm_print();
  608. lcd_commands_step = 0;
  609. lcd_commands_type = 0;
  610. }
  611. if (lcd_commands_step == 2 && !blocks_queued())
  612. {
  613. lcd_commands_step = 1;
  614. }
  615. if (lcd_commands_step == 3 && !blocks_queued())
  616. {
  617. lcd_commands_step = 2;
  618. }
  619. if (lcd_commands_step == 4 && !blocks_queued())
  620. {
  621. enquecommand_P(PSTR("G90"));
  622. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  623. lcd_commands_step = 3;
  624. }
  625. if (lcd_commands_step == 5 && !blocks_queued())
  626. {
  627. lcd_commands_step = 4;
  628. }
  629. if (lcd_commands_step == 6 && !blocks_queued())
  630. {
  631. enquecommand_P(PSTR("G91"));
  632. enquecommand_P(PSTR("G1 Z15 F1500"));
  633. st_synchronize();
  634. #ifdef SNMM
  635. lcd_commands_step = 7;
  636. #else
  637. lcd_commands_step = 5;
  638. #endif
  639. }
  640. }
  641. }
  642. static void lcd_return_to_status() {
  643. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  644. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  645. currentMenu == lcd_status_screen
  646. #endif
  647. );
  648. lcd_goto_menu(lcd_status_screen, 0, false);
  649. }
  650. static void lcd_sdcard_pause() {
  651. card.pauseSDPrint();
  652. isPrintPaused = true;
  653. lcdDrawUpdate = 3;
  654. }
  655. static void lcd_sdcard_resume() {
  656. card.startFileprint();
  657. isPrintPaused = false;
  658. lcdDrawUpdate = 3;
  659. }
  660. float move_menu_scale;
  661. static void lcd_move_menu_axis();
  662. /* Menu implementation */
  663. void lcd_preheat_pla()
  664. {
  665. setTargetHotend0(PLA_PREHEAT_HOTEND_TEMP);
  666. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  667. fanSpeed = 0;
  668. lcd_return_to_status();
  669. setWatch(); // heater sanity check timer
  670. }
  671. void lcd_preheat_abs()
  672. {
  673. setTargetHotend0(ABS_PREHEAT_HOTEND_TEMP);
  674. setTargetBed(ABS_PREHEAT_HPB_TEMP);
  675. fanSpeed = 0;
  676. lcd_return_to_status();
  677. setWatch(); // heater sanity check timer
  678. }
  679. void lcd_preheat_pp()
  680. {
  681. setTargetHotend0(PP_PREHEAT_HOTEND_TEMP);
  682. setTargetBed(PP_PREHEAT_HPB_TEMP);
  683. fanSpeed = 0;
  684. lcd_return_to_status();
  685. setWatch(); // heater sanity check timer
  686. }
  687. void lcd_preheat_pet()
  688. {
  689. setTargetHotend0(PET_PREHEAT_HOTEND_TEMP);
  690. setTargetBed(PET_PREHEAT_HPB_TEMP);
  691. fanSpeed = 0;
  692. lcd_return_to_status();
  693. setWatch(); // heater sanity check timer
  694. }
  695. void lcd_preheat_hips()
  696. {
  697. setTargetHotend0(HIPS_PREHEAT_HOTEND_TEMP);
  698. setTargetBed(HIPS_PREHEAT_HPB_TEMP);
  699. fanSpeed = 0;
  700. lcd_return_to_status();
  701. setWatch(); // heater sanity check timer
  702. }
  703. void lcd_preheat_flex()
  704. {
  705. setTargetHotend0(FLEX_PREHEAT_HOTEND_TEMP);
  706. setTargetBed(FLEX_PREHEAT_HPB_TEMP);
  707. fanSpeed = 0;
  708. lcd_return_to_status();
  709. setWatch(); // heater sanity check timer
  710. }
  711. void lcd_cooldown()
  712. {
  713. setTargetHotend0(0);
  714. setTargetHotend1(0);
  715. setTargetHotend2(0);
  716. setTargetBed(0);
  717. fanSpeed = 0;
  718. lcd_return_to_status();
  719. }
  720. static void lcd_preheat_menu()
  721. {
  722. START_MENU();
  723. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  724. MENU_ITEM(function, PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)), lcd_preheat_abs);
  725. MENU_ITEM(function, PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)), lcd_preheat_pla);
  726. MENU_ITEM(function, PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)), lcd_preheat_pet);
  727. MENU_ITEM(function, PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)), lcd_preheat_hips);
  728. MENU_ITEM(function, PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)), lcd_preheat_pp);
  729. MENU_ITEM(function, PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)), lcd_preheat_flex);
  730. MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown);
  731. END_MENU();
  732. }
  733. static void lcd_support_menu()
  734. {
  735. if (menuData.supportMenu.status == 0 || lcdDrawUpdate == 2) {
  736. // Menu was entered or SD card status has changed (plugged in or removed).
  737. // Initialize its status.
  738. menuData.supportMenu.status = 1;
  739. menuData.supportMenu.is_flash_air = card.ToshibaFlashAir_isEnabled() && card.ToshibaFlashAir_GetIP(menuData.supportMenu.ip);
  740. if (menuData.supportMenu.is_flash_air)
  741. sprintf_P(menuData.supportMenu.ip_str, PSTR("%d.%d.%d.%d"),
  742. menuData.supportMenu.ip[0], menuData.supportMenu.ip[1],
  743. menuData.supportMenu.ip[2], menuData.supportMenu.ip[3]);
  744. } else if (menuData.supportMenu.is_flash_air &&
  745. menuData.supportMenu.ip[0] == 0 && menuData.supportMenu.ip[1] == 0 &&
  746. menuData.supportMenu.ip[2] == 0 && menuData.supportMenu.ip[3] == 0 &&
  747. ++ menuData.supportMenu.status == 16) {
  748. // Waiting for the FlashAir card to get an IP address from a router. Force an update.
  749. menuData.supportMenu.status = 0;
  750. }
  751. START_MENU();
  752. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  753. // Ideally this block would be optimized out by the compiler.
  754. const uint8_t fw_string_len = strlen_P(FW_VERSION_STR_P());
  755. if (fw_string_len < 6) {
  756. MENU_ITEM(back, PSTR(MSG_FW_VERSION " - " FW_version), lcd_main_menu);
  757. } else {
  758. MENU_ITEM(back, PSTR("FW - " FW_version), lcd_main_menu);
  759. }
  760. MENU_ITEM(back, MSG_PRUSA3D, lcd_main_menu);
  761. MENU_ITEM(back, MSG_PRUSA3D_FORUM, lcd_main_menu);
  762. MENU_ITEM(back, MSG_PRUSA3D_HOWTO, lcd_main_menu);
  763. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  764. MENU_ITEM(back, PSTR(FILAMENT_SIZE), lcd_main_menu);
  765. MENU_ITEM(back, PSTR(ELECTRONICS),lcd_main_menu);
  766. MENU_ITEM(back, PSTR(NOZZLE_TYPE),lcd_main_menu);
  767. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  768. MENU_ITEM(back, PSTR("Date: "), lcd_main_menu);
  769. MENU_ITEM(back, PSTR(__DATE__), lcd_main_menu);
  770. // Show the FlashAir IP address, if the card is available.
  771. if (menuData.supportMenu.is_flash_air) {
  772. MENU_ITEM(back, PSTR("------------"), lcd_main_menu);
  773. MENU_ITEM(back, PSTR("FlashAir IP Addr:"), lcd_main_menu);
  774. MENU_ITEM(back_RAM, menuData.supportMenu.ip_str, lcd_main_menu);
  775. }
  776. END_MENU();
  777. }
  778. void lcd_unLoadFilament()
  779. {
  780. if (degHotend0() > EXTRUDE_MINTEMP) {
  781. enquecommand_P(PSTR(UNLOAD_FILAMENT_0));
  782. enquecommand_P(PSTR(UNLOAD_FILAMENT_1));
  783. } else {
  784. lcd_implementation_clear();
  785. lcd.setCursor(0, 0);
  786. lcd_printPGM(MSG_ERROR);
  787. lcd.setCursor(0, 2);
  788. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  789. delay(2000);
  790. lcd_implementation_clear();
  791. }
  792. lcd_return_to_status();
  793. }
  794. void lcd_change_filament() {
  795. lcd_implementation_clear();
  796. lcd.setCursor(0, 1);
  797. lcd_printPGM(MSG_CHANGING_FILAMENT);
  798. }
  799. void lcd_wait_interact() {
  800. lcd_implementation_clear();
  801. lcd.setCursor(0, 1);
  802. lcd_printPGM(MSG_INSERT_FILAMENT);
  803. lcd.setCursor(0, 2);
  804. lcd_printPGM(MSG_PRESS);
  805. }
  806. void lcd_change_success() {
  807. lcd_implementation_clear();
  808. lcd.setCursor(0, 2);
  809. lcd_printPGM(MSG_CHANGE_SUCCESS);
  810. }
  811. void lcd_loading_color() {
  812. lcd_implementation_clear();
  813. lcd.setCursor(0, 0);
  814. lcd_printPGM(MSG_LOADING_COLOR);
  815. lcd.setCursor(0, 2);
  816. lcd_printPGM(MSG_PLEASE_WAIT);
  817. for (int i = 0; i < 20; i++) {
  818. lcd.setCursor(i, 3);
  819. lcd.print(".");
  820. for (int j = 0; j < 10 ; j++) {
  821. manage_heater();
  822. manage_inactivity(true);
  823. delay(85);
  824. }
  825. }
  826. }
  827. void lcd_loading_filament() {
  828. lcd_implementation_clear();
  829. lcd.setCursor(0, 0);
  830. lcd_printPGM(MSG_LOADING_FILAMENT);
  831. lcd.setCursor(0, 2);
  832. lcd_printPGM(MSG_PLEASE_WAIT);
  833. for (int i = 0; i < 20; i++) {
  834. lcd.setCursor(i, 3);
  835. lcd.print(".");
  836. for (int j = 0; j < 10 ; j++) {
  837. manage_heater();
  838. manage_inactivity(true);
  839. delay(110);
  840. }
  841. }
  842. }
  843. void lcd_alright() {
  844. int enc_dif = 0;
  845. int cursor_pos = 1;
  846. lcd_implementation_clear();
  847. lcd.setCursor(0, 0);
  848. lcd_printPGM(MSG_CORRECTLY);
  849. lcd.setCursor(1, 1);
  850. lcd_printPGM(MSG_YES);
  851. lcd.setCursor(1, 2);
  852. lcd_printPGM(MSG_NOT_LOADED);
  853. lcd.setCursor(1, 3);
  854. lcd_printPGM(MSG_NOT_COLOR);
  855. lcd.setCursor(0, 1);
  856. lcd.print(">");
  857. enc_dif = encoderDiff;
  858. while (lcd_change_fil_state == 0) {
  859. manage_heater();
  860. manage_inactivity(true);
  861. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  862. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  863. if (enc_dif > encoderDiff ) {
  864. cursor_pos --;
  865. }
  866. if (enc_dif < encoderDiff ) {
  867. cursor_pos ++;
  868. }
  869. if (cursor_pos > 3) {
  870. cursor_pos = 3;
  871. }
  872. if (cursor_pos < 1) {
  873. cursor_pos = 1;
  874. }
  875. lcd.setCursor(0, 1);
  876. lcd.print(" ");
  877. lcd.setCursor(0, 2);
  878. lcd.print(" ");
  879. lcd.setCursor(0, 3);
  880. lcd.print(" ");
  881. lcd.setCursor(0, cursor_pos);
  882. lcd.print(">");
  883. enc_dif = encoderDiff;
  884. delay(100);
  885. }
  886. }
  887. if (lcd_clicked()) {
  888. lcd_change_fil_state = cursor_pos;
  889. delay(500);
  890. }
  891. };
  892. lcd_implementation_clear();
  893. lcd_return_to_status();
  894. }
  895. void lcd_LoadFilament()
  896. {
  897. if (degHotend0() > EXTRUDE_MINTEMP)
  898. {
  899. custom_message = true;
  900. lcd_commands_type = LCD_COMMAND_LOAD_FILAMENT;
  901. SERIAL_ECHOLN("Loading filament");
  902. // commands() will handle the rest
  903. }
  904. else
  905. {
  906. lcd_implementation_clear();
  907. lcd.setCursor(0, 0);
  908. lcd_printPGM(MSG_ERROR);
  909. lcd.setCursor(0, 2);
  910. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  911. delay(2000);
  912. lcd_implementation_clear();
  913. }
  914. lcd_return_to_status();
  915. }
  916. void lcd_menu_statistics()
  917. {
  918. if (IS_SD_PRINTING)
  919. {
  920. int _met = total_filament_used / 100000;
  921. int _cm = (total_filament_used - (_met * 100000))/10;
  922. int _t = (millis() - starttime) / 1000;
  923. int _h = _t / 3600;
  924. int _m = (_t - (_h * 3600)) / 60;
  925. int _s = _t - ((_h * 3600) + (_m * 60));
  926. lcd.setCursor(0, 0);
  927. lcd_printPGM(MSG_STATS_FILAMENTUSED);
  928. lcd.setCursor(6, 1);
  929. lcd.print(itostr3(_met));
  930. lcd.print("m ");
  931. lcd.print(ftostr32ns(_cm));
  932. lcd.print("cm");
  933. lcd.setCursor(0, 2);
  934. lcd_printPGM(MSG_STATS_PRINTTIME);
  935. lcd.setCursor(8, 3);
  936. lcd.print(itostr2(_h));
  937. lcd.print("h ");
  938. lcd.print(itostr2(_m));
  939. lcd.print("m ");
  940. lcd.print(itostr2(_s));
  941. lcd.print("s");
  942. if (lcd_clicked())
  943. {
  944. lcd_quick_feedback();
  945. lcd_return_to_status();
  946. }
  947. }
  948. else
  949. {
  950. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  951. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME);
  952. uint8_t _days, _hours, _minutes;
  953. float _filament_m = (float)_filament;
  954. int _filament_km = (_filament >= 100000) ? _filament / 100000 : 0;
  955. if (_filament_km > 0) _filament_m = _filament - (_filament_km * 100000);
  956. _days = _time / 1440;
  957. _hours = (_time - (_days * 1440)) / 60;
  958. _minutes = _time - ((_days * 1440) + (_hours * 60));
  959. lcd_implementation_clear();
  960. lcd.setCursor(0, 0);
  961. lcd_printPGM(MSG_STATS_TOTALFILAMENT);
  962. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)), 1);
  963. lcd.print(ftostr32ns(_filament_m));
  964. if (_filament_km > 0)
  965. {
  966. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)) - 3, 1);
  967. lcd.print("km");
  968. lcd.setCursor(17 - strlen(ftostr32ns(_filament_m)) - 8, 1);
  969. lcd.print(itostr4(_filament_km));
  970. }
  971. lcd.setCursor(18, 1);
  972. lcd.print("m");
  973. lcd.setCursor(0, 2);
  974. lcd_printPGM(MSG_STATS_TOTALPRINTTIME);;
  975. lcd.setCursor(18, 3);
  976. lcd.print("m");
  977. lcd.setCursor(14, 3);
  978. lcd.print(itostr3(_minutes));
  979. lcd.setCursor(14, 3);
  980. lcd.print(":");
  981. lcd.setCursor(12, 3);
  982. lcd.print("h");
  983. lcd.setCursor(9, 3);
  984. lcd.print(itostr3(_hours));
  985. lcd.setCursor(9, 3);
  986. lcd.print(":");
  987. lcd.setCursor(7, 3);
  988. lcd.print("d");
  989. lcd.setCursor(4, 3);
  990. lcd.print(itostr3(_days));
  991. while (!lcd_clicked())
  992. {
  993. manage_heater();
  994. manage_inactivity(true);
  995. delay(100);
  996. }
  997. lcd_quick_feedback();
  998. lcd_return_to_status();
  999. }
  1000. }
  1001. static void _lcd_move(const char *name, int axis, int min, int max) {
  1002. if (encoderPosition != 0) {
  1003. refresh_cmd_timeout();
  1004. if (! planner_queue_full()) {
  1005. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  1006. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  1007. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  1008. encoderPosition = 0;
  1009. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  1010. 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);
  1011. lcdDrawUpdate = 1;
  1012. }
  1013. }
  1014. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  1015. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  1016. }
  1017. static void lcd_move_e()
  1018. {
  1019. if (degHotend0() > EXTRUDE_MINTEMP) {
  1020. if (encoderPosition != 0)
  1021. {
  1022. refresh_cmd_timeout();
  1023. if (! planner_queue_full()) {
  1024. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  1025. encoderPosition = 0;
  1026. 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);
  1027. lcdDrawUpdate = 1;
  1028. }
  1029. }
  1030. if (lcdDrawUpdate)
  1031. {
  1032. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  1033. }
  1034. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  1035. }
  1036. else {
  1037. lcd_implementation_clear();
  1038. lcd.setCursor(0, 0);
  1039. lcd_printPGM(MSG_ERROR);
  1040. lcd.setCursor(0, 2);
  1041. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  1042. delay(2000);
  1043. lcd_return_to_status();
  1044. }
  1045. }
  1046. // Save a single axis babystep value.
  1047. void EEPROM_save_B(int pos, int* value)
  1048. {
  1049. union Data data;
  1050. data.value = *value;
  1051. eeprom_update_byte((unsigned char*)pos, data.b[0]);
  1052. eeprom_update_byte((unsigned char*)pos + 1, data.b[1]);
  1053. }
  1054. // Read a single axis babystep value.
  1055. void EEPROM_read_B(int pos, int* value)
  1056. {
  1057. union Data data;
  1058. data.b[0] = eeprom_read_byte((unsigned char*)pos);
  1059. data.b[1] = eeprom_read_byte((unsigned char*)pos + 1);
  1060. *value = data.value;
  1061. }
  1062. static void lcd_move_x() {
  1063. _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS);
  1064. }
  1065. static void lcd_move_y() {
  1066. _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  1067. }
  1068. static void lcd_move_z() {
  1069. _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  1070. }
  1071. static void _lcd_babystep(int axis, const char *msg)
  1072. {
  1073. if (menuData.babyStep.status == 0) {
  1074. // Menu was entered.
  1075. // Initialize its status.
  1076. menuData.babyStep.status = 1;
  1077. EEPROM_read_B(EEPROM_BABYSTEP_X, &menuData.babyStep.babystepMem[0]);
  1078. EEPROM_read_B(EEPROM_BABYSTEP_Y, &menuData.babyStep.babystepMem[1]);
  1079. EEPROM_read_B(EEPROM_BABYSTEP_Z, &menuData.babyStep.babystepMem[2]);
  1080. menuData.babyStep.babystepMemMM[0] = menuData.babyStep.babystepMem[0]/axis_steps_per_unit[X_AXIS];
  1081. menuData.babyStep.babystepMemMM[1] = menuData.babyStep.babystepMem[1]/axis_steps_per_unit[Y_AXIS];
  1082. menuData.babyStep.babystepMemMM[2] = menuData.babyStep.babystepMem[2]/axis_steps_per_unit[Z_AXIS];
  1083. lcdDrawUpdate = 1;
  1084. // Wait 90 seconds before closing the live adjust dialog.
  1085. lcd_timeoutToStatus = millis() + 90000;
  1086. }
  1087. if (encoderPosition != 0)
  1088. {
  1089. CRITICAL_SECTION_START
  1090. babystepsTodo[axis] += (int)encoderPosition;
  1091. CRITICAL_SECTION_END
  1092. menuData.babyStep.babystepMem[axis] += (int)encoderPosition;
  1093. menuData.babyStep.babystepMemMM[axis] = menuData.babyStep.babystepMem[axis]/axis_steps_per_unit[Z_AXIS];
  1094. delay(50);
  1095. encoderPosition = 0;
  1096. lcdDrawUpdate = 1;
  1097. }
  1098. if (lcdDrawUpdate)
  1099. lcd_implementation_drawedit_2(msg, ftostr13ns(menuData.babyStep.babystepMemMM[axis]));
  1100. if (LCD_CLICKED || menuExiting) {
  1101. // Only update the EEPROM when leaving the menu.
  1102. EEPROM_save_B(
  1103. (axis == 0) ? EEPROM_BABYSTEP_X : ((axis == 1) ? EEPROM_BABYSTEP_Y : EEPROM_BABYSTEP_Z),
  1104. &menuData.babyStep.babystepMem[axis]);
  1105. }
  1106. if (LCD_CLICKED) lcd_goto_menu(lcd_main_menu);
  1107. }
  1108. static void lcd_babystep_x() {
  1109. _lcd_babystep(X_AXIS, (MSG_BABYSTEPPING_X));
  1110. }
  1111. static void lcd_babystep_y() {
  1112. _lcd_babystep(Y_AXIS, (MSG_BABYSTEPPING_Y));
  1113. }
  1114. static void lcd_babystep_z() {
  1115. _lcd_babystep(Z_AXIS, (MSG_BABYSTEPPING_Z));
  1116. }
  1117. static void lcd_adjust_bed();
  1118. static void lcd_adjust_bed_reset()
  1119. {
  1120. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  1121. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  1122. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  1123. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  1124. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  1125. lcd_goto_menu(lcd_adjust_bed, 0, false);
  1126. // Because we did not leave the menu, the menuData did not reset.
  1127. // Force refresh of the bed leveling data.
  1128. menuData.adjustBed.status = 0;
  1129. }
  1130. void adjust_bed_reset() {
  1131. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  1132. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT, 0);
  1133. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  1134. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  1135. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR, 0);
  1136. menuData.adjustBed.left = menuData.adjustBed.left2 = 0;
  1137. menuData.adjustBed.right = menuData.adjustBed.right2 = 0;
  1138. menuData.adjustBed.front = menuData.adjustBed.front2 = 0;
  1139. menuData.adjustBed.rear = menuData.adjustBed.rear2 = 0;
  1140. }
  1141. #define BED_ADJUSTMENT_UM_MAX 50
  1142. static void lcd_adjust_bed()
  1143. {
  1144. if (menuData.adjustBed.status == 0) {
  1145. // Menu was entered.
  1146. // Initialize its status.
  1147. menuData.adjustBed.status = 1;
  1148. bool valid = false;
  1149. menuData.adjustBed.left = menuData.adjustBed.left2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT);
  1150. menuData.adjustBed.right = menuData.adjustBed.right2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT);
  1151. menuData.adjustBed.front = menuData.adjustBed.front2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT);
  1152. menuData.adjustBed.rear = menuData.adjustBed.rear2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR);
  1153. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1 &&
  1154. menuData.adjustBed.left >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.left <= BED_ADJUSTMENT_UM_MAX &&
  1155. menuData.adjustBed.right >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.right <= BED_ADJUSTMENT_UM_MAX &&
  1156. menuData.adjustBed.front >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.front <= BED_ADJUSTMENT_UM_MAX &&
  1157. menuData.adjustBed.rear >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.rear <= BED_ADJUSTMENT_UM_MAX)
  1158. valid = true;
  1159. if (! valid) {
  1160. // Reset the values: simulate an edit.
  1161. menuData.adjustBed.left2 = 0;
  1162. menuData.adjustBed.right2 = 0;
  1163. menuData.adjustBed.front2 = 0;
  1164. menuData.adjustBed.rear2 = 0;
  1165. }
  1166. lcdDrawUpdate = 1;
  1167. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  1168. }
  1169. if (menuData.adjustBed.left != menuData.adjustBed.left2)
  1170. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, menuData.adjustBed.left = menuData.adjustBed.left2);
  1171. if (menuData.adjustBed.right != menuData.adjustBed.right2)
  1172. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, menuData.adjustBed.right = menuData.adjustBed.right2);
  1173. if (menuData.adjustBed.front != menuData.adjustBed.front2)
  1174. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, menuData.adjustBed.front = menuData.adjustBed.front2);
  1175. if (menuData.adjustBed.rear != menuData.adjustBed.rear2)
  1176. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, menuData.adjustBed.rear = menuData.adjustBed.rear2);
  1177. START_MENU();
  1178. MENU_ITEM(back, MSG_SETTINGS, lcd_calibration_menu);
  1179. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_LEFT, &menuData.adjustBed.left2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1180. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_RIGHT, &menuData.adjustBed.right2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1181. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_FRONT, &menuData.adjustBed.front2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1182. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_REAR, &menuData.adjustBed.rear2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1183. MENU_ITEM(function, MSG_BED_CORRECTION_RESET, lcd_adjust_bed_reset);
  1184. END_MENU();
  1185. }
  1186. void lcd_adjust_z() {
  1187. int enc_dif = 0;
  1188. int cursor_pos = 1;
  1189. int fsm = 0;
  1190. lcd_implementation_clear();
  1191. lcd.setCursor(0, 0);
  1192. lcd_printPGM(MSG_ADJUSTZ);
  1193. lcd.setCursor(1, 1);
  1194. lcd_printPGM(MSG_YES);
  1195. lcd.setCursor(1, 2);
  1196. lcd_printPGM(MSG_NO);
  1197. lcd.setCursor(0, 1);
  1198. lcd.print(">");
  1199. enc_dif = encoderDiff;
  1200. while (fsm == 0) {
  1201. manage_heater();
  1202. manage_inactivity(true);
  1203. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1204. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1205. if (enc_dif > encoderDiff ) {
  1206. cursor_pos --;
  1207. }
  1208. if (enc_dif < encoderDiff ) {
  1209. cursor_pos ++;
  1210. }
  1211. if (cursor_pos > 2) {
  1212. cursor_pos = 2;
  1213. }
  1214. if (cursor_pos < 1) {
  1215. cursor_pos = 1;
  1216. }
  1217. lcd.setCursor(0, 1);
  1218. lcd.print(" ");
  1219. lcd.setCursor(0, 2);
  1220. lcd.print(" ");
  1221. lcd.setCursor(0, cursor_pos);
  1222. lcd.print(">");
  1223. enc_dif = encoderDiff;
  1224. delay(100);
  1225. }
  1226. }
  1227. if (lcd_clicked()) {
  1228. fsm = cursor_pos;
  1229. if (fsm == 1) {
  1230. int babystepLoadZ = 0;
  1231. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ);
  1232. CRITICAL_SECTION_START
  1233. babystepsTodo[Z_AXIS] = babystepLoadZ;
  1234. CRITICAL_SECTION_END
  1235. } else {
  1236. int zero = 0;
  1237. EEPROM_save_B(EEPROM_BABYSTEP_X, &zero);
  1238. EEPROM_save_B(EEPROM_BABYSTEP_Y, &zero);
  1239. EEPROM_save_B(EEPROM_BABYSTEP_Z, &zero);
  1240. }
  1241. delay(500);
  1242. }
  1243. };
  1244. lcd_implementation_clear();
  1245. lcd_return_to_status();
  1246. }
  1247. void lcd_wait_for_cool_down() {
  1248. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  1249. lcd_display_message_fullscreen_P(MSG_WAITING_TEMP);
  1250. lcd.setCursor(0, 2);
  1251. lcd.print(LCD_STR_THERMOMETER[0]);
  1252. lcd.print(ftostr3(degHotend(0)));
  1253. lcd.print("/0");
  1254. // lcd.print(LCD_STR_DEGREE);
  1255. // lcd_printPGM(PSTR(LCD_STR_DEGREE));
  1256. lcd.setCursor(0, 3);
  1257. lcd.print(LCD_STR_BEDTEMP[0]);
  1258. lcd.print(ftostr3(degBed()));
  1259. lcd.print("/0");
  1260. // lcd_printPGM(PSTR(LCD_STR_DEGREE));
  1261. delay_keep_alive(1000);
  1262. }
  1263. }
  1264. // Lets the user move the Z carriage up to the end stoppers.
  1265. // When done, it sets the current Z to Z_MAX_POS and returns true.
  1266. // Otherwise the Z calibration is not changed and false is returned.
  1267. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  1268. {
  1269. bool clean_nozzle_asked = false;
  1270. // 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.
  1271. current_position[Z_AXIS] = 0;
  1272. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  1273. // Until confirmed by the confirmation dialog.
  1274. for (;;) {
  1275. unsigned long previous_millis_cmd = millis();
  1276. const char *msg = only_z ? MSG_MOVE_CARRIAGE_TO_THE_TOP_Z : MSG_MOVE_CARRIAGE_TO_THE_TOP;
  1277. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  1278. const bool multi_screen = msg_next != NULL;
  1279. unsigned long previous_millis_msg = millis();
  1280. // Until the user finishes the z up movement.
  1281. encoderDiff = 0;
  1282. encoderPosition = 0;
  1283. for (;;) {
  1284. // if (millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  1285. // goto canceled;
  1286. manage_heater();
  1287. manage_inactivity(true);
  1288. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) {
  1289. delay(50);
  1290. previous_millis_cmd = millis();
  1291. encoderPosition += abs(encoderDiff / ENCODER_PULSES_PER_STEP);
  1292. encoderDiff = 0;
  1293. if (! planner_queue_full()) {
  1294. // Only move up, whatever direction the user rotates the encoder.
  1295. current_position[Z_AXIS] += fabs(encoderPosition);
  1296. encoderPosition = 0;
  1297. 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);
  1298. }
  1299. }
  1300. if (lcd_clicked()) {
  1301. // Abort a move if in progress.
  1302. planner_abort_hard();
  1303. while (lcd_clicked()) ;
  1304. delay(10);
  1305. while (lcd_clicked()) ;
  1306. break;
  1307. }
  1308. if (multi_screen && millis() - previous_millis_msg > 5000) {
  1309. if (msg_next == NULL)
  1310. msg_next = msg;
  1311. msg_next = lcd_display_message_fullscreen_P(msg_next);
  1312. previous_millis_msg = millis();
  1313. }
  1314. }
  1315. if (! clean_nozzle_asked) {
  1316. lcd_show_fullscreen_message_and_wait_P(MSG_CONFIRM_NOZZLE_CLEAN);
  1317. clean_nozzle_asked = true;
  1318. }
  1319. // Let the user confirm, that the Z carriage is at the top end stoppers.
  1320. int8_t result = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_CONFIRM_CARRIAGE_AT_THE_TOP, false);
  1321. if (result == -1)
  1322. goto canceled;
  1323. else if (result == 1)
  1324. goto calibrated;
  1325. // otherwise perform another round of the Z up dialog.
  1326. }
  1327. calibrated:
  1328. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  1329. // during the search for the induction points.
  1330. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  1331. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  1332. if(only_z){/*
  1333. lcd_display_message_fullscreen_P(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1);
  1334. lcd_implementation_print_at(0, 3, 1);
  1335. lcd_printPGM(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2);*/
  1336. }else{
  1337. lcd_display_message_fullscreen_P(MSG_FIND_BED_OFFSET_AND_SKEW_LINE1);
  1338. lcd_implementation_print_at(0, 2, 1);
  1339. lcd_printPGM(MSG_FIND_BED_OFFSET_AND_SKEW_LINE2);
  1340. }
  1341. return true;
  1342. canceled:
  1343. return false;
  1344. }
  1345. static inline bool pgm_is_whitespace(const char *c_addr)
  1346. {
  1347. const char c = pgm_read_byte(c_addr);
  1348. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  1349. }
  1350. static inline bool pgm_is_interpunction(const char *c_addr)
  1351. {
  1352. const char c = pgm_read_byte(c_addr);
  1353. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  1354. }
  1355. const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines)
  1356. {
  1357. // Disable update of the screen by the usual lcd_update() routine.
  1358. lcd_update_enable(false);
  1359. lcd_implementation_clear();
  1360. lcd.setCursor(0, 0);
  1361. const char *msgend = msg;
  1362. uint8_t row = 0;
  1363. bool multi_screen = false;
  1364. for (; row < 4; ++ row) {
  1365. while (pgm_is_whitespace(msg))
  1366. ++ msg;
  1367. if (pgm_read_byte(msg) == 0)
  1368. // End of the message.
  1369. break;
  1370. lcd.setCursor(0, row);
  1371. uint8_t linelen = min(strlen_P(msg), 20);
  1372. const char *msgend2 = msg + linelen;
  1373. msgend = msgend2;
  1374. if (row == 3 && linelen == 20) {
  1375. // Last line of the display, full line shall be displayed.
  1376. // Find out, whether this message will be split into multiple screens.
  1377. while (pgm_is_whitespace(msgend))
  1378. ++ msgend;
  1379. multi_screen = pgm_read_byte(msgend) != 0;
  1380. if (multi_screen)
  1381. msgend = (msgend2 -= 2);
  1382. }
  1383. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  1384. // Splitting a word. Find the start of the current word.
  1385. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  1386. -- msgend;
  1387. if (msgend == msg)
  1388. // Found a single long word, which cannot be split. Just cut it.
  1389. msgend = msgend2;
  1390. }
  1391. for (; msg < msgend; ++ msg) {
  1392. char c = char(pgm_read_byte(msg));
  1393. if (c == '~')
  1394. c = ' ';
  1395. lcd.print(c);
  1396. }
  1397. }
  1398. if (multi_screen) {
  1399. // Display the "next screen" indicator character.
  1400. // lcd_set_custom_characters_arrows();
  1401. lcd_set_custom_characters_nextpage();
  1402. lcd.setCursor(19, 3);
  1403. // Display the down arrow.
  1404. lcd.print(char(1));
  1405. }
  1406. nlines = row;
  1407. return multi_screen ? msgend : NULL;
  1408. }
  1409. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  1410. {
  1411. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  1412. bool multi_screen = msg_next != NULL;
  1413. // Until confirmed by a button click.
  1414. for (;;) {
  1415. // Wait for 5 seconds before displaying the next text.
  1416. for (uint8_t i = 0; i < 100; ++ i) {
  1417. delay_keep_alive(50);
  1418. if (lcd_clicked()) {
  1419. while (lcd_clicked()) ;
  1420. delay(10);
  1421. while (lcd_clicked()) ;
  1422. return;
  1423. }
  1424. }
  1425. if (multi_screen) {
  1426. if (msg_next == NULL)
  1427. msg_next = msg;
  1428. msg_next = lcd_display_message_fullscreen_P(msg_next);
  1429. }
  1430. }
  1431. }
  1432. void lcd_wait_for_click()
  1433. {
  1434. for (;;) {
  1435. manage_heater();
  1436. manage_inactivity(true);
  1437. if (lcd_clicked()) {
  1438. while (lcd_clicked()) ;
  1439. delay(10);
  1440. while (lcd_clicked()) ;
  1441. return;
  1442. }
  1443. }
  1444. }
  1445. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting)
  1446. {
  1447. lcd_display_message_fullscreen_P(msg);
  1448. lcd.setCursor(1, 2);
  1449. lcd_printPGM(MSG_YES);
  1450. lcd.setCursor(0, 3);
  1451. lcd_printPGM(PSTR(">"));
  1452. lcd_printPGM(MSG_NO);
  1453. bool yes = false;
  1454. // Wait for user confirmation or a timeout.
  1455. unsigned long previous_millis_cmd = millis();
  1456. int8_t enc_dif = encoderDiff;
  1457. for (;;) {
  1458. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  1459. return -1;
  1460. manage_heater();
  1461. manage_inactivity(true);
  1462. if (abs((enc_dif - encoderDiff)) > 4) {
  1463. if (abs(enc_dif - encoderDiff) > 1) {
  1464. lcd.setCursor(0, 2);
  1465. if (enc_dif > encoderDiff && yes) {
  1466. lcd_printPGM((PSTR(" ")));
  1467. lcd.setCursor(0, 3);
  1468. lcd_printPGM((PSTR(">")));
  1469. yes = false;
  1470. } else if (enc_dif < encoderDiff && ! yes) {
  1471. lcd_printPGM((PSTR(">")));
  1472. lcd.setCursor(0, 3);
  1473. lcd_printPGM((PSTR(" ")));
  1474. yes = true;
  1475. }
  1476. enc_dif = encoderDiff;
  1477. }
  1478. }
  1479. if (lcd_clicked()) {
  1480. while (lcd_clicked()) ;
  1481. delay(10);
  1482. while (lcd_clicked()) ;
  1483. return yes;
  1484. }
  1485. }
  1486. }
  1487. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  1488. {
  1489. const char *msg = NULL;
  1490. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  1491. lcd_show_fullscreen_message_and_wait_P(MSG_BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND);
  1492. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  1493. if (point_too_far_mask == 0)
  1494. msg = MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
  1495. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  1496. // Only the center point or all the three front points.
  1497. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR;
  1498. else if (point_too_far_mask & 1 == 0)
  1499. // The right and maybe the center point out of reach.
  1500. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR;
  1501. else
  1502. // The left and maybe the center point out of reach.
  1503. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR;
  1504. lcd_show_fullscreen_message_and_wait_P(msg);
  1505. } else {
  1506. if (point_too_far_mask != 0) {
  1507. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  1508. // Only the center point or all the three front points.
  1509. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR;
  1510. else if (point_too_far_mask & 1 == 0)
  1511. // The right and maybe the center point out of reach.
  1512. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR;
  1513. else
  1514. // The left and maybe the center point out of reach.
  1515. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR;
  1516. lcd_show_fullscreen_message_and_wait_P(msg);
  1517. }
  1518. if (point_too_far_mask == 0 || result > 0) {
  1519. switch (result) {
  1520. default:
  1521. // should not happen
  1522. msg = MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
  1523. break;
  1524. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  1525. msg = MSG_BED_SKEW_OFFSET_DETECTION_PERFECT;
  1526. break;
  1527. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  1528. msg = MSG_BED_SKEW_OFFSET_DETECTION_SKEW_MILD;
  1529. break;
  1530. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  1531. msg = MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME;
  1532. break;
  1533. }
  1534. lcd_show_fullscreen_message_and_wait_P(msg);
  1535. }
  1536. }
  1537. }
  1538. static void lcd_show_end_stops() {
  1539. lcd.setCursor(0, 0);
  1540. lcd_printPGM((PSTR("End stops diag")));
  1541. lcd.setCursor(0, 1);
  1542. lcd_printPGM((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("X1")) : (PSTR("X0")));
  1543. lcd.setCursor(0, 2);
  1544. lcd_printPGM((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Y1")) : (PSTR("Y0")));
  1545. lcd.setCursor(0, 3);
  1546. lcd_printPGM((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Z1")) : (PSTR("Z0")));
  1547. }
  1548. static void menu_show_end_stops() {
  1549. lcd_show_end_stops();
  1550. if (LCD_CLICKED) lcd_goto_menu(lcd_calibration_menu);
  1551. }
  1552. // Lets the user move the Z carriage up to the end stoppers.
  1553. // When done, it sets the current Z to Z_MAX_POS and returns true.
  1554. // Otherwise the Z calibration is not changed and false is returned.
  1555. void lcd_diag_show_end_stops()
  1556. {
  1557. int enc_dif = encoderDiff;
  1558. lcd_implementation_clear();
  1559. for (;;) {
  1560. manage_heater();
  1561. manage_inactivity(true);
  1562. lcd_show_end_stops();
  1563. if (lcd_clicked()) {
  1564. while (lcd_clicked()) ;
  1565. delay(10);
  1566. while (lcd_clicked()) ;
  1567. break;
  1568. }
  1569. }
  1570. lcd_implementation_clear();
  1571. lcd_return_to_status();
  1572. }
  1573. void prusa_statistics(int _message) {
  1574. switch (_message)
  1575. {
  1576. case 0: // default message
  1577. if (IS_SD_PRINTING)
  1578. {
  1579. SERIAL_ECHO("{");
  1580. prusa_stat_printerstatus(4);
  1581. prusa_stat_printinfo();
  1582. SERIAL_ECHOLN("}");
  1583. }
  1584. else
  1585. {
  1586. SERIAL_ECHO("{");
  1587. prusa_stat_printerstatus(1);
  1588. SERIAL_ECHOLN("}");
  1589. }
  1590. break;
  1591. case 1: // 1 heating
  1592. farm_status = 2;
  1593. SERIAL_ECHO("{");
  1594. prusa_stat_printerstatus(2);
  1595. SERIAL_ECHOLN("}");
  1596. farm_timer = 1;
  1597. break;
  1598. case 2: // heating done
  1599. farm_status = 3;
  1600. SERIAL_ECHO("{");
  1601. prusa_stat_printerstatus(3);
  1602. SERIAL_ECHOLN("}");
  1603. farm_timer = 1;
  1604. if (IS_SD_PRINTING)
  1605. {
  1606. farm_status = 4;
  1607. SERIAL_ECHO("{");
  1608. prusa_stat_printerstatus(4);
  1609. SERIAL_ECHOLN("}");
  1610. }
  1611. else
  1612. {
  1613. SERIAL_ECHO("{");
  1614. prusa_stat_printerstatus(3);
  1615. SERIAL_ECHOLN("}");;
  1616. }
  1617. farm_timer = 1;
  1618. break;
  1619. case 3: // filament change
  1620. break;
  1621. case 4: // print succesfull
  1622. SERIAL_ECHOLN("{[RES:1]}");
  1623. farm_timer = 2;
  1624. break;
  1625. case 5: // print not succesfull
  1626. SERIAL_ECHOLN("{[RES:0]}");
  1627. farm_timer = 2;
  1628. break;
  1629. case 6: // print done
  1630. SERIAL_ECHOLN("{[PRN:8]}");
  1631. farm_timer = 2;
  1632. break;
  1633. case 7: // print done - stopped
  1634. SERIAL_ECHOLN("{[PRN:9]}");
  1635. farm_timer = 2;
  1636. break;
  1637. case 8: // printer started
  1638. SERIAL_ECHO("{[PRN:0][PFN:");
  1639. SERIAL_ECHO(farm_no);
  1640. SERIAL_ECHOLN("]}");
  1641. farm_timer = 2;
  1642. break;
  1643. case 20: // echo farm no
  1644. SERIAL_ECHO("{[PFN:");
  1645. SERIAL_ECHO(farm_no);
  1646. SERIAL_ECHOLN("]}");
  1647. farm_timer = 5;
  1648. break;
  1649. case 21: // temperatures
  1650. SERIAL_ECHO("{");
  1651. prusa_stat_temperatures();
  1652. SERIAL_ECHOLN("}");
  1653. break;
  1654. case 22: // waiting for filament change
  1655. SERIAL_ECHOLN("{[PRN:5]}");
  1656. break;
  1657. case 90: // Error - Thermal Runaway
  1658. SERIAL_ECHOLN("{[ERR:1]}");
  1659. break;
  1660. case 91: // Error - Thermal Runaway Preheat
  1661. SERIAL_ECHOLN("{[ERR:2]}");
  1662. break;
  1663. case 92: // Error - Min temp
  1664. SERIAL_ECHOLN("{[ERR:3]}");
  1665. break;
  1666. case 93: // Error - Max temp
  1667. SERIAL_ECHOLN("{[ERR:4]}");
  1668. break;
  1669. case 99: // heartbeat
  1670. SERIAL_ECHO("{[PRN:99]");
  1671. prusa_stat_temperatures();
  1672. SERIAL_ECHOLN("}");
  1673. break;
  1674. }
  1675. }
  1676. static void prusa_stat_printerstatus(int _status)
  1677. {
  1678. SERIAL_ECHO("[PRN:");
  1679. SERIAL_ECHO(_status);
  1680. SERIAL_ECHO("]");
  1681. }
  1682. static void prusa_stat_temperatures()
  1683. {
  1684. SERIAL_ECHO("[ST0:");
  1685. SERIAL_ECHO(target_temperature[0]);
  1686. SERIAL_ECHO("][STB:");
  1687. SERIAL_ECHO(target_temperature_bed);
  1688. SERIAL_ECHO("][AT0:");
  1689. SERIAL_ECHO(current_temperature[0]);
  1690. SERIAL_ECHO("][ATB:");
  1691. SERIAL_ECHO(current_temperature_bed);
  1692. SERIAL_ECHO("]");
  1693. }
  1694. static void prusa_stat_printinfo()
  1695. {
  1696. SERIAL_ECHO("[TFU:");
  1697. SERIAL_ECHO(total_filament_used);
  1698. SERIAL_ECHO("][PCD:");
  1699. SERIAL_ECHO(itostr3(card.percentDone()));
  1700. SERIAL_ECHO("][FEM:");
  1701. SERIAL_ECHO(itostr3(feedmultiply));
  1702. SERIAL_ECHO("][FNM:");
  1703. SERIAL_ECHO(longFilenameOLD);
  1704. SERIAL_ECHO("][TIM:");
  1705. if (starttime != 0)
  1706. {
  1707. SERIAL_ECHO(millis() / 1000 - starttime / 1000);
  1708. }
  1709. else
  1710. {
  1711. SERIAL_ECHO(0);
  1712. }
  1713. SERIAL_ECHO("][FWR:");
  1714. SERIAL_ECHO(FW_version);
  1715. SERIAL_ECHO("]");
  1716. }
  1717. void lcd_pick_babystep(){
  1718. int enc_dif = 0;
  1719. int cursor_pos = 1;
  1720. int fsm = 0;
  1721. lcd_implementation_clear();
  1722. lcd.setCursor(0, 0);
  1723. lcd_printPGM(MSG_PICK_Z);
  1724. lcd.setCursor(3, 2);
  1725. lcd.print("1");
  1726. lcd.setCursor(3, 3);
  1727. lcd.print("2");
  1728. lcd.setCursor(12, 2);
  1729. lcd.print("3");
  1730. lcd.setCursor(12, 3);
  1731. lcd.print("4");
  1732. lcd.setCursor(1, 2);
  1733. lcd.print(">");
  1734. enc_dif = encoderDiff;
  1735. while (fsm == 0) {
  1736. manage_heater();
  1737. manage_inactivity(true);
  1738. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1739. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1740. if (enc_dif > encoderDiff ) {
  1741. cursor_pos --;
  1742. }
  1743. if (enc_dif < encoderDiff ) {
  1744. cursor_pos ++;
  1745. }
  1746. if (cursor_pos > 4) {
  1747. cursor_pos = 4;
  1748. }
  1749. if (cursor_pos < 1) {
  1750. cursor_pos = 1;
  1751. }
  1752. lcd.setCursor(1, 2);
  1753. lcd.print(" ");
  1754. lcd.setCursor(1, 3);
  1755. lcd.print(" ");
  1756. lcd.setCursor(10, 2);
  1757. lcd.print(" ");
  1758. lcd.setCursor(10, 3);
  1759. lcd.print(" ");
  1760. if (cursor_pos < 3) {
  1761. lcd.setCursor(1, cursor_pos+1);
  1762. lcd.print(">");
  1763. }else{
  1764. lcd.setCursor(10, cursor_pos-1);
  1765. lcd.print(">");
  1766. }
  1767. enc_dif = encoderDiff;
  1768. delay(100);
  1769. }
  1770. }
  1771. if (lcd_clicked()) {
  1772. fsm = cursor_pos;
  1773. int babyStepZ;
  1774. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babyStepZ);
  1775. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babyStepZ);
  1776. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  1777. delay(500);
  1778. }
  1779. };
  1780. lcd_implementation_clear();
  1781. lcd_return_to_status();
  1782. }
  1783. void lcd_move_menu_axis()
  1784. {
  1785. START_MENU();
  1786. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  1787. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  1788. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  1789. if (move_menu_scale < 10.0)
  1790. {
  1791. if (!isPrintPaused)
  1792. {
  1793. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  1794. }
  1795. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  1796. }
  1797. END_MENU();
  1798. }
  1799. static void lcd_move_menu_1mm()
  1800. {
  1801. move_menu_scale = 1.0;
  1802. lcd_move_menu_axis();
  1803. }
  1804. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  1805. {
  1806. do
  1807. {
  1808. eeprom_write_byte((unsigned char*)pos, *value);
  1809. pos++;
  1810. value++;
  1811. } while (--size);
  1812. }
  1813. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  1814. {
  1815. do
  1816. {
  1817. *value = eeprom_read_byte((unsigned char*)pos);
  1818. pos++;
  1819. value++;
  1820. } while (--size);
  1821. }
  1822. static void lcd_silent_mode_set() {
  1823. SilentModeMenu = !SilentModeMenu;
  1824. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  1825. digipot_init();
  1826. lcd_goto_menu(lcd_settings_menu, 7);
  1827. }
  1828. static void lcd_set_lang(unsigned char lang) {
  1829. lang_selected = lang;
  1830. firstrun = 1;
  1831. eeprom_update_byte((unsigned char *)EEPROM_LANG, lang);
  1832. /*langsel=0;*/
  1833. if (langsel == LANGSEL_MODAL)
  1834. // From modal mode to an active mode? This forces the menu to return to the setup menu.
  1835. langsel = LANGSEL_ACTIVE;
  1836. }
  1837. void lcd_force_language_selection() {
  1838. eeprom_update_byte((unsigned char *)EEPROM_LANG, LANG_ID_FORCE_SELECTION);
  1839. }
  1840. static void lcd_language_menu()
  1841. {
  1842. START_MENU();
  1843. if (langsel == LANGSEL_OFF) {
  1844. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  1845. } else if (langsel == LANGSEL_ACTIVE) {
  1846. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  1847. }
  1848. for (int i=0;i<LANG_NUM;i++){
  1849. MENU_ITEM(setlang, MSG_LANGUAGE_NAME_EXPLICIT(i), i);
  1850. }
  1851. END_MENU();
  1852. }
  1853. void lcd_mesh_bedleveling()
  1854. {
  1855. enquecommand_P(PSTR("G80"));
  1856. lcd_return_to_status();
  1857. }
  1858. void lcd_mesh_calibration()
  1859. {
  1860. enquecommand_P(PSTR("M45"));
  1861. lcd_return_to_status();
  1862. }
  1863. void lcd_mesh_calibration_z()
  1864. {
  1865. enquecommand_P(PSTR("M45 Z"));
  1866. lcd_return_to_status();
  1867. }
  1868. #ifndef SNMM
  1869. void lcd_calibrate_extruder() {
  1870. long steps_start = st_get_position(E_AXIS);
  1871. long steps_final;
  1872. float e_steps_per_unit;
  1873. lcd_show_fullscreen_message_and_wait_P(MSG_MARK_FIL);
  1874. lcd_implementation_clear();
  1875. lcd.setCursor(0, 1); lcd_printPGM(MSG_PLEASE_WAIT);
  1876. current_position[E_AXIS] += 70;
  1877. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 5, active_extruder);
  1878. st_synchronize();
  1879. lcd_display_message_fullscreen_P(MSG_E_CAL_KNOB);
  1880. while (!LCD_CLICKED) {
  1881. //manage_inactivity(true);
  1882. manage_heater();
  1883. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) {
  1884. delay(50);
  1885. //previous_millis_cmd = millis();
  1886. encoderPosition += (encoderDiff / ENCODER_PULSES_PER_STEP);
  1887. encoderDiff = 0;
  1888. if (!planner_queue_full()) {
  1889. current_position[E_AXIS] += float(abs((int)encoderPosition)) * 0.05;
  1890. encoderPosition = 0;
  1891. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 5, active_extruder);
  1892. lcdDrawUpdate = 1;
  1893. }
  1894. }
  1895. //end_position = current_position[E_AXIS];
  1896. //steps = st_get_position(E_AXIS);
  1897. //steps_final = st_get_position(E_AXIS);
  1898. //e_steps_per_unit = ((float)(steps_final - steps_start)) / 100;
  1899. //if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR("Result:"), ftostr31(e_steps_per_unit));
  1900. }
  1901. steps_final = st_get_position(E_AXIS);
  1902. e_steps_per_unit = ((float)(steps_final - steps_start)) / 100.f;
  1903. if (e_steps_per_unit < 100) e_steps_per_unit = 100;
  1904. if (e_steps_per_unit > 250) e_steps_per_unit = 250;
  1905. lcd_implementation_clear();
  1906. //axis_steps_per_unit[E_AXIS] = eeprom_read_float((float*)EEPROM_STEPS_PER_UNIT_E);
  1907. //lcd_implementation_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  1908. //delay_keep_alive(2000);
  1909. //zapis do eeprom
  1910. //eeprom_update_float((float*)EEPROM_STEPS_PER_UNIT_E, e_steps_per_unit);
  1911. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  1912. //enquecommand_P(PSTR("M92 E%f"), e_steps_per_unit);
  1913. enquecommand_P(PSTR("M500")); //store settings to eeprom
  1914. //axis_steps_per_unit[E_AXIS] = eeprom_read_float((float*)EEPROM_STEPS_PER_UNIT_E);
  1915. lcd_implementation_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  1916. delay_keep_alive(2000);
  1917. lcd_show_fullscreen_message_and_wait_P(MSG_CLEAN_NOZZLE_E);
  1918. lcd_update_enable(true);
  1919. lcd_return_to_status();
  1920. }
  1921. #endif
  1922. void lcd_toshiba_flash_air_compatibility_toggle()
  1923. {
  1924. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  1925. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  1926. }
  1927. static void lcd_settings_menu()
  1928. {
  1929. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  1930. START_MENU();
  1931. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1932. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  1933. if (!homing_flag)
  1934. {
  1935. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu_1mm);
  1936. }
  1937. if (!isPrintPaused)
  1938. {
  1939. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  1940. }
  1941. if ((SilentModeMenu == 0) || (farm_mode) ) {
  1942. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  1943. } else {
  1944. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  1945. }
  1946. if (!isPrintPaused && !homing_flag)
  1947. {
  1948. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  1949. }
  1950. MENU_ITEM(submenu, MSG_LANGUAGE_SELECT, lcd_language_menu);
  1951. if (card.ToshibaFlashAir_isEnabled()) {
  1952. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON, lcd_toshiba_flash_air_compatibility_toggle);
  1953. } else {
  1954. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF, lcd_toshiba_flash_air_compatibility_toggle);
  1955. }
  1956. if (farm_mode)
  1957. {
  1958. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  1959. }
  1960. END_MENU();
  1961. }
  1962. static void lcd_calibration_menu()
  1963. {
  1964. START_MENU();
  1965. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  1966. if (!isPrintPaused)
  1967. {
  1968. MENU_ITEM(function, MSG_SELFTEST, lcd_selftest);
  1969. #ifndef MESH_BED_LEVELING
  1970. // MK1
  1971. // "Calibrate Z"
  1972. MENU_ITEM(gcode, MSG_HOMEYZ, PSTR("G28 Z"));
  1973. #else
  1974. // MK2
  1975. MENU_ITEM(function, MSG_CALIBRATE_BED, lcd_mesh_calibration);
  1976. // "Calibrate Z" with storing the reference values to EEPROM.
  1977. MENU_ITEM(submenu, MSG_HOMEYZ, lcd_mesh_calibration_z);
  1978. #ifndef SNMM
  1979. MENU_ITEM(function, MSG_CALIBRATE_E, lcd_calibrate_extruder);
  1980. #endif
  1981. // "Mesh Bed Leveling"
  1982. MENU_ITEM(submenu, MSG_MESH_BED_LEVELING, lcd_mesh_bedleveling);
  1983. #endif
  1984. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28 W"));
  1985. MENU_ITEM(submenu, MSG_BED_CORRECTION_MENU, lcd_adjust_bed);
  1986. MENU_ITEM(submenu, MSG_SHOW_END_STOPS, menu_show_end_stops);
  1987. MENU_ITEM(gcode, MSG_CALIBRATE_BED_RESET, PSTR("M44"));
  1988. }
  1989. END_MENU();
  1990. }
  1991. /*
  1992. void lcd_mylang_top(int hlaska) {
  1993. lcd.setCursor(0,0);
  1994. lcd.print(" ");
  1995. lcd.setCursor(0,0);
  1996. lcd_printPGM(MSG_ALL[hlaska-1][LANGUAGE_SELECT]);
  1997. }
  1998. void lcd_mylang_drawmenu(int cursor) {
  1999. int first = 0;
  2000. if (cursor>2) first = cursor-2;
  2001. if (cursor==LANG_NUM) first = LANG_NUM-3;
  2002. lcd.setCursor(0, 1);
  2003. lcd.print(" ");
  2004. lcd.setCursor(1, 1);
  2005. lcd_printPGM(MSG_ALL[first][LANGUAGE_NAME]);
  2006. lcd.setCursor(0, 2);
  2007. lcd.print(" ");
  2008. lcd.setCursor(1, 2);
  2009. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  2010. lcd.setCursor(0, 3);
  2011. lcd.print(" ");
  2012. lcd.setCursor(1, 3);
  2013. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  2014. if (cursor==1) lcd.setCursor(0, 1);
  2015. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  2016. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  2017. lcd.print(">");
  2018. if (cursor<LANG_NUM-1) {
  2019. lcd.setCursor(19,3);
  2020. lcd.print("\x01");
  2021. }
  2022. if (cursor>2) {
  2023. lcd.setCursor(19,1);
  2024. lcd.print("^");
  2025. }
  2026. }
  2027. */
  2028. void lcd_mylang_drawmenu(int cursor) {
  2029. int first = 0;
  2030. if (cursor>3) first = cursor-3;
  2031. if (cursor==LANG_NUM && LANG_NUM>4) first = LANG_NUM-4;
  2032. if (cursor==LANG_NUM && LANG_NUM==4) first = LANG_NUM-4;
  2033. lcd.setCursor(0, 0);
  2034. lcd.print(" ");
  2035. lcd.setCursor(1, 0);
  2036. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+0));
  2037. lcd.setCursor(0, 1);
  2038. lcd.print(" ");
  2039. lcd.setCursor(1, 1);
  2040. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+1));
  2041. lcd.setCursor(0, 2);
  2042. lcd.print(" ");
  2043. if (LANG_NUM > 2){
  2044. lcd.setCursor(1, 2);
  2045. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+2));
  2046. }
  2047. lcd.setCursor(0, 3);
  2048. lcd.print(" ");
  2049. if (LANG_NUM>3) {
  2050. lcd.setCursor(1, 3);
  2051. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+3));
  2052. }
  2053. if (cursor==1) lcd.setCursor(0, 0);
  2054. if (cursor==2) lcd.setCursor(0, 1);
  2055. if (cursor>2) lcd.setCursor(0, 2);
  2056. if (cursor==LANG_NUM && LANG_NUM>3) lcd.setCursor(0, 3);
  2057. lcd.print(">");
  2058. if (cursor<LANG_NUM-1 && LANG_NUM>4) {
  2059. lcd.setCursor(19,3);
  2060. lcd.print("\x01");
  2061. }
  2062. if (cursor>3 && LANG_NUM>4) {
  2063. lcd.setCursor(19,0);
  2064. lcd.print("^");
  2065. }
  2066. }
  2067. void lcd_mylang_drawcursor(int cursor) {
  2068. if (cursor==1) lcd.setCursor(0, 1);
  2069. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  2070. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  2071. lcd.print(">");
  2072. }
  2073. void lcd_mylang() {
  2074. int enc_dif = 0;
  2075. int cursor_pos = 1;
  2076. lang_selected=255;
  2077. int hlaska=1;
  2078. int counter=0;
  2079. lcd_set_custom_characters_arrows();
  2080. lcd_implementation_clear();
  2081. //lcd_mylang_top(hlaska);
  2082. lcd_mylang_drawmenu(cursor_pos);
  2083. enc_dif = encoderDiff;
  2084. while ( (lang_selected == 255) ) {
  2085. manage_heater();
  2086. manage_inactivity(true);
  2087. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  2088. //if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  2089. if (enc_dif > encoderDiff ) {
  2090. cursor_pos --;
  2091. }
  2092. if (enc_dif < encoderDiff ) {
  2093. cursor_pos ++;
  2094. }
  2095. if (cursor_pos > LANG_NUM) {
  2096. cursor_pos = LANG_NUM;
  2097. }
  2098. if (cursor_pos < 1) {
  2099. cursor_pos = 1;
  2100. }
  2101. lcd_mylang_drawmenu(cursor_pos);
  2102. enc_dif = encoderDiff;
  2103. delay(100);
  2104. //}
  2105. } else delay(20);
  2106. if (lcd_clicked()) {
  2107. lcd_set_lang(cursor_pos-1);
  2108. delay(500);
  2109. }
  2110. /*
  2111. if (++counter == 80) {
  2112. hlaska++;
  2113. if(hlaska>LANG_NUM) hlaska=1;
  2114. lcd_mylang_top(hlaska);
  2115. lcd_mylang_drawcursor(cursor_pos);
  2116. counter=0;
  2117. }
  2118. */
  2119. };
  2120. if(MYSERIAL.available() > 1){
  2121. lang_selected = 0;
  2122. firstrun = 0;
  2123. }
  2124. lcd_set_custom_characters_degree();
  2125. lcd_implementation_clear();
  2126. lcd_return_to_status();
  2127. }
  2128. char reset_menu() {
  2129. int enc_dif = 0;
  2130. char cursor_pos = 0;
  2131. lcd_implementation_clear();
  2132. lcd.setCursor(1, 0);
  2133. lcd_printPGM(PSTR("Language"));
  2134. lcd.setCursor(1, 1);
  2135. lcd_printPGM(PSTR("Statistics"));
  2136. lcd.setCursor(1, 2);
  2137. lcd_printPGM(PSTR("Shiping prep"));
  2138. lcd.setCursor(1, 3);
  2139. lcd_printPGM(PSTR("All data"));
  2140. lcd.setCursor(0, 0);
  2141. lcd.print(">");
  2142. enc_dif = encoderDiff;
  2143. while (1) {
  2144. manage_heater();
  2145. manage_inactivity(true);
  2146. if (abs((enc_dif - encoderDiff)) > 4) {
  2147. if ((abs(enc_dif - encoderDiff)) > 1) {
  2148. if (enc_dif > encoderDiff) {
  2149. cursor_pos--;
  2150. }
  2151. if (enc_dif < encoderDiff) {
  2152. cursor_pos++;
  2153. }
  2154. if (cursor_pos > 3) {
  2155. cursor_pos = 3;
  2156. }
  2157. if (cursor_pos < 0) {
  2158. cursor_pos = 0;
  2159. }
  2160. lcd.setCursor(0, 0);
  2161. lcd.print(" ");
  2162. lcd.setCursor(0, 1);
  2163. lcd.print(" ");
  2164. lcd.setCursor(0, 2);
  2165. lcd.print(" ");
  2166. lcd.setCursor(0, 3);
  2167. lcd.print(" ");
  2168. lcd.setCursor(0, cursor_pos);
  2169. lcd.print(">");
  2170. enc_dif = encoderDiff;
  2171. delay(100);
  2172. }
  2173. }
  2174. if (lcd_clicked()) {
  2175. while (lcd_clicked());
  2176. delay(10);
  2177. while (lcd_clicked());
  2178. return(cursor_pos);
  2179. }
  2180. }
  2181. }
  2182. #ifdef SNMM
  2183. static void extr_mov(float shift, float feed_rate) { //move extruder no matter what the current heater temperature is
  2184. set_extrude_min_temp(.0);
  2185. current_position[E_AXIS] += shift;
  2186. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feed_rate, active_extruder);
  2187. set_extrude_min_temp(EXTRUDE_MINTEMP);
  2188. }
  2189. void change_extr(int extr) { //switches multiplexer for extruders
  2190. st_synchronize();
  2191. delay(100);
  2192. disable_e0();
  2193. disable_e1();
  2194. disable_e2();
  2195. pinMode(E_MUX0_PIN, OUTPUT);
  2196. pinMode(E_MUX1_PIN, OUTPUT);
  2197. pinMode(E_MUX2_PIN, OUTPUT);
  2198. switch (extr) {
  2199. case 1:
  2200. WRITE(E_MUX0_PIN, HIGH);
  2201. WRITE(E_MUX1_PIN, LOW);
  2202. WRITE(E_MUX2_PIN, LOW);
  2203. break;
  2204. case 2:
  2205. WRITE(E_MUX0_PIN, LOW);
  2206. WRITE(E_MUX1_PIN, HIGH);
  2207. WRITE(E_MUX2_PIN, LOW);
  2208. break;
  2209. case 3:
  2210. WRITE(E_MUX0_PIN, HIGH);
  2211. WRITE(E_MUX1_PIN, HIGH);
  2212. WRITE(E_MUX2_PIN, LOW);
  2213. break;
  2214. default:
  2215. WRITE(E_MUX0_PIN, LOW);
  2216. WRITE(E_MUX1_PIN, LOW);
  2217. WRITE(E_MUX2_PIN, LOW);
  2218. break;
  2219. }
  2220. delay(100);
  2221. }
  2222. static int get_ext_nr() { //reads multiplexer input pins and return current extruder number (counted from 0)
  2223. return(4 * READ(E_MUX2_PIN) + 2 * READ(E_MUX1_PIN) + READ(E_MUX0_PIN));
  2224. }
  2225. static void extr_adj(int extruder) //loading filament for SNMM
  2226. {
  2227. bool correct;
  2228. max_feedrate[E_AXIS] =80;
  2229. //max_feedrate[E_AXIS] = 50;
  2230. START:
  2231. lcd_implementation_clear();
  2232. lcd.setCursor(0, 0);
  2233. switch (extruder) {
  2234. case 1: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T1); break;
  2235. case 2: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T2); break;
  2236. case 3: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T3); break;
  2237. default: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T0); break;
  2238. }
  2239. do{
  2240. extr_mov(0.001,1000);
  2241. delay_keep_alive(2);
  2242. } while (!lcd_clicked());
  2243. //delay_keep_alive(500);
  2244. st_synchronize();
  2245. //correct = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FIL_LOADED_CHECK, false);
  2246. //if (!correct) goto START;
  2247. //extr_mov(BOWDEN_LENGTH/2.f, 500); //dividing by 2 is there because of max. extrusion length limitation (x_max + y_max)
  2248. //extr_mov(BOWDEN_LENGTH/2.f, 500);
  2249. extr_mov(BOWDEN_LENGTH, 500);
  2250. lcd_implementation_clear();
  2251. lcd.setCursor(0, 1); lcd_printPGM(MSG_PLEASE_WAIT);
  2252. st_synchronize();
  2253. max_feedrate[E_AXIS] = 50;
  2254. lcd_update_enable(true);
  2255. lcd_return_to_status();
  2256. lcdDrawUpdate = 2;
  2257. }
  2258. static void extr_unload() { //unloads filament
  2259. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  2260. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  2261. int8_t SilentMode;
  2262. if (degHotend0() > EXTRUDE_MINTEMP) {
  2263. lcd_implementation_clear();
  2264. lcd_display_message_fullscreen_P(PSTR(""));
  2265. max_feedrate[E_AXIS] = 50;
  2266. lcd.setCursor(0, 1); lcd_printPGM(MSG_PLEASE_WAIT);
  2267. current_position[Z_AXIS] += 15; //lifting in Z direction to make space for extrusion
  2268. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 25, active_extruder);
  2269. current_position[E_AXIS] += 10; //extrusion
  2270. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 10, active_extruder);
  2271. digipot_current(2, E_MOTOR_HIGH_CURRENT);
  2272. if (current_temperature[0] < 230) { //PLA & all other filaments
  2273. current_position[E_AXIS] += 5.4;
  2274. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2800 / 60, active_extruder);
  2275. current_position[E_AXIS] += 3.2;
  2276. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  2277. current_position[E_AXIS] += 3;
  2278. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3400 / 60, active_extruder);
  2279. }
  2280. else { //ABS
  2281. current_position[E_AXIS] += 3.1;
  2282. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder);
  2283. current_position[E_AXIS] += 3.1;
  2284. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  2285. current_position[E_AXIS] += 4;
  2286. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  2287. /*current_position[X_AXIS] += 23; //delay
  2288. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay
  2289. current_position[X_AXIS] -= 23; //delay
  2290. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay*/
  2291. delay_keep_alive(4700);
  2292. }
  2293. max_feedrate[E_AXIS] = 80;
  2294. current_position[E_AXIS] -= (BOWDEN_LENGTH + 60 + FIL_LOAD_LENGTH) / 2;
  2295. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  2296. current_position[E_AXIS] -= (BOWDEN_LENGTH + 60 + FIL_LOAD_LENGTH) / 2;
  2297. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  2298. st_synchronize();
  2299. //digipot_init();
  2300. if (SilentMode == 1) digipot_current(2, tmp_motor[2]); //set back to normal operation currents
  2301. else digipot_current(2, tmp_motor_loud[2]);
  2302. lcd_update_enable(true);
  2303. lcd_return_to_status();
  2304. max_feedrate[E_AXIS] = 50;
  2305. }
  2306. else {
  2307. lcd_implementation_clear();
  2308. lcd.setCursor(0, 0);
  2309. lcd_printPGM(MSG_ERROR);
  2310. lcd.setCursor(0, 2);
  2311. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  2312. delay(2000);
  2313. lcd_implementation_clear();
  2314. }
  2315. lcd_return_to_status();
  2316. }
  2317. //wrapper functions for loading filament
  2318. static void extr_adj_0(){
  2319. change_extr(0);
  2320. extr_adj(0);
  2321. }
  2322. static void extr_adj_1() {
  2323. change_extr(1);
  2324. extr_adj(1);
  2325. }
  2326. static void extr_adj_2() {
  2327. change_extr(2);
  2328. extr_adj(2);
  2329. }
  2330. static void extr_adj_3() {
  2331. change_extr(3);
  2332. extr_adj(3);
  2333. }
  2334. //wrapper functions for changing extruders
  2335. static void extr_change_0() {
  2336. change_extr(0);
  2337. lcd_return_to_status();
  2338. }
  2339. static void extr_change_1() {
  2340. change_extr(1);
  2341. lcd_return_to_status();
  2342. }
  2343. static void extr_change_2() {
  2344. change_extr(2);
  2345. lcd_return_to_status();
  2346. }
  2347. static void extr_change_3() {
  2348. change_extr(3);
  2349. lcd_return_to_status();
  2350. }
  2351. //wrapper functions for unloading filament
  2352. static void extr_unload_0() {
  2353. change_extr(0);
  2354. extr_unload();
  2355. }
  2356. static void extr_unload_1() {
  2357. change_extr(1);
  2358. extr_unload();
  2359. }
  2360. static void extr_unload_2() {
  2361. change_extr(2);
  2362. extr_unload();
  2363. }
  2364. static void extr_unload_3() {
  2365. change_extr(3);
  2366. extr_unload();
  2367. }
  2368. static void fil_load_menu()
  2369. {
  2370. START_MENU();
  2371. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2372. MENU_ITEM(function, PSTR("Load filament 1"), extr_adj_0);
  2373. MENU_ITEM(function, PSTR("Load filament 2 "), extr_adj_1);
  2374. MENU_ITEM(function, PSTR("Load filament 3"), extr_adj_2);
  2375. MENU_ITEM(function, PSTR("Load filament 4"), extr_adj_3);
  2376. END_MENU();
  2377. }
  2378. static void fil_unload_menu()
  2379. {
  2380. START_MENU();
  2381. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2382. MENU_ITEM(function, PSTR("Unload filament 1"), extr_unload_0);
  2383. MENU_ITEM(function, PSTR("Unload filament 2"), extr_unload_1);
  2384. MENU_ITEM(function, PSTR("Unload filament 3"), extr_unload_2);
  2385. MENU_ITEM(function, PSTR("Unload filament 4"), extr_unload_3);
  2386. END_MENU();
  2387. }
  2388. static void change_extr_menu(){
  2389. START_MENU();
  2390. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2391. MENU_ITEM(function, PSTR("Extruder 1"), extr_change_0);
  2392. MENU_ITEM(function, PSTR("Extruder 2"), extr_change_1);
  2393. MENU_ITEM(function, PSTR("Extruder 3"), extr_change_2);
  2394. MENU_ITEM(function, PSTR("Extruder 4"), extr_change_3);
  2395. END_MENU();
  2396. }
  2397. #endif
  2398. static void lcd_farm_no()
  2399. {
  2400. int enc_dif = 0;
  2401. int _farmno = farm_no;
  2402. int _ret = 0;
  2403. lcd_implementation_clear();
  2404. lcd.setCursor(0, 0);
  2405. lcd.print("Farm no");
  2406. do
  2407. {
  2408. if (abs((enc_dif - encoderDiff)) > 2) {
  2409. if (enc_dif > encoderDiff) {
  2410. _farmno--;
  2411. }
  2412. if (enc_dif < encoderDiff) {
  2413. _farmno++;
  2414. }
  2415. enc_dif = 0;
  2416. encoderDiff = 0;
  2417. }
  2418. if (_farmno > 254) { _farmno = 1; }
  2419. if (_farmno < 1) { _farmno = 254; }
  2420. lcd.setCursor(0, 2);
  2421. lcd.print(_farmno);
  2422. lcd.print(" ");
  2423. delay(100);
  2424. if (lcd_clicked())
  2425. {
  2426. _ret = 1;
  2427. farm_no = _farmno;
  2428. EEPROM_save_B(EEPROM_FARM_MODE, &farm_no);
  2429. prusa_statistics(20);
  2430. lcd_return_to_status();
  2431. }
  2432. manage_heater();
  2433. } while (_ret == 0);
  2434. }
  2435. void lcd_confirm_print()
  2436. {
  2437. int enc_dif = 0;
  2438. int cursor_pos = 1;
  2439. int _ret = 0;
  2440. int _t = 0;
  2441. lcd_implementation_clear();
  2442. lcd.setCursor(0, 0);
  2443. lcd.print("Print ok ?");
  2444. do
  2445. {
  2446. if (abs((enc_dif - encoderDiff)) > 2) {
  2447. if (enc_dif > encoderDiff) {
  2448. cursor_pos--;
  2449. }
  2450. if (enc_dif < encoderDiff) {
  2451. cursor_pos++;
  2452. }
  2453. }
  2454. if (cursor_pos > 2) { cursor_pos = 2; }
  2455. if (cursor_pos < 1) { cursor_pos = 1; }
  2456. lcd.setCursor(0, 2); lcd.print(" ");
  2457. lcd.setCursor(0, 3); lcd.print(" ");
  2458. lcd.setCursor(2, 2);
  2459. lcd_printPGM(MSG_YES);
  2460. lcd.setCursor(2, 3);
  2461. lcd_printPGM(MSG_NO);
  2462. lcd.setCursor(0, 1 + cursor_pos);
  2463. lcd.print(">");
  2464. delay(100);
  2465. _t = _t + 1;
  2466. if (_t>100)
  2467. {
  2468. prusa_statistics(99);
  2469. _t = 0;
  2470. }
  2471. if (lcd_clicked())
  2472. {
  2473. if (cursor_pos == 1)
  2474. {
  2475. _ret = 1;
  2476. prusa_statistics(20);
  2477. prusa_statistics(4);
  2478. }
  2479. if (cursor_pos == 2)
  2480. {
  2481. _ret = 2;
  2482. prusa_statistics(20);
  2483. prusa_statistics(5);
  2484. }
  2485. }
  2486. manage_heater();
  2487. manage_inactivity();
  2488. } while (_ret == 0);
  2489. }
  2490. static void lcd_main_menu()
  2491. {
  2492. SDscrool = 0;
  2493. START_MENU();
  2494. // Majkl superawesome menu
  2495. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  2496. if (farm_mode && !IS_SD_PRINTING )
  2497. {
  2498. int tempScrool = 0;
  2499. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  2500. //delay(100);
  2501. return; // nothing to do (so don't thrash the SD card)
  2502. uint16_t fileCnt = card.getnrfilenames();
  2503. card.getWorkDirName();
  2504. if (card.filename[0] == '/')
  2505. {
  2506. #if SDCARDDETECT == -1
  2507. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  2508. #endif
  2509. } else {
  2510. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  2511. }
  2512. for (uint16_t i = 0; i < fileCnt; i++)
  2513. {
  2514. if (_menuItemNr == _lineNr)
  2515. {
  2516. #ifndef SDCARD_RATHERRECENTFIRST
  2517. card.getfilename(i);
  2518. #else
  2519. card.getfilename(fileCnt - 1 - i);
  2520. #endif
  2521. if (card.filenameIsDir)
  2522. {
  2523. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  2524. } else {
  2525. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  2526. }
  2527. } else {
  2528. MENU_ITEM_DUMMY();
  2529. }
  2530. }
  2531. MENU_ITEM(back, PSTR("- - - - - - - - -"), lcd_status_screen);
  2532. }
  2533. if ( ( IS_SD_PRINTING || is_usb_printing ) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) )
  2534. {
  2535. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  2536. }
  2537. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing )
  2538. {
  2539. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  2540. } else
  2541. {
  2542. MENU_ITEM(submenu, MSG_PREHEAT, lcd_preheat_menu);
  2543. }
  2544. #ifdef SDSUPPORT
  2545. if (card.cardOK)
  2546. {
  2547. if (card.isFileOpen())
  2548. {
  2549. if (card.sdprinting)
  2550. {
  2551. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  2552. }
  2553. else
  2554. {
  2555. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  2556. }
  2557. MENU_ITEM(submenu, MSG_STOP_PRINT, lcd_sdcard_stop);
  2558. }
  2559. else
  2560. {
  2561. if (!is_usb_printing)
  2562. {
  2563. //if (farm_mode) MENU_ITEM(submenu, MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  2564. /*else*/ MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  2565. }
  2566. #if SDCARDDETECT < 1
  2567. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  2568. #endif
  2569. }
  2570. } else
  2571. {
  2572. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  2573. #if SDCARDDETECT < 1
  2574. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  2575. #endif
  2576. }
  2577. #endif
  2578. if (IS_SD_PRINTING || is_usb_printing)
  2579. {
  2580. }
  2581. else
  2582. {
  2583. #ifndef SNMM
  2584. MENU_ITEM(function, MSG_LOAD_FILAMENT, lcd_LoadFilament);
  2585. MENU_ITEM(function, MSG_UNLOAD_FILAMENT, lcd_unLoadFilament);
  2586. #endif
  2587. #ifdef SNMM
  2588. MENU_ITEM(submenu, MSG_LOAD_FILAMENT, fil_load_menu);
  2589. MENU_ITEM(submenu, MSG_UNLOAD_FILAMENT, fil_unload_menu);
  2590. MENU_ITEM(submenu, MSG_CHANGE_EXTR, change_extr_menu);
  2591. #endif
  2592. MENU_ITEM(submenu, MSG_SETTINGS, lcd_settings_menu);
  2593. if(!isPrintPaused) MENU_ITEM(submenu, MSG_MENU_CALIBRATION, lcd_calibration_menu);
  2594. }
  2595. if (!is_usb_printing)
  2596. {
  2597. MENU_ITEM(submenu, MSG_STATISTICS, lcd_menu_statistics);
  2598. }
  2599. MENU_ITEM(submenu, MSG_SUPPORT, lcd_support_menu);
  2600. END_MENU();
  2601. }
  2602. void stack_error() {
  2603. SET_OUTPUT(BEEPER);
  2604. WRITE(BEEPER, HIGH);
  2605. delay(1000);
  2606. WRITE(BEEPER, LOW);
  2607. lcd_display_message_fullscreen_P(MSG_STACK_ERROR);
  2608. //err_triggered = 1;
  2609. while (1) delay_keep_alive(1000);
  2610. }
  2611. #ifdef SDSUPPORT
  2612. static void lcd_autostart_sd()
  2613. {
  2614. card.lastnr = 0;
  2615. card.setroot();
  2616. card.checkautostart(true);
  2617. }
  2618. #endif
  2619. static void lcd_silent_mode_set_tune() {
  2620. SilentModeMenu = !SilentModeMenu;
  2621. eeprom_update_byte((unsigned char*)EEPROM_SILENT, SilentModeMenu);
  2622. digipot_init();
  2623. lcd_goto_menu(lcd_tune_menu, 9);
  2624. }
  2625. static void lcd_tune_menu()
  2626. {
  2627. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  2628. START_MENU();
  2629. MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1
  2630. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2
  2631. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  2632. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  2633. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5
  2634. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6
  2635. #ifdef FILAMENTCHANGEENABLE
  2636. MENU_ITEM(gcode, MSG_FILAMENTCHANGE, PSTR("M600"));//7
  2637. #endif
  2638. if (SilentModeMenu == 0) {
  2639. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set_tune);
  2640. } else {
  2641. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set_tune);
  2642. }
  2643. END_MENU();
  2644. }
  2645. static void lcd_move_menu_01mm()
  2646. {
  2647. move_menu_scale = 0.1;
  2648. lcd_move_menu_axis();
  2649. }
  2650. static void lcd_control_temperature_menu()
  2651. {
  2652. #ifdef PIDTEMP
  2653. // set up temp variables - undo the default scaling
  2654. // raw_Ki = unscalePID_i(Ki);
  2655. // raw_Kd = unscalePID_d(Kd);
  2656. #endif
  2657. START_MENU();
  2658. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  2659. #if TEMP_SENSOR_0 != 0
  2660. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  2661. #endif
  2662. #if TEMP_SENSOR_1 != 0
  2663. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  2664. #endif
  2665. #if TEMP_SENSOR_2 != 0
  2666. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  2667. #endif
  2668. #if TEMP_SENSOR_BED != 0
  2669. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 3);
  2670. #endif
  2671. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  2672. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  2673. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  2674. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  2675. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  2676. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  2677. #endif
  2678. END_MENU();
  2679. }
  2680. #if SDCARDDETECT == -1
  2681. static void lcd_sd_refresh()
  2682. {
  2683. card.initsd();
  2684. currentMenuViewOffset = 0;
  2685. }
  2686. #endif
  2687. static void lcd_sd_updir()
  2688. {
  2689. SDscrool = 0;
  2690. card.updir();
  2691. currentMenuViewOffset = 0;
  2692. }
  2693. void lcd_sdcard_stop()
  2694. {
  2695. lcd.setCursor(0, 0);
  2696. lcd_printPGM(MSG_STOP_PRINT);
  2697. lcd.setCursor(2, 2);
  2698. lcd_printPGM(MSG_NO);
  2699. lcd.setCursor(2, 3);
  2700. lcd_printPGM(MSG_YES);
  2701. lcd.setCursor(0, 2); lcd.print(" ");
  2702. lcd.setCursor(0, 3); lcd.print(" ");
  2703. if ((int32_t)encoderPosition > 2) { encoderPosition = 2; }
  2704. if ((int32_t)encoderPosition < 1) { encoderPosition = 1; }
  2705. lcd.setCursor(0, 1 + encoderPosition);
  2706. lcd.print(">");
  2707. if (lcd_clicked())
  2708. {
  2709. if ((int32_t)encoderPosition == 1)
  2710. {
  2711. lcd_return_to_status();
  2712. }
  2713. if ((int32_t)encoderPosition == 2)
  2714. {
  2715. cancel_heatup = true;
  2716. #ifdef MESH_BED_LEVELING
  2717. mbl.active = false;
  2718. #endif
  2719. // Stop the stoppers, update the position from the stoppers.
  2720. planner_abort_hard();
  2721. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
  2722. // Z baystep is no more applied. Reset it.
  2723. babystep_reset();
  2724. // Clean the input command queue.
  2725. cmdqueue_reset();
  2726. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  2727. card.sdprinting = false;
  2728. card.closefile();
  2729. stoptime = millis();
  2730. unsigned long t = (stoptime - starttime) / 1000;
  2731. save_statistics(total_filament_used, t);
  2732. lcd_return_to_status();
  2733. lcd_ignore_click(true);
  2734. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  2735. // Turn off the print fan
  2736. SET_OUTPUT(FAN_PIN);
  2737. WRITE(FAN_PIN, 0);
  2738. fanSpeed=0;
  2739. }
  2740. }
  2741. }
  2742. /*
  2743. void getFileDescription(char *name, char *description) {
  2744. // get file description, ie the REAL filenam, ie the second line
  2745. card.openFile(name, true);
  2746. int i = 0;
  2747. // skip the first line (which is the version line)
  2748. while (true) {
  2749. uint16_t readByte = card.get();
  2750. if (readByte == '\n') {
  2751. break;
  2752. }
  2753. }
  2754. // read the second line (which is the description line)
  2755. while (true) {
  2756. uint16_t readByte = card.get();
  2757. if (i == 0) {
  2758. // skip the first '^'
  2759. readByte = card.get();
  2760. }
  2761. description[i] = readByte;
  2762. i++;
  2763. if (readByte == '\n') {
  2764. break;
  2765. }
  2766. }
  2767. card.closefile();
  2768. description[i-1] = 0;
  2769. }
  2770. */
  2771. void lcd_sdcard_menu()
  2772. {
  2773. int tempScrool = 0;
  2774. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  2775. //delay(100);
  2776. return; // nothing to do (so don't thrash the SD card)
  2777. uint16_t fileCnt = card.getnrfilenames();
  2778. START_MENU();
  2779. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2780. card.getWorkDirName();
  2781. if (card.filename[0] == '/')
  2782. {
  2783. #if SDCARDDETECT == -1
  2784. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  2785. #endif
  2786. } else {
  2787. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  2788. }
  2789. for (uint16_t i = 0; i < fileCnt; i++)
  2790. {
  2791. if (_menuItemNr == _lineNr)
  2792. {
  2793. #ifndef SDCARD_RATHERRECENTFIRST
  2794. card.getfilename(i);
  2795. #else
  2796. card.getfilename(fileCnt - 1 - i);
  2797. #endif
  2798. if (card.filenameIsDir)
  2799. {
  2800. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  2801. } else {
  2802. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  2803. }
  2804. } else {
  2805. MENU_ITEM_DUMMY();
  2806. }
  2807. }
  2808. END_MENU();
  2809. }
  2810. //char description [10] [31];
  2811. /*void get_description() {
  2812. uint16_t fileCnt = card.getnrfilenames();
  2813. for (uint16_t i = 0; i < fileCnt; i++)
  2814. {
  2815. card.getfilename(fileCnt - 1 - i);
  2816. getFileDescription(card.filename, description[i]);
  2817. }
  2818. }*/
  2819. /*void lcd_farm_sdcard_menu()
  2820. {
  2821. static int i = 0;
  2822. if (i == 0) {
  2823. get_description();
  2824. i++;
  2825. }
  2826. //int j;
  2827. //char description[31];
  2828. int tempScrool = 0;
  2829. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  2830. //delay(100);
  2831. return; // nothing to do (so don't thrash the SD card)
  2832. uint16_t fileCnt = card.getnrfilenames();
  2833. START_MENU();
  2834. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2835. card.getWorkDirName();
  2836. if (card.filename[0] == '/')
  2837. {
  2838. #if SDCARDDETECT == -1
  2839. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  2840. #endif
  2841. }
  2842. else {
  2843. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  2844. }
  2845. for (uint16_t i = 0; i < fileCnt; i++)
  2846. {
  2847. if (_menuItemNr == _lineNr)
  2848. {
  2849. #ifndef SDCARD_RATHERRECENTFIRST
  2850. card.getfilename(i);
  2851. #else
  2852. card.getfilename(fileCnt - 1 - i);
  2853. #endif
  2854. if (card.filenameIsDir)
  2855. {
  2856. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  2857. }
  2858. else {
  2859. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, description[i]);
  2860. }
  2861. }
  2862. else {
  2863. MENU_ITEM_DUMMY();
  2864. }
  2865. }
  2866. END_MENU();
  2867. }*/
  2868. #define menu_edit_type(_type, _name, _strFunc, scale) \
  2869. void menu_edit_ ## _name () \
  2870. { \
  2871. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  2872. if ((int32_t)encoderPosition > menuData.editMenuParentState.maxEditValue) encoderPosition = menuData.editMenuParentState.maxEditValue; \
  2873. if (lcdDrawUpdate) \
  2874. lcd_implementation_drawedit(menuData.editMenuParentState.editLabel, _strFunc(((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale)); \
  2875. if (LCD_CLICKED) \
  2876. { \
  2877. *((_type*)menuData.editMenuParentState.editValue) = ((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale; \
  2878. lcd_goto_menu(menuData.editMenuParentState.prevMenu, menuData.editMenuParentState.prevEncoderPosition, true, false); \
  2879. } \
  2880. } \
  2881. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  2882. { \
  2883. menuData.editMenuParentState.prevMenu = currentMenu; \
  2884. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  2885. \
  2886. lcdDrawUpdate = 2; \
  2887. menuData.editMenuParentState.editLabel = pstr; \
  2888. menuData.editMenuParentState.editValue = ptr; \
  2889. menuData.editMenuParentState.minEditValue = minValue * scale; \
  2890. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  2891. lcd_goto_menu(menu_edit_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  2892. \
  2893. }\
  2894. /*
  2895. void menu_edit_callback_ ## _name () { \
  2896. menu_edit_ ## _name (); \
  2897. if (LCD_CLICKED) (*callbackFunc)(); \
  2898. } \
  2899. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  2900. { \
  2901. menuData.editMenuParentState.prevMenu = currentMenu; \
  2902. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  2903. \
  2904. lcdDrawUpdate = 2; \
  2905. lcd_goto_menu(menu_edit_callback_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  2906. \
  2907. menuData.editMenuParentState.editLabel = pstr; \
  2908. menuData.editMenuParentState.editValue = ptr; \
  2909. menuData.editMenuParentState.minEditValue = minValue * scale; \
  2910. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  2911. callbackFunc = callback;\
  2912. }
  2913. */
  2914. menu_edit_type(int, int3, itostr3, 1)
  2915. menu_edit_type(float, float3, ftostr3, 1)
  2916. menu_edit_type(float, float32, ftostr32, 100)
  2917. menu_edit_type(float, float43, ftostr43, 1000)
  2918. menu_edit_type(float, float5, ftostr5, 0.01)
  2919. menu_edit_type(float, float51, ftostr51, 10)
  2920. menu_edit_type(float, float52, ftostr52, 100)
  2921. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  2922. static void lcd_selftest()
  2923. {
  2924. int _progress = 0;
  2925. bool _result = false;
  2926. lcd_implementation_clear();
  2927. lcd.setCursor(0, 0); lcd_printPGM(MSG_SELFTEST_START);
  2928. delay(2000);
  2929. _result = lcd_selftest_fan_dialog(1);
  2930. if (_result)
  2931. {
  2932. _result = lcd_selftest_fan_dialog(2);
  2933. }
  2934. if (_result)
  2935. {
  2936. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  2937. _result = lcd_selfcheck_endstops();
  2938. }
  2939. if (_result)
  2940. {
  2941. _progress = lcd_selftest_screen(1, _progress, 3, true, 1000);
  2942. _result = lcd_selfcheck_check_heater(false);
  2943. }
  2944. if (_result)
  2945. {
  2946. current_position[Z_AXIS] += 15; //move Z axis higher to avoid false triggering of Z end stop in case that we are very low - just above heatbed
  2947. _progress = lcd_selftest_screen(2, _progress, 3, true, 2000);
  2948. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  2949. }
  2950. if (_result)
  2951. {
  2952. _progress = lcd_selftest_screen(2, _progress, 3, true, 2000);
  2953. _result = lcd_selfcheck_pulleys(X_AXIS);
  2954. }
  2955. if (_result)
  2956. {
  2957. _progress = lcd_selftest_screen(3, _progress, 3, true, 1500);
  2958. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  2959. }
  2960. if (_result)
  2961. {
  2962. _progress = lcd_selftest_screen(3, _progress, 3, true, 1500);
  2963. _result = lcd_selfcheck_pulleys(Y_AXIS);
  2964. }
  2965. if (_result)
  2966. {
  2967. current_position[X_AXIS] = current_position[X_AXIS] - 3;
  2968. current_position[Y_AXIS] = current_position[Y_AXIS] - 14;
  2969. _progress = lcd_selftest_screen(4, _progress, 3, true, 1500);
  2970. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  2971. current_position[Z_AXIS] = current_position[Z_AXIS] + 15;
  2972. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  2973. }
  2974. if (_result)
  2975. {
  2976. _progress = lcd_selftest_screen(5, _progress, 3, true, 2000);
  2977. _result = lcd_selfcheck_check_heater(true);
  2978. }
  2979. if (_result)
  2980. {
  2981. _progress = lcd_selftest_screen(6, _progress, 3, true, 5000);
  2982. }
  2983. else
  2984. {
  2985. _progress = lcd_selftest_screen(7, _progress, 3, true, 5000);
  2986. }
  2987. lcd_implementation_clear();
  2988. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  2989. if (_result)
  2990. {
  2991. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_OK);
  2992. }
  2993. else
  2994. {
  2995. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  2996. }
  2997. }
  2998. /*static bool lcd_selfcheck_endstops()
  2999. {
  3000. bool _result = true;
  3001. 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)
  3002. {
  3003. current_position[0] = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? current_position[0] = current_position[0] + 10 : current_position[0];
  3004. current_position[1] = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? current_position[1] = current_position[1] + 10 : current_position[1];
  3005. current_position[2] = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? current_position[2] = current_position[2] + 10 : current_position[2];
  3006. }
  3007. 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);
  3008. delay(500);
  3009. 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)
  3010. {
  3011. _result = false;
  3012. String _error = String((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? "X" : "") +
  3013. String((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? "Y" : "") +
  3014. String((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? "Z" : "");
  3015. lcd_selftest_error(3, _error.c_str(), "");
  3016. }
  3017. manage_heater();
  3018. manage_inactivity();
  3019. return _result;
  3020. }*/
  3021. static bool lcd_selfcheck_axis(int _axis, int _travel)
  3022. {
  3023. bool _stepdone = false;
  3024. bool _stepresult = false;
  3025. int _progress = 0;
  3026. int _travel_done = 0;
  3027. int _err_endstop = 0;
  3028. int _lcd_refresh = 0;
  3029. _travel = _travel + (_travel / 10);
  3030. do {
  3031. /*if (_axis == 2)
  3032. {*/
  3033. current_position[_axis] = current_position[_axis] - 1;
  3034. /*}
  3035. else
  3036. {
  3037. current_position[_axis] = current_position[_axis] - 3;
  3038. }*/
  3039. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3040. st_synchronize();
  3041. 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)
  3042. {
  3043. if (_axis == 0)
  3044. {
  3045. _stepresult = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  3046. _err_endstop = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? 1 : 2;
  3047. disable_x();
  3048. }
  3049. if (_axis == 1)
  3050. {
  3051. _stepresult = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  3052. _err_endstop = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? 0 : 2;
  3053. disable_y();
  3054. }
  3055. if (_axis == 2)
  3056. {
  3057. _stepresult = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  3058. _err_endstop = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? 0 : 1;
  3059. disable_z();
  3060. }
  3061. _stepdone = true;
  3062. }
  3063. if (_lcd_refresh < 6)
  3064. {
  3065. _lcd_refresh++;
  3066. }
  3067. else
  3068. {
  3069. _progress = lcd_selftest_screen(2 + _axis, _progress, 3, false, 0);
  3070. _lcd_refresh = 0;
  3071. }
  3072. manage_heater();
  3073. manage_inactivity();
  3074. //delay(100);
  3075. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  3076. } while (!_stepdone);
  3077. //current_position[_axis] = current_position[_axis] + 15;
  3078. //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3079. if (!_stepresult)
  3080. {
  3081. const char *_error_1;
  3082. const char *_error_2;
  3083. if (_axis == X_AXIS) _error_1 = "X";
  3084. if (_axis == Y_AXIS) _error_1 = "Y";
  3085. if (_axis == Z_AXIS) _error_1 = "Z";
  3086. if (_err_endstop == 0) _error_2 = "X";
  3087. if (_err_endstop == 1) _error_2 = "Y";
  3088. if (_err_endstop == 2) _error_2 = "Z";
  3089. if (_travel_done >= _travel)
  3090. {
  3091. lcd_selftest_error(5, _error_1, _error_2);
  3092. }
  3093. else
  3094. {
  3095. lcd_selftest_error(4, _error_1, _error_2);
  3096. }
  3097. }
  3098. return _stepresult;
  3099. }
  3100. static bool lcd_selfcheck_pulleys(int axis)
  3101. {
  3102. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  3103. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  3104. float current_position_init;
  3105. float move;
  3106. bool endstop_triggered = false;
  3107. bool result = true;
  3108. int i;
  3109. unsigned long timeout_counter;// = 20000 + millis();
  3110. refresh_cmd_timeout();
  3111. if (axis == 0) move = 50; //230;
  3112. else move = 50; //190
  3113. /*while (!endstop_triggered) {
  3114. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) || (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1)) {
  3115. endstop_triggered = true;*/
  3116. current_position_init = current_position[axis];
  3117. timeout_counter = millis() + 2500;
  3118. /*}
  3119. else {
  3120. current_position[axis] -= 1;
  3121. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3122. st_synchronize();
  3123. if (millis() > timeout_counter) return(false);
  3124. }
  3125. }*/
  3126. current_position[axis] += 2;
  3127. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3128. for (i = 0; i < 5; i++) {
  3129. refresh_cmd_timeout();
  3130. current_position[axis] = current_position[axis] + move;
  3131. digipot_current(axis, 850); //set motor current higher
  3132. //max_jerk[X_AXIS] = 20;
  3133. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 200, active_extruder);
  3134. //max_jerk[X_AXIS] = DEFAULT_XJERK;
  3135. //digipot_current(axis, tmp_motor_loud[0]);
  3136. /*if (SilentMode == 1) digipot_current(2, tmp_motor[2]); //set back to normal operation currents
  3137. else */digipot_current(2, tmp_motor_loud[2]); //set motor current back
  3138. current_position[axis] = current_position[axis] - move;
  3139. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  3140. st_synchronize();
  3141. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) || (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1)) {
  3142. //current_position[axis] += 15;
  3143. //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3144. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  3145. return(false);
  3146. }
  3147. if (millis() > timeout_counter) {
  3148. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  3149. return(false);
  3150. }else timeout_counter = millis() + 2500;
  3151. }
  3152. endstop_triggered = false;
  3153. while (!endstop_triggered) {
  3154. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) || (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1)) {
  3155. endstop_triggered = true;
  3156. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  3157. current_position[axis] += 15;
  3158. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3159. return(true);
  3160. }
  3161. else {
  3162. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  3163. return(false);
  3164. }
  3165. }
  3166. else {
  3167. current_position[axis] -= 1;
  3168. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3169. st_synchronize();
  3170. if (millis() > timeout_counter) {
  3171. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  3172. return(false);
  3173. }
  3174. }
  3175. }
  3176. }
  3177. /*
  3178. static bool lcd_selfcheck_pulleys_2() {
  3179. int axis;
  3180. float current_position_init;
  3181. float trigger_position1, trigger_position2;
  3182. bool endstop_triggered = false;
  3183. for (axis = 0; axis < 2; axis++) {
  3184. while (!endstop_triggered) {
  3185. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) || (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1)) {
  3186. endstop_triggered = true;
  3187. current_position_init = current_position[axis];
  3188. //timeout_counter = millis() + 10000;
  3189. }
  3190. else {
  3191. current_position[axis] -= 1;
  3192. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3193. st_synchronize();
  3194. //if (millis() > timeout_counter) return(false);
  3195. }
  3196. }
  3197. }
  3198. current_position[0] += 50;
  3199. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3200. while (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING != 1);
  3201. trigger_position1 = current_position[X_AXIS];
  3202. st_synchronize();
  3203. current_position[0] -= 40;
  3204. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3205. st_synchronize();
  3206. current_position[0] += 40;
  3207. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3208. while (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING != 1);
  3209. trigger_position2 = current_position[X_AXIS];
  3210. if(trigger_position2 == trigger_position1) return true;
  3211. else return false;
  3212. }
  3213. static bool lcd_selfcheck_belts2() {
  3214. float current_position_init;
  3215. bool endstop_triggered = false;
  3216. int i, axis;
  3217. axis = 0;
  3218. //for (axis = 0; axis < 2; axis++) {
  3219. /*while (!endstop_triggered) {
  3220. if (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) {
  3221. endstop_triggered = true;
  3222. current_position_init = current_position[axis];
  3223. current_position[axis] += 30;
  3224. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  3225. st_synchronize();
  3226. current_position[axis] -= 29;
  3227. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 500, active_extruder);
  3228. if (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) return(false);
  3229. else return(true);
  3230. }
  3231. else {
  3232. current_position[axis] -= 1;
  3233. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3234. st_synchronize();
  3235. }
  3236. }
  3237. while (!endstop_triggered) {
  3238. if (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) {
  3239. endstop_triggered = true;
  3240. current_position_init = current_position[axis];
  3241. current_position[axis] += 30;
  3242. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  3243. st_synchronize();
  3244. for (i = 0; i < 50; i++) {
  3245. current_position[axis] -= 1;
  3246. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 500, active_extruder);
  3247. current_position[axis] += 1;
  3248. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 500, active_extruder);
  3249. st_synchronize();
  3250. }
  3251. if (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) return(false);
  3252. else return(true);
  3253. }
  3254. else {
  3255. current_position[axis] -= 1;
  3256. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3257. st_synchronize();
  3258. }
  3259. }
  3260. }
  3261. */
  3262. static bool lcd_selfcheck_endstops()
  3263. {
  3264. bool _result = true;
  3265. 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)
  3266. {
  3267. current_position[0] = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? current_position[0] = current_position[0] + 10 : current_position[0];
  3268. current_position[1] = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? current_position[1] = current_position[1] + 10 : current_position[1];
  3269. current_position[2] = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? current_position[2] = current_position[2] + 10 : current_position[2];
  3270. }
  3271. 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);
  3272. delay(500);
  3273. 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)
  3274. {
  3275. _result = false;
  3276. String _error = String((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? "X" : "") +
  3277. String((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? "Y" : "") +
  3278. String((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? "Z" : "");
  3279. lcd_selftest_error(3, _error.c_str(), "");
  3280. }
  3281. manage_heater();
  3282. manage_inactivity();
  3283. return _result;
  3284. }
  3285. static bool lcd_selfcheck_check_heater(bool _isbed)
  3286. {
  3287. int _counter = 0;
  3288. int _progress = 0;
  3289. bool _stepresult = false;
  3290. bool _docycle = true;
  3291. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  3292. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  3293. int _cycles = (_isbed) ? 120 : 30;
  3294. target_temperature[0] = (_isbed) ? 0 : 100;
  3295. target_temperature_bed = (_isbed) ? 100 : 0;
  3296. manage_heater();
  3297. manage_inactivity();
  3298. do {
  3299. _counter++;
  3300. (_counter < _cycles) ? _docycle = true : _docycle = false;
  3301. manage_heater();
  3302. manage_inactivity();
  3303. _progress = (_isbed) ? lcd_selftest_screen(5, _progress, 2, false, 400) : lcd_selftest_screen(1, _progress, 2, false, 400);
  3304. } while (_docycle);
  3305. target_temperature[0] = 0;
  3306. target_temperature_bed = 0;
  3307. manage_heater();
  3308. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  3309. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  3310. if (_opposite_result < (_isbed) ? 10 : 3)
  3311. {
  3312. if (_checked_result >= (_isbed) ? 3 : 10)
  3313. {
  3314. _stepresult = true;
  3315. }
  3316. else
  3317. {
  3318. lcd_selftest_error(1, "", "");
  3319. }
  3320. }
  3321. else
  3322. {
  3323. lcd_selftest_error(2, "", "");
  3324. }
  3325. manage_heater();
  3326. manage_inactivity();
  3327. return _stepresult;
  3328. }
  3329. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  3330. {
  3331. lcd_implementation_quick_feedback();
  3332. target_temperature[0] = 0;
  3333. target_temperature_bed = 0;
  3334. manage_heater();
  3335. manage_inactivity();
  3336. lcd_implementation_clear();
  3337. lcd.setCursor(0, 0);
  3338. lcd_printPGM(MSG_SELFTEST_ERROR);
  3339. lcd.setCursor(0, 1);
  3340. lcd_printPGM(MSG_SELFTEST_PLEASECHECK);
  3341. switch (_error_no)
  3342. {
  3343. case 1:
  3344. lcd.setCursor(0, 2);
  3345. lcd_printPGM(MSG_SELFTEST_HEATERTHERMISTOR);
  3346. lcd.setCursor(0, 3);
  3347. lcd_printPGM(MSG_SELFTEST_NOTCONNECTED);
  3348. break;
  3349. case 2:
  3350. lcd.setCursor(0, 2);
  3351. lcd_printPGM(MSG_SELFTEST_BEDHEATER);
  3352. lcd.setCursor(0, 3);
  3353. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  3354. break;
  3355. case 3:
  3356. lcd.setCursor(0, 2);
  3357. lcd_printPGM(MSG_SELFTEST_ENDSTOPS);
  3358. lcd.setCursor(0, 3);
  3359. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  3360. lcd.setCursor(17, 3);
  3361. lcd.print(_error_1);
  3362. break;
  3363. case 4:
  3364. lcd.setCursor(0, 2);
  3365. lcd_printPGM(MSG_SELFTEST_MOTOR);
  3366. lcd.setCursor(18, 2);
  3367. lcd.print(_error_1);
  3368. lcd.setCursor(0, 3);
  3369. lcd_printPGM(MSG_SELFTEST_ENDSTOP);
  3370. lcd.setCursor(18, 3);
  3371. lcd.print(_error_2);
  3372. break;
  3373. case 5:
  3374. lcd.setCursor(0, 2);
  3375. lcd_printPGM(MSG_SELFTEST_ENDSTOP_NOTHIT);
  3376. lcd.setCursor(0, 3);
  3377. lcd_printPGM(MSG_SELFTEST_MOTOR);
  3378. lcd.setCursor(18, 3);
  3379. lcd.print(_error_1);
  3380. break;
  3381. case 6:
  3382. lcd.setCursor(0, 2);
  3383. lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  3384. lcd.setCursor(0, 3);
  3385. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  3386. lcd.setCursor(18, 3);
  3387. lcd.print(_error_1);
  3388. break;
  3389. case 7:
  3390. lcd.setCursor(0, 2);
  3391. lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  3392. lcd.setCursor(0, 3);
  3393. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  3394. lcd.setCursor(18, 3);
  3395. lcd.print(_error_1);
  3396. break;
  3397. case 8:
  3398. lcd.setCursor(0, 2);
  3399. lcd_printPGM(MSG_LOOSE_PULLEY);
  3400. lcd.setCursor(0, 3);
  3401. lcd_printPGM(MSG_SELFTEST_MOTOR);
  3402. lcd.setCursor(18, 3);
  3403. lcd.print(_error_1);
  3404. break;
  3405. }
  3406. delay(1000);
  3407. lcd_implementation_quick_feedback();
  3408. do {
  3409. delay(100);
  3410. manage_heater();
  3411. manage_inactivity();
  3412. } while (!lcd_clicked());
  3413. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  3414. lcd_return_to_status();
  3415. }
  3416. static bool lcd_selftest_fan_dialog(int _fan)
  3417. {
  3418. bool _result = false;
  3419. int _errno = 0;
  3420. lcd_implementation_clear();
  3421. lcd.setCursor(0, 0); lcd_printPGM(MSG_SELFTEST_FAN);
  3422. switch (_fan)
  3423. {
  3424. case 1:
  3425. // extruder cooling fan
  3426. lcd.setCursor(0, 1); lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  3427. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  3428. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  3429. _errno = 7;
  3430. break;
  3431. case 2:
  3432. // object cooling fan
  3433. lcd.setCursor(0, 1); lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  3434. SET_OUTPUT(FAN_PIN);
  3435. analogWrite(FAN_PIN, 255);
  3436. _errno = 6;
  3437. break;
  3438. }
  3439. delay(500);
  3440. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  3441. lcd.setCursor(0, 3); lcd.print(">");
  3442. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  3443. int8_t enc_dif = 0;
  3444. bool _response = false;
  3445. do
  3446. {
  3447. switch (_fan)
  3448. {
  3449. case 1:
  3450. // extruder cooling fan
  3451. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  3452. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  3453. break;
  3454. case 2:
  3455. // object cooling fan
  3456. SET_OUTPUT(FAN_PIN);
  3457. analogWrite(FAN_PIN, 255);
  3458. break;
  3459. }
  3460. if (abs((enc_dif - encoderDiff)) > 2) {
  3461. if (enc_dif > encoderDiff) {
  3462. _result = true;
  3463. lcd.setCursor(0, 2); lcd.print(">");
  3464. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  3465. lcd.setCursor(0, 3); lcd.print(" ");
  3466. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  3467. }
  3468. if (enc_dif < encoderDiff) {
  3469. _result = false;
  3470. lcd.setCursor(0, 2); lcd.print(" ");
  3471. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  3472. lcd.setCursor(0, 3); lcd.print(">");
  3473. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  3474. }
  3475. enc_dif = 0;
  3476. encoderDiff = 0;
  3477. }
  3478. manage_heater();
  3479. delay(100);
  3480. if (lcd_clicked())
  3481. {
  3482. _response = true;
  3483. }
  3484. } while (!_response);
  3485. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  3486. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 0);
  3487. SET_OUTPUT(FAN_PIN);
  3488. analogWrite(FAN_PIN, 0);
  3489. fanSpeed = 0;
  3490. manage_heater();
  3491. if (!_result)
  3492. {
  3493. const char *_err;
  3494. lcd_selftest_error(_errno, _err, _err);
  3495. }
  3496. return _result;
  3497. }
  3498. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  3499. {
  3500. lcd_next_update_millis = millis() + (LCD_UPDATE_INTERVAL * 10000);
  3501. int _step_block = 0;
  3502. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  3503. if (_clear) lcd_implementation_clear();
  3504. lcd.setCursor(0, 0);
  3505. if (_step == -1) lcd_printPGM(MSG_SELFTEST_START);
  3506. if (_step == 0) lcd_printPGM(MSG_SELFTEST_CHECK_ENDSTOPS);
  3507. if (_step == 1) lcd_printPGM(MSG_SELFTEST_CHECK_HOTEND);
  3508. if (_step == 2) lcd_printPGM(MSG_SELFTEST_CHECK_X);
  3509. if (_step == 3) lcd_printPGM(MSG_SELFTEST_CHECK_Y);
  3510. if (_step == 4) lcd_printPGM(MSG_SELFTEST_CHECK_Z);
  3511. if (_step == 5) lcd_printPGM(MSG_SELFTEST_CHECK_BED);
  3512. if (_step == 6) lcd_printPGM(MSG_SELFTEST_CHECK_ALLCORRECT);
  3513. if (_step == 7) lcd_printPGM(MSG_SELFTEST_FAILED);
  3514. lcd.setCursor(0, 1);
  3515. lcd.print("--------------------");
  3516. if (_step != 7)
  3517. {
  3518. _step_block = 1;
  3519. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  3520. _step_block = 2;
  3521. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  3522. _step_block = 3;
  3523. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  3524. _step_block = 4;
  3525. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  3526. _step_block = 5;
  3527. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  3528. }
  3529. if (_delay > 0) delay(_delay);
  3530. _progress++;
  3531. return (_progress > _progress_scale * 2) ? 0 : _progress;
  3532. }
  3533. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  3534. {
  3535. lcd.setCursor(_col, _row);
  3536. switch (_state)
  3537. {
  3538. case 1:
  3539. lcd.print(_name);
  3540. lcd.setCursor(_col + strlen(_name), _row);
  3541. lcd.print(":");
  3542. lcd.setCursor(_col + strlen(_name) + 1, _row);
  3543. lcd.print(_indicator);
  3544. break;
  3545. case 2:
  3546. lcd.print(_name);
  3547. lcd.setCursor(_col + strlen(_name), _row);
  3548. lcd.print(":");
  3549. lcd.setCursor(_col + strlen(_name) + 1, _row);
  3550. lcd.print("OK");
  3551. break;
  3552. default:
  3553. lcd.print(_name);
  3554. }
  3555. }
  3556. /** End of menus **/
  3557. static void lcd_quick_feedback()
  3558. {
  3559. lcdDrawUpdate = 2;
  3560. blocking_enc = millis() + 500;
  3561. lcd_implementation_quick_feedback();
  3562. }
  3563. /** Menu action functions **/
  3564. static void menu_action_back(menuFunc_t data) {
  3565. lcd_goto_menu(data);
  3566. }
  3567. static void menu_action_submenu(menuFunc_t data) {
  3568. lcd_goto_menu(data);
  3569. }
  3570. static void menu_action_gcode(const char* pgcode) {
  3571. enquecommand_P(pgcode);
  3572. }
  3573. static void menu_action_setlang(unsigned char lang) {
  3574. lcd_set_lang(lang);
  3575. }
  3576. static void menu_action_function(menuFunc_t data) {
  3577. (*data)();
  3578. }
  3579. static void menu_action_sdfile(const char* filename, char* longFilename)
  3580. {
  3581. char cmd[30];
  3582. char* c;
  3583. sprintf_P(cmd, PSTR("M23 %s"), filename);
  3584. for (c = &cmd[4]; *c; c++)
  3585. *c = tolower(*c);
  3586. enquecommand(cmd);
  3587. enquecommand_P(PSTR("M24"));
  3588. lcd_return_to_status();
  3589. }
  3590. static void menu_action_sddirectory(const char* filename, char* longFilename)
  3591. {
  3592. card.chdir(filename);
  3593. encoderPosition = 0;
  3594. }
  3595. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  3596. {
  3597. *ptr = !(*ptr);
  3598. }
  3599. /*
  3600. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  3601. {
  3602. menu_action_setting_edit_bool(pstr, ptr);
  3603. (*callback)();
  3604. }
  3605. */
  3606. #endif//ULTIPANEL
  3607. /** LCD API **/
  3608. void lcd_init()
  3609. {
  3610. lcd_implementation_init();
  3611. #ifdef NEWPANEL
  3612. SET_INPUT(BTN_EN1);
  3613. SET_INPUT(BTN_EN2);
  3614. WRITE(BTN_EN1, HIGH);
  3615. WRITE(BTN_EN2, HIGH);
  3616. #if BTN_ENC > 0
  3617. SET_INPUT(BTN_ENC);
  3618. WRITE(BTN_ENC, HIGH);
  3619. #endif
  3620. #ifdef REPRAPWORLD_KEYPAD
  3621. pinMode(SHIFT_CLK, OUTPUT);
  3622. pinMode(SHIFT_LD, OUTPUT);
  3623. pinMode(SHIFT_OUT, INPUT);
  3624. WRITE(SHIFT_OUT, HIGH);
  3625. WRITE(SHIFT_LD, HIGH);
  3626. #endif
  3627. #else // Not NEWPANEL
  3628. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  3629. pinMode (SR_DATA_PIN, OUTPUT);
  3630. pinMode (SR_CLK_PIN, OUTPUT);
  3631. #elif defined(SHIFT_CLK)
  3632. pinMode(SHIFT_CLK, OUTPUT);
  3633. pinMode(SHIFT_LD, OUTPUT);
  3634. pinMode(SHIFT_EN, OUTPUT);
  3635. pinMode(SHIFT_OUT, INPUT);
  3636. WRITE(SHIFT_OUT, HIGH);
  3637. WRITE(SHIFT_LD, HIGH);
  3638. WRITE(SHIFT_EN, LOW);
  3639. #else
  3640. #ifdef ULTIPANEL
  3641. #error ULTIPANEL requires an encoder
  3642. #endif
  3643. #endif // SR_LCD_2W_NL
  3644. #endif//!NEWPANEL
  3645. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  3646. pinMode(SDCARDDETECT, INPUT);
  3647. WRITE(SDCARDDETECT, HIGH);
  3648. lcd_oldcardstatus = IS_SD_INSERTED;
  3649. #endif//(SDCARDDETECT > 0)
  3650. #ifdef LCD_HAS_SLOW_BUTTONS
  3651. slow_buttons = 0;
  3652. #endif
  3653. lcd_buttons_update();
  3654. #ifdef ULTIPANEL
  3655. encoderDiff = 0;
  3656. #endif
  3657. }
  3658. //#include <avr/pgmspace.h>
  3659. static volatile bool lcd_update_enabled = true;
  3660. unsigned long lcd_timeoutToStatus = 0;
  3661. void lcd_update_enable(bool enabled)
  3662. {
  3663. if (lcd_update_enabled != enabled) {
  3664. lcd_update_enabled = enabled;
  3665. if (enabled) {
  3666. // Reset encoder position. This is equivalent to re-entering a menu.
  3667. encoderPosition = 0;
  3668. encoderDiff = 0;
  3669. // Enabling the normal LCD update procedure.
  3670. // Reset the timeout interval.
  3671. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3672. // Force the keypad update now.
  3673. lcd_next_update_millis = millis() - 1;
  3674. // Full update.
  3675. lcd_implementation_clear();
  3676. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  3677. lcd_set_custom_characters(currentMenu == lcd_status_screen);
  3678. #else
  3679. if (currentMenu == lcd_status_screen)
  3680. lcd_set_custom_characters_degree();
  3681. else
  3682. lcd_set_custom_characters_arrows();
  3683. #endif
  3684. lcd_update(2);
  3685. } else {
  3686. // Clear the LCD always, or let it to the caller?
  3687. }
  3688. }
  3689. }
  3690. void lcd_update(uint8_t lcdDrawUpdateOverride)
  3691. {
  3692. if (lcdDrawUpdate < lcdDrawUpdateOverride)
  3693. lcdDrawUpdate = lcdDrawUpdateOverride;
  3694. if (! lcd_update_enabled)
  3695. return;
  3696. #ifdef LCD_HAS_SLOW_BUTTONS
  3697. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  3698. #endif
  3699. lcd_buttons_update();
  3700. #if (SDCARDDETECT > 0)
  3701. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  3702. {
  3703. lcdDrawUpdate = 2;
  3704. lcd_oldcardstatus = IS_SD_INSERTED;
  3705. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  3706. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  3707. currentMenu == lcd_status_screen
  3708. #endif
  3709. );
  3710. if (lcd_oldcardstatus)
  3711. {
  3712. card.initsd();
  3713. LCD_MESSAGERPGM(MSG_SD_INSERTED);
  3714. //get_description();
  3715. }
  3716. else
  3717. {
  3718. card.release();
  3719. LCD_MESSAGERPGM(MSG_SD_REMOVED);
  3720. }
  3721. }
  3722. #endif//CARDINSERTED
  3723. if (lcd_next_update_millis < millis())
  3724. {
  3725. #ifdef ULTIPANEL
  3726. #ifdef REPRAPWORLD_KEYPAD
  3727. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  3728. reprapworld_keypad_move_z_up();
  3729. }
  3730. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  3731. reprapworld_keypad_move_z_down();
  3732. }
  3733. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  3734. reprapworld_keypad_move_x_left();
  3735. }
  3736. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  3737. reprapworld_keypad_move_x_right();
  3738. }
  3739. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  3740. reprapworld_keypad_move_y_down();
  3741. }
  3742. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  3743. reprapworld_keypad_move_y_up();
  3744. }
  3745. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  3746. reprapworld_keypad_move_home();
  3747. }
  3748. #endif
  3749. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  3750. {
  3751. if (lcdDrawUpdate == 0)
  3752. lcdDrawUpdate = 1;
  3753. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  3754. encoderDiff = 0;
  3755. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3756. }
  3757. if (LCD_CLICKED)
  3758. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  3759. #endif//ULTIPANEL
  3760. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  3761. blink++; // Variable for fan animation and alive dot
  3762. u8g.firstPage();
  3763. do
  3764. {
  3765. u8g.setFont(u8g_font_6x10_marlin);
  3766. u8g.setPrintPos(125, 0);
  3767. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  3768. u8g.drawPixel(127, 63); // draw alive dot
  3769. u8g.setColorIndex(1); // black on white
  3770. (*currentMenu)();
  3771. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  3772. } while (u8g.nextPage());
  3773. #else
  3774. (*currentMenu)();
  3775. #endif
  3776. #ifdef LCD_HAS_STATUS_INDICATORS
  3777. lcd_implementation_update_indicators();
  3778. #endif
  3779. #ifdef ULTIPANEL
  3780. if (lcd_timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  3781. {
  3782. // Exiting a menu. Let's call the menu function the last time with menuExiting flag set to true
  3783. // to give it a chance to save its state.
  3784. // This is useful for example, when the babystep value has to be written into EEPROM.
  3785. if (currentMenu != NULL) {
  3786. menuExiting = true;
  3787. (*currentMenu)();
  3788. menuExiting = false;
  3789. }
  3790. lcd_return_to_status();
  3791. lcdDrawUpdate = 2;
  3792. }
  3793. #endif//ULTIPANEL
  3794. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  3795. if (lcdDrawUpdate) lcdDrawUpdate--;
  3796. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  3797. }
  3798. if (!SdFatUtil::test_stack_integrity()) stack_error();
  3799. }
  3800. void lcd_ignore_click(bool b)
  3801. {
  3802. ignore_click = b;
  3803. wait_for_unclick = false;
  3804. }
  3805. void lcd_finishstatus() {
  3806. int len = strlen(lcd_status_message);
  3807. if (len > 0) {
  3808. while (len < LCD_WIDTH) {
  3809. lcd_status_message[len++] = ' ';
  3810. }
  3811. }
  3812. lcd_status_message[LCD_WIDTH] = '\0';
  3813. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  3814. #if PROGRESS_MSG_EXPIRE > 0
  3815. messageTick =
  3816. #endif
  3817. progressBarTick = millis();
  3818. #endif
  3819. lcdDrawUpdate = 2;
  3820. #ifdef FILAMENT_LCD_DISPLAY
  3821. message_millis = millis(); //get status message to show up for a while
  3822. #endif
  3823. }
  3824. void lcd_setstatus(const char* message)
  3825. {
  3826. if (lcd_status_message_level > 0)
  3827. return;
  3828. strncpy(lcd_status_message, message, LCD_WIDTH);
  3829. lcd_finishstatus();
  3830. }
  3831. void lcd_setstatuspgm(const char* message)
  3832. {
  3833. if (lcd_status_message_level > 0)
  3834. return;
  3835. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  3836. lcd_finishstatus();
  3837. }
  3838. void lcd_setalertstatuspgm(const char* message)
  3839. {
  3840. lcd_setstatuspgm(message);
  3841. lcd_status_message_level = 1;
  3842. #ifdef ULTIPANEL
  3843. lcd_return_to_status();
  3844. #endif//ULTIPANEL
  3845. }
  3846. void lcd_reset_alert_level()
  3847. {
  3848. lcd_status_message_level = 0;
  3849. }
  3850. #ifdef DOGLCD
  3851. void lcd_setcontrast(uint8_t value)
  3852. {
  3853. lcd_contrast = value & 63;
  3854. u8g.setContrast(lcd_contrast);
  3855. }
  3856. #endif
  3857. #ifdef ULTIPANEL
  3858. /* Warning: This function is called from interrupt context */
  3859. void lcd_buttons_update()
  3860. {
  3861. #ifdef NEWPANEL
  3862. uint8_t newbutton = 0;
  3863. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  3864. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  3865. #if BTN_ENC > 0
  3866. if ((blocking_enc < millis()) && (READ(BTN_ENC) == 0))
  3867. newbutton |= EN_C;
  3868. #endif
  3869. buttons = newbutton;
  3870. #ifdef LCD_HAS_SLOW_BUTTONS
  3871. buttons |= slow_buttons;
  3872. #endif
  3873. #ifdef REPRAPWORLD_KEYPAD
  3874. // for the reprapworld_keypad
  3875. uint8_t newbutton_reprapworld_keypad = 0;
  3876. WRITE(SHIFT_LD, LOW);
  3877. WRITE(SHIFT_LD, HIGH);
  3878. for (int8_t i = 0; i < 8; i++) {
  3879. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  3880. if (READ(SHIFT_OUT))
  3881. newbutton_reprapworld_keypad |= (1 << 7);
  3882. WRITE(SHIFT_CLK, HIGH);
  3883. WRITE(SHIFT_CLK, LOW);
  3884. }
  3885. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  3886. #endif
  3887. #else //read it from the shift register
  3888. uint8_t newbutton = 0;
  3889. WRITE(SHIFT_LD, LOW);
  3890. WRITE(SHIFT_LD, HIGH);
  3891. unsigned char tmp_buttons = 0;
  3892. for (int8_t i = 0; i < 8; i++)
  3893. {
  3894. newbutton = newbutton >> 1;
  3895. if (READ(SHIFT_OUT))
  3896. newbutton |= (1 << 7);
  3897. WRITE(SHIFT_CLK, HIGH);
  3898. WRITE(SHIFT_CLK, LOW);
  3899. }
  3900. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  3901. #endif//!NEWPANEL
  3902. //manage encoder rotation
  3903. uint8_t enc = 0;
  3904. if (buttons & EN_A) enc |= B01;
  3905. if (buttons & EN_B) enc |= B10;
  3906. if (enc != lastEncoderBits)
  3907. {
  3908. switch (enc)
  3909. {
  3910. case encrot0:
  3911. if (lastEncoderBits == encrot3)
  3912. encoderDiff++;
  3913. else if (lastEncoderBits == encrot1)
  3914. encoderDiff--;
  3915. break;
  3916. case encrot1:
  3917. if (lastEncoderBits == encrot0)
  3918. encoderDiff++;
  3919. else if (lastEncoderBits == encrot2)
  3920. encoderDiff--;
  3921. break;
  3922. case encrot2:
  3923. if (lastEncoderBits == encrot1)
  3924. encoderDiff++;
  3925. else if (lastEncoderBits == encrot3)
  3926. encoderDiff--;
  3927. break;
  3928. case encrot3:
  3929. if (lastEncoderBits == encrot2)
  3930. encoderDiff++;
  3931. else if (lastEncoderBits == encrot0)
  3932. encoderDiff--;
  3933. break;
  3934. }
  3935. }
  3936. lastEncoderBits = enc;
  3937. }
  3938. bool lcd_detected(void)
  3939. {
  3940. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  3941. return lcd.LcdDetected() == 1;
  3942. #else
  3943. return true;
  3944. #endif
  3945. }
  3946. void lcd_buzz(long duration, uint16_t freq)
  3947. {
  3948. #ifdef LCD_USE_I2C_BUZZER
  3949. lcd.buzz(duration, freq);
  3950. #endif
  3951. }
  3952. bool lcd_clicked()
  3953. {
  3954. return LCD_CLICKED;
  3955. }
  3956. #endif//ULTIPANEL
  3957. /********************************/
  3958. /** Float conversion utilities **/
  3959. /********************************/
  3960. // convert float to string with +123.4 format
  3961. char conv[8];
  3962. char *ftostr3(const float &x)
  3963. {
  3964. return itostr3((int)x);
  3965. }
  3966. char *itostr2(const uint8_t &x)
  3967. {
  3968. //sprintf(conv,"%5.1f",x);
  3969. int xx = x;
  3970. conv[0] = (xx / 10) % 10 + '0';
  3971. conv[1] = (xx) % 10 + '0';
  3972. conv[2] = 0;
  3973. return conv;
  3974. }
  3975. // Convert float to string with 123.4 format, dropping sign
  3976. char *ftostr31(const float &x)
  3977. {
  3978. int xx = x * 10;
  3979. conv[0] = (xx >= 0) ? '+' : '-';
  3980. xx = abs(xx);
  3981. conv[1] = (xx / 1000) % 10 + '0';
  3982. conv[2] = (xx / 100) % 10 + '0';
  3983. conv[3] = (xx / 10) % 10 + '0';
  3984. conv[4] = '.';
  3985. conv[5] = (xx) % 10 + '0';
  3986. conv[6] = 0;
  3987. return conv;
  3988. }
  3989. // Convert float to string with 123.4 format
  3990. char *ftostr31ns(const float &x)
  3991. {
  3992. int xx = x * 10;
  3993. //conv[0]=(xx>=0)?'+':'-';
  3994. xx = abs(xx);
  3995. conv[0] = (xx / 1000) % 10 + '0';
  3996. conv[1] = (xx / 100) % 10 + '0';
  3997. conv[2] = (xx / 10) % 10 + '0';
  3998. conv[3] = '.';
  3999. conv[4] = (xx) % 10 + '0';
  4000. conv[5] = 0;
  4001. return conv;
  4002. }
  4003. char *ftostr32(const float &x)
  4004. {
  4005. long xx = x * 100;
  4006. if (xx >= 0)
  4007. conv[0] = (xx / 10000) % 10 + '0';
  4008. else
  4009. conv[0] = '-';
  4010. xx = abs(xx);
  4011. conv[1] = (xx / 1000) % 10 + '0';
  4012. conv[2] = (xx / 100) % 10 + '0';
  4013. conv[3] = '.';
  4014. conv[4] = (xx / 10) % 10 + '0';
  4015. conv[5] = (xx) % 10 + '0';
  4016. conv[6] = 0;
  4017. return conv;
  4018. }
  4019. //// Convert float to rj string with 123.45 format
  4020. char *ftostr32ns(const float &x) {
  4021. long xx = abs(x);
  4022. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  4023. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  4024. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : '0';
  4025. conv[3] = '.';
  4026. conv[4] = (xx / 10) % 10 + '0';
  4027. conv[5] = xx % 10 + '0';
  4028. return conv;
  4029. }
  4030. // Convert float to string with 1.234 format
  4031. char *ftostr43(const float &x)
  4032. {
  4033. long xx = x * 1000;
  4034. if (xx >= 0)
  4035. conv[0] = (xx / 1000) % 10 + '0';
  4036. else
  4037. conv[0] = '-';
  4038. xx = abs(xx);
  4039. conv[1] = '.';
  4040. conv[2] = (xx / 100) % 10 + '0';
  4041. conv[3] = (xx / 10) % 10 + '0';
  4042. conv[4] = (xx) % 10 + '0';
  4043. conv[5] = 0;
  4044. return conv;
  4045. }
  4046. //Float to string with 1.23 format
  4047. char *ftostr12ns(const float &x)
  4048. {
  4049. long xx = x * 100;
  4050. xx = abs(xx);
  4051. conv[0] = (xx / 100) % 10 + '0';
  4052. conv[1] = '.';
  4053. conv[2] = (xx / 10) % 10 + '0';
  4054. conv[3] = (xx) % 10 + '0';
  4055. conv[4] = 0;
  4056. return conv;
  4057. }
  4058. //Float to string with 1.234 format
  4059. char *ftostr13ns(const float &x)
  4060. {
  4061. long xx = x * 1000;
  4062. if (xx >= 0)
  4063. conv[0] = ' ';
  4064. else
  4065. conv[0] = '-';
  4066. xx = abs(xx);
  4067. conv[1] = (xx / 1000) % 10 + '0';
  4068. conv[2] = '.';
  4069. conv[3] = (xx / 100) % 10 + '0';
  4070. conv[4] = (xx / 10) % 10 + '0';
  4071. conv[5] = (xx) % 10 + '0';
  4072. conv[6] = 0;
  4073. return conv;
  4074. }
  4075. // convert float to space-padded string with -_23.4_ format
  4076. char *ftostr32sp(const float &x) {
  4077. long xx = abs(x * 100);
  4078. uint8_t dig;
  4079. if (x < 0) { // negative val = -_0
  4080. conv[0] = '-';
  4081. dig = (xx / 1000) % 10;
  4082. conv[1] = dig ? '0' + dig : ' ';
  4083. }
  4084. else { // positive val = __0
  4085. dig = (xx / 10000) % 10;
  4086. if (dig) {
  4087. conv[0] = '0' + dig;
  4088. conv[1] = '0' + (xx / 1000) % 10;
  4089. }
  4090. else {
  4091. conv[0] = ' ';
  4092. dig = (xx / 1000) % 10;
  4093. conv[1] = dig ? '0' + dig : ' ';
  4094. }
  4095. }
  4096. conv[2] = '0' + (xx / 100) % 10; // lsd always
  4097. dig = xx % 10;
  4098. if (dig) { // 2 decimal places
  4099. conv[5] = '0' + dig;
  4100. conv[4] = '0' + (xx / 10) % 10;
  4101. conv[3] = '.';
  4102. }
  4103. else { // 1 or 0 decimal place
  4104. dig = (xx / 10) % 10;
  4105. if (dig) {
  4106. conv[4] = '0' + dig;
  4107. conv[3] = '.';
  4108. }
  4109. else {
  4110. conv[3] = conv[4] = ' ';
  4111. }
  4112. conv[5] = ' ';
  4113. }
  4114. conv[6] = '\0';
  4115. return conv;
  4116. }
  4117. char *itostr31(const int &xx)
  4118. {
  4119. conv[0] = (xx >= 0) ? '+' : '-';
  4120. conv[1] = (xx / 1000) % 10 + '0';
  4121. conv[2] = (xx / 100) % 10 + '0';
  4122. conv[3] = (xx / 10) % 10 + '0';
  4123. conv[4] = '.';
  4124. conv[5] = (xx) % 10 + '0';
  4125. conv[6] = 0;
  4126. return conv;
  4127. }
  4128. // Convert int to rj string with 123 or -12 format
  4129. char *itostr3(const int &x)
  4130. {
  4131. int xx = x;
  4132. if (xx < 0) {
  4133. conv[0] = '-';
  4134. xx = -xx;
  4135. } else if (xx >= 100)
  4136. conv[0] = (xx / 100) % 10 + '0';
  4137. else
  4138. conv[0] = ' ';
  4139. if (xx >= 10)
  4140. conv[1] = (xx / 10) % 10 + '0';
  4141. else
  4142. conv[1] = ' ';
  4143. conv[2] = (xx) % 10 + '0';
  4144. conv[3] = 0;
  4145. return conv;
  4146. }
  4147. // Convert int to lj string with 123 format
  4148. char *itostr3left(const int &xx)
  4149. {
  4150. if (xx >= 100)
  4151. {
  4152. conv[0] = (xx / 100) % 10 + '0';
  4153. conv[1] = (xx / 10) % 10 + '0';
  4154. conv[2] = (xx) % 10 + '0';
  4155. conv[3] = 0;
  4156. }
  4157. else if (xx >= 10)
  4158. {
  4159. conv[0] = (xx / 10) % 10 + '0';
  4160. conv[1] = (xx) % 10 + '0';
  4161. conv[2] = 0;
  4162. }
  4163. else
  4164. {
  4165. conv[0] = (xx) % 10 + '0';
  4166. conv[1] = 0;
  4167. }
  4168. return conv;
  4169. }
  4170. // Convert int to rj string with 1234 format
  4171. char *itostr4(const int &xx) {
  4172. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  4173. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  4174. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  4175. conv[3] = xx % 10 + '0';
  4176. conv[4] = 0;
  4177. return conv;
  4178. }
  4179. // Convert float to rj string with 12345 format
  4180. char *ftostr5(const float &x) {
  4181. long xx = abs(x);
  4182. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  4183. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  4184. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  4185. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  4186. conv[4] = xx % 10 + '0';
  4187. conv[5] = 0;
  4188. return conv;
  4189. }
  4190. // Convert float to string with +1234.5 format
  4191. char *ftostr51(const float &x)
  4192. {
  4193. long xx = x * 10;
  4194. conv[0] = (xx >= 0) ? '+' : '-';
  4195. xx = abs(xx);
  4196. conv[1] = (xx / 10000) % 10 + '0';
  4197. conv[2] = (xx / 1000) % 10 + '0';
  4198. conv[3] = (xx / 100) % 10 + '0';
  4199. conv[4] = (xx / 10) % 10 + '0';
  4200. conv[5] = '.';
  4201. conv[6] = (xx) % 10 + '0';
  4202. conv[7] = 0;
  4203. return conv;
  4204. }
  4205. // Convert float to string with +123.45 format
  4206. char *ftostr52(const float &x)
  4207. {
  4208. long xx = x * 100;
  4209. conv[0] = (xx >= 0) ? '+' : '-';
  4210. xx = abs(xx);
  4211. conv[1] = (xx / 10000) % 10 + '0';
  4212. conv[2] = (xx / 1000) % 10 + '0';
  4213. conv[3] = (xx / 100) % 10 + '0';
  4214. conv[4] = '.';
  4215. conv[5] = (xx / 10) % 10 + '0';
  4216. conv[6] = (xx) % 10 + '0';
  4217. conv[7] = 0;
  4218. return conv;
  4219. }
  4220. /*
  4221. // Callback for after editing PID i value
  4222. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  4223. void copy_and_scalePID_i()
  4224. {
  4225. #ifdef PIDTEMP
  4226. Ki = scalePID_i(raw_Ki);
  4227. updatePID();
  4228. #endif
  4229. }
  4230. // Callback for after editing PID d value
  4231. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  4232. void copy_and_scalePID_d()
  4233. {
  4234. #ifdef PIDTEMP
  4235. Kd = scalePID_d(raw_Kd);
  4236. updatePID();
  4237. #endif
  4238. }
  4239. */
  4240. #endif //ULTRA_LCD