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 45KB

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