ultralcd.cpp 153 KB

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