ultralcd.cpp 139 KB

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