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

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