ultralcd.cpp 149 KB

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