ultralcd.cpp 127 KB

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