ultralcd.cpp 222 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910
  1. #include "temperature.h"
  2. #include "ultralcd.h"
  3. #include "fsensor.h"
  4. #ifdef ULTRA_LCD
  5. #include "Marlin.h"
  6. #include "language.h"
  7. #include "cardreader.h"
  8. #include "temperature.h"
  9. #include "stepper.h"
  10. #include "ConfigurationStore.h"
  11. #include <string.h>
  12. #include "Timer.h"
  13. #include "util.h"
  14. #include "mesh_bed_leveling.h"
  15. //#include "Configuration.h"
  16. #include "cmdqueue.h"
  17. #include "SdFatUtil.h"
  18. #ifdef PAT9125
  19. #include "pat9125.h"
  20. #endif //PAT9125
  21. #ifdef TMC2130
  22. #include "tmc2130.h"
  23. #endif //TMC2130
  24. int8_t encoderDiff; /* encoderDiff is updated from interrupt context and added to encoderPosition every LCD update */
  25. extern int lcd_change_fil_state;
  26. extern bool fans_check_enabled;
  27. extern bool filament_autoload_enabled;
  28. #ifdef PAT9125
  29. extern bool fsensor_not_responding;
  30. extern bool fsensor_enabled;
  31. #endif //PAT9125
  32. //Function pointer to menu functions.
  33. typedef void (*menu_func_t)(void);
  34. static void lcd_sd_updir();
  35. struct EditMenuParentState
  36. {
  37. //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings.
  38. menu_func_t prevMenu;
  39. uint16_t prevEncoderPosition;
  40. //Variables used when editing values.
  41. const char* editLabel;
  42. void* editValue;
  43. int32_t minEditValue, maxEditValue;
  44. // menu_func_t callbackFunc;
  45. };
  46. union MenuData
  47. {
  48. struct BabyStep
  49. {
  50. // 29B total
  51. int8_t status;
  52. int babystepMem[3];
  53. float babystepMemMM[3];
  54. } babyStep;
  55. struct SupportMenu
  56. {
  57. // 6B+16B=22B total
  58. int8_t status;
  59. bool is_flash_air;
  60. uint8_t ip[4];
  61. char ip_str[3*4+3+1];
  62. } supportMenu;
  63. struct AdjustBed
  64. {
  65. // 6+13+16=35B
  66. // editMenuParentState is used when an edit menu is entered, so it knows
  67. // the return menu and encoder state.
  68. struct EditMenuParentState editMenuParentState;
  69. int8_t status;
  70. int8_t left;
  71. int8_t right;
  72. int8_t front;
  73. int8_t rear;
  74. int left2;
  75. int right2;
  76. int front2;
  77. int rear2;
  78. } adjustBed;
  79. struct TuneMenu
  80. {
  81. // editMenuParentState is used when an edit menu is entered, so it knows
  82. // the return menu and encoder state.
  83. struct EditMenuParentState editMenuParentState;
  84. // To recognize, whether the menu has been just initialized.
  85. int8_t status;
  86. // Backup of extrudemultiply, to recognize, that the value has been changed and
  87. // it needs to be applied.
  88. int16_t extrudemultiply;
  89. } tuneMenu;
  90. // editMenuParentState is used when an edit menu is entered, so it knows
  91. // the return menu and encoder state.
  92. struct EditMenuParentState editMenuParentState;
  93. struct AutoLoadFilamentMenu
  94. {
  95. //ShortTimer timer;
  96. char dummy;
  97. } autoLoadFilamentMenu;
  98. struct _Lcd_moveMenu
  99. {
  100. bool initialized;
  101. bool endstopsEnabledPrevious;
  102. } _lcd_moveMenu;
  103. struct sdcard_menu_t
  104. {
  105. uint8_t viewState;
  106. } sdcard_menu;
  107. };
  108. // State of the currently active menu.
  109. // C Union manages sharing of the static memory by all the menus.
  110. union MenuData menuData = { 0 };
  111. union Data
  112. {
  113. byte b[2];
  114. int value;
  115. };
  116. #define MENU_DEPTH_MAX 4
  117. typedef struct
  118. {
  119. menu_func_t menu;
  120. uint8_t position;
  121. } menu_record_t;
  122. menu_record_t menu_stack[MENU_DEPTH_MAX];
  123. uint8_t menu_depth = 0;
  124. int8_t ReInitLCD = 0;
  125. int8_t SilentModeMenu = SILENT_MODE_OFF;
  126. int8_t FSensorStateMenu = 1;
  127. int8_t CrashDetectMenu = 1;
  128. extern void fsensor_block();
  129. extern void fsensor_unblock();
  130. extern bool fsensor_enable();
  131. extern void fsensor_disable();
  132. #ifdef TMC2130
  133. extern void crashdet_enable();
  134. extern void crashdet_disable();
  135. #endif //TMC2130
  136. #ifdef SNMM
  137. uint8_t snmm_extruder = 0;
  138. #endif
  139. #ifdef SDCARD_SORT_ALPHA
  140. bool presort_flag = false;
  141. #endif
  142. int lcd_commands_type=LCD_COMMAND_IDLE;
  143. int lcd_commands_step=0;
  144. bool isPrintPaused = false;
  145. uint8_t farm_mode = 0;
  146. int farm_no = 0;
  147. int farm_timer = 8;
  148. int farm_status = 0;
  149. bool printer_connected = true;
  150. unsigned long display_time; //just timer for showing pid finished message on lcd;
  151. float pid_temp = DEFAULT_PID_TEMP;
  152. bool long_press_active = false;
  153. static ShortTimer longPressTimer;
  154. unsigned long button_blanking_time = millis();
  155. bool button_pressed = false;
  156. bool menuExiting = false;
  157. #ifdef ULTIPANEL
  158. static float manual_feedrate[] = MANUAL_FEEDRATE;
  159. #endif // ULTIPANEL
  160. /* !Configuration settings */
  161. uint8_t lcd_status_message_level;
  162. char lcd_status_message[LCD_WIDTH + 1] = ""; //////WELCOME!
  163. unsigned char firstrun = 1;
  164. #include "ultralcd_implementation_hitachi_HD44780.h"
  165. static const char separator[] PROGMEM = "--------------------";
  166. /** forward declarations **/
  167. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines);
  168. // void copy_and_scalePID_i();
  169. // void copy_and_scalePID_d();
  170. /* Different menus */
  171. static void lcd_status_screen();
  172. #ifdef ULTIPANEL
  173. extern bool powersupply;
  174. static void lcd_main_menu();
  175. static void lcd_tune_menu();
  176. static void lcd_prepare_menu();
  177. //static void lcd_move_menu();
  178. static void lcd_settings_menu();
  179. static void lcd_calibration_menu();
  180. static void lcd_control_temperature_menu();
  181. static void lcd_control_temperature_preheat_pla_settings_menu();
  182. static void lcd_control_temperature_preheat_abs_settings_menu();
  183. static void lcd_control_motion_menu();
  184. static void lcd_control_volumetric_menu();
  185. static void lcd_settings_menu_back();
  186. static void prusa_stat_printerstatus(int _status);
  187. static void prusa_stat_farm_number();
  188. static void prusa_stat_temperatures();
  189. static void prusa_stat_printinfo();
  190. static void lcd_farm_no();
  191. static void lcd_menu_extruder_info();
  192. static void lcd_menu_xyz_y_min();
  193. static void lcd_menu_xyz_skew();
  194. static void lcd_menu_xyz_offset();
  195. #if defined(TMC2130) || defined(PAT9125)
  196. static void lcd_menu_fails_stats();
  197. #endif //TMC2130 or PAT9125
  198. void lcd_finishstatus();
  199. #ifdef DOGLCD
  200. static void lcd_set_contrast();
  201. #endif
  202. static void lcd_control_retract_menu();
  203. static void lcd_sdcard_menu();
  204. #ifdef DELTA_CALIBRATION_MENU
  205. static void lcd_delta_calibrate_menu();
  206. #endif // DELTA_CALIBRATION_MENU
  207. static void lcd_quick_feedback();//Cause an LCD refresh, and give the user visual or audible feedback that something has happened
  208. /* Different types of actions that can be used in menu items. */
  209. static void menu_action_sdfile(const char* filename, char* longFilename);
  210. static void menu_action_sddirectory(const char* filename, char* longFilename);
  211. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
  212. static void menu_action_setting_edit_wfac(const char* pstr, uint8_t* ptr, uint8_t minValue, uint8_t maxValue);
  213. static void menu_action_setting_edit_mres(const char* pstr, uint8_t* ptr, uint8_t minValue, uint8_t maxValue);
  214. static void menu_action_setting_edit_byte3(const char* pstr, uint8_t* ptr, uint8_t minValue, uint8_t maxValue);
  215. static void menu_action_setting_edit_int3(const char* pstr, int* ptr, int minValue, int maxValue);
  216. static void menu_action_setting_edit_float3(const char* pstr, float* ptr, float minValue, float maxValue);
  217. static void menu_action_setting_edit_float32(const char* pstr, float* ptr, float minValue, float maxValue);
  218. static void menu_action_setting_edit_float43(const char* pstr, float* ptr, float minValue, float maxValue);
  219. static void menu_action_setting_edit_float5(const char* pstr, float* ptr, float minValue, float maxValue);
  220. static void menu_action_setting_edit_float51(const char* pstr, float* ptr, float minValue, float maxValue);
  221. static void menu_action_setting_edit_float52(const char* pstr, float* ptr, float minValue, float maxValue);
  222. static void menu_action_setting_edit_long5(const char* pstr, unsigned long* ptr, unsigned long minValue, unsigned long maxValue);
  223. #define ENCODER_FEEDRATE_DEADZONE 10
  224. uint8_t menu_line = 0;
  225. uint8_t menu_item = 0;
  226. uint8_t menu_row = 0;
  227. bool wasClicked = false;
  228. #define MENU_ITEM(type, label, args...) do { \
  229. if (menu_item == menu_line) { \
  230. if (lcdDrawUpdate) { \
  231. const char* _label_pstr = (label); \
  232. if (encoderPosition == menu_item) { \
  233. lcd_implementation_drawmenu_ ## type ## _selected (menu_row, _label_pstr , ## args ); \
  234. }else{\
  235. lcd_implementation_drawmenu_ ## type (menu_row, _label_pstr , ## args ); \
  236. }\
  237. }\
  238. if (wasClicked && (encoderPosition == menu_item)) {\
  239. lcd_quick_feedback(); \
  240. menu_action_ ## type ( args ); \
  241. return;\
  242. }\
  243. }\
  244. menu_item++;\
  245. } while(0)
  246. #define MENU_ITEM_EDIT(type, label, args...) MENU_ITEM(setting_edit_ ## type, label, (label) , ## args )
  247. /** Used variables to keep track of the menu */
  248. #ifndef REPRAPWORLD_KEYPAD
  249. volatile uint8_t buttons;//Contains the bits of the currently pressed buttons.
  250. #else
  251. volatile uint8_t buttons_reprapworld_keypad; // to store the reprapworld_keypad shift register values
  252. #endif
  253. #ifdef LCD_HAS_SLOW_BUTTONS
  254. volatile uint8_t slow_buttons;//Contains the bits of the currently pressed buttons.
  255. #endif
  256. uint8_t currentMenuViewOffset; /* scroll offset in the current menu */
  257. uint8_t lastEncoderBits;
  258. int32_t encoderPosition;
  259. #if (SDCARDDETECT > 0)
  260. bool lcd_oldcardstatus;
  261. #endif
  262. #endif //ULTIPANEL
  263. menu_func_t menu_menu = lcd_status_screen; /* function pointer to the currently active menu */
  264. uint32_t lcd_next_update_millis;
  265. uint8_t lcd_status_update_delay;
  266. bool ignore_click = false;
  267. bool wait_for_unclick;
  268. 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) */
  269. // place-holders for Ki and Kd edits
  270. #ifdef PIDTEMP
  271. // float raw_Ki, raw_Kd;
  272. #endif
  273. static void lcd_goto_menu(menu_func_t menu, const uint32_t encoder = 0, const bool feedback = true, bool reset_menu_state = true)
  274. {
  275. asm("cli");
  276. if (menu_menu != menu)
  277. {
  278. menu_menu = menu;
  279. encoderPosition = encoder;
  280. asm("sei");
  281. if (reset_menu_state)
  282. {
  283. // Resets the global shared C union.
  284. // This ensures, that the menu entered will find out, that it shall initialize itself.
  285. memset(&menuData, 0, sizeof(menuData));
  286. }
  287. if (feedback) lcd_quick_feedback();
  288. }
  289. else
  290. asm("sei");
  291. }
  292. ////////////////////////////////////////////////////////////////////////////////
  293. // New Menu implementation
  294. #include <stdarg.h>
  295. int lcd_puts_P(const char* str)
  296. {
  297. return fputs_P(str, lcdout);
  298. }
  299. int lcd_putc(int c)
  300. {
  301. return fputc(c, lcdout);
  302. }
  303. int lcd_printf_P(const char* format, ...)
  304. {
  305. va_list args;
  306. va_start(args, format);
  307. int ret = vfprintf_P(lcdout, format, args);
  308. va_end(args);
  309. return ret;
  310. }
  311. #define MENU_BEGIN() menu_start(); for(menu_row = 0; menu_row < LCD_HEIGHT; menu_row++, menu_line++) { menu_item = 0;
  312. void menu_start(void)
  313. {
  314. if (encoderPosition > 0x8000) encoderPosition = 0;
  315. if (encoderPosition < 0) encoderPosition = 0;
  316. if (encoderPosition < currentMenuViewOffset)
  317. currentMenuViewOffset = encoderPosition;
  318. menu_line = currentMenuViewOffset;
  319. wasClicked = LCD_CLICKED;
  320. }
  321. #define MENU_END() menu_end(); }
  322. void menu_end(void)
  323. {
  324. if (encoderPosition >= menu_item)
  325. encoderPosition = menu_item - 1;
  326. if (((uint8_t)encoderPosition) >= currentMenuViewOffset + LCD_HEIGHT)
  327. {
  328. currentMenuViewOffset = encoderPosition - LCD_HEIGHT + 1;
  329. lcdDrawUpdate = 1;
  330. menu_line = currentMenuViewOffset - 1;
  331. menu_row = -1;
  332. }
  333. }
  334. void menu_back(void)
  335. {
  336. if (menu_depth > 0) lcd_goto_menu(menu_stack[--menu_depth].menu, menu_stack[menu_depth].position, true, true);
  337. }
  338. void menu_back_if_clicked(void)
  339. {
  340. if (lcd_clicked())
  341. menu_back();
  342. }
  343. void menu_back_if_clicked_fb(void)
  344. {
  345. if (lcd_clicked())
  346. {
  347. lcd_quick_feedback();
  348. menu_back();
  349. }
  350. }
  351. void menu_submenu(menu_func_t submenu)
  352. {
  353. if (menu_depth <= MENU_DEPTH_MAX)
  354. {
  355. menu_stack[menu_depth].menu = menu_menu;
  356. menu_stack[menu_depth++].position = encoderPosition;
  357. lcd_goto_menu(submenu);
  358. }
  359. }
  360. uint8_t menu_item_ret(void)
  361. {
  362. lcd_implementation_quick_feedback();
  363. lcdDrawUpdate = 2;
  364. button_pressed = false;
  365. return 1;
  366. }
  367. /*
  368. int menu_item_printf_P(char type_char, const char* format, ...)
  369. {
  370. va_list args;
  371. va_start(args, format);
  372. int ret = 0;
  373. lcd.setCursor(0, menu_row);
  374. if (encoderPosition == menu_item)
  375. lcd.print('>');
  376. else
  377. lcd.print(' ');
  378. int cnt = vfprintf_P(lcdout, format, args);
  379. for (int i = cnt; i < 18; i++)
  380. lcd.print(' ');
  381. lcd.print(type_char);
  382. va_end(args);
  383. return ret;
  384. }
  385. */
  386. int menu_draw_item_puts_P(char type_char, const char* str)
  387. {
  388. lcd.setCursor(0, menu_row);
  389. int cnt = lcd_printf_P(_N("%c%-18S%c"), (encoderPosition == menu_item)?'>':' ', str, type_char);
  390. return cnt;
  391. }
  392. /*
  393. int menu_draw_item_puts_P_int16(char type_char, const char* str, int16_t val, )
  394. {
  395. lcd.setCursor(0, menu_row);
  396. int cnt = lcd_printf_P(_N("%c%-18S%c"), (encoderPosition == menu_item)?'>':' ', str, type_char);
  397. return cnt;
  398. }
  399. */
  400. #define MENU_ITEM_DUMMY() menu_item_dummy()
  401. inline void menu_item_dummy(void)
  402. {
  403. menu_item++;
  404. }
  405. #define MENU_ITEM_TEXT_P(str) do { if (menu_item_text_P(str)) return; } while (0)
  406. uint8_t menu_item_text_P(const char* str)
  407. {
  408. if (menu_item == menu_line)
  409. {
  410. if (lcdDrawUpdate) menu_draw_item_puts_P(' ', str);
  411. if (wasClicked && (encoderPosition == menu_item))
  412. return menu_item_ret();
  413. }
  414. menu_item++;
  415. return 0;
  416. }
  417. #define MENU_ITEM_SUBMENU_P(str, submenu) do { if (menu_item_submenu_P(str, submenu)) return; } while (0)
  418. uint8_t menu_item_submenu_P(const char* str, menu_func_t submenu)
  419. {
  420. if (menu_item == menu_line)
  421. {
  422. if (lcdDrawUpdate) menu_draw_item_puts_P(LCD_STR_ARROW_RIGHT[0], str);
  423. if (wasClicked && (encoderPosition == menu_item))
  424. {
  425. menu_submenu(submenu);
  426. return menu_item_ret();
  427. }
  428. }
  429. menu_item++;
  430. return 0;
  431. }
  432. #define MENU_ITEM_BACK_P(str) do { if (menu_item_back_P(str)) return; } while (0)
  433. uint8_t menu_item_back_P(const char* str)
  434. {
  435. if (menu_item == menu_line)
  436. {
  437. if (lcdDrawUpdate) menu_draw_item_puts_P(LCD_STR_UPLEVEL[0], str);
  438. if (wasClicked && (encoderPosition == menu_item))
  439. {
  440. menu_back();
  441. return menu_item_ret();
  442. }
  443. }
  444. menu_item++;
  445. return 0;
  446. }
  447. #define MENU_ITEM_FUNCTION_P(str, func) do { if (menu_item_function_P(str, func)) return; } while (0)
  448. uint8_t menu_item_function_P(const char* str, menu_func_t func)
  449. {
  450. if (menu_item == menu_line)
  451. {
  452. if (lcdDrawUpdate) menu_draw_item_puts_P(' ', str);
  453. if (wasClicked && (encoderPosition == menu_item))
  454. {
  455. wasClicked = false;
  456. if (func) func();
  457. return menu_item_ret();
  458. }
  459. }
  460. menu_item++;
  461. return 0;
  462. }
  463. #define MENU_ITEM_GCODE_P(str, str_gcode) do { if (menu_item_gcode_P(str, str_gcode)) return; } while (0)
  464. uint8_t menu_item_gcode_P(const char* str, const char* str_gcode)
  465. {
  466. if (menu_item == menu_line)
  467. {
  468. if (lcdDrawUpdate) menu_draw_item_puts_P(' ', str);
  469. if (wasClicked && (encoderPosition == menu_item))
  470. {
  471. if (str_gcode) enquecommand_P(str_gcode);
  472. return menu_item_ret();
  473. }
  474. }
  475. menu_item++;
  476. return 0;
  477. }
  478. //#define MENU_ITEM_SDDIR(str, str_fn, str_fnl) do { if (menu_item_sddir(str, str_fn, str_fnl)) return; } while (0)
  479. #define MENU_ITEM_SDDIR(str, str_fn, str_fnl) MENU_ITEM(sddirectory, str, str_fn, str_fnl)
  480. uint8_t menu_item_sddir(const char* str, const char* str_fn, char* str_fnl)
  481. {
  482. // str_fnl[18] = 0;
  483. // printf_P(_N("menu dir %d '%s' '%s'\n"), menu_row, str_fn, str_fnl);
  484. if (menu_item == menu_line)
  485. {
  486. if (lcdDrawUpdate)
  487. {
  488. lcd.setCursor(0, menu_row);
  489. int cnt = lcd_printf_P(_N("%c%c%-18s"), (encoderPosition == menu_item)?'>':' ', LCD_STR_FOLDER[0], str_fnl[0]?str_fnl:str_fn);
  490. // int cnt = lcd_printf_P(_N("%c%c%-18s"), (encoderPosition == menu_item)?'>':' ', LCD_STR_FOLDER[0], str_fn);
  491. }
  492. if (wasClicked && (encoderPosition == menu_item))
  493. {
  494. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  495. strcpy(dir_names[depth], str_fn);
  496. // printf_P(PSTR("%s\n"), dir_names[depth]);
  497. card.chdir(str_fn);
  498. encoderPosition = 0;
  499. return menu_item_ret();
  500. }
  501. }
  502. menu_item++;
  503. return 0;
  504. }
  505. //#define MENU_ITEM_SDFILE(str, str_fn, str_fnl) do { if (menu_item_sdfile(str, str_fn, str_fnl)) return; } while (0)
  506. #define MENU_ITEM_SDFILE(str, str_fn, str_fnl) MENU_ITEM(sdfile, str, str_fn, str_fnl)
  507. uint8_t menu_item_sdfile(const char* str, const char* str_fn, char* str_fnl)
  508. {
  509. // printf_P(_N("menu sdfile\n"));
  510. // str_fnl[19] = 0;
  511. // printf_P(_N("menu file %d '%s' '%s'\n"), menu_row, str_fn, str_fnl);
  512. if (menu_item == menu_line)
  513. {
  514. if (lcdDrawUpdate)
  515. {
  516. // printf_P(_N("menu file %d %d '%s'\n"), menu_row, menuData.sdcard_menu.viewState, str_fnl[0]?str_fnl:str_fn);
  517. lcd.setCursor(0, menu_row);
  518. /* if (encoderPosition == menu_item)
  519. {
  520. lcd_printf_P(_N("%c%-19s"), (encoderPosition == menu_item)?'>':' ', (str_fnl[0]?str_fnl:str_fn) + 1);
  521. if (menuData.sdcard_menu.viewState == 0)
  522. {
  523. menuData.sdcard_menu.viewState++;
  524. lcd_printf_P(_N("%c%-19s"), (encoderPosition == menu_item)?'>':' ', (str_fnl[0]?str_fnl:str_fn) + 1);
  525. }
  526. else if (menuData.sdcard_menu.viewState == 1)
  527. {
  528. lcd_printf_P(_N("%c%-19s"), (encoderPosition == menu_item)?'>':' ', (str_fnl[0]?str_fnl:str_fn) + 2);
  529. }
  530. }
  531. else*/
  532. {
  533. str_fnl[19] = 0;
  534. lcd_printf_P(_N("%c%-19s"), (encoderPosition == menu_item)?'>':' ', str_fnl[0]?str_fnl:str_fn);
  535. }
  536. // int cnt = lcd_printf_P(_N("%c%-19s"), (encoderPosition == menu_item)?'>':' ', str_fnl);
  537. // int cnt = lcd_printf_P(_N("%cTESTIK.gcode"), (encoderPosition == menu_item)?'>':' ');
  538. }
  539. if (wasClicked && (encoderPosition == menu_item))
  540. {
  541. return menu_item_ret();
  542. }
  543. }
  544. menu_item++;
  545. return 0;
  546. }
  547. const char menu_fmt_int3[] PROGMEM = "%c%S:\x1b[%hhu;16H%3d";
  548. void _menu_edit_int3(void)
  549. {
  550. if (lcdDrawUpdate)
  551. {
  552. if (encoderPosition < menuData.editMenuParentState.minEditValue) encoderPosition = menuData.editMenuParentState.minEditValue;
  553. if (encoderPosition > menuData.editMenuParentState.maxEditValue) encoderPosition = menuData.editMenuParentState.maxEditValue;
  554. lcd.setCursor(0, 1);
  555. lcd_printf_P(menu_fmt_int3, ' ', menuData.editMenuParentState.editLabel, (uint8_t)1, (int)encoderPosition);
  556. }
  557. if (LCD_CLICKED)
  558. {
  559. *((int*)(menuData.editMenuParentState.editValue)) = (int)encoderPosition;
  560. menu_back();
  561. }
  562. }
  563. #define MENU_ITEM_EDIT_P_int3(str, pval, minval, maxval, fmt) do { if (menu_item_edit_int16(str, pval, minval, maxval, fmt)) return; } while (0)
  564. uint8_t menu_item_edit_int3(const char* str, int16_t* pval, int16_t min_val, int16_t max_val)
  565. {
  566. if (menu_item == menu_line)
  567. {
  568. if (lcdDrawUpdate)
  569. {
  570. lcd.setCursor(0, menu_row);
  571. lcd_printf_P(menu_fmt_int3, (encoderPosition == menu_item)?'>':' ', str, menu_row, *pval);
  572. }
  573. if (wasClicked && (encoderPosition == menu_item))
  574. {
  575. menu_submenu(_menu_edit_int3);
  576. menuData.editMenuParentState.editLabel = str;
  577. menuData.editMenuParentState.editValue = pval;
  578. menuData.editMenuParentState.minEditValue = min_val;
  579. menuData.editMenuParentState.maxEditValue = max_val;
  580. encoderPosition = *pval;
  581. return menu_item_ret();
  582. }
  583. }
  584. menu_item++;
  585. return 0;
  586. }
  587. /* Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent */
  588. static void lcd_status_screen()
  589. {
  590. if (firstrun == 1)
  591. {
  592. firstrun = 0;
  593. if(lcd_status_message_level == 0){
  594. strncpy_P(lcd_status_message, _T(WELCOME_MSG), LCD_WIDTH);
  595. lcd_finishstatus();
  596. }
  597. 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)
  598. {
  599. eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0);
  600. eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0);
  601. }
  602. }
  603. if (lcd_status_update_delay)
  604. lcd_status_update_delay--;
  605. else
  606. lcdDrawUpdate = 1;
  607. if (lcdDrawUpdate)
  608. {
  609. ReInitLCD++;
  610. if (ReInitLCD == 30)
  611. {
  612. lcd_implementation_init(); // to maybe revive the LCD if static electricity killed it.
  613. ReInitLCD = 0 ;
  614. }
  615. else
  616. {
  617. if ((ReInitLCD % 10) == 0)
  618. {
  619. //lcd_implementation_nodisplay();
  620. lcd_implementation_init_noclear(); //to maybe revive the LCD if static electricity killed it.
  621. }
  622. }
  623. //lcd_implementation_display();
  624. lcd_implementation_status_screen();
  625. //lcd_implementation_clear();
  626. if (farm_mode)
  627. {
  628. farm_timer--;
  629. if (farm_timer < 1)
  630. {
  631. farm_timer = 10;
  632. prusa_statistics(0);
  633. }
  634. switch (farm_timer)
  635. {
  636. case 8:
  637. prusa_statistics(21);
  638. break;
  639. case 5:
  640. if (IS_SD_PRINTING)
  641. {
  642. prusa_statistics(20);
  643. }
  644. break;
  645. }
  646. } // end of farm_mode
  647. 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 */
  648. if (lcd_commands_type != LCD_COMMAND_IDLE)
  649. {
  650. lcd_commands();
  651. }
  652. } // end of lcdDrawUpdate
  653. #ifdef ULTIPANEL
  654. bool current_click = LCD_CLICKED;
  655. if (ignore_click) {
  656. if (wait_for_unclick) {
  657. if (!current_click) {
  658. ignore_click = wait_for_unclick = false;
  659. }
  660. else {
  661. current_click = false;
  662. }
  663. }
  664. else if (current_click) {
  665. lcd_quick_feedback();
  666. wait_for_unclick = true;
  667. current_click = false;
  668. }
  669. }
  670. if (current_click && (lcd_commands_type != LCD_COMMAND_STOP_PRINT)) //click is aborted unless stop print finishes
  671. {
  672. menu_depth = 0; //redundant, as already done in lcd_return_to_status(), just to be sure
  673. menu_submenu(lcd_main_menu);
  674. lcd_implementation_init(); // to maybe revive the LCD if static electricity killed it.
  675. }
  676. #ifdef ULTIPANEL_FEEDMULTIPLY
  677. // Dead zone at 100% feedrate
  678. if ((feedmultiply < 100 && (feedmultiply + int(encoderPosition)) > 100) ||
  679. (feedmultiply > 100 && (feedmultiply + int(encoderPosition)) < 100))
  680. {
  681. encoderPosition = 0;
  682. feedmultiply = 100;
  683. }
  684. if (feedmultiply == 100 && int(encoderPosition) > ENCODER_FEEDRATE_DEADZONE)
  685. {
  686. feedmultiply += int(encoderPosition) - ENCODER_FEEDRATE_DEADZONE;
  687. encoderPosition = 0;
  688. }
  689. else if (feedmultiply == 100 && int(encoderPosition) < -ENCODER_FEEDRATE_DEADZONE)
  690. {
  691. feedmultiply += int(encoderPosition) + ENCODER_FEEDRATE_DEADZONE;
  692. encoderPosition = 0;
  693. }
  694. else if (feedmultiply != 100)
  695. {
  696. feedmultiply += int(encoderPosition);
  697. encoderPosition = 0;
  698. }
  699. #endif //ULTIPANEL_FEEDMULTIPLY
  700. if (feedmultiply < 10)
  701. feedmultiply = 10;
  702. else if (feedmultiply > 999)
  703. feedmultiply = 999;
  704. #endif //ULTIPANEL
  705. /*if (farm_mode && !printer_connected) {
  706. lcd.setCursor(0, 3);
  707. lcd_printPGM(_i("Printer disconnected"));////MSG_PRINTER_DISCONNECTED c=20 r=1
  708. }*/
  709. //#define FSENS_FACTOR (2580.8/50) //filament sensor factor [steps / encoder counts]
  710. //#define FSENS_FACTOR (2580.8/45.3) //filament sensor factor [steps / encoder counts]
  711. //lcd.setCursor(0, 3);
  712. //lcd_implementation_print(" ");
  713. //lcd.setCursor(0, 3);
  714. //lcd_implementation_print(pat9125_x);
  715. //lcd.setCursor(6, 3);
  716. //lcd_implementation_print(pat9125_y);
  717. //lcd.setCursor(12, 3);
  718. //lcd_implementation_print(pat9125_b);
  719. }
  720. #ifdef ULTIPANEL
  721. void lcd_commands()
  722. {
  723. if (lcd_commands_type == LCD_COMMAND_LONG_PAUSE)
  724. {
  725. if(lcd_commands_step == 0) {
  726. if (card.sdprinting) {
  727. card.pauseSDPrint();
  728. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  729. lcdDrawUpdate = 3;
  730. lcd_commands_step = 1;
  731. }
  732. else {
  733. lcd_commands_type = 0;
  734. }
  735. }
  736. if (lcd_commands_step == 1 && !blocks_queued() && !homing_flag) {
  737. lcd_setstatuspgm(_i("Print paused"));////MSG_PRINT_PAUSED c=20 r=1
  738. isPrintPaused = true;
  739. long_pause();
  740. lcd_commands_type = 0;
  741. lcd_commands_step = 0;
  742. }
  743. }
  744. if (lcd_commands_type == LCD_COMMAND_LONG_PAUSE_RESUME) {
  745. char cmd1[30];
  746. if (lcd_commands_step == 0) {
  747. lcdDrawUpdate = 3;
  748. lcd_commands_step = 4;
  749. }
  750. if (lcd_commands_step == 1 && !blocks_queued() && cmd_buffer_empty()) { //recover feedmultiply; cmd_buffer_empty() ensures that card.sdprinting is synchronized with buffered commands and thus print cant be paused until resume is finished
  751. sprintf_P(cmd1, PSTR("M220 S%d"), saved_feedmultiply);
  752. enquecommand(cmd1);
  753. isPrintPaused = false;
  754. pause_time += (millis() - start_pause_print); //accumulate time when print is paused for correct statistics calculation
  755. card.startFileprint();
  756. lcd_commands_step = 0;
  757. lcd_commands_type = 0;
  758. }
  759. if (lcd_commands_step == 2 && !blocks_queued()) { //turn on fan, move Z and unretract
  760. sprintf_P(cmd1, PSTR("M106 S%d"), fanSpeedBckp);
  761. enquecommand(cmd1);
  762. strcpy(cmd1, "G1 Z");
  763. strcat(cmd1, ftostr32(pause_lastpos[Z_AXIS]));
  764. enquecommand(cmd1);
  765. if (axis_relative_modes[3] == false) {
  766. enquecommand_P(PSTR("M83")); // set extruder to relative mode
  767. enquecommand_P(PSTR("G1 E" STRINGIFY(DEFAULT_RETRACTION))); //unretract
  768. enquecommand_P(PSTR("M82")); // set extruder to absolute mode
  769. }
  770. else {
  771. enquecommand_P(PSTR("G1 E" STRINGIFY(DEFAULT_RETRACTION))); //unretract
  772. }
  773. lcd_commands_step = 1;
  774. }
  775. if (lcd_commands_step == 3 && !blocks_queued()) { //wait for nozzle to reach target temp
  776. strcpy(cmd1, "M109 S");
  777. strcat(cmd1, ftostr3(HotendTempBckp));
  778. enquecommand(cmd1);
  779. lcd_commands_step = 2;
  780. }
  781. if (lcd_commands_step == 4 && !blocks_queued()) { //set temperature back and move xy
  782. strcpy(cmd1, "M104 S");
  783. strcat(cmd1, ftostr3(HotendTempBckp));
  784. enquecommand(cmd1);
  785. enquecommand_P(PSTR("G90")); //absolute positioning
  786. strcpy(cmd1, "G1 X");
  787. strcat(cmd1, ftostr32(pause_lastpos[X_AXIS]));
  788. strcat(cmd1, " Y");
  789. strcat(cmd1, ftostr32(pause_lastpos[Y_AXIS]));
  790. enquecommand(cmd1);
  791. lcd_setstatuspgm(_T(MSG_RESUMING_PRINT));
  792. lcd_commands_step = 3;
  793. }
  794. }
  795. #ifdef SNMM
  796. if (lcd_commands_type == LCD_COMMAND_V2_CAL)
  797. {
  798. char cmd1[30];
  799. float width = 0.4;
  800. float length = 20 - width;
  801. float extr = count_e(0.2, width, length);
  802. float extr_short_segment = count_e(0.2, width, width);
  803. if (lcd_commands_step>1) lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS; //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  804. if (lcd_commands_step == 0)
  805. {
  806. lcd_commands_step = 10;
  807. }
  808. if (lcd_commands_step == 10 && !blocks_queued() && cmd_buffer_empty())
  809. {
  810. enquecommand_P(PSTR("M107"));
  811. enquecommand_P(PSTR("M104 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  812. enquecommand_P(PSTR("M140 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  813. enquecommand_P(PSTR("M190 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  814. enquecommand_P(PSTR("M109 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  815. enquecommand_P(PSTR("T0"));
  816. enquecommand_P(_T(MSG_M117_V2_CALIBRATION));
  817. enquecommand_P(PSTR("G87")); //sets calibration status
  818. enquecommand_P(PSTR("G28"));
  819. enquecommand_P(PSTR("G21")); //set units to millimeters
  820. enquecommand_P(PSTR("G90")); //use absolute coordinates
  821. enquecommand_P(PSTR("M83")); //use relative distances for extrusion
  822. enquecommand_P(PSTR("G92 E0"));
  823. enquecommand_P(PSTR("M203 E100"));
  824. enquecommand_P(PSTR("M92 E140"));
  825. lcd_commands_step = 9;
  826. }
  827. if (lcd_commands_step == 9 && !blocks_queued() && cmd_buffer_empty())
  828. {
  829. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  830. enquecommand_P(PSTR("G1 Z0.250 F7200.000"));
  831. enquecommand_P(PSTR("G1 X50.0 E80.0 F1000.0"));
  832. enquecommand_P(PSTR("G1 X160.0 E20.0 F1000.0"));
  833. enquecommand_P(PSTR("G1 Z0.200 F7200.000"));
  834. enquecommand_P(PSTR("G1 X220.0 E13 F1000.0"));
  835. enquecommand_P(PSTR("G1 X240.0 E0 F1000.0"));
  836. enquecommand_P(PSTR("G92 E0.0"));
  837. enquecommand_P(PSTR("G21"));
  838. enquecommand_P(PSTR("G90"));
  839. enquecommand_P(PSTR("M83"));
  840. enquecommand_P(PSTR("G1 E-4 F2100.00000"));
  841. enquecommand_P(PSTR("G1 Z0.150 F7200.000"));
  842. enquecommand_P(PSTR("M204 S1000"));
  843. enquecommand_P(PSTR("G1 F4000"));
  844. lcd_implementation_clear();
  845. lcd_goto_menu(lcd_babystep_z, 0, false);
  846. lcd_commands_step = 8;
  847. }
  848. if (lcd_commands_step == 8 && !blocks_queued() && cmd_buffer_empty()) //draw meander
  849. {
  850. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  851. enquecommand_P(PSTR("G1 X50 Y155"));
  852. enquecommand_P(PSTR("G1 X60 Y155 E4"));
  853. enquecommand_P(PSTR("G1 F1080"));
  854. enquecommand_P(PSTR("G1 X75 Y155 E2.5"));
  855. enquecommand_P(PSTR("G1 X100 Y155 E2"));
  856. enquecommand_P(PSTR("G1 X200 Y155 E2.62773"));
  857. enquecommand_P(PSTR("G1 X200 Y135 E0.66174"));
  858. enquecommand_P(PSTR("G1 X50 Y135 E3.62773"));
  859. enquecommand_P(PSTR("G1 X50 Y115 E0.49386"));
  860. enquecommand_P(PSTR("G1 X200 Y115 E3.62773"));
  861. enquecommand_P(PSTR("G1 X200 Y95 E0.49386"));
  862. enquecommand_P(PSTR("G1 X50 Y95 E3.62773"));
  863. enquecommand_P(PSTR("G1 X50 Y75 E0.49386"));
  864. enquecommand_P(PSTR("G1 X200 Y75 E3.62773"));
  865. enquecommand_P(PSTR("G1 X200 Y55 E0.49386"));
  866. enquecommand_P(PSTR("G1 X50 Y55 E3.62773"));
  867. lcd_commands_step = 7;
  868. }
  869. if (lcd_commands_step == 7 && !blocks_queued() && cmd_buffer_empty())
  870. {
  871. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  872. strcpy(cmd1, "G1 X50 Y35 E");
  873. strcat(cmd1, ftostr43(extr));
  874. enquecommand(cmd1);
  875. for (int i = 0; i < 4; i++) {
  876. strcpy(cmd1, "G1 X70 Y");
  877. strcat(cmd1, ftostr32(35 - i*width * 2));
  878. strcat(cmd1, " E");
  879. strcat(cmd1, ftostr43(extr));
  880. enquecommand(cmd1);
  881. strcpy(cmd1, "G1 Y");
  882. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  883. strcat(cmd1, " E");
  884. strcat(cmd1, ftostr43(extr_short_segment));
  885. enquecommand(cmd1);
  886. strcpy(cmd1, "G1 X50 Y");
  887. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  888. strcat(cmd1, " E");
  889. strcat(cmd1, ftostr43(extr));
  890. enquecommand(cmd1);
  891. strcpy(cmd1, "G1 Y");
  892. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  893. strcat(cmd1, " E");
  894. strcat(cmd1, ftostr43(extr_short_segment));
  895. enquecommand(cmd1);
  896. }
  897. lcd_commands_step = 6;
  898. }
  899. if (lcd_commands_step == 6 && !blocks_queued() && cmd_buffer_empty())
  900. {
  901. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  902. for (int i = 4; i < 8; i++) {
  903. strcpy(cmd1, "G1 X70 Y");
  904. strcat(cmd1, ftostr32(35 - i*width * 2));
  905. strcat(cmd1, " E");
  906. strcat(cmd1, ftostr43(extr));
  907. enquecommand(cmd1);
  908. strcpy(cmd1, "G1 Y");
  909. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  910. strcat(cmd1, " E");
  911. strcat(cmd1, ftostr43(extr_short_segment));
  912. enquecommand(cmd1);
  913. strcpy(cmd1, "G1 X50 Y");
  914. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  915. strcat(cmd1, " E");
  916. strcat(cmd1, ftostr43(extr));
  917. enquecommand(cmd1);
  918. strcpy(cmd1, "G1 Y");
  919. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  920. strcat(cmd1, " E");
  921. strcat(cmd1, ftostr43(extr_short_segment));
  922. enquecommand(cmd1);
  923. }
  924. lcd_commands_step = 5;
  925. }
  926. if (lcd_commands_step == 5 && !blocks_queued() && cmd_buffer_empty())
  927. {
  928. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  929. for (int i = 8; i < 12; i++) {
  930. strcpy(cmd1, "G1 X70 Y");
  931. strcat(cmd1, ftostr32(35 - i*width * 2));
  932. strcat(cmd1, " E");
  933. strcat(cmd1, ftostr43(extr));
  934. enquecommand(cmd1);
  935. strcpy(cmd1, "G1 Y");
  936. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  937. strcat(cmd1, " E");
  938. strcat(cmd1, ftostr43(extr_short_segment));
  939. enquecommand(cmd1);
  940. strcpy(cmd1, "G1 X50 Y");
  941. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  942. strcat(cmd1, " E");
  943. strcat(cmd1, ftostr43(extr));
  944. enquecommand(cmd1);
  945. strcpy(cmd1, "G1 Y");
  946. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  947. strcat(cmd1, " E");
  948. strcat(cmd1, ftostr43(extr_short_segment));
  949. enquecommand(cmd1);
  950. }
  951. lcd_commands_step = 4;
  952. }
  953. if (lcd_commands_step == 4 && !blocks_queued() && cmd_buffer_empty())
  954. {
  955. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  956. for (int i = 12; i < 16; i++) {
  957. strcpy(cmd1, "G1 X70 Y");
  958. strcat(cmd1, ftostr32(35 - i*width * 2));
  959. strcat(cmd1, " E");
  960. strcat(cmd1, ftostr43(extr));
  961. enquecommand(cmd1);
  962. strcpy(cmd1, "G1 Y");
  963. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  964. strcat(cmd1, " E");
  965. strcat(cmd1, ftostr43(extr_short_segment));
  966. enquecommand(cmd1);
  967. strcpy(cmd1, "G1 X50 Y");
  968. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  969. strcat(cmd1, " E");
  970. strcat(cmd1, ftostr43(extr));
  971. enquecommand(cmd1);
  972. strcpy(cmd1, "G1 Y");
  973. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  974. strcat(cmd1, " E");
  975. strcat(cmd1, ftostr43(extr_short_segment));
  976. enquecommand(cmd1);
  977. }
  978. lcd_commands_step = 3;
  979. }
  980. if (lcd_commands_step == 3 && !blocks_queued() && cmd_buffer_empty())
  981. {
  982. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  983. enquecommand_P(PSTR("G1 E-0.07500 F2100.00000"));
  984. enquecommand_P(PSTR("G4 S0"));
  985. enquecommand_P(PSTR("G1 E-4 F2100.00000"));
  986. enquecommand_P(PSTR("G1 Z0.5 F7200.000"));
  987. enquecommand_P(PSTR("G1 X245 Y1"));
  988. enquecommand_P(PSTR("G1 X240 E4"));
  989. enquecommand_P(PSTR("G1 F4000"));
  990. enquecommand_P(PSTR("G1 X190 E2.7"));
  991. enquecommand_P(PSTR("G1 F4600"));
  992. enquecommand_P(PSTR("G1 X110 E2.8"));
  993. enquecommand_P(PSTR("G1 F5200"));
  994. enquecommand_P(PSTR("G1 X40 E3"));
  995. enquecommand_P(PSTR("G1 E-15.0000 F5000"));
  996. enquecommand_P(PSTR("G1 E-50.0000 F5400"));
  997. enquecommand_P(PSTR("G1 E-15.0000 F3000"));
  998. enquecommand_P(PSTR("G1 E-12.0000 F2000"));
  999. enquecommand_P(PSTR("G1 F1600"));
  1000. lcd_commands_step = 2;
  1001. }
  1002. if (lcd_commands_step == 2 && !blocks_queued() && cmd_buffer_empty())
  1003. {
  1004. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1005. enquecommand_P(PSTR("G1 X0 Y1 E3.0000"));
  1006. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  1007. enquecommand_P(PSTR("G1 F2000"));
  1008. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  1009. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  1010. enquecommand_P(PSTR("G1 F2400"));
  1011. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  1012. enquecommand_P(PSTR("G1 X50 Y1 E-5.0000"));
  1013. enquecommand_P(PSTR("G1 F2400"));
  1014. enquecommand_P(PSTR("G1 X0 Y1 E5.0000"));
  1015. enquecommand_P(PSTR("G1 X50 Y1 E-3.0000"));
  1016. enquecommand_P(PSTR("G4 S0"));
  1017. enquecommand_P(PSTR("M107"));
  1018. enquecommand_P(PSTR("M104 S0"));
  1019. enquecommand_P(PSTR("M140 S0"));
  1020. enquecommand_P(PSTR("G1 X10 Y180 F4000"));
  1021. enquecommand_P(PSTR("G1 Z10 F1300.000"));
  1022. enquecommand_P(PSTR("M84"));
  1023. lcd_commands_step = 1;
  1024. }
  1025. if (lcd_commands_step == 1 && !blocks_queued() && cmd_buffer_empty())
  1026. {
  1027. lcd_setstatuspgm(_T(WELCOME_MSG));
  1028. lcd_commands_step = 0;
  1029. lcd_commands_type = 0;
  1030. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) {
  1031. lcd_wizard(10);
  1032. }
  1033. }
  1034. }
  1035. #else //if not SNMM
  1036. if (lcd_commands_type == LCD_COMMAND_V2_CAL)
  1037. {
  1038. char cmd1[30];
  1039. float width = 0.4;
  1040. float length = 20 - width;
  1041. float extr = count_e(0.2, width, length);
  1042. float extr_short_segment = count_e(0.2, width, width);
  1043. if(lcd_commands_step>1) lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS; //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  1044. if (lcd_commands_step == 0)
  1045. {
  1046. lcd_commands_step = 9;
  1047. }
  1048. if (lcd_commands_step == 9 && !blocks_queued() && cmd_buffer_empty())
  1049. {
  1050. enquecommand_P(PSTR("M107"));
  1051. enquecommand_P(PSTR("M104 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  1052. enquecommand_P(PSTR("M140 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  1053. enquecommand_P(PSTR("M190 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP)));
  1054. enquecommand_P(PSTR("M109 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP)));
  1055. enquecommand_P(_T(MSG_M117_V2_CALIBRATION));
  1056. enquecommand_P(PSTR("G28"));
  1057. enquecommand_P(PSTR("G92 E0.0"));
  1058. lcd_commands_step = 8;
  1059. }
  1060. if (lcd_commands_step == 8 && !blocks_queued() && cmd_buffer_empty())
  1061. {
  1062. lcd_implementation_clear();
  1063. menu_depth = 0;
  1064. menu_submenu(lcd_babystep_z);
  1065. enquecommand_P(PSTR("G1 X60.0 E9.0 F1000.0")); //intro line
  1066. enquecommand_P(PSTR("G1 X100.0 E12.5 F1000.0")); //intro line
  1067. enquecommand_P(PSTR("G92 E0.0"));
  1068. enquecommand_P(PSTR("G21")); //set units to millimeters
  1069. enquecommand_P(PSTR("G90")); //use absolute coordinates
  1070. enquecommand_P(PSTR("M83")); //use relative distances for extrusion
  1071. enquecommand_P(PSTR("G1 E-1.50000 F2100.00000"));
  1072. enquecommand_P(PSTR("G1 Z0.150 F7200.000"));
  1073. enquecommand_P(PSTR("M204 S1000")); //set acceleration
  1074. enquecommand_P(PSTR("G1 F4000"));
  1075. lcd_commands_step = 7;
  1076. }
  1077. if (lcd_commands_step == 7 && !blocks_queued() && cmd_buffer_empty()) //draw meander
  1078. {
  1079. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1080. //just opposite direction
  1081. /*enquecommand_P(PSTR("G1 X50 Y55"));
  1082. enquecommand_P(PSTR("G1 F1080"));
  1083. enquecommand_P(PSTR("G1 X200 Y55 E3.62773"));
  1084. enquecommand_P(PSTR("G1 X200 Y75 E0.49386"));
  1085. enquecommand_P(PSTR("G1 X50 Y75 E3.62773"));
  1086. enquecommand_P(PSTR("G1 X50 Y95 E0.49386"));
  1087. enquecommand_P(PSTR("G1 X200 Y95 E3.62773"));
  1088. enquecommand_P(PSTR("G1 X200 Y115 E0.49386"));
  1089. enquecommand_P(PSTR("G1 X50 Y115 E3.62773"));
  1090. enquecommand_P(PSTR("G1 X50 Y135 E0.49386"));
  1091. enquecommand_P(PSTR("G1 X200 Y135 E3.62773"));
  1092. enquecommand_P(PSTR("G1 X200 Y155 E0.66174"));
  1093. enquecommand_P(PSTR("G1 X100 Y155 E2.62773"));
  1094. enquecommand_P(PSTR("G1 X75 Y155 E2"));
  1095. enquecommand_P(PSTR("G1 X50 Y155 E2.5"));
  1096. enquecommand_P(PSTR("G1 E - 0.07500 F2100.00000"));*/
  1097. enquecommand_P(PSTR("G1 X50 Y155"));
  1098. enquecommand_P(PSTR("G1 F1080"));
  1099. enquecommand_P(PSTR("G1 X75 Y155 E2.5"));
  1100. enquecommand_P(PSTR("G1 X100 Y155 E2"));
  1101. enquecommand_P(PSTR("G1 X200 Y155 E2.62773"));
  1102. enquecommand_P(PSTR("G1 X200 Y135 E0.66174"));
  1103. enquecommand_P(PSTR("G1 X50 Y135 E3.62773"));
  1104. enquecommand_P(PSTR("G1 X50 Y115 E0.49386"));
  1105. enquecommand_P(PSTR("G1 X200 Y115 E3.62773"));
  1106. enquecommand_P(PSTR("G1 X200 Y95 E0.49386"));
  1107. enquecommand_P(PSTR("G1 X50 Y95 E3.62773"));
  1108. enquecommand_P(PSTR("G1 X50 Y75 E0.49386"));
  1109. enquecommand_P(PSTR("G1 X200 Y75 E3.62773"));
  1110. enquecommand_P(PSTR("G1 X200 Y55 E0.49386"));
  1111. enquecommand_P(PSTR("G1 X50 Y55 E3.62773"));
  1112. strcpy(cmd1, "G1 X50 Y35 E");
  1113. strcat(cmd1, ftostr43(extr));
  1114. enquecommand(cmd1);
  1115. lcd_commands_step = 6;
  1116. }
  1117. if (lcd_commands_step == 6 && !blocks_queued() && cmd_buffer_empty())
  1118. {
  1119. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1120. for (int i = 0; i < 4; i++) {
  1121. strcpy(cmd1, "G1 X70 Y");
  1122. strcat(cmd1, ftostr32(35 - i*width * 2));
  1123. strcat(cmd1, " E");
  1124. strcat(cmd1, ftostr43(extr));
  1125. enquecommand(cmd1);
  1126. strcpy(cmd1, "G1 Y");
  1127. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1128. strcat(cmd1, " E");
  1129. strcat(cmd1, ftostr43(extr_short_segment));
  1130. enquecommand(cmd1);
  1131. strcpy(cmd1, "G1 X50 Y");
  1132. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1133. strcat(cmd1, " E");
  1134. strcat(cmd1, ftostr43(extr));
  1135. enquecommand(cmd1);
  1136. strcpy(cmd1, "G1 Y");
  1137. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1138. strcat(cmd1, " E");
  1139. strcat(cmd1, ftostr43(extr_short_segment));
  1140. enquecommand(cmd1);
  1141. }
  1142. lcd_commands_step = 5;
  1143. }
  1144. if (lcd_commands_step == 5 && !blocks_queued() && cmd_buffer_empty())
  1145. {
  1146. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1147. for (int i = 4; i < 8; i++) {
  1148. strcpy(cmd1, "G1 X70 Y");
  1149. strcat(cmd1, ftostr32(35 - i*width * 2));
  1150. strcat(cmd1, " E");
  1151. strcat(cmd1, ftostr43(extr));
  1152. enquecommand(cmd1);
  1153. strcpy(cmd1, "G1 Y");
  1154. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1155. strcat(cmd1, " E");
  1156. strcat(cmd1, ftostr43(extr_short_segment));
  1157. enquecommand(cmd1);
  1158. strcpy(cmd1, "G1 X50 Y");
  1159. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1160. strcat(cmd1, " E");
  1161. strcat(cmd1, ftostr43(extr));
  1162. enquecommand(cmd1);
  1163. strcpy(cmd1, "G1 Y");
  1164. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1165. strcat(cmd1, " E");
  1166. strcat(cmd1, ftostr43(extr_short_segment));
  1167. enquecommand(cmd1);
  1168. }
  1169. lcd_commands_step = 4;
  1170. }
  1171. if (lcd_commands_step == 4 && !blocks_queued() && cmd_buffer_empty())
  1172. {
  1173. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1174. for (int i = 8; i < 12; i++) {
  1175. strcpy(cmd1, "G1 X70 Y");
  1176. strcat(cmd1, ftostr32(35 - i*width * 2));
  1177. strcat(cmd1, " E");
  1178. strcat(cmd1, ftostr43(extr));
  1179. enquecommand(cmd1);
  1180. strcpy(cmd1, "G1 Y");
  1181. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1182. strcat(cmd1, " E");
  1183. strcat(cmd1, ftostr43(extr_short_segment));
  1184. enquecommand(cmd1);
  1185. strcpy(cmd1, "G1 X50 Y");
  1186. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1187. strcat(cmd1, " E");
  1188. strcat(cmd1, ftostr43(extr));
  1189. enquecommand(cmd1);
  1190. strcpy(cmd1, "G1 Y");
  1191. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1192. strcat(cmd1, " E");
  1193. strcat(cmd1, ftostr43(extr_short_segment));
  1194. enquecommand(cmd1);
  1195. }
  1196. lcd_commands_step = 3;
  1197. }
  1198. if (lcd_commands_step == 3 && !blocks_queued() && cmd_buffer_empty())
  1199. {
  1200. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1201. for (int i = 12; i < 16; i++) {
  1202. strcpy(cmd1, "G1 X70 Y");
  1203. strcat(cmd1, ftostr32(35 - i*width * 2));
  1204. strcat(cmd1, " E");
  1205. strcat(cmd1, ftostr43(extr));
  1206. enquecommand(cmd1);
  1207. strcpy(cmd1, "G1 Y");
  1208. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1209. strcat(cmd1, " E");
  1210. strcat(cmd1, ftostr43(extr_short_segment));
  1211. enquecommand(cmd1);
  1212. strcpy(cmd1, "G1 X50 Y");
  1213. strcat(cmd1, ftostr32(35 - (2 * i + 1)*width));
  1214. strcat(cmd1, " E");
  1215. strcat(cmd1, ftostr43(extr));
  1216. enquecommand(cmd1);
  1217. strcpy(cmd1, "G1 Y");
  1218. strcat(cmd1, ftostr32(35 - (i + 1)*width * 2));
  1219. strcat(cmd1, " E");
  1220. strcat(cmd1, ftostr43(extr_short_segment));
  1221. enquecommand(cmd1);
  1222. }
  1223. lcd_commands_step = 2;
  1224. }
  1225. if (lcd_commands_step == 2 && !blocks_queued() && cmd_buffer_empty())
  1226. {
  1227. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  1228. enquecommand_P(PSTR("G1 E-0.07500 F2100.00000"));
  1229. enquecommand_P(PSTR("M107")); //turn off printer fan
  1230. enquecommand_P(PSTR("M104 S0")); // turn off temperature
  1231. enquecommand_P(PSTR("M140 S0")); // turn off heatbed
  1232. enquecommand_P(PSTR("G1 Z10 F1300.000"));
  1233. enquecommand_P(PSTR("G1 X10 Y180 F4000")); //home X axis
  1234. enquecommand_P(PSTR("M84"));// disable motors
  1235. lcd_timeoutToStatus = millis() - 1; //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen
  1236. lcd_commands_step = 1;
  1237. }
  1238. if (lcd_commands_step == 1 && !blocks_queued() && cmd_buffer_empty())
  1239. {
  1240. lcd_setstatuspgm(_T(WELCOME_MSG));
  1241. lcd_commands_step = 0;
  1242. lcd_commands_type = 0;
  1243. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) {
  1244. lcd_wizard(10);
  1245. }
  1246. }
  1247. }
  1248. #endif // not SNMM
  1249. if (lcd_commands_type == LCD_COMMAND_STOP_PRINT) /// stop print
  1250. {
  1251. if (lcd_commands_step == 0)
  1252. {
  1253. lcd_commands_step = 6;
  1254. custom_message = true;
  1255. }
  1256. if (lcd_commands_step == 1 && !blocks_queued())
  1257. {
  1258. lcd_commands_step = 0;
  1259. lcd_commands_type = 0;
  1260. lcd_setstatuspgm(_T(WELCOME_MSG));
  1261. custom_message_type = 0;
  1262. custom_message = false;
  1263. isPrintPaused = false;
  1264. }
  1265. if (lcd_commands_step == 2 && !blocks_queued())
  1266. {
  1267. setTargetBed(0);
  1268. enquecommand_P(PSTR("M104 S0")); //set hotend temp to 0
  1269. manage_heater();
  1270. lcd_setstatuspgm(_T(WELCOME_MSG));
  1271. cancel_heatup = false;
  1272. lcd_commands_step = 1;
  1273. }
  1274. if (lcd_commands_step == 3 && !blocks_queued())
  1275. {
  1276. // M84: Disable steppers.
  1277. enquecommand_P(PSTR("M84"));
  1278. autotempShutdown();
  1279. lcd_commands_step = 2;
  1280. }
  1281. if (lcd_commands_step == 4 && !blocks_queued())
  1282. {
  1283. lcd_setstatuspgm(_T(MSG_PLEASE_WAIT));
  1284. // G90: Absolute positioning.
  1285. enquecommand_P(PSTR("G90"));
  1286. // M83: Set extruder to relative mode.
  1287. enquecommand_P(PSTR("M83"));
  1288. #ifdef X_CANCEL_POS
  1289. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  1290. #else
  1291. enquecommand_P(PSTR("G1 X50 Y" STRINGIFY(Y_MAX_POS) " E0 F7000"));
  1292. #endif
  1293. lcd_ignore_click(false);
  1294. #ifdef SNMM
  1295. lcd_commands_step = 8;
  1296. #else
  1297. lcd_commands_step = 3;
  1298. #endif
  1299. }
  1300. if (lcd_commands_step == 5 && !blocks_queued())
  1301. {
  1302. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  1303. // G91: Set to relative positioning.
  1304. enquecommand_P(PSTR("G91"));
  1305. // Lift up.
  1306. enquecommand_P(PSTR("G1 Z15 F1500"));
  1307. if (axis_known_position[X_AXIS] && axis_known_position[Y_AXIS]) lcd_commands_step = 4;
  1308. else lcd_commands_step = 3;
  1309. }
  1310. if (lcd_commands_step == 6 && !blocks_queued())
  1311. {
  1312. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  1313. cancel_heatup = true;
  1314. setTargetBed(0);
  1315. #ifndef SNMM
  1316. setTargetHotend(0, 0); //heating when changing filament for multicolor
  1317. setTargetHotend(0, 1);
  1318. setTargetHotend(0, 2);
  1319. #endif
  1320. manage_heater();
  1321. custom_message = true;
  1322. custom_message_type = 2;
  1323. lcd_commands_step = 5;
  1324. }
  1325. if (lcd_commands_step == 7 && !blocks_queued()) {
  1326. switch(snmm_stop_print_menu()) {
  1327. case 0: enquecommand_P(PSTR("M702")); break;//all
  1328. case 1: enquecommand_P(PSTR("M702 U")); break; //used
  1329. case 2: enquecommand_P(PSTR("M702 C")); break; //current
  1330. default: enquecommand_P(PSTR("M702")); break;
  1331. }
  1332. lcd_commands_step = 3;
  1333. }
  1334. 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)
  1335. lcd_commands_step = 7;
  1336. }
  1337. }
  1338. if (lcd_commands_type == 3)
  1339. {
  1340. lcd_commands_type = 0;
  1341. }
  1342. if (lcd_commands_type == LCD_COMMAND_FARM_MODE_CONFIRM) /// farm mode confirm
  1343. {
  1344. if (lcd_commands_step == 0) { lcd_commands_step = 6; custom_message = true; }
  1345. if (lcd_commands_step == 1 && !blocks_queued())
  1346. {
  1347. lcd_confirm_print();
  1348. lcd_commands_step = 0;
  1349. lcd_commands_type = 0;
  1350. }
  1351. if (lcd_commands_step == 2 && !blocks_queued())
  1352. {
  1353. lcd_commands_step = 1;
  1354. }
  1355. if (lcd_commands_step == 3 && !blocks_queued())
  1356. {
  1357. lcd_commands_step = 2;
  1358. }
  1359. if (lcd_commands_step == 4 && !blocks_queued())
  1360. {
  1361. enquecommand_P(PSTR("G90"));
  1362. enquecommand_P(PSTR("G1 X" STRINGIFY(X_CANCEL_POS) " Y" STRINGIFY(Y_CANCEL_POS) " E0 F7000"));
  1363. lcd_commands_step = 3;
  1364. }
  1365. if (lcd_commands_step == 5 && !blocks_queued())
  1366. {
  1367. lcd_commands_step = 4;
  1368. }
  1369. if (lcd_commands_step == 6 && !blocks_queued())
  1370. {
  1371. enquecommand_P(PSTR("G91"));
  1372. enquecommand_P(PSTR("G1 Z15 F1500"));
  1373. st_synchronize();
  1374. #ifdef SNMM
  1375. lcd_commands_step = 7;
  1376. #else
  1377. lcd_commands_step = 5;
  1378. #endif
  1379. }
  1380. }
  1381. if (lcd_commands_type == LCD_COMMAND_PID_EXTRUDER) {
  1382. char cmd1[30];
  1383. if (lcd_commands_step == 0) {
  1384. custom_message_type = 3;
  1385. custom_message_state = 1;
  1386. custom_message = true;
  1387. lcdDrawUpdate = 3;
  1388. lcd_commands_step = 3;
  1389. }
  1390. if (lcd_commands_step == 3 && !blocks_queued()) { //PID calibration
  1391. strcpy(cmd1, "M303 E0 S");
  1392. strcat(cmd1, ftostr3(pid_temp));
  1393. enquecommand(cmd1);
  1394. lcd_setstatuspgm(_i("PID cal. "));////MSG_PID_RUNNING c=20 r=1
  1395. lcd_commands_step = 2;
  1396. }
  1397. if (lcd_commands_step == 2 && pid_tuning_finished) { //saving to eeprom
  1398. pid_tuning_finished = false;
  1399. custom_message_state = 0;
  1400. lcd_setstatuspgm(_i("PID cal. finished"));////MSG_PID_FINISHED c=20 r=1
  1401. if (_Kp != 0 || _Ki != 0 || _Kd != 0) {
  1402. strcpy(cmd1, "M301 P");
  1403. strcat(cmd1, ftostr32(_Kp));
  1404. strcat(cmd1, " I");
  1405. strcat(cmd1, ftostr32(_Ki));
  1406. strcat(cmd1, " D");
  1407. strcat(cmd1, ftostr32(_Kd));
  1408. enquecommand(cmd1);
  1409. enquecommand_P(PSTR("M500"));
  1410. }
  1411. else {
  1412. SERIAL_ECHOPGM("Invalid PID cal. results. Not stored to EEPROM.");
  1413. }
  1414. display_time = millis();
  1415. lcd_commands_step = 1;
  1416. }
  1417. if ((lcd_commands_step == 1) && ((millis()- display_time)>2000)) { //calibration finished message
  1418. lcd_setstatuspgm(_T(WELCOME_MSG));
  1419. custom_message_type = 0;
  1420. custom_message = false;
  1421. pid_temp = DEFAULT_PID_TEMP;
  1422. lcd_commands_step = 0;
  1423. lcd_commands_type = 0;
  1424. }
  1425. }
  1426. }
  1427. static float count_e(float layer_heigth, float extrusion_width, float extrusion_length) {
  1428. //returns filament length in mm which needs to be extrude to form line with extrusion_length * extrusion_width * layer heigth dimensions
  1429. float extr = extrusion_length * layer_heigth * extrusion_width / (M_PI * pow(1.75, 2) / 4);
  1430. return extr;
  1431. }
  1432. static void lcd_return_to_status()
  1433. {
  1434. lcd_implementation_init(); // to maybe revive the LCD if static electricity killed it.
  1435. lcd_goto_menu(lcd_status_screen, 0, false);
  1436. menu_depth = 0;
  1437. }
  1438. void lcd_sdcard_pause() {
  1439. lcd_return_to_status();
  1440. lcd_commands_type = LCD_COMMAND_LONG_PAUSE;
  1441. }
  1442. static void lcd_sdcard_resume() {
  1443. lcd_return_to_status();
  1444. lcd_reset_alert_level(); //for fan speed error
  1445. lcd_commands_type = LCD_COMMAND_LONG_PAUSE_RESUME;
  1446. }
  1447. float move_menu_scale;
  1448. static void lcd_move_menu_axis();
  1449. /* Menu implementation */
  1450. void lcd_preheat_farm()
  1451. {
  1452. setTargetHotend0(FARM_PREHEAT_HOTEND_TEMP);
  1453. setTargetBed(FARM_PREHEAT_HPB_TEMP);
  1454. fanSpeed = 0;
  1455. lcd_return_to_status();
  1456. setWatch(); // heater sanity check timer
  1457. }
  1458. void lcd_preheat_farm_nozzle()
  1459. {
  1460. setTargetHotend0(FARM_PREHEAT_HOTEND_TEMP);
  1461. setTargetBed(0);
  1462. fanSpeed = 0;
  1463. lcd_return_to_status();
  1464. setWatch(); // heater sanity check timer
  1465. }
  1466. void lcd_preheat_pla()
  1467. {
  1468. setTargetHotend0(PLA_PREHEAT_HOTEND_TEMP);
  1469. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  1470. fanSpeed = 0;
  1471. lcd_return_to_status();
  1472. setWatch(); // heater sanity check timer
  1473. }
  1474. void lcd_preheat_abs()
  1475. {
  1476. setTargetHotend0(ABS_PREHEAT_HOTEND_TEMP);
  1477. setTargetBed(ABS_PREHEAT_HPB_TEMP);
  1478. fanSpeed = 0;
  1479. lcd_return_to_status();
  1480. setWatch(); // heater sanity check timer
  1481. }
  1482. void lcd_preheat_pp()
  1483. {
  1484. setTargetHotend0(PP_PREHEAT_HOTEND_TEMP);
  1485. setTargetBed(PP_PREHEAT_HPB_TEMP);
  1486. fanSpeed = 0;
  1487. lcd_return_to_status();
  1488. setWatch(); // heater sanity check timer
  1489. }
  1490. void lcd_preheat_pet()
  1491. {
  1492. setTargetHotend0(PET_PREHEAT_HOTEND_TEMP);
  1493. setTargetBed(PET_PREHEAT_HPB_TEMP);
  1494. fanSpeed = 0;
  1495. lcd_return_to_status();
  1496. setWatch(); // heater sanity check timer
  1497. }
  1498. void lcd_preheat_hips()
  1499. {
  1500. setTargetHotend0(HIPS_PREHEAT_HOTEND_TEMP);
  1501. setTargetBed(HIPS_PREHEAT_HPB_TEMP);
  1502. fanSpeed = 0;
  1503. lcd_return_to_status();
  1504. setWatch(); // heater sanity check timer
  1505. }
  1506. void lcd_preheat_flex()
  1507. {
  1508. setTargetHotend0(FLEX_PREHEAT_HOTEND_TEMP);
  1509. setTargetBed(FLEX_PREHEAT_HPB_TEMP);
  1510. fanSpeed = 0;
  1511. lcd_return_to_status();
  1512. setWatch(); // heater sanity check timer
  1513. }
  1514. void lcd_cooldown()
  1515. {
  1516. setTargetHotend0(0);
  1517. setTargetHotend1(0);
  1518. setTargetHotend2(0);
  1519. setTargetBed(0);
  1520. fanSpeed = 0;
  1521. lcd_return_to_status();
  1522. }
  1523. static void lcd_menu_extruder_info()
  1524. {
  1525. //|01234567890123456789|
  1526. //|Nozzle FAN: RPM|
  1527. //|Print FAN: RPM|
  1528. //|Fil. Xd: Yd: |
  1529. //|Int: Shut: |
  1530. //----------------------
  1531. int fan_speed_RPM[2];
  1532. // Display Nozzle fan RPM
  1533. fan_speed_RPM[0] = 60*fan_speed[0];
  1534. fan_speed_RPM[1] = 60*fan_speed[1];
  1535. #ifdef PAT9125
  1536. // Display X and Y difference from Filament sensor
  1537. // Display Light intensity from Filament sensor
  1538. // Frame_Avg register represents the average brightness of all pixels within a frame (324 pixels). This
  1539. // value ranges from 0(darkest) to 255(brightest).
  1540. // Display LASER shutter time from Filament sensor
  1541. // Shutter register is an index of LASER shutter time. It is automatically controlled by the chip's internal
  1542. // auto-exposure algorithm. When the chip is tracking on a good reflection surface, the Shutter is small.
  1543. // When the chip is tracking on a poor reflection surface, the Shutter is large. Value ranges from 0 to 46.
  1544. pat9125_update();
  1545. lcd_printf_P(_N(
  1546. ESC_H(0,0)
  1547. "Nozzle FAN: %4d RPM\n"
  1548. "Print FAN: %4d RPM\n"
  1549. "Fil. Xd:%3d Yd:%3d\n"
  1550. "Int: %3d Shut: %3d\n"
  1551. ),
  1552. fan_speed_RPM[0],
  1553. fan_speed_RPM[1],
  1554. pat9125_x, pat9125_y,
  1555. pat9125_b, pat9125_s
  1556. );
  1557. #else //PAT9125
  1558. printf_P(_N(
  1559. ESC_H(0,0)
  1560. "Nozzle FAN: %4d RPM\n"
  1561. "Print FAN: %4d RPM\n"
  1562. ),
  1563. fan_speed_RPM[0],
  1564. fan_speed_RPM[1]
  1565. );
  1566. #endif //PAT9125
  1567. menu_back_if_clicked();
  1568. }
  1569. #if defined(TMC2130) && defined(PAT9125)
  1570. static void lcd_menu_fails_stats_total()
  1571. {
  1572. //01234567890123456789
  1573. //Total failures
  1574. // Power failures 000
  1575. // Filam. runouts 000
  1576. // Crash X 000 Y 000
  1577. //////////////////////
  1578. uint16_t power = eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT);
  1579. uint16_t filam = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT);
  1580. uint16_t crashX = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT);
  1581. uint16_t crashY = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT);
  1582. lcd_printf_P(PSTR(ESC_H(0,0) "Total failures" ESC_H(1,1) "Power failures %-3d" ESC_H(1,2) "Filam. runouts %-3d" ESC_H(1,3) "Crash X %-3d Y %-3d"), power, filam, crashX, crashY);
  1583. menu_back_if_clicked_fb();
  1584. }
  1585. static void lcd_menu_fails_stats_print()
  1586. {
  1587. //01234567890123456789
  1588. //Last print failures
  1589. // Power failures 000
  1590. // Filam. runouts 000
  1591. // Crash X 000 Y 000
  1592. //////////////////////
  1593. uint8_t power = eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT);
  1594. uint8_t filam = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1595. uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X);
  1596. uint8_t crashY = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y);
  1597. lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Power failures %-3d" ESC_H(1,2) "Filam. runouts %-3d" ESC_H(1,3) "Crash X %-3d Y %-3d"), power, filam, crashX, crashY);
  1598. menu_back_if_clicked_fb();
  1599. }
  1600. /**
  1601. * @brief Open fail statistics menu
  1602. *
  1603. * This version of function is used, when there is filament sensor,
  1604. * power failure and crash detection.
  1605. * There are Last print and Total menu items.
  1606. */
  1607. static void lcd_menu_fails_stats()
  1608. {
  1609. MENU_BEGIN();
  1610. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1611. MENU_ITEM_SUBMENU_P(PSTR("Last print"), lcd_menu_fails_stats_print);
  1612. MENU_ITEM_SUBMENU_P(PSTR("Total"), lcd_menu_fails_stats_total);
  1613. MENU_END();
  1614. }
  1615. #elif defined(PAT9125)
  1616. /**
  1617. * @brief Print last print and total filament run outs
  1618. *
  1619. * This version of function is used, when there is filament sensor,
  1620. * but no other sensors (e.g. power failure, crash detection).
  1621. *
  1622. * Example screen:
  1623. * @code
  1624. * 01234567890123456789
  1625. * Last print failures
  1626. * Filam. runouts 0
  1627. * Total failures
  1628. * Filam. runouts 5
  1629. * @endcode
  1630. */
  1631. static void lcd_menu_fails_stats()
  1632. {
  1633. uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT);
  1634. uint16_t filamentTotal = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT);
  1635. lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Filam. runouts %-3d" ESC_H(0,2) "Total failures" ESC_H(1,3) "Filam. runouts %-3d"), filamentLast, filamentTotal);
  1636. menu_back_if_clicked();
  1637. }
  1638. #endif //TMC2130
  1639. #ifdef DEBUG_BUILD
  1640. #ifdef DEBUG_STACK_MONITOR
  1641. extern uint16_t SP_min;
  1642. extern char* __malloc_heap_start;
  1643. extern char* __malloc_heap_end;
  1644. #endif //DEBUG_STACK_MONITOR
  1645. static void lcd_menu_debug()
  1646. {
  1647. #ifdef DEBUG_STACK_MONITOR
  1648. lcd_printf_P(PSTR(ESC_H(1,1) "RAM statistics" ESC_H(5,1) "SP_min: 0x%04x" ESC_H(1,2) "heap_start: 0x%04x" ESC_H(3,3) "heap_end: 0x%04x"), SP_min, __malloc_heap_start, __malloc_heap_end);
  1649. #endif //DEBUG_STACK_MONITOR
  1650. menu_back_if_clicked_fb();
  1651. }
  1652. #endif /* DEBUG_BUILD */
  1653. static void lcd_menu_temperatures()
  1654. {
  1655. lcd_printf_P(PSTR(ESC_H(1,0) "Nozzle: %d%c" ESC_H(1,1) "Bed: %d%c"), (int)current_temperature[0], '\x01', (int)current_temperature_bed, '\x01');
  1656. #ifdef AMBIENT_THERMISTOR
  1657. lcd_printf_P(PSTR(ESC_H(1,2) "Ambient: %d%c" ESC_H(1,3) "PINDA: %d%c"), (int)current_temperature_ambient, '\x01', (int)current_temperature_pinda, '\x01');
  1658. #else //AMBIENT_THERMISTOR
  1659. lcd_printf_P(PSTR(ESC_H(1,2) "PINDA: %d%c"), (int)current_temperature_pinda, '\x01');
  1660. #endif //AMBIENT_THERMISTOR
  1661. menu_back_if_clicked();
  1662. }
  1663. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN)
  1664. #define VOLT_DIV_R1 10000
  1665. #define VOLT_DIV_R2 2370
  1666. #define VOLT_DIV_FAC ((float)VOLT_DIV_R2 / (VOLT_DIV_R2 + VOLT_DIV_R1))
  1667. #define VOLT_DIV_REF 5
  1668. static void lcd_menu_voltages()
  1669. {
  1670. float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1671. // float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC;
  1672. // lcd_printf_P(PSTR(ESC_H(1,1)"PWR: %d.%01dV" ESC_H(1,2)"BED: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr)), (int)volt_bed, (int)(10*fabs(volt_bed - (int)volt_bed)));
  1673. lcd_printf_P(PSTR( ESC_H(1,1)"PWR: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr))) ;
  1674. menu_back_if_clicked();
  1675. }
  1676. #endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN
  1677. #ifdef TMC2130
  1678. static void lcd_menu_belt_status()
  1679. {
  1680. lcd_printf_P(PSTR(ESC_H(1,0) "Belt status" ESC_H(2,1) "X %d" ESC_H(2,2) "Y %d" ), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X)), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y)));
  1681. menu_back_if_clicked();
  1682. }
  1683. #endif //TMC2130
  1684. extern void stop_and_save_print_to_ram(float z_move, float e_move);
  1685. extern void restore_print_from_ram_and_continue(float e_move);
  1686. static void lcd_menu_test_save()
  1687. {
  1688. stop_and_save_print_to_ram(10, -0.8);
  1689. }
  1690. static void lcd_menu_test_restore()
  1691. {
  1692. restore_print_from_ram_and_continue(0.8);
  1693. }
  1694. static void lcd_preheat_menu()
  1695. {
  1696. MENU_BEGIN();
  1697. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1698. if (farm_mode) {
  1699. MENU_ITEM_FUNCTION_P(PSTR("farm - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FARM_PREHEAT_HPB_TEMP)), lcd_preheat_farm);
  1700. MENU_ITEM_FUNCTION_P(PSTR("nozzle - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/0"), lcd_preheat_farm_nozzle);
  1701. MENU_ITEM_FUNCTION_P(_T(MSG_COOLDOWN), lcd_cooldown);
  1702. MENU_ITEM_FUNCTION_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)), lcd_preheat_abs);
  1703. } else {
  1704. MENU_ITEM_FUNCTION_P(PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)), lcd_preheat_pla);
  1705. MENU_ITEM_FUNCTION_P(PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)), lcd_preheat_pet);
  1706. MENU_ITEM_FUNCTION_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)), lcd_preheat_abs);
  1707. MENU_ITEM_FUNCTION_P(PSTR("HIPS - " STRINGIFY(HIPS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(HIPS_PREHEAT_HPB_TEMP)), lcd_preheat_hips);
  1708. MENU_ITEM_FUNCTION_P(PSTR("PP - " STRINGIFY(PP_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PP_PREHEAT_HPB_TEMP)), lcd_preheat_pp);
  1709. MENU_ITEM_FUNCTION_P(PSTR("FLEX - " STRINGIFY(FLEX_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FLEX_PREHEAT_HPB_TEMP)), lcd_preheat_flex);
  1710. MENU_ITEM_FUNCTION_P(_T(MSG_COOLDOWN), lcd_cooldown);
  1711. }
  1712. MENU_END();
  1713. }
  1714. static void lcd_support_menu()
  1715. {
  1716. if (menuData.supportMenu.status == 0 || lcdDrawUpdate == 2) {
  1717. // Menu was entered or SD card status has changed (plugged in or removed).
  1718. // Initialize its status.
  1719. menuData.supportMenu.status = 1;
  1720. menuData.supportMenu.is_flash_air = card.ToshibaFlashAir_isEnabled() && card.ToshibaFlashAir_GetIP(menuData.supportMenu.ip);
  1721. if (menuData.supportMenu.is_flash_air)
  1722. sprintf_P(menuData.supportMenu.ip_str, PSTR("%d.%d.%d.%d"),
  1723. menuData.supportMenu.ip[0], menuData.supportMenu.ip[1],
  1724. menuData.supportMenu.ip[2], menuData.supportMenu.ip[3]);
  1725. } else if (menuData.supportMenu.is_flash_air &&
  1726. menuData.supportMenu.ip[0] == 0 && menuData.supportMenu.ip[1] == 0 &&
  1727. menuData.supportMenu.ip[2] == 0 && menuData.supportMenu.ip[3] == 0 &&
  1728. ++ menuData.supportMenu.status == 16) {
  1729. // Waiting for the FlashAir card to get an IP address from a router. Force an update.
  1730. menuData.supportMenu.status = 0;
  1731. }
  1732. MENU_BEGIN();
  1733. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  1734. MENU_ITEM_BACK_P(PSTR("Firmware:"));
  1735. MENU_ITEM_BACK_P(PSTR(" " FW_VERSION_FULL));
  1736. #if (FW_DEV_VERSION != FW_VERSION_GOLD) && (FW_DEV_VERSION != FW_VERSION_RC)
  1737. MENU_ITEM_BACK_P(PSTR(" repo " FW_REPOSITORY));
  1738. #endif
  1739. // Ideally this block would be optimized out by the compiler.
  1740. /* const uint8_t fw_string_len = strlen_P(FW_VERSION_STR_P());
  1741. if (fw_string_len < 6) {
  1742. MENU_ITEM_BACK_P(PSTR(MSG_FW_VERSION " - " FW_version));
  1743. } else {
  1744. MENU_ITEM_BACK_P(PSTR("FW - " FW_version));
  1745. }*/
  1746. MENU_ITEM_BACK_P(_i("prusa3d.com"));////MSG_PRUSA3D c=0 r=0
  1747. MENU_ITEM_BACK_P(_i("forum.prusa3d.com"));////MSG_PRUSA3D_FORUM c=0 r=0
  1748. MENU_ITEM_BACK_P(_i("howto.prusa3d.com"));////MSG_PRUSA3D_HOWTO c=0 r=0
  1749. MENU_ITEM_BACK_P(PSTR("------------"));
  1750. MENU_ITEM_BACK_P(PSTR(FILAMENT_SIZE));
  1751. MENU_ITEM_BACK_P(PSTR(ELECTRONICS));
  1752. MENU_ITEM_BACK_P(PSTR(NOZZLE_TYPE));
  1753. MENU_ITEM_BACK_P(PSTR("------------"));
  1754. MENU_ITEM_BACK_P(_i("Date:"));////MSG_DATE c=17 r=1
  1755. MENU_ITEM_BACK_P(PSTR(__DATE__));
  1756. // Show the FlashAir IP address, if the card is available.
  1757. if (menuData.supportMenu.is_flash_air) {
  1758. MENU_ITEM_BACK_P(PSTR("------------"));
  1759. MENU_ITEM_BACK_P(PSTR("FlashAir IP Addr:"));
  1760. ///! MENU_ITEM(back_RAM, menuData.supportMenu.ip_str, 0);
  1761. }
  1762. #ifndef MK1BP
  1763. MENU_ITEM_BACK_P(PSTR("------------"));
  1764. MENU_ITEM_SUBMENU_P(_i("XYZ cal. details"), lcd_menu_xyz_y_min);////MSG_XYZ_DETAILS c=19 r=1
  1765. MENU_ITEM_SUBMENU_P(_i("Extruder info"), lcd_menu_extruder_info);////MSG_INFO_EXTRUDER c=15 r=1
  1766. #ifdef TMC2130
  1767. MENU_ITEM_SUBMENU_P(_i("Belt status"), lcd_menu_belt_status);////MSG_MENU_BELT_STATUS c=15 r=1
  1768. #endif //TMC2130
  1769. MENU_ITEM_SUBMENU_P(_i("Temperatures"), lcd_menu_temperatures);////MSG_MENU_TEMPERATURES c=15 r=1
  1770. #if defined (VOLT_BED_PIN) || defined (VOLT_PWR_PIN)
  1771. MENU_ITEM_SUBMENU_P(_i("Voltages"), lcd_menu_voltages);////MSG_MENU_VOLTAGES c=15 r=1
  1772. #endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN
  1773. #ifdef DEBUG_BUILD
  1774. MENU_ITEM_SUBMENU_P(PSTR("Debug"), lcd_menu_debug);
  1775. #endif /* DEBUG_BUILD */
  1776. #endif //MK1BP
  1777. MENU_END();
  1778. }
  1779. void lcd_set_fan_check() {
  1780. fans_check_enabled = !fans_check_enabled;
  1781. eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED, fans_check_enabled);
  1782. }
  1783. void lcd_set_filament_autoload() {
  1784. fautoload_set(!filament_autoload_enabled);
  1785. }
  1786. void lcd_unLoadFilament()
  1787. {
  1788. if (degHotend0() > EXTRUDE_MINTEMP) {
  1789. enquecommand_P(PSTR("M702")); //unload filament
  1790. } else {
  1791. lcd_implementation_clear();
  1792. lcd.setCursor(0, 0);
  1793. lcd_printPGM(_T(MSG_ERROR));
  1794. lcd.setCursor(0, 2);
  1795. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  1796. delay(2000);
  1797. lcd_implementation_clear();
  1798. }
  1799. menu_back();
  1800. }
  1801. void lcd_change_filament() {
  1802. lcd_implementation_clear();
  1803. lcd.setCursor(0, 1);
  1804. lcd_printPGM(_i("Changing filament!"));////MSG_CHANGING_FILAMENT c=20 r=0
  1805. }
  1806. void lcd_wait_interact() {
  1807. lcd_implementation_clear();
  1808. lcd.setCursor(0, 1);
  1809. #ifdef SNMM
  1810. lcd_printPGM(_i("Prepare new filament"));////MSG_PREPARE_FILAMENT c=20 r=1
  1811. #else
  1812. lcd_printPGM(_i("Insert filament"));////MSG_INSERT_FILAMENT c=20 r=0
  1813. #endif
  1814. lcd.setCursor(0, 2);
  1815. lcd_printPGM(_i("and press the knob"));////MSG_PRESS c=20 r=0
  1816. }
  1817. void lcd_change_success() {
  1818. lcd_implementation_clear();
  1819. lcd.setCursor(0, 2);
  1820. lcd_printPGM(_i("Change success!"));////MSG_CHANGE_SUCCESS c=0 r=0
  1821. }
  1822. void lcd_loading_color() {
  1823. lcd_implementation_clear();
  1824. lcd.setCursor(0, 0);
  1825. lcd_printPGM(_i("Loading color"));////MSG_LOADING_COLOR c=0 r=0
  1826. lcd.setCursor(0, 2);
  1827. lcd_printPGM(_T(MSG_PLEASE_WAIT));
  1828. for (int i = 0; i < 20; i++) {
  1829. lcd.setCursor(i, 3);
  1830. lcd.print(".");
  1831. for (int j = 0; j < 10 ; j++) {
  1832. manage_heater();
  1833. manage_inactivity(true);
  1834. delay(85);
  1835. }
  1836. }
  1837. }
  1838. void lcd_loading_filament() {
  1839. lcd_implementation_clear();
  1840. lcd.setCursor(0, 0);
  1841. lcd_printPGM(_T(MSG_LOADING_FILAMENT));
  1842. lcd.setCursor(0, 2);
  1843. lcd_printPGM(_T(MSG_PLEASE_WAIT));
  1844. for (int i = 0; i < 20; i++) {
  1845. lcd.setCursor(i, 3);
  1846. lcd.print(".");
  1847. for (int j = 0; j < 10 ; j++) {
  1848. manage_heater();
  1849. manage_inactivity(true);
  1850. #ifdef SNMM
  1851. delay(153);
  1852. #else
  1853. delay(137);
  1854. #endif
  1855. }
  1856. }
  1857. }
  1858. void lcd_alright() {
  1859. int enc_dif = 0;
  1860. int cursor_pos = 1;
  1861. lcd_implementation_clear();
  1862. lcd.setCursor(0, 0);
  1863. lcd_printPGM(_i("Changed correctly?"));////MSG_CORRECTLY c=20 r=0
  1864. lcd.setCursor(1, 1);
  1865. lcd_printPGM(_T(MSG_YES));
  1866. lcd.setCursor(1, 2);
  1867. lcd_printPGM(_i("Filament not loaded"));////MSG_NOT_LOADED c=19 r=0
  1868. lcd.setCursor(1, 3);
  1869. lcd_printPGM(_i("Color not correct"));////MSG_NOT_COLOR c=0 r=0
  1870. lcd.setCursor(0, 1);
  1871. lcd.print(">");
  1872. enc_dif = encoderDiff;
  1873. while (lcd_change_fil_state == 0) {
  1874. manage_heater();
  1875. manage_inactivity(true);
  1876. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1877. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1878. if (enc_dif > encoderDiff ) {
  1879. cursor_pos --;
  1880. }
  1881. if (enc_dif < encoderDiff ) {
  1882. cursor_pos ++;
  1883. }
  1884. if (cursor_pos > 3) {
  1885. cursor_pos = 3;
  1886. }
  1887. if (cursor_pos < 1) {
  1888. cursor_pos = 1;
  1889. }
  1890. lcd.setCursor(0, 1);
  1891. lcd.print(" ");
  1892. lcd.setCursor(0, 2);
  1893. lcd.print(" ");
  1894. lcd.setCursor(0, 3);
  1895. lcd.print(" ");
  1896. lcd.setCursor(0, cursor_pos);
  1897. lcd.print(">");
  1898. enc_dif = encoderDiff;
  1899. delay(100);
  1900. }
  1901. }
  1902. if (lcd_clicked()) {
  1903. lcd_change_fil_state = cursor_pos;
  1904. delay(500);
  1905. }
  1906. };
  1907. lcd_implementation_clear();
  1908. lcd_return_to_status();
  1909. }
  1910. #ifdef PAT9125
  1911. static void lcd_menu_AutoLoadFilament()
  1912. {
  1913. if (degHotend0() > EXTRUDE_MINTEMP)
  1914. {
  1915. uint8_t nlines;
  1916. lcd_display_message_fullscreen_nonBlocking_P(_i("Autoloading filament is active, just press the knob and insert filament..."),nlines);////MSG_AUTOLOADING_ENABLED c=20 r=4
  1917. }
  1918. else
  1919. {
  1920. ShortTimer* ptimer = (ShortTimer*)&(menuData.autoLoadFilamentMenu.dummy);
  1921. if (!ptimer->running()) ptimer->start();
  1922. lcd.setCursor(0, 0);
  1923. lcd_printPGM(_T(MSG_ERROR));
  1924. lcd.setCursor(0, 2);
  1925. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  1926. if (ptimer->expired(2000ul)) menu_back();
  1927. }
  1928. menu_back_if_clicked();
  1929. }
  1930. #endif //PAT9125
  1931. static void lcd_LoadFilament()
  1932. {
  1933. if (degHotend0() > EXTRUDE_MINTEMP)
  1934. {
  1935. custom_message = true;
  1936. loading_flag = true;
  1937. enquecommand_P(PSTR("M701")); //load filament
  1938. SERIAL_ECHOLN("Loading filament");
  1939. lcd_return_to_status();
  1940. }
  1941. else
  1942. {
  1943. lcd_implementation_clear();
  1944. lcd.setCursor(0, 0);
  1945. lcd_printPGM(_T(MSG_ERROR));
  1946. lcd.setCursor(0, 2);
  1947. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  1948. delay(2000);
  1949. lcd_implementation_clear();
  1950. }
  1951. }
  1952. void lcd_menu_statistics()
  1953. {
  1954. if (IS_SD_PRINTING)
  1955. {
  1956. int _met = total_filament_used / 100000;
  1957. int _cm = (total_filament_used - (_met * 100000)) / 10;
  1958. int _t = (millis() - starttime) / 1000;
  1959. int _h = _t / 3600;
  1960. int _m = (_t - (_h * 3600)) / 60;
  1961. int _s = _t - ((_h * 3600) + (_m * 60));
  1962. //|01234567890123456789|
  1963. //|Filament used: |
  1964. //| 000m 00.000cm |
  1965. //|Print time: |
  1966. //| 00h 00m 00s |
  1967. //----------------------
  1968. lcd_printf_P(_N(
  1969. ESC_2J
  1970. "%S:"
  1971. ESC_H(6,1) "%8.2f m\n"
  1972. "%S :"
  1973. ESC_H(8,3) "%2dh %02dm %02d"
  1974. ),
  1975. _i("Filament used"),
  1976. _met, _cm,
  1977. _i("Print time"),
  1978. _h, _m, _s
  1979. );
  1980. menu_back_if_clicked_fb();
  1981. }
  1982. else
  1983. {
  1984. unsigned long _filament = eeprom_read_dword((uint32_t *)EEPROM_FILAMENTUSED);
  1985. unsigned long _time = eeprom_read_dword((uint32_t *)EEPROM_TOTALTIME); //in minutes
  1986. uint8_t _hours, _minutes;
  1987. uint32_t _days;
  1988. float _filament_m = (float)_filament/100;
  1989. // int _filament_km = (_filament >= 100000) ? _filament / 100000 : 0;
  1990. // if (_filament_km > 0) _filament_m = _filament - (_filament_km * 100000);
  1991. _days = _time / 1440;
  1992. _hours = (_time - (_days * 1440)) / 60;
  1993. _minutes = _time - ((_days * 1440) + (_hours * 60));
  1994. //|01234567890123456789|
  1995. //|Total filament : |
  1996. //| 000.00 m |
  1997. //|Total print time : |
  1998. //| 00d :00h :00 m |
  1999. //----------------------
  2000. lcd_printf_P(_N(
  2001. ESC_2J
  2002. "%S :"
  2003. ESC_H(9,1) "%8.2f m\n"
  2004. "%S :\n"
  2005. "%7ldd :%2hhdh :%02hhd m"
  2006. ),
  2007. _i("Total filament"),
  2008. _filament_m,
  2009. _i("Total print time"),
  2010. _days, _hours, _minutes
  2011. );
  2012. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2013. while (!lcd_clicked())
  2014. {
  2015. manage_heater();
  2016. manage_inactivity(true);
  2017. delay(100);
  2018. }
  2019. KEEPALIVE_STATE(NOT_BUSY);
  2020. lcd_quick_feedback();
  2021. menu_back();
  2022. }
  2023. }
  2024. static void _lcd_move(const char *name, int axis, int min, int max) {
  2025. if (!menuData._lcd_moveMenu.initialized)
  2026. {
  2027. menuData._lcd_moveMenu.endstopsEnabledPrevious = enable_endstops(false);
  2028. menuData._lcd_moveMenu.initialized = true;
  2029. }
  2030. if (encoderPosition != 0) {
  2031. refresh_cmd_timeout();
  2032. if (! planner_queue_full()) {
  2033. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  2034. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  2035. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  2036. encoderPosition = 0;
  2037. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  2038. 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);
  2039. lcdDrawUpdate = 1;
  2040. }
  2041. }
  2042. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  2043. if (menuExiting || LCD_CLICKED) (void)enable_endstops(menuData._lcd_moveMenu.endstopsEnabledPrevious);
  2044. if (LCD_CLICKED) menu_back();
  2045. }
  2046. static void lcd_move_e()
  2047. {
  2048. if (degHotend0() > EXTRUDE_MINTEMP) {
  2049. if (encoderPosition != 0)
  2050. {
  2051. refresh_cmd_timeout();
  2052. if (! planner_queue_full()) {
  2053. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  2054. encoderPosition = 0;
  2055. 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);
  2056. lcdDrawUpdate = 1;
  2057. }
  2058. }
  2059. if (lcdDrawUpdate)
  2060. {
  2061. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  2062. }
  2063. if (LCD_CLICKED) menu_back();
  2064. }
  2065. else {
  2066. lcd_implementation_clear();
  2067. lcd.setCursor(0, 0);
  2068. lcd_printPGM(_T(MSG_ERROR));
  2069. lcd.setCursor(0, 2);
  2070. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  2071. delay(2000);
  2072. lcd_return_to_status();
  2073. }
  2074. }
  2075. /**
  2076. * @brief Show measured Y distance of front calibration points from Y_MIN_POS
  2077. *
  2078. * If those points are detected too close to edge of reachable area, their confidence is lowered.
  2079. * This functionality is applied more often for MK2 printers.
  2080. */
  2081. static void lcd_menu_xyz_y_min()
  2082. {
  2083. //|01234567890123456789|
  2084. //|Y distance from min:|
  2085. //|--------------------|
  2086. //|Left: N/A |
  2087. //|Right: N/A |
  2088. //----------------------
  2089. float distanceMin[2];
  2090. count_xyz_details(distanceMin);
  2091. lcd_printf_P(_N(
  2092. ESC_H(0,0)
  2093. "%S:\n"
  2094. "%S\n"
  2095. "%S:\n"
  2096. "%S:"
  2097. ),
  2098. _i("Y distance from min"),
  2099. separator,
  2100. _i("Left"),
  2101. _i("Right")
  2102. );
  2103. for (uint8_t i = 0; i < 2; i++)
  2104. {
  2105. lcd.setCursor(11,2+i);
  2106. if (distanceMin[i] >= 200) lcd_puts_P(_N("N/A"));
  2107. else lcd_printf_P(_N("%6.2fmm"), distanceMin[i]);
  2108. }
  2109. if (lcd_clicked())
  2110. lcd_goto_menu(lcd_menu_xyz_skew);
  2111. }
  2112. /**
  2113. * @brief Show measured axis skewness
  2114. */
  2115. float _deg(float rad)
  2116. {
  2117. return rad * 180 / M_PI;
  2118. }
  2119. static void lcd_menu_xyz_skew()
  2120. {
  2121. //|01234567890123456789|
  2122. //|Measured skew: N/A |
  2123. //|--------------------|
  2124. //|Slight skew: 0.12°|
  2125. //|Severe skew: 0.25°|
  2126. //----------------------
  2127. float angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW));
  2128. lcd_printf_P(_N(
  2129. ESC_H(0,0)
  2130. "%S:\n"
  2131. "%S\n"
  2132. "%S: %5.2f\x01\n"
  2133. "%S: %5.2f\x01"
  2134. ),
  2135. _i("Measured skew"),
  2136. separator,
  2137. _i("Slight skew"), _deg(bed_skew_angle_mild),
  2138. _i("Severe skew"), _deg(bed_skew_angle_extreme)
  2139. );
  2140. if (angleDiff < 100)
  2141. lcd_printf_P(_N(ESC_H(15,0)"%4.2f\x01"), _deg(angleDiff));
  2142. else
  2143. lcd_puts_P(_N(ESC_H(15,0)"N/A"));
  2144. if (lcd_clicked())
  2145. lcd_goto_menu(lcd_menu_xyz_offset);
  2146. }
  2147. /**
  2148. * @brief Show measured bed offset from expected position
  2149. */
  2150. static void lcd_menu_xyz_offset()
  2151. {
  2152. lcd.setCursor(0,0);
  2153. lcd_printPGM(_i("[0;0] point offset"));////MSG_MEASURED_OFFSET c=0 r=0
  2154. lcd_print_at_PGM(0, 1, separator);
  2155. lcd_print_at_PGM(0, 2, PSTR("X"));
  2156. lcd_print_at_PGM(0, 3, PSTR("Y"));
  2157. float vec_x[2];
  2158. float vec_y[2];
  2159. float cntr[2];
  2160. world2machine_read_valid(vec_x, vec_y, cntr);
  2161. for (int i = 0; i < 2; i++)
  2162. {
  2163. lcd_print_at_PGM(11, i + 2, PSTR(""));
  2164. lcd.print(cntr[i]);
  2165. lcd_print_at_PGM((cntr[i] < 0) ? 17 : 16, i + 2, PSTR("mm"));
  2166. }
  2167. menu_back_if_clicked();
  2168. }
  2169. // Save a single axis babystep value.
  2170. void EEPROM_save_B(int pos, int* value)
  2171. {
  2172. union Data data;
  2173. data.value = *value;
  2174. eeprom_update_byte((unsigned char*)pos, data.b[0]);
  2175. eeprom_update_byte((unsigned char*)pos + 1, data.b[1]);
  2176. }
  2177. // Read a single axis babystep value.
  2178. void EEPROM_read_B(int pos, int* value)
  2179. {
  2180. union Data data;
  2181. data.b[0] = eeprom_read_byte((unsigned char*)pos);
  2182. data.b[1] = eeprom_read_byte((unsigned char*)pos + 1);
  2183. *value = data.value;
  2184. }
  2185. static void lcd_move_x() {
  2186. _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS);
  2187. }
  2188. static void lcd_move_y() {
  2189. _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  2190. }
  2191. static void lcd_move_z() {
  2192. _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  2193. }
  2194. /**
  2195. * @brief Adjust first layer offset from bed if axis is Z_AXIS
  2196. *
  2197. * If menu is left (button pushed or timed out), value is stored to EEPROM and
  2198. * if the axis is Z_AXIS, CALIBRATION_STATUS_CALIBRATED is also stored.
  2199. * Purpose of this function for other axis then Z is unknown.
  2200. *
  2201. * @param axis AxisEnum X_AXIS Y_AXIS Z_AXIS
  2202. * other value leads to storing Z_AXIS
  2203. * @param msg text to be displayed
  2204. */
  2205. static void _lcd_babystep(int axis, const char *msg)
  2206. {
  2207. if (menuData.babyStep.status == 0) {
  2208. // Menu was entered.
  2209. // Initialize its status.
  2210. menuData.babyStep.status = 1;
  2211. check_babystep();
  2212. EEPROM_read_B(EEPROM_BABYSTEP_X, &menuData.babyStep.babystepMem[0]);
  2213. EEPROM_read_B(EEPROM_BABYSTEP_Y, &menuData.babyStep.babystepMem[1]);
  2214. EEPROM_read_B(EEPROM_BABYSTEP_Z, &menuData.babyStep.babystepMem[2]);
  2215. menuData.babyStep.babystepMemMM[0] = menuData.babyStep.babystepMem[0]/axis_steps_per_unit[X_AXIS];
  2216. menuData.babyStep.babystepMemMM[1] = menuData.babyStep.babystepMem[1]/axis_steps_per_unit[Y_AXIS];
  2217. menuData.babyStep.babystepMemMM[2] = menuData.babyStep.babystepMem[2]/axis_steps_per_unit[Z_AXIS];
  2218. lcdDrawUpdate = 1;
  2219. //SERIAL_ECHO("Z baby step: ");
  2220. //SERIAL_ECHO(menuData.babyStep.babystepMem[2]);
  2221. // Wait 90 seconds before closing the live adjust dialog.
  2222. lcd_timeoutToStatus = millis() + 90000;
  2223. }
  2224. if (encoderPosition != 0)
  2225. {
  2226. if (homing_flag) encoderPosition = 0;
  2227. menuData.babyStep.babystepMem[axis] += (int)encoderPosition;
  2228. if (axis == 2) {
  2229. if (menuData.babyStep.babystepMem[axis] < Z_BABYSTEP_MIN) menuData.babyStep.babystepMem[axis] = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
  2230. else if (menuData.babyStep.babystepMem[axis] > Z_BABYSTEP_MAX) menuData.babyStep.babystepMem[axis] = Z_BABYSTEP_MAX; //0
  2231. else {
  2232. CRITICAL_SECTION_START
  2233. babystepsTodo[axis] += (int)encoderPosition;
  2234. CRITICAL_SECTION_END
  2235. }
  2236. }
  2237. menuData.babyStep.babystepMemMM[axis] = menuData.babyStep.babystepMem[axis]/axis_steps_per_unit[axis];
  2238. delay(50);
  2239. encoderPosition = 0;
  2240. lcdDrawUpdate = 1;
  2241. }
  2242. if (lcdDrawUpdate)
  2243. lcd_implementation_drawedit_2(msg, ftostr13ns(menuData.babyStep.babystepMemMM[axis]));
  2244. if (LCD_CLICKED || menuExiting) {
  2245. // Only update the EEPROM when leaving the menu.
  2246. EEPROM_save_B(
  2247. (axis == X_AXIS) ? EEPROM_BABYSTEP_X : ((axis == Y_AXIS) ? EEPROM_BABYSTEP_Y : EEPROM_BABYSTEP_Z),
  2248. &menuData.babyStep.babystepMem[axis]);
  2249. if(Z_AXIS == axis) calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  2250. }
  2251. if (LCD_CLICKED) menu_back();
  2252. }
  2253. static void lcd_babystep_x() {
  2254. _lcd_babystep(X_AXIS, (_i("Babystepping X")));////MSG_BABYSTEPPING_X c=0 r=0
  2255. }
  2256. static void lcd_babystep_y() {
  2257. _lcd_babystep(Y_AXIS, (_i("Babystepping Y")));////MSG_BABYSTEPPING_Y c=0 r=0
  2258. }
  2259. static void lcd_babystep_z() {
  2260. _lcd_babystep(Z_AXIS, (_i("Adjusting Z")));////MSG_BABYSTEPPING_Z c=20 r=0
  2261. }
  2262. static void lcd_adjust_bed();
  2263. static void lcd_adjust_bed_reset()
  2264. {
  2265. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2266. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  2267. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2268. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2269. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  2270. menuData.adjustBed.status = 0;
  2271. }
  2272. void adjust_bed_reset() {
  2273. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2274. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT, 0);
  2275. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  2276. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  2277. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR, 0);
  2278. menuData.adjustBed.left = menuData.adjustBed.left2 = 0;
  2279. menuData.adjustBed.right = menuData.adjustBed.right2 = 0;
  2280. menuData.adjustBed.front = menuData.adjustBed.front2 = 0;
  2281. menuData.adjustBed.rear = menuData.adjustBed.rear2 = 0;
  2282. }
  2283. #define BED_ADJUSTMENT_UM_MAX 50
  2284. static void lcd_adjust_bed()
  2285. {
  2286. if (menuData.adjustBed.status == 0) {
  2287. // Menu was entered.
  2288. // Initialize its status.
  2289. menuData.adjustBed.status = 1;
  2290. bool valid = false;
  2291. menuData.adjustBed.left = menuData.adjustBed.left2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT);
  2292. menuData.adjustBed.right = menuData.adjustBed.right2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT);
  2293. menuData.adjustBed.front = menuData.adjustBed.front2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT);
  2294. menuData.adjustBed.rear = menuData.adjustBed.rear2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR);
  2295. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1 &&
  2296. menuData.adjustBed.left >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.left <= BED_ADJUSTMENT_UM_MAX &&
  2297. menuData.adjustBed.right >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.right <= BED_ADJUSTMENT_UM_MAX &&
  2298. menuData.adjustBed.front >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.front <= BED_ADJUSTMENT_UM_MAX &&
  2299. menuData.adjustBed.rear >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.rear <= BED_ADJUSTMENT_UM_MAX)
  2300. valid = true;
  2301. if (! valid) {
  2302. // Reset the values: simulate an edit.
  2303. menuData.adjustBed.left2 = 0;
  2304. menuData.adjustBed.right2 = 0;
  2305. menuData.adjustBed.front2 = 0;
  2306. menuData.adjustBed.rear2 = 0;
  2307. }
  2308. lcdDrawUpdate = 1;
  2309. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  2310. }
  2311. if (menuData.adjustBed.left != menuData.adjustBed.left2)
  2312. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, menuData.adjustBed.left = menuData.adjustBed.left2);
  2313. if (menuData.adjustBed.right != menuData.adjustBed.right2)
  2314. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, menuData.adjustBed.right = menuData.adjustBed.right2);
  2315. if (menuData.adjustBed.front != menuData.adjustBed.front2)
  2316. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, menuData.adjustBed.front = menuData.adjustBed.front2);
  2317. if (menuData.adjustBed.rear != menuData.adjustBed.rear2)
  2318. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, menuData.adjustBed.rear = menuData.adjustBed.rear2);
  2319. MENU_BEGIN();
  2320. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  2321. MENU_ITEM_EDIT(int3, _i("Left side [um]"), &menuData.adjustBed.left2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_LEFT c=14 r=1
  2322. MENU_ITEM_EDIT(int3, _i("Right side[um]"), &menuData.adjustBed.right2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_RIGHT c=14 r=1
  2323. MENU_ITEM_EDIT(int3, _i("Front side[um]"), &menuData.adjustBed.front2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_FRONT c=14 r=1
  2324. MENU_ITEM_EDIT(int3, _i("Rear side [um]"), &menuData.adjustBed.rear2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);////MSG_BED_CORRECTION_REAR c=14 r=1
  2325. MENU_ITEM_FUNCTION_P(_i("Reset"), lcd_adjust_bed_reset);////MSG_BED_CORRECTION_RESET c=0 r=0
  2326. MENU_END();
  2327. }
  2328. void pid_extruder() {
  2329. lcd_implementation_clear();
  2330. lcd.setCursor(1, 0);
  2331. lcd_printPGM(_i("Set temperature:"));////MSG_SET_TEMPERATURE c=19 r=1
  2332. pid_temp += int(encoderPosition);
  2333. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  2334. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  2335. encoderPosition = 0;
  2336. lcd.setCursor(1, 2);
  2337. lcd.print(ftostr3(pid_temp));
  2338. if (lcd_clicked()) {
  2339. lcd_commands_type = LCD_COMMAND_PID_EXTRUDER;
  2340. lcd_return_to_status();
  2341. lcd_update(2);
  2342. }
  2343. }
  2344. void lcd_adjust_z() {
  2345. int enc_dif = 0;
  2346. int cursor_pos = 1;
  2347. int fsm = 0;
  2348. lcd_implementation_clear();
  2349. lcd.setCursor(0, 0);
  2350. lcd_printPGM(_i("Auto adjust Z?"));////MSG_ADJUSTZ c=0 r=0
  2351. lcd.setCursor(1, 1);
  2352. lcd_printPGM(_T(MSG_YES));
  2353. lcd.setCursor(1, 2);
  2354. lcd_printPGM(_T(MSG_NO));
  2355. lcd.setCursor(0, 1);
  2356. lcd.print(">");
  2357. enc_dif = encoderDiff;
  2358. while (fsm == 0) {
  2359. manage_heater();
  2360. manage_inactivity(true);
  2361. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  2362. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  2363. if (enc_dif > encoderDiff ) {
  2364. cursor_pos --;
  2365. }
  2366. if (enc_dif < encoderDiff ) {
  2367. cursor_pos ++;
  2368. }
  2369. if (cursor_pos > 2) {
  2370. cursor_pos = 2;
  2371. }
  2372. if (cursor_pos < 1) {
  2373. cursor_pos = 1;
  2374. }
  2375. lcd.setCursor(0, 1);
  2376. lcd.print(" ");
  2377. lcd.setCursor(0, 2);
  2378. lcd.print(" ");
  2379. lcd.setCursor(0, cursor_pos);
  2380. lcd.print(">");
  2381. enc_dif = encoderDiff;
  2382. delay(100);
  2383. }
  2384. }
  2385. if (lcd_clicked()) {
  2386. fsm = cursor_pos;
  2387. if (fsm == 1) {
  2388. int babystepLoadZ = 0;
  2389. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ);
  2390. CRITICAL_SECTION_START
  2391. babystepsTodo[Z_AXIS] = babystepLoadZ;
  2392. CRITICAL_SECTION_END
  2393. } else {
  2394. int zero = 0;
  2395. EEPROM_save_B(EEPROM_BABYSTEP_X, &zero);
  2396. EEPROM_save_B(EEPROM_BABYSTEP_Y, &zero);
  2397. EEPROM_save_B(EEPROM_BABYSTEP_Z, &zero);
  2398. }
  2399. delay(500);
  2400. }
  2401. };
  2402. lcd_implementation_clear();
  2403. lcd_return_to_status();
  2404. }
  2405. bool lcd_wait_for_pinda(float temp) {
  2406. lcd_set_custom_characters_degree();
  2407. setTargetHotend(0, 0);
  2408. setTargetBed(0);
  2409. LongTimer pinda_timeout;
  2410. pinda_timeout.start();
  2411. bool target_temp_reached = true;
  2412. while (current_temperature_pinda > temp){
  2413. lcd_display_message_fullscreen_P(_i("Waiting for PINDA probe cooling"));////MSG_WAITING_TEMP_PINDA c=20 r=3
  2414. lcd.setCursor(0, 4);
  2415. lcd.print(LCD_STR_THERMOMETER[0]);
  2416. lcd.print(ftostr3(current_temperature_pinda));
  2417. lcd.print("/");
  2418. lcd.print(ftostr3(temp));
  2419. lcd.print(LCD_STR_DEGREE);
  2420. delay_keep_alive(1000);
  2421. serialecho_temperatures();
  2422. if (pinda_timeout.expired(8 * 60 * 1000ul)) { //PINDA cooling from 60 C to 35 C takes about 7 minutes
  2423. target_temp_reached = false;
  2424. break;
  2425. }
  2426. }
  2427. lcd_set_custom_characters_arrows();
  2428. lcd_update_enable(true);
  2429. return(target_temp_reached);
  2430. }
  2431. void lcd_wait_for_heater() {
  2432. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  2433. lcd.setCursor(0, 4);
  2434. lcd.print(LCD_STR_THERMOMETER[0]);
  2435. lcd.print(ftostr3(degHotend(active_extruder)));
  2436. lcd.print("/");
  2437. lcd.print(ftostr3(degTargetHotend(active_extruder)));
  2438. lcd.print(LCD_STR_DEGREE);
  2439. }
  2440. void lcd_wait_for_cool_down() {
  2441. lcd_set_custom_characters_degree();
  2442. setTargetHotend(0,0);
  2443. setTargetBed(0);
  2444. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  2445. lcd_display_message_fullscreen_P(_i("Waiting for nozzle and bed cooling"));////MSG_WAITING_TEMP c=20 r=3
  2446. lcd.setCursor(0, 4);
  2447. lcd.print(LCD_STR_THERMOMETER[0]);
  2448. lcd.print(ftostr3(degHotend(0)));
  2449. lcd.print("/0");
  2450. lcd.print(LCD_STR_DEGREE);
  2451. lcd.setCursor(9, 4);
  2452. lcd.print(LCD_STR_BEDTEMP[0]);
  2453. lcd.print(ftostr3(degBed()));
  2454. lcd.print("/0");
  2455. lcd.print(LCD_STR_DEGREE);
  2456. lcd_set_custom_characters();
  2457. delay_keep_alive(1000);
  2458. serialecho_temperatures();
  2459. }
  2460. lcd_set_custom_characters_arrows();
  2461. lcd_update_enable(true);
  2462. }
  2463. // Lets the user move the Z carriage up to the end stoppers.
  2464. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2465. // Otherwise the Z calibration is not changed and false is returned.
  2466. #ifndef TMC2130
  2467. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  2468. {
  2469. bool clean_nozzle_asked = false;
  2470. // 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.
  2471. current_position[Z_AXIS] = 0;
  2472. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2473. // Until confirmed by the confirmation dialog.
  2474. for (;;) {
  2475. unsigned long previous_millis_cmd = millis();
  2476. const char *msg = only_z ? _i("Calibrating Z. Rotate the knob to move the Z carriage up to the end stoppers. Click when done.") : _i("Calibrating XYZ. Rotate the knob to move the Z carriage up to the end stoppers. Click when done.");////MSG_MOVE_CARRIAGE_TO_THE_TOP c=20 r=8////MSG_MOVE_CARRIAGE_TO_THE_TOP_Z c=20 r=8
  2477. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2478. const bool multi_screen = msg_next != NULL;
  2479. unsigned long previous_millis_msg = millis();
  2480. // Until the user finishes the z up movement.
  2481. encoderDiff = 0;
  2482. encoderPosition = 0;
  2483. for (;;) {
  2484. // if (millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2485. // goto canceled;
  2486. manage_heater();
  2487. manage_inactivity(true);
  2488. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) {
  2489. delay(50);
  2490. previous_millis_cmd = millis();
  2491. encoderPosition += abs(encoderDiff / ENCODER_PULSES_PER_STEP);
  2492. encoderDiff = 0;
  2493. if (! planner_queue_full()) {
  2494. // Only move up, whatever direction the user rotates the encoder.
  2495. current_position[Z_AXIS] += fabs(encoderPosition);
  2496. encoderPosition = 0;
  2497. 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);
  2498. }
  2499. }
  2500. if (lcd_clicked()) {
  2501. // Abort a move if in progress.
  2502. planner_abort_hard();
  2503. while (lcd_clicked()) ;
  2504. delay(10);
  2505. while (lcd_clicked()) ;
  2506. break;
  2507. }
  2508. if (multi_screen && millis() - previous_millis_msg > 5000) {
  2509. if (msg_next == NULL)
  2510. msg_next = msg;
  2511. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2512. previous_millis_msg = millis();
  2513. }
  2514. }
  2515. if (! clean_nozzle_asked) {
  2516. lcd_show_fullscreen_message_and_wait_P(_T(MSG_CONFIRM_NOZZLE_CLEAN));
  2517. clean_nozzle_asked = true;
  2518. }
  2519. // Let the user confirm, that the Z carriage is at the top end stoppers.
  2520. int8_t result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Are left and right Z~carriages all up?"), false);////MSG_CONFIRM_CARRIAGE_AT_THE_TOP c=20 r=2
  2521. if (result == -1)
  2522. goto canceled;
  2523. else if (result == 1)
  2524. goto calibrated;
  2525. // otherwise perform another round of the Z up dialog.
  2526. }
  2527. calibrated:
  2528. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  2529. // during the search for the induction points.
  2530. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  2531. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  2532. if(only_z){
  2533. lcd_display_message_fullscreen_P(_T(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1));
  2534. lcd_implementation_print_at(0, 3, 1);
  2535. lcd_printPGM(_T(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2));
  2536. }else{
  2537. //lcd_show_fullscreen_message_and_wait_P(_T(MSG_PAPER));
  2538. lcd_display_message_fullscreen_P(_T(MSG_FIND_BED_OFFSET_AND_SKEW_LINE1));
  2539. lcd_implementation_print_at(0, 2, 1);
  2540. lcd_printPGM(_T(MSG_FIND_BED_OFFSET_AND_SKEW_LINE2));
  2541. }
  2542. return true;
  2543. canceled:
  2544. return false;
  2545. }
  2546. #endif // TMC2130
  2547. static inline bool pgm_is_whitespace(const char *c_addr)
  2548. {
  2549. const char c = pgm_read_byte(c_addr);
  2550. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  2551. }
  2552. static inline bool pgm_is_interpunction(const char *c_addr)
  2553. {
  2554. const char c = pgm_read_byte(c_addr);
  2555. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  2556. }
  2557. /**
  2558. * @brief show full screen message
  2559. *
  2560. * This function is non-blocking
  2561. * @param msg message to be displayed from PROGMEM
  2562. * @param nlines
  2563. * @return rest of the text (to be displayed on next page)
  2564. */
  2565. static const char* lcd_display_message_fullscreen_nonBlocking_P(const char *msg, uint8_t &nlines)
  2566. {
  2567. lcd.setCursor(0, 0);
  2568. const char *msgend = msg;
  2569. uint8_t row = 0;
  2570. bool multi_screen = false;
  2571. for (; row < 4; ++ row) {
  2572. while (pgm_is_whitespace(msg))
  2573. ++ msg;
  2574. if (pgm_read_byte(msg) == 0)
  2575. // End of the message.
  2576. break;
  2577. lcd.setCursor(0, row);
  2578. uint8_t linelen = min(strlen_P(msg), 20);
  2579. const char *msgend2 = msg + linelen;
  2580. msgend = msgend2;
  2581. if (row == 3 && linelen == 20) {
  2582. // Last line of the display, full line shall be displayed.
  2583. // Find out, whether this message will be split into multiple screens.
  2584. while (pgm_is_whitespace(msgend))
  2585. ++ msgend;
  2586. multi_screen = pgm_read_byte(msgend) != 0;
  2587. if (multi_screen)
  2588. msgend = (msgend2 -= 2);
  2589. }
  2590. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  2591. // Splitting a word. Find the start of the current word.
  2592. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  2593. -- msgend;
  2594. if (msgend == msg)
  2595. // Found a single long word, which cannot be split. Just cut it.
  2596. msgend = msgend2;
  2597. }
  2598. for (; msg < msgend; ++ msg) {
  2599. char c = char(pgm_read_byte(msg));
  2600. if (c == '~')
  2601. c = ' ';
  2602. lcd.print(c);
  2603. }
  2604. }
  2605. if (multi_screen) {
  2606. // Display the "next screen" indicator character.
  2607. // lcd_set_custom_characters_arrows();
  2608. lcd_set_custom_characters_nextpage();
  2609. lcd.setCursor(19, 3);
  2610. // Display the down arrow.
  2611. lcd.print(char(1));
  2612. }
  2613. nlines = row;
  2614. return multi_screen ? msgend : NULL;
  2615. }
  2616. const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines)
  2617. {
  2618. // Disable update of the screen by the usual lcd_update() routine.
  2619. lcd_update_enable(false);
  2620. lcd_implementation_clear();
  2621. return lcd_display_message_fullscreen_nonBlocking_P(msg, nlines);
  2622. }
  2623. /**
  2624. * @brief show full screen message and wait
  2625. *
  2626. * This function is blocking.
  2627. * @param msg message to be displayed from PROGMEM
  2628. */
  2629. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  2630. {
  2631. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2632. bool multi_screen = msg_next != NULL;
  2633. lcd_set_custom_characters_nextpage();
  2634. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2635. // Until confirmed by a button click.
  2636. for (;;) {
  2637. if (!multi_screen) {
  2638. lcd.setCursor(19, 3);
  2639. // Display the confirm char.
  2640. lcd.print(char(2));
  2641. }
  2642. // Wait for 5 seconds before displaying the next text.
  2643. for (uint8_t i = 0; i < 100; ++ i) {
  2644. delay_keep_alive(50);
  2645. if (lcd_clicked()) {
  2646. while (lcd_clicked()) ;
  2647. delay(10);
  2648. while (lcd_clicked()) ;
  2649. if (msg_next == NULL) {
  2650. KEEPALIVE_STATE(IN_HANDLER);
  2651. lcd_set_custom_characters();
  2652. lcd_update_enable(true);
  2653. lcd_update(2);
  2654. return;
  2655. }
  2656. else {
  2657. break;
  2658. }
  2659. }
  2660. }
  2661. if (multi_screen) {
  2662. if (msg_next == NULL)
  2663. msg_next = msg;
  2664. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2665. if (msg_next == NULL) {
  2666. lcd.setCursor(19, 3);
  2667. // Display the confirm char.
  2668. lcd.print(char(2));
  2669. }
  2670. }
  2671. }
  2672. }
  2673. void lcd_wait_for_click()
  2674. {
  2675. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2676. for (;;) {
  2677. manage_heater();
  2678. manage_inactivity(true);
  2679. if (lcd_clicked()) {
  2680. while (lcd_clicked()) ;
  2681. delay(10);
  2682. while (lcd_clicked()) ;
  2683. KEEPALIVE_STATE(IN_HANDLER);
  2684. return;
  2685. }
  2686. }
  2687. }
  2688. int8_t lcd_show_multiscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes) //currently just max. n*4 + 3 lines supported (set in language header files)
  2689. {
  2690. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  2691. bool multi_screen = msg_next != NULL;
  2692. bool yes = default_yes ? true : false;
  2693. // Wait for user confirmation or a timeout.
  2694. unsigned long previous_millis_cmd = millis();
  2695. int8_t enc_dif = encoderDiff;
  2696. //KEEPALIVE_STATE(PAUSED_FOR_USER);
  2697. for (;;) {
  2698. for (uint8_t i = 0; i < 100; ++i) {
  2699. delay_keep_alive(50);
  2700. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2701. return -1;
  2702. manage_heater();
  2703. manage_inactivity(true);
  2704. if (abs(enc_dif - encoderDiff) > 4) {
  2705. if (msg_next == NULL) {
  2706. lcd.setCursor(0, 3);
  2707. if (enc_dif < encoderDiff && yes) {
  2708. lcd_printPGM((PSTR(" ")));
  2709. lcd.setCursor(7, 3);
  2710. lcd_printPGM((PSTR(">")));
  2711. yes = false;
  2712. }
  2713. else if (enc_dif > encoderDiff && !yes) {
  2714. lcd_printPGM((PSTR(">")));
  2715. lcd.setCursor(7, 3);
  2716. lcd_printPGM((PSTR(" ")));
  2717. yes = true;
  2718. }
  2719. enc_dif = encoderDiff;
  2720. }
  2721. else {
  2722. break; //turning knob skips waiting loop
  2723. }
  2724. }
  2725. if (lcd_clicked()) {
  2726. while (lcd_clicked());
  2727. delay(10);
  2728. while (lcd_clicked());
  2729. if (msg_next == NULL) {
  2730. //KEEPALIVE_STATE(IN_HANDLER);
  2731. lcd_set_custom_characters();
  2732. return yes;
  2733. }
  2734. else break;
  2735. }
  2736. }
  2737. if (multi_screen) {
  2738. if (msg_next == NULL) {
  2739. msg_next = msg;
  2740. }
  2741. msg_next = lcd_display_message_fullscreen_P(msg_next);
  2742. }
  2743. if (msg_next == NULL) {
  2744. lcd.setCursor(0, 3);
  2745. if (yes) lcd_printPGM(PSTR(">"));
  2746. lcd.setCursor(1, 3);
  2747. lcd_printPGM(_T(MSG_YES));
  2748. lcd.setCursor(7, 3);
  2749. if (!yes) lcd_printPGM(PSTR(">"));
  2750. lcd.setCursor(8, 3);
  2751. lcd_printPGM(_T(MSG_NO));
  2752. }
  2753. }
  2754. }
  2755. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes)
  2756. {
  2757. lcd_display_message_fullscreen_P(msg);
  2758. if (default_yes) {
  2759. lcd.setCursor(0, 2);
  2760. lcd_printPGM(PSTR(">"));
  2761. lcd_printPGM(_T(MSG_YES));
  2762. lcd.setCursor(1, 3);
  2763. lcd_printPGM(_T(MSG_NO));
  2764. }
  2765. else {
  2766. lcd.setCursor(1, 2);
  2767. lcd_printPGM(_T(MSG_YES));
  2768. lcd.setCursor(0, 3);
  2769. lcd_printPGM(PSTR(">"));
  2770. lcd_printPGM(_T(MSG_NO));
  2771. }
  2772. bool yes = default_yes ? true : false;
  2773. // Wait for user confirmation or a timeout.
  2774. unsigned long previous_millis_cmd = millis();
  2775. int8_t enc_dif = encoderDiff;
  2776. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2777. for (;;) {
  2778. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  2779. return -1;
  2780. manage_heater();
  2781. manage_inactivity(true);
  2782. if (abs(enc_dif - encoderDiff) > 4) {
  2783. lcd.setCursor(0, 2);
  2784. if (enc_dif < encoderDiff && yes) {
  2785. lcd_printPGM((PSTR(" ")));
  2786. lcd.setCursor(0, 3);
  2787. lcd_printPGM((PSTR(">")));
  2788. yes = false;
  2789. }
  2790. else if (enc_dif > encoderDiff && !yes) {
  2791. lcd_printPGM((PSTR(">")));
  2792. lcd.setCursor(0, 3);
  2793. lcd_printPGM((PSTR(" ")));
  2794. yes = true;
  2795. }
  2796. enc_dif = encoderDiff;
  2797. }
  2798. if (lcd_clicked()) {
  2799. while (lcd_clicked());
  2800. delay(10);
  2801. while (lcd_clicked());
  2802. KEEPALIVE_STATE(IN_HANDLER);
  2803. return yes;
  2804. }
  2805. }
  2806. }
  2807. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  2808. {
  2809. const char *msg = NULL;
  2810. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  2811. lcd_show_fullscreen_message_and_wait_P(_i("XYZ calibration failed. Bed calibration point was not found."));////MSG_BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND c=20 r=8
  2812. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  2813. if (point_too_far_mask == 0)
  2814. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  2815. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2816. // Only the center point or all the three front points.
  2817. msg = _i("XYZ calibration failed. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR c=20 r=8
  2818. else if (point_too_far_mask & 1 == 0)
  2819. // The right and maybe the center point out of reach.
  2820. msg = _i("XYZ calibration failed. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR c=20 r=8
  2821. else
  2822. // The left and maybe the center point out of reach.
  2823. msg = _i("XYZ calibration failed. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR c=20 r=8
  2824. lcd_show_fullscreen_message_and_wait_P(msg);
  2825. } else {
  2826. if (point_too_far_mask != 0) {
  2827. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  2828. // Only the center point or all the three front points.
  2829. msg = _i("XYZ calibration compromised. Front calibration points not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR c=20 r=8
  2830. else if (point_too_far_mask & 1 == 0)
  2831. // The right and maybe the center point out of reach.
  2832. msg = _i("XYZ calibration compromised. Right front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR c=20 r=8
  2833. else
  2834. // The left and maybe the center point out of reach.
  2835. msg = _i("XYZ calibration compromised. Left front calibration point not reachable.");////MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR c=20 r=8
  2836. lcd_show_fullscreen_message_and_wait_P(msg);
  2837. }
  2838. if (point_too_far_mask == 0 || result > 0) {
  2839. switch (result) {
  2840. default:
  2841. // should not happen
  2842. msg = _T(MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED);
  2843. break;
  2844. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  2845. msg = _i("XYZ calibration ok. X/Y axes are perpendicular. Congratulations!");////MSG_BED_SKEW_OFFSET_DETECTION_PERFECT c=20 r=8
  2846. break;
  2847. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  2848. msg = _i("XYZ calibration all right. X/Y axes are slightly skewed. Good job!");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_MILD c=20 r=8
  2849. break;
  2850. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  2851. msg = _i("XYZ calibration all right. Skew will be corrected automatically.");////MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME c=20 r=8
  2852. break;
  2853. }
  2854. lcd_show_fullscreen_message_and_wait_P(msg);
  2855. }
  2856. }
  2857. }
  2858. void lcd_temp_cal_show_result(bool result) {
  2859. custom_message_type = 0;
  2860. custom_message = false;
  2861. disable_x();
  2862. disable_y();
  2863. disable_z();
  2864. disable_e0();
  2865. disable_e1();
  2866. disable_e2();
  2867. setTargetBed(0); //set bed target temperature back to 0
  2868. if (result == true) {
  2869. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
  2870. SERIAL_ECHOLNPGM("Temperature calibration done. Continue with pressing the knob.");
  2871. lcd_show_fullscreen_message_and_wait_P(_T(MSG_TEMP_CALIBRATION_DONE));
  2872. temp_cal_active = true;
  2873. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 1);
  2874. }
  2875. else {
  2876. eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 0);
  2877. SERIAL_ECHOLNPGM("Temperature calibration failed. Continue with pressing the knob.");
  2878. lcd_show_fullscreen_message_and_wait_P(_i("Temperature calibration failed"));////MSG_TEMP_CAL_FAILED c=20 r=8
  2879. temp_cal_active = false;
  2880. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, 0);
  2881. }
  2882. lcd_update_enable(true);
  2883. lcd_update(2);
  2884. }
  2885. static void lcd_show_end_stops() {
  2886. lcd.setCursor(0, 0);
  2887. lcd_printPGM((PSTR("End stops diag")));
  2888. lcd.setCursor(0, 1);
  2889. lcd_printPGM((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("X1")) : (PSTR("X0")));
  2890. lcd.setCursor(0, 2);
  2891. lcd_printPGM((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Y1")) : (PSTR("Y0")));
  2892. lcd.setCursor(0, 3);
  2893. lcd_printPGM((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Z1")) : (PSTR("Z0")));
  2894. }
  2895. static void menu_show_end_stops() {
  2896. lcd_show_end_stops();
  2897. if (LCD_CLICKED) menu_back();
  2898. }
  2899. // Lets the user move the Z carriage up to the end stoppers.
  2900. // When done, it sets the current Z to Z_MAX_POS and returns true.
  2901. // Otherwise the Z calibration is not changed and false is returned.
  2902. void lcd_diag_show_end_stops()
  2903. {
  2904. int enc_dif = encoderDiff;
  2905. lcd_implementation_clear();
  2906. for (;;) {
  2907. manage_heater();
  2908. manage_inactivity(true);
  2909. lcd_show_end_stops();
  2910. if (lcd_clicked()) {
  2911. while (lcd_clicked()) ;
  2912. delay(10);
  2913. while (lcd_clicked()) ;
  2914. break;
  2915. }
  2916. }
  2917. lcd_implementation_clear();
  2918. lcd_return_to_status();
  2919. }
  2920. void prusa_statistics(int _message, uint8_t _fil_nr) {
  2921. #ifdef DEBUG_DISABLE_PRUSA_STATISTICS
  2922. return;
  2923. #endif //DEBUG_DISABLE_PRUSA_STATISTICS
  2924. switch (_message)
  2925. {
  2926. case 0: // default message
  2927. if (IS_SD_PRINTING)
  2928. {
  2929. SERIAL_ECHO("{");
  2930. prusa_stat_printerstatus(4);
  2931. prusa_stat_farm_number();
  2932. prusa_stat_printinfo();
  2933. SERIAL_ECHOLN("}");
  2934. status_number = 4;
  2935. }
  2936. else
  2937. {
  2938. SERIAL_ECHO("{");
  2939. prusa_stat_printerstatus(1);
  2940. prusa_stat_farm_number();
  2941. SERIAL_ECHOLN("}");
  2942. status_number = 1;
  2943. }
  2944. break;
  2945. case 1: // 1 heating
  2946. farm_status = 2;
  2947. SERIAL_ECHO("{");
  2948. prusa_stat_printerstatus(2);
  2949. prusa_stat_farm_number();
  2950. SERIAL_ECHOLN("}");
  2951. status_number = 2;
  2952. farm_timer = 1;
  2953. break;
  2954. case 2: // heating done
  2955. farm_status = 3;
  2956. SERIAL_ECHO("{");
  2957. prusa_stat_printerstatus(3);
  2958. prusa_stat_farm_number();
  2959. SERIAL_ECHOLN("}");
  2960. status_number = 3;
  2961. farm_timer = 1;
  2962. if (IS_SD_PRINTING)
  2963. {
  2964. farm_status = 4;
  2965. SERIAL_ECHO("{");
  2966. prusa_stat_printerstatus(4);
  2967. prusa_stat_farm_number();
  2968. SERIAL_ECHOLN("}");
  2969. status_number = 4;
  2970. }
  2971. else
  2972. {
  2973. SERIAL_ECHO("{");
  2974. prusa_stat_printerstatus(3);
  2975. prusa_stat_farm_number();
  2976. SERIAL_ECHOLN("}");
  2977. status_number = 3;
  2978. }
  2979. farm_timer = 1;
  2980. break;
  2981. case 3: // filament change
  2982. break;
  2983. case 4: // print succesfull
  2984. SERIAL_ECHO("{[RES:1][FIL:");
  2985. MYSERIAL.print(int(_fil_nr));
  2986. SERIAL_ECHO("]");
  2987. prusa_stat_printerstatus(status_number);
  2988. prusa_stat_farm_number();
  2989. SERIAL_ECHOLN("}");
  2990. farm_timer = 2;
  2991. break;
  2992. case 5: // print not succesfull
  2993. SERIAL_ECHO("{[RES:0][FIL:");
  2994. MYSERIAL.print(int(_fil_nr));
  2995. SERIAL_ECHO("]");
  2996. prusa_stat_printerstatus(status_number);
  2997. prusa_stat_farm_number();
  2998. SERIAL_ECHOLN("}");
  2999. farm_timer = 2;
  3000. break;
  3001. case 6: // print done
  3002. SERIAL_ECHO("{[PRN:8]");
  3003. prusa_stat_farm_number();
  3004. SERIAL_ECHOLN("}");
  3005. status_number = 8;
  3006. farm_timer = 2;
  3007. break;
  3008. case 7: // print done - stopped
  3009. SERIAL_ECHO("{[PRN:9]");
  3010. prusa_stat_farm_number();
  3011. SERIAL_ECHOLN("}");
  3012. status_number = 9;
  3013. farm_timer = 2;
  3014. break;
  3015. case 8: // printer started
  3016. SERIAL_ECHO("{[PRN:0][PFN:");
  3017. status_number = 0;
  3018. SERIAL_ECHO(farm_no);
  3019. SERIAL_ECHOLN("]}");
  3020. farm_timer = 2;
  3021. break;
  3022. case 20: // echo farm no
  3023. SERIAL_ECHO("{");
  3024. prusa_stat_printerstatus(status_number);
  3025. prusa_stat_farm_number();
  3026. SERIAL_ECHOLN("}");
  3027. farm_timer = 4;
  3028. break;
  3029. case 21: // temperatures
  3030. SERIAL_ECHO("{");
  3031. prusa_stat_temperatures();
  3032. prusa_stat_farm_number();
  3033. prusa_stat_printerstatus(status_number);
  3034. SERIAL_ECHOLN("}");
  3035. break;
  3036. case 22: // waiting for filament change
  3037. SERIAL_ECHO("{[PRN:5]");
  3038. prusa_stat_farm_number();
  3039. SERIAL_ECHOLN("}");
  3040. status_number = 5;
  3041. break;
  3042. case 90: // Error - Thermal Runaway
  3043. SERIAL_ECHO("{[ERR:1]");
  3044. prusa_stat_farm_number();
  3045. SERIAL_ECHOLN("}");
  3046. break;
  3047. case 91: // Error - Thermal Runaway Preheat
  3048. SERIAL_ECHO("{[ERR:2]");
  3049. prusa_stat_farm_number();
  3050. SERIAL_ECHOLN("}");
  3051. break;
  3052. case 92: // Error - Min temp
  3053. SERIAL_ECHO("{[ERR:3]");
  3054. prusa_stat_farm_number();
  3055. SERIAL_ECHOLN("}");
  3056. break;
  3057. case 93: // Error - Max temp
  3058. SERIAL_ECHO("{[ERR:4]");
  3059. prusa_stat_farm_number();
  3060. SERIAL_ECHOLN("}");
  3061. break;
  3062. case 99: // heartbeat
  3063. SERIAL_ECHO("{[PRN:99]");
  3064. prusa_stat_temperatures();
  3065. SERIAL_ECHO("[PFN:");
  3066. SERIAL_ECHO(farm_no);
  3067. SERIAL_ECHO("]");
  3068. SERIAL_ECHOLN("}");
  3069. break;
  3070. }
  3071. }
  3072. static void prusa_stat_printerstatus(int _status)
  3073. {
  3074. SERIAL_ECHO("[PRN:");
  3075. SERIAL_ECHO(_status);
  3076. SERIAL_ECHO("]");
  3077. }
  3078. static void prusa_stat_farm_number() {
  3079. SERIAL_ECHO("[PFN:");
  3080. SERIAL_ECHO(farm_no);
  3081. SERIAL_ECHO("]");
  3082. }
  3083. static void prusa_stat_temperatures()
  3084. {
  3085. SERIAL_ECHO("[ST0:");
  3086. SERIAL_ECHO(target_temperature[0]);
  3087. SERIAL_ECHO("][STB:");
  3088. SERIAL_ECHO(target_temperature_bed);
  3089. SERIAL_ECHO("][AT0:");
  3090. SERIAL_ECHO(current_temperature[0]);
  3091. SERIAL_ECHO("][ATB:");
  3092. SERIAL_ECHO(current_temperature_bed);
  3093. SERIAL_ECHO("]");
  3094. }
  3095. static void prusa_stat_printinfo()
  3096. {
  3097. SERIAL_ECHO("[TFU:");
  3098. SERIAL_ECHO(total_filament_used);
  3099. SERIAL_ECHO("][PCD:");
  3100. SERIAL_ECHO(itostr3(card.percentDone()));
  3101. SERIAL_ECHO("][FEM:");
  3102. SERIAL_ECHO(itostr3(feedmultiply));
  3103. SERIAL_ECHO("][FNM:");
  3104. SERIAL_ECHO(longFilenameOLD);
  3105. SERIAL_ECHO("][TIM:");
  3106. if (starttime != 0)
  3107. {
  3108. SERIAL_ECHO(millis() / 1000 - starttime / 1000);
  3109. }
  3110. else
  3111. {
  3112. SERIAL_ECHO(0);
  3113. }
  3114. SERIAL_ECHO("][FWR:");
  3115. SERIAL_ECHO(FW_VERSION);
  3116. SERIAL_ECHO("]");
  3117. }
  3118. /*
  3119. void lcd_pick_babystep(){
  3120. int enc_dif = 0;
  3121. int cursor_pos = 1;
  3122. int fsm = 0;
  3123. lcd_implementation_clear();
  3124. lcd.setCursor(0, 0);
  3125. lcd_printPGM(_i("Pick print"));////MSG_PICK_Z c=0 r=0
  3126. lcd.setCursor(3, 2);
  3127. lcd.print("1");
  3128. lcd.setCursor(3, 3);
  3129. lcd.print("2");
  3130. lcd.setCursor(12, 2);
  3131. lcd.print("3");
  3132. lcd.setCursor(12, 3);
  3133. lcd.print("4");
  3134. lcd.setCursor(1, 2);
  3135. lcd.print(">");
  3136. enc_dif = encoderDiff;
  3137. while (fsm == 0) {
  3138. manage_heater();
  3139. manage_inactivity(true);
  3140. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  3141. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  3142. if (enc_dif > encoderDiff ) {
  3143. cursor_pos --;
  3144. }
  3145. if (enc_dif < encoderDiff ) {
  3146. cursor_pos ++;
  3147. }
  3148. if (cursor_pos > 4) {
  3149. cursor_pos = 4;
  3150. }
  3151. if (cursor_pos < 1) {
  3152. cursor_pos = 1;
  3153. }
  3154. lcd.setCursor(1, 2);
  3155. lcd.print(" ");
  3156. lcd.setCursor(1, 3);
  3157. lcd.print(" ");
  3158. lcd.setCursor(10, 2);
  3159. lcd.print(" ");
  3160. lcd.setCursor(10, 3);
  3161. lcd.print(" ");
  3162. if (cursor_pos < 3) {
  3163. lcd.setCursor(1, cursor_pos+1);
  3164. lcd.print(">");
  3165. }else{
  3166. lcd.setCursor(10, cursor_pos-1);
  3167. lcd.print(">");
  3168. }
  3169. enc_dif = encoderDiff;
  3170. delay(100);
  3171. }
  3172. }
  3173. if (lcd_clicked()) {
  3174. fsm = cursor_pos;
  3175. int babyStepZ;
  3176. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babyStepZ);
  3177. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babyStepZ);
  3178. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  3179. delay(500);
  3180. }
  3181. };
  3182. lcd_implementation_clear();
  3183. lcd_return_to_status();
  3184. }
  3185. */
  3186. void lcd_move_menu_axis()
  3187. {
  3188. MENU_BEGIN();
  3189. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  3190. MENU_ITEM_SUBMENU_P(_i("Move X"), lcd_move_x);////MSG_MOVE_X c=0 r=0
  3191. MENU_ITEM_SUBMENU_P(_i("Move Y"), lcd_move_y);////MSG_MOVE_Y c=0 r=0
  3192. MENU_ITEM_SUBMENU_P(_i("Move Z"), lcd_move_z);////MSG_MOVE_Z c=0 r=0
  3193. MENU_ITEM_SUBMENU_P(_i("Extruder"), lcd_move_e);////MSG_MOVE_E c=0 r=0
  3194. MENU_END();
  3195. }
  3196. static void lcd_move_menu_1mm()
  3197. {
  3198. move_menu_scale = 1.0;
  3199. lcd_move_menu_axis();
  3200. }
  3201. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  3202. {
  3203. do
  3204. {
  3205. eeprom_write_byte((unsigned char*)pos, *value);
  3206. pos++;
  3207. value++;
  3208. } while (--size);
  3209. }
  3210. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  3211. {
  3212. do
  3213. {
  3214. *value = eeprom_read_byte((unsigned char*)pos);
  3215. pos++;
  3216. value++;
  3217. } while (--size);
  3218. }
  3219. #ifdef SDCARD_SORT_ALPHA
  3220. static void lcd_sort_type_set() {
  3221. uint8_t sdSort;
  3222. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3223. switch (sdSort) {
  3224. case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
  3225. case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break;
  3226. default: sdSort = SD_SORT_TIME;
  3227. }
  3228. eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort);
  3229. presort_flag = true;
  3230. }
  3231. #endif //SDCARD_SORT_ALPHA
  3232. #ifdef TMC2130
  3233. static void lcd_crash_mode_info()
  3234. {
  3235. lcd_update_enable(true);
  3236. static uint32_t tim = 0;
  3237. if ((tim + 1000) < millis())
  3238. {
  3239. fputs_P(_i("\x1b[2JCrash detection can\x1b[1;0Hbe turned on only in\x1b[2;0HNormal mode"), lcdout);////MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4
  3240. tim = millis();
  3241. }
  3242. menu_back_if_clicked();
  3243. }
  3244. static void lcd_crash_mode_info2()
  3245. {
  3246. lcd_update_enable(true);
  3247. static uint32_t tim = 0;
  3248. if ((tim + 1000) < millis())
  3249. {
  3250. fputs_P(_i("\x1b[2JWARNING:\x1b[1;0HCrash detection\x1b[2;0Hdisabled in\x1b[3;0HStealth mode"), lcdout);////MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4
  3251. tim = millis();
  3252. }
  3253. menu_back_if_clicked();
  3254. }
  3255. #endif //TMC2130
  3256. #ifdef PAT9125
  3257. static void lcd_filament_autoload_info()
  3258. {
  3259. uint8_t nlines;
  3260. lcd_update_enable(true);
  3261. static uint32_t tim = 0;
  3262. if ((tim + 1000) < millis())
  3263. {
  3264. lcd_display_message_fullscreen_nonBlocking_P(_i("Autoloading filament available only when filament sensor is turned on..."), nlines); ////MSG_AUTOLOADING_ONLY_IF_FSENS_ON c=20 r=4
  3265. tim = millis();
  3266. }
  3267. menu_back_if_clicked();
  3268. }
  3269. static void lcd_fsensor_fail()
  3270. {
  3271. uint8_t nlines;
  3272. lcd_update_enable(true);
  3273. static uint32_t tim = 0;
  3274. if ((tim + 1000) < millis())
  3275. {
  3276. lcd_display_message_fullscreen_nonBlocking_P(_i("ERROR: Filament sensor is not responding, please check connection."), nlines);////MSG_FSENS_NOT_RESPONDING c=20 r=4
  3277. tim = millis();
  3278. }
  3279. menu_back_if_clicked();
  3280. }
  3281. #endif //PAT9125
  3282. static void lcd_silent_mode_set() {
  3283. switch (SilentModeMenu) {
  3284. #ifdef TMC2130
  3285. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  3286. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  3287. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  3288. #else
  3289. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  3290. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  3291. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  3292. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  3293. #endif //TMC2130
  3294. }
  3295. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  3296. #ifdef TMC2130
  3297. // Wait until the planner queue is drained and the stepper routine achieves
  3298. // an idle state.
  3299. st_synchronize();
  3300. if (tmc2130_wait_standstill_xy(1000)) {}
  3301. // MYSERIAL.print("standstill OK");
  3302. // else
  3303. // MYSERIAL.print("standstill NG!");
  3304. cli();
  3305. tmc2130_mode = (SilentModeMenu != SILENT_MODE_NORMAL)?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
  3306. tmc2130_init();
  3307. // We may have missed a stepper timer interrupt due to the time spent in tmc2130_init.
  3308. // Be safe than sorry, reset the stepper timer before re-enabling interrupts.
  3309. st_reset_timer();
  3310. sei();
  3311. #endif //TMC2130
  3312. st_current_init();
  3313. #ifdef TMC2130
  3314. if (CrashDetectMenu && (SilentModeMenu != SILENT_MODE_NORMAL))
  3315. menu_submenu(lcd_crash_mode_info2);
  3316. #endif //TMC2130
  3317. }
  3318. #ifdef TMC2130
  3319. static void lcd_crash_mode_set()
  3320. {
  3321. CrashDetectMenu = !CrashDetectMenu; //set also from crashdet_enable() and crashdet_disable()
  3322. if (CrashDetectMenu==0) {
  3323. crashdet_disable();
  3324. }else{
  3325. crashdet_enable();
  3326. }
  3327. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) lcd_goto_menu(lcd_tune_menu, 9);
  3328. else lcd_goto_menu(lcd_settings_menu, 9);
  3329. }
  3330. #endif //TMC2130
  3331. #ifdef PAT9125
  3332. static void lcd_fsensor_state_set()
  3333. {
  3334. FSensorStateMenu = !FSensorStateMenu; //set also from fsensor_enable() and fsensor_disable()
  3335. if (!FSensorStateMenu) {
  3336. fsensor_disable();
  3337. if (filament_autoload_enabled)
  3338. menu_submenu(lcd_filament_autoload_info);
  3339. }else{
  3340. fsensor_enable();
  3341. if (fsensor_not_responding)
  3342. menu_submenu(lcd_fsensor_fail);
  3343. }
  3344. }
  3345. #endif //PAT9125
  3346. #if !SDSORT_USES_RAM
  3347. void lcd_set_degree() {
  3348. lcd_set_custom_characters_degree();
  3349. }
  3350. void lcd_set_progress() {
  3351. lcd_set_custom_characters_progress();
  3352. }
  3353. #endif
  3354. #if (LANG_MODE != 0)
  3355. void menu_setlang(unsigned char lang)
  3356. {
  3357. if (!lang_select(lang))
  3358. {
  3359. if (lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Copy selected language from XFLASH?"), false, true))
  3360. lang_boot_update_start(lang);
  3361. lcd_update_enable(true);
  3362. lcd_implementation_clear();
  3363. lcd_goto_menu(lcd_language_menu);
  3364. lcd_timeoutToStatus = -1; //infinite timeout
  3365. lcdDrawUpdate = 2;
  3366. }
  3367. }
  3368. static void lcd_language_menu()
  3369. {
  3370. MENU_BEGIN();
  3371. if (lang_is_selected()) MENU_ITEM_BACK_P(_T(MSG_SETTINGS)); //
  3372. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(0)))) //primary language
  3373. {
  3374. menu_setlang(0);
  3375. return;
  3376. }
  3377. uint8_t cnt = lang_get_count();
  3378. #ifdef W25X20CL
  3379. if (cnt == 2) //display secondary language in case of clear xflash
  3380. {
  3381. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(1))))
  3382. {
  3383. menu_setlang(1);
  3384. return;
  3385. }
  3386. }
  3387. else
  3388. for (int i = 2; i < cnt; i++) //skip seconday language - solved in lang_select (MK3)
  3389. #else //W25X20CL
  3390. for (int i = 1; i < cnt; i++) //all seconday languages (MK2/25)
  3391. #endif //W25X20CL
  3392. if (menu_item_text_P(lang_get_name_by_code(lang_get_code(i))))
  3393. {
  3394. menu_setlang(i);
  3395. return;
  3396. }
  3397. MENU_END();
  3398. }
  3399. #endif //(LANG_MODE != 0)
  3400. void lcd_mesh_bedleveling()
  3401. {
  3402. mesh_bed_run_from_menu = true;
  3403. enquecommand_P(PSTR("G80"));
  3404. lcd_return_to_status();
  3405. }
  3406. void lcd_mesh_calibration()
  3407. {
  3408. enquecommand_P(PSTR("M45"));
  3409. lcd_return_to_status();
  3410. }
  3411. void lcd_mesh_calibration_z()
  3412. {
  3413. enquecommand_P(PSTR("M45 Z"));
  3414. lcd_return_to_status();
  3415. }
  3416. void lcd_pinda_calibration_menu()
  3417. {
  3418. MENU_BEGIN();
  3419. MENU_ITEM_BACK_P(_T(MSG_MENU_CALIBRATION));
  3420. MENU_ITEM_SUBMENU_P(_i("Calibrate"), lcd_calibrate_pinda);////MSG_CALIBRATE_PINDA c=17 r=1
  3421. MENU_END();
  3422. }
  3423. void lcd_temp_calibration_set() {
  3424. temp_cal_active = !temp_cal_active;
  3425. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  3426. st_current_init();
  3427. }
  3428. #ifdef HAS_SECOND_SERIAL_PORT
  3429. void lcd_second_serial_set() {
  3430. if(selectedSerialPort == 1) selectedSerialPort = 0;
  3431. else selectedSerialPort = 1;
  3432. eeprom_update_byte((unsigned char *)EEPROM_SECOND_SERIAL_ACTIVE, selectedSerialPort);
  3433. MYSERIAL.begin(BAUDRATE);
  3434. }
  3435. #endif //HAS_SECOND_SERIAL_PORT
  3436. void lcd_calibrate_pinda() {
  3437. enquecommand_P(PSTR("G76"));
  3438. lcd_return_to_status();
  3439. }
  3440. #ifndef SNMM
  3441. /*void lcd_calibrate_extruder() {
  3442. if (degHotend0() > EXTRUDE_MINTEMP)
  3443. {
  3444. current_position[E_AXIS] = 0; //set initial position to zero
  3445. plan_set_e_position(current_position[E_AXIS]);
  3446. //long steps_start = st_get_position(E_AXIS);
  3447. long steps_final;
  3448. float e_steps_per_unit;
  3449. 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)
  3450. 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
  3451. const char *msg_e_cal_knob = _i("Rotate knob until mark reaches extruder body. Click when done.");////MSG_E_CAL_KNOB c=20 r=8
  3452. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3453. const bool multi_screen = msg_next_e_cal_knob != NULL;
  3454. unsigned long msg_millis;
  3455. lcd_show_fullscreen_message_and_wait_P(_i("Mark filament 100mm from extruder body. Click when done."));////MSG_MARK_FIL c=20 r=8
  3456. lcd_implementation_clear();
  3457. lcd.setCursor(0, 1); lcd_printPGM(_T(MSG_PLEASE_WAIT));
  3458. current_position[E_AXIS] += e_shift_calibration;
  3459. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3460. st_synchronize();
  3461. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  3462. msg_millis = millis();
  3463. while (!LCD_CLICKED) {
  3464. if (multi_screen && millis() - msg_millis > 5000) {
  3465. if (msg_next_e_cal_knob == NULL)
  3466. msg_next_e_cal_knob = msg_e_cal_knob;
  3467. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  3468. msg_millis = millis();
  3469. }
  3470. //manage_inactivity(true);
  3471. manage_heater();
  3472. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  3473. delay_keep_alive(50);
  3474. //previous_millis_cmd = millis();
  3475. encoderPosition += (encoderDiff / ENCODER_PULSES_PER_STEP);
  3476. encoderDiff = 0;
  3477. if (!planner_queue_full()) {
  3478. current_position[E_AXIS] += float(abs((int)encoderPosition)) * 0.01; //0.05
  3479. encoderPosition = 0;
  3480. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  3481. }
  3482. }
  3483. }
  3484. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  3485. //steps_final = st_get_position(E_AXIS);
  3486. lcdDrawUpdate = 1;
  3487. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  3488. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  3489. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  3490. lcd_implementation_clear();
  3491. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  3492. enquecommand_P(PSTR("M500")); //store settings to eeprom
  3493. //lcd_implementation_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  3494. //delay_keep_alive(2000);
  3495. delay_keep_alive(500);
  3496. lcd_show_fullscreen_message_and_wait_P(_i("E calibration finished. Please clean the nozzle. Click when done."));////MSG_CLEAN_NOZZLE_E c=20 r=8
  3497. lcd_update_enable(true);
  3498. lcdDrawUpdate = 2;
  3499. }
  3500. else
  3501. {
  3502. lcd_implementation_clear();
  3503. lcd.setCursor(0, 0);
  3504. lcd_printPGM(_T(MSG_ERROR));
  3505. lcd.setCursor(0, 2);
  3506. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  3507. delay(2000);
  3508. lcd_implementation_clear();
  3509. }
  3510. lcd_return_to_status();
  3511. }
  3512. void lcd_extr_cal_reset() {
  3513. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  3514. axis_steps_per_unit[E_AXIS] = tmp1[3];
  3515. //extrudemultiply = 100;
  3516. enquecommand_P(PSTR("M500"));
  3517. }*/
  3518. #endif
  3519. void lcd_toshiba_flash_air_compatibility_toggle()
  3520. {
  3521. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  3522. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  3523. }
  3524. void lcd_v2_calibration() {
  3525. bool loaded = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is PLA filament loaded?"), false, true);////MSG_PLA_FILAMENT_LOADED c=20 r=2
  3526. if (loaded) {
  3527. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3528. }
  3529. else {
  3530. lcd_display_message_fullscreen_P(_i("Please load PLA filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4
  3531. for (int i = 0; i < 20; i++) { //wait max. 2s
  3532. delay_keep_alive(100);
  3533. if (lcd_clicked()) {
  3534. while (lcd_clicked());
  3535. delay(10);
  3536. while (lcd_clicked());
  3537. break;
  3538. }
  3539. }
  3540. }
  3541. lcd_return_to_status();
  3542. lcd_update_enable(true);
  3543. }
  3544. void lcd_wizard() {
  3545. bool result = true;
  3546. if (calibration_status() != CALIBRATION_STATUS_ASSEMBLED) {
  3547. result = lcd_show_multiscreen_message_yes_no_and_wait_P(_i("Running Wizard will delete current calibration results and start from the beginning. Continue?"), false, false);////MSG_WIZARD_RERUN c=20 r=7
  3548. }
  3549. if (result) {
  3550. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED);
  3551. lcd_wizard(0);
  3552. }
  3553. else {
  3554. lcd_return_to_status();
  3555. lcd_update_enable(true);
  3556. lcd_update(2);
  3557. }
  3558. }
  3559. void lcd_language()
  3560. {
  3561. lcd_update_enable(true);
  3562. lcd_implementation_clear();
  3563. lcd_goto_menu(lcd_language_menu);
  3564. lcd_timeoutToStatus = -1; //infinite timeout
  3565. lcdDrawUpdate = 2;
  3566. while ((menu_menu != lcd_status_screen) && (!lang_is_selected()))
  3567. {
  3568. delay(50);
  3569. lcd_update();
  3570. manage_heater();
  3571. manage_inactivity(true);
  3572. }
  3573. if (lang_is_selected())
  3574. lcd_return_to_status();
  3575. else
  3576. lang_select(LANG_ID_PRI);
  3577. }
  3578. void lcd_wizard(int state) {
  3579. bool end = false;
  3580. int wizard_event;
  3581. const char *msg = NULL;
  3582. while (!end) {
  3583. switch (state) {
  3584. case 0: // run wizard?
  3585. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_i("Hi, I am your Original Prusa i3 printer. Would you like me to guide you through the setup process?"), false, true);////MSG_WIZARD_WELCOME c=20 r=7
  3586. if (wizard_event) {
  3587. state = 1;
  3588. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 1);
  3589. }
  3590. else {
  3591. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3592. end = true;
  3593. }
  3594. break;
  3595. case 1: // restore calibration status
  3596. switch (calibration_status()) {
  3597. case CALIBRATION_STATUS_ASSEMBLED: state = 2; break; //run selftest
  3598. case CALIBRATION_STATUS_XYZ_CALIBRATION: state = 3; break; //run xyz cal.
  3599. case CALIBRATION_STATUS_Z_CALIBRATION: state = 4; break; //run z cal.
  3600. case CALIBRATION_STATUS_LIVE_ADJUST: state = 5; break; //run live adjust
  3601. case CALIBRATION_STATUS_CALIBRATED: end = true; eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0); break;
  3602. default: state = 2; break; //if calibration status is unknown, run wizard from the beginning
  3603. }
  3604. break;
  3605. case 2: //selftest
  3606. lcd_show_fullscreen_message_and_wait_P(_i("First, I will run the selftest to check most common assembly problems."));////MSG_WIZARD_SELFTEST c=20 r=8
  3607. wizard_event = lcd_selftest();
  3608. if (wizard_event) {
  3609. calibration_status_store(CALIBRATION_STATUS_XYZ_CALIBRATION);
  3610. state = 3;
  3611. }
  3612. else end = true;
  3613. break;
  3614. case 3: //xyz cal.
  3615. lcd_show_fullscreen_message_and_wait_P(_i("I will run xyz calibration now. It will take approx. 12 mins."));////MSG_WIZARD_XYZ_CAL c=20 r=8
  3616. wizard_event = gcode_M45(false, 0);
  3617. if (wizard_event) state = 5;
  3618. else end = true;
  3619. break;
  3620. case 4: //z cal.
  3621. lcd_show_fullscreen_message_and_wait_P(_i("I will run z calibration now."));////MSG_WIZARD_Z_CAL c=20 r=8
  3622. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_T(MSG_STEEL_SHEET_CHECK), false, false);
  3623. if (!wizard_event) lcd_show_fullscreen_message_and_wait_P(_T(MSG_PLACE_STEEL_SHEET));
  3624. wizard_event = gcode_M45(true, 0);
  3625. if (wizard_event) state = 11; //shipped, no need to set first layer, go to final message directly
  3626. else end = true;
  3627. break;
  3628. case 5: //is filament loaded?
  3629. //start to preheat nozzle and bed to save some time later
  3630. setTargetHotend(PLA_PREHEAT_HOTEND_TEMP, 0);
  3631. setTargetBed(PLA_PREHEAT_HPB_TEMP);
  3632. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is filament loaded?"), false);////MSG_WIZARD_FILAMENT_LOADED c=20 r=2
  3633. if (wizard_event) state = 8;
  3634. else state = 6;
  3635. break;
  3636. case 6: //waiting for preheat nozzle for PLA;
  3637. #ifndef SNMM
  3638. lcd_display_message_fullscreen_P(_i("Now I will preheat nozzle for PLA."));////MSG_WIZARD_WILL_PREHEAT c=20 r=4
  3639. current_position[Z_AXIS] = 100; //move in z axis to make space for loading filament
  3640. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], homing_feedrate[Z_AXIS] / 60, active_extruder);
  3641. delay_keep_alive(2000);
  3642. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3643. while (abs(degHotend(0) - PLA_PREHEAT_HOTEND_TEMP) > 3) {
  3644. lcd_display_message_fullscreen_P(_T(MSG_WIZARD_HEATING));
  3645. lcd.setCursor(0, 4);
  3646. lcd.print(LCD_STR_THERMOMETER[0]);
  3647. lcd.print(ftostr3(degHotend(0)));
  3648. lcd.print("/");
  3649. lcd.print(PLA_PREHEAT_HOTEND_TEMP);
  3650. lcd.print(LCD_STR_DEGREE);
  3651. lcd_set_custom_characters();
  3652. delay_keep_alive(1000);
  3653. }
  3654. #endif //not SNMM
  3655. state = 7;
  3656. break;
  3657. case 7: //load filament
  3658. #ifdef PAT9125
  3659. fsensor_block();
  3660. #endif //PAT9125
  3661. lcd_show_fullscreen_message_and_wait_P(_i("Please insert PLA filament to the extruder, then press knob to load it."));////MSG_WIZARD_LOAD_FILAMENT c=20 r=8
  3662. lcd_update_enable(false);
  3663. lcd_implementation_clear();
  3664. lcd_print_at_PGM(0, 2, _T(MSG_LOADING_FILAMENT));
  3665. #ifdef SNMM
  3666. change_extr(0);
  3667. #endif
  3668. gcode_M701();
  3669. #ifdef PAT9125
  3670. fsensor_unblock();
  3671. #endif //PAT9125
  3672. state = 9;
  3673. break;
  3674. case 8:
  3675. wizard_event = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is it PLA filament?"), false, true);////MSG_WIZARD_PLA_FILAMENT c=20 r=2
  3676. if (wizard_event) state = 9;
  3677. else end = true;
  3678. break;
  3679. case 9:
  3680. lcd_show_fullscreen_message_and_wait_P(_i("Now I will calibrate distance between tip of the nozzle and heatbed surface."));////MSG_WIZARD_V2_CAL c=20 r=8
  3681. lcd_show_fullscreen_message_and_wait_P(_i("I will start to print line and you will gradually lower the nozzle by rotating the knob, until you reach optimal height. Check the pictures in our handbook in chapter Calibration."));////MSG_WIZARD_V2_CAL_2 c=20 r=12
  3682. lcd_commands_type = LCD_COMMAND_V2_CAL;
  3683. end = true;
  3684. break;
  3685. case 10: //repeat first layer cal.?
  3686. wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_i("Do you want to repeat last step to readjust distance between nozzle and heatbed?"), false);////MSG_WIZARD_REPEAT_V2_CAL c=20 r=7
  3687. if (wizard_event) {
  3688. lcd_show_fullscreen_message_and_wait_P(_i("Please clean heatbed and then press the knob."));////MSG_WIZARD_CLEAN_HEATBED c=20 r=8
  3689. state = 9;
  3690. }
  3691. else {
  3692. state = 11;
  3693. }
  3694. break;
  3695. case 11: //we are finished
  3696. eeprom_write_byte((uint8_t*)EEPROM_WIZARD_ACTIVE, 0);
  3697. end = true;
  3698. break;
  3699. default: break;
  3700. }
  3701. }
  3702. printf_P(_N("State: %d\n"), state);
  3703. switch (state) { //final message
  3704. case 0: //user dont want to use wizard
  3705. msg = _T(MSG_WIZARD_QUIT);
  3706. break;
  3707. case 1: //printer was already calibrated
  3708. msg = _T(MSG_WIZARD_DONE);
  3709. break;
  3710. case 2: //selftest
  3711. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3712. break;
  3713. case 3: //xyz cal.
  3714. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3715. break;
  3716. case 4: //z cal.
  3717. msg = _T(MSG_WIZARD_CALIBRATION_FAILED);
  3718. break;
  3719. case 8:
  3720. msg = _i("Please load PLA filament and then resume Wizard by rebooting the printer.");////MSG_WIZARD_INSERT_CORRECT_FILAMENT c=20 r=8
  3721. break;
  3722. case 9: break; //exit wizard for v2 calibration, which is implemted in lcd_commands (we need lcd_update running)
  3723. case 11: //we are finished
  3724. msg = _T(MSG_WIZARD_DONE);
  3725. lcd_reset_alert_level();
  3726. lcd_setstatuspgm(_T(WELCOME_MSG));
  3727. break;
  3728. default:
  3729. msg = _T(MSG_WIZARD_QUIT);
  3730. break;
  3731. }
  3732. if (state != 9) lcd_show_fullscreen_message_and_wait_P(msg);
  3733. lcd_update_enable(true);
  3734. lcd_return_to_status();
  3735. lcd_update(2);
  3736. }
  3737. static void lcd_settings_menu()
  3738. {
  3739. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  3740. MENU_BEGIN();
  3741. if (menu_item_back_P(_T(MSG_MAIN)))
  3742. {
  3743. lcd_settings_menu_back();
  3744. return;
  3745. }
  3746. MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE c=0 r=0
  3747. if (!homing_flag)
  3748. {
  3749. MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS c=0 r=0
  3750. }
  3751. if (!isPrintPaused)
  3752. {
  3753. MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=0 r=0
  3754. }
  3755. #ifndef TMC2130
  3756. if (!farm_mode) { //dont show in menu if we are in farm mode
  3757. switch (SilentModeMenu) {
  3758. case SILENT_MODE_POWER: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break;
  3759. case SILENT_MODE_SILENT: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break;
  3760. case SILENT_MODE_AUTO: MENU_ITEM_FUNCTION_P(_T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break;
  3761. default: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed
  3762. }
  3763. }
  3764. #endif //TMC2130
  3765. #ifdef PAT9125
  3766. #ifndef DEBUG_DISABLE_FSENSORCHECK
  3767. if (FSensorStateMenu == 0) {
  3768. if (fsensor_not_responding){
  3769. // Filament sensor not working
  3770. MENU_ITEM_FUNCTION_P(_i("Fil. sensor [N/A]"), lcd_fsensor_state_set);////MSG_FSENSOR_NA c=0 r=0
  3771. MENU_ITEM_SUBMENU_P(_T(MSG_FSENS_AUTOLOAD_NA), lcd_fsensor_fail);
  3772. }
  3773. else{
  3774. // Filament sensor turned off, working, no problems
  3775. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_OFF), lcd_fsensor_state_set);
  3776. MENU_ITEM_SUBMENU_P(_T(MSG_FSENS_AUTOLOAD_NA), lcd_filament_autoload_info);
  3777. }
  3778. } else {
  3779. // Filament sensor turned on, working, no problems
  3780. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set);
  3781. if (filament_autoload_enabled) {
  3782. MENU_ITEM_FUNCTION_P(_i("F. autoload [on]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_ON c=17 r=1
  3783. }
  3784. else {
  3785. MENU_ITEM_FUNCTION_P(_i("F. autoload [off]"), lcd_set_filament_autoload);////MSG_FSENS_AUTOLOAD_OFF c=17 r=1
  3786. }
  3787. }
  3788. #endif //DEBUG_DISABLE_FSENSORCHECK
  3789. #endif //PAT9125
  3790. if (fans_check_enabled == true) {
  3791. MENU_ITEM_FUNCTION_P(_i("Fans check [on]"), lcd_set_fan_check);////MSG_FANS_CHECK_ON c=17 r=1
  3792. }
  3793. else {
  3794. MENU_ITEM_FUNCTION_P(_i("Fans check [off]"), lcd_set_fan_check);////MSG_FANS_CHECK_OFF c=17 r=1
  3795. }
  3796. #ifdef TMC2130
  3797. if(!farm_mode)
  3798. {
  3799. if (SilentModeMenu == SILENT_MODE_NORMAL) { MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set); }
  3800. else MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set);
  3801. if (SilentModeMenu == SILENT_MODE_NORMAL)
  3802. {
  3803. if (CrashDetectMenu == 0) { MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set); }
  3804. else MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_ON), lcd_crash_mode_set);
  3805. }
  3806. else MENU_ITEM_SUBMENU_P(_T(MSG_CRASHDETECT_NA), lcd_crash_mode_info);
  3807. }
  3808. #ifdef TMC2130_LINEARITY_CORRECTION_XYZ
  3809. MENU_ITEM_EDIT(wfac, _i("X-correct"), &tmc2130_wave_fac[X_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_EXTRUDER_CORRECTION c=9 r=0
  3810. MENU_ITEM_EDIT(wfac, _i("Y-correct"), &tmc2130_wave_fac[Y_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_EXTRUDER_CORRECTION c=9 r=0
  3811. MENU_ITEM_EDIT(wfac, _i("Z-correct"), &tmc2130_wave_fac[Z_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_EXTRUDER_CORRECTION c=9 r=0
  3812. #endif //TMC2130_LINEARITY_CORRECTION_XYZ
  3813. MENU_ITEM_EDIT(wfac, _i("E-correct"), &tmc2130_wave_fac[E_AXIS], TMC2130_WAVE_FAC1000_MIN-TMC2130_WAVE_FAC1000_STP, TMC2130_WAVE_FAC1000_MAX);////MSG_EXTRUDER_CORRECTION c=9 r=0
  3814. #endif //TMC2130
  3815. if (temp_cal_active == false) {
  3816. MENU_ITEM_FUNCTION_P(_i("Temp. cal. [off]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_OFF c=20 r=1
  3817. }
  3818. else {
  3819. MENU_ITEM_FUNCTION_P(_i("Temp. cal. [on]"), lcd_temp_calibration_set);////MSG_TEMP_CALIBRATION_ON c=20 r=1
  3820. }
  3821. #ifdef HAS_SECOND_SERIAL_PORT
  3822. if (selectedSerialPort == 0) {
  3823. MENU_ITEM_FUNCTION_P(_i("RPi port [off]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_OFF c=17 r=1
  3824. }
  3825. else {
  3826. MENU_ITEM_FUNCTION_P(_i("RPi port [on]"), lcd_second_serial_set);////MSG_SECOND_SERIAL_ON c=17 r=1
  3827. }
  3828. #endif //HAS_SECOND_SERIAL
  3829. if (!isPrintPaused && !homing_flag)
  3830. {
  3831. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);
  3832. }
  3833. #if (LANG_MODE != 0)
  3834. MENU_ITEM_SUBMENU_P(_i("Select language"), lcd_language_menu);////MSG_LANGUAGE_SELECT c=0 r=0
  3835. #endif //(LANG_MODE != 0)
  3836. if (card.ToshibaFlashAir_isEnabled()) {
  3837. MENU_ITEM_FUNCTION_P(_i("SD card [FlshAir]"), lcd_toshiba_flash_air_compatibility_toggle);////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON c=19 r=1
  3838. } else {
  3839. MENU_ITEM_FUNCTION_P(_i("SD card [normal]"), lcd_toshiba_flash_air_compatibility_toggle);////MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF c=19 r=1
  3840. }
  3841. #ifdef SDCARD_SORT_ALPHA
  3842. if (!farm_mode) {
  3843. uint8_t sdSort;
  3844. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3845. switch (sdSort) {
  3846. case SD_SORT_TIME: MENU_ITEM_FUNCTION_P(_i("Sort: [Time]"), lcd_sort_type_set); break;////MSG_SORT_TIME c=17 r=1
  3847. case SD_SORT_ALPHA: MENU_ITEM_FUNCTION_P(_i("Sort: [Alphabet]"), lcd_sort_type_set); break;////MSG_SORT_ALPHA c=17 r=1
  3848. default: MENU_ITEM_FUNCTION_P(_i("Sort: [None]"), lcd_sort_type_set);////MSG_SORT_NONE c=17 r=1
  3849. }
  3850. }
  3851. #endif // SDCARD_SORT_ALPHA
  3852. if (farm_mode)
  3853. {
  3854. MENU_ITEM_SUBMENU_P(PSTR("Farm number"), lcd_farm_no);
  3855. MENU_ITEM_FUNCTION_P(PSTR("Disable farm mode"), lcd_disable_farm_mode);
  3856. }
  3857. MENU_END();
  3858. }
  3859. static void lcd_selftest_()
  3860. {
  3861. lcd_selftest();
  3862. }
  3863. #ifdef TMC2130
  3864. static void lcd_ustep_linearity_menu_save()
  3865. {
  3866. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC, tmc2130_wave_fac[X_AXIS]);
  3867. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC, tmc2130_wave_fac[Y_AXIS]);
  3868. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC, tmc2130_wave_fac[Z_AXIS]);
  3869. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC, tmc2130_wave_fac[E_AXIS]);
  3870. }
  3871. #endif //TMC2130
  3872. static void lcd_settings_menu_back()
  3873. {
  3874. #ifdef TMC2130
  3875. bool changed = false;
  3876. if (tmc2130_wave_fac[X_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[X_AXIS] = 0;
  3877. if (tmc2130_wave_fac[Y_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Y_AXIS] = 0;
  3878. if (tmc2130_wave_fac[Z_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[Z_AXIS] = 0;
  3879. if (tmc2130_wave_fac[E_AXIS] < TMC2130_WAVE_FAC1000_MIN) tmc2130_wave_fac[E_AXIS] = 0;
  3880. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_X_FAC) != tmc2130_wave_fac[X_AXIS]);
  3881. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Y_FAC) != tmc2130_wave_fac[Y_AXIS]);
  3882. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_Z_FAC) != tmc2130_wave_fac[Z_AXIS]);
  3883. changed |= (eeprom_read_byte((uint8_t*)EEPROM_TMC2130_WAVE_E_FAC) != tmc2130_wave_fac[E_AXIS]);
  3884. lcd_ustep_linearity_menu_save();
  3885. if (changed) tmc2130_init();
  3886. #endif //TMC2130
  3887. menu_menu = lcd_main_menu;
  3888. // lcd_main_menu();
  3889. }
  3890. static void lcd_calibration_menu()
  3891. {
  3892. MENU_BEGIN();
  3893. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  3894. if (!isPrintPaused)
  3895. {
  3896. MENU_ITEM_FUNCTION_P(_i("Wizard"), lcd_wizard);////MSG_WIZARD c=17 r=1
  3897. MENU_ITEM_SUBMENU_P(_i("First layer cal."), lcd_v2_calibration);////MSG_V2_CALIBRATION c=17 r=1
  3898. MENU_ITEM_GCODE_P(_T(MSG_AUTO_HOME), PSTR("G28 W"));
  3899. MENU_ITEM_FUNCTION_P(_i("Selftest "), lcd_selftest_v);////MSG_SELFTEST c=0 r=0
  3900. #ifdef MK1BP
  3901. // MK1
  3902. // "Calibrate Z"
  3903. MENU_ITEM_GCODE_P(_T(MSG_HOMEYZ), PSTR("G28 Z"));
  3904. #else //MK1BP
  3905. // MK2
  3906. MENU_ITEM_FUNCTION_P(_i("Calibrate XYZ"), lcd_mesh_calibration);////MSG_CALIBRATE_BED c=0 r=0
  3907. // "Calibrate Z" with storing the reference values to EEPROM.
  3908. MENU_ITEM_SUBMENU_P(_T(MSG_HOMEYZ), lcd_mesh_calibration_z);
  3909. #ifndef SNMM
  3910. //MENU_ITEM_FUNCTION_P(_i("Calibrate E"), lcd_calibrate_extruder);////MSG_CALIBRATE_E c=20 r=1
  3911. #endif
  3912. // "Mesh Bed Leveling"
  3913. MENU_ITEM_SUBMENU_P(_i("Mesh Bed Leveling"), lcd_mesh_bedleveling);////MSG_MESH_BED_LEVELING c=0 r=0
  3914. #endif //MK1BP
  3915. MENU_ITEM_SUBMENU_P(_i("Bed level correct"), lcd_adjust_bed);////MSG_BED_CORRECTION_MENU c=0 r=0
  3916. MENU_ITEM_SUBMENU_P(_i("PID calibration"), pid_extruder);////MSG_PID_EXTRUDER c=17 r=1
  3917. #ifndef TMC2130
  3918. MENU_ITEM_SUBMENU_P(_i("Show end stops"), menu_show_end_stops);////MSG_SHOW_END_STOPS c=17 r=1
  3919. #endif
  3920. #ifndef MK1BP
  3921. MENU_ITEM_GCODE_P(_i("Reset XYZ calibr."), PSTR("M44"));////MSG_CALIBRATE_BED_RESET c=0 r=0
  3922. #endif //MK1BP
  3923. #ifndef SNMM
  3924. //MENU_ITEM_FUNCTION_P(MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  3925. #endif
  3926. #ifndef MK1BP
  3927. MENU_ITEM_SUBMENU_P(_i("Temp. calibration"), lcd_pinda_calibration_menu);////MSG_CALIBRATION_PINDA_MENU c=17 r=1
  3928. #endif //MK1BP
  3929. }
  3930. MENU_END();
  3931. }
  3932. void bowden_menu() {
  3933. int enc_dif = encoderDiff;
  3934. int cursor_pos = 0;
  3935. lcd_implementation_clear();
  3936. lcd.setCursor(0, 0);
  3937. lcd.print(">");
  3938. for (int i = 0; i < 4; i++) {
  3939. lcd.setCursor(1, i);
  3940. lcd.print("Extruder ");
  3941. lcd.print(i);
  3942. lcd.print(": ");
  3943. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  3944. lcd.print(bowden_length[i] - 48);
  3945. }
  3946. enc_dif = encoderDiff;
  3947. while (1) {
  3948. manage_heater();
  3949. manage_inactivity(true);
  3950. if (abs((enc_dif - encoderDiff)) > 2) {
  3951. if (enc_dif > encoderDiff) {
  3952. cursor_pos--;
  3953. }
  3954. if (enc_dif < encoderDiff) {
  3955. cursor_pos++;
  3956. }
  3957. if (cursor_pos > 3) {
  3958. cursor_pos = 3;
  3959. }
  3960. if (cursor_pos < 0) {
  3961. cursor_pos = 0;
  3962. }
  3963. lcd.setCursor(0, 0);
  3964. lcd.print(" ");
  3965. lcd.setCursor(0, 1);
  3966. lcd.print(" ");
  3967. lcd.setCursor(0, 2);
  3968. lcd.print(" ");
  3969. lcd.setCursor(0, 3);
  3970. lcd.print(" ");
  3971. lcd.setCursor(0, cursor_pos);
  3972. lcd.print(">");
  3973. enc_dif = encoderDiff;
  3974. delay(100);
  3975. }
  3976. if (lcd_clicked()) {
  3977. while (lcd_clicked());
  3978. delay(10);
  3979. while (lcd_clicked());
  3980. lcd_implementation_clear();
  3981. while (1) {
  3982. manage_heater();
  3983. manage_inactivity(true);
  3984. lcd.setCursor(1, 1);
  3985. lcd.print("Extruder ");
  3986. lcd.print(cursor_pos);
  3987. lcd.print(": ");
  3988. lcd.setCursor(13, 1);
  3989. lcd.print(bowden_length[cursor_pos] - 48);
  3990. if (abs((enc_dif - encoderDiff)) > 2) {
  3991. if (enc_dif > encoderDiff) {
  3992. bowden_length[cursor_pos]--;
  3993. lcd.setCursor(13, 1);
  3994. lcd.print(bowden_length[cursor_pos] - 48);
  3995. enc_dif = encoderDiff;
  3996. }
  3997. if (enc_dif < encoderDiff) {
  3998. bowden_length[cursor_pos]++;
  3999. lcd.setCursor(13, 1);
  4000. lcd.print(bowden_length[cursor_pos] - 48);
  4001. enc_dif = encoderDiff;
  4002. }
  4003. }
  4004. delay(100);
  4005. if (lcd_clicked()) {
  4006. while (lcd_clicked());
  4007. delay(10);
  4008. while (lcd_clicked());
  4009. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  4010. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  4011. lcd_update_enable(true);
  4012. lcd_implementation_clear();
  4013. enc_dif = encoderDiff;
  4014. lcd.setCursor(0, cursor_pos);
  4015. lcd.print(">");
  4016. for (int i = 0; i < 4; i++) {
  4017. lcd.setCursor(1, i);
  4018. lcd.print("Extruder ");
  4019. lcd.print(i);
  4020. lcd.print(": ");
  4021. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  4022. lcd.print(bowden_length[i] - 48);
  4023. }
  4024. break;
  4025. }
  4026. else return;
  4027. }
  4028. }
  4029. }
  4030. }
  4031. }
  4032. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  4033. lcd_implementation_clear();
  4034. lcd_print_at_PGM(0,0,_T(MSG_UNLOAD_FILAMENT)); lcd.print(":");
  4035. lcd.setCursor(0, 1); lcd.print(">");
  4036. lcd_print_at_PGM(1,2,_i("Used during print"));////MSG_USED c=19 r=1
  4037. lcd_print_at_PGM(1,3,_i("Current"));////MSG_CURRENT c=19 r=1
  4038. char cursor_pos = 1;
  4039. int enc_dif = 0;
  4040. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4041. while (1) {
  4042. manage_heater();
  4043. manage_inactivity(true);
  4044. if (abs((enc_dif - encoderDiff)) > 4) {
  4045. if ((abs(enc_dif - encoderDiff)) > 1) {
  4046. if (enc_dif > encoderDiff) cursor_pos--;
  4047. if (enc_dif < encoderDiff) cursor_pos++;
  4048. if (cursor_pos > 3) cursor_pos = 3;
  4049. if (cursor_pos < 1) cursor_pos = 1;
  4050. lcd.setCursor(0, 1);
  4051. lcd.print(" ");
  4052. lcd.setCursor(0, 2);
  4053. lcd.print(" ");
  4054. lcd.setCursor(0, 3);
  4055. lcd.print(" ");
  4056. lcd.setCursor(0, cursor_pos);
  4057. lcd.print(">");
  4058. enc_dif = encoderDiff;
  4059. delay(100);
  4060. }
  4061. }
  4062. if (lcd_clicked()) {
  4063. while (lcd_clicked());
  4064. delay(10);
  4065. while (lcd_clicked());
  4066. KEEPALIVE_STATE(IN_HANDLER);
  4067. return(cursor_pos - 1);
  4068. }
  4069. }
  4070. }
  4071. char choose_extruder_menu() {
  4072. int items_no = 4;
  4073. int first = 0;
  4074. int enc_dif = 0;
  4075. char cursor_pos = 1;
  4076. enc_dif = encoderDiff;
  4077. lcd_implementation_clear();
  4078. lcd_printPGM(_T(MSG_CHOOSE_EXTRUDER));
  4079. lcd.setCursor(0, 1);
  4080. lcd.print(">");
  4081. for (int i = 0; i < 3; i++) {
  4082. lcd_print_at_PGM(1, i + 1, _T(MSG_EXTRUDER));
  4083. }
  4084. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4085. while (1) {
  4086. for (int i = 0; i < 3; i++) {
  4087. lcd.setCursor(2 + strlen_P(_T(MSG_EXTRUDER)), i+1);
  4088. lcd.print(first + i + 1);
  4089. }
  4090. manage_heater();
  4091. manage_inactivity(true);
  4092. if (abs((enc_dif - encoderDiff)) > 4) {
  4093. if ((abs(enc_dif - encoderDiff)) > 1) {
  4094. if (enc_dif > encoderDiff) {
  4095. cursor_pos--;
  4096. }
  4097. if (enc_dif < encoderDiff) {
  4098. cursor_pos++;
  4099. }
  4100. if (cursor_pos > 3) {
  4101. cursor_pos = 3;
  4102. if (first < items_no - 3) {
  4103. first++;
  4104. lcd_implementation_clear();
  4105. lcd_printPGM(_T(MSG_CHOOSE_EXTRUDER));
  4106. for (int i = 0; i < 3; i++) {
  4107. lcd_print_at_PGM(1, i + 1, _T(MSG_EXTRUDER));
  4108. }
  4109. }
  4110. }
  4111. if (cursor_pos < 1) {
  4112. cursor_pos = 1;
  4113. if (first > 0) {
  4114. first--;
  4115. lcd_implementation_clear();
  4116. lcd_printPGM(_T(MSG_CHOOSE_EXTRUDER));
  4117. for (int i = 0; i < 3; i++) {
  4118. lcd_print_at_PGM(1, i + 1, _T(MSG_EXTRUDER));
  4119. }
  4120. }
  4121. }
  4122. lcd.setCursor(0, 1);
  4123. lcd.print(" ");
  4124. lcd.setCursor(0, 2);
  4125. lcd.print(" ");
  4126. lcd.setCursor(0, 3);
  4127. lcd.print(" ");
  4128. lcd.setCursor(0, cursor_pos);
  4129. lcd.print(">");
  4130. enc_dif = encoderDiff;
  4131. delay(100);
  4132. }
  4133. }
  4134. if (lcd_clicked()) {
  4135. lcd_update(2);
  4136. while (lcd_clicked());
  4137. delay(10);
  4138. while (lcd_clicked());
  4139. KEEPALIVE_STATE(IN_HANDLER);
  4140. return(cursor_pos + first - 1);
  4141. }
  4142. }
  4143. }
  4144. char reset_menu() {
  4145. #ifdef SNMM
  4146. int items_no = 5;
  4147. #else
  4148. int items_no = 4;
  4149. #endif
  4150. static int first = 0;
  4151. int enc_dif = 0;
  4152. char cursor_pos = 0;
  4153. const char *item [items_no];
  4154. item[0] = "Language";
  4155. item[1] = "Statistics";
  4156. item[2] = "Shipping prep";
  4157. item[3] = "All Data";
  4158. #ifdef SNMM
  4159. item[4] = "Bowden length";
  4160. #endif // SNMM
  4161. enc_dif = encoderDiff;
  4162. lcd_implementation_clear();
  4163. lcd.setCursor(0, 0);
  4164. lcd.print(">");
  4165. while (1) {
  4166. for (int i = 0; i < 4; i++) {
  4167. lcd.setCursor(1, i);
  4168. lcd.print(item[first + i]);
  4169. }
  4170. manage_heater();
  4171. manage_inactivity(true);
  4172. if (abs((enc_dif - encoderDiff)) > 4) {
  4173. if ((abs(enc_dif - encoderDiff)) > 1) {
  4174. if (enc_dif > encoderDiff) {
  4175. cursor_pos--;
  4176. }
  4177. if (enc_dif < encoderDiff) {
  4178. cursor_pos++;
  4179. }
  4180. if (cursor_pos > 3) {
  4181. cursor_pos = 3;
  4182. if (first < items_no - 4) {
  4183. first++;
  4184. lcd_implementation_clear();
  4185. }
  4186. }
  4187. if (cursor_pos < 0) {
  4188. cursor_pos = 0;
  4189. if (first > 0) {
  4190. first--;
  4191. lcd_implementation_clear();
  4192. }
  4193. }
  4194. lcd.setCursor(0, 0);
  4195. lcd.print(" ");
  4196. lcd.setCursor(0, 1);
  4197. lcd.print(" ");
  4198. lcd.setCursor(0, 2);
  4199. lcd.print(" ");
  4200. lcd.setCursor(0, 3);
  4201. lcd.print(" ");
  4202. lcd.setCursor(0, cursor_pos);
  4203. lcd.print(">");
  4204. enc_dif = encoderDiff;
  4205. delay(100);
  4206. }
  4207. }
  4208. if (lcd_clicked()) {
  4209. while (lcd_clicked());
  4210. delay(10);
  4211. while (lcd_clicked());
  4212. return(cursor_pos + first);
  4213. }
  4214. }
  4215. }
  4216. static void lcd_disable_farm_mode()
  4217. {
  4218. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  4219. if (disable)
  4220. {
  4221. enquecommand_P(PSTR("G99"));
  4222. lcd_return_to_status();
  4223. }
  4224. lcd_update_enable(true);
  4225. lcdDrawUpdate = 2;
  4226. }
  4227. #ifdef SNMM
  4228. static void extr_mov(float shift, float feed_rate) { //move extruder no matter what the current heater temperature is
  4229. set_extrude_min_temp(.0);
  4230. current_position[E_AXIS] += shift;
  4231. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feed_rate, active_extruder);
  4232. set_extrude_min_temp(EXTRUDE_MINTEMP);
  4233. }
  4234. void change_extr(int extr) { //switches multiplexer for extruders
  4235. st_synchronize();
  4236. delay(100);
  4237. disable_e0();
  4238. disable_e1();
  4239. disable_e2();
  4240. snmm_extruder = extr;
  4241. pinMode(E_MUX0_PIN, OUTPUT);
  4242. pinMode(E_MUX1_PIN, OUTPUT);
  4243. switch (extr) {
  4244. case 1:
  4245. WRITE(E_MUX0_PIN, HIGH);
  4246. WRITE(E_MUX1_PIN, LOW);
  4247. break;
  4248. case 2:
  4249. WRITE(E_MUX0_PIN, LOW);
  4250. WRITE(E_MUX1_PIN, HIGH);
  4251. break;
  4252. case 3:
  4253. WRITE(E_MUX0_PIN, HIGH);
  4254. WRITE(E_MUX1_PIN, HIGH);
  4255. break;
  4256. default:
  4257. WRITE(E_MUX0_PIN, LOW);
  4258. WRITE(E_MUX1_PIN, LOW);
  4259. break;
  4260. }
  4261. delay(100);
  4262. }
  4263. static int get_ext_nr() { //reads multiplexer input pins and return current extruder number (counted from 0)
  4264. return(2 * READ(E_MUX1_PIN) + READ(E_MUX0_PIN));
  4265. }
  4266. void display_loading() {
  4267. switch (snmm_extruder) {
  4268. case 1: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T1)); break;
  4269. case 2: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T2)); break;
  4270. case 3: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T3)); break;
  4271. default: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T0)); break;
  4272. }
  4273. }
  4274. void extr_adj(int extruder) //loading filament for SNMM
  4275. {
  4276. bool correct;
  4277. max_feedrate[E_AXIS] =80;
  4278. //max_feedrate[E_AXIS] = 50;
  4279. START:
  4280. lcd_implementation_clear();
  4281. lcd.setCursor(0, 0);
  4282. switch (extruder) {
  4283. case 1: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T1)); break;
  4284. case 2: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T2)); break;
  4285. case 3: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T3)); break;
  4286. default: lcd_display_message_fullscreen_P(_T(MSG_FILAMENT_LOADING_T0)); break;
  4287. }
  4288. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4289. do{
  4290. extr_mov(0.001,1000);
  4291. delay_keep_alive(2);
  4292. } while (!lcd_clicked());
  4293. //delay_keep_alive(500);
  4294. KEEPALIVE_STATE(IN_HANDLER);
  4295. st_synchronize();
  4296. //correct = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FIL_LOADED_CHECK, false);
  4297. //if (!correct) goto START;
  4298. //extr_mov(BOWDEN_LENGTH/2.f, 500); //dividing by 2 is there because of max. extrusion length limitation (x_max + y_max)
  4299. //extr_mov(BOWDEN_LENGTH/2.f, 500);
  4300. extr_mov(bowden_length[extruder], 500);
  4301. lcd_implementation_clear();
  4302. lcd.setCursor(0, 0); lcd_printPGM(_T(MSG_LOADING_FILAMENT));
  4303. if(strlen(_T(MSG_LOADING_FILAMENT))>18) lcd.setCursor(0, 1);
  4304. else lcd.print(" ");
  4305. lcd.print(snmm_extruder + 1);
  4306. lcd.setCursor(0, 2); lcd_printPGM(_T(MSG_PLEASE_WAIT));
  4307. st_synchronize();
  4308. max_feedrate[E_AXIS] = 50;
  4309. lcd_update_enable(true);
  4310. lcd_return_to_status();
  4311. lcdDrawUpdate = 2;
  4312. }
  4313. void extr_unload() { //unloads filament
  4314. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  4315. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  4316. uint8_t SilentMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT);
  4317. if (degHotend0() > EXTRUDE_MINTEMP) {
  4318. lcd_implementation_clear();
  4319. lcd_display_message_fullscreen_P(PSTR(""));
  4320. max_feedrate[E_AXIS] = 50;
  4321. lcd.setCursor(0, 0); lcd_printPGM(_T(MSG_UNLOADING_FILAMENT));
  4322. lcd.print(" ");
  4323. lcd.print(snmm_extruder + 1);
  4324. lcd.setCursor(0, 2); lcd_printPGM(_T(MSG_PLEASE_WAIT));
  4325. if (current_position[Z_AXIS] < 15) {
  4326. current_position[Z_AXIS] += 15; //lifting in Z direction to make space for extrusion
  4327. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 25, active_extruder);
  4328. }
  4329. current_position[E_AXIS] += 10; //extrusion
  4330. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 10, active_extruder);
  4331. st_current_set(2, E_MOTOR_HIGH_CURRENT);
  4332. if (current_temperature[0] < 230) { //PLA & all other filaments
  4333. current_position[E_AXIS] += 5.4;
  4334. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2800 / 60, active_extruder);
  4335. current_position[E_AXIS] += 3.2;
  4336. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  4337. current_position[E_AXIS] += 3;
  4338. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3400 / 60, active_extruder);
  4339. }
  4340. else { //ABS
  4341. current_position[E_AXIS] += 3.1;
  4342. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder);
  4343. current_position[E_AXIS] += 3.1;
  4344. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  4345. current_position[E_AXIS] += 4;
  4346. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  4347. /*current_position[X_AXIS] += 23; //delay
  4348. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay
  4349. current_position[X_AXIS] -= 23; //delay
  4350. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay*/
  4351. delay_keep_alive(4700);
  4352. }
  4353. max_feedrate[E_AXIS] = 80;
  4354. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  4355. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  4356. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  4357. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  4358. st_synchronize();
  4359. //st_current_init();
  4360. if (SilentMode != SILENT_MODE_OFF) st_current_set(2, tmp_motor[2]); //set back to normal operation currents
  4361. else st_current_set(2, tmp_motor_loud[2]);
  4362. lcd_update_enable(true);
  4363. lcd_return_to_status();
  4364. max_feedrate[E_AXIS] = 50;
  4365. }
  4366. else {
  4367. lcd_implementation_clear();
  4368. lcd.setCursor(0, 0);
  4369. lcd_printPGM(_T(MSG_ERROR));
  4370. lcd.setCursor(0, 2);
  4371. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  4372. delay(2000);
  4373. lcd_implementation_clear();
  4374. }
  4375. lcd_return_to_status();
  4376. }
  4377. //wrapper functions for loading filament
  4378. static void extr_adj_0(){
  4379. change_extr(0);
  4380. extr_adj(0);
  4381. }
  4382. static void extr_adj_1() {
  4383. change_extr(1);
  4384. extr_adj(1);
  4385. }
  4386. static void extr_adj_2() {
  4387. change_extr(2);
  4388. extr_adj(2);
  4389. }
  4390. static void extr_adj_3() {
  4391. change_extr(3);
  4392. extr_adj(3);
  4393. }
  4394. static void load_all() {
  4395. for (int i = 0; i < 4; i++) {
  4396. change_extr(i);
  4397. extr_adj(i);
  4398. }
  4399. }
  4400. //wrapper functions for changing extruders
  4401. static void extr_change_0() {
  4402. change_extr(0);
  4403. lcd_return_to_status();
  4404. }
  4405. static void extr_change_1() {
  4406. change_extr(1);
  4407. lcd_return_to_status();
  4408. }
  4409. static void extr_change_2() {
  4410. change_extr(2);
  4411. lcd_return_to_status();
  4412. }
  4413. static void extr_change_3() {
  4414. change_extr(3);
  4415. lcd_return_to_status();
  4416. }
  4417. //wrapper functions for unloading filament
  4418. void extr_unload_all() {
  4419. if (degHotend0() > EXTRUDE_MINTEMP) {
  4420. for (int i = 0; i < 4; i++) {
  4421. change_extr(i);
  4422. extr_unload();
  4423. }
  4424. }
  4425. else {
  4426. lcd_implementation_clear();
  4427. lcd.setCursor(0, 0);
  4428. lcd_printPGM(_T(MSG_ERROR));
  4429. lcd.setCursor(0, 2);
  4430. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  4431. delay(2000);
  4432. lcd_implementation_clear();
  4433. lcd_return_to_status();
  4434. }
  4435. }
  4436. //unloading just used filament (for snmm)
  4437. void extr_unload_used() {
  4438. if (degHotend0() > EXTRUDE_MINTEMP) {
  4439. for (int i = 0; i < 4; i++) {
  4440. if (snmm_filaments_used & (1 << i)) {
  4441. change_extr(i);
  4442. extr_unload();
  4443. }
  4444. }
  4445. snmm_filaments_used = 0;
  4446. }
  4447. else {
  4448. lcd_implementation_clear();
  4449. lcd.setCursor(0, 0);
  4450. lcd_printPGM(_T(MSG_ERROR));
  4451. lcd.setCursor(0, 2);
  4452. lcd_printPGM(_T(MSG_PREHEAT_NOZZLE));
  4453. delay(2000);
  4454. lcd_implementation_clear();
  4455. lcd_return_to_status();
  4456. }
  4457. }
  4458. static void extr_unload_0() {
  4459. change_extr(0);
  4460. extr_unload();
  4461. }
  4462. static void extr_unload_1() {
  4463. change_extr(1);
  4464. extr_unload();
  4465. }
  4466. static void extr_unload_2() {
  4467. change_extr(2);
  4468. extr_unload();
  4469. }
  4470. static void extr_unload_3() {
  4471. change_extr(3);
  4472. extr_unload();
  4473. }
  4474. static void fil_load_menu()
  4475. {
  4476. MENU_BEGIN();
  4477. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4478. MENU_ITEM_FUNCTION_P(_i("Load all"), load_all);////MSG_LOAD_ALL c=0 r=0
  4479. MENU_ITEM_FUNCTION_P(_i("Load filament 1"), extr_adj_0);////MSG_LOAD_FILAMENT_1 c=17 r=0
  4480. MENU_ITEM_FUNCTION_P(_i("Load filament 2"), extr_adj_1);////MSG_LOAD_FILAMENT_2 c=17 r=0
  4481. MENU_ITEM_FUNCTION_P(_i("Load filament 3"), extr_adj_2);////MSG_LOAD_FILAMENT_3 c=17 r=0
  4482. MENU_ITEM_FUNCTION_P(_i("Load filament 4"), extr_adj_3);////MSG_LOAD_FILAMENT_4 c=17 r=0
  4483. MENU_END();
  4484. }
  4485. static void fil_unload_menu()
  4486. {
  4487. MENU_BEGIN();
  4488. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4489. MENU_ITEM_FUNCTION_P(_i("Unload all"), extr_unload_all);////MSG_UNLOAD_ALL c=0 r=0
  4490. MENU_ITEM_FUNCTION_P(_i("Unload filament 1"), extr_unload_0);////MSG_UNLOAD_FILAMENT_1 c=17 r=0
  4491. MENU_ITEM_FUNCTION_P(_i("Unload filament 2"), extr_unload_1);////MSG_UNLOAD_FILAMENT_2 c=17 r=0
  4492. MENU_ITEM_FUNCTION_P(_i("Unload filament 3"), extr_unload_2);////MSG_UNLOAD_FILAMENT_3 c=17 r=0
  4493. MENU_ITEM_FUNCTION_P(_i("Unload filament 4"), extr_unload_3);////MSG_UNLOAD_FILAMENT_4 c=17 r=0
  4494. MENU_END();
  4495. }
  4496. static void change_extr_menu(){
  4497. MENU_BEGIN();
  4498. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  4499. MENU_ITEM_FUNCTION_P(_i("Extruder 1"), extr_change_0);////MSG_EXTRUDER_1 c=17 r=1
  4500. MENU_ITEM_FUNCTION_P(_i("Extruder 2"), extr_change_1);////MSG_EXTRUDER_2 c=17 r=1
  4501. MENU_ITEM_FUNCTION_P(_i("Extruder 3"), extr_change_2);////MSG_EXTRUDER_3 c=17 r=1
  4502. MENU_ITEM_FUNCTION_P(_i("Extruder 4"), extr_change_3);////MSG_EXTRUDER_4 c=17 r=1
  4503. MENU_END();
  4504. }
  4505. #endif
  4506. static void lcd_farm_no()
  4507. {
  4508. char step = 0;
  4509. int enc_dif = 0;
  4510. int _farmno = farm_no;
  4511. int _ret = 0;
  4512. lcd_implementation_clear();
  4513. lcd.setCursor(0, 0);
  4514. lcd.print("Farm no");
  4515. do
  4516. {
  4517. if (abs((enc_dif - encoderDiff)) > 2) {
  4518. if (enc_dif > encoderDiff) {
  4519. switch (step) {
  4520. case(0): if (_farmno >= 100) _farmno -= 100; break;
  4521. case(1): if (_farmno % 100 >= 10) _farmno -= 10; break;
  4522. case(2): if (_farmno % 10 >= 1) _farmno--; break;
  4523. default: break;
  4524. }
  4525. }
  4526. if (enc_dif < encoderDiff) {
  4527. switch (step) {
  4528. case(0): if (_farmno < 900) _farmno += 100; break;
  4529. case(1): if (_farmno % 100 < 90) _farmno += 10; break;
  4530. case(2): if (_farmno % 10 <= 8)_farmno++; break;
  4531. default: break;
  4532. }
  4533. }
  4534. enc_dif = 0;
  4535. encoderDiff = 0;
  4536. }
  4537. lcd.setCursor(0, 2);
  4538. if (_farmno < 100) lcd.print("0");
  4539. if (_farmno < 10) lcd.print("0");
  4540. lcd.print(_farmno);
  4541. lcd.print(" ");
  4542. lcd.setCursor(0, 3);
  4543. lcd.print(" ");
  4544. lcd.setCursor(step, 3);
  4545. lcd.print("^");
  4546. delay(100);
  4547. if (lcd_clicked())
  4548. {
  4549. delay(200);
  4550. step++;
  4551. if(step == 3) {
  4552. _ret = 1;
  4553. farm_no = _farmno;
  4554. EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
  4555. prusa_statistics(20);
  4556. lcd_return_to_status();
  4557. }
  4558. }
  4559. manage_heater();
  4560. } while (_ret == 0);
  4561. }
  4562. unsigned char lcd_choose_color() {
  4563. //function returns index of currently chosen item
  4564. //following part can be modified from 2 to 255 items:
  4565. //-----------------------------------------------------
  4566. unsigned char items_no = 2;
  4567. const char *item[items_no];
  4568. item[0] = "Orange";
  4569. item[1] = "Black";
  4570. //-----------------------------------------------------
  4571. unsigned char active_rows;
  4572. static int first = 0;
  4573. int enc_dif = 0;
  4574. unsigned char cursor_pos = 1;
  4575. enc_dif = encoderDiff;
  4576. lcd_implementation_clear();
  4577. lcd.setCursor(0, 1);
  4578. lcd.print(">");
  4579. active_rows = items_no < 3 ? items_no : 3;
  4580. while (1) {
  4581. lcd_print_at_PGM(0, 0, PSTR("Choose color:"));
  4582. for (int i = 0; i < active_rows; i++) {
  4583. lcd.setCursor(1, i+1);
  4584. lcd.print(item[first + i]);
  4585. }
  4586. manage_heater();
  4587. manage_inactivity(true);
  4588. proc_commands();
  4589. if (abs((enc_dif - encoderDiff)) > 12) {
  4590. if (enc_dif > encoderDiff) {
  4591. cursor_pos--;
  4592. }
  4593. if (enc_dif < encoderDiff) {
  4594. cursor_pos++;
  4595. }
  4596. if (cursor_pos > active_rows) {
  4597. cursor_pos = active_rows;
  4598. if (first < items_no - active_rows) {
  4599. first++;
  4600. lcd_implementation_clear();
  4601. }
  4602. }
  4603. if (cursor_pos < 1) {
  4604. cursor_pos = 1;
  4605. if (first > 0) {
  4606. first--;
  4607. lcd_implementation_clear();
  4608. }
  4609. }
  4610. lcd.setCursor(0, 1);
  4611. lcd.print(" ");
  4612. lcd.setCursor(0, 2);
  4613. lcd.print(" ");
  4614. lcd.setCursor(0, 3);
  4615. lcd.print(" ");
  4616. lcd.setCursor(0, cursor_pos);
  4617. lcd.print(">");
  4618. enc_dif = encoderDiff;
  4619. delay(100);
  4620. }
  4621. if (lcd_clicked()) {
  4622. while (lcd_clicked());
  4623. delay(10);
  4624. while (lcd_clicked());
  4625. switch(cursor_pos + first - 1) {
  4626. case 0: return 1; break;
  4627. case 1: return 0; break;
  4628. default: return 99; break;
  4629. }
  4630. }
  4631. }
  4632. }
  4633. void lcd_confirm_print()
  4634. {
  4635. uint8_t filament_type;
  4636. int enc_dif = 0;
  4637. int cursor_pos = 1;
  4638. int _ret = 0;
  4639. int _t = 0;
  4640. enc_dif = encoderDiff;
  4641. lcd_implementation_clear();
  4642. lcd.setCursor(0, 0);
  4643. lcd.print("Print ok ?");
  4644. do
  4645. {
  4646. if (abs(enc_dif - encoderDiff) > 12) {
  4647. if (enc_dif > encoderDiff) {
  4648. cursor_pos--;
  4649. }
  4650. if (enc_dif < encoderDiff) {
  4651. cursor_pos++;
  4652. }
  4653. enc_dif = encoderDiff;
  4654. }
  4655. if (cursor_pos > 2) { cursor_pos = 2; }
  4656. if (cursor_pos < 1) { cursor_pos = 1; }
  4657. lcd.setCursor(0, 2); lcd.print(" ");
  4658. lcd.setCursor(0, 3); lcd.print(" ");
  4659. lcd.setCursor(2, 2);
  4660. lcd_printPGM(_T(MSG_YES));
  4661. lcd.setCursor(2, 3);
  4662. lcd_printPGM(_T(MSG_NO));
  4663. lcd.setCursor(0, 1 + cursor_pos);
  4664. lcd.print(">");
  4665. delay(100);
  4666. _t = _t + 1;
  4667. if (_t>100)
  4668. {
  4669. prusa_statistics(99);
  4670. _t = 0;
  4671. }
  4672. if (lcd_clicked())
  4673. {
  4674. if (cursor_pos == 1)
  4675. {
  4676. _ret = 1;
  4677. filament_type = lcd_choose_color();
  4678. prusa_statistics(4, filament_type);
  4679. no_response = true; //we need confirmation by recieving PRUSA thx
  4680. important_status = 4;
  4681. saved_filament_type = filament_type;
  4682. NcTime = millis();
  4683. }
  4684. if (cursor_pos == 2)
  4685. {
  4686. _ret = 2;
  4687. filament_type = lcd_choose_color();
  4688. prusa_statistics(5, filament_type);
  4689. no_response = true; //we need confirmation by recieving PRUSA thx
  4690. important_status = 5;
  4691. saved_filament_type = filament_type;
  4692. NcTime = millis();
  4693. }
  4694. }
  4695. manage_heater();
  4696. manage_inactivity();
  4697. proc_commands();
  4698. } while (_ret == 0);
  4699. }
  4700. #include "w25x20cl.h"
  4701. static void lcd_test_menu()
  4702. {
  4703. W25X20CL_SPI_ENTER();
  4704. w25x20cl_enable_wr();
  4705. w25x20cl_chip_erase();
  4706. w25x20cl_disable_wr();
  4707. }
  4708. static void lcd_main_menu()
  4709. {
  4710. MENU_BEGIN();
  4711. // Majkl superawesome menu
  4712. MENU_ITEM_BACK_P(_T(MSG_WATCH));
  4713. #ifdef RESUME_DEBUG
  4714. if (!saved_printing)
  4715. MENU_ITEM_FUNCTION_P(PSTR("tst - Save"), lcd_menu_test_save);
  4716. else
  4717. MENU_ITEM_FUNCTION_P(PSTR("tst - Restore"), lcd_menu_test_restore);
  4718. #endif //RESUME_DEBUG
  4719. #ifdef TMC2130_DEBUG
  4720. MENU_ITEM_FUNCTION_P(PSTR("recover print"), recover_print);
  4721. MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_);
  4722. #endif //TMC2130_DEBUG
  4723. /* if (farm_mode && !IS_SD_PRINTING )
  4724. {
  4725. int tempScrool = 0;
  4726. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  4727. //delay(100);
  4728. return; // nothing to do (so don't thrash the SD card)
  4729. uint16_t fileCnt = card.getnrfilenames();
  4730. card.getWorkDirName();
  4731. if (card.filename[0] == '/')
  4732. {
  4733. #if SDCARDDETECT == -1
  4734. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  4735. #endif
  4736. } else {
  4737. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  4738. }
  4739. for (uint16_t i = 0; i < fileCnt; i++)
  4740. {
  4741. if (menu_item == menu_line)
  4742. {
  4743. #ifndef SDCARD_RATHERRECENTFIRST
  4744. card.getfilename(i);
  4745. #else
  4746. card.getfilename(fileCnt - 1 - i);
  4747. #endif
  4748. if (card.filenameIsDir)
  4749. {
  4750. MENU_ITEM_SDDIR(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  4751. } else {
  4752. MENU_ITEM_SDFILE(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  4753. }
  4754. } else {
  4755. MENU_ITEM_DUMMY();
  4756. }
  4757. }
  4758. MENU_ITEM_BACK_P(PSTR("- - - - - - - - -"));
  4759. }*/
  4760. if ( ( IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag)
  4761. {
  4762. MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8
  4763. }
  4764. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4765. {
  4766. MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE c=0 r=0
  4767. } else
  4768. {
  4769. MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT c=0 r=0
  4770. }
  4771. #ifdef SDSUPPORT
  4772. if (card.cardOK || lcd_commands_type == LCD_COMMAND_V2_CAL)
  4773. {
  4774. if (card.isFileOpen())
  4775. {
  4776. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  4777. if (card.sdprinting)
  4778. {
  4779. MENU_ITEM_FUNCTION_P(_i("Pause print"), lcd_sdcard_pause);////MSG_PAUSE_PRINT c=0 r=0
  4780. }
  4781. else
  4782. {
  4783. MENU_ITEM_FUNCTION_P(_i("Resume print"), lcd_sdcard_resume);////MSG_RESUME_PRINT c=0 r=0
  4784. }
  4785. MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4786. }
  4787. }
  4788. else if (lcd_commands_type == LCD_COMMAND_V2_CAL && mesh_bed_leveling_flag == false && homing_flag == false) {
  4789. //MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
  4790. }
  4791. else
  4792. {
  4793. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4794. {
  4795. //if (farm_mode) MENU_ITEM_SUBMENU_P(MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  4796. /*else*/ MENU_ITEM_SUBMENU_P(_T(MSG_CARD_MENU), lcd_sdcard_menu);
  4797. }
  4798. #if SDCARDDETECT < 1
  4799. MENU_ITEM_GCODE_P(_i("Change SD card"), PSTR("M21")); // SD-card changed by user////MSG_CNG_SDCARD c=0 r=0
  4800. #endif
  4801. }
  4802. } else
  4803. {
  4804. MENU_ITEM_SUBMENU_P(_i("No SD card"), lcd_sdcard_menu);////MSG_NO_CARD c=0 r=0
  4805. #if SDCARDDETECT < 1
  4806. MENU_ITEM_GCODE_P(_i("Init. SD card"), PSTR("M21")); // Manually initialize the SD-card via user interface////MSG_INIT_SDCARD c=0 r=0
  4807. #endif
  4808. }
  4809. #endif
  4810. if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL))
  4811. {
  4812. if (farm_mode)
  4813. {
  4814. MENU_ITEM_SUBMENU_P(PSTR("Farm number"), lcd_farm_no);
  4815. }
  4816. }
  4817. else
  4818. {
  4819. #ifndef SNMM
  4820. #ifdef PAT9125
  4821. if ( ((filament_autoload_enabled == true) && (fsensor_enabled == true)))
  4822. MENU_ITEM_SUBMENU_P(_i("AutoLoad filament"), lcd_menu_AutoLoadFilament);////MSG_AUTOLOAD_FILAMENT c=17 r=0
  4823. else
  4824. #endif //PAT9125
  4825. MENU_ITEM_FUNCTION_P(_T(MSG_LOAD_FILAMENT), lcd_LoadFilament);
  4826. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), lcd_unLoadFilament);
  4827. #endif
  4828. #ifdef SNMM
  4829. MENU_ITEM_SUBMENU_P(_T(MSG_LOAD_FILAMENT), fil_load_menu);
  4830. MENU_ITEM_SUBMENU_P(_T(MSG_UNLOAD_FILAMENT), fil_unload_menu);
  4831. MENU_ITEM_SUBMENU_P(_i("Change extruder"), change_extr_menu);////MSG_CHANGE_EXTR c=20 r=1
  4832. #endif
  4833. MENU_ITEM_SUBMENU_P(_T(MSG_SETTINGS), lcd_settings_menu);
  4834. if(!isPrintPaused) MENU_ITEM_SUBMENU_P(_T(MSG_MENU_CALIBRATION), lcd_calibration_menu);
  4835. }
  4836. if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL))
  4837. {
  4838. MENU_ITEM_SUBMENU_P(_i("Statistics "), lcd_menu_statistics);////MSG_STATISTICS c=0 r=0
  4839. }
  4840. #if defined(TMC2130) || defined(PAT9125)
  4841. MENU_ITEM_SUBMENU_P(PSTR("Fail stats"), lcd_menu_fails_stats);
  4842. #endif
  4843. MENU_ITEM_SUBMENU_P(_i("Support"), lcd_support_menu);////MSG_SUPPORT c=0 r=0
  4844. // MENU_ITEM_SUBMENU_P(_i("W25x20CL init"), lcd_test_menu);////MSG_SUPPORT c=0 r=0
  4845. MENU_END();
  4846. }
  4847. void stack_error() {
  4848. SET_OUTPUT(BEEPER);
  4849. WRITE(BEEPER, HIGH);
  4850. delay(1000);
  4851. WRITE(BEEPER, LOW);
  4852. lcd_display_message_fullscreen_P(_i("Error - static memory has been overwritten"));////MSG_STACK_ERROR c=20 r=4
  4853. //err_triggered = 1;
  4854. while (1) delay_keep_alive(1000);
  4855. }
  4856. #ifdef DEBUG_STEPPER_TIMER_MISSED
  4857. bool stepper_timer_overflow_state = false;
  4858. uint16_t stepper_timer_overflow_max = 0;
  4859. uint16_t stepper_timer_overflow_last = 0;
  4860. uint16_t stepper_timer_overflow_cnt = 0;
  4861. void stepper_timer_overflow() {
  4862. char msg[28];
  4863. sprintf_P(msg, PSTR("#%d %d max %d"), ++ stepper_timer_overflow_cnt, stepper_timer_overflow_last >> 1, stepper_timer_overflow_max >> 1);
  4864. lcd_setstatus(msg);
  4865. stepper_timer_overflow_state = false;
  4866. if (stepper_timer_overflow_last > stepper_timer_overflow_max)
  4867. stepper_timer_overflow_max = stepper_timer_overflow_last;
  4868. SERIAL_ECHOPGM("Stepper timer overflow: ");
  4869. MYSERIAL.print(msg);
  4870. SERIAL_ECHOLNPGM("");
  4871. WRITE(BEEPER, LOW);
  4872. }
  4873. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  4874. #ifdef SDSUPPORT
  4875. static void lcd_autostart_sd()
  4876. {
  4877. card.lastnr = 0;
  4878. card.setroot();
  4879. card.checkautostart(true);
  4880. }
  4881. #endif
  4882. static void lcd_silent_mode_set_tune() {
  4883. switch (SilentModeMenu) {
  4884. #ifdef TMC2130
  4885. case SILENT_MODE_NORMAL: SilentModeMenu = SILENT_MODE_STEALTH; break;
  4886. case SILENT_MODE_STEALTH: SilentModeMenu = SILENT_MODE_NORMAL; break;
  4887. default: SilentModeMenu = SILENT_MODE_NORMAL; break; // (probably) not needed
  4888. #else
  4889. case SILENT_MODE_POWER: SilentModeMenu = SILENT_MODE_SILENT; break;
  4890. case SILENT_MODE_SILENT: SilentModeMenu = SILENT_MODE_AUTO; break;
  4891. case SILENT_MODE_AUTO: SilentModeMenu = SILENT_MODE_POWER; break;
  4892. default: SilentModeMenu = SILENT_MODE_POWER; break; // (probably) not needed
  4893. #endif //TMC2130
  4894. }
  4895. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  4896. st_current_init();
  4897. menu_back();
  4898. }
  4899. static void lcd_colorprint_change() {
  4900. enquecommand_P(PSTR("M600"));
  4901. custom_message = true;
  4902. custom_message_type = 2; //just print status message
  4903. lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
  4904. lcd_return_to_status();
  4905. lcdDrawUpdate = 3;
  4906. }
  4907. static void lcd_tune_menu()
  4908. {
  4909. if (menuData.tuneMenu.status == 0) {
  4910. // Menu was entered. Mark the menu as entered and save the current extrudemultiply value.
  4911. menuData.tuneMenu.status = 1;
  4912. menuData.tuneMenu.extrudemultiply = extrudemultiply;
  4913. } else if (menuData.tuneMenu.extrudemultiply != extrudemultiply) {
  4914. // extrudemultiply has been changed from the child menu. Apply the new value.
  4915. menuData.tuneMenu.extrudemultiply = extrudemultiply;
  4916. calculate_extruder_multipliers();
  4917. }
  4918. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  4919. MENU_BEGIN();
  4920. MENU_ITEM_BACK_P(_T(MSG_MAIN)); //1
  4921. MENU_ITEM_EDIT(int3, _i("Speed"), &feedmultiply, 10, 999);//2////MSG_SPEED c=0 r=0
  4922. MENU_ITEM_EDIT(int3, _T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  4923. MENU_ITEM_EDIT(int3, _T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  4924. MENU_ITEM_EDIT(int3, _T(MSG_FAN_SPEED), &fanSpeed, 0, 255);//5
  4925. MENU_ITEM_EDIT(int3, _i("Flow"), &extrudemultiply, 10, 999);//6////MSG_FLOW c=0 r=0
  4926. #ifdef FILAMENTCHANGEENABLE
  4927. MENU_ITEM_FUNCTION_P(_T(MSG_FILAMENTCHANGE), lcd_colorprint_change);//7
  4928. #endif
  4929. #ifndef DEBUG_DISABLE_FSENSORCHECK
  4930. #ifdef PAT9125
  4931. if (FSensorStateMenu == 0) {
  4932. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_OFF), lcd_fsensor_state_set);
  4933. }
  4934. else {
  4935. MENU_ITEM_FUNCTION_P(_T(MSG_FSENSOR_ON), lcd_fsensor_state_set);
  4936. }
  4937. #endif //PAT9125
  4938. #endif //DEBUG_DISABLE_FSENSORCHECK
  4939. #ifdef TMC2130
  4940. if(!farm_mode)
  4941. {
  4942. if (SilentModeMenu == SILENT_MODE_NORMAL) MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_OFF), lcd_silent_mode_set);
  4943. else MENU_ITEM_FUNCTION_P(_T(MSG_STEALTH_MODE_ON), lcd_silent_mode_set);
  4944. if (SilentModeMenu == SILENT_MODE_NORMAL)
  4945. {
  4946. if (CrashDetectMenu == 0) MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_OFF), lcd_crash_mode_set);
  4947. else MENU_ITEM_FUNCTION_P(_T(MSG_CRASHDETECT_ON), lcd_crash_mode_set);
  4948. }
  4949. else MENU_ITEM_SUBMENU_P(_T(MSG_CRASHDETECT_NA), lcd_crash_mode_info);
  4950. }
  4951. #else //TMC2130
  4952. if (!farm_mode) { //dont show in menu if we are in farm mode
  4953. switch (SilentModeMenu) {
  4954. case SILENT_MODE_POWER: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break;
  4955. case SILENT_MODE_SILENT: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_ON), lcd_silent_mode_set); break;
  4956. case SILENT_MODE_AUTO: MENU_ITEM_FUNCTION_P(_T(MSG_AUTO_MODE_ON), lcd_silent_mode_set); break;
  4957. default: MENU_ITEM_FUNCTION_P(_T(MSG_SILENT_MODE_OFF), lcd_silent_mode_set); break; // (probably) not needed
  4958. }
  4959. }
  4960. #endif //TMC2130
  4961. MENU_END();
  4962. }
  4963. static void lcd_move_menu_01mm()
  4964. {
  4965. move_menu_scale = 0.1;
  4966. lcd_move_menu_axis();
  4967. }
  4968. static void lcd_control_temperature_menu()
  4969. {
  4970. #ifdef PIDTEMP
  4971. // set up temp variables - undo the default scaling
  4972. // raw_Ki = unscalePID_i(Ki);
  4973. // raw_Kd = unscalePID_d(Kd);
  4974. #endif
  4975. MENU_BEGIN();
  4976. MENU_ITEM_BACK_P(_T(MSG_SETTINGS));
  4977. #if TEMP_SENSOR_0 != 0
  4978. //MENU_ITEM_EDIT_P_int16
  4979. if (menu_item_edit_int3(_T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10))
  4980. {
  4981. return;
  4982. }
  4983. // MENU_ITEM_EDIT(int3, _T(MSG_NOZZLE), &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  4984. #endif
  4985. #if TEMP_SENSOR_1 != 0
  4986. MENU_ITEM_EDIT(int3, _i("Nozzle2"), &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);////MSG_NOZZLE1 c=0 r=0
  4987. #endif
  4988. #if TEMP_SENSOR_2 != 0
  4989. MENU_ITEM_EDIT(int3, _i("Nozzle3"), &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);////MSG_NOZZLE2 c=0 r=0
  4990. #endif
  4991. #if TEMP_SENSOR_BED != 0
  4992. MENU_ITEM_EDIT(int3, _T(MSG_BED), &target_temperature_bed, 0, BED_MAXTEMP - 3);
  4993. #endif
  4994. MENU_ITEM_EDIT(int3, _T(MSG_FAN_SPEED), &fanSpeed, 0, 255);
  4995. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  4996. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  4997. MENU_ITEM_EDIT(float3, _i(" \002 Min"), &autotemp_min, 0, HEATER_0_MAXTEMP - 10);////MSG_MIN c=0 r=0
  4998. MENU_ITEM_EDIT(float3, _i(" \002 Max"), &autotemp_max, 0, HEATER_0_MAXTEMP - 10);////MSG_MAX c=0 r=0
  4999. MENU_ITEM_EDIT(float32, _i(" \002 Fact"), &autotemp_factor, 0.0, 1.0);////MSG_FACTOR c=0 r=0
  5000. #endif
  5001. MENU_END();
  5002. }
  5003. #if SDCARDDETECT == -1
  5004. static void lcd_sd_refresh()
  5005. {
  5006. card.initsd();
  5007. currentMenuViewOffset = 0;
  5008. }
  5009. #endif
  5010. static void lcd_sd_updir()
  5011. {
  5012. card.updir();
  5013. currentMenuViewOffset = 0;
  5014. }
  5015. void lcd_print_stop() {
  5016. cancel_heatup = true;
  5017. #ifdef MESH_BED_LEVELING
  5018. mbl.active = false;
  5019. #endif
  5020. // Stop the stoppers, update the position from the stoppers.
  5021. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  5022. planner_abort_hard();
  5023. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
  5024. // Z baystep is no more applied. Reset it.
  5025. babystep_reset();
  5026. }
  5027. // Clean the input command queue.
  5028. cmdqueue_reset();
  5029. lcd_setstatuspgm(_T(MSG_PRINT_ABORTED));
  5030. lcd_update(2);
  5031. card.sdprinting = false;
  5032. card.closefile();
  5033. stoptime = millis();
  5034. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  5035. pause_time = 0;
  5036. save_statistics(total_filament_used, t);
  5037. lcd_return_to_status();
  5038. lcd_ignore_click(true);
  5039. lcd_commands_step = 0;
  5040. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  5041. // Turn off the print fan
  5042. SET_OUTPUT(FAN_PIN);
  5043. WRITE(FAN_PIN, 0);
  5044. fanSpeed = 0;
  5045. }
  5046. void lcd_sdcard_stop()
  5047. {
  5048. lcd.setCursor(0, 0);
  5049. lcd_printPGM(_T(MSG_STOP_PRINT));
  5050. lcd.setCursor(2, 2);
  5051. lcd_printPGM(_T(MSG_NO));
  5052. lcd.setCursor(2, 3);
  5053. lcd_printPGM(_T(MSG_YES));
  5054. lcd.setCursor(0, 2); lcd.print(" ");
  5055. lcd.setCursor(0, 3); lcd.print(" ");
  5056. if ((int32_t)encoderPosition > 2) { encoderPosition = 2; }
  5057. if ((int32_t)encoderPosition < 1) { encoderPosition = 1; }
  5058. lcd.setCursor(0, 1 + encoderPosition);
  5059. lcd.print(">");
  5060. if (lcd_clicked())
  5061. {
  5062. if ((int32_t)encoderPosition == 1)
  5063. {
  5064. lcd_return_to_status();
  5065. }
  5066. if ((int32_t)encoderPosition == 2)
  5067. {
  5068. lcd_print_stop();
  5069. }
  5070. }
  5071. }
  5072. /*
  5073. void getFileDescription(char *name, char *description) {
  5074. // get file description, ie the REAL filenam, ie the second line
  5075. card.openFile(name, true);
  5076. int i = 0;
  5077. // skip the first line (which is the version line)
  5078. while (true) {
  5079. uint16_t readByte = card.get();
  5080. if (readByte == '\n') {
  5081. break;
  5082. }
  5083. }
  5084. // read the second line (which is the description line)
  5085. while (true) {
  5086. uint16_t readByte = card.get();
  5087. if (i == 0) {
  5088. // skip the first '^'
  5089. readByte = card.get();
  5090. }
  5091. description[i] = readByte;
  5092. i++;
  5093. if (readByte == '\n') {
  5094. break;
  5095. }
  5096. }
  5097. card.closefile();
  5098. description[i-1] = 0;
  5099. }
  5100. */
  5101. void lcd_sdcard_menu()
  5102. {
  5103. uint8_t sdSort = eeprom_read_byte((uint8_t*)EEPROM_SD_SORT);
  5104. int tempScrool = 0;
  5105. if (presort_flag == true) {
  5106. presort_flag = false;
  5107. card.presort();
  5108. }
  5109. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  5110. //delay(100);
  5111. return; // nothing to do (so don't thrash the SD card)
  5112. uint16_t fileCnt = card.getnrfilenames();
  5113. MENU_BEGIN();
  5114. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5115. card.getWorkDirName();
  5116. if (card.filename[0] == '/')
  5117. {
  5118. #if SDCARDDETECT == -1
  5119. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  5120. #endif
  5121. } else {
  5122. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  5123. }
  5124. for (uint16_t i = 0; i < fileCnt; i++)
  5125. {
  5126. if (menu_item == menu_line)
  5127. {
  5128. const uint16_t nr = ((sdSort == SD_SORT_NONE) || farm_mode || (sdSort == SD_SORT_TIME)) ? (fileCnt - 1 - i) : i;
  5129. /*#ifdef SDCARD_RATHERRECENTFIRST
  5130. #ifndef SDCARD_SORT_ALPHA
  5131. fileCnt - 1 -
  5132. #endif
  5133. #endif
  5134. i;*/
  5135. #ifdef SDCARD_SORT_ALPHA
  5136. if (sdSort == SD_SORT_NONE) card.getfilename(nr);
  5137. else card.getfilename_sorted(nr);
  5138. #else
  5139. card.getfilename(nr);
  5140. #endif
  5141. if (card.filenameIsDir)
  5142. MENU_ITEM_SDDIR(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  5143. else
  5144. MENU_ITEM_SDFILE(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  5145. } else {
  5146. MENU_ITEM_DUMMY();
  5147. }
  5148. }
  5149. MENU_END();
  5150. }
  5151. //char description [10] [31];
  5152. /*void get_description() {
  5153. uint16_t fileCnt = card.getnrfilenames();
  5154. for (uint16_t i = 0; i < fileCnt; i++)
  5155. {
  5156. card.getfilename(fileCnt - 1 - i);
  5157. getFileDescription(card.filename, description[i]);
  5158. }
  5159. }*/
  5160. /*void lcd_farm_sdcard_menu()
  5161. {
  5162. static int i = 0;
  5163. if (i == 0) {
  5164. get_description();
  5165. i++;
  5166. }
  5167. //int j;
  5168. //char description[31];
  5169. int tempScrool = 0;
  5170. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  5171. //delay(100);
  5172. return; // nothing to do (so don't thrash the SD card)
  5173. uint16_t fileCnt = card.getnrfilenames();
  5174. MENU_BEGIN();
  5175. MENU_ITEM_BACK_P(_T(MSG_MAIN));
  5176. card.getWorkDirName();
  5177. if (card.filename[0] == '/')
  5178. {
  5179. #if SDCARDDETECT == -1
  5180. MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh);
  5181. #endif
  5182. }
  5183. else {
  5184. MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  5185. }
  5186. for (uint16_t i = 0; i < fileCnt; i++)
  5187. {
  5188. if (menu_item == menu_line)
  5189. {
  5190. #ifndef SDCARD_RATHERRECENTFIRST
  5191. card.getfilename(i);
  5192. #else
  5193. card.getfilename(fileCnt - 1 - i);
  5194. #endif
  5195. if (card.filenameIsDir)
  5196. {
  5197. MENU_ITEM_SDDIR(_T(MSG_CARD_MENU), card.filename, card.longFilename);
  5198. }
  5199. else {
  5200. MENU_ITEM_SDFILE(_T(MSG_CARD_MENU), card.filename, description[i]);
  5201. }
  5202. }
  5203. else {
  5204. MENU_ITEM_DUMMY();
  5205. }
  5206. }
  5207. MENU_END();
  5208. }*/
  5209. #define menu_edit_type(_type, _name, _strFunc, scale) \
  5210. void menu_edit_ ## _name () \
  5211. { \
  5212. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  5213. if ((int32_t)encoderPosition > menuData.editMenuParentState.maxEditValue) encoderPosition = menuData.editMenuParentState.maxEditValue; \
  5214. if (lcdDrawUpdate) \
  5215. lcd_implementation_drawedit(menuData.editMenuParentState.editLabel, _strFunc(((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale)); \
  5216. if (LCD_CLICKED) \
  5217. { \
  5218. *((_type*)menuData.editMenuParentState.editValue) = ((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale; \
  5219. lcd_goto_menu(menuData.editMenuParentState.prevMenu, menuData.editMenuParentState.prevEncoderPosition, true, false); \
  5220. } \
  5221. } \
  5222. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  5223. { \
  5224. asm("cli"); \
  5225. menuData.editMenuParentState.prevMenu = menu_menu; \
  5226. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  5227. asm("sei"); \
  5228. \
  5229. lcdDrawUpdate = 2; \
  5230. menuData.editMenuParentState.editLabel = pstr; \
  5231. menuData.editMenuParentState.editValue = ptr; \
  5232. menuData.editMenuParentState.minEditValue = minValue * scale; \
  5233. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  5234. lcd_goto_menu(menu_edit_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  5235. \
  5236. }\
  5237. #ifdef TMC2130
  5238. extern char conv[8];
  5239. // Convert tmc2130 mres to string
  5240. char *mres_to_str3(const uint8_t &x)
  5241. {
  5242. return itostr3(256 >> x);
  5243. }
  5244. menu_edit_type(uint8_t, mres, mres_to_str3, 1)
  5245. // Convert tmc2130 wfac to string
  5246. char *wfac_to_str5(const uint8_t &x)
  5247. {
  5248. if (x >= TMC2130_WAVE_FAC1000_MIN)
  5249. {
  5250. conv[0] = '[';
  5251. ftostr43(((float)((uint16_t)x + 1000) / 1000), 1);
  5252. }
  5253. else strncpy_P(conv, _i(" [off"), 6);////MSG_EXTRUDER_CORRECTION_OFF c=6 r=0
  5254. conv[6] = ']';
  5255. conv[7] = ' ';
  5256. conv[8] = 0;
  5257. return conv;
  5258. }
  5259. menu_edit_type(uint8_t, wfac, wfac_to_str5, 1)
  5260. #endif //TMC2130
  5261. menu_edit_type(uint8_t, byte3, itostr3, 1)
  5262. menu_edit_type(int, int3, itostr3, 1)
  5263. menu_edit_type(float, float3, ftostr3, 1)
  5264. menu_edit_type(float, float32, ftostr32, 100)
  5265. menu_edit_type(float, float43, ftostr43, 1000)
  5266. menu_edit_type(float, float5, ftostr5, 0.01)
  5267. menu_edit_type(float, float51, ftostr51, 10)
  5268. menu_edit_type(float, float52, ftostr52, 100)
  5269. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  5270. static void lcd_selftest_v()
  5271. {
  5272. (void)lcd_selftest();
  5273. }
  5274. bool lcd_selftest()
  5275. {
  5276. int _progress = 0;
  5277. bool _result = true;
  5278. lcd_wait_for_cool_down();
  5279. lcd_implementation_clear();
  5280. lcd.setCursor(0, 0); lcd_printPGM(_i("Self test start "));////MSG_SELFTEST_START c=20 r=0
  5281. #ifdef TMC2130
  5282. FORCE_HIGH_POWER_START;
  5283. #endif // TMC2130
  5284. delay(2000);
  5285. KEEPALIVE_STATE(IN_HANDLER);
  5286. _progress = lcd_selftest_screen(-1, _progress, 3, true, 2000);
  5287. #if (defined(FANCHECK) && defined(TACH_0))
  5288. _result = lcd_selftest_fan_dialog(0);
  5289. #else //defined(TACH_0)
  5290. _result = lcd_selftest_manual_fan_check(0, false);
  5291. if (!_result)
  5292. {
  5293. const char *_err;
  5294. lcd_selftest_error(7, _err, _err); //extruder fan not spinning
  5295. }
  5296. #endif //defined(TACH_0)
  5297. if (_result)
  5298. {
  5299. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  5300. #if (defined(FANCHECK) && defined(TACH_1))
  5301. _result = lcd_selftest_fan_dialog(1);
  5302. #else //defined(TACH_1)
  5303. _result = lcd_selftest_manual_fan_check(1, false);
  5304. if (!_result)
  5305. {
  5306. const char *_err;
  5307. lcd_selftest_error(6, _err, _err); //print fan not spinning
  5308. }
  5309. #endif //defined(TACH_1)
  5310. }
  5311. if (_result)
  5312. {
  5313. _progress = lcd_selftest_screen(1, _progress, 3, true, 2000);
  5314. #ifndef TMC2130
  5315. _result = lcd_selfcheck_endstops();
  5316. #else
  5317. _result = true;
  5318. #endif
  5319. }
  5320. if (_result)
  5321. {
  5322. _progress = lcd_selftest_screen(3, _progress, 3, true, 1000);
  5323. _result = lcd_selfcheck_check_heater(false);
  5324. }
  5325. if (_result)
  5326. {
  5327. //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
  5328. _progress = lcd_selftest_screen(4, _progress, 3, true, 2000);
  5329. #ifdef TMC2130
  5330. _result = lcd_selfcheck_axis_sg(X_AXIS);
  5331. #else
  5332. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  5333. #endif //TMC2130
  5334. }
  5335. if (_result)
  5336. {
  5337. _progress = lcd_selftest_screen(4, _progress, 3, true, 0);
  5338. #ifndef TMC2130
  5339. _result = lcd_selfcheck_pulleys(X_AXIS);
  5340. #endif
  5341. }
  5342. if (_result)
  5343. {
  5344. _progress = lcd_selftest_screen(5, _progress, 3, true, 1500);
  5345. #ifdef TMC2130
  5346. _result = lcd_selfcheck_axis_sg(Y_AXIS);
  5347. #else
  5348. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  5349. #endif // TMC2130
  5350. }
  5351. if (_result)
  5352. {
  5353. _progress = lcd_selftest_screen(5, _progress, 3, true, 0);
  5354. #ifndef TMC2130
  5355. _result = lcd_selfcheck_pulleys(Y_AXIS);
  5356. #endif // TMC2130
  5357. }
  5358. if (_result)
  5359. {
  5360. #ifdef TMC2130
  5361. tmc2130_home_exit();
  5362. enable_endstops(false);
  5363. current_position[X_AXIS] = current_position[X_AXIS] + 14;
  5364. current_position[Y_AXIS] = current_position[Y_AXIS] + 12;
  5365. #endif
  5366. //homeaxis(X_AXIS);
  5367. //homeaxis(Y_AXIS);
  5368. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  5369. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5370. st_synchronize();
  5371. _progress = lcd_selftest_screen(6, _progress, 3, true, 1500);
  5372. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  5373. if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) != 1) {
  5374. enquecommand_P(PSTR("G28 W"));
  5375. enquecommand_P(PSTR("G1 Z15 F1000"));
  5376. }
  5377. }
  5378. #ifdef TMC2130
  5379. if (_result)
  5380. {
  5381. current_position[Z_AXIS] = current_position[Z_AXIS] + 10;
  5382. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5383. st_synchronize();
  5384. _progress = lcd_selftest_screen(13, 0, 2, true, 0);
  5385. bool bres = tmc2130_home_calibrate(X_AXIS);
  5386. _progress = lcd_selftest_screen(13, 1, 2, true, 0);
  5387. bres &= tmc2130_home_calibrate(Y_AXIS);
  5388. _progress = lcd_selftest_screen(13, 2, 2, true, 0);
  5389. if (bres)
  5390. eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1);
  5391. _result = bres;
  5392. }
  5393. #endif //TMC2130
  5394. if (_result)
  5395. {
  5396. _progress = lcd_selftest_screen(7, _progress, 3, true, 2000); //check bed
  5397. _result = lcd_selfcheck_check_heater(true);
  5398. }
  5399. if (_result)
  5400. {
  5401. _progress = lcd_selftest_screen(8, _progress, 3, true, 2000); //bed ok
  5402. #ifdef PAT9125
  5403. _progress = lcd_selftest_screen(9, _progress, 3, true, 2000); //check filaments sensor
  5404. _result = lcd_selftest_fsensor();
  5405. #endif // PAT9125
  5406. }
  5407. if (_result)
  5408. {
  5409. #ifdef PAT9125
  5410. _progress = lcd_selftest_screen(10, _progress, 3, true, 2000); //fil sensor OK
  5411. #endif // PAT9125
  5412. _progress = lcd_selftest_screen(11, _progress, 3, true, 5000); //all correct
  5413. }
  5414. else
  5415. {
  5416. _progress = lcd_selftest_screen(12, _progress, 3, true, 5000);
  5417. }
  5418. lcd_reset_alert_level();
  5419. enquecommand_P(PSTR("M84"));
  5420. lcd_implementation_clear();
  5421. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  5422. if (_result)
  5423. {
  5424. LCD_ALERTMESSAGERPGM(_i("Self test OK"));////MSG_SELFTEST_OK c=0 r=0
  5425. }
  5426. else
  5427. {
  5428. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  5429. }
  5430. #ifdef TMC2130
  5431. FORCE_HIGH_POWER_END;
  5432. #endif // TMC2130
  5433. KEEPALIVE_STATE(NOT_BUSY);
  5434. return(_result);
  5435. }
  5436. #ifdef TMC2130
  5437. static void reset_crash_det(char axis) {
  5438. current_position[axis] += 10;
  5439. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5440. st_synchronize();
  5441. if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true;
  5442. }
  5443. static bool lcd_selfcheck_axis_sg(char axis) {
  5444. // each axis length is measured twice
  5445. float axis_length, current_position_init, current_position_final;
  5446. float measured_axis_length[2];
  5447. float margin = 60;
  5448. float max_error_mm = 5;
  5449. switch (axis) {
  5450. case 0: axis_length = X_MAX_POS; break;
  5451. case 1: axis_length = Y_MAX_POS + 8; break;
  5452. default: axis_length = 210; break;
  5453. }
  5454. tmc2130_sg_stop_on_crash = false;
  5455. tmc2130_home_exit();
  5456. enable_endstops(true);
  5457. if (axis == X_AXIS) { //there is collision between cables and PSU cover in X axis if Z coordinate is too low
  5458. current_position[Z_AXIS] += 17;
  5459. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5460. tmc2130_home_enter(Z_AXIS_MASK);
  5461. st_synchronize();
  5462. tmc2130_home_exit();
  5463. }
  5464. // first axis length measurement begin
  5465. current_position[axis] -= (axis_length + margin);
  5466. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5467. st_synchronize();
  5468. tmc2130_sg_meassure_start(axis);
  5469. current_position_init = st_get_position_mm(axis);
  5470. current_position[axis] += 2 * margin;
  5471. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5472. st_synchronize();
  5473. current_position[axis] += axis_length;
  5474. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5475. st_synchronize();
  5476. uint16_t sg1 = tmc2130_sg_meassure_stop();
  5477. printf_P(PSTR("%c AXIS SG1=%d\n"), 'X'+axis, sg1);
  5478. eeprom_write_word(((uint16_t*)((axis == X_AXIS)?EEPROM_BELTSTATUS_X:EEPROM_BELTSTATUS_Y)), sg1);
  5479. current_position_final = st_get_position_mm(axis);
  5480. measured_axis_length[0] = abs(current_position_final - current_position_init);
  5481. // first measurement end and second measurement begin
  5482. current_position[axis] -= margin;
  5483. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5484. st_synchronize();
  5485. current_position[axis] -= (axis_length + margin);
  5486. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5487. st_synchronize();
  5488. current_position_init = st_get_position_mm(axis);
  5489. measured_axis_length[1] = abs(current_position_final - current_position_init);
  5490. //end of second measurement, now check for possible errors:
  5491. for(int i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length
  5492. printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]);
  5493. if (abs(measured_axis_length[i] - axis_length) > max_error_mm) {
  5494. enable_endstops(false);
  5495. const char *_error_1;
  5496. const char *_error_2;
  5497. if (axis == X_AXIS) _error_1 = "X";
  5498. if (axis == Y_AXIS) _error_1 = "Y";
  5499. if (axis == Z_AXIS) _error_1 = "Z";
  5500. lcd_selftest_error(9, _error_1, _error_2);
  5501. current_position[axis] = 0;
  5502. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5503. reset_crash_det(axis);
  5504. return false;
  5505. }
  5506. }
  5507. printf_P(_N("Axis length difference:%.3f\n"), abs(measured_axis_length[0] - measured_axis_length[1]));
  5508. if (abs(measured_axis_length[0] - measured_axis_length[1]) > 1) { //check if difference between first and second measurement is low
  5509. //loose pulleys
  5510. const char *_error_1;
  5511. const char *_error_2;
  5512. if (axis == X_AXIS) _error_1 = "X";
  5513. if (axis == Y_AXIS) _error_1 = "Y";
  5514. if (axis == Z_AXIS) _error_1 = "Z";
  5515. lcd_selftest_error(8, _error_1, _error_2);
  5516. current_position[axis] = 0;
  5517. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5518. reset_crash_det(axis);
  5519. return false;
  5520. }
  5521. current_position[axis] = 0;
  5522. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  5523. reset_crash_det(axis);
  5524. return true;
  5525. }
  5526. #endif //TMC2130
  5527. //#ifndef TMC2130
  5528. static bool lcd_selfcheck_axis(int _axis, int _travel)
  5529. {
  5530. // printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _axis, _travel);
  5531. bool _stepdone = false;
  5532. bool _stepresult = false;
  5533. int _progress = 0;
  5534. int _travel_done = 0;
  5535. int _err_endstop = 0;
  5536. int _lcd_refresh = 0;
  5537. _travel = _travel + (_travel / 10);
  5538. if (_axis == X_AXIS) {
  5539. current_position[Z_AXIS] += 17;
  5540. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5541. }
  5542. do {
  5543. current_position[_axis] = current_position[_axis] - 1;
  5544. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5545. st_synchronize();
  5546. #ifdef TMC2130
  5547. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1))
  5548. #else //TMC2130
  5549. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5550. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5551. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5552. #endif //TMC2130
  5553. {
  5554. if (_axis == 0)
  5555. {
  5556. _stepresult = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5557. _err_endstop = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? 1 : 2;
  5558. }
  5559. if (_axis == 1)
  5560. {
  5561. _stepresult = ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5562. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 2;
  5563. }
  5564. if (_axis == 2)
  5565. {
  5566. _stepresult = ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) ? true : false;
  5567. _err_endstop = ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ? 0 : 1;
  5568. printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _stepresult, _err_endstop);
  5569. /*disable_x();
  5570. disable_y();
  5571. disable_z();*/
  5572. }
  5573. _stepdone = true;
  5574. }
  5575. if (_lcd_refresh < 6)
  5576. {
  5577. _lcd_refresh++;
  5578. }
  5579. else
  5580. {
  5581. _progress = lcd_selftest_screen(4 + _axis, _progress, 3, false, 0);
  5582. _lcd_refresh = 0;
  5583. }
  5584. manage_heater();
  5585. manage_inactivity(true);
  5586. //delay(100);
  5587. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  5588. } while (!_stepdone);
  5589. //current_position[_axis] = current_position[_axis] + 15;
  5590. //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5591. if (!_stepresult)
  5592. {
  5593. const char *_error_1;
  5594. const char *_error_2;
  5595. if (_axis == X_AXIS) _error_1 = "X";
  5596. if (_axis == Y_AXIS) _error_1 = "Y";
  5597. if (_axis == Z_AXIS) _error_1 = "Z";
  5598. if (_err_endstop == 0) _error_2 = "X";
  5599. if (_err_endstop == 1) _error_2 = "Y";
  5600. if (_err_endstop == 2) _error_2 = "Z";
  5601. if (_travel_done >= _travel)
  5602. {
  5603. lcd_selftest_error(5, _error_1, _error_2);
  5604. }
  5605. else
  5606. {
  5607. lcd_selftest_error(4, _error_1, _error_2);
  5608. }
  5609. }
  5610. return _stepresult;
  5611. }
  5612. #ifndef TMC2130
  5613. static bool lcd_selfcheck_pulleys(int axis)
  5614. {
  5615. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  5616. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  5617. float current_position_init;
  5618. float move;
  5619. bool endstop_triggered = false;
  5620. int i;
  5621. unsigned long timeout_counter;
  5622. refresh_cmd_timeout();
  5623. manage_inactivity(true);
  5624. if (axis == 0) move = 50; //X_AXIS
  5625. else move = 50; //Y_AXIS
  5626. current_position_init = current_position[axis];
  5627. current_position[axis] += 2;
  5628. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5629. for (i = 0; i < 5; i++) {
  5630. refresh_cmd_timeout();
  5631. current_position[axis] = current_position[axis] + move;
  5632. st_current_set(0, 850); //set motor current higher
  5633. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 200, active_extruder);
  5634. st_synchronize();
  5635. if (SilentModeMenu != SILENT_MODE_OFF) st_current_set(0, tmp_motor[0]); //set back to normal operation currents
  5636. else st_current_set(0, tmp_motor_loud[0]); //set motor current back
  5637. current_position[axis] = current_position[axis] - move;
  5638. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  5639. st_synchronize();
  5640. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5641. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5642. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5643. return(false);
  5644. }
  5645. }
  5646. timeout_counter = millis() + 2500;
  5647. endstop_triggered = false;
  5648. manage_inactivity(true);
  5649. while (!endstop_triggered) {
  5650. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5651. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) {
  5652. endstop_triggered = true;
  5653. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  5654. current_position[axis] += (axis == X_AXIS) ? 13 : 9;
  5655. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5656. st_synchronize();
  5657. return(true);
  5658. }
  5659. else {
  5660. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5661. return(false);
  5662. }
  5663. }
  5664. else {
  5665. current_position[axis] -= 1;
  5666. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  5667. st_synchronize();
  5668. if (millis() > timeout_counter) {
  5669. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  5670. return(false);
  5671. }
  5672. }
  5673. }
  5674. return(true);
  5675. }
  5676. #endif //TMC2130
  5677. static bool lcd_selfcheck_endstops()
  5678. {
  5679. bool _result = true;
  5680. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5681. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5682. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5683. {
  5684. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) current_position[0] += 10;
  5685. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) current_position[1] += 10;
  5686. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) current_position[2] += 10;
  5687. }
  5688. 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);
  5689. delay(500);
  5690. if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) ||
  5691. ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) ||
  5692. ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1))
  5693. {
  5694. _result = false;
  5695. char _error[4] = "";
  5696. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X");
  5697. if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y");
  5698. if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z");
  5699. lcd_selftest_error(3, _error, "");
  5700. }
  5701. manage_heater();
  5702. manage_inactivity(true);
  5703. return _result;
  5704. }
  5705. //#endif //not defined TMC2130
  5706. static bool lcd_selfcheck_check_heater(bool _isbed)
  5707. {
  5708. int _counter = 0;
  5709. int _progress = 0;
  5710. bool _stepresult = false;
  5711. bool _docycle = true;
  5712. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  5713. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  5714. int _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  5715. target_temperature[0] = (_isbed) ? 0 : 200;
  5716. target_temperature_bed = (_isbed) ? 100 : 0;
  5717. manage_heater();
  5718. manage_inactivity(true);
  5719. KEEPALIVE_STATE(NOT_BUSY); //we are sending temperatures on serial line, so no need to send host keepalive messages
  5720. do {
  5721. _counter++;
  5722. _docycle = (_counter < _cycles) ? true : false;
  5723. manage_heater();
  5724. manage_inactivity(true);
  5725. _progress = (_isbed) ? lcd_selftest_screen(7, _progress, 2, false, 400) : lcd_selftest_screen(3, _progress, 2, false, 400);
  5726. /*if (_isbed) {
  5727. MYSERIAL.print("Bed temp:");
  5728. MYSERIAL.println(degBed());
  5729. }
  5730. else {
  5731. MYSERIAL.print("Hotend temp:");
  5732. MYSERIAL.println(degHotend(0));
  5733. }*/
  5734. if(_counter%5 == 0) serialecho_temperatures(); //show temperatures once in two seconds
  5735. } while (_docycle);
  5736. target_temperature[0] = 0;
  5737. target_temperature_bed = 0;
  5738. manage_heater();
  5739. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  5740. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  5741. /*
  5742. MYSERIAL.println("");
  5743. MYSERIAL.print("Checked result:");
  5744. MYSERIAL.println(_checked_result);
  5745. MYSERIAL.print("Opposite result:");
  5746. MYSERIAL.println(_opposite_result);
  5747. */
  5748. if (_opposite_result < ((_isbed) ? 10 : 3))
  5749. {
  5750. if (_checked_result >= ((_isbed) ? 3 : 10))
  5751. {
  5752. _stepresult = true;
  5753. }
  5754. else
  5755. {
  5756. lcd_selftest_error(1, "", "");
  5757. }
  5758. }
  5759. else
  5760. {
  5761. lcd_selftest_error(2, "", "");
  5762. }
  5763. manage_heater();
  5764. manage_inactivity(true);
  5765. KEEPALIVE_STATE(IN_HANDLER);
  5766. return _stepresult;
  5767. }
  5768. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  5769. {
  5770. lcd_implementation_quick_feedback();
  5771. target_temperature[0] = 0;
  5772. target_temperature_bed = 0;
  5773. manage_heater();
  5774. manage_inactivity();
  5775. lcd_implementation_clear();
  5776. lcd.setCursor(0, 0);
  5777. lcd_printPGM(_i("Selftest error !"));////MSG_SELFTEST_ERROR c=0 r=0
  5778. lcd.setCursor(0, 1);
  5779. lcd_printPGM(_i("Please check :"));////MSG_SELFTEST_PLEASECHECK c=0 r=0
  5780. switch (_error_no)
  5781. {
  5782. case 1:
  5783. lcd.setCursor(0, 2);
  5784. lcd_printPGM(_i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR c=0 r=0
  5785. lcd.setCursor(0, 3);
  5786. lcd_printPGM(_i("Not connected"));////MSG_SELFTEST_NOTCONNECTED c=0 r=0
  5787. break;
  5788. case 2:
  5789. lcd.setCursor(0, 2);
  5790. lcd_printPGM(_i("Bed / Heater"));////MSG_SELFTEST_BEDHEATER c=0 r=0
  5791. lcd.setCursor(0, 3);
  5792. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  5793. break;
  5794. case 3:
  5795. lcd.setCursor(0, 2);
  5796. lcd_printPGM(_i("Endstops"));////MSG_SELFTEST_ENDSTOPS c=0 r=0
  5797. lcd.setCursor(0, 3);
  5798. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  5799. lcd.setCursor(17, 3);
  5800. lcd.print(_error_1);
  5801. break;
  5802. case 4:
  5803. lcd.setCursor(0, 2);
  5804. lcd_printPGM(_T(MSG_SELFTEST_MOTOR));
  5805. lcd.setCursor(18, 2);
  5806. lcd.print(_error_1);
  5807. lcd.setCursor(0, 3);
  5808. lcd_printPGM(_i("Endstop"));////MSG_SELFTEST_ENDSTOP c=0 r=0
  5809. lcd.setCursor(18, 3);
  5810. lcd.print(_error_2);
  5811. break;
  5812. case 5:
  5813. lcd.setCursor(0, 2);
  5814. lcd_printPGM(_i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20 r=1
  5815. lcd.setCursor(0, 3);
  5816. lcd_printPGM(_T(MSG_SELFTEST_MOTOR));
  5817. lcd.setCursor(18, 3);
  5818. lcd.print(_error_1);
  5819. break;
  5820. case 6:
  5821. lcd.setCursor(0, 2);
  5822. lcd_printPGM(_T(MSG_SELFTEST_COOLING_FAN));
  5823. lcd.setCursor(0, 3);
  5824. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  5825. lcd.setCursor(18, 3);
  5826. lcd.print(_error_1);
  5827. break;
  5828. case 7:
  5829. lcd.setCursor(0, 2);
  5830. lcd_printPGM(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5831. lcd.setCursor(0, 3);
  5832. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  5833. lcd.setCursor(18, 3);
  5834. lcd.print(_error_1);
  5835. break;
  5836. case 8:
  5837. lcd.setCursor(0, 2);
  5838. lcd_printPGM(_i("Loose pulley"));////MSG_LOOSE_PULLEY c=20 r=1
  5839. lcd.setCursor(0, 3);
  5840. lcd_printPGM(_T(MSG_SELFTEST_MOTOR));
  5841. lcd.setCursor(18, 3);
  5842. lcd.print(_error_1);
  5843. break;
  5844. case 9:
  5845. lcd.setCursor(0, 2);
  5846. lcd_printPGM(_i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH c=0 r=0
  5847. lcd.setCursor(0, 3);
  5848. lcd_printPGM(_i("Axis"));////MSG_SELFTEST_AXIS c=0 r=0
  5849. lcd.setCursor(18, 3);
  5850. lcd.print(_error_1);
  5851. break;
  5852. case 10:
  5853. lcd.setCursor(0, 2);
  5854. lcd_printPGM(_i("Front/left fans"));////MSG_SELFTEST_FANS c=0 r=0
  5855. lcd.setCursor(0, 3);
  5856. lcd_printPGM(_i("Swapped"));////MSG_SELFTEST_SWAPPED c=0 r=0
  5857. lcd.setCursor(18, 3);
  5858. lcd.print(_error_1);
  5859. break;
  5860. case 11:
  5861. lcd.setCursor(0, 2);
  5862. lcd_printPGM(_i("Filament sensor"));////MSG_FILAMENT_SENSOR c=20 r=0
  5863. lcd.setCursor(0, 3);
  5864. lcd_printPGM(_T(MSG_SELFTEST_WIRINGERROR));
  5865. break;
  5866. }
  5867. delay(1000);
  5868. lcd_implementation_quick_feedback();
  5869. do {
  5870. delay(100);
  5871. manage_heater();
  5872. manage_inactivity();
  5873. } while (!lcd_clicked());
  5874. LCD_ALERTMESSAGERPGM(_T(MSG_SELFTEST_FAILED));
  5875. lcd_return_to_status();
  5876. }
  5877. #ifdef PAT9125
  5878. static bool lcd_selftest_fsensor() {
  5879. fsensor_init();
  5880. if (fsensor_not_responding)
  5881. {
  5882. const char *_err;
  5883. lcd_selftest_error(11, _err, _err);
  5884. }
  5885. return(!fsensor_not_responding);
  5886. }
  5887. #endif //PAT9125
  5888. static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite)
  5889. {
  5890. bool _result = check_opposite;
  5891. lcd_implementation_clear();
  5892. lcd.setCursor(0, 0); lcd_printPGM(_T(MSG_SELFTEST_FAN));
  5893. switch (_fan)
  5894. {
  5895. case 0:
  5896. // extruder cooling fan
  5897. lcd.setCursor(0, 1);
  5898. if(check_opposite == true) lcd_printPGM(_T(MSG_SELFTEST_COOLING_FAN));
  5899. else lcd_printPGM(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5900. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5901. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5902. break;
  5903. case 1:
  5904. // object cooling fan
  5905. lcd.setCursor(0, 1);
  5906. if (check_opposite == true) lcd_printPGM(_T(MSG_SELFTEST_EXTRUDER_FAN));
  5907. else lcd_printPGM(_T(MSG_SELFTEST_COOLING_FAN));
  5908. SET_OUTPUT(FAN_PIN);
  5909. analogWrite(FAN_PIN, 255);
  5910. break;
  5911. }
  5912. delay(500);
  5913. lcd.setCursor(1, 2); lcd_printPGM(_T(MSG_SELFTEST_FAN_YES));
  5914. lcd.setCursor(0, 3); lcd.print(">");
  5915. lcd.setCursor(1, 3); lcd_printPGM(_T(MSG_SELFTEST_FAN_NO));
  5916. int8_t enc_dif = 0;
  5917. KEEPALIVE_STATE(PAUSED_FOR_USER);
  5918. button_pressed = false;
  5919. do
  5920. {
  5921. switch (_fan)
  5922. {
  5923. case 0:
  5924. // extruder cooling fan
  5925. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5926. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  5927. break;
  5928. case 1:
  5929. // object cooling fan
  5930. SET_OUTPUT(FAN_PIN);
  5931. analogWrite(FAN_PIN, 255);
  5932. break;
  5933. }
  5934. if (abs((enc_dif - encoderDiff)) > 2) {
  5935. if (enc_dif > encoderDiff) {
  5936. _result = !check_opposite;
  5937. lcd.setCursor(0, 2); lcd.print(">");
  5938. lcd.setCursor(1, 2); lcd_printPGM(_T(MSG_SELFTEST_FAN_YES));
  5939. lcd.setCursor(0, 3); lcd.print(" ");
  5940. lcd.setCursor(1, 3); lcd_printPGM(_T(MSG_SELFTEST_FAN_NO));
  5941. }
  5942. if (enc_dif < encoderDiff) {
  5943. _result = check_opposite;
  5944. lcd.setCursor(0, 2); lcd.print(" ");
  5945. lcd.setCursor(1, 2); lcd_printPGM(_T(MSG_SELFTEST_FAN_YES));
  5946. lcd.setCursor(0, 3); lcd.print(">");
  5947. lcd.setCursor(1, 3); lcd_printPGM(_T(MSG_SELFTEST_FAN_NO));
  5948. }
  5949. enc_dif = 0;
  5950. encoderDiff = 0;
  5951. }
  5952. manage_heater();
  5953. delay(100);
  5954. } while (!lcd_clicked());
  5955. KEEPALIVE_STATE(IN_HANDLER);
  5956. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  5957. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 0);
  5958. SET_OUTPUT(FAN_PIN);
  5959. analogWrite(FAN_PIN, 0);
  5960. fanSpeed = 0;
  5961. manage_heater();
  5962. return _result;
  5963. }
  5964. static bool lcd_selftest_fan_dialog(int _fan)
  5965. {
  5966. bool _result = true;
  5967. int _errno = 7;
  5968. switch (_fan) {
  5969. case 0:
  5970. fanSpeed = 0;
  5971. manage_heater(); //turn off fan
  5972. setExtruderAutoFanState(EXTRUDER_0_AUTO_FAN_PIN, 1); //extruder fan
  5973. delay(2000); //delay_keep_alive would turn off extruder fan, because temerature is too low
  5974. manage_heater(); //count average fan speed from 2s delay and turn off fans
  5975. if (!fan_speed[0]) _result = false;
  5976. //SERIAL_ECHOPGM("Extruder fan speed: ");
  5977. //MYSERIAL.println(fan_speed[0]);
  5978. //SERIAL_ECHOPGM("Print fan speed: ");
  5979. //MYSERIAL.print(fan_speed[1]);
  5980. break;
  5981. case 1:
  5982. //will it work with Thotend > 50 C ?
  5983. fanSpeed = 150; //print fan
  5984. for (uint8_t i = 0; i < 5; i++) {
  5985. delay_keep_alive(1000);
  5986. lcd.setCursor(18, 3);
  5987. lcd.print("-");
  5988. delay_keep_alive(1000);
  5989. lcd.setCursor(18, 3);
  5990. lcd.print("|");
  5991. }
  5992. fanSpeed = 0;
  5993. manage_heater(); //turn off fan
  5994. manage_inactivity(true); //to turn off print fan
  5995. if (!fan_speed[1]) {
  5996. _result = false; _errno = 6; //print fan not spinning
  5997. }
  5998. else if (fan_speed[1] < 34) { //fan is spinning, but measured RPM are too low for print fan, it must be left extruder fan
  5999. //check fans manually
  6000. _result = lcd_selftest_manual_fan_check(1, true); //turn on print fan and check that left extruder fan is not spinning
  6001. if (_result) {
  6002. _result = lcd_selftest_manual_fan_check(1, false); //print fan is stil turned on; check that it is spinning
  6003. if (!_result) _errno = 6; //print fan not spinning
  6004. }
  6005. else {
  6006. _errno = 10; //swapped fans
  6007. }
  6008. }
  6009. //SERIAL_ECHOPGM("Extruder fan speed: ");
  6010. //MYSERIAL.println(fan_speed[0]);
  6011. //SERIAL_ECHOPGM("Print fan speed: ");
  6012. //MYSERIAL.println(fan_speed[1]);
  6013. break;
  6014. }
  6015. if (!_result)
  6016. {
  6017. const char *_err;
  6018. lcd_selftest_error(_errno, _err, _err);
  6019. }
  6020. return _result;
  6021. }
  6022. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  6023. {
  6024. lcd_next_update_millis = millis() + (LCD_UPDATE_INTERVAL * 10000);
  6025. int _step_block = 0;
  6026. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  6027. if (_clear) lcd_implementation_clear();
  6028. lcd.setCursor(0, 0);
  6029. if (_step == -1) lcd_printPGM(_T(MSG_SELFTEST_FAN));
  6030. if (_step == 0) lcd_printPGM(_T(MSG_SELFTEST_FAN));
  6031. if (_step == 1) lcd_printPGM(_T(MSG_SELFTEST_FAN));
  6032. if (_step == 2) lcd_printPGM(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20 r=0
  6033. if (_step == 3) lcd_printPGM(_i("Checking hotend "));////MSG_SELFTEST_CHECK_HOTEND c=20 r=0
  6034. if (_step == 4) lcd_printPGM(_i("Checking X axis "));////MSG_SELFTEST_CHECK_X c=20 r=0
  6035. if (_step == 5) lcd_printPGM(_i("Checking Y axis "));////MSG_SELFTEST_CHECK_Y c=20 r=0
  6036. if (_step == 6) lcd_printPGM(_i("Checking Z axis "));////MSG_SELFTEST_CHECK_Z c=20 r=0
  6037. if (_step == 7) lcd_printPGM(_T(MSG_SELFTEST_CHECK_BED));
  6038. if (_step == 8) lcd_printPGM(_T(MSG_SELFTEST_CHECK_BED));
  6039. if (_step == 9) lcd_printPGM(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6040. if (_step == 10) lcd_printPGM(_T(MSG_SELFTEST_CHECK_FSENSOR));
  6041. if (_step == 11) lcd_printPGM(_i("All correct "));////MSG_SELFTEST_CHECK_ALLCORRECT c=20 r=0
  6042. if (_step == 12) lcd_printPGM(_T(MSG_SELFTEST_FAILED));
  6043. if (_step == 13) lcd_printPGM(PSTR("Calibrating home"));
  6044. lcd.setCursor(0, 1);
  6045. lcd_printPGM(separator);
  6046. if ((_step >= -1) && (_step <= 1))
  6047. {
  6048. //SERIAL_ECHOLNPGM("Fan test");
  6049. lcd_print_at_PGM(0, 2, _i("Extruder fan:"));////MSG_SELFTEST_EXTRUDER_FAN_SPEED c=18 r=0
  6050. lcd.setCursor(18, 2);
  6051. (_step < 0) ? lcd.print(_indicator) : lcd.print("OK");
  6052. lcd_print_at_PGM(0, 3, _i("Print fan:"));////MSG_SELFTEST_PRINT_FAN_SPEED c=18 r=0
  6053. lcd.setCursor(18, 3);
  6054. (_step < 1) ? lcd.print(_indicator) : lcd.print("OK");
  6055. }
  6056. else if (_step >= 9 && _step <= 10)
  6057. {
  6058. lcd_print_at_PGM(0, 2, _i("Filament sensor:"));////MSG_SELFTEST_FILAMENT_SENSOR c=18 r=0
  6059. lcd.setCursor(18, 2);
  6060. (_step == 9) ? lcd.print(_indicator) : lcd.print("OK");
  6061. }
  6062. else if (_step < 9)
  6063. {
  6064. //SERIAL_ECHOLNPGM("Other tests");
  6065. _step_block = 3;
  6066. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  6067. _step_block = 4;
  6068. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  6069. _step_block = 5;
  6070. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  6071. _step_block = 6;
  6072. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  6073. _step_block = 7;
  6074. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  6075. }
  6076. if (_delay > 0) delay_keep_alive(_delay);
  6077. _progress++;
  6078. return (_progress > _progress_scale * 2) ? 0 : _progress;
  6079. }
  6080. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  6081. {
  6082. lcd.setCursor(_col, _row);
  6083. switch (_state)
  6084. {
  6085. case 1:
  6086. lcd.print(_name);
  6087. lcd.setCursor(_col + strlen(_name), _row);
  6088. lcd.print(":");
  6089. lcd.setCursor(_col + strlen(_name) + 1, _row);
  6090. lcd.print(_indicator);
  6091. break;
  6092. case 2:
  6093. lcd.print(_name);
  6094. lcd.setCursor(_col + strlen(_name), _row);
  6095. lcd.print(":");
  6096. lcd.setCursor(_col + strlen(_name) + 1, _row);
  6097. lcd.print("OK");
  6098. break;
  6099. default:
  6100. lcd.print(_name);
  6101. }
  6102. }
  6103. /** End of menus **/
  6104. static void lcd_quick_feedback()
  6105. {
  6106. lcdDrawUpdate = 2;
  6107. button_pressed = false;
  6108. lcd_implementation_quick_feedback();
  6109. }
  6110. /** Menu action functions **/
  6111. static bool check_file(const char* filename) {
  6112. if (farm_mode) return true;
  6113. bool result = false;
  6114. uint32_t filesize;
  6115. card.openFile((char*)filename, true);
  6116. filesize = card.getFileSize();
  6117. if (filesize > END_FILE_SECTION) {
  6118. card.setIndex(filesize - END_FILE_SECTION);
  6119. }
  6120. while (!card.eof() && !result) {
  6121. card.sdprinting = true;
  6122. get_command();
  6123. result = check_commands();
  6124. }
  6125. card.printingHasFinished();
  6126. strncpy_P(lcd_status_message, _T(WELCOME_MSG), LCD_WIDTH);
  6127. lcd_finishstatus();
  6128. return result;
  6129. }
  6130. static void menu_action_sdfile(const char* filename, char* longFilename)
  6131. {
  6132. loading_flag = false;
  6133. char cmd[30];
  6134. char* c;
  6135. bool result = true;
  6136. sprintf_P(cmd, PSTR("M23 %s"), filename);
  6137. for (c = &cmd[4]; *c; c++)
  6138. *c = tolower(*c);
  6139. const char end[5] = ".gco";
  6140. //we are storing just first 8 characters of 8.3 filename assuming that extension is always ".gco"
  6141. for (int i = 0; i < 8; i++) {
  6142. if (strcmp((cmd + i + 4), end) == 0) {
  6143. //filename is shorter then 8.3, store '\0' character on position where ".gco" string was found to terminate stored string properly
  6144. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, '\0');
  6145. break;
  6146. }
  6147. else {
  6148. eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, cmd[i + 4]);
  6149. }
  6150. }
  6151. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  6152. eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth);
  6153. for (uint8_t i = 0; i < depth; i++) {
  6154. for (int j = 0; j < 8; j++) {
  6155. eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, dir_names[i][j]);
  6156. }
  6157. }
  6158. if (!check_file(filename)) {
  6159. result = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("File incomplete. Continue anyway?"), false, false);////MSG_FILE_INCOMPLETE c=20 r=2
  6160. lcd_update_enable(true);
  6161. }
  6162. if (result) {
  6163. enquecommand(cmd);
  6164. enquecommand_P(PSTR("M24"));
  6165. }
  6166. lcd_return_to_status();
  6167. }
  6168. static void menu_action_sddirectory(const char* filename, char* longFilename)
  6169. {
  6170. uint8_t depth = (uint8_t)card.getWorkDirDepth();
  6171. strcpy(dir_names[depth], filename);
  6172. MYSERIAL.println(dir_names[depth]);
  6173. card.chdir(filename);
  6174. encoderPosition = 0;
  6175. }
  6176. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  6177. {
  6178. *ptr = !(*ptr);
  6179. }
  6180. #endif//ULTIPANEL
  6181. /** LCD API **/
  6182. void lcd_init()
  6183. {
  6184. lcd_implementation_init();
  6185. #ifdef NEWPANEL
  6186. SET_INPUT(BTN_EN1);
  6187. SET_INPUT(BTN_EN2);
  6188. WRITE(BTN_EN1, HIGH);
  6189. WRITE(BTN_EN2, HIGH);
  6190. #if BTN_ENC > 0
  6191. SET_INPUT(BTN_ENC);
  6192. WRITE(BTN_ENC, HIGH);
  6193. #endif
  6194. #ifdef REPRAPWORLD_KEYPAD
  6195. pinMode(SHIFT_CLK, OUTPUT);
  6196. pinMode(SHIFT_LD, OUTPUT);
  6197. pinMode(SHIFT_OUT, INPUT);
  6198. WRITE(SHIFT_OUT, HIGH);
  6199. WRITE(SHIFT_LD, HIGH);
  6200. #endif
  6201. #else // Not NEWPANEL
  6202. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  6203. pinMode (SR_DATA_PIN, OUTPUT);
  6204. pinMode (SR_CLK_PIN, OUTPUT);
  6205. #elif defined(SHIFT_CLK)
  6206. pinMode(SHIFT_CLK, OUTPUT);
  6207. pinMode(SHIFT_LD, OUTPUT);
  6208. pinMode(SHIFT_EN, OUTPUT);
  6209. pinMode(SHIFT_OUT, INPUT);
  6210. WRITE(SHIFT_OUT, HIGH);
  6211. WRITE(SHIFT_LD, HIGH);
  6212. WRITE(SHIFT_EN, LOW);
  6213. #else
  6214. #ifdef ULTIPANEL
  6215. #error ULTIPANEL requires an encoder
  6216. #endif
  6217. #endif // SR_LCD_2W_NL
  6218. #endif//!NEWPANEL
  6219. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  6220. pinMode(SDCARDDETECT, INPUT);
  6221. WRITE(SDCARDDETECT, HIGH);
  6222. lcd_oldcardstatus = IS_SD_INSERTED;
  6223. #endif//(SDCARDDETECT > 0)
  6224. #ifdef LCD_HAS_SLOW_BUTTONS
  6225. slow_buttons = 0;
  6226. #endif
  6227. lcd_buttons_update();
  6228. #ifdef ULTIPANEL
  6229. encoderDiff = 0;
  6230. #endif
  6231. }
  6232. //#include <avr/pgmspace.h>
  6233. static volatile bool lcd_update_enabled = true;
  6234. unsigned long lcd_timeoutToStatus = 0;
  6235. void lcd_update_enable(bool enabled)
  6236. {
  6237. if (lcd_update_enabled != enabled) {
  6238. lcd_update_enabled = enabled;
  6239. if (enabled) {
  6240. // Reset encoder position. This is equivalent to re-entering a menu.
  6241. encoderPosition = 0;
  6242. encoderDiff = 0;
  6243. // Enabling the normal LCD update procedure.
  6244. // Reset the timeout interval.
  6245. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6246. // Force the keypad update now.
  6247. lcd_next_update_millis = millis() - 1;
  6248. // Full update.
  6249. lcd_implementation_clear();
  6250. if (menu_menu == lcd_status_screen)
  6251. lcd_set_custom_characters_degree();
  6252. else
  6253. lcd_set_custom_characters_arrows();
  6254. lcd_update(2);
  6255. } else {
  6256. // Clear the LCD always, or let it to the caller?
  6257. }
  6258. }
  6259. }
  6260. void lcd_update(uint8_t lcdDrawUpdateOverride)
  6261. {
  6262. if (lcdDrawUpdate < lcdDrawUpdateOverride)
  6263. lcdDrawUpdate = lcdDrawUpdateOverride;
  6264. if (!lcd_update_enabled)
  6265. return;
  6266. #ifdef LCD_HAS_SLOW_BUTTONS
  6267. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  6268. #endif
  6269. lcd_buttons_update();
  6270. #if (SDCARDDETECT > 0)
  6271. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  6272. {
  6273. lcdDrawUpdate = 2;
  6274. lcd_oldcardstatus = IS_SD_INSERTED;
  6275. lcd_implementation_init(); // to maybe revive the LCD if static electricity killed it.
  6276. if (lcd_oldcardstatus)
  6277. {
  6278. card.initsd();
  6279. LCD_MESSAGERPGM(_i("Card inserted"));////MSG_SD_INSERTED c=0 r=0
  6280. //get_description();
  6281. }
  6282. else
  6283. {
  6284. card.release();
  6285. LCD_MESSAGERPGM(_i("Card removed"));////MSG_SD_REMOVED c=0 r=0
  6286. }
  6287. }
  6288. #endif//CARDINSERTED
  6289. if (lcd_next_update_millis < millis())
  6290. {
  6291. #ifdef DEBUG_BLINK_ACTIVE
  6292. static bool active_led = false;
  6293. active_led = !active_led;
  6294. pinMode(LED_PIN, OUTPUT);
  6295. digitalWrite(LED_PIN, active_led?HIGH:LOW);
  6296. #endif //DEBUG_BLINK_ACTIVE
  6297. #ifdef ULTIPANEL
  6298. #ifdef REPRAPWORLD_KEYPAD
  6299. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  6300. reprapworld_keypad_move_z_up();
  6301. }
  6302. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  6303. reprapworld_keypad_move_z_down();
  6304. }
  6305. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  6306. reprapworld_keypad_move_x_left();
  6307. }
  6308. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  6309. reprapworld_keypad_move_x_right();
  6310. }
  6311. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  6312. reprapworld_keypad_move_y_down();
  6313. }
  6314. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  6315. reprapworld_keypad_move_y_up();
  6316. }
  6317. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  6318. reprapworld_keypad_move_home();
  6319. }
  6320. #endif
  6321. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  6322. {
  6323. if (lcdDrawUpdate == 0)
  6324. lcdDrawUpdate = 1;
  6325. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  6326. encoderDiff = 0;
  6327. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6328. }
  6329. if (LCD_CLICKED) lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6330. #endif//ULTIPANEL
  6331. (*menu_menu)();
  6332. #ifdef LCD_HAS_STATUS_INDICATORS
  6333. lcd_implementation_update_indicators();
  6334. #endif
  6335. #ifdef ULTIPANEL
  6336. if (lcd_timeoutToStatus < millis() && menu_menu != lcd_status_screen)
  6337. {
  6338. // Exiting a menu. Let's call the menu function the last time with menuExiting flag set to true
  6339. // to give it a chance to save its state.
  6340. // This is useful for example, when the babystep value has to be written into EEPROM.
  6341. if (menu_menu != NULL) {
  6342. menuExiting = true;
  6343. (*menu_menu)();
  6344. menuExiting = false;
  6345. }
  6346. lcd_implementation_clear();
  6347. lcd_return_to_status();
  6348. lcdDrawUpdate = 2;
  6349. }
  6350. #endif//ULTIPANEL
  6351. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  6352. if (lcdDrawUpdate) lcdDrawUpdate--;
  6353. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  6354. }
  6355. if (!SdFatUtil::test_stack_integrity()) stack_error();
  6356. #ifdef DEBUG_STEPPER_TIMER_MISSED
  6357. if (stepper_timer_overflow_state) stepper_timer_overflow();
  6358. #endif /* DEBUG_STEPPER_TIMER_MISSED */
  6359. lcd_ping(); //check that we have received ping command if we are in farm mode
  6360. lcd_send_status();
  6361. if (lcd_commands_type == LCD_COMMAND_V2_CAL) lcd_commands();
  6362. }
  6363. void lcd_printer_connected() {
  6364. printer_connected = true;
  6365. }
  6366. static void lcd_send_status() {
  6367. if (farm_mode && no_response && ((millis() - NcTime) > (NC_TIME * 1000))) {
  6368. //send important status messages periodicaly
  6369. prusa_statistics(important_status, saved_filament_type);
  6370. NcTime = millis();
  6371. #ifdef FARM_CONNECT_MESSAGE
  6372. lcd_connect_printer();
  6373. #endif //FARM_CONNECT_MESSAGE
  6374. }
  6375. }
  6376. static void lcd_connect_printer() {
  6377. lcd_update_enable(false);
  6378. lcd_implementation_clear();
  6379. bool pressed = false;
  6380. int i = 0;
  6381. int t = 0;
  6382. lcd_set_custom_characters_progress();
  6383. lcd_implementation_print_at(0, 0, "Connect printer to");
  6384. lcd_implementation_print_at(0, 1, "monitoring or hold");
  6385. lcd_implementation_print_at(0, 2, "the knob to continue");
  6386. while (no_response) {
  6387. i++;
  6388. t++;
  6389. delay_keep_alive(100);
  6390. proc_commands();
  6391. if (t == 10) {
  6392. prusa_statistics(important_status, saved_filament_type);
  6393. t = 0;
  6394. }
  6395. if (READ(BTN_ENC)) { //if button is not pressed
  6396. i = 0;
  6397. lcd_implementation_print_at(0, 3, " ");
  6398. }
  6399. if (i!=0) lcd_implementation_print_at((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, "\x01");
  6400. if (i == NC_BUTTON_LONG_PRESS * 10) {
  6401. no_response = false;
  6402. }
  6403. }
  6404. lcd_set_custom_characters_degree();
  6405. lcd_update_enable(true);
  6406. lcd_update(2);
  6407. }
  6408. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  6409. if (farm_mode) {
  6410. bool empty = is_buffer_empty();
  6411. if ((millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  6412. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  6413. //therefore longer period is used
  6414. printer_connected = false;
  6415. }
  6416. else {
  6417. lcd_printer_connected();
  6418. }
  6419. }
  6420. }
  6421. void lcd_ignore_click(bool b)
  6422. {
  6423. ignore_click = b;
  6424. wait_for_unclick = false;
  6425. }
  6426. void lcd_finishstatus() {
  6427. int len = strlen(lcd_status_message);
  6428. if (len > 0) {
  6429. while (len < LCD_WIDTH) {
  6430. lcd_status_message[len++] = ' ';
  6431. }
  6432. }
  6433. lcd_status_message[LCD_WIDTH] = '\0';
  6434. lcdDrawUpdate = 2;
  6435. }
  6436. void lcd_setstatus(const char* message)
  6437. {
  6438. if (lcd_status_message_level > 0)
  6439. return;
  6440. strncpy(lcd_status_message, message, LCD_WIDTH);
  6441. lcd_finishstatus();
  6442. }
  6443. void lcd_setstatuspgm(const char* message)
  6444. {
  6445. if (lcd_status_message_level > 0)
  6446. return;
  6447. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  6448. lcd_status_message[LCD_WIDTH] = 0;
  6449. lcd_finishstatus();
  6450. }
  6451. void lcd_setalertstatuspgm(const char* message)
  6452. {
  6453. lcd_setstatuspgm(message);
  6454. lcd_status_message_level = 1;
  6455. #ifdef ULTIPANEL
  6456. lcd_return_to_status();
  6457. #endif//ULTIPANEL
  6458. }
  6459. void lcd_reset_alert_level()
  6460. {
  6461. lcd_status_message_level = 0;
  6462. }
  6463. uint8_t get_message_level()
  6464. {
  6465. return lcd_status_message_level;
  6466. }
  6467. #ifdef DOGLCD
  6468. void lcd_setcontrast(uint8_t value)
  6469. {
  6470. lcd_contrast = value & 63;
  6471. u8g.setContrast(lcd_contrast);
  6472. }
  6473. #endif
  6474. #ifdef ULTIPANEL
  6475. /* Warning: This function is called from interrupt context */
  6476. void lcd_buttons_update()
  6477. {
  6478. static bool _lock = false;
  6479. if (_lock) return;
  6480. _lock = true;
  6481. #ifdef NEWPANEL
  6482. uint8_t newbutton = 0;
  6483. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  6484. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  6485. #if BTN_ENC > 0
  6486. if (lcd_update_enabled == true) { //if we are in non-modal mode, long press can be used and short press triggers with button release
  6487. if (READ(BTN_ENC) == 0) { //button is pressed
  6488. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  6489. if (millis() > button_blanking_time) {
  6490. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  6491. if (button_pressed == false && long_press_active == false) {
  6492. longPressTimer.start();
  6493. button_pressed = true;
  6494. }
  6495. else {
  6496. if (longPressTimer.expired(LONG_PRESS_TIME)) {
  6497. long_press_active = true;
  6498. move_menu_scale = 1.0;
  6499. menu_submenu(lcd_move_z);
  6500. }
  6501. }
  6502. }
  6503. }
  6504. else { //button not pressed
  6505. if (button_pressed) { //button was released
  6506. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  6507. if (long_press_active == false) { //button released before long press gets activated
  6508. newbutton |= EN_C;
  6509. }
  6510. else if (menu_menu == lcd_move_z) lcd_quick_feedback();
  6511. //button_pressed is set back to false via lcd_quick_feedback function
  6512. }
  6513. else {
  6514. long_press_active = false;
  6515. }
  6516. }
  6517. }
  6518. else { //we are in modal mode
  6519. if (READ(BTN_ENC) == 0)
  6520. newbutton |= EN_C;
  6521. }
  6522. #endif
  6523. buttons = newbutton;
  6524. #ifdef LCD_HAS_SLOW_BUTTONS
  6525. buttons |= slow_buttons;
  6526. #endif
  6527. #ifdef REPRAPWORLD_KEYPAD
  6528. // for the reprapworld_keypad
  6529. uint8_t newbutton_reprapworld_keypad = 0;
  6530. WRITE(SHIFT_LD, LOW);
  6531. WRITE(SHIFT_LD, HIGH);
  6532. for (int8_t i = 0; i < 8; i++) {
  6533. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  6534. if (READ(SHIFT_OUT))
  6535. newbutton_reprapworld_keypad |= (1 << 7);
  6536. WRITE(SHIFT_CLK, HIGH);
  6537. WRITE(SHIFT_CLK, LOW);
  6538. }
  6539. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  6540. #endif
  6541. #else //read it from the shift register
  6542. uint8_t newbutton = 0;
  6543. WRITE(SHIFT_LD, LOW);
  6544. WRITE(SHIFT_LD, HIGH);
  6545. unsigned char tmp_buttons = 0;
  6546. for (int8_t i = 0; i < 8; i++)
  6547. {
  6548. newbutton = newbutton >> 1;
  6549. if (READ(SHIFT_OUT))
  6550. newbutton |= (1 << 7);
  6551. WRITE(SHIFT_CLK, HIGH);
  6552. WRITE(SHIFT_CLK, LOW);
  6553. }
  6554. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  6555. #endif//!NEWPANEL
  6556. //manage encoder rotation
  6557. uint8_t enc = 0;
  6558. if (buttons & EN_A) enc |= B01;
  6559. if (buttons & EN_B) enc |= B10;
  6560. if (enc != lastEncoderBits)
  6561. {
  6562. switch (enc)
  6563. {
  6564. case encrot0:
  6565. if (lastEncoderBits == encrot3)
  6566. encoderDiff++;
  6567. else if (lastEncoderBits == encrot1)
  6568. encoderDiff--;
  6569. break;
  6570. case encrot1:
  6571. if (lastEncoderBits == encrot0)
  6572. encoderDiff++;
  6573. else if (lastEncoderBits == encrot2)
  6574. encoderDiff--;
  6575. break;
  6576. case encrot2:
  6577. if (lastEncoderBits == encrot1)
  6578. encoderDiff++;
  6579. else if (lastEncoderBits == encrot3)
  6580. encoderDiff--;
  6581. break;
  6582. case encrot3:
  6583. if (lastEncoderBits == encrot2)
  6584. encoderDiff++;
  6585. else if (lastEncoderBits == encrot0)
  6586. encoderDiff--;
  6587. break;
  6588. }
  6589. }
  6590. lastEncoderBits = enc;
  6591. _lock = false;
  6592. }
  6593. bool lcd_detected(void)
  6594. {
  6595. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  6596. return lcd.LcdDetected() == 1;
  6597. #else
  6598. return true;
  6599. #endif
  6600. }
  6601. void lcd_buzz(long duration, uint16_t freq)
  6602. {
  6603. #ifdef LCD_USE_I2C_BUZZER
  6604. lcd.buzz(duration, freq);
  6605. #endif
  6606. }
  6607. bool lcd_clicked()
  6608. {
  6609. bool clicked = LCD_CLICKED;
  6610. if(clicked) button_pressed = false;
  6611. return clicked;
  6612. }
  6613. #endif//ULTIPANEL
  6614. /********************************/
  6615. /** Float conversion utilities **/
  6616. /********************************/
  6617. // convert float to string with +123.4 format
  6618. char conv[8];
  6619. char *ftostr3(const float &x)
  6620. {
  6621. return itostr3((int)x);
  6622. }
  6623. char *itostr2(const uint8_t &x)
  6624. {
  6625. //sprintf(conv,"%5.1f",x);
  6626. int xx = x;
  6627. conv[0] = (xx / 10) % 10 + '0';
  6628. conv[1] = (xx) % 10 + '0';
  6629. conv[2] = 0;
  6630. return conv;
  6631. }
  6632. // Convert float to string with 123.4 format, dropping sign
  6633. char *ftostr31(const float &x)
  6634. {
  6635. int xx = x * 10;
  6636. conv[0] = (xx >= 0) ? '+' : '-';
  6637. xx = abs(xx);
  6638. conv[1] = (xx / 1000) % 10 + '0';
  6639. conv[2] = (xx / 100) % 10 + '0';
  6640. conv[3] = (xx / 10) % 10 + '0';
  6641. conv[4] = '.';
  6642. conv[5] = (xx) % 10 + '0';
  6643. conv[6] = 0;
  6644. return conv;
  6645. }
  6646. // Convert float to string with 123.4 format
  6647. char *ftostr31ns(const float &x)
  6648. {
  6649. int xx = x * 10;
  6650. //conv[0]=(xx>=0)?'+':'-';
  6651. xx = abs(xx);
  6652. conv[0] = (xx / 1000) % 10 + '0';
  6653. conv[1] = (xx / 100) % 10 + '0';
  6654. conv[2] = (xx / 10) % 10 + '0';
  6655. conv[3] = '.';
  6656. conv[4] = (xx) % 10 + '0';
  6657. conv[5] = 0;
  6658. return conv;
  6659. }
  6660. char *ftostr32(const float &x)
  6661. {
  6662. long xx = x * 100;
  6663. if (xx >= 0)
  6664. conv[0] = (xx / 10000) % 10 + '0';
  6665. else
  6666. conv[0] = '-';
  6667. xx = abs(xx);
  6668. conv[1] = (xx / 1000) % 10 + '0';
  6669. conv[2] = (xx / 100) % 10 + '0';
  6670. conv[3] = '.';
  6671. conv[4] = (xx / 10) % 10 + '0';
  6672. conv[5] = (xx) % 10 + '0';
  6673. conv[6] = 0;
  6674. return conv;
  6675. }
  6676. //// Convert float to rj string with 123.45 format
  6677. char *ftostr32ns(const float &x) {
  6678. long xx = abs(x);
  6679. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  6680. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6681. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : '0';
  6682. conv[3] = '.';
  6683. conv[4] = (xx / 10) % 10 + '0';
  6684. conv[5] = xx % 10 + '0';
  6685. return conv;
  6686. }
  6687. // Convert float to string with 1.234 format
  6688. char *ftostr43(const float &x, uint8_t offset)
  6689. {
  6690. const size_t maxOffset = sizeof(conv)/sizeof(conv[0]) - 6;
  6691. if (offset>maxOffset) offset = maxOffset;
  6692. long xx = x * 1000;
  6693. if (xx >= 0)
  6694. conv[offset] = (xx / 1000) % 10 + '0';
  6695. else
  6696. conv[offset] = '-';
  6697. xx = abs(xx);
  6698. conv[offset + 1] = '.';
  6699. conv[offset + 2] = (xx / 100) % 10 + '0';
  6700. conv[offset + 3] = (xx / 10) % 10 + '0';
  6701. conv[offset + 4] = (xx) % 10 + '0';
  6702. conv[offset + 5] = 0;
  6703. return conv;
  6704. }
  6705. //Float to string with 1.23 format
  6706. char *ftostr12ns(const float &x)
  6707. {
  6708. long xx = x * 100;
  6709. xx = abs(xx);
  6710. conv[0] = (xx / 100) % 10 + '0';
  6711. conv[1] = '.';
  6712. conv[2] = (xx / 10) % 10 + '0';
  6713. conv[3] = (xx) % 10 + '0';
  6714. conv[4] = 0;
  6715. return conv;
  6716. }
  6717. //Float to string with 1.234 format
  6718. char *ftostr13ns(const float &x)
  6719. {
  6720. long xx = x * 1000;
  6721. if (xx >= 0)
  6722. conv[0] = ' ';
  6723. else
  6724. conv[0] = '-';
  6725. xx = abs(xx);
  6726. conv[1] = (xx / 1000) % 10 + '0';
  6727. conv[2] = '.';
  6728. conv[3] = (xx / 100) % 10 + '0';
  6729. conv[4] = (xx / 10) % 10 + '0';
  6730. conv[5] = (xx) % 10 + '0';
  6731. conv[6] = 0;
  6732. return conv;
  6733. }
  6734. // convert float to space-padded string with -_23.4_ format
  6735. char *ftostr32sp(const float &x) {
  6736. long xx = abs(x * 100);
  6737. uint8_t dig;
  6738. if (x < 0) { // negative val = -_0
  6739. conv[0] = '-';
  6740. dig = (xx / 1000) % 10;
  6741. conv[1] = dig ? '0' + dig : ' ';
  6742. }
  6743. else { // positive val = __0
  6744. dig = (xx / 10000) % 10;
  6745. if (dig) {
  6746. conv[0] = '0' + dig;
  6747. conv[1] = '0' + (xx / 1000) % 10;
  6748. }
  6749. else {
  6750. conv[0] = ' ';
  6751. dig = (xx / 1000) % 10;
  6752. conv[1] = dig ? '0' + dig : ' ';
  6753. }
  6754. }
  6755. conv[2] = '0' + (xx / 100) % 10; // lsd always
  6756. dig = xx % 10;
  6757. if (dig) { // 2 decimal places
  6758. conv[5] = '0' + dig;
  6759. conv[4] = '0' + (xx / 10) % 10;
  6760. conv[3] = '.';
  6761. }
  6762. else { // 1 or 0 decimal place
  6763. dig = (xx / 10) % 10;
  6764. if (dig) {
  6765. conv[4] = '0' + dig;
  6766. conv[3] = '.';
  6767. }
  6768. else {
  6769. conv[3] = conv[4] = ' ';
  6770. }
  6771. conv[5] = ' ';
  6772. }
  6773. conv[6] = '\0';
  6774. return conv;
  6775. }
  6776. char *itostr31(const int &xx)
  6777. {
  6778. conv[0] = (xx >= 0) ? '+' : '-';
  6779. conv[1] = (xx / 1000) % 10 + '0';
  6780. conv[2] = (xx / 100) % 10 + '0';
  6781. conv[3] = (xx / 10) % 10 + '0';
  6782. conv[4] = '.';
  6783. conv[5] = (xx) % 10 + '0';
  6784. conv[6] = 0;
  6785. return conv;
  6786. }
  6787. // Convert int to rj string with 123 or -12 format
  6788. char *itostr3(const int &x)
  6789. {
  6790. int xx = x;
  6791. if (xx < 0) {
  6792. conv[0] = '-';
  6793. xx = -xx;
  6794. } else if (xx >= 100)
  6795. conv[0] = (xx / 100) % 10 + '0';
  6796. else
  6797. conv[0] = ' ';
  6798. if (xx >= 10)
  6799. conv[1] = (xx / 10) % 10 + '0';
  6800. else
  6801. conv[1] = ' ';
  6802. conv[2] = (xx) % 10 + '0';
  6803. conv[3] = 0;
  6804. return conv;
  6805. }
  6806. // Convert int to lj string with 123 format
  6807. char *itostr3left(const int &xx)
  6808. {
  6809. if (xx >= 100)
  6810. {
  6811. conv[0] = (xx / 100) % 10 + '0';
  6812. conv[1] = (xx / 10) % 10 + '0';
  6813. conv[2] = (xx) % 10 + '0';
  6814. conv[3] = 0;
  6815. }
  6816. else if (xx >= 10)
  6817. {
  6818. conv[0] = (xx / 10) % 10 + '0';
  6819. conv[1] = (xx) % 10 + '0';
  6820. conv[2] = 0;
  6821. }
  6822. else
  6823. {
  6824. conv[0] = (xx) % 10 + '0';
  6825. conv[1] = 0;
  6826. }
  6827. return conv;
  6828. }
  6829. // Convert int to rj string with 1234 format
  6830. char *itostr4(const int &xx) {
  6831. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6832. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  6833. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  6834. conv[3] = xx % 10 + '0';
  6835. conv[4] = 0;
  6836. return conv;
  6837. }
  6838. // Convert float to rj string with 12345 format
  6839. char *ftostr5(const float &x) {
  6840. long xx = abs(x);
  6841. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  6842. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  6843. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  6844. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  6845. conv[4] = xx % 10 + '0';
  6846. conv[5] = 0;
  6847. return conv;
  6848. }
  6849. // Convert float to string with +1234.5 format
  6850. char *ftostr51(const float &x)
  6851. {
  6852. long xx = x * 10;
  6853. conv[0] = (xx >= 0) ? '+' : '-';
  6854. xx = abs(xx);
  6855. conv[1] = (xx / 10000) % 10 + '0';
  6856. conv[2] = (xx / 1000) % 10 + '0';
  6857. conv[3] = (xx / 100) % 10 + '0';
  6858. conv[4] = (xx / 10) % 10 + '0';
  6859. conv[5] = '.';
  6860. conv[6] = (xx) % 10 + '0';
  6861. conv[7] = 0;
  6862. return conv;
  6863. }
  6864. // Convert float to string with +123.45 format
  6865. char *ftostr52(const float &x)
  6866. {
  6867. long xx = x * 100;
  6868. conv[0] = (xx >= 0) ? '+' : '-';
  6869. xx = abs(xx);
  6870. conv[1] = (xx / 10000) % 10 + '0';
  6871. conv[2] = (xx / 1000) % 10 + '0';
  6872. conv[3] = (xx / 100) % 10 + '0';
  6873. conv[4] = '.';
  6874. conv[5] = (xx / 10) % 10 + '0';
  6875. conv[6] = (xx) % 10 + '0';
  6876. conv[7] = 0;
  6877. return conv;
  6878. }
  6879. #endif //ULTRA_LCD