ultralcd.cpp 131 KB

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