ultralcd.cpp 152 KB

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