My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ultralcd.pde 37KB

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