ultralcd.cpp 146 KB

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