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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986
  1. #include "ultralcd.h"
  2. #ifdef ULTRA_LCD
  3. #include "Marlin.h"
  4. #include <LiquidCrystal.h>
  5. //===========================================================================
  6. //=============================imported variables============================
  7. //===========================================================================
  8. extern volatile int feedmultiply;
  9. extern volatile bool feedmultiplychanged;
  10. extern long position[4];
  11. extern CardReader card;
  12. //===========================================================================
  13. //=============================public variables============================
  14. //===========================================================================
  15. volatile char buttons=0; //the last checked buttons in a bit array.
  16. int encoderpos=0;
  17. short lastenc=0;
  18. //===========================================================================
  19. //=============================private variables============================
  20. //===========================================================================
  21. static char messagetext[LCD_WIDTH]="";
  22. //return for string conversion routines
  23. static char conv[8];
  24. 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
  25. static unsigned long previous_millis_lcd=0;
  26. //static long previous_millis_buttons=0;
  27. #ifdef NEWPANEL
  28. static long blocking=0;
  29. #else
  30. static long blocking[8]={0,0,0,0,0,0,0,0};
  31. #endif
  32. static MainMenu menu;
  33. void lcdProgMemprint(const char *str)
  34. {
  35. char ch=pgm_read_byte(str);
  36. while(ch)
  37. {
  38. lcd.print(ch);
  39. ch=pgm_read_byte(++str);
  40. }
  41. }
  42. #define lcdprintPGM(x) lcdProgMemprint(MYPGM(x))
  43. //===========================================================================
  44. //=============================functions ============================
  45. //===========================================================================
  46. FORCE_INLINE int intround(const float &x){return int(0.5+x);}
  47. void lcd_status(const char* message)
  48. {
  49. strncpy(messagetext,message,LCD_WIDTH);
  50. messagetext[strlen(message)]=0;
  51. }
  52. void lcd_statuspgm(const char* message)
  53. {
  54. char ch=pgm_read_byte(message);
  55. char *target=messagetext;
  56. uint8_t cnt=0;
  57. while(ch &&cnt<LCD_WIDTH)
  58. {
  59. *target=ch;
  60. target++;
  61. cnt++;
  62. ch=pgm_read_byte(++message);
  63. }
  64. *target=0;
  65. }
  66. FORCE_INLINE void clear()
  67. {
  68. lcd.clear();
  69. }
  70. void lcd_init()
  71. {
  72. //beep();
  73. byte Degree[8] =
  74. {
  75. B01100,
  76. B10010,
  77. B10010,
  78. B01100,
  79. B00000,
  80. B00000,
  81. B00000,
  82. B00000
  83. };
  84. byte Thermometer[8] =
  85. {
  86. B00100,
  87. B01010,
  88. B01010,
  89. B01010,
  90. B01010,
  91. B10001,
  92. B10001,
  93. B01110
  94. };
  95. byte uplevel[8]={0x04, 0x0e, 0x1f, 0x04, 0x1c, 0x00, 0x00, 0x00};//thanks joris
  96. byte refresh[8]={0x00, 0x06, 0x19, 0x18, 0x03, 0x13, 0x0c, 0x00}; //thanks joris
  97. byte folder [8]={0x00, 0x1c, 0x1f, 0x11, 0x11, 0x1f, 0x00, 0x00}; //thanks joris
  98. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  99. lcd.createChar(1,Degree);
  100. lcd.createChar(2,Thermometer);
  101. lcd.createChar(3,uplevel);
  102. lcd.createChar(4,refresh);
  103. lcd.createChar(5,folder);
  104. LCD_MESSAGEPGM("UltiMarlin ready.");
  105. }
  106. void beep()
  107. {
  108. //return;
  109. #ifdef ULTIPANEL
  110. #if (BEEPER > -1)
  111. {
  112. pinMode(BEEPER,OUTPUT);
  113. for(int8_t i=0;i<20;i++){
  114. WRITE(BEEPER,HIGH);
  115. delay(5);
  116. WRITE(BEEPER,LOW);
  117. delay(5);
  118. }
  119. }
  120. #endif
  121. #endif
  122. }
  123. void beepshort()
  124. {
  125. //return;
  126. #ifdef ULTIPANEL
  127. #if (BEEPER > -1)
  128. {
  129. pinMode(BEEPER,OUTPUT);
  130. for(int8_t i=0;i<10;i++){
  131. WRITE(BEEPER,HIGH);
  132. delay(3);
  133. WRITE(BEEPER,LOW);
  134. delay(3);
  135. }
  136. }
  137. #endif
  138. #endif
  139. }
  140. void lcd_status()
  141. {
  142. #ifdef ULTIPANEL
  143. static uint8_t oldbuttons=0;
  144. //static long previous_millis_buttons=0;
  145. //static long previous_lcdinit=0;
  146. // buttons_check(); // Done in temperature interrupt
  147. //previous_millis_buttons=millis();
  148. long ms=millis();
  149. for(int8_t i=0; i<8; i++) {
  150. #ifndef NEWPANEL
  151. if((blocking[i]>ms))
  152. buttons &= ~(1<<i);
  153. #else
  154. if((blocking>ms))
  155. buttons &= ~(1<<i);
  156. #endif
  157. }
  158. if((buttons==oldbuttons) && ((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
  159. return;
  160. oldbuttons=buttons;
  161. #else
  162. if(((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
  163. return;
  164. #endif
  165. previous_millis_lcd=millis();
  166. menu.update();
  167. }
  168. #ifdef ULTIPANEL
  169. void buttons_init()
  170. {
  171. #ifdef NEWPANEL
  172. pinMode(BTN_EN1,INPUT);
  173. pinMode(BTN_EN2,INPUT);
  174. pinMode(BTN_ENC,INPUT);
  175. pinMode(SDCARDDETECT,INPUT);
  176. WRITE(BTN_EN1,HIGH);
  177. WRITE(BTN_EN2,HIGH);
  178. WRITE(BTN_ENC,HIGH);
  179. #if (SDCARDDETECT > -1)
  180. {
  181. WRITE(SDCARDDETECT,HIGH);
  182. }
  183. #endif
  184. #else
  185. pinMode(SHIFT_CLK,OUTPUT);
  186. pinMode(SHIFT_LD,OUTPUT);
  187. pinMode(SHIFT_EN,OUTPUT);
  188. pinMode(SHIFT_OUT,INPUT);
  189. WRITE(SHIFT_OUT,HIGH);
  190. WRITE(SHIFT_LD,HIGH);
  191. WRITE(SHIFT_EN,LOW);
  192. #endif
  193. }
  194. void buttons_check()
  195. {
  196. #ifdef NEWPANEL
  197. uint8_t newbutton=0;
  198. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  199. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  200. if((blocking<millis()) &&(READ(BTN_ENC)==0))
  201. newbutton|=EN_C;
  202. buttons=newbutton;
  203. #else //read it from the shift register
  204. uint8_t newbutton=0;
  205. WRITE(SHIFT_LD,LOW);
  206. WRITE(SHIFT_LD,HIGH);
  207. unsigned char tmp_buttons=0;
  208. for(int8_t i=0;i<8;i++)
  209. {
  210. newbutton = newbutton>>1;
  211. if(READ(SHIFT_OUT))
  212. newbutton|=(1<<7);
  213. WRITE(SHIFT_CLK,HIGH);
  214. WRITE(SHIFT_CLK,LOW);
  215. }
  216. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  217. #endif
  218. //manage encoder rotation
  219. char enc=0;
  220. if(buttons&EN_A)
  221. enc|=(1<<0);
  222. if(buttons&EN_B)
  223. enc|=(1<<1);
  224. if(enc!=lastenc)
  225. {
  226. switch(enc)
  227. {
  228. case encrot0:
  229. if(lastenc==encrot3)
  230. encoderpos++;
  231. else if(lastenc==encrot1)
  232. encoderpos--;
  233. break;
  234. case encrot1:
  235. if(lastenc==encrot0)
  236. encoderpos++;
  237. else if(lastenc==encrot2)
  238. encoderpos--;
  239. break;
  240. case encrot2:
  241. if(lastenc==encrot1)
  242. encoderpos++;
  243. else if(lastenc==encrot3)
  244. encoderpos--;
  245. break;
  246. case encrot3:
  247. if(lastenc==encrot2)
  248. encoderpos++;
  249. else if(lastenc==encrot0)
  250. encoderpos--;
  251. break;
  252. default:
  253. ;
  254. }
  255. }
  256. lastenc=enc;
  257. }
  258. #endif
  259. MainMenu::MainMenu()
  260. {
  261. status=Main_Status;
  262. displayStartingRow=0;
  263. activeline=0;
  264. force_lcd_update=true;
  265. #ifdef ULTIPANEL
  266. buttons_init();
  267. #endif
  268. lcd_init();
  269. linechanging=false;
  270. tune=false;
  271. }
  272. void MainMenu::showStatus()
  273. {
  274. #if LCD_HEIGHT==4
  275. static int olddegHotEnd0=-1;
  276. static int oldtargetHotEnd0=-1;
  277. //force_lcd_update=true;
  278. if(force_lcd_update||feedmultiplychanged) //initial display of content
  279. {
  280. feedmultiplychanged=false;
  281. encoderpos=feedmultiply;
  282. clear();
  283. lcd.setCursor(0,0);lcdprintPGM("\002123/567\001 ");
  284. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  285. lcd.setCursor(10,0);lcdprintPGM("B123/567\001 ");
  286. #endif
  287. }
  288. int tHotEnd0=intround(degHotend0());
  289. if((abs(tHotEnd0-olddegHotEnd0)>1)||force_lcd_update) //>1 because otherwise the lcd is refreshed to often.
  290. {
  291. lcd.setCursor(1,0);
  292. lcd.print(ftostr3(tHotEnd0));
  293. olddegHotEnd0=tHotEnd0;
  294. }
  295. int ttHotEnd0=intround(degTargetHotend0());
  296. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  297. {
  298. lcd.setCursor(5,0);
  299. lcd.print(ftostr3(ttHotEnd0));
  300. oldtargetHotEnd0=ttHotEnd0;
  301. }
  302. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  303. static int oldtBed=-1;
  304. static int oldtargetBed=-1;
  305. int tBed=intround(degBed());
  306. if((tBed!=oldtBed)||force_lcd_update)
  307. {
  308. lcd.setCursor(11,0);
  309. lcd.print(ftostr3(tBed));
  310. oldtBed=tBed;
  311. }
  312. int targetBed=intround(degTargetBed());
  313. if((targetBed!=oldtargetBed)||force_lcd_update)
  314. {
  315. lcd.setCursor(15,0);
  316. lcd.print(ftostr3(targetBed));
  317. oldtargetBed=targetBed;
  318. }
  319. #endif
  320. //starttime=2;
  321. static uint16_t oldtime=0;
  322. if(starttime!=0)
  323. {
  324. lcd.setCursor(0,1);
  325. uint16_t time=millis()/60000-starttime/60000;
  326. if(starttime!=oldtime)
  327. {
  328. lcd.print(itostr2(time/60));lcdprintPGM("h ");lcd.print(itostr2(time%60));lcdprintPGM("m");
  329. oldtime=time;
  330. }
  331. }
  332. static int oldzpos=0;
  333. int currentz=current_position[2]*100;
  334. if((currentz!=oldzpos)||force_lcd_update)
  335. {
  336. lcd.setCursor(10,1);
  337. lcdprintPGM("Z:");lcd.print(ftostr32(current_position[2]));
  338. oldzpos=currentz;
  339. }
  340. static int oldfeedmultiply=0;
  341. int curfeedmultiply=feedmultiply;
  342. if(encoderpos!=curfeedmultiply||force_lcd_update)
  343. {
  344. curfeedmultiply=encoderpos;
  345. if(curfeedmultiply<10)
  346. curfeedmultiply=10;
  347. if(curfeedmultiply>999)
  348. curfeedmultiply=999;
  349. feedmultiply=curfeedmultiply;
  350. encoderpos=curfeedmultiply;
  351. }
  352. if((curfeedmultiply!=oldfeedmultiply)||force_lcd_update)
  353. {
  354. oldfeedmultiply=curfeedmultiply;
  355. lcd.setCursor(0,2);
  356. lcd.print(itostr3(curfeedmultiply));lcdprintPGM("% ");
  357. }
  358. if(messagetext[0]!='\0')
  359. {
  360. lcd.setCursor(0,LCD_HEIGHT-1);
  361. lcd.print(messagetext);
  362. uint8_t n=strlen(messagetext);
  363. for(int8_t i=0;i<LCD_WIDTH-n;i++)
  364. lcd.print(" ");
  365. messagetext[0]='\0';
  366. }
  367. static uint8_t oldpercent=101;
  368. uint8_t percent=card.percentDone();
  369. if(oldpercent!=percent ||force_lcd_update)
  370. {
  371. lcd.setCursor(7,2);
  372. lcd.print(itostr3((int)percent));
  373. lcdprintPGM("%SD");
  374. }
  375. #else //smaller LCDS----------------------------------
  376. static int olddegHotEnd0=-1;
  377. static int oldtargetHotEnd0=-1;
  378. if(force_lcd_update) //initial display of content
  379. {
  380. encoderpos=feedmultiply;
  381. lcd.setCursor(0,0);lcdprintPGM("\002123/567\001 ");
  382. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  383. lcd.setCursor(10,0);lcdprintPGM("B123/567\001 ");
  384. #endif
  385. }
  386. int tHotEnd0=intround(degHotend0());
  387. int ttHotEnd0=intround(degTargetHotend0());
  388. if((abs(tHotEnd0-olddegHotEnd0)>1)||force_lcd_update)
  389. {
  390. lcd.setCursor(1,0);
  391. lcd.print(ftostr3(tHotEnd0));
  392. olddegHotEnd0=tHotEnd0;
  393. }
  394. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  395. {
  396. lcd.setCursor(5,0);
  397. lcd.print(ftostr3(ttHotEnd0));
  398. oldtargetHotEnd0=ttHotEnd0;
  399. }
  400. if(messagetext[0]!='\0')
  401. {
  402. lcd.setCursor(0,LCD_HEIGHT-1);
  403. lcd.print(messagetext);
  404. uint8_t n=strlen(messagetext);
  405. for(int8_t i=0;i<LCD_WIDTH-n;i++)
  406. lcd.print(" ");
  407. messagetext[0]='\0';
  408. }
  409. #endif
  410. force_lcd_update=false;
  411. }
  412. enum {ItemP_exit, ItemP_autostart,ItemP_disstep,ItemP_home, ItemP_origin, ItemP_preheat, ItemP_cooldown,/*ItemP_extrude,*/ItemP_move};
  413. //any action must not contain a ',' character anywhere, or this breaks:
  414. #define MENUITEM(repaint_action, click_action) \
  415. {\
  416. if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  417. if((activeline==line) && CLICKED) {click_action} \
  418. }
  419. void MainMenu::showPrepare()
  420. {
  421. uint8_t line=0;
  422. clearIfNecessary();
  423. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  424. {
  425. //Serial.println((int)(line-lineoffset));
  426. switch(i)
  427. {
  428. case ItemP_exit:
  429. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  430. break;
  431. case ItemP_autostart:
  432. MENUITEM( lcdprintPGM(" Autostart") , BLOCK;card.lastnr=0;card.setroot();card.checkautostart(true);beepshort(); ) ;
  433. break;
  434. case ItemP_disstep:
  435. MENUITEM( lcdprintPGM(" Disable Steppers") , BLOCK;enquecommand("M84");beepshort(); ) ;
  436. break;
  437. case ItemP_home:
  438. MENUITEM( lcdprintPGM(" Auto Home") , BLOCK;enquecommand("G28 X-105 Y-105 Z0");beepshort(); ) ;
  439. break;
  440. case ItemP_origin:
  441. MENUITEM( lcdprintPGM(" Set Origin") , BLOCK;enquecommand("G92 X0 Y0 Z0");beepshort(); ) ;
  442. break;
  443. case ItemP_preheat:
  444. MENUITEM( lcdprintPGM(" Preheat") , BLOCK;setTargetHotend0(170);setTargetBed(70);beepshort(); ) ;
  445. break;
  446. case ItemP_cooldown:
  447. MENUITEM( lcdprintPGM(" Cooldown") , BLOCK;setTargetHotend0(0);setTargetBed(0);beepshort(); ) ;
  448. break;
  449. // case ItemP_extrude:
  450. // MENUITEM( lcdprintPGM(" Extrude") , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E50");beepshort(); ) ;
  451. // break;
  452. case ItemP_move:
  453. MENUITEM( lcdprintPGM(" Move Axis \x7E") , BLOCK;status=Sub_PrepareMove;beepshort(); );
  454. break;
  455. default:
  456. break;
  457. }
  458. line++;
  459. }
  460. updateActiveLines(ItemP_move,encoderpos);
  461. }
  462. enum {
  463. ItemAM_exit,
  464. ItemAM_X, ItemAM_Y, ItemAM_Z, ItemAM_E
  465. };
  466. void MainMenu::showAxisMove()
  467. {
  468. uint8_t line=0;
  469. clearIfNecessary();
  470. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  471. {
  472. switch(i)
  473. {
  474. case ItemAM_exit:
  475. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  476. break;
  477. case ItemAM_X:
  478. MENUITEM( lcdprintPGM(" X+") , BLOCK;enquecommand("G92 X0");enquecommand("G1 F700 X10");beepshort(); ) ;
  479. break;
  480. case ItemAM_Y:
  481. MENUITEM( lcdprintPGM(" Y+") , BLOCK;enquecommand("G92 Y0");enquecommand("G1 F700 Y10");beepshort(); ) ;
  482. break;
  483. case ItemAM_Z:
  484. MENUITEM( lcdprintPGM(" Z+") , BLOCK;enquecommand("G92 Z0");enquecommand("G1 F700 Z10");beepshort(); ) ;
  485. break;
  486. case ItemAM_E:
  487. MENUITEM( lcdprintPGM(" Extrude") , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E50");beepshort(); ) ;
  488. break;
  489. default:
  490. break;
  491. }
  492. line++;
  493. }
  494. updateActiveLines(ItemAM_Z,encoderpos);
  495. }
  496. enum {ItemT_exit,ItemT_speed,ItemT_flow,ItemT_nozzle,
  497. #if (HEATER_BED_PIN > -1)
  498. ItemT_bed,
  499. #endif
  500. ItemT_fan};
  501. void MainMenu::showTune()
  502. {
  503. uint8_t line=0;
  504. clearIfNecessary();
  505. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  506. {
  507. //Serial.println((int)(line-lineoffset));
  508. switch(i)
  509. {
  510. case ItemT_exit:
  511. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  512. break;
  513. case ItemT_speed:
  514. {
  515. if(force_lcd_update)
  516. {
  517. lcd.setCursor(0,line);lcdprintPGM(" Speed:");
  518. lcd.setCursor(13,line);lcd.print(ftostr3(feedmultiply));
  519. }
  520. if((activeline!=line) )
  521. break;
  522. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  523. {
  524. linechanging=!linechanging;
  525. if(linechanging)
  526. {
  527. encoderpos=feedmultiply;
  528. }
  529. else
  530. {
  531. encoderpos=activeline*lcdslow;
  532. beepshort();
  533. }
  534. BLOCK;
  535. }
  536. if(linechanging)
  537. {
  538. if(encoderpos<1) encoderpos=1;
  539. if(encoderpos>400) encoderpos=400;
  540. feedmultiply = encoderpos;
  541. feedmultiplychanged=true;
  542. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  543. }
  544. }break;
  545. case ItemT_nozzle:
  546. {
  547. if(force_lcd_update)
  548. {
  549. lcd.setCursor(0,line);lcdprintPGM(" \002Nozzle:");
  550. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  551. }
  552. if((activeline!=line) )
  553. break;
  554. if(CLICKED)
  555. {
  556. linechanging=!linechanging;
  557. if(linechanging)
  558. {
  559. encoderpos=intround(degTargetHotend0());
  560. }
  561. else
  562. {
  563. setTargetHotend0(encoderpos);
  564. encoderpos=activeline*lcdslow;
  565. beepshort();
  566. }
  567. BLOCK;
  568. }
  569. if(linechanging)
  570. {
  571. if(encoderpos<0) encoderpos=0;
  572. if(encoderpos>260) encoderpos=260;
  573. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  574. }
  575. }break;
  576. #if (HEATER_BED_PIN > -1)
  577. case ItemT_bed:
  578. {
  579. if(force_lcd_update)
  580. {
  581. lcd.setCursor(0,line);lcdprintPGM(" \002Bed:");
  582. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  583. }
  584. if((activeline!=line) )
  585. break;
  586. if(CLICKED)
  587. {
  588. linechanging=!linechanging;
  589. if(linechanging)
  590. {
  591. encoderpos=intround(degTargetBed());
  592. }
  593. else
  594. {
  595. setTargetBed(encoderpos);
  596. encoderpos=activeline*lcdslow;
  597. beepshort();
  598. }
  599. BLOCK;
  600. }
  601. if(linechanging)
  602. {
  603. if(encoderpos<0) encoderpos=0;
  604. if(encoderpos>260) encoderpos=260;
  605. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  606. }
  607. }break;
  608. #endif
  609. case ItemT_fan:
  610. {
  611. if(force_lcd_update)
  612. {
  613. lcd.setCursor(0,line);lcdprintPGM(" Fan speed:");
  614. lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
  615. }
  616. if((activeline!=line) )
  617. break;
  618. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  619. {
  620. linechanging=!linechanging;
  621. if(linechanging)
  622. {
  623. encoderpos=fanpwm;
  624. }
  625. else
  626. {
  627. encoderpos=activeline*lcdslow;
  628. beepshort();
  629. }
  630. BLOCK;
  631. }
  632. if(linechanging)
  633. {
  634. if(encoderpos<0) encoderpos=0;
  635. if(encoderpos>255) encoderpos=255;
  636. fanpwm=encoderpos;
  637. analogWrite(FAN_PIN, fanpwm);
  638. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  639. }
  640. }break;
  641. case ItemT_flow://axis_steps_per_unit[i] = code_value();
  642. {
  643. if(force_lcd_update)
  644. {
  645. lcd.setCursor(0,line);lcdprintPGM(" Flow:");
  646. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3]));
  647. }
  648. if((activeline!=line) )
  649. break;
  650. if(CLICKED)
  651. {
  652. linechanging=!linechanging;
  653. if(linechanging)
  654. {
  655. encoderpos=(int)axis_steps_per_unit[3];
  656. }
  657. else
  658. {
  659. float factor=float(encoderpos)/float(axis_steps_per_unit[3]);
  660. position[E_AXIS]=lround(position[E_AXIS]*factor);
  661. //current_position[3]*=factor;
  662. axis_steps_per_unit[E_AXIS]= encoderpos;
  663. encoderpos=activeline*lcdslow;
  664. }
  665. BLOCK;
  666. beepshort();
  667. }
  668. if(linechanging)
  669. {
  670. if(encoderpos<5) encoderpos=5;
  671. if(encoderpos>9999) encoderpos=9999;
  672. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  673. }
  674. }break;
  675. default:
  676. break;
  677. }
  678. line++;
  679. }
  680. updateActiveLines(ItemT_fan,encoderpos);
  681. }
  682. //does not work
  683. // #define MENUCHANGEITEM(repaint_action, enter_action, accept_action, change_action) \
  684. // {\
  685. // if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  686. // if(activeline==line) \
  687. // { \
  688. // if(CLICKED) \
  689. // { \
  690. // linechanging=!linechanging; \
  691. // if(linechanging) {enter_action;} \
  692. // else {accept_action;} \
  693. // } \
  694. // else \
  695. // if(linechanging) {change_action};}\
  696. // }
  697. //
  698. enum {
  699. ItemCT_exit,ItemCT_nozzle,
  700. #ifdef AUTOTEMP
  701. ItemCT_autotempactive,
  702. ItemCT_autotempmin,ItemCT_autotempmax,ItemCT_autotempfact,
  703. #endif
  704. #if (HEATER_BED_PIN > -1)
  705. ItemCT_bed,
  706. #endif
  707. ItemCT_fan,
  708. ItemCT_PID_P,ItemCT_PID_I,ItemCT_PID_D,ItemCT_PID_C
  709. };
  710. void MainMenu::showControlTemp()
  711. {
  712. uint8_t line=0;
  713. clearIfNecessary();
  714. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  715. {
  716. switch(i)
  717. {
  718. case ItemCT_exit:
  719. MENUITEM( lcdprintPGM(" Control \003") , BLOCK;status=Main_Control;beepshort(); ) ;
  720. break;
  721. case ItemCT_nozzle:
  722. {
  723. if(force_lcd_update)
  724. {
  725. lcd.setCursor(0,line);lcdprintPGM(" \002Nozzle:");
  726. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  727. }
  728. if((activeline!=line) )
  729. break;
  730. if(CLICKED)
  731. {
  732. linechanging=!linechanging;
  733. if(linechanging)
  734. {
  735. encoderpos=intround(degTargetHotend0());
  736. }
  737. else
  738. {
  739. setTargetHotend0(encoderpos);
  740. encoderpos=activeline*lcdslow;
  741. beepshort();
  742. }
  743. BLOCK;
  744. }
  745. if(linechanging)
  746. {
  747. if(encoderpos<0) encoderpos=0;
  748. if(encoderpos>260) encoderpos=260;
  749. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  750. }
  751. }break;
  752. #ifdef AUTOTEMP
  753. case ItemCT_autotempmin:
  754. {
  755. if(force_lcd_update)
  756. {
  757. lcd.setCursor(0,line);lcdprintPGM(" \002 Min:");
  758. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_min));
  759. }
  760. if((activeline!=line) )
  761. break;
  762. if(CLICKED)
  763. {
  764. linechanging=!linechanging;
  765. if(linechanging)
  766. {
  767. encoderpos=intround(autotemp_min);
  768. }
  769. else
  770. {
  771. autotemp_min=encoderpos;
  772. encoderpos=activeline*lcdslow;
  773. beepshort();
  774. }
  775. BLOCK;
  776. }
  777. if(linechanging)
  778. {
  779. if(encoderpos<0) encoderpos=0;
  780. if(encoderpos>260) encoderpos=260;
  781. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  782. }
  783. }break;
  784. case ItemCT_autotempmax:
  785. {
  786. if(force_lcd_update)
  787. {
  788. lcd.setCursor(0,line);lcdprintPGM(" \002 Max:");
  789. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_max));
  790. }
  791. if((activeline!=line) )
  792. break;
  793. if(CLICKED)
  794. {
  795. linechanging=!linechanging;
  796. if(linechanging)
  797. {
  798. encoderpos=intround(autotemp_max);
  799. }
  800. else
  801. {
  802. autotemp_max=encoderpos;
  803. encoderpos=activeline*lcdslow;
  804. beepshort();
  805. }
  806. BLOCK;
  807. }
  808. if(linechanging)
  809. {
  810. if(encoderpos<0) encoderpos=0;
  811. if(encoderpos>260) encoderpos=260;
  812. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  813. }
  814. }break;
  815. case ItemCT_autotempfact:
  816. {
  817. if(force_lcd_update)
  818. {
  819. lcd.setCursor(0,line);lcdprintPGM(" \002 Fact:");
  820. lcd.setCursor(13,line);lcd.print(ftostr32(autotemp_factor));
  821. }
  822. if((activeline!=line) )
  823. break;
  824. if(CLICKED)
  825. {
  826. linechanging=!linechanging;
  827. if(linechanging)
  828. {
  829. encoderpos=intround(autotemp_factor*100);
  830. }
  831. else
  832. {
  833. autotemp_max=encoderpos;
  834. encoderpos=activeline*lcdslow;
  835. beepshort();
  836. }
  837. BLOCK;
  838. }
  839. if(linechanging)
  840. {
  841. if(encoderpos<0) encoderpos=0;
  842. if(encoderpos>99) encoderpos=99;
  843. lcd.setCursor(13,line);lcd.print(ftostr32(encoderpos/100.));
  844. }
  845. }break;
  846. case ItemCT_autotempactive:
  847. {
  848. if(force_lcd_update)
  849. {
  850. lcd.setCursor(0,line);lcdprintPGM(" Autotemp:");
  851. lcd.setCursor(13,line);
  852. if(autotemp_enabled)
  853. lcdprintPGM("On");
  854. else
  855. lcdprintPGM("Off");
  856. }
  857. if((activeline!=line) )
  858. break;
  859. if(CLICKED)
  860. {
  861. autotemp_enabled=!autotemp_enabled;
  862. lcd.setCursor(13,line);
  863. if(autotemp_enabled)
  864. lcdprintPGM("On ");
  865. else
  866. lcdprintPGM("Off");
  867. BLOCK;
  868. }
  869. }break;
  870. #endif //autotemp
  871. #if (HEATER_BED_PIN > -1)
  872. case ItemCT_bed:
  873. {
  874. if(force_lcd_update)
  875. {
  876. lcd.setCursor(0,line);lcdprintPGM(" \002Bed:");
  877. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  878. }
  879. if((activeline!=line) )
  880. break;
  881. if(CLICKED)
  882. {
  883. linechanging=!linechanging;
  884. if(linechanging)
  885. {
  886. encoderpos=intround(degTargetBed());
  887. }
  888. else
  889. {
  890. setTargetBed(encoderpos);
  891. encoderpos=activeline*lcdslow;
  892. beepshort();
  893. }
  894. BLOCK;
  895. }
  896. if(linechanging)
  897. {
  898. if(encoderpos<0) encoderpos=0;
  899. if(encoderpos>260) encoderpos=260;
  900. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  901. }
  902. }break;
  903. #endif
  904. case ItemCT_fan:
  905. {
  906. if(force_lcd_update)
  907. {
  908. lcd.setCursor(0,line);lcdprintPGM(" Fan speed:");
  909. lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
  910. }
  911. if((activeline!=line) )
  912. break;
  913. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  914. {
  915. linechanging=!linechanging;
  916. if(linechanging)
  917. {
  918. encoderpos=fanpwm;
  919. }
  920. else
  921. {
  922. encoderpos=activeline*lcdslow;
  923. beepshort();
  924. }
  925. BLOCK;
  926. }
  927. if(linechanging)
  928. {
  929. if(encoderpos<0) encoderpos=0;
  930. if(encoderpos>255) encoderpos=255;
  931. fanpwm=encoderpos;
  932. analogWrite(FAN_PIN, fanpwm);
  933. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  934. }
  935. }break;
  936. case ItemCT_PID_P:
  937. {
  938. if(force_lcd_update)
  939. {
  940. lcd.setCursor(0,line);lcdprintPGM(" PID-P: ");
  941. lcd.setCursor(13,line);lcd.print(itostr4(Kp));
  942. }
  943. if((activeline!=line) )
  944. break;
  945. if(CLICKED)
  946. {
  947. linechanging=!linechanging;
  948. if(linechanging)
  949. {
  950. encoderpos=(int)Kp;
  951. }
  952. else
  953. {
  954. Kp= encoderpos;
  955. encoderpos=activeline*lcdslow;
  956. }
  957. BLOCK;
  958. beepshort();
  959. }
  960. if(linechanging)
  961. {
  962. if(encoderpos<1) encoderpos=1;
  963. if(encoderpos>9990) encoderpos=9990;
  964. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  965. }
  966. }break;
  967. case ItemCT_PID_I:
  968. {
  969. if(force_lcd_update)
  970. {
  971. lcd.setCursor(0,line);lcdprintPGM(" PID-I: ");
  972. lcd.setCursor(13,line);lcd.print(ftostr51(Ki/PID_dT));
  973. }
  974. if((activeline!=line) )
  975. break;
  976. if(CLICKED)
  977. {
  978. linechanging=!linechanging;
  979. if(linechanging)
  980. {
  981. encoderpos=(int)(Ki*10/PID_dT);
  982. }
  983. else
  984. {
  985. Ki= encoderpos/10.*PID_dT;
  986. encoderpos=activeline*lcdslow;
  987. }
  988. BLOCK;
  989. beepshort();
  990. }
  991. if(linechanging)
  992. {
  993. if(encoderpos<0) encoderpos=0;
  994. if(encoderpos>9990) encoderpos=9990;
  995. lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.));
  996. }
  997. }break;
  998. case ItemCT_PID_D:
  999. {
  1000. if(force_lcd_update)
  1001. {
  1002. lcd.setCursor(0,line);lcdprintPGM(" PID-D: ");
  1003. lcd.setCursor(13,line);lcd.print(itostr4(Kd*PID_dT));
  1004. }
  1005. if((activeline!=line) )
  1006. break;
  1007. if(CLICKED)
  1008. {
  1009. linechanging=!linechanging;
  1010. if(linechanging)
  1011. {
  1012. encoderpos=(int)(Kd/5./PID_dT);
  1013. }
  1014. else
  1015. {
  1016. Kd= encoderpos;
  1017. encoderpos=activeline*lcdslow;
  1018. }
  1019. BLOCK;
  1020. beepshort();
  1021. }
  1022. if(linechanging)
  1023. {
  1024. if(encoderpos<0) encoderpos=0;
  1025. if(encoderpos>9990) encoderpos=9990;
  1026. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1027. }
  1028. }break;
  1029. case ItemCT_PID_C:
  1030. #ifdef PID_ADD_EXTRUSION_RATE
  1031. {
  1032. if(force_lcd_update)
  1033. {
  1034. lcd.setCursor(0,line);lcdprintPGM(" PID-C: ");
  1035. lcd.setCursor(13,line);lcd.print(itostr3(Kc));
  1036. }
  1037. if((activeline!=line) )
  1038. break;
  1039. if(CLICKED)
  1040. {
  1041. linechanging=!linechanging;
  1042. if(linechanging)
  1043. {
  1044. encoderpos=(int)Kc;
  1045. }
  1046. else
  1047. {
  1048. Kc= encoderpos;
  1049. encoderpos=activeline*lcdslow;
  1050. }
  1051. BLOCK;
  1052. beepshort();
  1053. }
  1054. if(linechanging)
  1055. {
  1056. if(encoderpos<0) encoderpos=0;
  1057. if(encoderpos>990) encoderpos=990;
  1058. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1059. }
  1060. }
  1061. #endif
  1062. break;
  1063. default:
  1064. break;
  1065. }
  1066. line++;
  1067. }
  1068. #ifdef PID_ADD_EXTRUSION_RATE
  1069. updateActiveLines(ItemCT_PID_C,encoderpos);
  1070. #else
  1071. updateActiveLines(ItemCT_PID_D,encoderpos);
  1072. #endif
  1073. }
  1074. enum {
  1075. ItemCM_exit,
  1076. ItemCM_acc, ItemCM_xyjerk,
  1077. ItemCM_vmaxx, ItemCM_vmaxy, ItemCM_vmaxz, ItemCM_vmaxe,
  1078. ItemCM_vtravmin,ItemCM_vmin,
  1079. ItemCM_amaxx, ItemCM_amaxy, ItemCM_amaxz, ItemCM_amaxe,
  1080. ItemCM_aret,ItemCM_esteps
  1081. };
  1082. void MainMenu::showControlMotion()
  1083. {
  1084. uint8_t line=0;
  1085. clearIfNecessary();
  1086. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1087. {
  1088. switch(i)
  1089. {
  1090. case ItemCM_exit:
  1091. MENUITEM( lcdprintPGM(" Control \003") , BLOCK;status=Main_Control;beepshort(); ) ;
  1092. break;
  1093. case ItemCM_acc:
  1094. {
  1095. if(force_lcd_update)
  1096. {
  1097. lcd.setCursor(0,line);lcdprintPGM(" Acc:");
  1098. lcd.setCursor(13,line);lcd.print(itostr3(acceleration/100));lcdprintPGM("00");
  1099. }
  1100. if((activeline!=line) )
  1101. break;
  1102. if(CLICKED)
  1103. {
  1104. linechanging=!linechanging;
  1105. if(linechanging)
  1106. {
  1107. encoderpos=(int)acceleration/100;
  1108. }
  1109. else
  1110. {
  1111. acceleration= encoderpos*100;
  1112. encoderpos=activeline*lcdslow;
  1113. }
  1114. BLOCK;
  1115. beepshort();
  1116. }
  1117. if(linechanging)
  1118. {
  1119. if(encoderpos<5) encoderpos=5;
  1120. if(encoderpos>990) encoderpos=990;
  1121. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1122. }
  1123. }break;
  1124. case ItemCM_xyjerk: //max_xy_jerk
  1125. {
  1126. if(force_lcd_update)
  1127. {
  1128. lcd.setCursor(0,line);lcdprintPGM(" Vxy-jerk: ");
  1129. lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk));
  1130. }
  1131. if((activeline!=line) )
  1132. break;
  1133. if(CLICKED)
  1134. {
  1135. linechanging=!linechanging;
  1136. if(linechanging)
  1137. {
  1138. encoderpos=(int)max_xy_jerk;
  1139. }
  1140. else
  1141. {
  1142. max_xy_jerk= encoderpos;
  1143. encoderpos=activeline*lcdslow;
  1144. }
  1145. BLOCK;
  1146. beepshort();
  1147. }
  1148. if(linechanging)
  1149. {
  1150. if(encoderpos<1) encoderpos=1;
  1151. if(encoderpos>990) encoderpos=990;
  1152. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1153. }
  1154. }break;
  1155. case ItemCM_vmaxx:
  1156. case ItemCM_vmaxy:
  1157. case ItemCM_vmaxz:
  1158. case ItemCM_vmaxe:
  1159. {
  1160. if(force_lcd_update)
  1161. {
  1162. lcd.setCursor(0,line);lcdprintPGM(" Vmax ");
  1163. if(i==ItemCM_vmaxx)lcdprintPGM("x:");
  1164. if(i==ItemCM_vmaxy)lcdprintPGM("y:");
  1165. if(i==ItemCM_vmaxz)lcdprintPGM("z:");
  1166. if(i==ItemCM_vmaxe)lcdprintPGM("e:");
  1167. lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemCM_vmaxx]));
  1168. }
  1169. if((activeline!=line) )
  1170. break;
  1171. if(CLICKED)
  1172. {
  1173. linechanging=!linechanging;
  1174. if(linechanging)
  1175. {
  1176. encoderpos=(int)max_feedrate[i-ItemCM_vmaxx];
  1177. }
  1178. else
  1179. {
  1180. max_feedrate[i-ItemCM_vmaxx]= encoderpos;
  1181. encoderpos=activeline*lcdslow;
  1182. }
  1183. BLOCK;
  1184. beepshort();
  1185. }
  1186. if(linechanging)
  1187. {
  1188. if(encoderpos<1) encoderpos=1;
  1189. if(encoderpos>990) encoderpos=990;
  1190. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1191. }
  1192. }break;
  1193. case ItemCM_vmin:
  1194. {
  1195. if(force_lcd_update)
  1196. {
  1197. lcd.setCursor(0,line);lcdprintPGM(" Vmin:");
  1198. lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate));
  1199. }
  1200. if((activeline!=line) )
  1201. break;
  1202. if(CLICKED)
  1203. {
  1204. linechanging=!linechanging;
  1205. if(linechanging)
  1206. {
  1207. encoderpos=(int)(minimumfeedrate);
  1208. }
  1209. else
  1210. {
  1211. minimumfeedrate= encoderpos;
  1212. encoderpos=activeline*lcdslow;
  1213. }
  1214. BLOCK;
  1215. beepshort();
  1216. }
  1217. if(linechanging)
  1218. {
  1219. if(encoderpos<0) encoderpos=0;
  1220. if(encoderpos>990) encoderpos=990;
  1221. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1222. }
  1223. }break;
  1224. case ItemCM_vtravmin:
  1225. {
  1226. if(force_lcd_update)
  1227. {
  1228. lcd.setCursor(0,line);lcdprintPGM(" VTrav min:");
  1229. lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate));
  1230. }
  1231. if((activeline!=line) )
  1232. break;
  1233. if(CLICKED)
  1234. {
  1235. linechanging=!linechanging;
  1236. if(linechanging)
  1237. {
  1238. encoderpos=(int)mintravelfeedrate;
  1239. }
  1240. else
  1241. {
  1242. mintravelfeedrate= encoderpos;
  1243. encoderpos=activeline*lcdslow;
  1244. }
  1245. BLOCK;
  1246. beepshort();
  1247. }
  1248. if(linechanging)
  1249. {
  1250. if(encoderpos<0) encoderpos=0;
  1251. if(encoderpos>990) encoderpos=990;
  1252. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1253. }
  1254. }break;
  1255. case ItemCM_amaxx:
  1256. case ItemCM_amaxy:
  1257. case ItemCM_amaxz:
  1258. case ItemCM_amaxe:
  1259. {
  1260. if(force_lcd_update)
  1261. {
  1262. lcd.setCursor(0,line);lcdprintPGM(" Amax ");
  1263. if(i==ItemCM_amaxx)lcdprintPGM("x:");
  1264. if(i==ItemCM_amaxy)lcdprintPGM("y:");
  1265. if(i==ItemCM_amaxz)lcdprintPGM("z:");
  1266. if(i==ItemCM_amaxe)lcdprintPGM("e:");
  1267. lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100));lcdprintPGM("00");
  1268. }
  1269. if((activeline!=line) )
  1270. break;
  1271. if(CLICKED)
  1272. {
  1273. linechanging=!linechanging;
  1274. if(linechanging)
  1275. {
  1276. encoderpos=(int)max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100;
  1277. }
  1278. else
  1279. {
  1280. max_acceleration_units_per_sq_second[i-ItemCM_amaxx]= encoderpos*100;
  1281. encoderpos=activeline*lcdslow;
  1282. }
  1283. BLOCK;
  1284. beepshort();
  1285. }
  1286. if(linechanging)
  1287. {
  1288. if(encoderpos<1) encoderpos=1;
  1289. if(encoderpos>990) encoderpos=990;
  1290. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1291. }
  1292. }break;
  1293. case ItemCM_aret://float retract_acceleration = 7000;
  1294. {
  1295. if(force_lcd_update)
  1296. {
  1297. lcd.setCursor(0,line);lcdprintPGM(" A-retract:");
  1298. lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcdprintPGM("00");
  1299. }
  1300. if((activeline!=line) )
  1301. break;
  1302. if(CLICKED)
  1303. {
  1304. linechanging=!linechanging;
  1305. if(linechanging)
  1306. {
  1307. encoderpos=(int)retract_acceleration/100;
  1308. }
  1309. else
  1310. {
  1311. retract_acceleration= encoderpos*100;
  1312. encoderpos=activeline*lcdslow;
  1313. }
  1314. BLOCK;
  1315. beepshort();
  1316. }
  1317. if(linechanging)
  1318. {
  1319. if(encoderpos<10) encoderpos=10;
  1320. if(encoderpos>990) encoderpos=990;
  1321. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1322. }
  1323. }break;
  1324. case ItemCM_esteps://axis_steps_per_unit[i] = code_value();
  1325. {
  1326. if(force_lcd_update)
  1327. {
  1328. lcd.setCursor(0,line);lcdprintPGM(" Esteps/mm:");
  1329. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3]));
  1330. }
  1331. if((activeline!=line) )
  1332. break;
  1333. if(CLICKED)
  1334. {
  1335. linechanging=!linechanging;
  1336. if(linechanging)
  1337. {
  1338. encoderpos=(int)axis_steps_per_unit[3];
  1339. }
  1340. else
  1341. {
  1342. float factor=float(encoderpos)/float(axis_steps_per_unit[3]);
  1343. position[E_AXIS]=lround(position[E_AXIS]*factor);
  1344. //current_position[3]*=factor;
  1345. axis_steps_per_unit[E_AXIS]= encoderpos;
  1346. encoderpos=activeline*lcdslow;
  1347. }
  1348. BLOCK;
  1349. beepshort();
  1350. }
  1351. if(linechanging)
  1352. {
  1353. if(encoderpos<5) encoderpos=5;
  1354. if(encoderpos>9999) encoderpos=9999;
  1355. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1356. }
  1357. }break;
  1358. default:
  1359. break;
  1360. }
  1361. line++;
  1362. }
  1363. updateActiveLines(ItemCM_esteps,encoderpos);
  1364. }
  1365. enum {
  1366. ItemC_exit,ItemC_temp,ItemC_move,
  1367. ItemC_store, ItemC_load,ItemC_failsafe
  1368. };
  1369. void MainMenu::showControl()
  1370. {
  1371. uint8_t line=0;
  1372. clearIfNecessary();
  1373. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1374. {
  1375. switch(i)
  1376. {
  1377. case ItemC_exit:
  1378. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  1379. break;
  1380. case ItemC_temp:
  1381. MENUITEM( lcdprintPGM(" Temperature \x7E") , BLOCK;status=Sub_TempControl;beepshort(); ) ;
  1382. break;
  1383. case ItemC_move:
  1384. MENUITEM( lcdprintPGM(" Motion \x7E") , BLOCK;status=Sub_MotionControl;beepshort(); ) ;
  1385. break;
  1386. case ItemC_store:
  1387. {
  1388. if(force_lcd_update)
  1389. {
  1390. lcd.setCursor(0,line);lcdprintPGM(" Store EPROM");
  1391. }
  1392. if((activeline==line) && CLICKED)
  1393. {
  1394. //enquecommand("M84");
  1395. beepshort();
  1396. BLOCK;
  1397. EEPROM_StoreSettings();
  1398. }
  1399. }break;
  1400. case ItemC_load:
  1401. {
  1402. if(force_lcd_update)
  1403. {
  1404. lcd.setCursor(0,line);lcdprintPGM(" Load EPROM");
  1405. }
  1406. if((activeline==line) && CLICKED)
  1407. {
  1408. //enquecommand("M84");
  1409. beepshort();
  1410. BLOCK;
  1411. EEPROM_RetrieveSettings();
  1412. }
  1413. }break;
  1414. case ItemC_failsafe:
  1415. {
  1416. if(force_lcd_update)
  1417. {
  1418. lcd.setCursor(0,line);lcdprintPGM(" Restore Failsafe");
  1419. }
  1420. if((activeline==line) && CLICKED)
  1421. {
  1422. //enquecommand("M84");
  1423. beepshort();
  1424. BLOCK;
  1425. EEPROM_RetrieveSettings(true);
  1426. }
  1427. }break;
  1428. default:
  1429. break;
  1430. }
  1431. line++;
  1432. }
  1433. updateActiveLines(ItemC_failsafe,encoderpos);
  1434. }
  1435. void MainMenu::showSD()
  1436. {
  1437. #ifdef SDSUPPORT
  1438. uint8_t line=0;
  1439. clearIfNecessary();
  1440. static uint8_t nrfiles=0;
  1441. if(force_lcd_update)
  1442. {
  1443. if(card.cardOK)
  1444. {
  1445. nrfiles=card.getnrfilenames();
  1446. }
  1447. else
  1448. {
  1449. nrfiles=0;
  1450. lineoffset=0;
  1451. }
  1452. }
  1453. bool enforceupdate=false;
  1454. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1455. {
  1456. switch(i)
  1457. {
  1458. case 0:
  1459. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  1460. break;
  1461. // case 1:
  1462. // {
  1463. // if(force_lcd_update)
  1464. // {
  1465. // lcd.setCursor(0,line);
  1466. // #ifdef CARDINSERTED
  1467. // if(CARDINSERTED)
  1468. // #else
  1469. // if(true)
  1470. // #endif
  1471. // {
  1472. // lcdprintPGM(" \004Refresh");
  1473. // }
  1474. // else
  1475. // {
  1476. // lcdprintPGM(" \004Insert Card");
  1477. // }
  1478. //
  1479. // }
  1480. // if((activeline==line) && CLICKED)
  1481. // {
  1482. // BLOCK;
  1483. // beepshort();
  1484. // card.initsd();
  1485. // force_lcd_update=true;
  1486. // nrfiles=card.getnrfilenames();
  1487. // }
  1488. // }break;
  1489. case 1:
  1490. MENUITEM( lcd.print(" ");card.getWorkDirName();if(card.filename[0]=='/') lcdprintPGM("\004Refresh");else {lcd.print("\005");lcd.print(card.filename);lcd.print("/..");} , BLOCK;card.updir();enforceupdate=true;lineoffset=0;beepshort(); ) ;
  1491. break;
  1492. default:
  1493. {
  1494. #define FIRSTITEM 2
  1495. if(i-FIRSTITEM<nrfiles)
  1496. {
  1497. if(force_lcd_update)
  1498. {
  1499. card.getfilename(i-FIRSTITEM);
  1500. //Serial.print("Filenr:");Serial.println(i-2);
  1501. lcd.setCursor(0,line);lcdprintPGM(" ");
  1502. if(card.filenameIsDir) lcd.print("\005");
  1503. lcd.print(card.filename);
  1504. }
  1505. if((activeline==line) && CLICKED)
  1506. {
  1507. BLOCK
  1508. card.getfilename(i-FIRSTITEM);
  1509. if(card.filenameIsDir)
  1510. {
  1511. for(int8_t i=0;i<strlen(card.filename);i++)
  1512. card.filename[i]=tolower(card.filename[i]);
  1513. card.chdir(card.filename);
  1514. lineoffset=0;
  1515. enforceupdate=true;
  1516. }
  1517. else
  1518. {
  1519. char cmd[30];
  1520. for(int8_t i=0;i<strlen(card.filename);i++)
  1521. card.filename[i]=tolower(card.filename[i]);
  1522. sprintf(cmd,"M23 %s",card.filename);
  1523. //sprintf(cmd,"M115");
  1524. enquecommand(cmd);
  1525. enquecommand("M24");
  1526. beep();
  1527. status=Main_Status;
  1528. lcd_status(card.filename);
  1529. }
  1530. }
  1531. }
  1532. }
  1533. break;
  1534. }
  1535. line++;
  1536. }
  1537. updateActiveLines(FIRSTITEM+nrfiles-1,encoderpos);
  1538. if(enforceupdate)
  1539. {
  1540. force_lcd_update=true;
  1541. enforceupdate=false;
  1542. }
  1543. #endif
  1544. }
  1545. enum {ItemM_watch, ItemM_prepare, ItemM_control, ItemM_file };
  1546. void MainMenu::showMainMenu()
  1547. {
  1548. #ifndef ULTIPANEL
  1549. force_lcd_update=false;
  1550. #endif
  1551. if(tune)
  1552. {
  1553. if(!(movesplanned() ||card.sdprinting))
  1554. {
  1555. force_lcd_update=true;
  1556. tune=false;
  1557. }
  1558. }
  1559. else
  1560. {
  1561. if(movesplanned() ||card.sdprinting)
  1562. {
  1563. force_lcd_update=true;
  1564. tune=true;
  1565. }
  1566. }
  1567. clearIfNecessary();
  1568. for(int8_t line=0;line<LCD_HEIGHT;line++)
  1569. {
  1570. switch(line)
  1571. {
  1572. case ItemM_watch:
  1573. MENUITEM( lcdprintPGM(" Watch \003") , BLOCK;status=Main_Status;beepshort(); ) ;
  1574. break;
  1575. case ItemM_prepare:
  1576. MENUITEM( if(!tune) lcdprintPGM(" Prepare \x7E");else lcdprintPGM(" Tune \x7E"); , BLOCK;status=Main_Prepare;beepshort(); ) ;
  1577. break;
  1578. case ItemM_control:
  1579. MENUITEM( lcdprintPGM(" Control \x7E") , BLOCK;status=Main_Control;beepshort(); ) ;
  1580. break;
  1581. #ifdef SDSUPPORT
  1582. case ItemM_file:
  1583. {
  1584. if(force_lcd_update)
  1585. {
  1586. lcd.setCursor(0,line);
  1587. #ifdef CARDINSERTED
  1588. if(CARDINSERTED)
  1589. #else
  1590. if(true)
  1591. #endif
  1592. {
  1593. if(card.sdprinting)
  1594. lcdprintPGM(" Stop Print \x7E");
  1595. else
  1596. lcdprintPGM(" Card Menu \x7E");
  1597. }
  1598. else
  1599. {
  1600. lcdprintPGM(" No Card");
  1601. }
  1602. }
  1603. #ifdef CARDINSERTED
  1604. if(CARDINSERTED)
  1605. #endif
  1606. if((activeline==line)&&CLICKED)
  1607. {
  1608. card.printingHasFinished();
  1609. BLOCK;
  1610. status=Main_SD;
  1611. beepshort();
  1612. }
  1613. }break;
  1614. #else
  1615. case ItemM_file:
  1616. break;
  1617. #endif
  1618. default:
  1619. SERIAL_ERROR_START;
  1620. SERIAL_ERRORLNPGM("Something is wrong in the MenuStructure.");
  1621. break;
  1622. }
  1623. }
  1624. updateActiveLines(3,encoderpos);
  1625. }
  1626. void MainMenu::update()
  1627. {
  1628. static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
  1629. static long timeoutToStatus=0;
  1630. static bool oldcardstatus=false;
  1631. #ifdef CARDINSERTED
  1632. if((CARDINSERTED != oldcardstatus))
  1633. {
  1634. force_lcd_update=true;
  1635. oldcardstatus=CARDINSERTED;
  1636. //Serial.println("echo: SD CHANGE");
  1637. if(CARDINSERTED)
  1638. {
  1639. card.initsd();
  1640. LCD_MESSAGEPGM("Card inserted");
  1641. }
  1642. else
  1643. {
  1644. card.release();
  1645. LCD_MESSAGEPGM("Card removed");
  1646. }
  1647. }
  1648. #endif
  1649. if(status!=oldstatus)
  1650. {
  1651. force_lcd_update=true;
  1652. encoderpos=0;
  1653. lineoffset=0;
  1654. oldstatus=status;
  1655. }
  1656. if( (encoderpos!=lastencoderpos) || CLICKED)
  1657. timeoutToStatus=millis()+STATUSTIMEOUT;
  1658. switch(status)
  1659. {
  1660. case Main_Status:
  1661. {
  1662. showStatus();
  1663. if(CLICKED)
  1664. {
  1665. linechanging=false;
  1666. BLOCK
  1667. status=Main_Menu;
  1668. timeoutToStatus=millis()+STATUSTIMEOUT;
  1669. }
  1670. }break;
  1671. case Main_Menu:
  1672. {
  1673. showMainMenu();
  1674. linechanging=false;
  1675. }break;
  1676. case Main_Prepare:
  1677. {
  1678. if(tune)
  1679. {
  1680. showTune();
  1681. }
  1682. else
  1683. {
  1684. showPrepare();
  1685. }
  1686. }break;
  1687. case Sub_PrepareMove:
  1688. {
  1689. showAxisMove();
  1690. }break;
  1691. case Main_Control:
  1692. {
  1693. showControl();
  1694. }break;
  1695. case Sub_MotionControl:
  1696. {
  1697. showControlMotion();
  1698. }break;
  1699. case Sub_TempControl:
  1700. {
  1701. showControlTemp();
  1702. }break;
  1703. case Main_SD:
  1704. {
  1705. showSD();
  1706. }break;
  1707. }
  1708. if(timeoutToStatus<millis())
  1709. status=Main_Status;
  1710. //force_lcd_update=false;
  1711. lastencoderpos=encoderpos;
  1712. }
  1713. // convert float to string with +123.4 format
  1714. char *ftostr3(const float &x)
  1715. {
  1716. //sprintf(conv,"%5.1f",x);
  1717. int xx=x;
  1718. conv[0]=(xx/100)%10+'0';
  1719. conv[1]=(xx/10)%10+'0';
  1720. conv[2]=(xx)%10+'0';
  1721. conv[3]=0;
  1722. return conv;
  1723. }
  1724. char *itostr2(const uint8_t &x)
  1725. {
  1726. //sprintf(conv,"%5.1f",x);
  1727. int xx=x;
  1728. conv[0]=(xx/10)%10+'0';
  1729. conv[1]=(xx)%10+'0';
  1730. conv[2]=0;
  1731. return conv;
  1732. }
  1733. // convert float to string with +123.4 format
  1734. char *ftostr31(const float &x)
  1735. {
  1736. int xx=x*10;
  1737. conv[0]=(xx>=0)?'+':'-';
  1738. xx=abs(xx);
  1739. conv[1]=(xx/1000)%10+'0';
  1740. conv[2]=(xx/100)%10+'0';
  1741. conv[3]=(xx/10)%10+'0';
  1742. conv[4]='.';
  1743. conv[5]=(xx)%10+'0';
  1744. conv[6]=0;
  1745. return conv;
  1746. }
  1747. char *ftostr32(const float &x)
  1748. {
  1749. int xx=x*100;
  1750. conv[0]=(xx>=0)?'+':'-';
  1751. xx=abs(xx);
  1752. conv[1]=(xx/100)%10+'0';
  1753. conv[2]='.';
  1754. conv[3]=(xx/10)%10+'0';
  1755. conv[4]=(xx)%10+'0';
  1756. conv[6]=0;
  1757. return conv;
  1758. }
  1759. char *itostr31(const int &xx)
  1760. {
  1761. conv[0]=(xx>=0)?'+':'-';
  1762. conv[1]=(xx/1000)%10+'0';
  1763. conv[2]=(xx/100)%10+'0';
  1764. conv[3]=(xx/10)%10+'0';
  1765. conv[4]='.';
  1766. conv[5]=(xx)%10+'0';
  1767. conv[6]=0;
  1768. return conv;
  1769. }
  1770. char *itostr3(const int &xx)
  1771. {
  1772. conv[0]=(xx/100)%10+'0';
  1773. conv[1]=(xx/10)%10+'0';
  1774. conv[2]=(xx)%10+'0';
  1775. conv[3]=0;
  1776. return conv;
  1777. }
  1778. char *itostr4(const int &xx)
  1779. {
  1780. conv[0]=(xx/1000)%10+'0';
  1781. conv[1]=(xx/100)%10+'0';
  1782. conv[2]=(xx/10)%10+'0';
  1783. conv[3]=(xx)%10+'0';
  1784. conv[4]=0;
  1785. return conv;
  1786. }
  1787. // convert float to string with +1234.5 format
  1788. char *ftostr51(const float &x)
  1789. {
  1790. int xx=x*10;
  1791. conv[0]=(xx>=0)?'+':'-';
  1792. xx=abs(xx);
  1793. conv[1]=(xx/10000)%10+'0';
  1794. conv[2]=(xx/1000)%10+'0';
  1795. conv[3]=(xx/100)%10+'0';
  1796. conv[4]=(xx/10)%10+'0';
  1797. conv[5]='.';
  1798. conv[6]=(xx)%10+'0';
  1799. conv[7]=0;
  1800. return conv;
  1801. }
  1802. #endif //ULTRA_LCD