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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598
  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. #else //smaller LCDS----------------------------------
  337. static int olddegHotEnd0=-1;
  338. static int oldtargetHotEnd0=-1;
  339. if(force_lcd_update) //initial display of content
  340. {
  341. encoderpos=feedmultiply;
  342. lcd.setCursor(0,0);lcdprintPGM("\002123/567\001 ");
  343. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  344. lcd.setCursor(10,0);lcdprintPGM("B123/567\001 ");
  345. #endif
  346. }
  347. int tHotEnd0=intround(degHotend0());
  348. int ttHotEnd0=intround(degTargetHotend0());
  349. if((abs(tHotEnd0-olddegHotEnd0)>1)||force_lcd_update)
  350. {
  351. lcd.setCursor(1,0);
  352. lcd.print(ftostr3(tHotEnd0));
  353. olddegHotEnd0=tHotEnd0;
  354. }
  355. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  356. {
  357. lcd.setCursor(5,0);
  358. lcd.print(ftostr3(ttHotEnd0));
  359. oldtargetHotEnd0=ttHotEnd0;
  360. }
  361. if(messagetext[0]!='\0')
  362. {
  363. lcd.setCursor(0,LCD_HEIGHT-1);
  364. lcd.print(fillto(LCD_WIDTH,messagetext));
  365. messagetext[0]='\0';
  366. }
  367. #endif
  368. }
  369. enum {ItemP_exit, ItemP_home, ItemP_origin, ItemP_preheat, ItemP_extrude, ItemP_disstep};
  370. void MainMenu::showPrepare()
  371. {
  372. uint8_t line=0;
  373. if(lastlineoffset!=lineoffset)
  374. {
  375. force_lcd_update=true;
  376. clear();
  377. }
  378. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  379. {
  380. //Serial.println((int)(line-lineoffset));
  381. switch(i)
  382. {
  383. case ItemP_exit:
  384. {
  385. if(force_lcd_update)
  386. {
  387. lcd.setCursor(0,line);lcdprintPGM(" Prepare");
  388. }
  389. if((activeline==line) && CLICKED)
  390. {
  391. BLOCK
  392. status=Main_Menu;
  393. beepshort();
  394. }
  395. }break;
  396. case ItemP_home:
  397. {
  398. if(force_lcd_update)
  399. {
  400. lcd.setCursor(0,line);lcdprintPGM(" Auto Home");
  401. }
  402. if((activeline==line) && CLICKED)
  403. {
  404. BLOCK
  405. enquecommand("G28 X-105 Y-105 Z0");
  406. beepshort();
  407. }
  408. }break;
  409. case ItemP_origin:
  410. {
  411. if(force_lcd_update)
  412. {
  413. lcd.setCursor(0,line);lcdprintPGM(" Set Origin");
  414. }
  415. if((activeline==line) && CLICKED)
  416. {
  417. BLOCK
  418. enquecommand("G92 X0 Y0 Z0");
  419. beepshort();
  420. }
  421. }break;
  422. case ItemP_preheat:
  423. {
  424. if(force_lcd_update)
  425. {
  426. lcd.setCursor(0,line);lcdprintPGM(" Preheat");
  427. }
  428. if((activeline==line) && CLICKED)
  429. {
  430. BLOCK
  431. setTargetHotend0(170);
  432. beepshort();
  433. }
  434. }break;
  435. case ItemP_extrude:
  436. {
  437. if(force_lcd_update)
  438. {
  439. lcd.setCursor(0,line);lcdprintPGM(" Extrude");
  440. }
  441. if((activeline==line) && CLICKED)
  442. {
  443. BLOCK
  444. enquecommand("G92 E0");
  445. enquecommand("G1 F700 E50");
  446. beepshort();
  447. }
  448. }break;
  449. case ItemP_disstep:
  450. {
  451. if(force_lcd_update)
  452. {
  453. lcd.setCursor(0,line);lcdprintPGM(" Disable Steppers");
  454. }
  455. if((activeline==line) && CLICKED)
  456. {
  457. BLOCK
  458. enquecommand("M84");
  459. beepshort();
  460. }
  461. }break;
  462. default:
  463. break;
  464. }
  465. line++;
  466. }
  467. lastlineoffset=lineoffset;
  468. if((encoderpos/lcdslow!=lastencoderpos/lcdslow)||force_lcd_update)
  469. {
  470. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?' ':' ');
  471. if(encoderpos<0)
  472. {
  473. lineoffset--;
  474. if(lineoffset<0)
  475. lineoffset=0;
  476. encoderpos=0;
  477. force_lcd_update=true;
  478. }
  479. if(encoderpos/lcdslow>3)
  480. {
  481. lineoffset++;
  482. encoderpos=3*lcdslow;
  483. if(lineoffset>(ItemP_disstep+1-LCD_HEIGHT))
  484. lineoffset=ItemP_disstep+1-LCD_HEIGHT;
  485. force_lcd_update=true;
  486. }
  487. //encoderpos=encoderpos%LCD_HEIGHT;
  488. lastencoderpos=encoderpos;
  489. activeline=encoderpos/lcdslow;
  490. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003');
  491. }
  492. }
  493. enum {
  494. ItemC_exit, ItemC_nozzle,
  495. ItemC_PID_P,ItemC_PID_I,ItemC_PID_D,ItemC_PID_C,
  496. ItemC_fan,
  497. ItemC_acc, ItemC_xyjerk,
  498. ItemC_vmaxx, ItemC_vmaxy, ItemC_vmaxz, ItemC_vmaxe,
  499. ItemC_vtravmin,ItemC_vmin,
  500. ItemC_amaxx, ItemC_amaxy, ItemC_amaxz, ItemC_amaxe,
  501. ItemC_aret,ItemC_esteps, ItemC_store, ItemC_load,ItemC_failsafe
  502. };
  503. void MainMenu::showControl()
  504. {
  505. uint8_t line=0;
  506. if((lastlineoffset!=lineoffset)||force_lcd_update)
  507. {
  508. force_lcd_update=true;
  509. clear();
  510. }
  511. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  512. {
  513. switch(i)
  514. {
  515. case ItemC_exit:
  516. {
  517. if(force_lcd_update)
  518. {
  519. lcd.setCursor(0,line);lcdprintPGM(" Control");
  520. }
  521. if((activeline==line) && CLICKED)
  522. {
  523. BLOCK
  524. status=Main_Menu;
  525. beepshort();
  526. }
  527. }break;
  528. case ItemC_nozzle:
  529. {
  530. if(force_lcd_update)
  531. {
  532. lcd.setCursor(0,line);lcdprintPGM(" \002Nozzle:");
  533. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degHotend0())));
  534. }
  535. if((activeline==line) )
  536. {
  537. if(CLICKED)
  538. {
  539. linechanging=!linechanging;
  540. if(linechanging)
  541. {
  542. encoderpos=intround(degHotend0());
  543. }
  544. else
  545. {
  546. setTargetHotend0(encoderpos);
  547. encoderpos=activeline*lcdslow;
  548. beepshort();
  549. }
  550. BLOCK;
  551. }
  552. if(linechanging)
  553. {
  554. if(encoderpos<0) encoderpos=0;
  555. if(encoderpos>260) encoderpos=260;
  556. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  557. }
  558. }
  559. }break;
  560. case ItemC_fan:
  561. {
  562. if(force_lcd_update)
  563. {
  564. lcd.setCursor(0,line);lcdprintPGM(" Fan speed:");
  565. lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
  566. }
  567. if((activeline==line) )
  568. {
  569. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  570. {
  571. linechanging=!linechanging;
  572. if(linechanging)
  573. {
  574. encoderpos=fanpwm;
  575. }
  576. else
  577. {
  578. fanpwm = constrain(encoderpos,0,255);
  579. encoderpos=fanpwm;
  580. analogWrite(FAN_PIN, fanpwm);
  581. beepshort();
  582. }
  583. BLOCK;
  584. }
  585. if(linechanging)
  586. {
  587. if(encoderpos<0) encoderpos=0;
  588. if(encoderpos>255) encoderpos=255;
  589. fanpwm=encoderpos;
  590. analogWrite(FAN_PIN, fanpwm);
  591. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  592. }
  593. }
  594. }break;
  595. case ItemC_acc:
  596. {
  597. if(force_lcd_update)
  598. {
  599. lcd.setCursor(0,line);lcdprintPGM(" Acc:");
  600. lcd.setCursor(13,line);lcd.print(itostr3(acceleration/100));lcdprintPGM("00");
  601. }
  602. if((activeline==line) )
  603. {
  604. if(CLICKED)
  605. {
  606. linechanging=!linechanging;
  607. if(linechanging)
  608. {
  609. encoderpos=(int)acceleration/100;
  610. }
  611. else
  612. {
  613. acceleration= encoderpos*100;
  614. encoderpos=activeline*lcdslow;
  615. }
  616. BLOCK;
  617. beepshort();
  618. }
  619. if(linechanging)
  620. {
  621. if(encoderpos<5) encoderpos=5;
  622. if(encoderpos>990) encoderpos=990;
  623. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  624. }
  625. }
  626. }break;
  627. case ItemC_xyjerk: //max_xy_jerk
  628. {
  629. if(force_lcd_update)
  630. {
  631. lcd.setCursor(0,line);lcdprintPGM(" Vxy-jerk: ");
  632. lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk/60));
  633. }
  634. if((activeline==line) )
  635. {
  636. if(CLICKED)
  637. {
  638. linechanging=!linechanging;
  639. if(linechanging)
  640. {
  641. encoderpos=(int)max_xy_jerk/60;
  642. }
  643. else
  644. {
  645. max_xy_jerk= encoderpos*60;
  646. encoderpos=activeline*lcdslow;
  647. }
  648. BLOCK;
  649. beepshort();
  650. }
  651. if(linechanging)
  652. {
  653. if(encoderpos<1) encoderpos=1;
  654. if(encoderpos>990) encoderpos=990;
  655. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  656. }
  657. }
  658. }break;
  659. case ItemC_PID_P:
  660. {
  661. if(force_lcd_update)
  662. {
  663. lcd.setCursor(0,line);lcdprintPGM(" PID-P: ");
  664. lcd.setCursor(13,line);lcd.print(itostr4(Kp));
  665. }
  666. if((activeline==line) )
  667. {
  668. if(CLICKED)
  669. {
  670. linechanging=!linechanging;
  671. if(linechanging)
  672. {
  673. encoderpos=(int)Kp/5;
  674. }
  675. else
  676. {
  677. Kp= encoderpos*5;
  678. encoderpos=activeline*lcdslow;
  679. }
  680. BLOCK;
  681. beepshort();
  682. }
  683. if(linechanging)
  684. {
  685. if(encoderpos<1) encoderpos=1;
  686. if(encoderpos>9990/5) encoderpos=9990/5;
  687. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
  688. }
  689. }
  690. }break;
  691. case ItemC_PID_I:
  692. {
  693. if(force_lcd_update)
  694. {
  695. lcd.setCursor(0,line);lcdprintPGM(" PID-I: ");
  696. lcd.setCursor(13,line);lcd.print(ftostr51(Ki));
  697. }
  698. if((activeline==line) )
  699. {
  700. if(CLICKED)
  701. {
  702. linechanging=!linechanging;
  703. if(linechanging)
  704. {
  705. encoderpos=(int)(Ki*10);
  706. }
  707. else
  708. {
  709. Ki= encoderpos/10.;
  710. encoderpos=activeline*lcdslow;
  711. }
  712. BLOCK;
  713. beepshort();
  714. }
  715. if(linechanging)
  716. {
  717. if(encoderpos<0) encoderpos=0;
  718. if(encoderpos>9990) encoderpos=9990;
  719. lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.));
  720. }
  721. }
  722. }break;
  723. case ItemC_PID_D:
  724. {
  725. if(force_lcd_update)
  726. {
  727. lcd.setCursor(0,line);lcdprintPGM(" PID-D: ");
  728. lcd.setCursor(13,line);lcd.print(itostr4(Kd));
  729. }
  730. if((activeline==line) )
  731. {
  732. if(CLICKED)
  733. {
  734. linechanging=!linechanging;
  735. if(linechanging)
  736. {
  737. encoderpos=(int)Kd/5;
  738. }
  739. else
  740. {
  741. Kd= encoderpos*5;
  742. encoderpos=activeline*lcdslow;
  743. }
  744. BLOCK;
  745. beepshort();
  746. }
  747. if(linechanging)
  748. {
  749. if(encoderpos<0) encoderpos=0;
  750. if(encoderpos>9990/5) encoderpos=9990/5;
  751. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
  752. }
  753. }
  754. }break;
  755. case ItemC_PID_C:
  756. {
  757. if(force_lcd_update)
  758. {
  759. lcd.setCursor(0,line);lcdprintPGM(" PID-C: ");
  760. lcd.setCursor(13,line);lcd.print(itostr3(Kc));
  761. }
  762. if((activeline==line) )
  763. {
  764. if(CLICKED)
  765. {
  766. linechanging=!linechanging;
  767. if(linechanging)
  768. {
  769. encoderpos=(int)Kc;
  770. }
  771. else
  772. {
  773. Kc= encoderpos;
  774. encoderpos=activeline*lcdslow;
  775. }
  776. BLOCK;
  777. beepshort();
  778. }
  779. if(linechanging)
  780. {
  781. if(encoderpos<0) encoderpos=0;
  782. if(encoderpos>990) encoderpos=990;
  783. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  784. }
  785. }
  786. }break;
  787. case ItemC_vmaxx:
  788. case ItemC_vmaxy:
  789. case ItemC_vmaxz:
  790. case ItemC_vmaxe:
  791. {
  792. if(force_lcd_update)
  793. {
  794. lcd.setCursor(0,line);lcdprintPGM(" Vmax ");
  795. if(i==ItemC_vmaxx)lcdprintPGM("x:");
  796. if(i==ItemC_vmaxy)lcdprintPGM("y:");
  797. if(i==ItemC_vmaxz)lcdprintPGM("z:");
  798. if(i==ItemC_vmaxe)lcdprintPGM("e:");
  799. lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemC_vmaxx]/60));
  800. }
  801. if((activeline==line) )
  802. {
  803. if(CLICKED)
  804. {
  805. linechanging=!linechanging;
  806. if(linechanging)
  807. {
  808. encoderpos=(int)max_feedrate[i-ItemC_vmaxx]/60;
  809. }
  810. else
  811. {
  812. max_feedrate[i-ItemC_vmaxx]= encoderpos*60;
  813. encoderpos=activeline*lcdslow;
  814. }
  815. BLOCK;
  816. beepshort();
  817. }
  818. if(linechanging)
  819. {
  820. if(encoderpos<1) encoderpos=1;
  821. if(encoderpos>990) encoderpos=990;
  822. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  823. }
  824. }
  825. }break;
  826. case ItemC_vmin:
  827. {
  828. if(force_lcd_update)
  829. {
  830. lcd.setCursor(0,line);lcdprintPGM(" Vmin:");
  831. lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate/60));
  832. }
  833. if((activeline==line) )
  834. {
  835. if(CLICKED)
  836. {
  837. linechanging=!linechanging;
  838. if(linechanging)
  839. {
  840. encoderpos=(int)(minimumfeedrate/60.);
  841. }
  842. else
  843. {
  844. minimumfeedrate= encoderpos*60;
  845. encoderpos=activeline*lcdslow;
  846. }
  847. BLOCK;
  848. beepshort();
  849. }
  850. if(linechanging)
  851. {
  852. if(encoderpos<0) encoderpos=0;
  853. if(encoderpos>990) encoderpos=990;
  854. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  855. }
  856. }
  857. }break;
  858. case ItemC_vtravmin:
  859. {
  860. if(force_lcd_update)
  861. {
  862. lcd.setCursor(0,line);lcdprintPGM(" VTrav min:");
  863. lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate/60));
  864. }
  865. if((activeline==line) )
  866. {
  867. if(CLICKED)
  868. {
  869. linechanging=!linechanging;
  870. if(linechanging)
  871. {
  872. encoderpos=(int)mintravelfeedrate/60;
  873. }
  874. else
  875. {
  876. mintravelfeedrate= encoderpos*60;
  877. encoderpos=activeline*lcdslow;
  878. }
  879. BLOCK;
  880. beepshort();
  881. }
  882. if(linechanging)
  883. {
  884. if(encoderpos<0) encoderpos=0;
  885. if(encoderpos>990) encoderpos=990;
  886. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  887. }
  888. }
  889. }break;
  890. case ItemC_amaxx:
  891. case ItemC_amaxy:
  892. case ItemC_amaxz:
  893. case ItemC_amaxe:
  894. {
  895. if(force_lcd_update)
  896. {
  897. lcd.setCursor(0,line);lcdprintPGM(" Amax ");
  898. if(i==ItemC_amaxx)lcdprintPGM("x:");
  899. if(i==ItemC_amaxy)lcdprintPGM("y:");
  900. if(i==ItemC_amaxz)lcdprintPGM("z:");
  901. if(i==ItemC_amaxe)lcdprintPGM("e:");
  902. lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemC_amaxx]/100));lcdprintPGM("00");
  903. }
  904. if((activeline==line) )
  905. {
  906. if(CLICKED)
  907. {
  908. linechanging=!linechanging;
  909. if(linechanging)
  910. {
  911. encoderpos=(int)max_acceleration_units_per_sq_second[i-ItemC_amaxx]/100;
  912. }
  913. else
  914. {
  915. max_acceleration_units_per_sq_second[i-ItemC_amaxx]= encoderpos*100;
  916. encoderpos=activeline*lcdslow;
  917. }
  918. BLOCK;
  919. beepshort();
  920. }
  921. if(linechanging)
  922. {
  923. if(encoderpos<1) encoderpos=1;
  924. if(encoderpos>990) encoderpos=990;
  925. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  926. }
  927. }
  928. }break;
  929. case ItemC_aret://float retract_acceleration = 7000;
  930. {
  931. if(force_lcd_update)
  932. {
  933. lcd.setCursor(0,line);lcdprintPGM(" A-retract:");
  934. lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcdprintPGM("00");
  935. }
  936. if((activeline==line) )
  937. {
  938. if(CLICKED)
  939. {
  940. linechanging=!linechanging;
  941. if(linechanging)
  942. {
  943. encoderpos=(int)retract_acceleration/100;
  944. }
  945. else
  946. {
  947. retract_acceleration= encoderpos*100;
  948. encoderpos=activeline*lcdslow;
  949. }
  950. BLOCK;
  951. beepshort();
  952. }
  953. if(linechanging)
  954. {
  955. if(encoderpos<10) encoderpos=10;
  956. if(encoderpos>990) encoderpos=990;
  957. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  958. }
  959. }
  960. }break;
  961. case ItemC_esteps://axis_steps_per_unit[i] = code_value();
  962. {
  963. if(force_lcd_update)
  964. {
  965. lcd.setCursor(0,line);lcdprintPGM(" Esteps/mm:");
  966. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3]));
  967. }
  968. if((activeline==line) )
  969. {
  970. if(CLICKED)
  971. {
  972. linechanging=!linechanging;
  973. if(linechanging)
  974. {
  975. encoderpos=(int)axis_steps_per_unit[3];
  976. }
  977. else
  978. {
  979. float factor=float(encoderpos)/float(axis_steps_per_unit[3]);
  980. position[E_AXIS]=lround(position[E_AXIS]*factor);
  981. //current_position[3]*=factor;
  982. axis_steps_per_unit[E_AXIS]= encoderpos;
  983. encoderpos=activeline*lcdslow;
  984. }
  985. BLOCK;
  986. beepshort();
  987. }
  988. if(linechanging)
  989. {
  990. if(encoderpos<5) encoderpos=5;
  991. if(encoderpos>9999) encoderpos=9999;
  992. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  993. }
  994. }
  995. }break;
  996. case ItemC_store:
  997. {
  998. if(force_lcd_update)
  999. {
  1000. lcd.setCursor(0,line);lcdprintPGM(" Store EPROM");
  1001. }
  1002. if((activeline==line) && CLICKED)
  1003. {
  1004. //enquecommand("M84");
  1005. beepshort();
  1006. BLOCK;
  1007. StoreSettings();
  1008. }
  1009. }break;
  1010. case ItemC_load:
  1011. {
  1012. if(force_lcd_update)
  1013. {
  1014. lcd.setCursor(0,line);lcdprintPGM(" Load EPROM");
  1015. }
  1016. if((activeline==line) && CLICKED)
  1017. {
  1018. //enquecommand("M84");
  1019. beepshort();
  1020. BLOCK;
  1021. RetrieveSettings();
  1022. }
  1023. }break;
  1024. case ItemC_failsafe:
  1025. {
  1026. if(force_lcd_update)
  1027. {
  1028. lcd.setCursor(0,line);lcdprintPGM(" Restore Failsafe");
  1029. }
  1030. if((activeline==line) && CLICKED)
  1031. {
  1032. //enquecommand("M84");
  1033. beepshort();
  1034. BLOCK;
  1035. RetrieveSettings(true);
  1036. }
  1037. }break;
  1038. default:
  1039. break;
  1040. }
  1041. line++;
  1042. }
  1043. lastlineoffset=lineoffset;
  1044. if(!linechanging && ((encoderpos/lcdslow!=lastencoderpos/lcdslow)||force_lcd_update))
  1045. {
  1046. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?' ':' ');
  1047. if(encoderpos<0)
  1048. {
  1049. lineoffset--;
  1050. if(lineoffset<0)
  1051. lineoffset=0;
  1052. encoderpos=0;
  1053. force_lcd_update=true;
  1054. }
  1055. if(encoderpos/lcdslow>3)
  1056. {
  1057. lineoffset++;
  1058. encoderpos=3*lcdslow;
  1059. if(lineoffset>(ItemC_failsafe+1-LCD_HEIGHT))
  1060. lineoffset=ItemC_failsafe+1-LCD_HEIGHT;
  1061. force_lcd_update=true;
  1062. }
  1063. //encoderpos=encoderpos%LCD_HEIGHT;
  1064. lastencoderpos=encoderpos;
  1065. activeline=encoderpos/lcdslow;
  1066. if(activeline>3) activeline=3;
  1067. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003');
  1068. }
  1069. }
  1070. void MainMenu::showSD()
  1071. {
  1072. #ifdef SDSUPPORT
  1073. uint8_t line=0;
  1074. if(lastlineoffset!=lineoffset)
  1075. {
  1076. force_lcd_update=true;
  1077. }
  1078. static uint8_t nrfiles=0;
  1079. if(force_lcd_update)
  1080. {
  1081. clear();
  1082. if(card.cardOK)
  1083. {
  1084. nrfiles=card.getnrfilenames();
  1085. }
  1086. else
  1087. {
  1088. nrfiles=0;
  1089. lineoffset=0;
  1090. }
  1091. //Serial.print("Nr files:"); Serial.println((int)nrfiles);
  1092. }
  1093. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1094. {
  1095. switch(i)
  1096. {
  1097. case 0:
  1098. {
  1099. if(force_lcd_update)
  1100. {
  1101. lcd.setCursor(0,line);lcdprintPGM(" File");
  1102. }
  1103. if((activeline==line) && CLICKED)
  1104. {
  1105. BLOCK
  1106. status=Main_Menu;
  1107. beepshort();
  1108. }
  1109. }break;
  1110. case 1:
  1111. {
  1112. if(force_lcd_update)
  1113. {
  1114. lcd.setCursor(0,line);
  1115. #ifdef CARDINSERTED
  1116. if(CARDINSERTED)
  1117. #else
  1118. if(true)
  1119. #endif
  1120. {
  1121. lcdprintPGM(" \004Refresh");
  1122. }
  1123. else
  1124. {
  1125. lcdprintPGM(" \004Insert Card");
  1126. }
  1127. }
  1128. if((activeline==line) && CLICKED)
  1129. {
  1130. BLOCK;
  1131. beepshort();
  1132. card.initsd();
  1133. force_lcd_update=true;
  1134. nrfiles=card.getnrfilenames();
  1135. }
  1136. }break;
  1137. default:
  1138. {
  1139. if(i-2<nrfiles)
  1140. {
  1141. if(force_lcd_update)
  1142. {
  1143. card.getfilename(i-2);
  1144. //Serial.print("Filenr:");Serial.println(i-2);
  1145. lcd.setCursor(0,line);lcdprintPGM(" ");lcd.print(card.filename);
  1146. }
  1147. if((activeline==line) && CLICKED)
  1148. {
  1149. BLOCK
  1150. card.getfilename(i-2);
  1151. char cmd[30];
  1152. for(int8_t i=0;i<strlen(card.filename);i++)
  1153. card.filename[i]=tolower(card.filename[i]);
  1154. sprintf(cmd,"M23 %s",card.filename);
  1155. //sprintf(cmd,"M115");
  1156. enquecommand(cmd);
  1157. enquecommand("M24");
  1158. beep();
  1159. status=Main_Status;
  1160. lcd_status(card.filename);
  1161. }
  1162. }
  1163. }
  1164. break;
  1165. }
  1166. line++;
  1167. }
  1168. lastlineoffset=lineoffset;
  1169. if((encoderpos!=lastencoderpos)||force_lcd_update)
  1170. {
  1171. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?' ':' ');
  1172. if(encoderpos<0)
  1173. {
  1174. lineoffset--;
  1175. if(lineoffset<0)
  1176. lineoffset=0;
  1177. encoderpos=0;
  1178. force_lcd_update=true;
  1179. }
  1180. if(encoderpos/lcdslow>3)
  1181. {
  1182. lineoffset++;
  1183. encoderpos=3*lcdslow;
  1184. if(lineoffset>(1+nrfiles+1-LCD_HEIGHT))
  1185. lineoffset=1+nrfiles+1-LCD_HEIGHT;
  1186. force_lcd_update=true;
  1187. }
  1188. lastencoderpos=encoderpos;
  1189. activeline=encoderpos;
  1190. if(activeline>3)
  1191. {
  1192. activeline=3;
  1193. }
  1194. if(activeline<0)
  1195. {
  1196. activeline=0;
  1197. }
  1198. if(activeline>1+nrfiles) activeline=1+nrfiles;
  1199. if(lineoffset>1+nrfiles) lineoffset=1+nrfiles;
  1200. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003');
  1201. }
  1202. #endif
  1203. }
  1204. enum {ItemM_watch, ItemM_prepare, ItemM_control, ItemM_file };
  1205. void MainMenu::showMainMenu()
  1206. {
  1207. //if(int(encoderpos/lcdslow)!=int(lastencoderpos/lcdslow))
  1208. // force_lcd_update=true;
  1209. #ifndef ULTIPANEL
  1210. force_lcd_update=false;
  1211. #endif
  1212. //Serial.println((int)activeline);
  1213. if(force_lcd_update)
  1214. clear();
  1215. for(int8_t line=0;line<LCD_HEIGHT;line++)
  1216. {
  1217. switch(line)
  1218. {
  1219. case ItemM_watch:
  1220. {
  1221. if(force_lcd_update) {lcd.setCursor(0,line);lcdprintPGM(" Watch \x7E");}
  1222. if((activeline==line)&&CLICKED)
  1223. {
  1224. BLOCK;
  1225. beepshort();
  1226. status=Main_Status;
  1227. }
  1228. } break;
  1229. case ItemM_prepare:
  1230. {
  1231. if(force_lcd_update) {lcd.setCursor(0,line);lcdprintPGM(" Prepare \x7E");}
  1232. if((activeline==line)&&CLICKED)
  1233. {
  1234. BLOCK;
  1235. status=Main_Prepare;
  1236. beepshort();
  1237. }
  1238. } break;
  1239. case ItemM_control:
  1240. {
  1241. if(force_lcd_update) {lcd.setCursor(0,line);lcdprintPGM(" Control \x7E");}
  1242. if((activeline==line)&&CLICKED)
  1243. {
  1244. BLOCK;
  1245. status=Main_Control;
  1246. beepshort();
  1247. }
  1248. }break;
  1249. #ifdef SDSUPPORT
  1250. case ItemM_file:
  1251. {
  1252. if(force_lcd_update)
  1253. {
  1254. lcd.setCursor(0,line);
  1255. #ifdef CARDINSERTED
  1256. if(CARDINSERTED)
  1257. #else
  1258. if(true)
  1259. #endif
  1260. {
  1261. if(card.sdprinting)
  1262. lcdprintPGM(" Stop Print \x7E");
  1263. else
  1264. lcdprintPGM(" Card Menu \x7E");
  1265. }
  1266. else
  1267. {
  1268. lcdprintPGM(" No Card");
  1269. }
  1270. }
  1271. #ifdef CARDINSERTED
  1272. if(CARDINSERTED)
  1273. #endif
  1274. if((activeline==line)&&CLICKED)
  1275. {
  1276. card.sdprinting = false;
  1277. BLOCK;
  1278. status=Main_SD;
  1279. beepshort();
  1280. }
  1281. }break;
  1282. #endif
  1283. default:
  1284. SERIAL_ERROR_START;
  1285. SERIAL_ERRORLNPGM("Something is wrong in the MenuStructure.");
  1286. break;
  1287. }
  1288. }
  1289. if(activeline<0)
  1290. activeline=0;
  1291. if(activeline>=LCD_HEIGHT)
  1292. activeline=LCD_HEIGHT-1;
  1293. if((encoderpos!=lastencoderpos)||force_lcd_update)
  1294. {
  1295. lcd.setCursor(0,activeline);lcd.print(activeline?' ':' ');
  1296. if(encoderpos<0) encoderpos=0;
  1297. if(encoderpos>3*lcdslow)
  1298. encoderpos=3*lcdslow;
  1299. activeline=abs(encoderpos/lcdslow)%LCD_HEIGHT;
  1300. if(activeline<0)
  1301. activeline=0;
  1302. if(activeline>=LCD_HEIGHT)
  1303. activeline=LCD_HEIGHT-1;
  1304. lastencoderpos=encoderpos;
  1305. lcd.setCursor(0,activeline);lcd.print(activeline?'>':'\003');
  1306. }
  1307. }
  1308. void MainMenu::update()
  1309. {
  1310. static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
  1311. static long timeoutToStatus=0;
  1312. static bool oldcardstatus=false;
  1313. #ifdef CARDINSERTED
  1314. if((CARDINSERTED != oldcardstatus))
  1315. {
  1316. force_lcd_update=true;
  1317. oldcardstatus=CARDINSERTED;
  1318. //Serial.println("echo: SD CHANGE");
  1319. if(CARDINSERTED)
  1320. {
  1321. card.initsd();
  1322. lcd_status("Card inserted");
  1323. }
  1324. else
  1325. {
  1326. card.release();
  1327. lcd_status("Card removed");
  1328. }
  1329. }
  1330. #endif
  1331. if(status!=oldstatus)
  1332. {
  1333. //Serial.println(status);
  1334. //clear();
  1335. force_lcd_update=true;
  1336. encoderpos=0;
  1337. lineoffset=0;
  1338. oldstatus=status;
  1339. }
  1340. if( (encoderpos!=lastencoderpos) || CLICKED)
  1341. timeoutToStatus=millis()+STATUSTIMEOUT;
  1342. switch(status)
  1343. {
  1344. case Main_Status:
  1345. {
  1346. showStatus();
  1347. if(CLICKED)
  1348. {
  1349. linechanging=false;
  1350. BLOCK
  1351. status=Main_Menu;
  1352. timeoutToStatus=millis()+STATUSTIMEOUT;
  1353. }
  1354. }break;
  1355. case Main_Menu:
  1356. {
  1357. showMainMenu();
  1358. linechanging=false;
  1359. }break;
  1360. case Main_Prepare:
  1361. {
  1362. showPrepare();
  1363. }break;
  1364. case Main_Control:
  1365. {
  1366. showControl();
  1367. }break;
  1368. case Main_SD:
  1369. {
  1370. showSD();
  1371. }break;
  1372. }
  1373. if(timeoutToStatus<millis())
  1374. status=Main_Status;
  1375. force_lcd_update=false;
  1376. lastencoderpos=encoderpos;
  1377. }
  1378. // convert float to string with +123.4 format
  1379. char *ftostr3(const float &x)
  1380. {
  1381. //sprintf(conv,"%5.1f",x);
  1382. int xx=x;
  1383. conv[0]=(xx/100)%10+'0';
  1384. conv[1]=(xx/10)%10+'0';
  1385. conv[2]=(xx)%10+'0';
  1386. conv[3]=0;
  1387. return conv;
  1388. }
  1389. char *itostr2(const uint8_t &x)
  1390. {
  1391. //sprintf(conv,"%5.1f",x);
  1392. int xx=x;
  1393. conv[0]=(xx/10)%10+'0';
  1394. conv[1]=(xx)%10+'0';
  1395. conv[2]=0;
  1396. return conv;
  1397. }
  1398. // convert float to string with +123.4 format
  1399. char *ftostr31(const float &x)
  1400. {
  1401. int xx=x*10;
  1402. conv[0]=(xx>=0)?'+':'-';
  1403. xx=abs(xx);
  1404. conv[1]=(xx/1000)%10+'0';
  1405. conv[2]=(xx/100)%10+'0';
  1406. conv[3]=(xx/10)%10+'0';
  1407. conv[4]='.';
  1408. conv[5]=(xx)%10+'0';
  1409. conv[6]=0;
  1410. return conv;
  1411. }
  1412. char *itostr31(const int &xx)
  1413. {
  1414. conv[0]=(xx>=0)?'+':'-';
  1415. conv[1]=(xx/1000)%10+'0';
  1416. conv[2]=(xx/100)%10+'0';
  1417. conv[3]=(xx/10)%10+'0';
  1418. conv[4]='.';
  1419. conv[5]=(xx)%10+'0';
  1420. conv[6]=0;
  1421. return conv;
  1422. }
  1423. char *itostr3(const int &xx)
  1424. {
  1425. conv[0]=(xx/100)%10+'0';
  1426. conv[1]=(xx/10)%10+'0';
  1427. conv[2]=(xx)%10+'0';
  1428. conv[3]=0;
  1429. return conv;
  1430. }
  1431. char *itostr4(const int &xx)
  1432. {
  1433. conv[0]=(xx/1000)%10+'0';
  1434. conv[1]=(xx/100)%10+'0';
  1435. conv[2]=(xx/10)%10+'0';
  1436. conv[3]=(xx)%10+'0';
  1437. conv[4]=0;
  1438. return conv;
  1439. }
  1440. // convert float to string with +1234.5 format
  1441. char *ftostr51(const float &x)
  1442. {
  1443. int xx=x*10;
  1444. conv[0]=(xx>=0)?'+':'-';
  1445. xx=abs(xx);
  1446. conv[1]=(xx/10000)%10+'0';
  1447. conv[2]=(xx/1000)%10+'0';
  1448. conv[3]=(xx/100)%10+'0';
  1449. conv[4]=(xx/10)%10+'0';
  1450. conv[5]='.';
  1451. conv[6]=(xx)%10+'0';
  1452. conv[7]=0;
  1453. return conv;
  1454. }
  1455. char *fillto(int8_t n,char *c)
  1456. {
  1457. static char ret[25];
  1458. bool endfound=false;
  1459. for(int8_t i=0;i<n;i++)
  1460. {
  1461. ret[i]=c[i];
  1462. if(c[i]==0)
  1463. {
  1464. endfound=true;
  1465. }
  1466. if(endfound)
  1467. {
  1468. ret[i]=' ';
  1469. }
  1470. }
  1471. ret[n]=0;
  1472. return ret;
  1473. }
  1474. #endif //ULTRA_LCD