My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ultralcd.pde 38KB

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