My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.pde 65KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700
  1. #include "language.h"
  2. #include "temperature.h"
  3. #include "ultralcd.h"
  4. #ifdef ULTRA_LCD
  5. #include "Marlin.h"
  6. #include "language.h"
  7. #include "temperature.h"
  8. #include "EEPROMwrite.h"
  9. #include <LiquidCrystal.h>
  10. //===========================================================================
  11. //=============================imported variables============================
  12. //===========================================================================
  13. extern volatile int feedmultiply;
  14. extern volatile bool feedmultiplychanged;
  15. extern volatile int extrudemultiply;
  16. extern long position[4];
  17. #ifdef SDSUPPORT
  18. #include "cardreader.h"
  19. extern CardReader card;
  20. #endif
  21. //===========================================================================
  22. //=============================public variables============================
  23. //===========================================================================
  24. volatile char buttons=0; //the last checked buttons in a bit array.
  25. long encoderpos=0;
  26. short lastenc=0;
  27. //===========================================================================
  28. //=============================private variables============================
  29. //===========================================================================
  30. static char messagetext[LCD_WIDTH]="";
  31. //return for string conversion routines
  32. static char conv[8];
  33. LiquidCrystal lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7
  34. static unsigned long previous_millis_lcd=0;
  35. //static long previous_millis_buttons=0;
  36. #ifdef NEWPANEL
  37. static long blocking=0;
  38. #else
  39. static long blocking[8]={0,0,0,0,0,0,0,0};
  40. #endif
  41. static MainMenu menu;
  42. void lcdProgMemprint(const char *str)
  43. {
  44. char ch=pgm_read_byte(str);
  45. while(ch)
  46. {
  47. lcd.print(ch);
  48. ch=pgm_read_byte(++str);
  49. }
  50. }
  51. #define lcdprintPGM(x) lcdProgMemprint(MYPGM(x))
  52. //===========================================================================
  53. //=============================functions ============================
  54. //===========================================================================
  55. int intround(const float &x){return int(0.5+x);}
  56. void lcd_status(const char* message)
  57. {
  58. strncpy(messagetext,message,LCD_WIDTH);
  59. messagetext[strlen(message)]=0;
  60. }
  61. void lcd_statuspgm(const char* message)
  62. {
  63. char ch=pgm_read_byte(message);
  64. char *target=messagetext;
  65. uint8_t cnt=0;
  66. while(ch &&cnt<LCD_WIDTH)
  67. {
  68. *target=ch;
  69. target++;
  70. cnt++;
  71. ch=pgm_read_byte(++message);
  72. }
  73. *target=0;
  74. }
  75. FORCE_INLINE void clear()
  76. {
  77. lcd.clear();
  78. }
  79. void lcd_init()
  80. {
  81. //beep();
  82. #ifdef ULTIPANEL
  83. buttons_init();
  84. #endif
  85. byte Degree[8] =
  86. {
  87. B01100,
  88. B10010,
  89. B10010,
  90. B01100,
  91. B00000,
  92. B00000,
  93. B00000,
  94. B00000
  95. };
  96. byte Thermometer[8] =
  97. {
  98. B00100,
  99. B01010,
  100. B01010,
  101. B01010,
  102. B01010,
  103. B10001,
  104. B10001,
  105. B01110
  106. };
  107. byte uplevel[8]={0x04, 0x0e, 0x1f, 0x04, 0x1c, 0x00, 0x00, 0x00};//thanks joris
  108. byte refresh[8]={0x00, 0x06, 0x19, 0x18, 0x03, 0x13, 0x0c, 0x00}; //thanks joris
  109. byte folder [8]={0x00, 0x1c, 0x1f, 0x11, 0x11, 0x1f, 0x00, 0x00}; //thanks joris
  110. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  111. lcd.createChar(1,Degree);
  112. lcd.createChar(2,Thermometer);
  113. lcd.createChar(3,uplevel);
  114. lcd.createChar(4,refresh);
  115. lcd.createChar(5,folder);
  116. LCD_MESSAGEPGM(WELCOME_MSG);
  117. }
  118. void beep()
  119. {
  120. //return;
  121. #ifdef ULTIPANEL
  122. #if (BEEPER > -1)
  123. {
  124. pinMode(BEEPER,OUTPUT);
  125. for(int8_t i=0;i<20;i++){
  126. WRITE(BEEPER,HIGH);
  127. delay(5);
  128. WRITE(BEEPER,LOW);
  129. delay(5);
  130. }
  131. }
  132. #endif
  133. #endif
  134. }
  135. void beepshort()
  136. {
  137. //return;
  138. #ifdef ULTIPANEL
  139. #if (BEEPER > -1)
  140. {
  141. pinMode(BEEPER,OUTPUT);
  142. for(int8_t i=0;i<10;i++){
  143. WRITE(BEEPER,HIGH);
  144. delay(3);
  145. WRITE(BEEPER,LOW);
  146. delay(3);
  147. }
  148. }
  149. #endif
  150. #endif
  151. }
  152. void lcd_status()
  153. {
  154. #ifdef ULTIPANEL
  155. static uint8_t oldbuttons=0;
  156. //static long previous_millis_buttons=0;
  157. //static long previous_lcdinit=0;
  158. // buttons_check(); // Done in temperature interrupt
  159. //previous_millis_buttons=millis();
  160. long ms=millis();
  161. for(int8_t i=0; i<8; i++) {
  162. #ifndef NEWPANEL
  163. if((blocking[i]>ms))
  164. buttons &= ~(1<<i);
  165. #else
  166. if((blocking>ms))
  167. buttons &= ~(1<<i);
  168. #endif
  169. }
  170. if((buttons==oldbuttons) && ((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
  171. return;
  172. oldbuttons=buttons;
  173. #else
  174. if(((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
  175. return;
  176. #endif
  177. previous_millis_lcd=millis();
  178. menu.update();
  179. }
  180. #ifdef ULTIPANEL
  181. void buttons_init()
  182. {
  183. #ifdef NEWPANEL
  184. pinMode(BTN_EN1,INPUT);
  185. pinMode(BTN_EN2,INPUT);
  186. pinMode(BTN_ENC,INPUT);
  187. pinMode(SDCARDDETECT,INPUT);
  188. WRITE(BTN_EN1,HIGH);
  189. WRITE(BTN_EN2,HIGH);
  190. WRITE(BTN_ENC,HIGH);
  191. #if (SDCARDDETECT > -1)
  192. {
  193. WRITE(SDCARDDETECT,HIGH);
  194. }
  195. #endif
  196. #else
  197. pinMode(SHIFT_CLK,OUTPUT);
  198. pinMode(SHIFT_LD,OUTPUT);
  199. pinMode(SHIFT_EN,OUTPUT);
  200. pinMode(SHIFT_OUT,INPUT);
  201. WRITE(SHIFT_OUT,HIGH);
  202. WRITE(SHIFT_LD,HIGH);
  203. WRITE(SHIFT_EN,LOW);
  204. #endif
  205. }
  206. void buttons_check()
  207. {
  208. #ifdef NEWPANEL
  209. uint8_t newbutton=0;
  210. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  211. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  212. if((blocking<millis()) &&(READ(BTN_ENC)==0))
  213. newbutton|=EN_C;
  214. buttons=newbutton;
  215. #else //read it from the shift register
  216. uint8_t newbutton=0;
  217. WRITE(SHIFT_LD,LOW);
  218. WRITE(SHIFT_LD,HIGH);
  219. unsigned char tmp_buttons=0;
  220. for(int8_t i=0;i<8;i++)
  221. {
  222. newbutton = newbutton>>1;
  223. if(READ(SHIFT_OUT))
  224. newbutton|=(1<<7);
  225. WRITE(SHIFT_CLK,HIGH);
  226. WRITE(SHIFT_CLK,LOW);
  227. }
  228. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  229. #endif
  230. //manage encoder rotation
  231. char enc=0;
  232. if(buttons&EN_A)
  233. enc|=(1<<0);
  234. if(buttons&EN_B)
  235. enc|=(1<<1);
  236. if(enc!=lastenc)
  237. {
  238. switch(enc)
  239. {
  240. case encrot0:
  241. if(lastenc==encrot3)
  242. encoderpos++;
  243. else if(lastenc==encrot1)
  244. encoderpos--;
  245. break;
  246. case encrot1:
  247. if(lastenc==encrot0)
  248. encoderpos++;
  249. else if(lastenc==encrot2)
  250. encoderpos--;
  251. break;
  252. case encrot2:
  253. if(lastenc==encrot1)
  254. encoderpos++;
  255. else if(lastenc==encrot3)
  256. encoderpos--;
  257. break;
  258. case encrot3:
  259. if(lastenc==encrot2)
  260. encoderpos++;
  261. else if(lastenc==encrot0)
  262. encoderpos--;
  263. break;
  264. default:
  265. ;
  266. }
  267. }
  268. lastenc=enc;
  269. }
  270. #endif
  271. MainMenu::MainMenu()
  272. {
  273. status=Main_Status;
  274. displayStartingRow=0;
  275. activeline=0;
  276. force_lcd_update=true;
  277. linechanging=false;
  278. tune=false;
  279. }
  280. void MainMenu::showStatus()
  281. {
  282. #if LCD_HEIGHT==4
  283. static int olddegHotEnd0=-1;
  284. static int oldtargetHotEnd0=-1;
  285. //force_lcd_update=true;
  286. if(force_lcd_update) //initial display of content
  287. {
  288. encoderpos=feedmultiply;
  289. clear();
  290. lcd.setCursor(0,0);lcdprintPGM("\002---/---\001 ");
  291. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  292. lcd.setCursor(10,0);lcdprintPGM("B---/---\001 ");
  293. #elif EXTRUDERS > 1
  294. lcd.setCursor(10,0);lcdprintPGM("\002---/---\001 ");
  295. #endif
  296. }
  297. int tHotEnd0=intround(degHotend0());
  298. if((tHotEnd0!=olddegHotEnd0)||force_lcd_update)
  299. {
  300. lcd.setCursor(1,0);
  301. lcd.print(ftostr3(tHotEnd0));
  302. olddegHotEnd0=tHotEnd0;
  303. }
  304. int ttHotEnd0=intround(degTargetHotend0());
  305. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  306. {
  307. lcd.setCursor(5,0);
  308. lcd.print(ftostr3(ttHotEnd0));
  309. oldtargetHotEnd0=ttHotEnd0;
  310. }
  311. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  312. static int oldtBed=-1;
  313. static int oldtargetBed=-1;
  314. int tBed=intround(degBed());
  315. if((tBed!=oldtBed)||force_lcd_update)
  316. {
  317. lcd.setCursor(11,0);
  318. lcd.print(ftostr3(tBed));
  319. oldtBed=tBed;
  320. }
  321. int targetBed=intround(degTargetBed());
  322. if((targetBed!=oldtargetBed)||force_lcd_update)
  323. {
  324. lcd.setCursor(15,0);
  325. lcd.print(ftostr3(targetBed));
  326. oldtargetBed=targetBed;
  327. }
  328. #elif EXTRUDERS > 1
  329. static int olddegHotEnd1=-1;
  330. static int oldtargetHotEnd1=-1;
  331. int tHotEnd1=intround(degHotend1());
  332. if((tHotEnd1!=olddegHotEnd1)||force_lcd_update)
  333. {
  334. lcd.setCursor(11,0);
  335. lcd.print(ftostr3(tHotEnd1));
  336. olddegHotEnd1=tHotEnd1;
  337. }
  338. int ttHotEnd1=intround(degTargetHotend1());
  339. if((ttHotEnd1!=oldtargetHotEnd1)||force_lcd_update)
  340. {
  341. lcd.setCursor(15,0);
  342. lcd.print(ftostr3(ttHotEnd1));
  343. oldtargetHotEnd1=ttHotEnd1;
  344. }
  345. #endif
  346. //starttime=2;
  347. static uint16_t oldtime=0;
  348. if(starttime!=0)
  349. {
  350. lcd.setCursor(0,1);
  351. uint16_t time=millis()/60000-starttime/60000;
  352. if(starttime!=oldtime)
  353. {
  354. lcd.print(itostr2(time/60));lcdprintPGM("h ");lcd.print(itostr2(time%60));lcdprintPGM("m");
  355. oldtime=time;
  356. }
  357. }
  358. static int oldzpos=0;
  359. int currentz=current_position[2]*100;
  360. if((currentz!=oldzpos)||force_lcd_update)
  361. {
  362. lcd.setCursor(10,1);
  363. lcdprintPGM("Z:");lcd.print(ftostr52(current_position[2]));
  364. oldzpos=currentz;
  365. }
  366. static int oldfeedmultiply=0;
  367. int curfeedmultiply=feedmultiply;
  368. if(feedmultiplychanged == true) {
  369. feedmultiplychanged = false;
  370. encoderpos = curfeedmultiply;
  371. }
  372. if(encoderpos!=curfeedmultiply||force_lcd_update)
  373. {
  374. curfeedmultiply=encoderpos;
  375. if(curfeedmultiply<10)
  376. curfeedmultiply=10;
  377. if(curfeedmultiply>999)
  378. curfeedmultiply=999;
  379. feedmultiply=curfeedmultiply;
  380. encoderpos=curfeedmultiply;
  381. }
  382. if((curfeedmultiply!=oldfeedmultiply)||force_lcd_update)
  383. {
  384. oldfeedmultiply=curfeedmultiply;
  385. lcd.setCursor(0,2);
  386. lcd.print(itostr3(curfeedmultiply));lcdprintPGM("% ");
  387. }
  388. if(messagetext[0]!='\0')
  389. {
  390. lcd.setCursor(0,LCD_HEIGHT-1);
  391. lcd.print(messagetext);
  392. uint8_t n=strlen(messagetext);
  393. for(int8_t i=0;i<LCD_WIDTH-n;i++)
  394. lcd.print(" ");
  395. messagetext[0]='\0';
  396. }
  397. #ifdef SDSUPPORT
  398. static uint8_t oldpercent=101;
  399. uint8_t percent=card.percentDone();
  400. if(oldpercent!=percent ||force_lcd_update)
  401. {
  402. lcd.setCursor(10,2);
  403. lcd.print(itostr3((int)percent));
  404. lcdprintPGM("%SD");
  405. }
  406. #endif
  407. #else //smaller LCDS----------------------------------
  408. static int olddegHotEnd0=-1;
  409. static int oldtargetHotEnd0=-1;
  410. if(force_lcd_update) //initial display of content
  411. {
  412. encoderpos=feedmultiply;
  413. lcd.setCursor(0,0);lcdprintPGM("\002---/---\001 ");
  414. }
  415. int tHotEnd0=intround(degHotend0());
  416. int ttHotEnd0=intround(degTargetHotend0());
  417. if((abs(tHotEnd0-olddegHotEnd0)>1)||force_lcd_update)
  418. {
  419. lcd.setCursor(1,0);
  420. lcd.print(ftostr3(tHotEnd0));
  421. olddegHotEnd0=tHotEnd0;
  422. }
  423. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  424. {
  425. lcd.setCursor(5,0);
  426. lcd.print(ftostr3(ttHotEnd0));
  427. oldtargetHotEnd0=ttHotEnd0;
  428. }
  429. if(messagetext[0]!='\0')
  430. {
  431. lcd.setCursor(0,LCD_HEIGHT-1);
  432. lcd.print(messagetext);
  433. uint8_t n=strlen(messagetext);
  434. for(int8_t i=0;i<LCD_WIDTH-n;i++)
  435. lcd.print(" ");
  436. messagetext[0]='\0';
  437. }
  438. #endif
  439. force_lcd_update=false;
  440. }
  441. enum {ItemP_exit, ItemP_autostart,ItemP_disstep,ItemP_home, ItemP_origin, ItemP_preheat_pla, ItemP_preheat_abs, ItemP_cooldown,/*ItemP_extrude,*/ItemP_move};
  442. //any action must not contain a ',' character anywhere, or this breaks:
  443. #define MENUITEM(repaint_action, click_action) \
  444. {\
  445. if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  446. if((activeline==line) && CLICKED) {click_action} \
  447. }
  448. void MainMenu::showPrepare()
  449. {
  450. #ifdef ULTIPANEL
  451. uint8_t line=0;
  452. clearIfNecessary();
  453. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  454. {
  455. //Serial.println((int)(line-lineoffset));
  456. switch(i)
  457. {
  458. case ItemP_exit:
  459. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  460. break;
  461. case ItemP_autostart:
  462. MENUITEM( lcdprintPGM(MSG_AUTOSTART) , BLOCK;
  463. #ifdef SDSUPPORT
  464. card.lastnr=0;card.setroot();card.checkautostart(true);
  465. #endif
  466. beepshort(); ) ;
  467. break;
  468. case ItemP_disstep:
  469. MENUITEM( lcdprintPGM(MSG_DISABLE_STEPPERS) , BLOCK;enquecommand("M84");beepshort(); ) ;
  470. break;
  471. case ItemP_home:
  472. MENUITEM( lcdprintPGM(MSG_AUTO_HOME) , BLOCK;enquecommand("G28");beepshort(); ) ;
  473. break;
  474. case ItemP_origin:
  475. MENUITEM( lcdprintPGM(MSG_SET_ORIGIN) , BLOCK;enquecommand("G92 X0 Y0 Z0");beepshort(); ) ;
  476. break;
  477. case ItemP_preheat_pla:
  478. MENUITEM( lcdprintPGM(MSG_PREHEAT_PLA) , BLOCK;setTargetHotend0(PLA_PREHEAT_HOTEND_TEMP);setTargetBed(PLA_PREHEAT_HPB_TEMP);
  479. #if FAN_PIN > -1
  480. FanSpeed=PLA_PREHEAT_FAN_SPEED;
  481. analogWrite(FAN_PIN, FanSpeed);
  482. #endif
  483. beepshort(); );
  484. break;
  485. case ItemP_preheat_abs:
  486. MENUITEM( lcdprintPGM(MSG_PREHEAT_ABS) , BLOCK;setTargetHotend0(ABS_PREHEAT_HOTEND_TEMP);setTargetBed(ABS_PREHEAT_HPB_TEMP);
  487. #if FAN_PIN > -1
  488. FanSpeed=ABS_PREHEAT_FAN_SPEED;
  489. analogWrite(FAN_PIN, FanSpeed);
  490. #endif
  491. beepshort(); );
  492. break;
  493. case ItemP_cooldown:
  494. MENUITEM( lcdprintPGM(MSG_COOLDOWN) , BLOCK;setTargetHotend0(0);setTargetHotend1(0);setTargetHotend2(0);setTargetBed(0);beepshort(); ) ;
  495. break;
  496. // case ItemP_extrude:
  497. // MENUITEM( lcdprintPGM(" Extrude") , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E50");beepshort(); ) ;
  498. // break;
  499. case ItemP_move:
  500. MENUITEM( lcdprintPGM(MSG_MOVE_AXIS) , BLOCK;status=Sub_PrepareMove;beepshort(); );
  501. break;
  502. default:
  503. break;
  504. }
  505. line++;
  506. }
  507. updateActiveLines(ItemP_move,encoderpos);
  508. #endif
  509. }
  510. enum {
  511. ItemAM_exit,
  512. ItemAM_X, ItemAM_Y, ItemAM_Z, ItemAM_E, ItemAM_ERetract
  513. };
  514. void MainMenu::showAxisMove()
  515. {
  516. uint8_t line=0;
  517. int oldencoderpos=0;
  518. clearIfNecessary();
  519. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  520. {
  521. switch(i)
  522. {
  523. case ItemAM_exit:
  524. MENUITEM( lcdprintPGM(MSG_PREPARE_ALT) , BLOCK;status=Main_Prepare;beepshort(); ) ;
  525. break;
  526. case ItemAM_X:
  527. {
  528. //oldencoderpos=0;
  529. if(force_lcd_update)
  530. {
  531. lcd.setCursor(0,line);lcdprintPGM(" X:");
  532. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[X_AXIS]));
  533. }
  534. if((activeline!=line) )
  535. break;
  536. if(CLICKED)
  537. {
  538. linechanging=!linechanging;
  539. if(linechanging)
  540. {
  541. enquecommand("G91");
  542. }
  543. else
  544. {
  545. enquecommand("G90");
  546. encoderpos=activeline*lcdslow;
  547. beepshort();
  548. }
  549. BLOCK;
  550. }
  551. if(linechanging)
  552. {
  553. if (encoderpos >0)
  554. {
  555. enquecommand("G1 F700 X0.1");
  556. oldencoderpos=encoderpos;
  557. encoderpos=0;
  558. }
  559. else if (encoderpos < 0)
  560. {
  561. enquecommand("G1 F700 X-0.1");
  562. oldencoderpos=encoderpos;
  563. encoderpos=0;
  564. }
  565. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[X_AXIS]));
  566. }
  567. }
  568. break;
  569. case ItemAM_Y:
  570. {
  571. if(force_lcd_update)
  572. {
  573. lcd.setCursor(0,line);lcdprintPGM(" Y:");
  574. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Y_AXIS]));
  575. }
  576. if((activeline!=line) )
  577. break;
  578. if(CLICKED)
  579. {
  580. linechanging=!linechanging;
  581. if(linechanging)
  582. {
  583. enquecommand("G91");
  584. }
  585. else
  586. {
  587. enquecommand("G90");
  588. encoderpos=activeline*lcdslow;
  589. beepshort();
  590. }
  591. BLOCK;
  592. }
  593. if(linechanging)
  594. {
  595. if (encoderpos >0)
  596. {
  597. enquecommand("G1 F700 Y0.1");
  598. oldencoderpos=encoderpos;
  599. encoderpos=0;
  600. }
  601. else if (encoderpos < 0)
  602. {
  603. enquecommand("G1 F700 Y-0.1");
  604. oldencoderpos=encoderpos;
  605. encoderpos=0;
  606. }
  607. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Y_AXIS]));
  608. }
  609. }
  610. break;
  611. case ItemAM_Z:
  612. {
  613. if(force_lcd_update)
  614. {
  615. lcd.setCursor(0,line);lcdprintPGM(" Z:");
  616. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Z_AXIS]));
  617. }
  618. if((activeline!=line) )
  619. break;
  620. if(CLICKED)
  621. {
  622. linechanging=!linechanging;
  623. if(linechanging)
  624. {
  625. enquecommand("G91");
  626. }
  627. else
  628. {
  629. enquecommand("G90");
  630. encoderpos=activeline*lcdslow;
  631. beepshort();
  632. }
  633. BLOCK;
  634. }
  635. if(linechanging)
  636. {
  637. if (encoderpos >0)
  638. {
  639. enquecommand("G1 F70 Z0.1");
  640. oldencoderpos=encoderpos;
  641. encoderpos=0;
  642. }
  643. else if (encoderpos < 0)
  644. {
  645. enquecommand("G1 F70 Z-0.1");
  646. oldencoderpos=encoderpos;
  647. encoderpos=0;
  648. }
  649. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Z_AXIS]));
  650. }
  651. }
  652. break;
  653. case ItemAM_E:
  654. // ErikDB: TODO: this length should be changed for volumetric.
  655. MENUITEM( lcdprintPGM(MSG_EXTRUDE) , BLOCK;enquecommand("G92 E0");enquecommand("G1 F70 E1");beepshort(); ) ;
  656. break;
  657. case ItemAM_ERetract:
  658. // ErikDB: TODO: this length should be changed for volumetric.
  659. MENUITEM( lcdprintPGM(MSG_RETRACT) , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E-1");beepshort(); ) ;
  660. break;
  661. default:
  662. break;
  663. }
  664. line++;
  665. }
  666. updateActiveLines(ItemAM_ERetract,encoderpos);
  667. }
  668. enum {ItemT_exit,ItemT_speed,ItemT_flow,ItemT_nozzle,
  669. #if (HEATER_BED_PIN > -1)
  670. ItemT_bed,
  671. #endif
  672. ItemT_fan};
  673. void MainMenu::showTune()
  674. {
  675. uint8_t line=0;
  676. clearIfNecessary();
  677. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  678. {
  679. //Serial.println((int)(line-lineoffset));
  680. switch(i)
  681. {
  682. case ItemT_exit:
  683. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  684. break;
  685. case ItemT_speed:
  686. {
  687. if(force_lcd_update)
  688. {
  689. lcd.setCursor(0,line);lcdprintPGM(MSG_SPEED);
  690. lcd.setCursor(13,line);lcd.print(ftostr3(feedmultiply));
  691. }
  692. if((activeline!=line) )
  693. break;
  694. if(CLICKED) //AnalogWrite(FAN_PIN, fanpwm);
  695. {
  696. linechanging=!linechanging;
  697. if(linechanging)
  698. {
  699. encoderpos=feedmultiply;
  700. }
  701. else
  702. {
  703. encoderpos=activeline*lcdslow;
  704. beepshort();
  705. }
  706. BLOCK;
  707. }
  708. if(linechanging)
  709. {
  710. if(encoderpos<1) encoderpos=1;
  711. if(encoderpos>400) encoderpos=400;
  712. feedmultiply = encoderpos;
  713. feedmultiplychanged=true;
  714. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  715. }
  716. }break;
  717. case ItemT_nozzle:
  718. {
  719. if(force_lcd_update)
  720. {
  721. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE);
  722. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  723. }
  724. if((activeline!=line) )
  725. break;
  726. if(CLICKED)
  727. {
  728. linechanging=!linechanging;
  729. if(linechanging)
  730. {
  731. encoderpos=intround(degTargetHotend0());
  732. }
  733. else
  734. {
  735. setTargetHotend0(encoderpos);
  736. encoderpos=activeline*lcdslow;
  737. beepshort();
  738. }
  739. BLOCK;
  740. }
  741. if(linechanging)
  742. {
  743. if(encoderpos<0) encoderpos=0;
  744. if(encoderpos>260) encoderpos=260;
  745. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  746. }
  747. }break;
  748. #if (HEATER_BED_PIN > -1)
  749. case ItemT_bed:
  750. {
  751. if(force_lcd_update)
  752. {
  753. lcd.setCursor(0,line);lcdprintPGM(MSG_BED);
  754. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  755. }
  756. if((activeline!=line) )
  757. break;
  758. if(CLICKED)
  759. {
  760. linechanging=!linechanging;
  761. if(linechanging)
  762. {
  763. encoderpos=intround(degTargetBed());
  764. }
  765. else
  766. {
  767. setTargetBed(encoderpos);
  768. encoderpos=activeline*lcdslow;
  769. beepshort();
  770. }
  771. BLOCK;
  772. }
  773. if(linechanging)
  774. {
  775. if(encoderpos<0) encoderpos=0;
  776. if(encoderpos>260) encoderpos=260;
  777. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  778. }
  779. }break;
  780. #endif
  781. case ItemT_fan:
  782. {
  783. if(force_lcd_update)
  784. {
  785. lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
  786. lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
  787. }
  788. if((activeline!=line) )
  789. break;
  790. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  791. {
  792. linechanging=!linechanging;
  793. if(linechanging)
  794. {
  795. encoderpos=FanSpeed;
  796. }
  797. else
  798. {
  799. encoderpos=activeline*lcdslow;
  800. beepshort();
  801. }
  802. BLOCK;
  803. }
  804. if(linechanging)
  805. {
  806. if(encoderpos<0) encoderpos=0;
  807. if(encoderpos>255) encoderpos=255;
  808. FanSpeed=encoderpos;
  809. analogWrite(FAN_PIN, FanSpeed);
  810. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  811. }
  812. }break;
  813. case ItemT_flow://axis_steps_per_unit[i] = code_value();
  814. {
  815. if(force_lcd_update)
  816. {
  817. lcd.setCursor(0,line);lcdprintPGM(MSG_FLOW);
  818. lcd.setCursor(13,line);lcd.print(ftostr52(axis_steps_per_unit[E_AXIS]));
  819. }
  820. if((activeline!=line) )
  821. break;
  822. if(CLICKED)
  823. {
  824. linechanging=!linechanging;
  825. if(linechanging)
  826. {
  827. encoderpos=(long)(axis_steps_per_unit[E_AXIS]*100.0);
  828. }
  829. else
  830. {
  831. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[E_AXIS]);
  832. position[E_AXIS]=lround(position[E_AXIS]*factor);
  833. //current_position[E_AXIS]*=factor;
  834. axis_steps_per_unit[E_AXIS]= encoderpos/100.0;
  835. encoderpos=activeline*lcdslow;
  836. }
  837. BLOCK;
  838. beepshort();
  839. }
  840. if(linechanging)
  841. {
  842. if(encoderpos<5) encoderpos=5;
  843. if(encoderpos>999999) encoderpos=999999;
  844. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.0));
  845. }
  846. }break;
  847. default:
  848. break;
  849. }
  850. line++;
  851. }
  852. updateActiveLines(ItemT_fan,encoderpos);
  853. }
  854. //does not work
  855. // #define MENUCHANGEITEM(repaint_action, enter_action, accept_action, change_action) \
  856. // {\
  857. // if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  858. // if(activeline==line) \
  859. // { \
  860. // if(CLICKED) \
  861. // { \
  862. // linechanging=!linechanging; \
  863. // if(linechanging) {enter_action;} \
  864. // else {accept_action;} \
  865. // } \
  866. // else \
  867. // if(linechanging) {change_action};}\
  868. // }
  869. //
  870. enum {
  871. ItemCT_exit,ItemCT_nozzle0,
  872. #ifdef AUTOTEMP
  873. ItemCT_autotempactive,
  874. ItemCT_autotempmin,ItemCT_autotempmax,ItemCT_autotempfact,
  875. #endif
  876. #if EXTRUDERS > 1
  877. ItemCT_nozzle1,
  878. #endif
  879. #if EXTRUDERS > 2
  880. ItemCT_nozzle2,
  881. #endif
  882. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  883. ItemCT_bed,
  884. #endif
  885. ItemCT_fan,
  886. ItemCT_PID_P,ItemCT_PID_I,ItemCT_PID_D,ItemCT_PID_C
  887. };
  888. void MainMenu::showControlTemp()
  889. {
  890. uint8_t line=0;
  891. clearIfNecessary();
  892. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  893. {
  894. switch(i)
  895. {
  896. case ItemCT_exit:
  897. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  898. break;
  899. case ItemCT_nozzle0:
  900. {
  901. if(force_lcd_update)
  902. {
  903. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE);
  904. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  905. }
  906. if((activeline!=line) )
  907. break;
  908. if(CLICKED)
  909. {
  910. linechanging=!linechanging;
  911. if(linechanging)
  912. {
  913. encoderpos=intround(degTargetHotend0());
  914. }
  915. else
  916. {
  917. setTargetHotend0(encoderpos);
  918. encoderpos=activeline*lcdslow;
  919. beepshort();
  920. }
  921. BLOCK;
  922. }
  923. if(linechanging)
  924. {
  925. if(encoderpos<0) encoderpos=0;
  926. if(encoderpos>260) encoderpos=260;
  927. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  928. }
  929. }break;
  930. #if EXTRUDERS > 1
  931. case ItemCT_nozzle1:
  932. {
  933. if(force_lcd_update)
  934. {
  935. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE1);
  936. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend1())));
  937. }
  938. if((activeline!=line) )
  939. break;
  940. if(CLICKED)
  941. {
  942. linechanging=!linechanging;
  943. if(linechanging)
  944. {
  945. encoderpos=intround(degTargetHotend1());
  946. }
  947. else
  948. {
  949. setTargetHotend1(encoderpos);
  950. encoderpos=activeline*lcdslow;
  951. beepshort();
  952. }
  953. BLOCK;
  954. }
  955. if(linechanging)
  956. {
  957. if(encoderpos<0) encoderpos=0;
  958. if(encoderpos>260) encoderpos=260;
  959. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  960. }
  961. }break;
  962. #endif
  963. #if EXTRUDERS > 2
  964. case ItemCT_nozzle2:
  965. {
  966. if(force_lcd_update)
  967. {
  968. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE2);
  969. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend2())));
  970. }
  971. if((activeline!=line) )
  972. break;
  973. if(CLICKED)
  974. {
  975. linechanging=!linechanging;
  976. if(linechanging)
  977. {
  978. encoderpos=intround(degTargetHotend2());
  979. }
  980. else
  981. {
  982. setTargetHotend1(encoderpos);
  983. encoderpos=activeline*lcdslow;
  984. beepshort();
  985. }
  986. BLOCK;
  987. }
  988. if(linechanging)
  989. {
  990. if(encoderpos<0) encoderpos=0;
  991. if(encoderpos>260) encoderpos=260;
  992. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  993. }
  994. }break;
  995. #endif
  996. #ifdef AUTOTEMP
  997. case ItemCT_autotempmin:
  998. {
  999. if(force_lcd_update)
  1000. {
  1001. lcd.setCursor(0,line);lcdprintPGM(MSG_MIN);
  1002. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_min));
  1003. }
  1004. if((activeline!=line) )
  1005. break;
  1006. if(CLICKED)
  1007. {
  1008. linechanging=!linechanging;
  1009. if(linechanging)
  1010. {
  1011. encoderpos=intround(autotemp_min);
  1012. }
  1013. else
  1014. {
  1015. autotemp_min=encoderpos;
  1016. encoderpos=activeline*lcdslow;
  1017. beepshort();
  1018. }
  1019. BLOCK;
  1020. }
  1021. if(linechanging)
  1022. {
  1023. if(encoderpos<0) encoderpos=0;
  1024. if(encoderpos>260) encoderpos=260;
  1025. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1026. }
  1027. }break;
  1028. case ItemCT_autotempmax:
  1029. {
  1030. if(force_lcd_update)
  1031. {
  1032. lcd.setCursor(0,line);lcdprintPGM(MSG_MAX);
  1033. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_max));
  1034. }
  1035. if((activeline!=line) )
  1036. break;
  1037. if(CLICKED)
  1038. {
  1039. linechanging=!linechanging;
  1040. if(linechanging)
  1041. {
  1042. encoderpos=intround(autotemp_max);
  1043. }
  1044. else
  1045. {
  1046. autotemp_max=encoderpos;
  1047. encoderpos=activeline*lcdslow;
  1048. beepshort();
  1049. }
  1050. BLOCK;
  1051. }
  1052. if(linechanging)
  1053. {
  1054. if(encoderpos<0) encoderpos=0;
  1055. if(encoderpos>260) encoderpos=260;
  1056. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1057. }
  1058. }break;
  1059. case ItemCT_autotempfact:
  1060. {
  1061. if(force_lcd_update)
  1062. {
  1063. lcd.setCursor(0,line);lcdprintPGM(MSG_FACTOR);
  1064. lcd.setCursor(13,line);lcd.print(ftostr32(autotemp_factor));
  1065. }
  1066. if((activeline!=line) )
  1067. break;
  1068. if(CLICKED)
  1069. {
  1070. linechanging=!linechanging;
  1071. if(linechanging)
  1072. {
  1073. encoderpos=intround(autotemp_factor*100);
  1074. }
  1075. else
  1076. {
  1077. autotemp_max=encoderpos;
  1078. encoderpos=activeline*lcdslow;
  1079. beepshort();
  1080. }
  1081. BLOCK;
  1082. }
  1083. if(linechanging)
  1084. {
  1085. if(encoderpos<0) encoderpos=0;
  1086. if(encoderpos>99) encoderpos=99;
  1087. lcd.setCursor(13,line);lcd.print(ftostr32(encoderpos/100.));
  1088. }
  1089. }break;
  1090. case ItemCT_autotempactive:
  1091. {
  1092. if(force_lcd_update)
  1093. {
  1094. lcd.setCursor(0,line);lcdprintPGM(MSG_AUTOTEMP);
  1095. lcd.setCursor(13,line);
  1096. if(autotemp_enabled)
  1097. lcdprintPGM(MSG_ON);
  1098. else
  1099. lcdprintPGM(MSG_OFF);
  1100. }
  1101. if((activeline!=line) )
  1102. break;
  1103. if(CLICKED)
  1104. {
  1105. autotemp_enabled=!autotemp_enabled;
  1106. lcd.setCursor(13,line);
  1107. if(autotemp_enabled)
  1108. lcdprintPGM(MSG_ON);
  1109. else
  1110. lcdprintPGM(MSG_OFF);
  1111. BLOCK;
  1112. }
  1113. }break;
  1114. #endif //autotemp
  1115. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  1116. case ItemCT_bed:
  1117. {
  1118. if(force_lcd_update)
  1119. {
  1120. lcd.setCursor(0,line);lcdprintPGM(MSG_BED);
  1121. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  1122. }
  1123. if((activeline!=line) )
  1124. break;
  1125. if(CLICKED)
  1126. {
  1127. linechanging=!linechanging;
  1128. if(linechanging)
  1129. {
  1130. encoderpos=intround(degTargetBed());
  1131. }
  1132. else
  1133. {
  1134. setTargetBed(encoderpos);
  1135. encoderpos=activeline*lcdslow;
  1136. beepshort();
  1137. }
  1138. BLOCK;
  1139. }
  1140. if(linechanging)
  1141. {
  1142. if(encoderpos<0) encoderpos=0;
  1143. if(encoderpos>260) encoderpos=260;
  1144. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1145. }
  1146. }break;
  1147. #endif
  1148. case ItemCT_fan:
  1149. {
  1150. if(force_lcd_update)
  1151. {
  1152. lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
  1153. lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
  1154. }
  1155. if((activeline!=line) )
  1156. break;
  1157. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  1158. {
  1159. linechanging=!linechanging;
  1160. if(linechanging)
  1161. {
  1162. encoderpos=FanSpeed;
  1163. }
  1164. else
  1165. {
  1166. encoderpos=activeline*lcdslow;
  1167. beepshort();
  1168. }
  1169. BLOCK;
  1170. }
  1171. if(linechanging)
  1172. {
  1173. if(encoderpos<0) encoderpos=0;
  1174. if(encoderpos>255) encoderpos=255;
  1175. FanSpeed=encoderpos;
  1176. analogWrite(FAN_PIN, FanSpeed);
  1177. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1178. }
  1179. }break;
  1180. #ifdef PIDTEMP
  1181. case ItemCT_PID_P:
  1182. {
  1183. if(force_lcd_update)
  1184. {
  1185. lcd.setCursor(0,line);lcdprintPGM(" PID-P: ");
  1186. lcd.setCursor(13,line);lcd.print(itostr4(Kp));
  1187. }
  1188. if((activeline!=line) )
  1189. break;
  1190. if(CLICKED)
  1191. {
  1192. linechanging=!linechanging;
  1193. if(linechanging)
  1194. {
  1195. encoderpos=(long)Kp;
  1196. }
  1197. else
  1198. {
  1199. Kp= encoderpos;
  1200. encoderpos=activeline*lcdslow;
  1201. }
  1202. BLOCK;
  1203. beepshort();
  1204. }
  1205. if(linechanging)
  1206. {
  1207. if(encoderpos<1) encoderpos=1;
  1208. if(encoderpos>9990) encoderpos=9990;
  1209. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1210. }
  1211. }break;
  1212. case ItemCT_PID_I:
  1213. {
  1214. if(force_lcd_update)
  1215. {
  1216. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_I);
  1217. lcd.setCursor(13,line);lcd.print(ftostr51(Ki/PID_dT));
  1218. }
  1219. if((activeline!=line) )
  1220. break;
  1221. if(CLICKED)
  1222. {
  1223. linechanging=!linechanging;
  1224. if(linechanging)
  1225. {
  1226. encoderpos=(long)(Ki*10/PID_dT);
  1227. }
  1228. else
  1229. {
  1230. Ki= encoderpos/10.*PID_dT;
  1231. encoderpos=activeline*lcdslow;
  1232. }
  1233. BLOCK;
  1234. beepshort();
  1235. }
  1236. if(linechanging)
  1237. {
  1238. if(encoderpos<0) encoderpos=0;
  1239. if(encoderpos>9990) encoderpos=9990;
  1240. lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.));
  1241. }
  1242. }break;
  1243. case ItemCT_PID_D:
  1244. {
  1245. if(force_lcd_update)
  1246. {
  1247. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_D);
  1248. lcd.setCursor(13,line);lcd.print(itostr4(Kd*PID_dT));
  1249. }
  1250. if((activeline!=line) )
  1251. break;
  1252. if(CLICKED)
  1253. {
  1254. linechanging=!linechanging;
  1255. if(linechanging)
  1256. {
  1257. encoderpos=(long)(Kd/5./PID_dT);
  1258. }
  1259. else
  1260. {
  1261. Kd= encoderpos;
  1262. encoderpos=activeline*lcdslow;
  1263. }
  1264. BLOCK;
  1265. beepshort();
  1266. }
  1267. if(linechanging)
  1268. {
  1269. if(encoderpos<0) encoderpos=0;
  1270. if(encoderpos>9990) encoderpos=9990;
  1271. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1272. }
  1273. }break;
  1274. case ItemCT_PID_C:
  1275. #ifdef PID_ADD_EXTRUSION_RATE
  1276. {
  1277. if(force_lcd_update)
  1278. {
  1279. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_C);
  1280. lcd.setCursor(13,line);lcd.print(itostr3(Kc));
  1281. }
  1282. if((activeline!=line) )
  1283. break;
  1284. if(CLICKED)
  1285. {
  1286. linechanging=!linechanging;
  1287. if(linechanging)
  1288. {
  1289. encoderpos=(long)Kc;
  1290. }
  1291. else
  1292. {
  1293. Kc= encoderpos;
  1294. encoderpos=activeline*lcdslow;
  1295. }
  1296. BLOCK;
  1297. beepshort();
  1298. }
  1299. if(linechanging)
  1300. {
  1301. if(encoderpos<0) encoderpos=0;
  1302. if(encoderpos>990) encoderpos=990;
  1303. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1304. }
  1305. }
  1306. #endif
  1307. #endif
  1308. break;
  1309. default:
  1310. break;
  1311. }
  1312. line++;
  1313. }
  1314. #ifdef PID_ADD_EXTRUSION_RATE
  1315. updateActiveLines(ItemCT_PID_C,encoderpos);
  1316. #else
  1317. updateActiveLines(ItemCT_PID_D,encoderpos);
  1318. #endif
  1319. }
  1320. enum {
  1321. ItemCM_exit,
  1322. ItemCM_acc, ItemCM_xyjerk,
  1323. ItemCM_vmaxx, ItemCM_vmaxy, ItemCM_vmaxz, ItemCM_vmaxe,
  1324. ItemCM_vtravmin,ItemCM_vmin,
  1325. ItemCM_amaxx, ItemCM_amaxy, ItemCM_amaxz, ItemCM_amaxe,
  1326. ItemCM_aret, ItemCM_xsteps,ItemCM_ysteps, ItemCM_zsteps, ItemCM_esteps
  1327. };
  1328. void MainMenu::showControlMotion()
  1329. {
  1330. uint8_t line=0;
  1331. clearIfNecessary();
  1332. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1333. {
  1334. switch(i)
  1335. {
  1336. case ItemCM_exit:
  1337. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  1338. break;
  1339. case ItemCM_acc:
  1340. {
  1341. if(force_lcd_update)
  1342. {
  1343. lcd.setCursor(0,line);lcdprintPGM(MSG_ACC);
  1344. lcd.setCursor(13,line);lcd.print(itostr3(acceleration/100));lcdprintPGM("00");
  1345. }
  1346. if((activeline!=line) )
  1347. break;
  1348. if(CLICKED)
  1349. {
  1350. linechanging=!linechanging;
  1351. if(linechanging)
  1352. {
  1353. encoderpos=(long)acceleration/100;
  1354. }
  1355. else
  1356. {
  1357. acceleration= encoderpos*100;
  1358. encoderpos=activeline*lcdslow;
  1359. }
  1360. BLOCK;
  1361. beepshort();
  1362. }
  1363. if(linechanging)
  1364. {
  1365. if(encoderpos<5) encoderpos=5;
  1366. if(encoderpos>990) encoderpos=990;
  1367. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1368. }
  1369. }break;
  1370. case ItemCM_xyjerk: //max_xy_jerk
  1371. {
  1372. if(force_lcd_update)
  1373. {
  1374. lcd.setCursor(0,line);lcdprintPGM(MSG_VXY_JERK);
  1375. lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk));
  1376. }
  1377. if((activeline!=line) )
  1378. break;
  1379. if(CLICKED)
  1380. {
  1381. linechanging=!linechanging;
  1382. if(linechanging)
  1383. {
  1384. encoderpos=(long)max_xy_jerk;
  1385. }
  1386. else
  1387. {
  1388. max_xy_jerk= encoderpos;
  1389. encoderpos=activeline*lcdslow;
  1390. }
  1391. BLOCK;
  1392. beepshort();
  1393. }
  1394. if(linechanging)
  1395. {
  1396. if(encoderpos<1) encoderpos=1;
  1397. if(encoderpos>990) encoderpos=990;
  1398. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1399. }
  1400. }break;
  1401. case ItemCM_vmaxx:
  1402. case ItemCM_vmaxy:
  1403. case ItemCM_vmaxz:
  1404. case ItemCM_vmaxe:
  1405. {
  1406. if(force_lcd_update)
  1407. {
  1408. lcd.setCursor(0,line);lcdprintPGM(MSG_VMAX);
  1409. if(i==ItemCM_vmaxx)lcdprintPGM(MSG_X);
  1410. if(i==ItemCM_vmaxy)lcdprintPGM(MSG_Y);
  1411. if(i==ItemCM_vmaxz)lcdprintPGM(MSG_Z);
  1412. if(i==ItemCM_vmaxe)lcdprintPGM(MSG_E);
  1413. lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemCM_vmaxx]));
  1414. }
  1415. if((activeline!=line) )
  1416. break;
  1417. if(CLICKED)
  1418. {
  1419. linechanging=!linechanging;
  1420. if(linechanging)
  1421. {
  1422. encoderpos=(long)max_feedrate[i-ItemCM_vmaxx];
  1423. }
  1424. else
  1425. {
  1426. max_feedrate[i-ItemCM_vmaxx]= encoderpos;
  1427. encoderpos=activeline*lcdslow;
  1428. }
  1429. BLOCK;
  1430. beepshort();
  1431. }
  1432. if(linechanging)
  1433. {
  1434. if(encoderpos<1) encoderpos=1;
  1435. if(encoderpos>990) encoderpos=990;
  1436. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1437. }
  1438. }break;
  1439. case ItemCM_vmin:
  1440. {
  1441. if(force_lcd_update)
  1442. {
  1443. lcd.setCursor(0,line);lcdprintPGM(MSG_VMIN);
  1444. lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate));
  1445. }
  1446. if((activeline!=line) )
  1447. break;
  1448. if(CLICKED)
  1449. {
  1450. linechanging=!linechanging;
  1451. if(linechanging)
  1452. {
  1453. encoderpos=(long)(minimumfeedrate);
  1454. }
  1455. else
  1456. {
  1457. minimumfeedrate= encoderpos;
  1458. encoderpos=activeline*lcdslow;
  1459. }
  1460. BLOCK;
  1461. beepshort();
  1462. }
  1463. if(linechanging)
  1464. {
  1465. if(encoderpos<0) encoderpos=0;
  1466. if(encoderpos>990) encoderpos=990;
  1467. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1468. }
  1469. }break;
  1470. case ItemCM_vtravmin:
  1471. {
  1472. if(force_lcd_update)
  1473. {
  1474. lcd.setCursor(0,line);lcdprintPGM(MSG_VTRAV_MIN);
  1475. lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate));
  1476. }
  1477. if((activeline!=line) )
  1478. break;
  1479. if(CLICKED)
  1480. {
  1481. linechanging=!linechanging;
  1482. if(linechanging)
  1483. {
  1484. encoderpos=(long)mintravelfeedrate;
  1485. }
  1486. else
  1487. {
  1488. mintravelfeedrate= encoderpos;
  1489. encoderpos=activeline*lcdslow;
  1490. }
  1491. BLOCK;
  1492. beepshort();
  1493. }
  1494. if(linechanging)
  1495. {
  1496. if(encoderpos<0) encoderpos=0;
  1497. if(encoderpos>990) encoderpos=990;
  1498. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1499. }
  1500. }break;
  1501. case ItemCM_amaxx:
  1502. case ItemCM_amaxy:
  1503. case ItemCM_amaxz:
  1504. case ItemCM_amaxe:
  1505. {
  1506. if(force_lcd_update)
  1507. {
  1508. lcd.setCursor(0,line);lcdprintPGM(" Amax ");
  1509. if(i==ItemCM_amaxx)lcdprintPGM(MSG_X);
  1510. if(i==ItemCM_amaxy)lcdprintPGM(MSG_Y);
  1511. if(i==ItemCM_amaxz)lcdprintPGM(MSG_Z);
  1512. if(i==ItemCM_amaxe)lcdprintPGM(MSG_E);
  1513. lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100));lcdprintPGM("00");
  1514. }
  1515. if((activeline!=line) )
  1516. break;
  1517. if(CLICKED)
  1518. {
  1519. linechanging=!linechanging;
  1520. if(linechanging)
  1521. {
  1522. encoderpos=(long)max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100;
  1523. }
  1524. else
  1525. {
  1526. max_acceleration_units_per_sq_second[i-ItemCM_amaxx]= encoderpos*100;
  1527. encoderpos=activeline*lcdslow;
  1528. }
  1529. BLOCK;
  1530. beepshort();
  1531. }
  1532. if(linechanging)
  1533. {
  1534. if(encoderpos<1) encoderpos=1;
  1535. if(encoderpos>990) encoderpos=990;
  1536. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1537. }
  1538. }break;
  1539. case ItemCM_aret://float retract_acceleration = 7000;
  1540. {
  1541. if(force_lcd_update)
  1542. {
  1543. lcd.setCursor(0,line);lcdprintPGM(MSG_A_RETRACT);
  1544. lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcdprintPGM("00");
  1545. }
  1546. if((activeline!=line) )
  1547. break;
  1548. if(CLICKED)
  1549. {
  1550. linechanging=!linechanging;
  1551. if(linechanging)
  1552. {
  1553. encoderpos=(long)retract_acceleration/100;
  1554. }
  1555. else
  1556. {
  1557. retract_acceleration= encoderpos*100;
  1558. encoderpos=activeline*lcdslow;
  1559. }
  1560. BLOCK;
  1561. beepshort();
  1562. }
  1563. if(linechanging)
  1564. {
  1565. if(encoderpos<10) encoderpos=10;
  1566. if(encoderpos>990) encoderpos=990;
  1567. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1568. }
  1569. }break;
  1570. case ItemCM_xsteps://axis_steps_per_unit[i] = code_value();
  1571. {
  1572. if(force_lcd_update)
  1573. {
  1574. lcd.setCursor(0,line);lcdprintPGM(MSG_XSTEPS);
  1575. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[X_AXIS]));
  1576. }
  1577. if((activeline!=line) )
  1578. break;
  1579. if(CLICKED)
  1580. {
  1581. linechanging=!linechanging;
  1582. if(linechanging)
  1583. {
  1584. encoderpos=(long)(axis_steps_per_unit[X_AXIS]*100.0);
  1585. }
  1586. else
  1587. {
  1588. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[X_AXIS]);
  1589. position[X_AXIS]=lround(position[X_AXIS]*factor);
  1590. //current_position[X_AXIS]*=factor;
  1591. axis_steps_per_unit[X_AXIS]= encoderpos/100.0;
  1592. encoderpos=activeline*lcdslow;
  1593. }
  1594. BLOCK;
  1595. beepshort();
  1596. }
  1597. if(linechanging)
  1598. {
  1599. if(encoderpos<5) encoderpos=5;
  1600. if(encoderpos>999999) encoderpos=999999;
  1601. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1602. }
  1603. }break;
  1604. case ItemCM_ysteps://axis_steps_per_unit[i] = code_value();
  1605. {
  1606. if(force_lcd_update)
  1607. {
  1608. lcd.setCursor(0,line);lcdprintPGM(MSG_YSTEPS);
  1609. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[Y_AXIS]));
  1610. }
  1611. if((activeline!=line) )
  1612. break;
  1613. if(CLICKED)
  1614. {
  1615. linechanging=!linechanging;
  1616. if(linechanging)
  1617. {
  1618. encoderpos=(long)(axis_steps_per_unit[Y_AXIS]*100.0);
  1619. }
  1620. else
  1621. {
  1622. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[Y_AXIS]);
  1623. position[Y_AXIS]=lround(position[Y_AXIS]*factor);
  1624. //current_position[Y_AXIS]*=factor;
  1625. axis_steps_per_unit[Y_AXIS]= encoderpos/100.0;
  1626. encoderpos=activeline*lcdslow;
  1627. }
  1628. BLOCK;
  1629. beepshort();
  1630. }
  1631. if(linechanging)
  1632. {
  1633. if(encoderpos<5) encoderpos=5;
  1634. if(encoderpos>999999) encoderpos=999999;
  1635. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1636. }
  1637. }break;
  1638. case ItemCM_zsteps://axis_steps_per_unit[i] = code_value();
  1639. {
  1640. if(force_lcd_update)
  1641. {
  1642. lcd.setCursor(0,line);lcdprintPGM(MSG_ZSTEPS);
  1643. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[Z_AXIS]));
  1644. }
  1645. if((activeline!=line) )
  1646. break;
  1647. if(CLICKED)
  1648. {
  1649. linechanging=!linechanging;
  1650. if(linechanging)
  1651. {
  1652. encoderpos=(long)(axis_steps_per_unit[Z_AXIS]*100.0);
  1653. }
  1654. else
  1655. {
  1656. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[Z_AXIS]);
  1657. position[Z_AXIS]=lround(position[Z_AXIS]*factor);
  1658. //current_position[Z_AXIS]*=factor;
  1659. axis_steps_per_unit[Z_AXIS]= encoderpos/100.0;
  1660. encoderpos=activeline*lcdslow;
  1661. }
  1662. BLOCK;
  1663. beepshort();
  1664. }
  1665. if(linechanging)
  1666. {
  1667. if(encoderpos<5) encoderpos=5;
  1668. if(encoderpos>999999) encoderpos=999999;
  1669. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1670. }
  1671. }break;
  1672. case ItemCM_esteps://axis_steps_per_unit[i] = code_value();
  1673. {
  1674. if(force_lcd_update)
  1675. {
  1676. lcd.setCursor(0,line);lcdprintPGM(MSG_ESTEPS);
  1677. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[E_AXIS]));
  1678. }
  1679. if((activeline!=line) )
  1680. break;
  1681. if(CLICKED)
  1682. {
  1683. linechanging=!linechanging;
  1684. if(linechanging)
  1685. {
  1686. encoderpos=(long)(axis_steps_per_unit[E_AXIS]*100.0);
  1687. }
  1688. else
  1689. {
  1690. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[E_AXIS]);
  1691. position[E_AXIS]=lround(position[E_AXIS]*factor);
  1692. //current_position[E_AXIS]*=factor;
  1693. axis_steps_per_unit[E_AXIS]= encoderpos/100.0;
  1694. encoderpos=activeline*lcdslow;
  1695. }
  1696. BLOCK;
  1697. beepshort();
  1698. }
  1699. if(linechanging)
  1700. {
  1701. if(encoderpos<5) encoderpos=5;
  1702. if(encoderpos>999999) encoderpos=999999;
  1703. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1704. }
  1705. }break;
  1706. default:
  1707. break;
  1708. }
  1709. line++;
  1710. }
  1711. updateActiveLines(ItemCM_esteps,encoderpos);
  1712. }
  1713. enum {
  1714. ItemR_exit,
  1715. ItemR_autoretract,
  1716. ItemR_retract_length,ItemR_retract_feedrate,ItemR_retract_zlift,
  1717. ItemR_unretract_length,ItemR_unretract_feedrate,
  1718. };
  1719. void MainMenu::showControlRetract()
  1720. {
  1721. #ifdef FWRETRACT
  1722. uint8_t line=0;
  1723. clearIfNecessary();
  1724. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1725. {
  1726. switch(i)
  1727. {
  1728. case ItemR_exit:
  1729. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  1730. break;
  1731. //float retract_length=2, retract_feedrate=1200, retract_zlift=0.4;
  1732. //float retract_recover_length=0, retract_recover_feedrate=500;
  1733. case ItemR_autoretract:
  1734. {
  1735. if(force_lcd_update)
  1736. {
  1737. lcd.setCursor(0,line);lcdprintPGM(MSG_AUTORETRACT);
  1738. lcd.setCursor(13,line);
  1739. if(autoretract_enabled)
  1740. lcdprintPGM(MSG_ON);
  1741. else
  1742. lcdprintPGM(MSG_OFF);
  1743. }
  1744. if((activeline!=line) )
  1745. break;
  1746. if(CLICKED)
  1747. {
  1748. autoretract_enabled=!autoretract_enabled;
  1749. lcd.setCursor(13,line);
  1750. if(autoretract_enabled)
  1751. lcdprintPGM(MSG_ON);
  1752. else
  1753. lcdprintPGM(MSG_OFF);
  1754. BLOCK;
  1755. }
  1756. }break;
  1757. case ItemR_retract_length:
  1758. {
  1759. if(force_lcd_update)
  1760. {
  1761. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT);
  1762. lcd.setCursor(13,line);lcd.print(ftostr52(retract_length));
  1763. }
  1764. if((activeline!=line) )
  1765. break;
  1766. if(CLICKED)
  1767. {
  1768. linechanging=!linechanging;
  1769. if(linechanging)
  1770. {
  1771. encoderpos=(long)(retract_length*100);
  1772. }
  1773. else
  1774. {
  1775. retract_length= encoderpos/100.;
  1776. encoderpos=activeline*lcdslow;
  1777. }
  1778. BLOCK;
  1779. beepshort();
  1780. }
  1781. if(linechanging)
  1782. {
  1783. if(encoderpos<1) encoderpos=1;
  1784. if(encoderpos>990) encoderpos=990;
  1785. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.));
  1786. }
  1787. }break;
  1788. case ItemR_retract_feedrate:
  1789. {
  1790. if(force_lcd_update)
  1791. {
  1792. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACTF);
  1793. lcd.setCursor(13,line);lcd.print(itostr4(retract_feedrate));
  1794. }
  1795. if((activeline!=line) )
  1796. break;
  1797. if(CLICKED)
  1798. {
  1799. linechanging=!linechanging;
  1800. if(linechanging)
  1801. {
  1802. encoderpos=(long)(retract_feedrate/5);
  1803. }
  1804. else
  1805. {
  1806. retract_feedrate= encoderpos*5.;
  1807. encoderpos=activeline*lcdslow;
  1808. }
  1809. BLOCK;
  1810. beepshort();
  1811. }
  1812. if(linechanging)
  1813. {
  1814. if(encoderpos<1) encoderpos=1;
  1815. if(encoderpos>990) encoderpos=990;
  1816. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
  1817. }
  1818. }break;
  1819. case ItemR_retract_zlift://float retract_acceleration = 7000;
  1820. {
  1821. if(force_lcd_update)
  1822. {
  1823. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_ZLIFT);
  1824. lcd.setCursor(13,line);lcd.print(ftostr52(retract_zlift));;
  1825. }
  1826. if((activeline!=line) )
  1827. break;
  1828. if(CLICKED)
  1829. {
  1830. linechanging=!linechanging;
  1831. if(linechanging)
  1832. {
  1833. encoderpos=(long)(retract_zlift*10);
  1834. }
  1835. else
  1836. {
  1837. retract_zlift= encoderpos/10.;
  1838. encoderpos=activeline*lcdslow;
  1839. }
  1840. BLOCK;
  1841. beepshort();
  1842. }
  1843. if(linechanging)
  1844. {
  1845. if(encoderpos<0) encoderpos=0;
  1846. if(encoderpos>990) encoderpos=990;
  1847. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/10.));
  1848. }
  1849. }break;
  1850. case ItemR_unretract_length:
  1851. {
  1852. if(force_lcd_update)
  1853. {
  1854. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_RECOVER);
  1855. lcd.setCursor(13,line);lcd.print(ftostr52(retract_recover_length));;
  1856. }
  1857. if((activeline!=line) )
  1858. break;
  1859. if(CLICKED)
  1860. {
  1861. linechanging=!linechanging;
  1862. if(linechanging)
  1863. {
  1864. encoderpos=(long)(retract_recover_length*100);
  1865. }
  1866. else
  1867. {
  1868. retract_recover_length= encoderpos/100.;
  1869. encoderpos=activeline*lcdslow;
  1870. }
  1871. BLOCK;
  1872. beepshort();
  1873. }
  1874. if(linechanging)
  1875. {
  1876. if(encoderpos<0) encoderpos=0;
  1877. if(encoderpos>990) encoderpos=990;
  1878. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.));
  1879. }
  1880. }break;
  1881. case ItemR_unretract_feedrate:
  1882. {
  1883. if(force_lcd_update)
  1884. {
  1885. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_RECOVERF);
  1886. lcd.setCursor(13,line);lcd.print(itostr4(retract_recover_feedrate));
  1887. }
  1888. if((activeline!=line) )
  1889. break;
  1890. if(CLICKED)
  1891. {
  1892. linechanging=!linechanging;
  1893. if(linechanging)
  1894. {
  1895. encoderpos=(long)retract_recover_feedrate/5;
  1896. }
  1897. else
  1898. {
  1899. retract_recover_feedrate= encoderpos*5.;
  1900. encoderpos=activeline*lcdslow;
  1901. }
  1902. BLOCK;
  1903. beepshort();
  1904. }
  1905. if(linechanging)
  1906. {
  1907. if(encoderpos<1) encoderpos=1;
  1908. if(encoderpos>990) encoderpos=990;
  1909. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
  1910. }
  1911. }break;
  1912. default:
  1913. break;
  1914. }
  1915. line++;
  1916. }
  1917. updateActiveLines(ItemR_unretract_feedrate,encoderpos);
  1918. #endif
  1919. }
  1920. enum {
  1921. ItemC_exit,ItemC_temp,ItemC_move,
  1922. #ifdef FWRETRACT
  1923. ItemC_rectract,
  1924. #endif
  1925. ItemC_store, ItemC_load,ItemC_failsafe
  1926. };
  1927. void MainMenu::showControl()
  1928. {
  1929. uint8_t line=0;
  1930. clearIfNecessary();
  1931. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1932. {
  1933. switch(i)
  1934. {
  1935. case ItemC_exit:
  1936. MENUITEM( lcdprintPGM(MSG_MAIN_WIDE) , BLOCK;status=Main_Menu;beepshort(); ) ;
  1937. break;
  1938. case ItemC_temp:
  1939. MENUITEM( lcdprintPGM(MSG_TEMPERATURE_WIDE) , BLOCK;status=Sub_TempControl;beepshort(); ) ;
  1940. break;
  1941. case ItemC_move:
  1942. MENUITEM( lcdprintPGM(MSG_MOTION_WIDE) , BLOCK;status=Sub_MotionControl;beepshort(); ) ;
  1943. break;
  1944. #ifdef FWRETRACT
  1945. case ItemC_rectract:
  1946. MENUITEM( lcdprintPGM(MSG_RECTRACT_WIDE) , BLOCK;status=Sub_RetractControl;beepshort(); ) ;
  1947. break;
  1948. #endif
  1949. case ItemC_store:
  1950. {
  1951. if(force_lcd_update)
  1952. {
  1953. lcd.setCursor(0,line);lcdprintPGM(MSG_STORE_EPROM);
  1954. }
  1955. if((activeline==line) && CLICKED)
  1956. {
  1957. //enquecommand("M84");
  1958. beepshort();
  1959. BLOCK;
  1960. EEPROM_StoreSettings();
  1961. }
  1962. }break;
  1963. case ItemC_load:
  1964. {
  1965. if(force_lcd_update)
  1966. {
  1967. lcd.setCursor(0,line);lcdprintPGM(MSG_LOAD_EPROM);
  1968. }
  1969. if((activeline==line) && CLICKED)
  1970. {
  1971. //enquecommand("M84");
  1972. beepshort();
  1973. BLOCK;
  1974. EEPROM_RetrieveSettings();
  1975. }
  1976. }break;
  1977. case ItemC_failsafe:
  1978. {
  1979. if(force_lcd_update)
  1980. {
  1981. lcd.setCursor(0,line);lcdprintPGM(MSG_RESTORE_FAILSAFE);
  1982. }
  1983. if((activeline==line) && CLICKED)
  1984. {
  1985. //enquecommand("M84");
  1986. beepshort();
  1987. BLOCK;
  1988. EEPROM_RetrieveSettings(true);
  1989. }
  1990. }break;
  1991. default:
  1992. break;
  1993. }
  1994. line++;
  1995. }
  1996. updateActiveLines(ItemC_failsafe,encoderpos);
  1997. }
  1998. void MainMenu::showSD()
  1999. {
  2000. #ifdef SDSUPPORT
  2001. uint8_t line=0;
  2002. clearIfNecessary();
  2003. static uint8_t nrfiles=0;
  2004. if(force_lcd_update)
  2005. {
  2006. if(card.cardOK)
  2007. {
  2008. nrfiles=card.getnrfilenames();
  2009. }
  2010. else
  2011. {
  2012. nrfiles=0;
  2013. lineoffset=0;
  2014. }
  2015. }
  2016. bool enforceupdate=false;
  2017. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  2018. {
  2019. switch(i)
  2020. {
  2021. case 0:
  2022. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  2023. break;
  2024. // case 1:
  2025. // {
  2026. // if(force_lcd_update)
  2027. // {
  2028. // lcd.setCursor(0,line);
  2029. // #ifdef CARDINSERTED
  2030. // if(CARDINSERTED)
  2031. // #else
  2032. // if(true)
  2033. // #endif
  2034. // {
  2035. // lcdprintPGM(" \004Refresh");
  2036. // }
  2037. // else
  2038. // {
  2039. // lcdprintPGM(" \004Insert Card");
  2040. // }
  2041. //
  2042. // }
  2043. // if((activeline==line) && CLICKED)
  2044. // {
  2045. // BLOCK;
  2046. // beepshort();
  2047. // card.initsd();
  2048. // force_lcd_update=true;
  2049. // nrfiles=card.getnrfilenames();
  2050. // }
  2051. // }break;
  2052. case 1:
  2053. MENUITEM( lcd.print(" ");card.getWorkDirName();
  2054. if(card.filename[0]=='/') lcdprintPGM(MSG_REFRESH);
  2055. else {
  2056. lcd.print("\005");
  2057. lcd.print(card.filename);
  2058. lcd.print("/..");
  2059. } ,
  2060. BLOCK;
  2061. if(SDCARDDETECT == -1) card.initsd();
  2062. card.updir();
  2063. enforceupdate=true;
  2064. lineoffset=0;
  2065. beepshort(); ) ;
  2066. break;
  2067. default:
  2068. {
  2069. #define FIRSTITEM 2
  2070. if(i-FIRSTITEM<nrfiles)
  2071. {
  2072. if(force_lcd_update)
  2073. {
  2074. card.getfilename(i-FIRSTITEM);
  2075. //Serial.print("Filenr:");Serial.println(i-2);
  2076. lcd.setCursor(0,line);lcdprintPGM(" ");
  2077. if(card.filenameIsDir) lcd.print("\005");
  2078. lcd.print(card.filename);
  2079. }
  2080. if((activeline==line) && CLICKED)
  2081. {
  2082. BLOCK
  2083. card.getfilename(i-FIRSTITEM);
  2084. if(card.filenameIsDir)
  2085. {
  2086. for(int8_t i=0;i<strlen(card.filename);i++)
  2087. card.filename[i]=tolower(card.filename[i]);
  2088. card.chdir(card.filename);
  2089. lineoffset=0;
  2090. enforceupdate=true;
  2091. }
  2092. else
  2093. {
  2094. char cmd[30];
  2095. for(int8_t i=0;i<strlen(card.filename);i++)
  2096. card.filename[i]=tolower(card.filename[i]);
  2097. sprintf(cmd,"M23 %s",card.filename);
  2098. //sprintf(cmd,"M115");
  2099. enquecommand(cmd);
  2100. enquecommand("M24");
  2101. beep();
  2102. status=Main_Status;
  2103. lcd_status(card.filename);
  2104. }
  2105. }
  2106. }
  2107. }
  2108. break;
  2109. }
  2110. line++;
  2111. }
  2112. updateActiveLines(FIRSTITEM+nrfiles-1,encoderpos);
  2113. if(enforceupdate)
  2114. {
  2115. force_lcd_update=true;
  2116. enforceupdate=false;
  2117. }
  2118. #endif
  2119. }
  2120. enum {ItemM_watch, ItemM_prepare, ItemM_control, ItemM_file, ItemM_pause};
  2121. void MainMenu::showMainMenu()
  2122. {
  2123. #ifndef ULTIPANEL
  2124. force_lcd_update=false;
  2125. #endif
  2126. if(tune)
  2127. {
  2128. if(!(movesplanned() || IS_SD_PRINTING))
  2129. {
  2130. force_lcd_update=true;
  2131. tune=false;
  2132. }
  2133. }
  2134. else
  2135. {
  2136. if(movesplanned() || IS_SD_PRINTING)
  2137. {
  2138. force_lcd_update=true;
  2139. tune=true;
  2140. }
  2141. }
  2142. clearIfNecessary();
  2143. uint8_t line=0;
  2144. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  2145. {
  2146. switch(i)
  2147. {
  2148. case ItemM_watch:
  2149. MENUITEM( lcdprintPGM(MSG_WATCH) , BLOCK;status=Main_Status;beepshort(); ) ;
  2150. break;
  2151. case ItemM_prepare:
  2152. MENUITEM( if(!tune) lcdprintPGM(MSG_PREPARE);else lcdprintPGM(MSG_TUNE); , BLOCK;status=Main_Prepare;beepshort(); ) ;
  2153. break;
  2154. case ItemM_control:
  2155. MENUITEM( lcdprintPGM(MSG_CONTROL_ARROW) , BLOCK;status=Main_Control;beepshort(); ) ;
  2156. break;
  2157. #ifdef SDSUPPORT
  2158. case ItemM_file:
  2159. {
  2160. if(force_lcd_update)
  2161. {
  2162. lcd.setCursor(0,line);
  2163. #ifdef CARDINSERTED
  2164. if(CARDINSERTED)
  2165. #else
  2166. if(true)
  2167. #endif
  2168. {
  2169. if(card.sdprinting)
  2170. lcdprintPGM(MSG_STOP_PRINT);
  2171. else
  2172. lcdprintPGM(MSG_CARD_MENU);
  2173. }
  2174. else
  2175. {
  2176. lcdprintPGM(MSG_NO_CARD);
  2177. }
  2178. }
  2179. #ifdef CARDINSERTED
  2180. if(CARDINSERTED)
  2181. #endif
  2182. if((activeline==line)&&CLICKED)
  2183. {
  2184. card.printingHasFinished();
  2185. BLOCK;
  2186. status=Main_SD;
  2187. beepshort();
  2188. }
  2189. }break;
  2190. case ItemM_pause:
  2191. {
  2192. if(force_lcd_update)
  2193. {
  2194. lcd.setCursor(0,line);
  2195. #ifdef CARDINSERTED
  2196. if(CARDINSERTED)
  2197. #else
  2198. if(true)
  2199. #endif
  2200. {
  2201. if(card.sdprinting)
  2202. lcdprintPGM(MSG_PAUSE_PRINT);
  2203. else
  2204. lcdprintPGM(MSG_RESUME_PRINT);
  2205. }
  2206. else
  2207. {
  2208. //lcdprintPGM(MSG_NO_CARD);
  2209. }
  2210. }
  2211. #ifdef CARDINSERTED
  2212. if(CARDINSERTED)
  2213. #endif
  2214. if((activeline==line) && CLICKED)
  2215. {
  2216. if(card.sdprinting)
  2217. {
  2218. card.pauseSDPrint();
  2219. beepshort();
  2220. status = Main_Status;
  2221. }
  2222. else
  2223. {
  2224. card.startFileprint();
  2225. starttime=millis();
  2226. beepshort();
  2227. status = Main_Status;
  2228. }
  2229. }
  2230. }break;
  2231. #else
  2232. case ItemM_file:
  2233. break;
  2234. case ItemM_pause:
  2235. break;
  2236. #endif
  2237. default:
  2238. SERIAL_ERROR_START;
  2239. SERIAL_ERRORLNPGM(MSG_SERIAL_ERROR_MENU_STRUCTURE);
  2240. break;
  2241. }
  2242. line++;
  2243. }
  2244. uint8_t numberOfLines = 4;
  2245. #ifdef SDSUPPORT
  2246. numberOfLines = 4;
  2247. #else
  2248. numberOfLines = 3;
  2249. #endif
  2250. updateActiveLines(numberOfLines,encoderpos);
  2251. }
  2252. void MainMenu::update()
  2253. {
  2254. static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
  2255. static long timeoutToStatus=0;
  2256. static bool oldcardstatus=false;
  2257. #ifdef CARDINSERTED
  2258. if((CARDINSERTED != oldcardstatus))
  2259. {
  2260. force_lcd_update=true;
  2261. oldcardstatus=CARDINSERTED;
  2262. lcd_init(); // to maybe revive the lcd if static electricty killed it.
  2263. //Serial.println("echo: SD CHANGE");
  2264. if(CARDINSERTED)
  2265. {
  2266. card.initsd();
  2267. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  2268. }
  2269. else
  2270. {
  2271. card.release();
  2272. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  2273. }
  2274. }
  2275. #endif
  2276. if(status!=oldstatus)
  2277. {
  2278. force_lcd_update=true;
  2279. encoderpos=0;
  2280. lineoffset=0;
  2281. oldstatus=status;
  2282. }
  2283. if( (encoderpos!=lastencoderpos) || CLICKED)
  2284. timeoutToStatus=millis()+STATUSTIMEOUT;
  2285. switch(status)
  2286. {
  2287. case Main_Status:
  2288. {
  2289. showStatus();
  2290. if(CLICKED)
  2291. {
  2292. linechanging=false;
  2293. BLOCK
  2294. status=Main_Menu;
  2295. timeoutToStatus=millis()+STATUSTIMEOUT;
  2296. }
  2297. }break;
  2298. case Main_Menu:
  2299. {
  2300. showMainMenu();
  2301. linechanging=false;
  2302. }break;
  2303. case Main_Prepare:
  2304. {
  2305. if(tune)
  2306. {
  2307. showTune();
  2308. }
  2309. else
  2310. {
  2311. showPrepare();
  2312. }
  2313. }break;
  2314. case Sub_PrepareMove:
  2315. {
  2316. showAxisMove();
  2317. }break;
  2318. case Main_Control:
  2319. {
  2320. showControl();
  2321. }break;
  2322. case Sub_MotionControl:
  2323. {
  2324. showControlMotion();
  2325. }break;
  2326. case Sub_RetractControl:
  2327. {
  2328. showControlRetract();
  2329. }break;
  2330. case Sub_TempControl:
  2331. {
  2332. showControlTemp();
  2333. }break;
  2334. case Main_SD:
  2335. {
  2336. showSD();
  2337. }break;
  2338. }
  2339. if(timeoutToStatus<millis())
  2340. status=Main_Status;
  2341. //force_lcd_update=false;
  2342. lastencoderpos=encoderpos;
  2343. }
  2344. // convert float to string with +123.4 format
  2345. char *ftostr3(const float &x)
  2346. {
  2347. //sprintf(conv,"%5.1f",x);
  2348. int xx=x;
  2349. conv[0]=(xx/100)%10+'0';
  2350. conv[1]=(xx/10)%10+'0';
  2351. conv[2]=(xx)%10+'0';
  2352. conv[3]=0;
  2353. return conv;
  2354. }
  2355. char *itostr2(const uint8_t &x)
  2356. {
  2357. //sprintf(conv,"%5.1f",x);
  2358. int xx=x;
  2359. conv[0]=(xx/10)%10+'0';
  2360. conv[1]=(xx)%10+'0';
  2361. conv[2]=0;
  2362. return conv;
  2363. }
  2364. // convert float to string with +123.4 format
  2365. char *ftostr31(const float &x)
  2366. {
  2367. int xx=x*10;
  2368. conv[0]=(xx>=0)?'+':'-';
  2369. xx=abs(xx);
  2370. conv[1]=(xx/1000)%10+'0';
  2371. conv[2]=(xx/100)%10+'0';
  2372. conv[3]=(xx/10)%10+'0';
  2373. conv[4]='.';
  2374. conv[5]=(xx)%10+'0';
  2375. conv[6]=0;
  2376. return conv;
  2377. }
  2378. char *ftostr32(const float &x)
  2379. {
  2380. int xx=x*100;
  2381. conv[0]=(xx>=0)?'+':'-';
  2382. xx=abs(xx);
  2383. conv[1]=(xx/100)%10+'0';
  2384. conv[2]='.';
  2385. conv[3]=(xx/10)%10+'0';
  2386. conv[4]=(xx)%10+'0';
  2387. conv[6]=0;
  2388. return conv;
  2389. }
  2390. char *itostr31(const int &xx)
  2391. {
  2392. conv[0]=(xx>=0)?'+':'-';
  2393. conv[1]=(xx/1000)%10+'0';
  2394. conv[2]=(xx/100)%10+'0';
  2395. conv[3]=(xx/10)%10+'0';
  2396. conv[4]='.';
  2397. conv[5]=(xx)%10+'0';
  2398. conv[6]=0;
  2399. return conv;
  2400. }
  2401. char *itostr3(const int &xx)
  2402. {
  2403. conv[0]=(xx/100)%10+'0';
  2404. conv[1]=(xx/10)%10+'0';
  2405. conv[2]=(xx)%10+'0';
  2406. conv[3]=0;
  2407. return conv;
  2408. }
  2409. char *itostr4(const int &xx)
  2410. {
  2411. conv[0]=(xx/1000)%10+'0';
  2412. conv[1]=(xx/100)%10+'0';
  2413. conv[2]=(xx/10)%10+'0';
  2414. conv[3]=(xx)%10+'0';
  2415. conv[4]=0;
  2416. return conv;
  2417. }
  2418. // convert float to string with +1234.5 format
  2419. char *ftostr51(const float &x)
  2420. {
  2421. int xx=x*10;
  2422. conv[0]=(xx>=0)?'+':'-';
  2423. xx=abs(xx);
  2424. conv[1]=(xx/10000)%10+'0';
  2425. conv[2]=(xx/1000)%10+'0';
  2426. conv[3]=(xx/100)%10+'0';
  2427. conv[4]=(xx/10)%10+'0';
  2428. conv[5]='.';
  2429. conv[6]=(xx)%10+'0';
  2430. conv[7]=0;
  2431. return conv;
  2432. }
  2433. // convert float to string with +123.45 format
  2434. char *ftostr52(const float &x)
  2435. {
  2436. int xx=x*100;
  2437. conv[0]=(xx>=0)?'+':'-';
  2438. xx=abs(xx);
  2439. conv[1]=(xx/10000)%10+'0';
  2440. conv[2]=(xx/1000)%10+'0';
  2441. conv[3]=(xx/100)%10+'0';
  2442. conv[4]='.';
  2443. conv[5]=(xx/10)%10+'0';
  2444. conv[6]=(xx)%10+'0';
  2445. conv[7]=0;
  2446. return conv;
  2447. }
  2448. #endif //ULTRA_LCD