ultralcd.cpp 146 KB

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