ultralcd.cpp 132 KB

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