ultralcd.cpp 151 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809
  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. KEEPALIVE_STATE(PAUSED_FOR_USER);
  1031. while (!lcd_clicked())
  1032. {
  1033. manage_heater();
  1034. manage_inactivity(true);
  1035. delay(100);
  1036. }
  1037. KEEPALIVE_STATE(NOT_BUSY);
  1038. lcd_quick_feedback();
  1039. lcd_return_to_status();
  1040. }
  1041. }
  1042. static void _lcd_move(const char *name, int axis, int min, int max) {
  1043. if (encoderPosition != 0) {
  1044. refresh_cmd_timeout();
  1045. if (! planner_queue_full()) {
  1046. current_position[axis] += float((int)encoderPosition) * move_menu_scale;
  1047. if (min_software_endstops && current_position[axis] < min) current_position[axis] = min;
  1048. if (max_software_endstops && current_position[axis] > max) current_position[axis] = max;
  1049. encoderPosition = 0;
  1050. world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]);
  1051. 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);
  1052. lcdDrawUpdate = 1;
  1053. }
  1054. }
  1055. if (lcdDrawUpdate) lcd_implementation_drawedit(name, ftostr31(current_position[axis]));
  1056. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis); {
  1057. }
  1058. }
  1059. static void lcd_move_e()
  1060. {
  1061. if (degHotend0() > EXTRUDE_MINTEMP) {
  1062. if (encoderPosition != 0)
  1063. {
  1064. refresh_cmd_timeout();
  1065. if (! planner_queue_full()) {
  1066. current_position[E_AXIS] += float((int)encoderPosition) * move_menu_scale;
  1067. encoderPosition = 0;
  1068. 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);
  1069. lcdDrawUpdate = 1;
  1070. }
  1071. }
  1072. if (lcdDrawUpdate)
  1073. {
  1074. lcd_implementation_drawedit(PSTR("Extruder"), ftostr31(current_position[E_AXIS]));
  1075. }
  1076. if (LCD_CLICKED) lcd_goto_menu(lcd_move_menu_axis);
  1077. }
  1078. else {
  1079. lcd_implementation_clear();
  1080. lcd.setCursor(0, 0);
  1081. lcd_printPGM(MSG_ERROR);
  1082. lcd.setCursor(0, 2);
  1083. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  1084. delay(2000);
  1085. lcd_return_to_status();
  1086. }
  1087. }
  1088. void lcd_service_mode_show_result() {
  1089. float angleDiff;
  1090. lcd_set_custom_characters_degree();
  1091. count_xyz_details();
  1092. angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW));
  1093. lcd_update_enable(false);
  1094. lcd_implementation_clear();
  1095. lcd_printPGM(MSG_Y_DISTANCE_FROM_MIN);
  1096. lcd_print_at_PGM(0, 1, MSG_LEFT);
  1097. lcd_print_at_PGM(0, 2, MSG_CENTER);
  1098. lcd_print_at_PGM(0, 3, MSG_RIGHT);
  1099. for (int i = 0; i < 3; i++) {
  1100. if(distance_from_min[i] < 200) {
  1101. lcd_print_at_PGM(11, i + 1, PSTR(""));
  1102. lcd.print(distance_from_min[i]);
  1103. lcd_print_at_PGM((distance_from_min[i] < 0) ? 17 : 16, i + 1, PSTR("mm"));
  1104. } else lcd_print_at_PGM(11, i + 1, PSTR("N/A"));
  1105. }
  1106. delay_keep_alive(500);
  1107. KEEPALIVE_STATE(PAUSED_FOR_USER);
  1108. while (!lcd_clicked()) {
  1109. delay_keep_alive(100);
  1110. }
  1111. delay_keep_alive(500);
  1112. lcd_implementation_clear();
  1113. lcd_printPGM(MSG_MEASURED_SKEW);
  1114. if (angleDiff < 100) {
  1115. lcd.setCursor(15, 0);
  1116. lcd.print(angleDiff * 180 / M_PI);
  1117. lcd.print(LCD_STR_DEGREE);
  1118. }else lcd_print_at_PGM(16, 0, PSTR("N/A"));
  1119. lcd_print_at_PGM(0, 1, PSTR("--------------------"));
  1120. lcd_print_at_PGM(0, 2, MSG_SLIGHT_SKEW);
  1121. lcd_print_at_PGM(15, 2, PSTR(""));
  1122. lcd.print(bed_skew_angle_mild * 180 / M_PI);
  1123. lcd.print(LCD_STR_DEGREE);
  1124. lcd_print_at_PGM(0, 3, MSG_SEVERE_SKEW);
  1125. lcd_print_at_PGM(15, 3, PSTR(""));
  1126. lcd.print(bed_skew_angle_extreme * 180 / M_PI);
  1127. lcd.print(LCD_STR_DEGREE);
  1128. delay_keep_alive(500);
  1129. while (!lcd_clicked()) {
  1130. delay_keep_alive(100);
  1131. }
  1132. KEEPALIVE_STATE(NOT_BUSY);
  1133. delay_keep_alive(500);
  1134. lcd_set_custom_characters_arrows();
  1135. lcd_return_to_status();
  1136. lcd_update_enable(true);
  1137. lcd_update(2);
  1138. }
  1139. // Save a single axis babystep value.
  1140. void EEPROM_save_B(int pos, int* value)
  1141. {
  1142. union Data data;
  1143. data.value = *value;
  1144. eeprom_update_byte((unsigned char*)pos, data.b[0]);
  1145. eeprom_update_byte((unsigned char*)pos + 1, data.b[1]);
  1146. }
  1147. // Read a single axis babystep value.
  1148. void EEPROM_read_B(int pos, int* value)
  1149. {
  1150. union Data data;
  1151. data.b[0] = eeprom_read_byte((unsigned char*)pos);
  1152. data.b[1] = eeprom_read_byte((unsigned char*)pos + 1);
  1153. *value = data.value;
  1154. }
  1155. static void lcd_move_x() {
  1156. _lcd_move(PSTR("X"), X_AXIS, X_MIN_POS, X_MAX_POS);
  1157. }
  1158. static void lcd_move_y() {
  1159. _lcd_move(PSTR("Y"), Y_AXIS, Y_MIN_POS, Y_MAX_POS);
  1160. }
  1161. static void lcd_move_z() {
  1162. _lcd_move(PSTR("Z"), Z_AXIS, Z_MIN_POS, Z_MAX_POS);
  1163. }
  1164. static void _lcd_babystep(int axis, const char *msg)
  1165. {
  1166. if (menuData.babyStep.status == 0) {
  1167. // Menu was entered.
  1168. // Initialize its status.
  1169. menuData.babyStep.status = 1;
  1170. check_babystep();
  1171. EEPROM_read_B(EEPROM_BABYSTEP_X, &menuData.babyStep.babystepMem[0]);
  1172. EEPROM_read_B(EEPROM_BABYSTEP_Y, &menuData.babyStep.babystepMem[1]);
  1173. EEPROM_read_B(EEPROM_BABYSTEP_Z, &menuData.babyStep.babystepMem[2]);
  1174. menuData.babyStep.babystepMemMM[0] = menuData.babyStep.babystepMem[0]/axis_steps_per_unit[X_AXIS];
  1175. menuData.babyStep.babystepMemMM[1] = menuData.babyStep.babystepMem[1]/axis_steps_per_unit[Y_AXIS];
  1176. menuData.babyStep.babystepMemMM[2] = menuData.babyStep.babystepMem[2]/axis_steps_per_unit[Z_AXIS];
  1177. lcdDrawUpdate = 1;
  1178. //SERIAL_ECHO("Z baby step: ");
  1179. //SERIAL_ECHO(menuData.babyStep.babystepMem[2]);
  1180. // Wait 90 seconds before closing the live adjust dialog.
  1181. lcd_timeoutToStatus = millis() + 90000;
  1182. }
  1183. if (encoderPosition != 0)
  1184. {
  1185. if (homing_flag) encoderPosition = 0;
  1186. menuData.babyStep.babystepMem[axis] += (int)encoderPosition;
  1187. if (axis == 2) {
  1188. if (menuData.babyStep.babystepMem[axis] < Z_BABYSTEP_MIN) menuData.babyStep.babystepMem[axis] = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm
  1189. else if (menuData.babyStep.babystepMem[axis] > Z_BABYSTEP_MAX) menuData.babyStep.babystepMem[axis] = Z_BABYSTEP_MAX; //0
  1190. else {
  1191. CRITICAL_SECTION_START
  1192. babystepsTodo[axis] += (int)encoderPosition;
  1193. CRITICAL_SECTION_END
  1194. }
  1195. }
  1196. menuData.babyStep.babystepMemMM[axis] = menuData.babyStep.babystepMem[axis]/axis_steps_per_unit[axis];
  1197. delay(50);
  1198. encoderPosition = 0;
  1199. lcdDrawUpdate = 1;
  1200. }
  1201. if (lcdDrawUpdate)
  1202. lcd_implementation_drawedit_2(msg, ftostr13ns(menuData.babyStep.babystepMemMM[axis]));
  1203. if (LCD_CLICKED || menuExiting) {
  1204. // Only update the EEPROM when leaving the menu.
  1205. EEPROM_save_B(
  1206. (axis == 0) ? EEPROM_BABYSTEP_X : ((axis == 1) ? EEPROM_BABYSTEP_Y : EEPROM_BABYSTEP_Z),
  1207. &menuData.babyStep.babystepMem[axis]);
  1208. }
  1209. if (LCD_CLICKED) lcd_goto_menu(lcd_main_menu);
  1210. }
  1211. static void lcd_babystep_x() {
  1212. _lcd_babystep(X_AXIS, (MSG_BABYSTEPPING_X));
  1213. }
  1214. static void lcd_babystep_y() {
  1215. _lcd_babystep(Y_AXIS, (MSG_BABYSTEPPING_Y));
  1216. }
  1217. static void lcd_babystep_z() {
  1218. _lcd_babystep(Z_AXIS, (MSG_BABYSTEPPING_Z));
  1219. }
  1220. static void lcd_adjust_bed();
  1221. static void lcd_adjust_bed_reset()
  1222. {
  1223. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  1224. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT , 0);
  1225. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  1226. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  1227. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR , 0);
  1228. lcd_goto_menu(lcd_adjust_bed, 0, false);
  1229. // Because we did not leave the menu, the menuData did not reset.
  1230. // Force refresh of the bed leveling data.
  1231. menuData.adjustBed.status = 0;
  1232. }
  1233. void adjust_bed_reset() {
  1234. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  1235. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_LEFT, 0);
  1236. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, 0);
  1237. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_FRONT, 0);
  1238. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_REAR, 0);
  1239. menuData.adjustBed.left = menuData.adjustBed.left2 = 0;
  1240. menuData.adjustBed.right = menuData.adjustBed.right2 = 0;
  1241. menuData.adjustBed.front = menuData.adjustBed.front2 = 0;
  1242. menuData.adjustBed.rear = menuData.adjustBed.rear2 = 0;
  1243. }
  1244. #define BED_ADJUSTMENT_UM_MAX 50
  1245. static void lcd_adjust_bed()
  1246. {
  1247. if (menuData.adjustBed.status == 0) {
  1248. // Menu was entered.
  1249. // Initialize its status.
  1250. menuData.adjustBed.status = 1;
  1251. bool valid = false;
  1252. menuData.adjustBed.left = menuData.adjustBed.left2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT);
  1253. menuData.adjustBed.right = menuData.adjustBed.right2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT);
  1254. menuData.adjustBed.front = menuData.adjustBed.front2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT);
  1255. menuData.adjustBed.rear = menuData.adjustBed.rear2 = eeprom_read_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR);
  1256. if (eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1 &&
  1257. menuData.adjustBed.left >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.left <= BED_ADJUSTMENT_UM_MAX &&
  1258. menuData.adjustBed.right >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.right <= BED_ADJUSTMENT_UM_MAX &&
  1259. menuData.adjustBed.front >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.front <= BED_ADJUSTMENT_UM_MAX &&
  1260. menuData.adjustBed.rear >= -BED_ADJUSTMENT_UM_MAX && menuData.adjustBed.rear <= BED_ADJUSTMENT_UM_MAX)
  1261. valid = true;
  1262. if (! valid) {
  1263. // Reset the values: simulate an edit.
  1264. menuData.adjustBed.left2 = 0;
  1265. menuData.adjustBed.right2 = 0;
  1266. menuData.adjustBed.front2 = 0;
  1267. menuData.adjustBed.rear2 = 0;
  1268. }
  1269. lcdDrawUpdate = 1;
  1270. eeprom_update_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID, 1);
  1271. }
  1272. if (menuData.adjustBed.left != menuData.adjustBed.left2)
  1273. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_LEFT, menuData.adjustBed.left = menuData.adjustBed.left2);
  1274. if (menuData.adjustBed.right != menuData.adjustBed.right2)
  1275. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_RIGHT, menuData.adjustBed.right = menuData.adjustBed.right2);
  1276. if (menuData.adjustBed.front != menuData.adjustBed.front2)
  1277. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_FRONT, menuData.adjustBed.front = menuData.adjustBed.front2);
  1278. if (menuData.adjustBed.rear != menuData.adjustBed.rear2)
  1279. eeprom_update_int8((unsigned char*)EEPROM_BED_CORRECTION_REAR, menuData.adjustBed.rear = menuData.adjustBed.rear2);
  1280. START_MENU();
  1281. MENU_ITEM(back, MSG_SETTINGS, lcd_calibration_menu);
  1282. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_LEFT, &menuData.adjustBed.left2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1283. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_RIGHT, &menuData.adjustBed.right2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1284. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_FRONT, &menuData.adjustBed.front2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1285. MENU_ITEM_EDIT(int3, MSG_BED_CORRECTION_REAR, &menuData.adjustBed.rear2, -BED_ADJUSTMENT_UM_MAX, BED_ADJUSTMENT_UM_MAX);
  1286. MENU_ITEM(function, MSG_BED_CORRECTION_RESET, lcd_adjust_bed_reset);
  1287. END_MENU();
  1288. }
  1289. void pid_extruder() {
  1290. lcd_implementation_clear();
  1291. lcd.setCursor(1, 0);
  1292. lcd_printPGM(MSG_SET_TEMPERATURE);
  1293. pid_temp += int(encoderPosition);
  1294. if (pid_temp > HEATER_0_MAXTEMP) pid_temp = HEATER_0_MAXTEMP;
  1295. if (pid_temp < HEATER_0_MINTEMP) pid_temp = HEATER_0_MINTEMP;
  1296. encoderPosition = 0;
  1297. lcd.setCursor(1, 2);
  1298. lcd.print(ftostr3(pid_temp));
  1299. if (lcd_clicked()) {
  1300. lcd_commands_type = LCD_COMMAND_PID_EXTRUDER;
  1301. lcd_return_to_status();
  1302. lcd_update(2);
  1303. }
  1304. }
  1305. void lcd_adjust_z() {
  1306. int enc_dif = 0;
  1307. int cursor_pos = 1;
  1308. int fsm = 0;
  1309. lcd_implementation_clear();
  1310. lcd.setCursor(0, 0);
  1311. lcd_printPGM(MSG_ADJUSTZ);
  1312. lcd.setCursor(1, 1);
  1313. lcd_printPGM(MSG_YES);
  1314. lcd.setCursor(1, 2);
  1315. lcd_printPGM(MSG_NO);
  1316. lcd.setCursor(0, 1);
  1317. lcd.print(">");
  1318. enc_dif = encoderDiff;
  1319. while (fsm == 0) {
  1320. manage_heater();
  1321. manage_inactivity(true);
  1322. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1323. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1324. if (enc_dif > encoderDiff ) {
  1325. cursor_pos --;
  1326. }
  1327. if (enc_dif < encoderDiff ) {
  1328. cursor_pos ++;
  1329. }
  1330. if (cursor_pos > 2) {
  1331. cursor_pos = 2;
  1332. }
  1333. if (cursor_pos < 1) {
  1334. cursor_pos = 1;
  1335. }
  1336. lcd.setCursor(0, 1);
  1337. lcd.print(" ");
  1338. lcd.setCursor(0, 2);
  1339. lcd.print(" ");
  1340. lcd.setCursor(0, cursor_pos);
  1341. lcd.print(">");
  1342. enc_dif = encoderDiff;
  1343. delay(100);
  1344. }
  1345. }
  1346. if (lcd_clicked()) {
  1347. fsm = cursor_pos;
  1348. if (fsm == 1) {
  1349. int babystepLoadZ = 0;
  1350. EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ);
  1351. CRITICAL_SECTION_START
  1352. babystepsTodo[Z_AXIS] = babystepLoadZ;
  1353. CRITICAL_SECTION_END
  1354. } else {
  1355. int zero = 0;
  1356. EEPROM_save_B(EEPROM_BABYSTEP_X, &zero);
  1357. EEPROM_save_B(EEPROM_BABYSTEP_Y, &zero);
  1358. EEPROM_save_B(EEPROM_BABYSTEP_Z, &zero);
  1359. }
  1360. delay(500);
  1361. }
  1362. };
  1363. lcd_implementation_clear();
  1364. lcd_return_to_status();
  1365. }
  1366. void lcd_wait_for_cool_down() {
  1367. lcd_set_custom_characters_degree();
  1368. while ((degHotend(0)>MAX_HOTEND_TEMP_CALIBRATION) || (degBed() > MAX_BED_TEMP_CALIBRATION)) {
  1369. lcd_display_message_fullscreen_P(MSG_WAITING_TEMP);
  1370. lcd.setCursor(0, 4);
  1371. lcd.print(LCD_STR_THERMOMETER[0]);
  1372. lcd.print(ftostr3(degHotend(0)));
  1373. lcd.print("/0");
  1374. lcd.print(LCD_STR_DEGREE);
  1375. lcd.setCursor(9, 4);
  1376. lcd.print(LCD_STR_BEDTEMP[0]);
  1377. lcd.print(ftostr3(degBed()));
  1378. lcd.print("/0");
  1379. lcd.print(LCD_STR_DEGREE);
  1380. lcd_set_custom_characters();
  1381. delay_keep_alive(1000);
  1382. }
  1383. lcd_set_custom_characters_arrows();
  1384. }
  1385. // Lets the user move the Z carriage up to the end stoppers.
  1386. // When done, it sets the current Z to Z_MAX_POS and returns true.
  1387. // Otherwise the Z calibration is not changed and false is returned.
  1388. bool lcd_calibrate_z_end_stop_manual(bool only_z)
  1389. {
  1390. bool clean_nozzle_asked = false;
  1391. // 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.
  1392. current_position[Z_AXIS] = 0;
  1393. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  1394. // Until confirmed by the confirmation dialog.
  1395. for (;;) {
  1396. unsigned long previous_millis_cmd = millis();
  1397. const char *msg = only_z ? MSG_MOVE_CARRIAGE_TO_THE_TOP_Z : MSG_MOVE_CARRIAGE_TO_THE_TOP;
  1398. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  1399. const bool multi_screen = msg_next != NULL;
  1400. unsigned long previous_millis_msg = millis();
  1401. // Until the user finishes the z up movement.
  1402. encoderDiff = 0;
  1403. encoderPosition = 0;
  1404. for (;;) {
  1405. // if (millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  1406. // goto canceled;
  1407. manage_heater();
  1408. manage_inactivity(true);
  1409. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) {
  1410. delay(50);
  1411. previous_millis_cmd = millis();
  1412. encoderPosition += abs(encoderDiff / ENCODER_PULSES_PER_STEP);
  1413. encoderDiff = 0;
  1414. if (! planner_queue_full()) {
  1415. // Only move up, whatever direction the user rotates the encoder.
  1416. current_position[Z_AXIS] += fabs(encoderPosition);
  1417. encoderPosition = 0;
  1418. 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);
  1419. }
  1420. }
  1421. if (lcd_clicked()) {
  1422. // Abort a move if in progress.
  1423. planner_abort_hard();
  1424. while (lcd_clicked()) ;
  1425. delay(10);
  1426. while (lcd_clicked()) ;
  1427. break;
  1428. }
  1429. if (multi_screen && millis() - previous_millis_msg > 5000) {
  1430. if (msg_next == NULL)
  1431. msg_next = msg;
  1432. msg_next = lcd_display_message_fullscreen_P(msg_next);
  1433. previous_millis_msg = millis();
  1434. }
  1435. }
  1436. if (! clean_nozzle_asked) {
  1437. lcd_show_fullscreen_message_and_wait_P(MSG_CONFIRM_NOZZLE_CLEAN);
  1438. clean_nozzle_asked = true;
  1439. }
  1440. // Let the user confirm, that the Z carriage is at the top end stoppers.
  1441. int8_t result = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_CONFIRM_CARRIAGE_AT_THE_TOP, false);
  1442. if (result == -1)
  1443. goto canceled;
  1444. else if (result == 1)
  1445. goto calibrated;
  1446. // otherwise perform another round of the Z up dialog.
  1447. }
  1448. calibrated:
  1449. // Let the machine think the Z axis is a bit higher than it is, so it will not home into the bed
  1450. // during the search for the induction points.
  1451. current_position[Z_AXIS] = Z_MAX_POS-3.f;
  1452. plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
  1453. if(only_z){
  1454. lcd_display_message_fullscreen_P(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1);
  1455. lcd_implementation_print_at(0, 3, 1);
  1456. lcd_printPGM(MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2);
  1457. }else{
  1458. lcd_show_fullscreen_message_and_wait_P(MSG_PAPER);
  1459. lcd_display_message_fullscreen_P(MSG_FIND_BED_OFFSET_AND_SKEW_LINE1);
  1460. lcd_implementation_print_at(0, 2, 1);
  1461. lcd_printPGM(MSG_FIND_BED_OFFSET_AND_SKEW_LINE2);
  1462. }
  1463. return true;
  1464. canceled:
  1465. return false;
  1466. }
  1467. static inline bool pgm_is_whitespace(const char *c_addr)
  1468. {
  1469. const char c = pgm_read_byte(c_addr);
  1470. return c == ' ' || c == '\t' || c == '\r' || c == '\n';
  1471. }
  1472. static inline bool pgm_is_interpunction(const char *c_addr)
  1473. {
  1474. const char c = pgm_read_byte(c_addr);
  1475. return c == '.' || c == ',' || c == ':'|| c == ';' || c == '?' || c == '!' || c == '/';
  1476. }
  1477. const char* lcd_display_message_fullscreen_P(const char *msg, uint8_t &nlines)
  1478. {
  1479. // Disable update of the screen by the usual lcd_update() routine.
  1480. lcd_update_enable(false);
  1481. lcd_implementation_clear();
  1482. lcd.setCursor(0, 0);
  1483. const char *msgend = msg;
  1484. uint8_t row = 0;
  1485. bool multi_screen = false;
  1486. for (; row < 4; ++ row) {
  1487. while (pgm_is_whitespace(msg))
  1488. ++ msg;
  1489. if (pgm_read_byte(msg) == 0)
  1490. // End of the message.
  1491. break;
  1492. lcd.setCursor(0, row);
  1493. uint8_t linelen = min(strlen_P(msg), 20);
  1494. const char *msgend2 = msg + linelen;
  1495. msgend = msgend2;
  1496. if (row == 3 && linelen == 20) {
  1497. // Last line of the display, full line shall be displayed.
  1498. // Find out, whether this message will be split into multiple screens.
  1499. while (pgm_is_whitespace(msgend))
  1500. ++ msgend;
  1501. multi_screen = pgm_read_byte(msgend) != 0;
  1502. if (multi_screen)
  1503. msgend = (msgend2 -= 2);
  1504. }
  1505. if (pgm_read_byte(msgend) != 0 && ! pgm_is_whitespace(msgend) && ! pgm_is_interpunction(msgend)) {
  1506. // Splitting a word. Find the start of the current word.
  1507. while (msgend > msg && ! pgm_is_whitespace(msgend - 1))
  1508. -- msgend;
  1509. if (msgend == msg)
  1510. // Found a single long word, which cannot be split. Just cut it.
  1511. msgend = msgend2;
  1512. }
  1513. for (; msg < msgend; ++ msg) {
  1514. char c = char(pgm_read_byte(msg));
  1515. if (c == '~')
  1516. c = ' ';
  1517. lcd.print(c);
  1518. }
  1519. }
  1520. if (multi_screen) {
  1521. // Display the "next screen" indicator character.
  1522. // lcd_set_custom_characters_arrows();
  1523. lcd_set_custom_characters_nextpage();
  1524. lcd.setCursor(19, 3);
  1525. // Display the down arrow.
  1526. lcd.print(char(1));
  1527. }
  1528. nlines = row;
  1529. return multi_screen ? msgend : NULL;
  1530. }
  1531. void lcd_show_fullscreen_message_and_wait_P(const char *msg)
  1532. {
  1533. const char *msg_next = lcd_display_message_fullscreen_P(msg);
  1534. bool multi_screen = msg_next != NULL;
  1535. KEEPALIVE_STATE(PAUSED_FOR_USER);
  1536. // Until confirmed by a button click.
  1537. for (;;) {
  1538. // Wait for 5 seconds before displaying the next text.
  1539. for (uint8_t i = 0; i < 100; ++ i) {
  1540. delay_keep_alive(50);
  1541. if (lcd_clicked()) {
  1542. while (lcd_clicked()) ;
  1543. delay(10);
  1544. while (lcd_clicked()) ;
  1545. KEEPALIVE_STATE(IN_HANDLER);
  1546. return;
  1547. }
  1548. }
  1549. if (multi_screen) {
  1550. if (msg_next == NULL)
  1551. msg_next = msg;
  1552. msg_next = lcd_display_message_fullscreen_P(msg_next);
  1553. }
  1554. }
  1555. }
  1556. void lcd_wait_for_click()
  1557. {
  1558. KEEPALIVE_STATE(PAUSED_FOR_USER);
  1559. for (;;) {
  1560. manage_heater();
  1561. manage_inactivity(true);
  1562. if (lcd_clicked()) {
  1563. while (lcd_clicked()) ;
  1564. delay(10);
  1565. while (lcd_clicked()) ;
  1566. KEEPALIVE_STATE(IN_HANDLER);
  1567. return;
  1568. }
  1569. }
  1570. }
  1571. int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow_timeouting, bool default_yes)
  1572. {
  1573. lcd_display_message_fullscreen_P(msg);
  1574. if (default_yes) {
  1575. lcd.setCursor(0, 2);
  1576. lcd_printPGM(PSTR(">"));
  1577. lcd_printPGM(MSG_YES);
  1578. lcd.setCursor(1, 3);
  1579. lcd_printPGM(MSG_NO);
  1580. }
  1581. else {
  1582. lcd.setCursor(1, 2);
  1583. lcd_printPGM(MSG_YES);
  1584. lcd.setCursor(0, 3);
  1585. lcd_printPGM(PSTR(">"));
  1586. lcd_printPGM(MSG_NO);
  1587. }
  1588. bool yes = default_yes ? true : false;
  1589. // Wait for user confirmation or a timeout.
  1590. unsigned long previous_millis_cmd = millis();
  1591. int8_t enc_dif = encoderDiff;
  1592. KEEPALIVE_STATE(PAUSED_FOR_USER);
  1593. for (;;) {
  1594. if (allow_timeouting && millis() - previous_millis_cmd > LCD_TIMEOUT_TO_STATUS)
  1595. return -1;
  1596. manage_heater();
  1597. manage_inactivity(true);
  1598. if (abs(enc_dif - encoderDiff) > 4) {
  1599. lcd.setCursor(0, 2);
  1600. if (enc_dif < encoderDiff && yes) {
  1601. lcd_printPGM((PSTR(" ")));
  1602. lcd.setCursor(0, 3);
  1603. lcd_printPGM((PSTR(">")));
  1604. yes = false;
  1605. }
  1606. else if (enc_dif > encoderDiff && !yes) {
  1607. lcd_printPGM((PSTR(">")));
  1608. lcd.setCursor(0, 3);
  1609. lcd_printPGM((PSTR(" ")));
  1610. yes = true;
  1611. }
  1612. enc_dif = encoderDiff;
  1613. }
  1614. if (lcd_clicked()) {
  1615. while (lcd_clicked());
  1616. delay(10);
  1617. while (lcd_clicked());
  1618. KEEPALIVE_STATE(IN_HANDLER);
  1619. return yes;
  1620. }
  1621. }
  1622. }
  1623. void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, uint8_t point_too_far_mask)
  1624. {
  1625. const char *msg = NULL;
  1626. if (result == BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND) {
  1627. lcd_show_fullscreen_message_and_wait_P(MSG_BED_SKEW_OFFSET_DETECTION_POINT_NOT_FOUND);
  1628. } else if (result == BED_SKEW_OFFSET_DETECTION_FITTING_FAILED) {
  1629. if (point_too_far_mask == 0)
  1630. msg = MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
  1631. else if (point_too_far_mask == 2 || point_too_far_mask == 7)
  1632. // Only the center point or all the three front points.
  1633. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_BOTH_FAR;
  1634. else if (point_too_far_mask & 1 == 0)
  1635. // The right and maybe the center point out of reach.
  1636. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_RIGHT_FAR;
  1637. else
  1638. // The left and maybe the center point out of reach.
  1639. msg = MSG_BED_SKEW_OFFSET_DETECTION_FAILED_FRONT_LEFT_FAR;
  1640. lcd_show_fullscreen_message_and_wait_P(msg);
  1641. } else {
  1642. if (point_too_far_mask != 0) {
  1643. if (point_too_far_mask == 2 || point_too_far_mask == 7)
  1644. // Only the center point or all the three front points.
  1645. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_BOTH_FAR;
  1646. else if (point_too_far_mask & 1 == 0)
  1647. // The right and maybe the center point out of reach.
  1648. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_RIGHT_FAR;
  1649. else
  1650. // The left and maybe the center point out of reach.
  1651. msg = MSG_BED_SKEW_OFFSET_DETECTION_WARNING_FRONT_LEFT_FAR;
  1652. lcd_show_fullscreen_message_and_wait_P(msg);
  1653. }
  1654. if (point_too_far_mask == 0 || result > 0) {
  1655. switch (result) {
  1656. default:
  1657. // should not happen
  1658. msg = MSG_BED_SKEW_OFFSET_DETECTION_FITTING_FAILED;
  1659. break;
  1660. case BED_SKEW_OFFSET_DETECTION_PERFECT:
  1661. msg = MSG_BED_SKEW_OFFSET_DETECTION_PERFECT;
  1662. break;
  1663. case BED_SKEW_OFFSET_DETECTION_SKEW_MILD:
  1664. msg = MSG_BED_SKEW_OFFSET_DETECTION_SKEW_MILD;
  1665. break;
  1666. case BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME:
  1667. msg = MSG_BED_SKEW_OFFSET_DETECTION_SKEW_EXTREME;
  1668. break;
  1669. }
  1670. lcd_show_fullscreen_message_and_wait_P(msg);
  1671. }
  1672. }
  1673. }
  1674. static void lcd_show_end_stops() {
  1675. lcd.setCursor(0, 0);
  1676. lcd_printPGM((PSTR("End stops diag")));
  1677. lcd.setCursor(0, 1);
  1678. lcd_printPGM((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("X1")) : (PSTR("X0")));
  1679. lcd.setCursor(0, 2);
  1680. lcd_printPGM((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Y1")) : (PSTR("Y0")));
  1681. lcd.setCursor(0, 3);
  1682. lcd_printPGM((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? (PSTR("Z1")) : (PSTR("Z0")));
  1683. }
  1684. static void menu_show_end_stops() {
  1685. lcd_show_end_stops();
  1686. if (LCD_CLICKED) lcd_goto_menu(lcd_calibration_menu);
  1687. }
  1688. // Lets the user move the Z carriage up to the end stoppers.
  1689. // When done, it sets the current Z to Z_MAX_POS and returns true.
  1690. // Otherwise the Z calibration is not changed and false is returned.
  1691. void lcd_diag_show_end_stops()
  1692. {
  1693. int enc_dif = encoderDiff;
  1694. lcd_implementation_clear();
  1695. for (;;) {
  1696. manage_heater();
  1697. manage_inactivity(true);
  1698. lcd_show_end_stops();
  1699. if (lcd_clicked()) {
  1700. while (lcd_clicked()) ;
  1701. delay(10);
  1702. while (lcd_clicked()) ;
  1703. break;
  1704. }
  1705. }
  1706. lcd_implementation_clear();
  1707. lcd_return_to_status();
  1708. }
  1709. void prusa_statistics(int _message, uint8_t _fil_nr) {
  1710. #ifdef DEBUG_DISABLE_PRUSA_STATISTICS
  1711. return;
  1712. #endif //DEBUG_DISABLE_PRUSA_STATISTICS
  1713. switch (_message)
  1714. {
  1715. case 0: // default message
  1716. if (IS_SD_PRINTING)
  1717. {
  1718. SERIAL_ECHO("{");
  1719. prusa_stat_printerstatus(4);
  1720. prusa_stat_farm_number();
  1721. prusa_stat_printinfo();
  1722. SERIAL_ECHOLN("}");
  1723. status_number = 4;
  1724. }
  1725. else
  1726. {
  1727. SERIAL_ECHO("{");
  1728. prusa_stat_printerstatus(1);
  1729. prusa_stat_farm_number();
  1730. SERIAL_ECHOLN("}");
  1731. status_number = 1;
  1732. }
  1733. break;
  1734. case 1: // 1 heating
  1735. farm_status = 2;
  1736. SERIAL_ECHO("{");
  1737. prusa_stat_printerstatus(2);
  1738. prusa_stat_farm_number();
  1739. SERIAL_ECHOLN("}");
  1740. status_number = 2;
  1741. farm_timer = 1;
  1742. break;
  1743. case 2: // heating done
  1744. farm_status = 3;
  1745. SERIAL_ECHO("{");
  1746. prusa_stat_printerstatus(3);
  1747. prusa_stat_farm_number();
  1748. SERIAL_ECHOLN("}");
  1749. status_number = 3;
  1750. farm_timer = 1;
  1751. if (IS_SD_PRINTING)
  1752. {
  1753. farm_status = 4;
  1754. SERIAL_ECHO("{");
  1755. prusa_stat_printerstatus(4);
  1756. prusa_stat_farm_number();
  1757. SERIAL_ECHOLN("}");
  1758. status_number = 4;
  1759. }
  1760. else
  1761. {
  1762. SERIAL_ECHO("{");
  1763. prusa_stat_printerstatus(3);
  1764. prusa_stat_farm_number();
  1765. SERIAL_ECHOLN("}");
  1766. status_number = 3;
  1767. }
  1768. farm_timer = 1;
  1769. break;
  1770. case 3: // filament change
  1771. break;
  1772. case 4: // print succesfull
  1773. SERIAL_ECHO("{[RES:1][FIL:");
  1774. MYSERIAL.print(int(_fil_nr));
  1775. SERIAL_ECHO("]");
  1776. prusa_stat_printerstatus(status_number);
  1777. prusa_stat_farm_number();
  1778. SERIAL_ECHOLN("}");
  1779. farm_timer = 2;
  1780. break;
  1781. case 5: // print not succesfull
  1782. SERIAL_ECHO("{[RES:0][FIL:");
  1783. MYSERIAL.print(int(_fil_nr));
  1784. SERIAL_ECHO("]");
  1785. prusa_stat_printerstatus(status_number);
  1786. prusa_stat_farm_number();
  1787. SERIAL_ECHOLN("}");
  1788. farm_timer = 2;
  1789. break;
  1790. case 6: // print done
  1791. SERIAL_ECHO("{[PRN:8]");
  1792. prusa_stat_farm_number();
  1793. SERIAL_ECHOLN("}");
  1794. status_number = 8;
  1795. farm_timer = 2;
  1796. break;
  1797. case 7: // print done - stopped
  1798. SERIAL_ECHO("{[PRN:9]");
  1799. prusa_stat_farm_number();
  1800. SERIAL_ECHOLN("}");
  1801. status_number = 9;
  1802. farm_timer = 2;
  1803. break;
  1804. case 8: // printer started
  1805. SERIAL_ECHO("{[PRN:0][PFN:");
  1806. status_number = 0;
  1807. SERIAL_ECHO(farm_no);
  1808. SERIAL_ECHOLN("]}");
  1809. farm_timer = 2;
  1810. break;
  1811. case 20: // echo farm no
  1812. SERIAL_ECHO("{");
  1813. prusa_stat_printerstatus(status_number);
  1814. prusa_stat_farm_number();
  1815. SERIAL_ECHOLN("}");
  1816. farm_timer = 5;
  1817. break;
  1818. case 21: // temperatures
  1819. SERIAL_ECHO("{");
  1820. prusa_stat_temperatures();
  1821. prusa_stat_farm_number();
  1822. prusa_stat_printerstatus(status_number);
  1823. SERIAL_ECHOLN("}");
  1824. break;
  1825. case 22: // waiting for filament change
  1826. SERIAL_ECHO("{[PRN:5]");
  1827. prusa_stat_farm_number();
  1828. SERIAL_ECHOLN("}");
  1829. status_number = 5;
  1830. break;
  1831. case 90: // Error - Thermal Runaway
  1832. SERIAL_ECHO("{[ERR:1]");
  1833. prusa_stat_farm_number();
  1834. SERIAL_ECHOLN("}");
  1835. break;
  1836. case 91: // Error - Thermal Runaway Preheat
  1837. SERIAL_ECHO("{[ERR:2]");
  1838. prusa_stat_farm_number();
  1839. SERIAL_ECHOLN("}");
  1840. break;
  1841. case 92: // Error - Min temp
  1842. SERIAL_ECHOLN("{[ERR:3]");
  1843. prusa_stat_farm_number();
  1844. SERIAL_ECHOLN("}");
  1845. break;
  1846. case 93: // Error - Max temp
  1847. SERIAL_ECHO("{[ERR:4]");
  1848. prusa_stat_farm_number();
  1849. SERIAL_ECHOLN("}");
  1850. break;
  1851. case 99: // heartbeat
  1852. SERIAL_ECHO("{[PRN:99]");
  1853. prusa_stat_temperatures();
  1854. SERIAL_ECHO("[PFN:");
  1855. SERIAL_ECHO(farm_no);
  1856. SERIAL_ECHO("]");
  1857. SERIAL_ECHOLN("}");
  1858. break;
  1859. }
  1860. }
  1861. static void prusa_stat_printerstatus(int _status)
  1862. {
  1863. SERIAL_ECHO("[PRN:");
  1864. SERIAL_ECHO(_status);
  1865. SERIAL_ECHO("]");
  1866. }
  1867. static void prusa_stat_farm_number() {
  1868. SERIAL_ECHO("[PFN:");
  1869. SERIAL_ECHO(farm_no);
  1870. SERIAL_ECHO("]");
  1871. }
  1872. static void prusa_stat_temperatures()
  1873. {
  1874. SERIAL_ECHO("[ST0:");
  1875. SERIAL_ECHO(target_temperature[0]);
  1876. SERIAL_ECHO("][STB:");
  1877. SERIAL_ECHO(target_temperature_bed);
  1878. SERIAL_ECHO("][AT0:");
  1879. SERIAL_ECHO(current_temperature[0]);
  1880. SERIAL_ECHO("][ATB:");
  1881. SERIAL_ECHO(current_temperature_bed);
  1882. SERIAL_ECHO("]");
  1883. }
  1884. static void prusa_stat_printinfo()
  1885. {
  1886. SERIAL_ECHO("[TFU:");
  1887. SERIAL_ECHO(total_filament_used);
  1888. SERIAL_ECHO("][PCD:");
  1889. SERIAL_ECHO(itostr3(card.percentDone()));
  1890. SERIAL_ECHO("][FEM:");
  1891. SERIAL_ECHO(itostr3(feedmultiply));
  1892. SERIAL_ECHO("][FNM:");
  1893. SERIAL_ECHO(longFilenameOLD);
  1894. SERIAL_ECHO("][TIM:");
  1895. if (starttime != 0)
  1896. {
  1897. SERIAL_ECHO(millis() / 1000 - starttime / 1000);
  1898. }
  1899. else
  1900. {
  1901. SERIAL_ECHO(0);
  1902. }
  1903. SERIAL_ECHO("][FWR:");
  1904. SERIAL_ECHO(FW_version);
  1905. SERIAL_ECHO("]");
  1906. }
  1907. void lcd_pick_babystep(){
  1908. int enc_dif = 0;
  1909. int cursor_pos = 1;
  1910. int fsm = 0;
  1911. lcd_implementation_clear();
  1912. lcd.setCursor(0, 0);
  1913. lcd_printPGM(MSG_PICK_Z);
  1914. lcd.setCursor(3, 2);
  1915. lcd.print("1");
  1916. lcd.setCursor(3, 3);
  1917. lcd.print("2");
  1918. lcd.setCursor(12, 2);
  1919. lcd.print("3");
  1920. lcd.setCursor(12, 3);
  1921. lcd.print("4");
  1922. lcd.setCursor(1, 2);
  1923. lcd.print(">");
  1924. enc_dif = encoderDiff;
  1925. while (fsm == 0) {
  1926. manage_heater();
  1927. manage_inactivity(true);
  1928. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  1929. if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  1930. if (enc_dif > encoderDiff ) {
  1931. cursor_pos --;
  1932. }
  1933. if (enc_dif < encoderDiff ) {
  1934. cursor_pos ++;
  1935. }
  1936. if (cursor_pos > 4) {
  1937. cursor_pos = 4;
  1938. }
  1939. if (cursor_pos < 1) {
  1940. cursor_pos = 1;
  1941. }
  1942. lcd.setCursor(1, 2);
  1943. lcd.print(" ");
  1944. lcd.setCursor(1, 3);
  1945. lcd.print(" ");
  1946. lcd.setCursor(10, 2);
  1947. lcd.print(" ");
  1948. lcd.setCursor(10, 3);
  1949. lcd.print(" ");
  1950. if (cursor_pos < 3) {
  1951. lcd.setCursor(1, cursor_pos+1);
  1952. lcd.print(">");
  1953. }else{
  1954. lcd.setCursor(10, cursor_pos-1);
  1955. lcd.print(">");
  1956. }
  1957. enc_dif = encoderDiff;
  1958. delay(100);
  1959. }
  1960. }
  1961. if (lcd_clicked()) {
  1962. fsm = cursor_pos;
  1963. int babyStepZ;
  1964. EEPROM_read_B(EEPROM_BABYSTEP_Z0+((fsm-1)*2),&babyStepZ);
  1965. EEPROM_save_B(EEPROM_BABYSTEP_Z,&babyStepZ);
  1966. calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
  1967. delay(500);
  1968. }
  1969. };
  1970. lcd_implementation_clear();
  1971. lcd_return_to_status();
  1972. }
  1973. void lcd_move_menu_axis()
  1974. {
  1975. START_MENU();
  1976. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  1977. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_x);
  1978. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_y);
  1979. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_z);
  1980. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_e);
  1981. END_MENU();
  1982. }
  1983. static void lcd_move_menu_1mm()
  1984. {
  1985. move_menu_scale = 1.0;
  1986. lcd_move_menu_axis();
  1987. }
  1988. void EEPROM_save(int pos, uint8_t* value, uint8_t size)
  1989. {
  1990. do
  1991. {
  1992. eeprom_write_byte((unsigned char*)pos, *value);
  1993. pos++;
  1994. value++;
  1995. } while (--size);
  1996. }
  1997. void EEPROM_read(int pos, uint8_t* value, uint8_t size)
  1998. {
  1999. do
  2000. {
  2001. *value = eeprom_read_byte((unsigned char*)pos);
  2002. pos++;
  2003. value++;
  2004. } while (--size);
  2005. }
  2006. #ifdef SDCARD_SORT_ALPHA
  2007. static void lcd_sort_type_set() {
  2008. uint8_t sdSort;
  2009. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  2010. switch (sdSort) {
  2011. case SD_SORT_TIME: sdSort = SD_SORT_ALPHA; break;
  2012. case SD_SORT_ALPHA: sdSort = SD_SORT_NONE; break;
  2013. default: sdSort = SD_SORT_TIME;
  2014. }
  2015. eeprom_update_byte((unsigned char *)EEPROM_SD_SORT, sdSort);
  2016. lcd_goto_menu(lcd_sdcard_menu, 1);
  2017. //lcd_update(2);
  2018. //delay(1000);
  2019. card.presort();
  2020. }
  2021. #endif //SDCARD_SORT_ALPHA
  2022. static void lcd_silent_mode_set() {
  2023. SilentModeMenu = !SilentModeMenu;
  2024. eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
  2025. digipot_init();
  2026. lcd_goto_menu(lcd_settings_menu, 7);
  2027. }
  2028. static void lcd_set_lang(unsigned char lang) {
  2029. lang_selected = lang;
  2030. firstrun = 1;
  2031. eeprom_update_byte((unsigned char *)EEPROM_LANG, lang);
  2032. /*langsel=0;*/
  2033. if (langsel == LANGSEL_MODAL)
  2034. // From modal mode to an active mode? This forces the menu to return to the setup menu.
  2035. langsel = LANGSEL_ACTIVE;
  2036. }
  2037. #if !SDSORT_USES_RAM
  2038. void lcd_set_arrows() {
  2039. void lcd_set_custom_characters_arrows();
  2040. }
  2041. void lcd_set_progress() {
  2042. lcd_set_custom_characters_progress();
  2043. }
  2044. #endif
  2045. void lcd_force_language_selection() {
  2046. eeprom_update_byte((unsigned char *)EEPROM_LANG, LANG_ID_FORCE_SELECTION);
  2047. }
  2048. static void lcd_language_menu()
  2049. {
  2050. START_MENU();
  2051. if (langsel == LANGSEL_OFF) {
  2052. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  2053. } else if (langsel == LANGSEL_ACTIVE) {
  2054. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  2055. }
  2056. for (int i=0;i<LANG_NUM;i++){
  2057. MENU_ITEM(setlang, MSG_LANGUAGE_NAME_EXPLICIT(i), i);
  2058. }
  2059. END_MENU();
  2060. }
  2061. void lcd_mesh_bedleveling()
  2062. {
  2063. mesh_bed_run_from_menu = true;
  2064. enquecommand_P(PSTR("G80"));
  2065. lcd_return_to_status();
  2066. }
  2067. void lcd_mesh_calibration()
  2068. {
  2069. enquecommand_P(PSTR("M45"));
  2070. lcd_return_to_status();
  2071. }
  2072. void lcd_mesh_calibration_z()
  2073. {
  2074. enquecommand_P(PSTR("M45 Z"));
  2075. lcd_return_to_status();
  2076. }
  2077. void lcd_pinda_calibration_menu()
  2078. {
  2079. START_MENU();
  2080. MENU_ITEM(back, MSG_MENU_CALIBRATION, lcd_calibration_menu);
  2081. MENU_ITEM(submenu, MSG_CALIBRATE_PINDA, lcd_calibrate_pinda);
  2082. if (temp_cal_active == false) {
  2083. MENU_ITEM(function, MSG_TEMP_CALIBRATION_OFF, lcd_temp_calibration_set);
  2084. }
  2085. else {
  2086. MENU_ITEM(function, MSG_TEMP_CALIBRATION_ON, lcd_temp_calibration_set);
  2087. }
  2088. END_MENU();
  2089. }
  2090. void lcd_temp_calibration_set() {
  2091. temp_cal_active = !temp_cal_active;
  2092. eeprom_update_byte((unsigned char *)EEPROM_TEMP_CAL_ACTIVE, temp_cal_active);
  2093. digipot_init();
  2094. lcd_goto_menu(lcd_pinda_calibration_menu, 2);
  2095. }
  2096. void lcd_calibrate_pinda() {
  2097. enquecommand_P(PSTR("G76"));
  2098. lcd_return_to_status();
  2099. }
  2100. #ifndef SNMM
  2101. /*void lcd_calibrate_extruder() {
  2102. if (degHotend0() > EXTRUDE_MINTEMP)
  2103. {
  2104. current_position[E_AXIS] = 0; //set initial position to zero
  2105. plan_set_e_position(current_position[E_AXIS]);
  2106. //long steps_start = st_get_position(E_AXIS);
  2107. long steps_final;
  2108. float e_steps_per_unit;
  2109. 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)
  2110. 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
  2111. const char *msg_e_cal_knob = MSG_E_CAL_KNOB;
  2112. const char *msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_e_cal_knob);
  2113. const bool multi_screen = msg_next_e_cal_knob != NULL;
  2114. unsigned long msg_millis;
  2115. lcd_show_fullscreen_message_and_wait_P(MSG_MARK_FIL);
  2116. lcd_implementation_clear();
  2117. lcd.setCursor(0, 1); lcd_printPGM(MSG_PLEASE_WAIT);
  2118. current_position[E_AXIS] += e_shift_calibration;
  2119. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  2120. st_synchronize();
  2121. lcd_display_message_fullscreen_P(msg_e_cal_knob);
  2122. msg_millis = millis();
  2123. while (!LCD_CLICKED) {
  2124. if (multi_screen && millis() - msg_millis > 5000) {
  2125. if (msg_next_e_cal_knob == NULL)
  2126. msg_next_e_cal_knob = msg_e_cal_knob;
  2127. msg_next_e_cal_knob = lcd_display_message_fullscreen_P(msg_next_e_cal_knob);
  2128. msg_millis = millis();
  2129. }
  2130. //manage_inactivity(true);
  2131. manage_heater();
  2132. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP) { //adjusting mark by knob rotation
  2133. delay_keep_alive(50);
  2134. //previous_millis_cmd = millis();
  2135. encoderPosition += (encoderDiff / ENCODER_PULSES_PER_STEP);
  2136. encoderDiff = 0;
  2137. if (!planner_queue_full()) {
  2138. current_position[E_AXIS] += float(abs((int)encoderPosition)) * 0.01; //0.05
  2139. encoderPosition = 0;
  2140. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feedrate, active_extruder);
  2141. }
  2142. }
  2143. }
  2144. steps_final = current_position[E_AXIS] * axis_steps_per_unit[E_AXIS];
  2145. //steps_final = st_get_position(E_AXIS);
  2146. lcdDrawUpdate = 1;
  2147. e_steps_per_unit = ((float)(steps_final)) / 100.0f;
  2148. if (e_steps_per_unit < MIN_E_STEPS_PER_UNIT) e_steps_per_unit = MIN_E_STEPS_PER_UNIT;
  2149. if (e_steps_per_unit > MAX_E_STEPS_PER_UNIT) e_steps_per_unit = MAX_E_STEPS_PER_UNIT;
  2150. lcd_implementation_clear();
  2151. axis_steps_per_unit[E_AXIS] = e_steps_per_unit;
  2152. enquecommand_P(PSTR("M500")); //store settings to eeprom
  2153. //lcd_implementation_drawedit(PSTR("Result"), ftostr31(axis_steps_per_unit[E_AXIS]));
  2154. //delay_keep_alive(2000);
  2155. delay_keep_alive(500);
  2156. lcd_show_fullscreen_message_and_wait_P(MSG_CLEAN_NOZZLE_E);
  2157. lcd_update_enable(true);
  2158. lcdDrawUpdate = 2;
  2159. }
  2160. else
  2161. {
  2162. lcd_implementation_clear();
  2163. lcd.setCursor(0, 0);
  2164. lcd_printPGM(MSG_ERROR);
  2165. lcd.setCursor(0, 2);
  2166. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  2167. delay(2000);
  2168. lcd_implementation_clear();
  2169. }
  2170. lcd_return_to_status();
  2171. }
  2172. void lcd_extr_cal_reset() {
  2173. float tmp1[] = DEFAULT_AXIS_STEPS_PER_UNIT;
  2174. axis_steps_per_unit[E_AXIS] = tmp1[3];
  2175. //extrudemultiply = 100;
  2176. enquecommand_P(PSTR("M500"));
  2177. }*/
  2178. #endif
  2179. void lcd_toshiba_flash_air_compatibility_toggle()
  2180. {
  2181. card.ToshibaFlashAir_enable(! card.ToshibaFlashAir_isEnabled());
  2182. eeprom_update_byte((uint8_t*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY, card.ToshibaFlashAir_isEnabled());
  2183. }
  2184. static void lcd_settings_menu()
  2185. {
  2186. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  2187. START_MENU();
  2188. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2189. MENU_ITEM(submenu, MSG_TEMPERATURE, lcd_control_temperature_menu);
  2190. if (!homing_flag)
  2191. {
  2192. MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu_1mm);
  2193. }
  2194. if (!isPrintPaused)
  2195. {
  2196. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  2197. }
  2198. if ((SilentModeMenu == 0) || (farm_mode) ) {
  2199. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set);
  2200. } else {
  2201. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set);
  2202. }
  2203. if (!isPrintPaused && !homing_flag)
  2204. {
  2205. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);
  2206. }
  2207. MENU_ITEM(submenu, MSG_LANGUAGE_SELECT, lcd_language_menu);
  2208. if (card.ToshibaFlashAir_isEnabled()) {
  2209. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON, lcd_toshiba_flash_air_compatibility_toggle);
  2210. } else {
  2211. MENU_ITEM(function, MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF, lcd_toshiba_flash_air_compatibility_toggle);
  2212. }
  2213. if (farm_mode)
  2214. {
  2215. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  2216. MENU_ITEM(function, PSTR("Disable farm mode"), lcd_disable_farm_mode);
  2217. }
  2218. MENU_ITEM(function, MSG_WIZARD, lcd_wizard);
  2219. END_MENU();
  2220. }
  2221. static void lcd_calibration_menu()
  2222. {
  2223. START_MENU();
  2224. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2225. if (!isPrintPaused)
  2226. {
  2227. MENU_ITEM(function, MSG_SELFTEST, lcd_selftest);
  2228. #ifdef MK1BP
  2229. // MK1
  2230. // "Calibrate Z"
  2231. MENU_ITEM(gcode, MSG_HOMEYZ, PSTR("G28 Z"));
  2232. #else //MK1BP
  2233. // MK2
  2234. MENU_ITEM(function, MSG_CALIBRATE_BED, lcd_mesh_calibration);
  2235. // "Calibrate Z" with storing the reference values to EEPROM.
  2236. MENU_ITEM(submenu, MSG_HOMEYZ, lcd_mesh_calibration_z);
  2237. #ifndef SNMM
  2238. //MENU_ITEM(function, MSG_CALIBRATE_E, lcd_calibrate_extruder);
  2239. #endif
  2240. // "Mesh Bed Leveling"
  2241. MENU_ITEM(submenu, MSG_MESH_BED_LEVELING, lcd_mesh_bedleveling);
  2242. #endif //MK1BP
  2243. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28 W"));
  2244. MENU_ITEM(submenu, MSG_BED_CORRECTION_MENU, lcd_adjust_bed);
  2245. #ifndef MK1BP
  2246. MENU_ITEM(submenu, MSG_CALIBRATION_PINDA_MENU, lcd_pinda_calibration_menu);
  2247. #endif //MK1BP
  2248. MENU_ITEM(submenu, MSG_PID_EXTRUDER, pid_extruder);
  2249. MENU_ITEM(submenu, MSG_SHOW_END_STOPS, menu_show_end_stops);
  2250. #ifndef MK1BP
  2251. MENU_ITEM(gcode, MSG_CALIBRATE_BED_RESET, PSTR("M44"));
  2252. #endif //MK1BP
  2253. #ifndef SNMM
  2254. //MENU_ITEM(function, MSG_RESET_CALIBRATE_E, lcd_extr_cal_reset);
  2255. #endif
  2256. }
  2257. END_MENU();
  2258. }
  2259. /*
  2260. void lcd_mylang_top(int hlaska) {
  2261. lcd.setCursor(0,0);
  2262. lcd.print(" ");
  2263. lcd.setCursor(0,0);
  2264. lcd_printPGM(MSG_ALL[hlaska-1][LANGUAGE_SELECT]);
  2265. }
  2266. void lcd_mylang_drawmenu(int cursor) {
  2267. int first = 0;
  2268. if (cursor>2) first = cursor-2;
  2269. if (cursor==LANG_NUM) first = LANG_NUM-3;
  2270. lcd.setCursor(0, 1);
  2271. lcd.print(" ");
  2272. lcd.setCursor(1, 1);
  2273. lcd_printPGM(MSG_ALL[first][LANGUAGE_NAME]);
  2274. lcd.setCursor(0, 2);
  2275. lcd.print(" ");
  2276. lcd.setCursor(1, 2);
  2277. lcd_printPGM(MSG_ALL[first+1][LANGUAGE_NAME]);
  2278. lcd.setCursor(0, 3);
  2279. lcd.print(" ");
  2280. lcd.setCursor(1, 3);
  2281. lcd_printPGM(MSG_ALL[first+2][LANGUAGE_NAME]);
  2282. if (cursor==1) lcd.setCursor(0, 1);
  2283. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  2284. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  2285. lcd.print(">");
  2286. if (cursor<LANG_NUM-1) {
  2287. lcd.setCursor(19,3);
  2288. lcd.print("\x01");
  2289. }
  2290. if (cursor>2) {
  2291. lcd.setCursor(19,1);
  2292. lcd.print("^");
  2293. }
  2294. }
  2295. */
  2296. void lcd_mylang_drawmenu(int cursor) {
  2297. int first = 0;
  2298. if (cursor>3) first = cursor-3;
  2299. if (cursor==LANG_NUM && LANG_NUM>4) first = LANG_NUM-4;
  2300. if (cursor==LANG_NUM && LANG_NUM==4) first = LANG_NUM-4;
  2301. lcd.setCursor(0, 0);
  2302. lcd.print(" ");
  2303. lcd.setCursor(1, 0);
  2304. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+0));
  2305. lcd.setCursor(0, 1);
  2306. lcd.print(" ");
  2307. lcd.setCursor(1, 1);
  2308. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+1));
  2309. lcd.setCursor(0, 2);
  2310. lcd.print(" ");
  2311. if (LANG_NUM > 2){
  2312. lcd.setCursor(1, 2);
  2313. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+2));
  2314. }
  2315. lcd.setCursor(0, 3);
  2316. lcd.print(" ");
  2317. if (LANG_NUM>3) {
  2318. lcd.setCursor(1, 3);
  2319. lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+3));
  2320. }
  2321. if (cursor==1) lcd.setCursor(0, 0);
  2322. if (cursor==2) lcd.setCursor(0, 1);
  2323. if (cursor>2) lcd.setCursor(0, 2);
  2324. if (cursor==LANG_NUM && LANG_NUM>3) lcd.setCursor(0, 3);
  2325. lcd.print(">");
  2326. if (cursor<LANG_NUM-1 && LANG_NUM>4) {
  2327. lcd.setCursor(19,3);
  2328. lcd.print("\x01");
  2329. }
  2330. if (cursor>3 && LANG_NUM>4) {
  2331. lcd.setCursor(19,0);
  2332. lcd.print("^");
  2333. }
  2334. }
  2335. void lcd_mylang_drawcursor(int cursor) {
  2336. if (cursor==1) lcd.setCursor(0, 1);
  2337. if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
  2338. if (cursor==LANG_NUM) lcd.setCursor(0, 3);
  2339. lcd.print(">");
  2340. }
  2341. void lcd_mylang() {
  2342. int enc_dif = 0;
  2343. int cursor_pos = 1;
  2344. lang_selected=255;
  2345. int hlaska=1;
  2346. int counter=0;
  2347. lcd_set_custom_characters_arrows();
  2348. lcd_implementation_clear();
  2349. //lcd_mylang_top(hlaska);
  2350. lcd_mylang_drawmenu(cursor_pos);
  2351. enc_dif = encoderDiff;
  2352. while ( (lang_selected == 255) ) {
  2353. manage_heater();
  2354. manage_inactivity(true);
  2355. if ( abs((enc_dif - encoderDiff)) > 4 ) {
  2356. //if ( (abs(enc_dif - encoderDiff)) > 1 ) {
  2357. if (enc_dif > encoderDiff ) {
  2358. cursor_pos --;
  2359. }
  2360. if (enc_dif < encoderDiff ) {
  2361. cursor_pos ++;
  2362. }
  2363. if (cursor_pos > LANG_NUM) {
  2364. cursor_pos = LANG_NUM;
  2365. }
  2366. if (cursor_pos < 1) {
  2367. cursor_pos = 1;
  2368. }
  2369. lcd_mylang_drawmenu(cursor_pos);
  2370. enc_dif = encoderDiff;
  2371. delay(100);
  2372. //}
  2373. } else delay(20);
  2374. if (lcd_clicked()) {
  2375. lcd_set_lang(cursor_pos-1);
  2376. delay(500);
  2377. }
  2378. /*
  2379. if (++counter == 80) {
  2380. hlaska++;
  2381. if(hlaska>LANG_NUM) hlaska=1;
  2382. lcd_mylang_top(hlaska);
  2383. lcd_mylang_drawcursor(cursor_pos);
  2384. counter=0;
  2385. }
  2386. */
  2387. };
  2388. if(MYSERIAL.available() > 1){
  2389. lang_selected = 0;
  2390. firstrun = 0;
  2391. }
  2392. lcd_set_custom_characters_degree();
  2393. lcd_implementation_clear();
  2394. lcd_return_to_status();
  2395. }
  2396. void bowden_menu() {
  2397. int enc_dif = encoderDiff;
  2398. int cursor_pos = 0;
  2399. lcd_implementation_clear();
  2400. lcd.setCursor(0, 0);
  2401. lcd.print(">");
  2402. for (int i = 0; i < 4; i++) {
  2403. lcd.setCursor(1, i);
  2404. lcd.print("Extruder ");
  2405. lcd.print(i);
  2406. lcd.print(": ");
  2407. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  2408. lcd.print(bowden_length[i] - 48);
  2409. }
  2410. enc_dif = encoderDiff;
  2411. while (1) {
  2412. manage_heater();
  2413. manage_inactivity(true);
  2414. if (abs((enc_dif - encoderDiff)) > 2) {
  2415. if (enc_dif > encoderDiff) {
  2416. cursor_pos--;
  2417. }
  2418. if (enc_dif < encoderDiff) {
  2419. cursor_pos++;
  2420. }
  2421. if (cursor_pos > 3) {
  2422. cursor_pos = 3;
  2423. }
  2424. if (cursor_pos < 0) {
  2425. cursor_pos = 0;
  2426. }
  2427. lcd.setCursor(0, 0);
  2428. lcd.print(" ");
  2429. lcd.setCursor(0, 1);
  2430. lcd.print(" ");
  2431. lcd.setCursor(0, 2);
  2432. lcd.print(" ");
  2433. lcd.setCursor(0, 3);
  2434. lcd.print(" ");
  2435. lcd.setCursor(0, cursor_pos);
  2436. lcd.print(">");
  2437. enc_dif = encoderDiff;
  2438. delay(100);
  2439. }
  2440. if (lcd_clicked()) {
  2441. while (lcd_clicked());
  2442. delay(10);
  2443. while (lcd_clicked());
  2444. lcd_implementation_clear();
  2445. while (1) {
  2446. manage_heater();
  2447. manage_inactivity(true);
  2448. lcd.setCursor(1, 1);
  2449. lcd.print("Extruder ");
  2450. lcd.print(cursor_pos);
  2451. lcd.print(": ");
  2452. lcd.setCursor(13, 1);
  2453. lcd.print(bowden_length[cursor_pos] - 48);
  2454. if (abs((enc_dif - encoderDiff)) > 2) {
  2455. if (enc_dif > encoderDiff) {
  2456. bowden_length[cursor_pos]--;
  2457. lcd.setCursor(13, 1);
  2458. lcd.print(bowden_length[cursor_pos] - 48);
  2459. enc_dif = encoderDiff;
  2460. }
  2461. if (enc_dif < encoderDiff) {
  2462. bowden_length[cursor_pos]++;
  2463. lcd.setCursor(13, 1);
  2464. lcd.print(bowden_length[cursor_pos] - 48);
  2465. enc_dif = encoderDiff;
  2466. }
  2467. }
  2468. delay(100);
  2469. if (lcd_clicked()) {
  2470. while (lcd_clicked());
  2471. delay(10);
  2472. while (lcd_clicked());
  2473. EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]);
  2474. if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) {
  2475. lcd_update_enable(true);
  2476. lcd_implementation_clear();
  2477. enc_dif = encoderDiff;
  2478. lcd.setCursor(0, cursor_pos);
  2479. lcd.print(">");
  2480. for (int i = 0; i < 4; i++) {
  2481. lcd.setCursor(1, i);
  2482. lcd.print("Extruder ");
  2483. lcd.print(i);
  2484. lcd.print(": ");
  2485. EEPROM_read_B(EEPROM_BOWDEN_LENGTH + i * 2, &bowden_length[i]);
  2486. lcd.print(bowden_length[i] - 48);
  2487. }
  2488. break;
  2489. }
  2490. else return;
  2491. }
  2492. }
  2493. }
  2494. }
  2495. }
  2496. static char snmm_stop_print_menu() { //menu for choosing which filaments will be unloaded in stop print
  2497. lcd_implementation_clear();
  2498. lcd_print_at_PGM(0,0,MSG_UNLOAD_FILAMENT); lcd.print(":");
  2499. lcd.setCursor(0, 1); lcd.print(">");
  2500. lcd_print_at_PGM(1,1,MSG_ALL);
  2501. lcd_print_at_PGM(1,2,MSG_USED);
  2502. lcd_print_at_PGM(1,3,MSG_CURRENT);
  2503. char cursor_pos = 1;
  2504. int enc_dif = 0;
  2505. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2506. while (1) {
  2507. manage_heater();
  2508. manage_inactivity(true);
  2509. if (abs((enc_dif - encoderDiff)) > 4) {
  2510. if ((abs(enc_dif - encoderDiff)) > 1) {
  2511. if (enc_dif > encoderDiff) cursor_pos--;
  2512. if (enc_dif < encoderDiff) cursor_pos++;
  2513. if (cursor_pos > 3) cursor_pos = 3;
  2514. if (cursor_pos < 1) cursor_pos = 1;
  2515. lcd.setCursor(0, 1);
  2516. lcd.print(" ");
  2517. lcd.setCursor(0, 2);
  2518. lcd.print(" ");
  2519. lcd.setCursor(0, 3);
  2520. lcd.print(" ");
  2521. lcd.setCursor(0, cursor_pos);
  2522. lcd.print(">");
  2523. enc_dif = encoderDiff;
  2524. delay(100);
  2525. }
  2526. }
  2527. if (lcd_clicked()) {
  2528. while (lcd_clicked());
  2529. delay(10);
  2530. while (lcd_clicked());
  2531. KEEPALIVE_STATE(IN_HANDLER);
  2532. return(cursor_pos - 1);
  2533. }
  2534. }
  2535. }
  2536. char choose_extruder_menu() {
  2537. int items_no = 4;
  2538. int first = 0;
  2539. int enc_dif = 0;
  2540. char cursor_pos = 1;
  2541. enc_dif = encoderDiff;
  2542. lcd_implementation_clear();
  2543. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  2544. lcd.setCursor(0, 1);
  2545. lcd.print(">");
  2546. for (int i = 0; i < 3; i++) {
  2547. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  2548. }
  2549. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2550. while (1) {
  2551. for (int i = 0; i < 3; i++) {
  2552. lcd.setCursor(2 + strlen_P(MSG_EXTRUDER), i+1);
  2553. lcd.print(first + i + 1);
  2554. }
  2555. manage_heater();
  2556. manage_inactivity(true);
  2557. if (abs((enc_dif - encoderDiff)) > 4) {
  2558. if ((abs(enc_dif - encoderDiff)) > 1) {
  2559. if (enc_dif > encoderDiff) {
  2560. cursor_pos--;
  2561. }
  2562. if (enc_dif < encoderDiff) {
  2563. cursor_pos++;
  2564. }
  2565. if (cursor_pos > 3) {
  2566. cursor_pos = 3;
  2567. if (first < items_no - 3) {
  2568. first++;
  2569. lcd_implementation_clear();
  2570. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  2571. for (int i = 0; i < 3; i++) {
  2572. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  2573. }
  2574. }
  2575. }
  2576. if (cursor_pos < 1) {
  2577. cursor_pos = 1;
  2578. if (first > 0) {
  2579. first--;
  2580. lcd_implementation_clear();
  2581. lcd_printPGM(MSG_CHOOSE_EXTRUDER);
  2582. for (int i = 0; i < 3; i++) {
  2583. lcd_print_at_PGM(1, i + 1, MSG_EXTRUDER);
  2584. }
  2585. }
  2586. }
  2587. lcd.setCursor(0, 1);
  2588. lcd.print(" ");
  2589. lcd.setCursor(0, 2);
  2590. lcd.print(" ");
  2591. lcd.setCursor(0, 3);
  2592. lcd.print(" ");
  2593. lcd.setCursor(0, cursor_pos);
  2594. lcd.print(">");
  2595. enc_dif = encoderDiff;
  2596. delay(100);
  2597. }
  2598. }
  2599. if (lcd_clicked()) {
  2600. lcd_update(2);
  2601. while (lcd_clicked());
  2602. delay(10);
  2603. while (lcd_clicked());
  2604. KEEPALIVE_STATE(IN_HANDLER);
  2605. return(cursor_pos + first - 1);
  2606. }
  2607. }
  2608. }
  2609. char reset_menu() {
  2610. #ifdef SNMM
  2611. int items_no = 5;
  2612. #else
  2613. int items_no = 4;
  2614. #endif
  2615. static int first = 0;
  2616. int enc_dif = 0;
  2617. char cursor_pos = 0;
  2618. const char *item [items_no];
  2619. item[0] = "Language";
  2620. item[1] = "Statistics";
  2621. item[2] = "Shipping prep";
  2622. item[3] = "All Data";
  2623. #ifdef SNMM
  2624. item[4] = "Bowden length";
  2625. #endif // SNMM
  2626. enc_dif = encoderDiff;
  2627. lcd_implementation_clear();
  2628. lcd.setCursor(0, 0);
  2629. lcd.print(">");
  2630. while (1) {
  2631. for (int i = 0; i < 4; i++) {
  2632. lcd.setCursor(1, i);
  2633. lcd.print(item[first + i]);
  2634. }
  2635. manage_heater();
  2636. manage_inactivity(true);
  2637. if (abs((enc_dif - encoderDiff)) > 4) {
  2638. if ((abs(enc_dif - encoderDiff)) > 1) {
  2639. if (enc_dif > encoderDiff) {
  2640. cursor_pos--;
  2641. }
  2642. if (enc_dif < encoderDiff) {
  2643. cursor_pos++;
  2644. }
  2645. if (cursor_pos > 3) {
  2646. cursor_pos = 3;
  2647. if (first < items_no - 4) {
  2648. first++;
  2649. lcd_implementation_clear();
  2650. }
  2651. }
  2652. if (cursor_pos < 0) {
  2653. cursor_pos = 0;
  2654. if (first > 0) {
  2655. first--;
  2656. lcd_implementation_clear();
  2657. }
  2658. }
  2659. lcd.setCursor(0, 0);
  2660. lcd.print(" ");
  2661. lcd.setCursor(0, 1);
  2662. lcd.print(" ");
  2663. lcd.setCursor(0, 2);
  2664. lcd.print(" ");
  2665. lcd.setCursor(0, 3);
  2666. lcd.print(" ");
  2667. lcd.setCursor(0, cursor_pos);
  2668. lcd.print(">");
  2669. enc_dif = encoderDiff;
  2670. delay(100);
  2671. }
  2672. }
  2673. if (lcd_clicked()) {
  2674. while (lcd_clicked());
  2675. delay(10);
  2676. while (lcd_clicked());
  2677. return(cursor_pos + first);
  2678. }
  2679. }
  2680. }
  2681. static void lcd_disable_farm_mode() {
  2682. int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
  2683. if (disable) {
  2684. enquecommand_P(PSTR("G99"));
  2685. lcd_return_to_status();
  2686. }
  2687. else {
  2688. lcd_goto_menu(lcd_settings_menu);
  2689. }
  2690. lcd_update_enable(true);
  2691. lcdDrawUpdate = 2;
  2692. }
  2693. static void lcd_ping_allert() {
  2694. if ((abs(millis() - allert_timer)*0.001) > PING_ALLERT_PERIOD) {
  2695. allert_timer = millis();
  2696. SET_OUTPUT(BEEPER);
  2697. for (int i = 0; i < 2; i++) {
  2698. WRITE(BEEPER, HIGH);
  2699. delay(50);
  2700. WRITE(BEEPER, LOW);
  2701. delay(100);
  2702. }
  2703. }
  2704. };
  2705. #ifdef SNMM
  2706. static void extr_mov(float shift, float feed_rate) { //move extruder no matter what the current heater temperature is
  2707. set_extrude_min_temp(.0);
  2708. current_position[E_AXIS] += shift;
  2709. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], feed_rate, active_extruder);
  2710. set_extrude_min_temp(EXTRUDE_MINTEMP);
  2711. }
  2712. void change_extr(int extr) { //switches multiplexer for extruders
  2713. st_synchronize();
  2714. delay(100);
  2715. disable_e0();
  2716. disable_e1();
  2717. disable_e2();
  2718. #ifdef SNMM
  2719. snmm_extruder = extr;
  2720. #endif
  2721. pinMode(E_MUX0_PIN, OUTPUT);
  2722. pinMode(E_MUX1_PIN, OUTPUT);
  2723. switch (extr) {
  2724. case 1:
  2725. WRITE(E_MUX0_PIN, HIGH);
  2726. WRITE(E_MUX1_PIN, LOW);
  2727. break;
  2728. case 2:
  2729. WRITE(E_MUX0_PIN, LOW);
  2730. WRITE(E_MUX1_PIN, HIGH);
  2731. break;
  2732. case 3:
  2733. WRITE(E_MUX0_PIN, HIGH);
  2734. WRITE(E_MUX1_PIN, HIGH);
  2735. break;
  2736. default:
  2737. WRITE(E_MUX0_PIN, LOW);
  2738. WRITE(E_MUX1_PIN, LOW);
  2739. break;
  2740. }
  2741. delay(100);
  2742. }
  2743. static int get_ext_nr() { //reads multiplexer input pins and return current extruder number (counted from 0)
  2744. return(2 * READ(E_MUX1_PIN) + READ(E_MUX0_PIN));
  2745. }
  2746. void display_loading() {
  2747. switch (snmm_extruder) {
  2748. case 1: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T1); break;
  2749. case 2: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T2); break;
  2750. case 3: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T3); break;
  2751. default: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T0); break;
  2752. }
  2753. }
  2754. void extr_adj(int extruder) //loading filament for SNMM
  2755. {
  2756. bool correct;
  2757. max_feedrate[E_AXIS] =80;
  2758. //max_feedrate[E_AXIS] = 50;
  2759. START:
  2760. lcd_implementation_clear();
  2761. lcd.setCursor(0, 0);
  2762. switch (extruder) {
  2763. case 1: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T1); break;
  2764. case 2: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T2); break;
  2765. case 3: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T3); break;
  2766. default: lcd_display_message_fullscreen_P(MSG_FILAMENT_LOADING_T0); break;
  2767. }
  2768. KEEPALIVE_STATE(PAUSED_FOR_USER);
  2769. do{
  2770. extr_mov(0.001,1000);
  2771. delay_keep_alive(2);
  2772. } while (!lcd_clicked());
  2773. //delay_keep_alive(500);
  2774. KEEPALIVE_STATE(IN_HANDLER);
  2775. st_synchronize();
  2776. //correct = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FIL_LOADED_CHECK, false);
  2777. //if (!correct) goto START;
  2778. //extr_mov(BOWDEN_LENGTH/2.f, 500); //dividing by 2 is there because of max. extrusion length limitation (x_max + y_max)
  2779. //extr_mov(BOWDEN_LENGTH/2.f, 500);
  2780. extr_mov(bowden_length[extruder], 500);
  2781. lcd_implementation_clear();
  2782. lcd.setCursor(0, 0); lcd_printPGM(MSG_LOADING_FILAMENT);
  2783. if(strlen(MSG_LOADING_FILAMENT)>18) lcd.setCursor(0, 1);
  2784. else lcd.print(" ");
  2785. lcd.print(snmm_extruder + 1);
  2786. lcd.setCursor(0, 2); lcd_printPGM(MSG_PLEASE_WAIT);
  2787. st_synchronize();
  2788. max_feedrate[E_AXIS] = 50;
  2789. lcd_update_enable(true);
  2790. lcd_return_to_status();
  2791. lcdDrawUpdate = 2;
  2792. }
  2793. void extr_unload() { //unloads filament
  2794. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  2795. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  2796. int8_t SilentMode;
  2797. if (degHotend0() > EXTRUDE_MINTEMP) {
  2798. lcd_implementation_clear();
  2799. lcd_display_message_fullscreen_P(PSTR(""));
  2800. max_feedrate[E_AXIS] = 50;
  2801. lcd.setCursor(0, 0); lcd_printPGM(MSG_UNLOADING_FILAMENT);
  2802. lcd.print(" ");
  2803. lcd.print(snmm_extruder + 1);
  2804. lcd.setCursor(0, 2); lcd_printPGM(MSG_PLEASE_WAIT);
  2805. if (current_position[Z_AXIS] < 15) {
  2806. current_position[Z_AXIS] += 15; //lifting in Z direction to make space for extrusion
  2807. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 25, active_extruder);
  2808. }
  2809. current_position[E_AXIS] += 10; //extrusion
  2810. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 10, active_extruder);
  2811. digipot_current(2, E_MOTOR_HIGH_CURRENT);
  2812. if (current_temperature[0] < 230) { //PLA & all other filaments
  2813. current_position[E_AXIS] += 5.4;
  2814. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2800 / 60, active_extruder);
  2815. current_position[E_AXIS] += 3.2;
  2816. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  2817. current_position[E_AXIS] += 3;
  2818. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3400 / 60, active_extruder);
  2819. }
  2820. else { //ABS
  2821. current_position[E_AXIS] += 3.1;
  2822. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder);
  2823. current_position[E_AXIS] += 3.1;
  2824. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
  2825. current_position[E_AXIS] += 4;
  2826. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder);
  2827. /*current_position[X_AXIS] += 23; //delay
  2828. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay
  2829. current_position[X_AXIS] -= 23; //delay
  2830. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); //delay*/
  2831. delay_keep_alive(4700);
  2832. }
  2833. max_feedrate[E_AXIS] = 80;
  2834. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  2835. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  2836. current_position[E_AXIS] -= (bowden_length[snmm_extruder] + 60 + FIL_LOAD_LENGTH) / 2;
  2837. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
  2838. st_synchronize();
  2839. //digipot_init();
  2840. if (SilentMode == 1) digipot_current(2, tmp_motor[2]); //set back to normal operation currents
  2841. else digipot_current(2, tmp_motor_loud[2]);
  2842. lcd_update_enable(true);
  2843. lcd_return_to_status();
  2844. max_feedrate[E_AXIS] = 50;
  2845. }
  2846. else {
  2847. lcd_implementation_clear();
  2848. lcd.setCursor(0, 0);
  2849. lcd_printPGM(MSG_ERROR);
  2850. lcd.setCursor(0, 2);
  2851. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  2852. delay(2000);
  2853. lcd_implementation_clear();
  2854. }
  2855. lcd_return_to_status();
  2856. }
  2857. //wrapper functions for loading filament
  2858. static void extr_adj_0(){
  2859. change_extr(0);
  2860. extr_adj(0);
  2861. }
  2862. static void extr_adj_1() {
  2863. change_extr(1);
  2864. extr_adj(1);
  2865. }
  2866. static void extr_adj_2() {
  2867. change_extr(2);
  2868. extr_adj(2);
  2869. }
  2870. static void extr_adj_3() {
  2871. change_extr(3);
  2872. extr_adj(3);
  2873. }
  2874. static void load_all() {
  2875. for (int i = 0; i < 4; i++) {
  2876. change_extr(i);
  2877. extr_adj(i);
  2878. }
  2879. }
  2880. //wrapper functions for changing extruders
  2881. static void extr_change_0() {
  2882. change_extr(0);
  2883. lcd_return_to_status();
  2884. }
  2885. static void extr_change_1() {
  2886. change_extr(1);
  2887. lcd_return_to_status();
  2888. }
  2889. static void extr_change_2() {
  2890. change_extr(2);
  2891. lcd_return_to_status();
  2892. }
  2893. static void extr_change_3() {
  2894. change_extr(3);
  2895. lcd_return_to_status();
  2896. }
  2897. //wrapper functions for unloading filament
  2898. void extr_unload_all() {
  2899. if (degHotend0() > EXTRUDE_MINTEMP) {
  2900. for (int i = 0; i < 4; i++) {
  2901. change_extr(i);
  2902. extr_unload();
  2903. }
  2904. }
  2905. else {
  2906. lcd_implementation_clear();
  2907. lcd.setCursor(0, 0);
  2908. lcd_printPGM(MSG_ERROR);
  2909. lcd.setCursor(0, 2);
  2910. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  2911. delay(2000);
  2912. lcd_implementation_clear();
  2913. lcd_return_to_status();
  2914. }
  2915. }
  2916. //unloading just used filament (for snmm)
  2917. void extr_unload_used() {
  2918. if (degHotend0() > EXTRUDE_MINTEMP) {
  2919. for (int i = 0; i < 4; i++) {
  2920. if (snmm_filaments_used & (1 << i)) {
  2921. change_extr(i);
  2922. extr_unload();
  2923. }
  2924. }
  2925. snmm_filaments_used = 0;
  2926. }
  2927. else {
  2928. lcd_implementation_clear();
  2929. lcd.setCursor(0, 0);
  2930. lcd_printPGM(MSG_ERROR);
  2931. lcd.setCursor(0, 2);
  2932. lcd_printPGM(MSG_PREHEAT_NOZZLE);
  2933. delay(2000);
  2934. lcd_implementation_clear();
  2935. lcd_return_to_status();
  2936. }
  2937. }
  2938. static void extr_unload_0() {
  2939. change_extr(0);
  2940. extr_unload();
  2941. }
  2942. static void extr_unload_1() {
  2943. change_extr(1);
  2944. extr_unload();
  2945. }
  2946. static void extr_unload_2() {
  2947. change_extr(2);
  2948. extr_unload();
  2949. }
  2950. static void extr_unload_3() {
  2951. change_extr(3);
  2952. extr_unload();
  2953. }
  2954. static void fil_load_menu()
  2955. {
  2956. START_MENU();
  2957. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2958. MENU_ITEM(function, MSG_LOAD_ALL, load_all);
  2959. MENU_ITEM(function, MSG_LOAD_FILAMENT_1, extr_adj_0);
  2960. MENU_ITEM(function, MSG_LOAD_FILAMENT_2, extr_adj_1);
  2961. MENU_ITEM(function, MSG_LOAD_FILAMENT_3, extr_adj_2);
  2962. MENU_ITEM(function, MSG_LOAD_FILAMENT_4, extr_adj_3);
  2963. END_MENU();
  2964. }
  2965. static void fil_unload_menu()
  2966. {
  2967. START_MENU();
  2968. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2969. MENU_ITEM(function, MSG_UNLOAD_ALL, extr_unload_all);
  2970. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_1, extr_unload_0);
  2971. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_2, extr_unload_1);
  2972. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_3, extr_unload_2);
  2973. MENU_ITEM(function, MSG_UNLOAD_FILAMENT_4, extr_unload_3);
  2974. END_MENU();
  2975. }
  2976. static void change_extr_menu(){
  2977. START_MENU();
  2978. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  2979. MENU_ITEM(function, MSG_EXTRUDER_1, extr_change_0);
  2980. MENU_ITEM(function, MSG_EXTRUDER_2, extr_change_1);
  2981. MENU_ITEM(function, MSG_EXTRUDER_3, extr_change_2);
  2982. MENU_ITEM(function, MSG_EXTRUDER_4, extr_change_3);
  2983. END_MENU();
  2984. }
  2985. #endif
  2986. static void lcd_farm_no()
  2987. {
  2988. char step = 0;
  2989. int enc_dif = 0;
  2990. int _farmno = farm_no;
  2991. int _ret = 0;
  2992. lcd_implementation_clear();
  2993. lcd.setCursor(0, 0);
  2994. lcd.print("Farm no");
  2995. do
  2996. {
  2997. if (abs((enc_dif - encoderDiff)) > 2) {
  2998. if (enc_dif > encoderDiff) {
  2999. switch (step) {
  3000. case(0): if (_farmno >= 100) _farmno -= 100; break;
  3001. case(1): if (_farmno % 100 >= 10) _farmno -= 10; break;
  3002. case(2): if (_farmno % 10 >= 1) _farmno--; break;
  3003. default: break;
  3004. }
  3005. }
  3006. if (enc_dif < encoderDiff) {
  3007. switch (step) {
  3008. case(0): if (_farmno < 900) _farmno += 100; break;
  3009. case(1): if (_farmno % 100 < 90) _farmno += 10; break;
  3010. case(2): if (_farmno % 10 <= 8)_farmno++; break;
  3011. default: break;
  3012. }
  3013. }
  3014. enc_dif = 0;
  3015. encoderDiff = 0;
  3016. }
  3017. lcd.setCursor(0, 2);
  3018. if (_farmno < 100) lcd.print("0");
  3019. if (_farmno < 10) lcd.print("0");
  3020. lcd.print(_farmno);
  3021. lcd.print(" ");
  3022. lcd.setCursor(0, 3);
  3023. lcd.print(" ");
  3024. lcd.setCursor(step, 3);
  3025. lcd.print("^");
  3026. delay(100);
  3027. if (lcd_clicked())
  3028. {
  3029. delay(200);
  3030. step++;
  3031. if(step == 3) {
  3032. _ret = 1;
  3033. farm_no = _farmno;
  3034. EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
  3035. prusa_statistics(20);
  3036. lcd_return_to_status();
  3037. }
  3038. }
  3039. manage_heater();
  3040. } while (_ret == 0);
  3041. }
  3042. unsigned char lcd_choose_color() {
  3043. //function returns index of currently chosen item
  3044. //following part can be modified from 2 to 255 items:
  3045. //-----------------------------------------------------
  3046. unsigned char items_no = 2;
  3047. const char *item[items_no];
  3048. item[0] = "Black";
  3049. item[1] = "Orange";
  3050. //-----------------------------------------------------
  3051. unsigned char active_rows;
  3052. static int first = 0;
  3053. int enc_dif = 0;
  3054. unsigned char cursor_pos = 1;
  3055. enc_dif = encoderDiff;
  3056. lcd_implementation_clear();
  3057. lcd.setCursor(0, 1);
  3058. lcd.print(">");
  3059. active_rows = items_no < 3 ? items_no : 3;
  3060. while (1) {
  3061. lcd_print_at_PGM(0, 0, PSTR("Choose color:"));
  3062. for (int i = 0; i < active_rows; i++) {
  3063. lcd.setCursor(1, i+1);
  3064. lcd.print(item[first + i]);
  3065. }
  3066. manage_heater();
  3067. manage_inactivity(true);
  3068. if (abs((enc_dif - encoderDiff)) > 4) {
  3069. if ((abs(enc_dif - encoderDiff)) > 1) {
  3070. if (enc_dif > encoderDiff) {
  3071. cursor_pos--;
  3072. }
  3073. if (enc_dif < encoderDiff) {
  3074. cursor_pos++;
  3075. }
  3076. if (cursor_pos > active_rows) {
  3077. cursor_pos = active_rows;
  3078. if (first < items_no - active_rows) {
  3079. first++;
  3080. lcd_implementation_clear();
  3081. }
  3082. }
  3083. if (cursor_pos < 1) {
  3084. cursor_pos = 1;
  3085. if (first > 0) {
  3086. first--;
  3087. lcd_implementation_clear();
  3088. }
  3089. }
  3090. lcd.setCursor(0, 1);
  3091. lcd.print(" ");
  3092. lcd.setCursor(0, 2);
  3093. lcd.print(" ");
  3094. lcd.setCursor(0, 3);
  3095. lcd.print(" ");
  3096. lcd.setCursor(0, cursor_pos);
  3097. lcd.print(">");
  3098. enc_dif = encoderDiff;
  3099. delay(100);
  3100. }
  3101. }
  3102. if (lcd_clicked()) {
  3103. while (lcd_clicked());
  3104. delay(10);
  3105. while (lcd_clicked());
  3106. return(cursor_pos + first - 1);
  3107. }
  3108. }
  3109. }
  3110. void lcd_confirm_print()
  3111. {
  3112. uint8_t filament_type;
  3113. int enc_dif = 0;
  3114. int cursor_pos = 1;
  3115. int _ret = 0;
  3116. int _t = 0;
  3117. lcd_implementation_clear();
  3118. lcd.setCursor(0, 0);
  3119. lcd.print("Print ok ?");
  3120. do
  3121. {
  3122. if (abs((enc_dif - encoderDiff)) > 2) {
  3123. if (enc_dif > encoderDiff) {
  3124. cursor_pos--;
  3125. }
  3126. if (enc_dif < encoderDiff) {
  3127. cursor_pos++;
  3128. }
  3129. }
  3130. if (cursor_pos > 2) { cursor_pos = 2; }
  3131. if (cursor_pos < 1) { cursor_pos = 1; }
  3132. lcd.setCursor(0, 2); lcd.print(" ");
  3133. lcd.setCursor(0, 3); lcd.print(" ");
  3134. lcd.setCursor(2, 2);
  3135. lcd_printPGM(MSG_YES);
  3136. lcd.setCursor(2, 3);
  3137. lcd_printPGM(MSG_NO);
  3138. lcd.setCursor(0, 1 + cursor_pos);
  3139. lcd.print(">");
  3140. delay(100);
  3141. _t = _t + 1;
  3142. if (_t>100)
  3143. {
  3144. prusa_statistics(99);
  3145. _t = 0;
  3146. }
  3147. if (lcd_clicked())
  3148. {
  3149. if (cursor_pos == 1)
  3150. {
  3151. _ret = 1;
  3152. filament_type = lcd_choose_color();
  3153. prusa_statistics(4, filament_type);
  3154. no_response = true; //we need confirmation by recieving PRUSA thx
  3155. important_status = 4;
  3156. saved_filament_type = filament_type;
  3157. NcTime = millis();
  3158. }
  3159. if (cursor_pos == 2)
  3160. {
  3161. _ret = 2;
  3162. filament_type = lcd_choose_color();
  3163. prusa_statistics(5, filament_type);
  3164. no_response = true; //we need confirmation by recieving PRUSA thx
  3165. important_status = 5;
  3166. saved_filament_type = filament_type;
  3167. NcTime = millis();
  3168. }
  3169. }
  3170. manage_heater();
  3171. manage_inactivity();
  3172. } while (_ret == 0);
  3173. }
  3174. static void lcd_main_menu()
  3175. {
  3176. SDscrool = 0;
  3177. START_MENU();
  3178. // Majkl superawesome menu
  3179. MENU_ITEM(back, MSG_WATCH, lcd_status_screen);
  3180. /* if (farm_mode && !IS_SD_PRINTING )
  3181. {
  3182. int tempScrool = 0;
  3183. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  3184. //delay(100);
  3185. return; // nothing to do (so don't thrash the SD card)
  3186. uint16_t fileCnt = card.getnrfilenames();
  3187. card.getWorkDirName();
  3188. if (card.filename[0] == '/')
  3189. {
  3190. #if SDCARDDETECT == -1
  3191. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  3192. #endif
  3193. } else {
  3194. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  3195. }
  3196. for (uint16_t i = 0; i < fileCnt; i++)
  3197. {
  3198. if (_menuItemNr == _lineNr)
  3199. {
  3200. #ifndef SDCARD_RATHERRECENTFIRST
  3201. card.getfilename(i);
  3202. #else
  3203. card.getfilename(fileCnt - 1 - i);
  3204. #endif
  3205. if (card.filenameIsDir)
  3206. {
  3207. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  3208. } else {
  3209. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  3210. }
  3211. } else {
  3212. MENU_ITEM_DUMMY();
  3213. }
  3214. }
  3215. MENU_ITEM(back, PSTR("- - - - - - - - -"), lcd_status_screen);
  3216. }*/
  3217. if ( ( IS_SD_PRINTING || is_usb_printing ) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag)
  3218. {
  3219. MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8
  3220. }
  3221. if ( moves_planned() || IS_SD_PRINTING || is_usb_printing )
  3222. {
  3223. MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
  3224. } else
  3225. {
  3226. MENU_ITEM(submenu, MSG_PREHEAT, lcd_preheat_menu);
  3227. }
  3228. #ifdef SDSUPPORT
  3229. if (card.cardOK)
  3230. {
  3231. if (card.isFileOpen())
  3232. {
  3233. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  3234. if (card.sdprinting)
  3235. {
  3236. MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
  3237. }
  3238. else
  3239. {
  3240. MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
  3241. }
  3242. MENU_ITEM(submenu, MSG_STOP_PRINT, lcd_sdcard_stop);
  3243. }
  3244. }
  3245. else
  3246. {
  3247. if (!is_usb_printing)
  3248. {
  3249. //if (farm_mode) MENU_ITEM(submenu, MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu);
  3250. /*else*/ MENU_ITEM(submenu, MSG_CARD_MENU, lcd_sdcard_menu);
  3251. }
  3252. #if SDCARDDETECT < 1
  3253. MENU_ITEM(gcode, MSG_CNG_SDCARD, PSTR("M21")); // SD-card changed by user
  3254. #endif
  3255. }
  3256. } else
  3257. {
  3258. MENU_ITEM(submenu, MSG_NO_CARD, lcd_sdcard_menu);
  3259. #if SDCARDDETECT < 1
  3260. MENU_ITEM(gcode, MSG_INIT_SDCARD, PSTR("M21")); // Manually initialize the SD-card via user interface
  3261. #endif
  3262. }
  3263. #endif
  3264. if (IS_SD_PRINTING || is_usb_printing)
  3265. {
  3266. if (farm_mode)
  3267. {
  3268. MENU_ITEM(submenu, PSTR("Farm number"), lcd_farm_no);
  3269. }
  3270. }
  3271. else
  3272. {
  3273. #ifndef SNMM
  3274. MENU_ITEM(function, MSG_LOAD_FILAMENT, lcd_LoadFilament);
  3275. MENU_ITEM(function, MSG_UNLOAD_FILAMENT, lcd_unLoadFilament);
  3276. #endif
  3277. #ifdef SNMM
  3278. MENU_ITEM(submenu, MSG_LOAD_FILAMENT, fil_load_menu);
  3279. MENU_ITEM(submenu, MSG_UNLOAD_FILAMENT, fil_unload_menu);
  3280. MENU_ITEM(submenu, MSG_CHANGE_EXTR, change_extr_menu);
  3281. #endif
  3282. MENU_ITEM(submenu, MSG_SETTINGS, lcd_settings_menu);
  3283. if(!isPrintPaused) MENU_ITEM(submenu, MSG_MENU_CALIBRATION, lcd_calibration_menu);
  3284. }
  3285. if (!is_usb_printing)
  3286. {
  3287. MENU_ITEM(submenu, MSG_STATISTICS, lcd_menu_statistics);
  3288. }
  3289. MENU_ITEM(submenu, MSG_SUPPORT, lcd_support_menu);
  3290. END_MENU();
  3291. }
  3292. void stack_error() {
  3293. SET_OUTPUT(BEEPER);
  3294. WRITE(BEEPER, HIGH);
  3295. delay(1000);
  3296. WRITE(BEEPER, LOW);
  3297. lcd_display_message_fullscreen_P(MSG_STACK_ERROR);
  3298. //err_triggered = 1;
  3299. while (1) delay_keep_alive(1000);
  3300. }
  3301. #ifdef SDSUPPORT
  3302. static void lcd_autostart_sd()
  3303. {
  3304. card.lastnr = 0;
  3305. card.setroot();
  3306. card.checkautostart(true);
  3307. }
  3308. #endif
  3309. static void lcd_silent_mode_set_tune() {
  3310. SilentModeMenu = !SilentModeMenu;
  3311. eeprom_update_byte((unsigned char*)EEPROM_SILENT, SilentModeMenu);
  3312. digipot_init();
  3313. lcd_goto_menu(lcd_tune_menu, 9);
  3314. }
  3315. static void lcd_colorprint_change() {
  3316. enquecommand_P(PSTR("M600"));
  3317. custom_message = true;
  3318. custom_message_type = 2; //just print status message
  3319. lcd_setstatuspgm(MSG_FINISHING_MOVEMENTS);
  3320. lcd_return_to_status();
  3321. lcdDrawUpdate = 3;
  3322. }
  3323. static void lcd_tune_menu()
  3324. {
  3325. EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu));
  3326. START_MENU();
  3327. MENU_ITEM(back, MSG_MAIN, lcd_main_menu); //1
  3328. MENU_ITEM_EDIT(int3, MSG_SPEED, &feedmultiply, 10, 999);//2
  3329. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);//3
  3330. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 10);//4
  3331. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);//5
  3332. MENU_ITEM_EDIT(int3, MSG_FLOW, &extrudemultiply, 10, 999);//6
  3333. #ifdef FILAMENTCHANGEENABLE
  3334. MENU_ITEM(function, MSG_FILAMENTCHANGE, lcd_colorprint_change);//7
  3335. #endif
  3336. if (SilentModeMenu == 0) {
  3337. MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set_tune);
  3338. } else {
  3339. MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set_tune);
  3340. }
  3341. END_MENU();
  3342. }
  3343. static void lcd_move_menu_01mm()
  3344. {
  3345. move_menu_scale = 0.1;
  3346. lcd_move_menu_axis();
  3347. }
  3348. static void lcd_control_temperature_menu()
  3349. {
  3350. #ifdef PIDTEMP
  3351. // set up temp variables - undo the default scaling
  3352. // raw_Ki = unscalePID_i(Ki);
  3353. // raw_Kd = unscalePID_d(Kd);
  3354. #endif
  3355. START_MENU();
  3356. MENU_ITEM(back, MSG_SETTINGS, lcd_settings_menu);
  3357. #if TEMP_SENSOR_0 != 0
  3358. MENU_ITEM_EDIT(int3, MSG_NOZZLE, &target_temperature[0], 0, HEATER_0_MAXTEMP - 10);
  3359. #endif
  3360. #if TEMP_SENSOR_1 != 0
  3361. MENU_ITEM_EDIT(int3, MSG_NOZZLE1, &target_temperature[1], 0, HEATER_1_MAXTEMP - 10);
  3362. #endif
  3363. #if TEMP_SENSOR_2 != 0
  3364. MENU_ITEM_EDIT(int3, MSG_NOZZLE2, &target_temperature[2], 0, HEATER_2_MAXTEMP - 10);
  3365. #endif
  3366. #if TEMP_SENSOR_BED != 0
  3367. MENU_ITEM_EDIT(int3, MSG_BED, &target_temperature_bed, 0, BED_MAXTEMP - 3);
  3368. #endif
  3369. MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &fanSpeed, 0, 255);
  3370. #if defined AUTOTEMP && (TEMP_SENSOR_0 != 0)
  3371. MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &autotemp_enabled);
  3372. MENU_ITEM_EDIT(float3, MSG_MIN, &autotemp_min, 0, HEATER_0_MAXTEMP - 10);
  3373. MENU_ITEM_EDIT(float3, MSG_MAX, &autotemp_max, 0, HEATER_0_MAXTEMP - 10);
  3374. MENU_ITEM_EDIT(float32, MSG_FACTOR, &autotemp_factor, 0.0, 1.0);
  3375. #endif
  3376. END_MENU();
  3377. }
  3378. #if SDCARDDETECT == -1
  3379. static void lcd_sd_refresh()
  3380. {
  3381. card.initsd();
  3382. currentMenuViewOffset = 0;
  3383. }
  3384. #endif
  3385. static void lcd_sd_updir()
  3386. {
  3387. SDscrool = 0;
  3388. card.updir();
  3389. currentMenuViewOffset = 0;
  3390. }
  3391. void lcd_sdcard_stop()
  3392. {
  3393. lcd.setCursor(0, 0);
  3394. lcd_printPGM(MSG_STOP_PRINT);
  3395. lcd.setCursor(2, 2);
  3396. lcd_printPGM(MSG_NO);
  3397. lcd.setCursor(2, 3);
  3398. lcd_printPGM(MSG_YES);
  3399. lcd.setCursor(0, 2); lcd.print(" ");
  3400. lcd.setCursor(0, 3); lcd.print(" ");
  3401. if ((int32_t)encoderPosition > 2) { encoderPosition = 2; }
  3402. if ((int32_t)encoderPosition < 1) { encoderPosition = 1; }
  3403. lcd.setCursor(0, 1 + encoderPosition);
  3404. lcd.print(">");
  3405. if (lcd_clicked())
  3406. {
  3407. if ((int32_t)encoderPosition == 1)
  3408. {
  3409. lcd_return_to_status();
  3410. }
  3411. if ((int32_t)encoderPosition == 2)
  3412. {
  3413. cancel_heatup = true;
  3414. #ifdef MESH_BED_LEVELING
  3415. mbl.active = false;
  3416. #endif
  3417. // Stop the stoppers, update the position from the stoppers.
  3418. if (mesh_bed_leveling_flag == false && homing_flag == false) {
  3419. planner_abort_hard();
  3420. // Because the planner_abort_hard() initialized current_position[Z] from the stepper,
  3421. // Z baystep is no more applied. Reset it.
  3422. babystep_reset();
  3423. }
  3424. // Clean the input command queue.
  3425. cmdqueue_reset();
  3426. lcd_setstatuspgm(MSG_PRINT_ABORTED);
  3427. lcd_update(2);
  3428. card.sdprinting = false;
  3429. card.closefile();
  3430. stoptime = millis();
  3431. unsigned long t = (stoptime - starttime - pause_time) / 1000; //time in s
  3432. pause_time = 0;
  3433. save_statistics(total_filament_used, t);
  3434. lcd_return_to_status();
  3435. lcd_ignore_click(true);
  3436. lcd_commands_type = LCD_COMMAND_STOP_PRINT;
  3437. if (farm_mode) prusa_statistics(7);
  3438. // Turn off the print fan
  3439. SET_OUTPUT(FAN_PIN);
  3440. WRITE(FAN_PIN, 0);
  3441. fanSpeed=0;
  3442. }
  3443. }
  3444. }
  3445. /*
  3446. void getFileDescription(char *name, char *description) {
  3447. // get file description, ie the REAL filenam, ie the second line
  3448. card.openFile(name, true);
  3449. int i = 0;
  3450. // skip the first line (which is the version line)
  3451. while (true) {
  3452. uint16_t readByte = card.get();
  3453. if (readByte == '\n') {
  3454. break;
  3455. }
  3456. }
  3457. // read the second line (which is the description line)
  3458. while (true) {
  3459. uint16_t readByte = card.get();
  3460. if (i == 0) {
  3461. // skip the first '^'
  3462. readByte = card.get();
  3463. }
  3464. description[i] = readByte;
  3465. i++;
  3466. if (readByte == '\n') {
  3467. break;
  3468. }
  3469. }
  3470. card.closefile();
  3471. description[i-1] = 0;
  3472. }
  3473. */
  3474. void lcd_sdcard_menu()
  3475. {
  3476. uint8_t sdSort;
  3477. int tempScrool = 0;
  3478. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  3479. //delay(100);
  3480. return; // nothing to do (so don't thrash the SD card)
  3481. uint16_t fileCnt = card.getnrfilenames();
  3482. START_MENU();
  3483. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3484. if (!farm_mode) {
  3485. #ifdef SDCARD_SORT_ALPHA
  3486. EEPROM_read(EEPROM_SD_SORT, (uint8_t*)&sdSort, sizeof(sdSort));
  3487. switch (sdSort) {
  3488. case SD_SORT_TIME: MENU_ITEM(function, MSG_SORT_TIME, lcd_sort_type_set); break;
  3489. case SD_SORT_ALPHA: MENU_ITEM(function, MSG_SORT_ALPHA, lcd_sort_type_set); break;
  3490. default: MENU_ITEM(function, MSG_SORT_NONE, lcd_sort_type_set);
  3491. }
  3492. #endif // SDCARD_SORT_ALPHA
  3493. }
  3494. card.getWorkDirName();
  3495. if (card.filename[0] == '/')
  3496. {
  3497. #if SDCARDDETECT == -1
  3498. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  3499. #endif
  3500. } else {
  3501. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  3502. }
  3503. for (uint16_t i = 0; i < fileCnt; i++)
  3504. {
  3505. if (_menuItemNr == _lineNr)
  3506. {
  3507. const uint16_t nr = ((sdSort == SD_SORT_NONE) || farm_mode) ? (fileCnt - 1 - i) : i;
  3508. /* #ifdef SDCARD_RATHERRECENTFIRST
  3509. #ifndef SDCARD_SORT_ALPHA
  3510. fileCnt - 1 -
  3511. #endif
  3512. #endif
  3513. i;*/
  3514. #ifdef SDCARD_SORT_ALPHA
  3515. if (sdSort == SD_SORT_NONE) card.getfilename(nr);
  3516. else card.getfilename_sorted(nr);
  3517. #else
  3518. card.getfilename(nr);
  3519. #endif
  3520. if (card.filenameIsDir)
  3521. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  3522. else
  3523. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
  3524. } else {
  3525. MENU_ITEM_DUMMY();
  3526. }
  3527. }
  3528. END_MENU();
  3529. }
  3530. //char description [10] [31];
  3531. /*void get_description() {
  3532. uint16_t fileCnt = card.getnrfilenames();
  3533. for (uint16_t i = 0; i < fileCnt; i++)
  3534. {
  3535. card.getfilename(fileCnt - 1 - i);
  3536. getFileDescription(card.filename, description[i]);
  3537. }
  3538. }*/
  3539. /*void lcd_farm_sdcard_menu()
  3540. {
  3541. static int i = 0;
  3542. if (i == 0) {
  3543. get_description();
  3544. i++;
  3545. }
  3546. //int j;
  3547. //char description[31];
  3548. int tempScrool = 0;
  3549. if (lcdDrawUpdate == 0 && LCD_CLICKED == 0)
  3550. //delay(100);
  3551. return; // nothing to do (so don't thrash the SD card)
  3552. uint16_t fileCnt = card.getnrfilenames();
  3553. START_MENU();
  3554. MENU_ITEM(back, MSG_MAIN, lcd_main_menu);
  3555. card.getWorkDirName();
  3556. if (card.filename[0] == '/')
  3557. {
  3558. #if SDCARDDETECT == -1
  3559. MENU_ITEM(function, MSG_REFRESH, lcd_sd_refresh);
  3560. #endif
  3561. }
  3562. else {
  3563. MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir);
  3564. }
  3565. for (uint16_t i = 0; i < fileCnt; i++)
  3566. {
  3567. if (_menuItemNr == _lineNr)
  3568. {
  3569. #ifndef SDCARD_RATHERRECENTFIRST
  3570. card.getfilename(i);
  3571. #else
  3572. card.getfilename(fileCnt - 1 - i);
  3573. #endif
  3574. if (card.filenameIsDir)
  3575. {
  3576. MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
  3577. }
  3578. else {
  3579. MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, description[i]);
  3580. }
  3581. }
  3582. else {
  3583. MENU_ITEM_DUMMY();
  3584. }
  3585. }
  3586. END_MENU();
  3587. }*/
  3588. #define menu_edit_type(_type, _name, _strFunc, scale) \
  3589. void menu_edit_ ## _name () \
  3590. { \
  3591. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  3592. if ((int32_t)encoderPosition > menuData.editMenuParentState.maxEditValue) encoderPosition = menuData.editMenuParentState.maxEditValue; \
  3593. if (lcdDrawUpdate) \
  3594. lcd_implementation_drawedit(menuData.editMenuParentState.editLabel, _strFunc(((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale)); \
  3595. if (LCD_CLICKED) \
  3596. { \
  3597. *((_type*)menuData.editMenuParentState.editValue) = ((_type)((int32_t)encoderPosition + menuData.editMenuParentState.minEditValue)) / scale; \
  3598. lcd_goto_menu(menuData.editMenuParentState.prevMenu, menuData.editMenuParentState.prevEncoderPosition, true, false); \
  3599. } \
  3600. } \
  3601. static void menu_action_setting_edit_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue) \
  3602. { \
  3603. menuData.editMenuParentState.prevMenu = currentMenu; \
  3604. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  3605. \
  3606. lcdDrawUpdate = 2; \
  3607. menuData.editMenuParentState.editLabel = pstr; \
  3608. menuData.editMenuParentState.editValue = ptr; \
  3609. menuData.editMenuParentState.minEditValue = minValue * scale; \
  3610. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  3611. lcd_goto_menu(menu_edit_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  3612. \
  3613. }\
  3614. /*
  3615. void menu_edit_callback_ ## _name () { \
  3616. menu_edit_ ## _name (); \
  3617. if (LCD_CLICKED) (*callbackFunc)(); \
  3618. } \
  3619. static void menu_action_setting_edit_callback_ ## _name (const char* pstr, _type* ptr, _type minValue, _type maxValue, menuFunc_t callback) \
  3620. { \
  3621. menuData.editMenuParentState.prevMenu = currentMenu; \
  3622. menuData.editMenuParentState.prevEncoderPosition = encoderPosition; \
  3623. \
  3624. lcdDrawUpdate = 2; \
  3625. lcd_goto_menu(menu_edit_callback_ ## _name, (*ptr) * scale - menuData.editMenuParentState.minEditValue, true, false); \
  3626. \
  3627. menuData.editMenuParentState.editLabel = pstr; \
  3628. menuData.editMenuParentState.editValue = ptr; \
  3629. menuData.editMenuParentState.minEditValue = minValue * scale; \
  3630. menuData.editMenuParentState.maxEditValue = maxValue * scale - menuData.editMenuParentState.minEditValue; \
  3631. callbackFunc = callback;\
  3632. }
  3633. */
  3634. menu_edit_type(int, int3, itostr3, 1)
  3635. menu_edit_type(float, float3, ftostr3, 1)
  3636. menu_edit_type(float, float32, ftostr32, 100)
  3637. menu_edit_type(float, float43, ftostr43, 1000)
  3638. menu_edit_type(float, float5, ftostr5, 0.01)
  3639. menu_edit_type(float, float51, ftostr51, 10)
  3640. menu_edit_type(float, float52, ftostr52, 100)
  3641. menu_edit_type(unsigned long, long5, ftostr5, 0.01)
  3642. static void lcd_selftest()
  3643. {
  3644. int _progress = 0;
  3645. bool _result = false;
  3646. lcd_implementation_clear();
  3647. lcd.setCursor(0, 0); lcd_printPGM(MSG_SELFTEST_START);
  3648. delay(2000);
  3649. _result = lcd_selftest_fan_dialog(1);
  3650. if (_result)
  3651. {
  3652. _result = lcd_selftest_fan_dialog(2);
  3653. }
  3654. if (_result)
  3655. {
  3656. _progress = lcd_selftest_screen(0, _progress, 3, true, 2000);
  3657. _result = lcd_selfcheck_endstops();
  3658. }
  3659. if (_result)
  3660. {
  3661. _progress = lcd_selftest_screen(1, _progress, 3, true, 1000);
  3662. _result = lcd_selfcheck_check_heater(false);
  3663. }
  3664. if (_result)
  3665. {
  3666. 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
  3667. _progress = lcd_selftest_screen(2, _progress, 3, true, 2000);
  3668. _result = lcd_selfcheck_axis(X_AXIS, X_MAX_POS);
  3669. }
  3670. if (_result)
  3671. {
  3672. _progress = lcd_selftest_screen(2, _progress, 3, true, 0);
  3673. _result = lcd_selfcheck_pulleys(X_AXIS);
  3674. }
  3675. if (_result)
  3676. {
  3677. _progress = lcd_selftest_screen(3, _progress, 3, true, 1500);
  3678. _result = lcd_selfcheck_axis(Y_AXIS, Y_MAX_POS);
  3679. }
  3680. if (_result)
  3681. {
  3682. _progress = lcd_selftest_screen(3, _progress, 3, true, 0);
  3683. _result = lcd_selfcheck_pulleys(Y_AXIS);
  3684. }
  3685. if (_result)
  3686. {
  3687. current_position[X_AXIS] = current_position[X_AXIS] - 3;
  3688. current_position[Y_AXIS] = current_position[Y_AXIS] - 14;
  3689. _progress = lcd_selftest_screen(4, _progress, 3, true, 1500);
  3690. _result = lcd_selfcheck_axis(2, Z_MAX_POS);
  3691. enquecommand_P(PSTR("G28 W"));
  3692. enquecommand_P(PSTR("G1 Z15"));
  3693. }
  3694. if (_result)
  3695. {
  3696. _progress = lcd_selftest_screen(5, _progress, 3, true, 2000);
  3697. _result = lcd_selfcheck_check_heater(true);
  3698. }
  3699. if (_result)
  3700. {
  3701. _progress = lcd_selftest_screen(6, _progress, 3, true, 5000);
  3702. }
  3703. else
  3704. {
  3705. _progress = lcd_selftest_screen(7, _progress, 3, true, 5000);
  3706. }
  3707. lcd_reset_alert_level();
  3708. enquecommand_P(PSTR("M84"));
  3709. lcd_implementation_clear();
  3710. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  3711. if (_result)
  3712. {
  3713. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_OK);
  3714. }
  3715. else
  3716. {
  3717. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  3718. }
  3719. }
  3720. static bool lcd_selfcheck_axis(int _axis, int _travel)
  3721. {
  3722. bool _stepdone = false;
  3723. bool _stepresult = false;
  3724. int _progress = 0;
  3725. int _travel_done = 0;
  3726. int _err_endstop = 0;
  3727. int _lcd_refresh = 0;
  3728. _travel = _travel + (_travel / 10);
  3729. do {
  3730. current_position[_axis] = current_position[_axis] - 1;
  3731. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3732. st_synchronize();
  3733. 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)
  3734. {
  3735. if (_axis == 0)
  3736. {
  3737. _stepresult = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  3738. _err_endstop = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? 1 : 2;
  3739. }
  3740. if (_axis == 1)
  3741. {
  3742. _stepresult = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  3743. _err_endstop = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? 0 : 2;
  3744. }
  3745. if (_axis == 2)
  3746. {
  3747. _stepresult = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? true : false;
  3748. _err_endstop = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? 0 : 1;
  3749. /*disable_x();
  3750. disable_y();
  3751. disable_z();*/
  3752. }
  3753. _stepdone = true;
  3754. }
  3755. if (_lcd_refresh < 6)
  3756. {
  3757. _lcd_refresh++;
  3758. }
  3759. else
  3760. {
  3761. _progress = lcd_selftest_screen(2 + _axis, _progress, 3, false, 0);
  3762. _lcd_refresh = 0;
  3763. }
  3764. manage_heater();
  3765. manage_inactivity(true);
  3766. //delay(100);
  3767. (_travel_done <= _travel) ? _travel_done++ : _stepdone = true;
  3768. } while (!_stepdone);
  3769. //current_position[_axis] = current_position[_axis] + 15;
  3770. //plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3771. if (!_stepresult)
  3772. {
  3773. const char *_error_1;
  3774. const char *_error_2;
  3775. if (_axis == X_AXIS) _error_1 = "X";
  3776. if (_axis == Y_AXIS) _error_1 = "Y";
  3777. if (_axis == Z_AXIS) _error_1 = "Z";
  3778. if (_err_endstop == 0) _error_2 = "X";
  3779. if (_err_endstop == 1) _error_2 = "Y";
  3780. if (_err_endstop == 2) _error_2 = "Z";
  3781. if (_travel_done >= _travel)
  3782. {
  3783. lcd_selftest_error(5, _error_1, _error_2);
  3784. }
  3785. else
  3786. {
  3787. lcd_selftest_error(4, _error_1, _error_2);
  3788. }
  3789. }
  3790. return _stepresult;
  3791. }
  3792. static bool lcd_selfcheck_pulleys(int axis)
  3793. {
  3794. float tmp_motor_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD;
  3795. float tmp_motor[3] = DEFAULT_PWM_MOTOR_CURRENT;
  3796. float current_position_init;
  3797. float move;
  3798. bool endstop_triggered = false;
  3799. bool result = true;
  3800. int i;
  3801. unsigned long timeout_counter;
  3802. refresh_cmd_timeout();
  3803. manage_inactivity(true);
  3804. if (axis == 0) move = 50; //X_AXIS
  3805. else move = 50; //Y_AXIS
  3806. current_position_init = current_position[axis];
  3807. current_position[axis] += 2;
  3808. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3809. for (i = 0; i < 5; i++) {
  3810. refresh_cmd_timeout();
  3811. current_position[axis] = current_position[axis] + move;
  3812. digipot_current(0, 850); //set motor current higher
  3813. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 200, active_extruder);
  3814. st_synchronize();
  3815. if (SilentModeMenu == 1) digipot_current(0, tmp_motor[0]); //set back to normal operation currents
  3816. else digipot_current(0, tmp_motor_loud[0]); //set motor current back
  3817. current_position[axis] = current_position[axis] - move;
  3818. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], 50, active_extruder);
  3819. st_synchronize();
  3820. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) || (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1)) {
  3821. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  3822. return(false);
  3823. }
  3824. }
  3825. timeout_counter = millis() + 2500;
  3826. endstop_triggered = false;
  3827. manage_inactivity(true);
  3828. while (!endstop_triggered) {
  3829. if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) || (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1)) {
  3830. endstop_triggered = true;
  3831. if (current_position_init - 1 <= current_position[axis] && current_position_init + 1 >= current_position[axis]) {
  3832. current_position[axis] += 15;
  3833. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3834. st_synchronize();
  3835. return(true);
  3836. }
  3837. else {
  3838. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  3839. return(false);
  3840. }
  3841. }
  3842. else {
  3843. current_position[axis] -= 1;
  3844. plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder);
  3845. st_synchronize();
  3846. if (millis() > timeout_counter) {
  3847. lcd_selftest_error(8, (axis == 0) ? "X" : "Y", "");
  3848. return(false);
  3849. }
  3850. }
  3851. }
  3852. }
  3853. static bool lcd_selfcheck_endstops()
  3854. {
  3855. bool _result = true;
  3856. 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)
  3857. {
  3858. current_position[0] = (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) ? current_position[0] = current_position[0] + 10 : current_position[0];
  3859. current_position[1] = (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) ? current_position[1] = current_position[1] + 10 : current_position[1];
  3860. current_position[2] = (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) ? current_position[2] = current_position[2] + 10 : current_position[2];
  3861. }
  3862. 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);
  3863. delay(500);
  3864. 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)
  3865. {
  3866. _result = false;
  3867. char _error[4] = "";
  3868. if (READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING == 1) strcat(_error, "X");
  3869. if (READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING == 1) strcat(_error, "Y");
  3870. if (READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING == 1) strcat(_error, "Z");
  3871. lcd_selftest_error(3, _error, "");
  3872. }
  3873. manage_heater();
  3874. manage_inactivity(true);
  3875. return _result;
  3876. }
  3877. static bool lcd_selfcheck_check_heater(bool _isbed)
  3878. {
  3879. int _counter = 0;
  3880. int _progress = 0;
  3881. bool _stepresult = false;
  3882. bool _docycle = true;
  3883. int _checked_snapshot = (_isbed) ? degBed() : degHotend(0);
  3884. int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed();
  3885. int _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s
  3886. target_temperature[0] = (_isbed) ? 0 : 200;
  3887. target_temperature_bed = (_isbed) ? 100 : 0;
  3888. manage_heater();
  3889. manage_inactivity(true);
  3890. do {
  3891. _counter++;
  3892. _docycle = (_counter < _cycles) ? true : false;
  3893. manage_heater();
  3894. manage_inactivity(true);
  3895. _progress = (_isbed) ? lcd_selftest_screen(5, _progress, 2, false, 400) : lcd_selftest_screen(1, _progress, 2, false, 400);
  3896. /*if (_isbed) {
  3897. MYSERIAL.print("Bed temp:");
  3898. MYSERIAL.println(degBed());
  3899. }
  3900. else {
  3901. MYSERIAL.print("Hotend temp:");
  3902. MYSERIAL.println(degHotend(0));
  3903. }*/
  3904. } while (_docycle);
  3905. target_temperature[0] = 0;
  3906. target_temperature_bed = 0;
  3907. manage_heater();
  3908. int _checked_result = (_isbed) ? degBed() - _checked_snapshot : degHotend(0) - _checked_snapshot;
  3909. int _opposite_result = (_isbed) ? degHotend(0) - _opposite_snapshot : degBed() - _opposite_snapshot;
  3910. /*
  3911. MYSERIAL.println("");
  3912. MYSERIAL.print("Checked result:");
  3913. MYSERIAL.println(_checked_result);
  3914. MYSERIAL.print("Opposite result:");
  3915. MYSERIAL.println(_opposite_result);
  3916. */
  3917. if (_opposite_result < ((_isbed) ? 10 : 3))
  3918. {
  3919. if (_checked_result >= ((_isbed) ? 3 : 10))
  3920. {
  3921. _stepresult = true;
  3922. }
  3923. else
  3924. {
  3925. lcd_selftest_error(1, "", "");
  3926. }
  3927. }
  3928. else
  3929. {
  3930. lcd_selftest_error(2, "", "");
  3931. }
  3932. manage_heater();
  3933. manage_inactivity(true);
  3934. return _stepresult;
  3935. }
  3936. static void lcd_selftest_error(int _error_no, const char *_error_1, const char *_error_2)
  3937. {
  3938. lcd_implementation_quick_feedback();
  3939. target_temperature[0] = 0;
  3940. target_temperature_bed = 0;
  3941. manage_heater();
  3942. manage_inactivity();
  3943. lcd_implementation_clear();
  3944. lcd.setCursor(0, 0);
  3945. lcd_printPGM(MSG_SELFTEST_ERROR);
  3946. lcd.setCursor(0, 1);
  3947. lcd_printPGM(MSG_SELFTEST_PLEASECHECK);
  3948. switch (_error_no)
  3949. {
  3950. case 1:
  3951. lcd.setCursor(0, 2);
  3952. lcd_printPGM(MSG_SELFTEST_HEATERTHERMISTOR);
  3953. lcd.setCursor(0, 3);
  3954. lcd_printPGM(MSG_SELFTEST_NOTCONNECTED);
  3955. break;
  3956. case 2:
  3957. lcd.setCursor(0, 2);
  3958. lcd_printPGM(MSG_SELFTEST_BEDHEATER);
  3959. lcd.setCursor(0, 3);
  3960. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  3961. break;
  3962. case 3:
  3963. lcd.setCursor(0, 2);
  3964. lcd_printPGM(MSG_SELFTEST_ENDSTOPS);
  3965. lcd.setCursor(0, 3);
  3966. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  3967. lcd.setCursor(17, 3);
  3968. lcd.print(_error_1);
  3969. break;
  3970. case 4:
  3971. lcd.setCursor(0, 2);
  3972. lcd_printPGM(MSG_SELFTEST_MOTOR);
  3973. lcd.setCursor(18, 2);
  3974. lcd.print(_error_1);
  3975. lcd.setCursor(0, 3);
  3976. lcd_printPGM(MSG_SELFTEST_ENDSTOP);
  3977. lcd.setCursor(18, 3);
  3978. lcd.print(_error_2);
  3979. break;
  3980. case 5:
  3981. lcd.setCursor(0, 2);
  3982. lcd_printPGM(MSG_SELFTEST_ENDSTOP_NOTHIT);
  3983. lcd.setCursor(0, 3);
  3984. lcd_printPGM(MSG_SELFTEST_MOTOR);
  3985. lcd.setCursor(18, 3);
  3986. lcd.print(_error_1);
  3987. break;
  3988. case 6:
  3989. lcd.setCursor(0, 2);
  3990. lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  3991. lcd.setCursor(0, 3);
  3992. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  3993. lcd.setCursor(18, 3);
  3994. lcd.print(_error_1);
  3995. break;
  3996. case 7:
  3997. lcd.setCursor(0, 2);
  3998. lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  3999. lcd.setCursor(0, 3);
  4000. lcd_printPGM(MSG_SELFTEST_WIRINGERROR);
  4001. lcd.setCursor(18, 3);
  4002. lcd.print(_error_1);
  4003. break;
  4004. case 8:
  4005. lcd.setCursor(0, 2);
  4006. lcd_printPGM(MSG_LOOSE_PULLEY);
  4007. lcd.setCursor(0, 3);
  4008. lcd_printPGM(MSG_SELFTEST_MOTOR);
  4009. lcd.setCursor(18, 3);
  4010. lcd.print(_error_1);
  4011. break;
  4012. }
  4013. delay(1000);
  4014. lcd_implementation_quick_feedback();
  4015. do {
  4016. delay(100);
  4017. manage_heater();
  4018. manage_inactivity();
  4019. } while (!lcd_clicked());
  4020. LCD_ALERTMESSAGERPGM(MSG_SELFTEST_FAILED);
  4021. lcd_return_to_status();
  4022. }
  4023. static bool lcd_selftest_fan_dialog(int _fan)
  4024. {
  4025. bool _result = false;
  4026. int _errno = 0;
  4027. lcd_implementation_clear();
  4028. lcd.setCursor(0, 0); lcd_printPGM(MSG_SELFTEST_FAN);
  4029. switch (_fan)
  4030. {
  4031. case 1:
  4032. // extruder cooling fan
  4033. lcd.setCursor(0, 1); lcd_printPGM(MSG_SELFTEST_EXTRUDER_FAN);
  4034. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  4035. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  4036. _errno = 7;
  4037. break;
  4038. case 2:
  4039. // object cooling fan
  4040. lcd.setCursor(0, 1); lcd_printPGM(MSG_SELFTEST_COOLING_FAN);
  4041. SET_OUTPUT(FAN_PIN);
  4042. analogWrite(FAN_PIN, 255);
  4043. _errno = 6;
  4044. break;
  4045. }
  4046. delay(500);
  4047. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  4048. lcd.setCursor(0, 3); lcd.print(">");
  4049. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  4050. int8_t enc_dif = 0;
  4051. KEEPALIVE_STATE(PAUSED_FOR_USER);
  4052. do
  4053. {
  4054. switch (_fan)
  4055. {
  4056. case 1:
  4057. // extruder cooling fan
  4058. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  4059. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1);
  4060. break;
  4061. case 2:
  4062. // object cooling fan
  4063. SET_OUTPUT(FAN_PIN);
  4064. analogWrite(FAN_PIN, 255);
  4065. break;
  4066. }
  4067. if (abs((enc_dif - encoderDiff)) > 2) {
  4068. if (enc_dif > encoderDiff) {
  4069. _result = true;
  4070. lcd.setCursor(0, 2); lcd.print(">");
  4071. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  4072. lcd.setCursor(0, 3); lcd.print(" ");
  4073. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  4074. }
  4075. if (enc_dif < encoderDiff) {
  4076. _result = false;
  4077. lcd.setCursor(0, 2); lcd.print(" ");
  4078. lcd.setCursor(1, 2); lcd_printPGM(MSG_SELFTEST_FAN_YES);
  4079. lcd.setCursor(0, 3); lcd.print(">");
  4080. lcd.setCursor(1, 3); lcd_printPGM(MSG_SELFTEST_FAN_NO);
  4081. }
  4082. enc_dif = 0;
  4083. encoderDiff = 0;
  4084. }
  4085. manage_heater();
  4086. delay(100);
  4087. } while (!lcd_clicked());
  4088. KEEPALIVE_STATE(IN_HANDLER);
  4089. SET_OUTPUT(EXTRUDER_0_AUTO_FAN_PIN);
  4090. WRITE(EXTRUDER_0_AUTO_FAN_PIN, 0);
  4091. SET_OUTPUT(FAN_PIN);
  4092. analogWrite(FAN_PIN, 0);
  4093. fanSpeed = 0;
  4094. manage_heater();
  4095. if (!_result)
  4096. {
  4097. const char *_err;
  4098. lcd_selftest_error(_errno, _err, _err);
  4099. }
  4100. return _result;
  4101. }
  4102. static int lcd_selftest_screen(int _step, int _progress, int _progress_scale, bool _clear, int _delay)
  4103. {
  4104. lcd_next_update_millis = millis() + (LCD_UPDATE_INTERVAL * 10000);
  4105. int _step_block = 0;
  4106. const char *_indicator = (_progress > _progress_scale) ? "-" : "|";
  4107. if (_clear) lcd_implementation_clear();
  4108. lcd.setCursor(0, 0);
  4109. if (_step == -1) lcd_printPGM(MSG_SELFTEST_START);
  4110. if (_step == 0) lcd_printPGM(MSG_SELFTEST_CHECK_ENDSTOPS);
  4111. if (_step == 1) lcd_printPGM(MSG_SELFTEST_CHECK_HOTEND);
  4112. if (_step == 2) lcd_printPGM(MSG_SELFTEST_CHECK_X);
  4113. if (_step == 3) lcd_printPGM(MSG_SELFTEST_CHECK_Y);
  4114. if (_step == 4) lcd_printPGM(MSG_SELFTEST_CHECK_Z);
  4115. if (_step == 5) lcd_printPGM(MSG_SELFTEST_CHECK_BED);
  4116. if (_step == 6) lcd_printPGM(MSG_SELFTEST_CHECK_ALLCORRECT);
  4117. if (_step == 7) lcd_printPGM(MSG_SELFTEST_FAILED);
  4118. lcd.setCursor(0, 1);
  4119. lcd.print("--------------------");
  4120. if (_step != 7)
  4121. {
  4122. _step_block = 1;
  4123. lcd_selftest_screen_step(3, 9, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Hotend", _indicator);
  4124. _step_block = 2;
  4125. lcd_selftest_screen_step(2, 2, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "X", _indicator);
  4126. _step_block = 3;
  4127. lcd_selftest_screen_step(2, 8, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Y", _indicator);
  4128. _step_block = 4;
  4129. lcd_selftest_screen_step(2, 14, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Z", _indicator);
  4130. _step_block = 5;
  4131. lcd_selftest_screen_step(3, 0, ((_step == _step_block) ? 1 : (_step < _step_block) ? 0 : 2), "Bed", _indicator);
  4132. }
  4133. if (_delay > 0) delay(_delay);
  4134. _progress++;
  4135. return (_progress > _progress_scale * 2) ? 0 : _progress;
  4136. }
  4137. static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator)
  4138. {
  4139. lcd.setCursor(_col, _row);
  4140. switch (_state)
  4141. {
  4142. case 1:
  4143. lcd.print(_name);
  4144. lcd.setCursor(_col + strlen(_name), _row);
  4145. lcd.print(":");
  4146. lcd.setCursor(_col + strlen(_name) + 1, _row);
  4147. lcd.print(_indicator);
  4148. break;
  4149. case 2:
  4150. lcd.print(_name);
  4151. lcd.setCursor(_col + strlen(_name), _row);
  4152. lcd.print(":");
  4153. lcd.setCursor(_col + strlen(_name) + 1, _row);
  4154. lcd.print("OK");
  4155. break;
  4156. default:
  4157. lcd.print(_name);
  4158. }
  4159. }
  4160. /** End of menus **/
  4161. static void lcd_quick_feedback()
  4162. {
  4163. lcdDrawUpdate = 2;
  4164. button_pressed = false;
  4165. lcd_implementation_quick_feedback();
  4166. }
  4167. /** Menu action functions **/
  4168. static void menu_action_back(menuFunc_t data) {
  4169. lcd_goto_menu(data);
  4170. }
  4171. static void menu_action_submenu(menuFunc_t data) {
  4172. lcd_goto_menu(data);
  4173. }
  4174. static void menu_action_gcode(const char* pgcode) {
  4175. enquecommand_P(pgcode);
  4176. }
  4177. static void menu_action_setlang(unsigned char lang) {
  4178. lcd_set_lang(lang);
  4179. }
  4180. static void menu_action_function(menuFunc_t data) {
  4181. (*data)();
  4182. }
  4183. static void menu_action_sdfile(const char* filename, char* longFilename)
  4184. {
  4185. loading_flag = false;
  4186. char cmd[30];
  4187. char* c;
  4188. sprintf_P(cmd, PSTR("M23 %s"), filename);
  4189. for (c = &cmd[4]; *c; c++)
  4190. *c = tolower(*c);
  4191. enquecommand(cmd);
  4192. enquecommand_P(PSTR("M24"));
  4193. lcd_return_to_status();
  4194. }
  4195. static void menu_action_sddirectory(const char* filename, char* longFilename)
  4196. {
  4197. card.chdir(filename);
  4198. encoderPosition = 0;
  4199. }
  4200. static void menu_action_setting_edit_bool(const char* pstr, bool* ptr)
  4201. {
  4202. *ptr = !(*ptr);
  4203. }
  4204. /*
  4205. static void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, menuFunc_t callback)
  4206. {
  4207. menu_action_setting_edit_bool(pstr, ptr);
  4208. (*callback)();
  4209. }
  4210. */
  4211. #endif//ULTIPANEL
  4212. /** LCD API **/
  4213. void lcd_init()
  4214. {
  4215. lcd_implementation_init();
  4216. #ifdef NEWPANEL
  4217. SET_INPUT(BTN_EN1);
  4218. SET_INPUT(BTN_EN2);
  4219. WRITE(BTN_EN1, HIGH);
  4220. WRITE(BTN_EN2, HIGH);
  4221. #if BTN_ENC > 0
  4222. SET_INPUT(BTN_ENC);
  4223. WRITE(BTN_ENC, HIGH);
  4224. #endif
  4225. #ifdef REPRAPWORLD_KEYPAD
  4226. pinMode(SHIFT_CLK, OUTPUT);
  4227. pinMode(SHIFT_LD, OUTPUT);
  4228. pinMode(SHIFT_OUT, INPUT);
  4229. WRITE(SHIFT_OUT, HIGH);
  4230. WRITE(SHIFT_LD, HIGH);
  4231. #endif
  4232. #else // Not NEWPANEL
  4233. #ifdef SR_LCD_2W_NL // Non latching 2 wire shift register
  4234. pinMode (SR_DATA_PIN, OUTPUT);
  4235. pinMode (SR_CLK_PIN, OUTPUT);
  4236. #elif defined(SHIFT_CLK)
  4237. pinMode(SHIFT_CLK, OUTPUT);
  4238. pinMode(SHIFT_LD, OUTPUT);
  4239. pinMode(SHIFT_EN, OUTPUT);
  4240. pinMode(SHIFT_OUT, INPUT);
  4241. WRITE(SHIFT_OUT, HIGH);
  4242. WRITE(SHIFT_LD, HIGH);
  4243. WRITE(SHIFT_EN, LOW);
  4244. #else
  4245. #ifdef ULTIPANEL
  4246. #error ULTIPANEL requires an encoder
  4247. #endif
  4248. #endif // SR_LCD_2W_NL
  4249. #endif//!NEWPANEL
  4250. #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0)
  4251. pinMode(SDCARDDETECT, INPUT);
  4252. WRITE(SDCARDDETECT, HIGH);
  4253. lcd_oldcardstatus = IS_SD_INSERTED;
  4254. #endif//(SDCARDDETECT > 0)
  4255. #ifdef LCD_HAS_SLOW_BUTTONS
  4256. slow_buttons = 0;
  4257. #endif
  4258. lcd_buttons_update();
  4259. #ifdef ULTIPANEL
  4260. encoderDiff = 0;
  4261. #endif
  4262. }
  4263. //#include <avr/pgmspace.h>
  4264. static volatile bool lcd_update_enabled = true;
  4265. unsigned long lcd_timeoutToStatus = 0;
  4266. void lcd_update_enable(bool enabled)
  4267. {
  4268. if (lcd_update_enabled != enabled) {
  4269. lcd_update_enabled = enabled;
  4270. if (enabled) {
  4271. // Reset encoder position. This is equivalent to re-entering a menu.
  4272. encoderPosition = 0;
  4273. encoderDiff = 0;
  4274. // Enabling the normal LCD update procedure.
  4275. // Reset the timeout interval.
  4276. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  4277. // Force the keypad update now.
  4278. lcd_next_update_millis = millis() - 1;
  4279. // Full update.
  4280. lcd_implementation_clear();
  4281. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  4282. lcd_set_custom_characters(currentMenu == lcd_status_screen);
  4283. #else
  4284. if (currentMenu == lcd_status_screen)
  4285. lcd_set_custom_characters_degree();
  4286. else
  4287. lcd_set_custom_characters_arrows();
  4288. #endif
  4289. lcd_update(2);
  4290. } else {
  4291. // Clear the LCD always, or let it to the caller?
  4292. }
  4293. }
  4294. }
  4295. void lcd_update(uint8_t lcdDrawUpdateOverride)
  4296. {
  4297. if (lcdDrawUpdate < lcdDrawUpdateOverride)
  4298. lcdDrawUpdate = lcdDrawUpdateOverride;
  4299. if (!lcd_update_enabled)
  4300. return;
  4301. #ifdef LCD_HAS_SLOW_BUTTONS
  4302. slow_buttons = lcd_implementation_read_slow_buttons(); // buttons which take too long to read in interrupt context
  4303. #endif
  4304. lcd_buttons_update();
  4305. #if (SDCARDDETECT > 0)
  4306. if ((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected()))
  4307. {
  4308. lcdDrawUpdate = 2;
  4309. lcd_oldcardstatus = IS_SD_INSERTED;
  4310. lcd_implementation_init( // to maybe revive the LCD if static electricity killed it.
  4311. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  4312. currentMenu == lcd_status_screen
  4313. #endif
  4314. );
  4315. if (lcd_oldcardstatus)
  4316. {
  4317. card.initsd();
  4318. LCD_MESSAGERPGM(MSG_SD_INSERTED);
  4319. //get_description();
  4320. }
  4321. else
  4322. {
  4323. card.release();
  4324. LCD_MESSAGERPGM(MSG_SD_REMOVED);
  4325. }
  4326. }
  4327. #endif//CARDINSERTED
  4328. if (lcd_next_update_millis < millis())
  4329. {
  4330. #ifdef ULTIPANEL
  4331. #ifdef REPRAPWORLD_KEYPAD
  4332. if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) {
  4333. reprapworld_keypad_move_z_up();
  4334. }
  4335. if (REPRAPWORLD_KEYPAD_MOVE_Z_DOWN) {
  4336. reprapworld_keypad_move_z_down();
  4337. }
  4338. if (REPRAPWORLD_KEYPAD_MOVE_X_LEFT) {
  4339. reprapworld_keypad_move_x_left();
  4340. }
  4341. if (REPRAPWORLD_KEYPAD_MOVE_X_RIGHT) {
  4342. reprapworld_keypad_move_x_right();
  4343. }
  4344. if (REPRAPWORLD_KEYPAD_MOVE_Y_DOWN) {
  4345. reprapworld_keypad_move_y_down();
  4346. }
  4347. if (REPRAPWORLD_KEYPAD_MOVE_Y_UP) {
  4348. reprapworld_keypad_move_y_up();
  4349. }
  4350. if (REPRAPWORLD_KEYPAD_MOVE_HOME) {
  4351. reprapworld_keypad_move_home();
  4352. }
  4353. #endif
  4354. if (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP)
  4355. {
  4356. if (lcdDrawUpdate == 0)
  4357. lcdDrawUpdate = 1;
  4358. encoderPosition += encoderDiff / ENCODER_PULSES_PER_STEP;
  4359. encoderDiff = 0;
  4360. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  4361. }
  4362. if (LCD_CLICKED) lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  4363. #endif//ULTIPANEL
  4364. #ifdef DOGLCD // Changes due to different driver architecture of the DOGM display
  4365. blink++; // Variable for fan animation and alive dot
  4366. u8g.firstPage();
  4367. do
  4368. {
  4369. u8g.setFont(u8g_font_6x10_marlin);
  4370. u8g.setPrintPos(125, 0);
  4371. if (blink % 2) u8g.setColorIndex(1); else u8g.setColorIndex(0); // Set color for the alive dot
  4372. u8g.drawPixel(127, 63); // draw alive dot
  4373. u8g.setColorIndex(1); // black on white
  4374. (*currentMenu)();
  4375. if (!lcdDrawUpdate) break; // Terminate display update, when nothing new to draw. This must be done before the last dogm.next()
  4376. } while (u8g.nextPage());
  4377. #else
  4378. (*currentMenu)();
  4379. #endif
  4380. #ifdef LCD_HAS_STATUS_INDICATORS
  4381. lcd_implementation_update_indicators();
  4382. #endif
  4383. #ifdef ULTIPANEL
  4384. if (lcd_timeoutToStatus < millis() && currentMenu != lcd_status_screen)
  4385. {
  4386. // Exiting a menu. Let's call the menu function the last time with menuExiting flag set to true
  4387. // to give it a chance to save its state.
  4388. // This is useful for example, when the babystep value has to be written into EEPROM.
  4389. if (currentMenu != NULL) {
  4390. menuExiting = true;
  4391. (*currentMenu)();
  4392. menuExiting = false;
  4393. }
  4394. lcd_return_to_status();
  4395. lcdDrawUpdate = 2;
  4396. }
  4397. #endif//ULTIPANEL
  4398. if (lcdDrawUpdate == 2) lcd_implementation_clear();
  4399. if (lcdDrawUpdate) lcdDrawUpdate--;
  4400. lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
  4401. }
  4402. if (!SdFatUtil::test_stack_integrity()) stack_error();
  4403. lcd_ping(); //check that we have received ping command if we are in farm mode
  4404. lcd_send_status();
  4405. }
  4406. void lcd_printer_connected() {
  4407. printer_connected = true;
  4408. }
  4409. static void lcd_send_status() {
  4410. if (farm_mode && no_response && ((millis() - NcTime) > (NC_TIME * 1000))) {
  4411. //send important status messages periodicaly
  4412. prusa_statistics(important_status, saved_filament_type);
  4413. NcTime = millis();
  4414. lcd_connect_printer();
  4415. }
  4416. };
  4417. static void lcd_connect_printer() {
  4418. lcd_update_enable(false);
  4419. lcd_implementation_clear();
  4420. bool pressed = false;
  4421. int i = 0;
  4422. int t = 0;
  4423. lcd_set_custom_characters_progress();
  4424. lcd_implementation_print_at(0, 0, "Connect printer to");
  4425. lcd_implementation_print_at(0, 1, "monitoring or hold");
  4426. lcd_implementation_print_at(0, 2, "the knob to continue");
  4427. while (no_response) {
  4428. i++;
  4429. t++;
  4430. delay_keep_alive(100);
  4431. proc_commands();
  4432. if (t == 10) {
  4433. prusa_statistics(important_status, saved_filament_type);
  4434. t = 0;
  4435. }
  4436. if (READ(BTN_ENC)) { //if button is not pressed
  4437. i = 0;
  4438. lcd_implementation_print_at(0, 3, " ");
  4439. }
  4440. if (i!=0) lcd_implementation_print_at((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, "\x01");
  4441. if (i == NC_BUTTON_LONG_PRESS * 10) {
  4442. no_response = false;
  4443. }
  4444. }
  4445. lcd_set_custom_characters_degree();
  4446. lcd_update_enable(true);
  4447. lcd_update(2);
  4448. }
  4449. void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
  4450. if (farm_mode) {
  4451. bool empty = is_buffer_empty();
  4452. if ((millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
  4453. //if there are comamnds in buffer, some long gcodes can delay execution of ping command
  4454. //therefore longer period is used
  4455. printer_connected = false;
  4456. //lcd_ping_allert(); //acustic signals
  4457. }
  4458. else {
  4459. lcd_printer_connected();
  4460. }
  4461. }
  4462. }
  4463. void lcd_ignore_click(bool b)
  4464. {
  4465. ignore_click = b;
  4466. wait_for_unclick = false;
  4467. }
  4468. void lcd_finishstatus() {
  4469. int len = strlen(lcd_status_message);
  4470. if (len > 0) {
  4471. while (len < LCD_WIDTH) {
  4472. lcd_status_message[len++] = ' ';
  4473. }
  4474. }
  4475. lcd_status_message[LCD_WIDTH] = '\0';
  4476. #if defined(LCD_PROGRESS_BAR) && defined(SDSUPPORT)
  4477. #if PROGRESS_MSG_EXPIRE > 0
  4478. messageTick =
  4479. #endif
  4480. progressBarTick = millis();
  4481. #endif
  4482. lcdDrawUpdate = 2;
  4483. #ifdef FILAMENT_LCD_DISPLAY
  4484. message_millis = millis(); //get status message to show up for a while
  4485. #endif
  4486. }
  4487. void lcd_setstatus(const char* message)
  4488. {
  4489. if (lcd_status_message_level > 0)
  4490. return;
  4491. strncpy(lcd_status_message, message, LCD_WIDTH);
  4492. lcd_finishstatus();
  4493. }
  4494. void lcd_setstatuspgm(const char* message)
  4495. {
  4496. if (lcd_status_message_level > 0)
  4497. return;
  4498. strncpy_P(lcd_status_message, message, LCD_WIDTH);
  4499. lcd_finishstatus();
  4500. }
  4501. void lcd_setalertstatuspgm(const char* message)
  4502. {
  4503. lcd_setstatuspgm(message);
  4504. lcd_status_message_level = 1;
  4505. #ifdef ULTIPANEL
  4506. lcd_return_to_status();
  4507. #endif//ULTIPANEL
  4508. }
  4509. void lcd_reset_alert_level()
  4510. {
  4511. lcd_status_message_level = 0;
  4512. }
  4513. #ifdef DOGLCD
  4514. void lcd_setcontrast(uint8_t value)
  4515. {
  4516. lcd_contrast = value & 63;
  4517. u8g.setContrast(lcd_contrast);
  4518. }
  4519. #endif
  4520. #ifdef ULTIPANEL
  4521. /* Warning: This function is called from interrupt context */
  4522. void lcd_buttons_update()
  4523. {
  4524. #ifdef NEWPANEL
  4525. uint8_t newbutton = 0;
  4526. if (READ(BTN_EN1) == 0) newbutton |= EN_A;
  4527. if (READ(BTN_EN2) == 0) newbutton |= EN_B;
  4528. #if BTN_ENC > 0
  4529. if (lcd_update_enabled == true) { //if we are in non-modal mode, long press can be used and short press triggers with button release
  4530. if (READ(BTN_ENC) == 0) { //button is pressed
  4531. lcd_timeoutToStatus = millis() + LCD_TIMEOUT_TO_STATUS;
  4532. if (millis() > button_blanking_time) {
  4533. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  4534. if (button_pressed == false && long_press_active == false) {
  4535. if (currentMenu != lcd_move_z) {
  4536. savedMenu = currentMenu;
  4537. savedEncoderPosition = encoderPosition;
  4538. }
  4539. long_press_timer = millis();
  4540. button_pressed = true;
  4541. }
  4542. else {
  4543. if (millis() - long_press_timer > LONG_PRESS_TIME) { //long press activated
  4544. long_press_active = true;
  4545. move_menu_scale = 1.0;
  4546. lcd_goto_menu(lcd_move_z);
  4547. }
  4548. }
  4549. }
  4550. }
  4551. else { //button not pressed
  4552. if (button_pressed) { //button was released
  4553. button_blanking_time = millis() + BUTTON_BLANKING_TIME;
  4554. if (long_press_active == false) { //button released before long press gets activated
  4555. if (currentMenu == lcd_move_z) {
  4556. //return to previously active menu and previous encoder position
  4557. lcd_goto_menu(savedMenu, savedEncoderPosition);
  4558. }
  4559. else {
  4560. newbutton |= EN_C;
  4561. }
  4562. }
  4563. else if (currentMenu == lcd_move_z) lcd_quick_feedback();
  4564. //button_pressed is set back to false via lcd_quick_feedback function
  4565. }
  4566. else {
  4567. long_press_active = false;
  4568. }
  4569. }
  4570. }
  4571. else { //we are in modal mode
  4572. if (READ(BTN_ENC) == 0)
  4573. newbutton |= EN_C;
  4574. }
  4575. #endif
  4576. buttons = newbutton;
  4577. #ifdef LCD_HAS_SLOW_BUTTONS
  4578. buttons |= slow_buttons;
  4579. #endif
  4580. #ifdef REPRAPWORLD_KEYPAD
  4581. // for the reprapworld_keypad
  4582. uint8_t newbutton_reprapworld_keypad = 0;
  4583. WRITE(SHIFT_LD, LOW);
  4584. WRITE(SHIFT_LD, HIGH);
  4585. for (int8_t i = 0; i < 8; i++) {
  4586. newbutton_reprapworld_keypad = newbutton_reprapworld_keypad >> 1;
  4587. if (READ(SHIFT_OUT))
  4588. newbutton_reprapworld_keypad |= (1 << 7);
  4589. WRITE(SHIFT_CLK, HIGH);
  4590. WRITE(SHIFT_CLK, LOW);
  4591. }
  4592. buttons_reprapworld_keypad = ~newbutton_reprapworld_keypad; //invert it, because a pressed switch produces a logical 0
  4593. #endif
  4594. #else //read it from the shift register
  4595. uint8_t newbutton = 0;
  4596. WRITE(SHIFT_LD, LOW);
  4597. WRITE(SHIFT_LD, HIGH);
  4598. unsigned char tmp_buttons = 0;
  4599. for (int8_t i = 0; i < 8; i++)
  4600. {
  4601. newbutton = newbutton >> 1;
  4602. if (READ(SHIFT_OUT))
  4603. newbutton |= (1 << 7);
  4604. WRITE(SHIFT_CLK, HIGH);
  4605. WRITE(SHIFT_CLK, LOW);
  4606. }
  4607. buttons = ~newbutton; //invert it, because a pressed switch produces a logical 0
  4608. #endif//!NEWPANEL
  4609. //manage encoder rotation
  4610. uint8_t enc = 0;
  4611. if (buttons & EN_A) enc |= B01;
  4612. if (buttons & EN_B) enc |= B10;
  4613. if (enc != lastEncoderBits)
  4614. {
  4615. switch (enc)
  4616. {
  4617. case encrot0:
  4618. if (lastEncoderBits == encrot3)
  4619. encoderDiff++;
  4620. else if (lastEncoderBits == encrot1)
  4621. encoderDiff--;
  4622. break;
  4623. case encrot1:
  4624. if (lastEncoderBits == encrot0)
  4625. encoderDiff++;
  4626. else if (lastEncoderBits == encrot2)
  4627. encoderDiff--;
  4628. break;
  4629. case encrot2:
  4630. if (lastEncoderBits == encrot1)
  4631. encoderDiff++;
  4632. else if (lastEncoderBits == encrot3)
  4633. encoderDiff--;
  4634. break;
  4635. case encrot3:
  4636. if (lastEncoderBits == encrot2)
  4637. encoderDiff++;
  4638. else if (lastEncoderBits == encrot0)
  4639. encoderDiff--;
  4640. break;
  4641. }
  4642. }
  4643. lastEncoderBits = enc;
  4644. }
  4645. bool lcd_detected(void)
  4646. {
  4647. #if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE)
  4648. return lcd.LcdDetected() == 1;
  4649. #else
  4650. return true;
  4651. #endif
  4652. }
  4653. void lcd_buzz(long duration, uint16_t freq)
  4654. {
  4655. #ifdef LCD_USE_I2C_BUZZER
  4656. lcd.buzz(duration, freq);
  4657. #endif
  4658. }
  4659. bool lcd_clicked()
  4660. {
  4661. bool clicked = LCD_CLICKED;
  4662. if(clicked) button_pressed = false;
  4663. return clicked;
  4664. }
  4665. #endif//ULTIPANEL
  4666. /********************************/
  4667. /** Float conversion utilities **/
  4668. /********************************/
  4669. // convert float to string with +123.4 format
  4670. char conv[8];
  4671. char *ftostr3(const float &x)
  4672. {
  4673. return itostr3((int)x);
  4674. }
  4675. char *itostr2(const uint8_t &x)
  4676. {
  4677. //sprintf(conv,"%5.1f",x);
  4678. int xx = x;
  4679. conv[0] = (xx / 10) % 10 + '0';
  4680. conv[1] = (xx) % 10 + '0';
  4681. conv[2] = 0;
  4682. return conv;
  4683. }
  4684. // Convert float to string with 123.4 format, dropping sign
  4685. char *ftostr31(const float &x)
  4686. {
  4687. int xx = x * 10;
  4688. conv[0] = (xx >= 0) ? '+' : '-';
  4689. xx = abs(xx);
  4690. conv[1] = (xx / 1000) % 10 + '0';
  4691. conv[2] = (xx / 100) % 10 + '0';
  4692. conv[3] = (xx / 10) % 10 + '0';
  4693. conv[4] = '.';
  4694. conv[5] = (xx) % 10 + '0';
  4695. conv[6] = 0;
  4696. return conv;
  4697. }
  4698. // Convert float to string with 123.4 format
  4699. char *ftostr31ns(const float &x)
  4700. {
  4701. int xx = x * 10;
  4702. //conv[0]=(xx>=0)?'+':'-';
  4703. xx = abs(xx);
  4704. conv[0] = (xx / 1000) % 10 + '0';
  4705. conv[1] = (xx / 100) % 10 + '0';
  4706. conv[2] = (xx / 10) % 10 + '0';
  4707. conv[3] = '.';
  4708. conv[4] = (xx) % 10 + '0';
  4709. conv[5] = 0;
  4710. return conv;
  4711. }
  4712. char *ftostr32(const float &x)
  4713. {
  4714. long xx = x * 100;
  4715. if (xx >= 0)
  4716. conv[0] = (xx / 10000) % 10 + '0';
  4717. else
  4718. conv[0] = '-';
  4719. xx = abs(xx);
  4720. conv[1] = (xx / 1000) % 10 + '0';
  4721. conv[2] = (xx / 100) % 10 + '0';
  4722. conv[3] = '.';
  4723. conv[4] = (xx / 10) % 10 + '0';
  4724. conv[5] = (xx) % 10 + '0';
  4725. conv[6] = 0;
  4726. return conv;
  4727. }
  4728. //// Convert float to rj string with 123.45 format
  4729. char *ftostr32ns(const float &x) {
  4730. long xx = abs(x);
  4731. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  4732. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  4733. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : '0';
  4734. conv[3] = '.';
  4735. conv[4] = (xx / 10) % 10 + '0';
  4736. conv[5] = xx % 10 + '0';
  4737. return conv;
  4738. }
  4739. // Convert float to string with 1.234 format
  4740. char *ftostr43(const float &x)
  4741. {
  4742. long xx = x * 1000;
  4743. if (xx >= 0)
  4744. conv[0] = (xx / 1000) % 10 + '0';
  4745. else
  4746. conv[0] = '-';
  4747. xx = abs(xx);
  4748. conv[1] = '.';
  4749. conv[2] = (xx / 100) % 10 + '0';
  4750. conv[3] = (xx / 10) % 10 + '0';
  4751. conv[4] = (xx) % 10 + '0';
  4752. conv[5] = 0;
  4753. return conv;
  4754. }
  4755. //Float to string with 1.23 format
  4756. char *ftostr12ns(const float &x)
  4757. {
  4758. long xx = x * 100;
  4759. xx = abs(xx);
  4760. conv[0] = (xx / 100) % 10 + '0';
  4761. conv[1] = '.';
  4762. conv[2] = (xx / 10) % 10 + '0';
  4763. conv[3] = (xx) % 10 + '0';
  4764. conv[4] = 0;
  4765. return conv;
  4766. }
  4767. //Float to string with 1.234 format
  4768. char *ftostr13ns(const float &x)
  4769. {
  4770. long xx = x * 1000;
  4771. if (xx >= 0)
  4772. conv[0] = ' ';
  4773. else
  4774. conv[0] = '-';
  4775. xx = abs(xx);
  4776. conv[1] = (xx / 1000) % 10 + '0';
  4777. conv[2] = '.';
  4778. conv[3] = (xx / 100) % 10 + '0';
  4779. conv[4] = (xx / 10) % 10 + '0';
  4780. conv[5] = (xx) % 10 + '0';
  4781. conv[6] = 0;
  4782. return conv;
  4783. }
  4784. // convert float to space-padded string with -_23.4_ format
  4785. char *ftostr32sp(const float &x) {
  4786. long xx = abs(x * 100);
  4787. uint8_t dig;
  4788. if (x < 0) { // negative val = -_0
  4789. conv[0] = '-';
  4790. dig = (xx / 1000) % 10;
  4791. conv[1] = dig ? '0' + dig : ' ';
  4792. }
  4793. else { // positive val = __0
  4794. dig = (xx / 10000) % 10;
  4795. if (dig) {
  4796. conv[0] = '0' + dig;
  4797. conv[1] = '0' + (xx / 1000) % 10;
  4798. }
  4799. else {
  4800. conv[0] = ' ';
  4801. dig = (xx / 1000) % 10;
  4802. conv[1] = dig ? '0' + dig : ' ';
  4803. }
  4804. }
  4805. conv[2] = '0' + (xx / 100) % 10; // lsd always
  4806. dig = xx % 10;
  4807. if (dig) { // 2 decimal places
  4808. conv[5] = '0' + dig;
  4809. conv[4] = '0' + (xx / 10) % 10;
  4810. conv[3] = '.';
  4811. }
  4812. else { // 1 or 0 decimal place
  4813. dig = (xx / 10) % 10;
  4814. if (dig) {
  4815. conv[4] = '0' + dig;
  4816. conv[3] = '.';
  4817. }
  4818. else {
  4819. conv[3] = conv[4] = ' ';
  4820. }
  4821. conv[5] = ' ';
  4822. }
  4823. conv[6] = '\0';
  4824. return conv;
  4825. }
  4826. char *itostr31(const int &xx)
  4827. {
  4828. conv[0] = (xx >= 0) ? '+' : '-';
  4829. conv[1] = (xx / 1000) % 10 + '0';
  4830. conv[2] = (xx / 100) % 10 + '0';
  4831. conv[3] = (xx / 10) % 10 + '0';
  4832. conv[4] = '.';
  4833. conv[5] = (xx) % 10 + '0';
  4834. conv[6] = 0;
  4835. return conv;
  4836. }
  4837. // Convert int to rj string with 123 or -12 format
  4838. char *itostr3(const int &x)
  4839. {
  4840. int xx = x;
  4841. if (xx < 0) {
  4842. conv[0] = '-';
  4843. xx = -xx;
  4844. } else if (xx >= 100)
  4845. conv[0] = (xx / 100) % 10 + '0';
  4846. else
  4847. conv[0] = ' ';
  4848. if (xx >= 10)
  4849. conv[1] = (xx / 10) % 10 + '0';
  4850. else
  4851. conv[1] = ' ';
  4852. conv[2] = (xx) % 10 + '0';
  4853. conv[3] = 0;
  4854. return conv;
  4855. }
  4856. // Convert int to lj string with 123 format
  4857. char *itostr3left(const int &xx)
  4858. {
  4859. if (xx >= 100)
  4860. {
  4861. conv[0] = (xx / 100) % 10 + '0';
  4862. conv[1] = (xx / 10) % 10 + '0';
  4863. conv[2] = (xx) % 10 + '0';
  4864. conv[3] = 0;
  4865. }
  4866. else if (xx >= 10)
  4867. {
  4868. conv[0] = (xx / 10) % 10 + '0';
  4869. conv[1] = (xx) % 10 + '0';
  4870. conv[2] = 0;
  4871. }
  4872. else
  4873. {
  4874. conv[0] = (xx) % 10 + '0';
  4875. conv[1] = 0;
  4876. }
  4877. return conv;
  4878. }
  4879. // Convert int to rj string with 1234 format
  4880. char *itostr4(const int &xx) {
  4881. conv[0] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  4882. conv[1] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  4883. conv[2] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  4884. conv[3] = xx % 10 + '0';
  4885. conv[4] = 0;
  4886. return conv;
  4887. }
  4888. // Convert float to rj string with 12345 format
  4889. char *ftostr5(const float &x) {
  4890. long xx = abs(x);
  4891. conv[0] = xx >= 10000 ? (xx / 10000) % 10 + '0' : ' ';
  4892. conv[1] = xx >= 1000 ? (xx / 1000) % 10 + '0' : ' ';
  4893. conv[2] = xx >= 100 ? (xx / 100) % 10 + '0' : ' ';
  4894. conv[3] = xx >= 10 ? (xx / 10) % 10 + '0' : ' ';
  4895. conv[4] = xx % 10 + '0';
  4896. conv[5] = 0;
  4897. return conv;
  4898. }
  4899. // Convert float to string with +1234.5 format
  4900. char *ftostr51(const float &x)
  4901. {
  4902. long xx = x * 10;
  4903. conv[0] = (xx >= 0) ? '+' : '-';
  4904. xx = abs(xx);
  4905. conv[1] = (xx / 10000) % 10 + '0';
  4906. conv[2] = (xx / 1000) % 10 + '0';
  4907. conv[3] = (xx / 100) % 10 + '0';
  4908. conv[4] = (xx / 10) % 10 + '0';
  4909. conv[5] = '.';
  4910. conv[6] = (xx) % 10 + '0';
  4911. conv[7] = 0;
  4912. return conv;
  4913. }
  4914. // Convert float to string with +123.45 format
  4915. char *ftostr52(const float &x)
  4916. {
  4917. long xx = x * 100;
  4918. conv[0] = (xx >= 0) ? '+' : '-';
  4919. xx = abs(xx);
  4920. conv[1] = (xx / 10000) % 10 + '0';
  4921. conv[2] = (xx / 1000) % 10 + '0';
  4922. conv[3] = (xx / 100) % 10 + '0';
  4923. conv[4] = '.';
  4924. conv[5] = (xx / 10) % 10 + '0';
  4925. conv[6] = (xx) % 10 + '0';
  4926. conv[7] = 0;
  4927. return conv;
  4928. }
  4929. /*
  4930. // Callback for after editing PID i value
  4931. // grab the PID i value out of the temp variable; scale it; then update the PID driver
  4932. void copy_and_scalePID_i()
  4933. {
  4934. #ifdef PIDTEMP
  4935. Ki = scalePID_i(raw_Ki);
  4936. updatePID();
  4937. #endif
  4938. }
  4939. // Callback for after editing PID d value
  4940. // grab the PID d value out of the temp variable; scale it; then update the PID driver
  4941. void copy_and_scalePID_d()
  4942. {
  4943. #ifdef PIDTEMP
  4944. Kd = scalePID_d(raw_Kd);
  4945. updatePID();
  4946. #endif
  4947. }
  4948. */
  4949. #endif //ULTRA_LCD