My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ultralcd.pde 41KB

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