ultralcd.cpp 157 KB

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