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

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