ultralcd.cpp 133 KB

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