ultralcd.cpp 152 KB

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