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

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