ultralcd.cpp 129 KB

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