ultralcd.cpp 138 KB

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