ultralcd.cpp 129 KB

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