ultralcd.cpp 139 KB

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