ultralcd.cpp 132 KB

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