ultralcd.cpp 155 KB

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