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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285
  1. #include "ultralcd.h"
  2. #ifdef ULTRA_LCD
  3. #include "Marlin.h"
  4. #include <LiquidCrystal.h>
  5. //===========================================================================
  6. //=============================imported variables============================
  7. //===========================================================================
  8. extern volatile int feedmultiply;
  9. extern volatile bool feedmultiplychanged;
  10. extern volatile int extrudemultiply;
  11. extern long position[4];
  12. #ifdef SDSUPPORT
  13. extern CardReader card;
  14. #endif
  15. //===========================================================================
  16. //=============================public variables============================
  17. //===========================================================================
  18. volatile char buttons=0; //the last checked buttons in a bit array.
  19. int encoderpos=0;
  20. short lastenc=0;
  21. //===========================================================================
  22. //=============================private variables============================
  23. //===========================================================================
  24. static char messagetext[LCD_WIDTH]="";
  25. //return for string conversion routines
  26. static char conv[8];
  27. 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
  28. static unsigned long previous_millis_lcd=0;
  29. //static long previous_millis_buttons=0;
  30. #ifdef NEWPANEL
  31. static long blocking=0;
  32. #else
  33. static long blocking[8]={0,0,0,0,0,0,0,0};
  34. #endif
  35. static MainMenu menu;
  36. void lcdProgMemprint(const char *str)
  37. {
  38. char ch=pgm_read_byte(str);
  39. while(ch)
  40. {
  41. lcd.print(ch);
  42. ch=pgm_read_byte(++str);
  43. }
  44. }
  45. #define lcdprintPGM(x) lcdProgMemprint(MYPGM(x))
  46. //===========================================================================
  47. //=============================functions ============================
  48. //===========================================================================
  49. int intround(const float &x){return int(0.5+x);}
  50. void lcd_status(const char* message)
  51. {
  52. strncpy(messagetext,message,LCD_WIDTH);
  53. messagetext[strlen(message)]=0;
  54. }
  55. void lcd_statuspgm(const char* message)
  56. {
  57. char ch=pgm_read_byte(message);
  58. char *target=messagetext;
  59. uint8_t cnt=0;
  60. while(ch &&cnt<LCD_WIDTH)
  61. {
  62. *target=ch;
  63. target++;
  64. cnt++;
  65. ch=pgm_read_byte(++message);
  66. }
  67. *target=0;
  68. }
  69. FORCE_INLINE void clear()
  70. {
  71. lcd.clear();
  72. }
  73. void lcd_init()
  74. {
  75. //beep();
  76. byte Degree[8] =
  77. {
  78. B01100,
  79. B10010,
  80. B10010,
  81. B01100,
  82. B00000,
  83. B00000,
  84. B00000,
  85. B00000
  86. };
  87. byte Thermometer[8] =
  88. {
  89. B00100,
  90. B01010,
  91. B01010,
  92. B01010,
  93. B01010,
  94. B10001,
  95. B10001,
  96. B01110
  97. };
  98. byte uplevel[8]={0x04, 0x0e, 0x1f, 0x04, 0x1c, 0x00, 0x00, 0x00};//thanks joris
  99. byte refresh[8]={0x00, 0x06, 0x19, 0x18, 0x03, 0x13, 0x0c, 0x00}; //thanks joris
  100. byte folder [8]={0x00, 0x1c, 0x1f, 0x11, 0x11, 0x1f, 0x00, 0x00}; //thanks joris
  101. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  102. lcd.createChar(1,Degree);
  103. lcd.createChar(2,Thermometer);
  104. lcd.createChar(3,uplevel);
  105. lcd.createChar(4,refresh);
  106. lcd.createChar(5,folder);
  107. LCD_MESSAGEPGM(WELCOME_MSG);
  108. }
  109. void beep()
  110. {
  111. //return;
  112. #ifdef ULTIPANEL
  113. #if (BEEPER > -1)
  114. {
  115. pinMode(BEEPER,OUTPUT);
  116. for(int8_t i=0;i<20;i++){
  117. WRITE(BEEPER,HIGH);
  118. delay(5);
  119. WRITE(BEEPER,LOW);
  120. delay(5);
  121. }
  122. }
  123. #endif
  124. #endif
  125. }
  126. void beepshort()
  127. {
  128. //return;
  129. #ifdef ULTIPANEL
  130. #if (BEEPER > -1)
  131. {
  132. pinMode(BEEPER,OUTPUT);
  133. for(int8_t i=0;i<10;i++){
  134. WRITE(BEEPER,HIGH);
  135. delay(3);
  136. WRITE(BEEPER,LOW);
  137. delay(3);
  138. }
  139. }
  140. #endif
  141. #endif
  142. }
  143. void lcd_status()
  144. {
  145. #ifdef ULTIPANEL
  146. static uint8_t oldbuttons=0;
  147. //static long previous_millis_buttons=0;
  148. //static long previous_lcdinit=0;
  149. // buttons_check(); // Done in temperature interrupt
  150. //previous_millis_buttons=millis();
  151. long ms=millis();
  152. for(int8_t i=0; i<8; i++) {
  153. #ifndef NEWPANEL
  154. if((blocking[i]>ms))
  155. buttons &= ~(1<<i);
  156. #else
  157. if((blocking>ms))
  158. buttons &= ~(1<<i);
  159. #endif
  160. }
  161. if((buttons==oldbuttons) && ((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
  162. return;
  163. oldbuttons=buttons;
  164. #else
  165. if(((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
  166. return;
  167. #endif
  168. previous_millis_lcd=millis();
  169. menu.update();
  170. }
  171. #ifdef ULTIPANEL
  172. void buttons_init()
  173. {
  174. #ifdef NEWPANEL
  175. pinMode(BTN_EN1,INPUT);
  176. pinMode(BTN_EN2,INPUT);
  177. pinMode(BTN_ENC,INPUT);
  178. pinMode(SDCARDDETECT,INPUT);
  179. WRITE(BTN_EN1,HIGH);
  180. WRITE(BTN_EN2,HIGH);
  181. WRITE(BTN_ENC,HIGH);
  182. #if (SDCARDDETECT > -1)
  183. {
  184. WRITE(SDCARDDETECT,HIGH);
  185. }
  186. #endif
  187. #else
  188. pinMode(SHIFT_CLK,OUTPUT);
  189. pinMode(SHIFT_LD,OUTPUT);
  190. pinMode(SHIFT_EN,OUTPUT);
  191. pinMode(SHIFT_OUT,INPUT);
  192. WRITE(SHIFT_OUT,HIGH);
  193. WRITE(SHIFT_LD,HIGH);
  194. WRITE(SHIFT_EN,LOW);
  195. #endif
  196. }
  197. void buttons_check()
  198. {
  199. #ifdef NEWPANEL
  200. uint8_t newbutton=0;
  201. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  202. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  203. if((blocking<millis()) &&(READ(BTN_ENC)==0))
  204. newbutton|=EN_C;
  205. buttons=newbutton;
  206. #else //read it from the shift register
  207. uint8_t newbutton=0;
  208. WRITE(SHIFT_LD,LOW);
  209. WRITE(SHIFT_LD,HIGH);
  210. unsigned char tmp_buttons=0;
  211. for(int8_t i=0;i<8;i++)
  212. {
  213. newbutton = newbutton>>1;
  214. if(READ(SHIFT_OUT))
  215. newbutton|=(1<<7);
  216. WRITE(SHIFT_CLK,HIGH);
  217. WRITE(SHIFT_CLK,LOW);
  218. }
  219. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  220. #endif
  221. //manage encoder rotation
  222. char enc=0;
  223. if(buttons&EN_A)
  224. enc|=(1<<0);
  225. if(buttons&EN_B)
  226. enc|=(1<<1);
  227. if(enc!=lastenc)
  228. {
  229. switch(enc)
  230. {
  231. case encrot0:
  232. if(lastenc==encrot3)
  233. encoderpos++;
  234. else if(lastenc==encrot1)
  235. encoderpos--;
  236. break;
  237. case encrot1:
  238. if(lastenc==encrot0)
  239. encoderpos++;
  240. else if(lastenc==encrot2)
  241. encoderpos--;
  242. break;
  243. case encrot2:
  244. if(lastenc==encrot1)
  245. encoderpos++;
  246. else if(lastenc==encrot3)
  247. encoderpos--;
  248. break;
  249. case encrot3:
  250. if(lastenc==encrot2)
  251. encoderpos++;
  252. else if(lastenc==encrot0)
  253. encoderpos--;
  254. break;
  255. default:
  256. ;
  257. }
  258. }
  259. lastenc=enc;
  260. }
  261. #endif
  262. MainMenu::MainMenu()
  263. {
  264. status=Main_Status;
  265. displayStartingRow=0;
  266. activeline=0;
  267. force_lcd_update=true;
  268. #ifdef ULTIPANEL
  269. buttons_init();
  270. #endif
  271. lcd_init();
  272. linechanging=false;
  273. tune=false;
  274. }
  275. void MainMenu::showStatus()
  276. {
  277. #if LCD_HEIGHT==4
  278. static int olddegHotEnd0=-1;
  279. static int oldtargetHotEnd0=-1;
  280. //force_lcd_update=true;
  281. if(force_lcd_update) //initial display of content
  282. {
  283. encoderpos=feedmultiply;
  284. clear();
  285. lcd.setCursor(0,0);lcdprintPGM("\002---/---\001 ");
  286. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  287. lcd.setCursor(10,0);lcdprintPGM("B---/---\001 ");
  288. #endif
  289. }
  290. int tHotEnd0=intround(degHotend0());
  291. if((tHotEnd0!=olddegHotEnd0)||force_lcd_update)
  292. {
  293. lcd.setCursor(1,0);
  294. lcd.print(ftostr3(tHotEnd0));
  295. olddegHotEnd0=tHotEnd0;
  296. }
  297. int ttHotEnd0=intround(degTargetHotend0());
  298. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  299. {
  300. lcd.setCursor(5,0);
  301. lcd.print(ftostr3(ttHotEnd0));
  302. oldtargetHotEnd0=ttHotEnd0;
  303. }
  304. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  305. static int oldtBed=-1;
  306. static int oldtargetBed=-1;
  307. int tBed=intround(degBed());
  308. if((tBed!=oldtBed)||force_lcd_update)
  309. {
  310. lcd.setCursor(11,0);
  311. lcd.print(ftostr3(tBed));
  312. oldtBed=tBed;
  313. }
  314. int targetBed=intround(degTargetBed());
  315. if((targetBed!=oldtargetBed)||force_lcd_update)
  316. {
  317. lcd.setCursor(15,0);
  318. lcd.print(ftostr3(targetBed));
  319. oldtargetBed=targetBed;
  320. }
  321. #endif
  322. //starttime=2;
  323. static uint16_t oldtime=0;
  324. if(starttime!=0)
  325. {
  326. lcd.setCursor(0,1);
  327. uint16_t time=millis()/60000-starttime/60000;
  328. if(starttime!=oldtime)
  329. {
  330. lcd.print(itostr2(time/60));lcdprintPGM("h ");lcd.print(itostr2(time%60));lcdprintPGM("m");
  331. oldtime=time;
  332. }
  333. }
  334. static int oldzpos=0;
  335. int currentz=current_position[2]*100;
  336. if((currentz!=oldzpos)||force_lcd_update)
  337. {
  338. lcd.setCursor(10,1);
  339. lcdprintPGM("Z:");lcd.print(ftostr52(current_position[2]));
  340. oldzpos=currentz;
  341. }
  342. static int oldfeedmultiply=0;
  343. int curfeedmultiply=feedmultiply;
  344. if(feedmultiplychanged == true) {
  345. feedmultiplychanged = false;
  346. encoderpos = curfeedmultiply;
  347. }
  348. if(encoderpos!=curfeedmultiply||force_lcd_update)
  349. {
  350. curfeedmultiply=encoderpos;
  351. if(curfeedmultiply<10)
  352. curfeedmultiply=10;
  353. if(curfeedmultiply>999)
  354. curfeedmultiply=999;
  355. feedmultiply=curfeedmultiply;
  356. encoderpos=curfeedmultiply;
  357. }
  358. if((curfeedmultiply!=oldfeedmultiply)||force_lcd_update)
  359. {
  360. oldfeedmultiply=curfeedmultiply;
  361. lcd.setCursor(0,2);
  362. lcd.print(itostr3(curfeedmultiply));lcdprintPGM("% ");
  363. }
  364. if(messagetext[0]!='\0')
  365. {
  366. lcd.setCursor(0,LCD_HEIGHT-1);
  367. lcd.print(messagetext);
  368. uint8_t n=strlen(messagetext);
  369. for(int8_t i=0;i<LCD_WIDTH-n;i++)
  370. lcd.print(" ");
  371. messagetext[0]='\0';
  372. }
  373. #ifdef SDSUPPORT
  374. static uint8_t oldpercent=101;
  375. uint8_t percent=card.percentDone();
  376. if(oldpercent!=percent ||force_lcd_update)
  377. {
  378. lcd.setCursor(10,2);
  379. lcd.print(itostr3((int)percent));
  380. lcdprintPGM("%SD");
  381. }
  382. #endif
  383. #else //smaller LCDS----------------------------------
  384. static int olddegHotEnd0=-1;
  385. static int oldtargetHotEnd0=-1;
  386. if(force_lcd_update) //initial display of content
  387. {
  388. encoderpos=feedmultiply;
  389. lcd.setCursor(0,0);lcdprintPGM("\002123/567\001 ");
  390. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  391. lcd.setCursor(10,0);lcdprintPGM("B123/567\001 ");
  392. #endif
  393. }
  394. int tHotEnd0=intround(degHotend0());
  395. int ttHotEnd0=intround(degTargetHotend0());
  396. if((abs(tHotEnd0-olddegHotEnd0)>1)||force_lcd_update)
  397. {
  398. lcd.setCursor(1,0);
  399. lcd.print(ftostr3(tHotEnd0));
  400. olddegHotEnd0=tHotEnd0;
  401. }
  402. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  403. {
  404. lcd.setCursor(5,0);
  405. lcd.print(ftostr3(ttHotEnd0));
  406. oldtargetHotEnd0=ttHotEnd0;
  407. }
  408. if(messagetext[0]!='\0')
  409. {
  410. lcd.setCursor(0,LCD_HEIGHT-1);
  411. lcd.print(messagetext);
  412. uint8_t n=strlen(messagetext);
  413. for(int8_t i=0;i<LCD_WIDTH-n;i++)
  414. lcd.print(" ");
  415. messagetext[0]='\0';
  416. }
  417. #endif
  418. force_lcd_update=false;
  419. }
  420. enum {ItemP_exit, ItemP_autostart,ItemP_disstep,ItemP_home, ItemP_origin, ItemP_preheat_pla, ItemP_preheat_abs, ItemP_cooldown,/*ItemP_extrude,*/ItemP_move};
  421. //any action must not contain a ',' character anywhere, or this breaks:
  422. #define MENUITEM(repaint_action, click_action) \
  423. {\
  424. if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  425. if((activeline==line) && CLICKED) {click_action} \
  426. }
  427. void MainMenu::showPrepare()
  428. {
  429. #ifdef ULTIPANEL
  430. uint8_t line=0;
  431. clearIfNecessary();
  432. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  433. {
  434. //Serial.println((int)(line-lineoffset));
  435. switch(i)
  436. {
  437. case ItemP_exit:
  438. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  439. break;
  440. case ItemP_autostart:
  441. MENUITEM( lcdprintPGM(MSG_AUTOSTART) , BLOCK;
  442. #ifdef SDSUPPORT
  443. card.lastnr=0;card.setroot();card.checkautostart(true);
  444. #endif
  445. beepshort(); ) ;
  446. break;
  447. case ItemP_disstep:
  448. MENUITEM( lcdprintPGM(MSG_DISABLE_STEPPERS) , BLOCK;enquecommand("M84");beepshort(); ) ;
  449. break;
  450. case ItemP_home:
  451. MENUITEM( lcdprintPGM(MSG_AUTO_HOME) , BLOCK;enquecommand("G28");beepshort(); ) ;
  452. break;
  453. case ItemP_origin:
  454. MENUITEM( lcdprintPGM(MSG_SET_ORIGIN) , BLOCK;enquecommand("G92 X0 Y0 Z0");beepshort(); ) ;
  455. break;
  456. case ItemP_preheat_pla:
  457. MENUITEM( lcdprintPGM(MSG_PREHEAT_PLA) , BLOCK;setTargetHotend0(PLA_PREHEAT_HOTEND_TEMP);setTargetBed(PLA_PREHEAT_HPB_TEMP);
  458. #if FAN_PIN > -1
  459. analogWrite(FAN_PIN, PLA_PREHEAT_FAN_SPEED);
  460. #endif
  461. beepshort(); );
  462. break;
  463. case ItemP_preheat_abs:
  464. MENUITEM( lcdprintPGM(MSG_PREHEAT_ABS) , BLOCK;setTargetHotend0(ABS_PREHEAT_HOTEND_TEMP);setTargetBed(ABS_PREHEAT_HPB_TEMP);
  465. #if FAN_PIN > -1
  466. analogWrite(FAN_PIN, ABS_PREHEAT_FAN_SPEED);
  467. #endif
  468. beepshort(); );
  469. break;
  470. case ItemP_cooldown:
  471. MENUITEM( lcdprintPGM(MSG_COOLDOWN) , BLOCK;setTargetHotend0(0);setTargetBed(0);beepshort(); ) ;
  472. break;
  473. // case ItemP_extrude:
  474. // MENUITEM( lcdprintPGM(" Extrude") , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E50");beepshort(); ) ;
  475. // break;
  476. case ItemP_move:
  477. MENUITEM( lcdprintPGM(MSG_MOVE_AXIS) , BLOCK;status=Sub_PrepareMove;beepshort(); );
  478. break;
  479. default:
  480. break;
  481. }
  482. line++;
  483. }
  484. updateActiveLines(ItemP_move,encoderpos);
  485. #endif
  486. }
  487. enum {
  488. ItemAM_exit,
  489. ItemAM_X, ItemAM_Y, ItemAM_Z, ItemAM_E
  490. };
  491. void MainMenu::showAxisMove()
  492. {
  493. uint8_t line=0;
  494. int oldencoderpos=0;
  495. clearIfNecessary();
  496. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  497. {
  498. switch(i)
  499. {
  500. case ItemAM_exit:
  501. MENUITEM( lcdprintPGM(MSG_PREPARE_ALT) , BLOCK;status=Main_Menu;beepshort(); ) ;
  502. break;
  503. case ItemAM_X:
  504. {
  505. //oldencoderpos=0;
  506. if(force_lcd_update)
  507. {
  508. lcd.setCursor(0,line);lcdprintPGM(" X:");
  509. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[X_AXIS]));
  510. }
  511. if((activeline!=line) )
  512. break;
  513. if(CLICKED)
  514. {
  515. linechanging=!linechanging;
  516. if(linechanging)
  517. {
  518. enquecommand("G91");
  519. }
  520. else
  521. {
  522. enquecommand("G90");
  523. encoderpos=activeline*lcdslow;
  524. beepshort();
  525. }
  526. BLOCK;
  527. }
  528. if(linechanging)
  529. {
  530. if (encoderpos >0)
  531. {
  532. enquecommand("G1 F700 X0.1");
  533. oldencoderpos=encoderpos;
  534. encoderpos=0;
  535. }
  536. else if (encoderpos < 0)
  537. {
  538. enquecommand("G1 F700 X-0.1");
  539. oldencoderpos=encoderpos;
  540. encoderpos=0;
  541. }
  542. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[X_AXIS]));
  543. }
  544. }
  545. break;
  546. case ItemAM_Y:
  547. {
  548. if(force_lcd_update)
  549. {
  550. lcd.setCursor(0,line);lcdprintPGM(" Y:");
  551. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Y_AXIS]));
  552. }
  553. if((activeline!=line) )
  554. break;
  555. if(CLICKED)
  556. {
  557. linechanging=!linechanging;
  558. if(linechanging)
  559. {
  560. enquecommand("G91");
  561. }
  562. else
  563. {
  564. enquecommand("G90");
  565. encoderpos=activeline*lcdslow;
  566. beepshort();
  567. }
  568. BLOCK;
  569. }
  570. if(linechanging)
  571. {
  572. if (encoderpos >0)
  573. {
  574. enquecommand("G1 F700 Y0.1");
  575. oldencoderpos=encoderpos;
  576. encoderpos=0;
  577. }
  578. else if (encoderpos < 0)
  579. {
  580. enquecommand("G1 F700 Y-0.1");
  581. oldencoderpos=encoderpos;
  582. encoderpos=0;
  583. }
  584. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Y_AXIS]));
  585. }
  586. }
  587. break;
  588. case ItemAM_Z:
  589. {
  590. if(force_lcd_update)
  591. {
  592. lcd.setCursor(0,line);lcdprintPGM(" Z:");
  593. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Z_AXIS]));
  594. }
  595. if((activeline!=line) )
  596. break;
  597. if(CLICKED)
  598. {
  599. linechanging=!linechanging;
  600. if(linechanging)
  601. {
  602. enquecommand("G91");
  603. }
  604. else
  605. {
  606. enquecommand("G90");
  607. encoderpos=activeline*lcdslow;
  608. beepshort();
  609. }
  610. BLOCK;
  611. }
  612. if(linechanging)
  613. {
  614. if (encoderpos >0)
  615. {
  616. enquecommand("G1 F70 Z0.1");
  617. oldencoderpos=encoderpos;
  618. encoderpos=0;
  619. }
  620. else if (encoderpos < 0)
  621. {
  622. enquecommand("G1 F70 Z-0.1");
  623. oldencoderpos=encoderpos;
  624. encoderpos=0;
  625. }
  626. lcd.setCursor(11,line);lcd.print(ftostr52(current_position[Z_AXIS]));
  627. }
  628. }
  629. break;
  630. case ItemAM_E:
  631. MENUITEM( lcdprintPGM(MSG_EXTRUDE) , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E5");beepshort(); ) ;
  632. break;
  633. default:
  634. break;
  635. }
  636. line++;
  637. }
  638. updateActiveLines(ItemAM_E,encoderpos);
  639. }
  640. enum {ItemT_exit,ItemT_speed,ItemT_flow,ItemT_nozzle,
  641. #if (HEATER_BED_PIN > -1)
  642. ItemT_bed,
  643. #endif
  644. ItemT_fan};
  645. void MainMenu::showTune()
  646. {
  647. uint8_t line=0;
  648. clearIfNecessary();
  649. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  650. {
  651. //Serial.println((int)(line-lineoffset));
  652. switch(i)
  653. {
  654. case ItemT_exit:
  655. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  656. break;
  657. case ItemT_speed:
  658. {
  659. if(force_lcd_update)
  660. {
  661. lcd.setCursor(0,line);lcdprintPGM(MSG_SPEED);
  662. lcd.setCursor(13,line);lcd.print(ftostr3(feedmultiply));
  663. }
  664. if((activeline!=line) )
  665. break;
  666. if(CLICKED) //AnalogWrite(FAN_PIN, fanpwm);
  667. {
  668. linechanging=!linechanging;
  669. if(linechanging)
  670. {
  671. encoderpos=feedmultiply;
  672. }
  673. else
  674. {
  675. encoderpos=activeline*lcdslow;
  676. beepshort();
  677. }
  678. BLOCK;
  679. }
  680. if(linechanging)
  681. {
  682. if(encoderpos<1) encoderpos=1;
  683. if(encoderpos>400) encoderpos=400;
  684. feedmultiply = encoderpos;
  685. feedmultiplychanged=true;
  686. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  687. }
  688. }break;
  689. case ItemT_nozzle:
  690. {
  691. if(force_lcd_update)
  692. {
  693. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE);
  694. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  695. }
  696. if((activeline!=line) )
  697. break;
  698. if(CLICKED)
  699. {
  700. linechanging=!linechanging;
  701. if(linechanging)
  702. {
  703. encoderpos=intround(degTargetHotend0());
  704. }
  705. else
  706. {
  707. setTargetHotend0(encoderpos);
  708. encoderpos=activeline*lcdslow;
  709. beepshort();
  710. }
  711. BLOCK;
  712. }
  713. if(linechanging)
  714. {
  715. if(encoderpos<0) encoderpos=0;
  716. if(encoderpos>260) encoderpos=260;
  717. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  718. }
  719. }break;
  720. #if (HEATER_BED_PIN > -1)
  721. case ItemT_bed:
  722. {
  723. if(force_lcd_update)
  724. {
  725. lcd.setCursor(0,line);lcdprintPGM(MSG_BED);
  726. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  727. }
  728. if((activeline!=line) )
  729. break;
  730. if(CLICKED)
  731. {
  732. linechanging=!linechanging;
  733. if(linechanging)
  734. {
  735. encoderpos=intround(degTargetBed());
  736. }
  737. else
  738. {
  739. setTargetBed(encoderpos);
  740. encoderpos=activeline*lcdslow;
  741. beepshort();
  742. }
  743. BLOCK;
  744. }
  745. if(linechanging)
  746. {
  747. if(encoderpos<0) encoderpos=0;
  748. if(encoderpos>260) encoderpos=260;
  749. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  750. }
  751. }break;
  752. #endif
  753. case ItemT_fan:
  754. {
  755. if(force_lcd_update)
  756. {
  757. lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
  758. lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
  759. }
  760. if((activeline!=line) )
  761. break;
  762. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  763. {
  764. linechanging=!linechanging;
  765. if(linechanging)
  766. {
  767. encoderpos=FanSpeed;
  768. }
  769. else
  770. {
  771. encoderpos=activeline*lcdslow;
  772. beepshort();
  773. }
  774. BLOCK;
  775. }
  776. if(linechanging)
  777. {
  778. if(encoderpos<0) encoderpos=0;
  779. if(encoderpos>255) encoderpos=255;
  780. FanSpeed=encoderpos;
  781. analogWrite(FAN_PIN, FanSpeed);
  782. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  783. }
  784. }break;
  785. case ItemT_flow://axis_steps_per_unit[i] = code_value();
  786. {
  787. if(force_lcd_update)
  788. {
  789. lcd.setCursor(0,line);lcdprintPGM(MSG_FLOW);
  790. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3]));
  791. }
  792. if((activeline!=line) )
  793. break;
  794. if(CLICKED)
  795. {
  796. linechanging=!linechanging;
  797. if(linechanging)
  798. {
  799. encoderpos=(int)axis_steps_per_unit[3];
  800. }
  801. else
  802. {
  803. float factor=float(encoderpos)/float(axis_steps_per_unit[3]);
  804. position[E_AXIS]=lround(position[E_AXIS]*factor);
  805. //current_position[3]*=factor;
  806. axis_steps_per_unit[E_AXIS]= encoderpos;
  807. encoderpos=activeline*lcdslow;
  808. }
  809. BLOCK;
  810. beepshort();
  811. }
  812. if(linechanging)
  813. {
  814. if(encoderpos<5) encoderpos=5;
  815. if(encoderpos>9999) encoderpos=9999;
  816. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  817. }
  818. }break;
  819. default:
  820. break;
  821. }
  822. line++;
  823. }
  824. updateActiveLines(ItemT_fan,encoderpos);
  825. }
  826. //does not work
  827. // #define MENUCHANGEITEM(repaint_action, enter_action, accept_action, change_action) \
  828. // {\
  829. // if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  830. // if(activeline==line) \
  831. // { \
  832. // if(CLICKED) \
  833. // { \
  834. // linechanging=!linechanging; \
  835. // if(linechanging) {enter_action;} \
  836. // else {accept_action;} \
  837. // } \
  838. // else \
  839. // if(linechanging) {change_action};}\
  840. // }
  841. //
  842. enum {
  843. ItemCT_exit,ItemCT_nozzle,
  844. #ifdef AUTOTEMP
  845. ItemCT_autotempactive,
  846. ItemCT_autotempmin,ItemCT_autotempmax,ItemCT_autotempfact,
  847. #endif
  848. #if (HEATER_BED_PIN > -1)
  849. ItemCT_bed,
  850. #endif
  851. ItemCT_fan,
  852. ItemCT_PID_P,ItemCT_PID_I,ItemCT_PID_D,ItemCT_PID_C
  853. };
  854. void MainMenu::showControlTemp()
  855. {
  856. uint8_t line=0;
  857. clearIfNecessary();
  858. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  859. {
  860. switch(i)
  861. {
  862. case ItemCT_exit:
  863. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  864. break;
  865. case ItemCT_nozzle:
  866. {
  867. if(force_lcd_update)
  868. {
  869. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE);
  870. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  871. }
  872. if((activeline!=line) )
  873. break;
  874. if(CLICKED)
  875. {
  876. linechanging=!linechanging;
  877. if(linechanging)
  878. {
  879. encoderpos=intround(degTargetHotend0());
  880. }
  881. else
  882. {
  883. setTargetHotend0(encoderpos);
  884. encoderpos=activeline*lcdslow;
  885. beepshort();
  886. }
  887. BLOCK;
  888. }
  889. if(linechanging)
  890. {
  891. if(encoderpos<0) encoderpos=0;
  892. if(encoderpos>260) encoderpos=260;
  893. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  894. }
  895. }break;
  896. #ifdef AUTOTEMP
  897. case ItemCT_autotempmin:
  898. {
  899. if(force_lcd_update)
  900. {
  901. lcd.setCursor(0,line);lcdprintPGM(MSG_MIN);
  902. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_min));
  903. }
  904. if((activeline!=line) )
  905. break;
  906. if(CLICKED)
  907. {
  908. linechanging=!linechanging;
  909. if(linechanging)
  910. {
  911. encoderpos=intround(autotemp_min);
  912. }
  913. else
  914. {
  915. autotemp_min=encoderpos;
  916. encoderpos=activeline*lcdslow;
  917. beepshort();
  918. }
  919. BLOCK;
  920. }
  921. if(linechanging)
  922. {
  923. if(encoderpos<0) encoderpos=0;
  924. if(encoderpos>260) encoderpos=260;
  925. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  926. }
  927. }break;
  928. case ItemCT_autotempmax:
  929. {
  930. if(force_lcd_update)
  931. {
  932. lcd.setCursor(0,line);lcdprintPGM(MSG_MAX);
  933. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_max));
  934. }
  935. if((activeline!=line) )
  936. break;
  937. if(CLICKED)
  938. {
  939. linechanging=!linechanging;
  940. if(linechanging)
  941. {
  942. encoderpos=intround(autotemp_max);
  943. }
  944. else
  945. {
  946. autotemp_max=encoderpos;
  947. encoderpos=activeline*lcdslow;
  948. beepshort();
  949. }
  950. BLOCK;
  951. }
  952. if(linechanging)
  953. {
  954. if(encoderpos<0) encoderpos=0;
  955. if(encoderpos>260) encoderpos=260;
  956. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  957. }
  958. }break;
  959. case ItemCT_autotempfact:
  960. {
  961. if(force_lcd_update)
  962. {
  963. lcd.setCursor(0,line);lcdprintPGM(MSG_FACTOR);
  964. lcd.setCursor(13,line);lcd.print(ftostr32(autotemp_factor));
  965. }
  966. if((activeline!=line) )
  967. break;
  968. if(CLICKED)
  969. {
  970. linechanging=!linechanging;
  971. if(linechanging)
  972. {
  973. encoderpos=intround(autotemp_factor*100);
  974. }
  975. else
  976. {
  977. autotemp_max=encoderpos;
  978. encoderpos=activeline*lcdslow;
  979. beepshort();
  980. }
  981. BLOCK;
  982. }
  983. if(linechanging)
  984. {
  985. if(encoderpos<0) encoderpos=0;
  986. if(encoderpos>99) encoderpos=99;
  987. lcd.setCursor(13,line);lcd.print(ftostr32(encoderpos/100.));
  988. }
  989. }break;
  990. case ItemCT_autotempactive:
  991. {
  992. if(force_lcd_update)
  993. {
  994. lcd.setCursor(0,line);lcdprintPGM(MSG_AUTOTEMP);
  995. lcd.setCursor(13,line);
  996. if(autotemp_enabled)
  997. lcdprintPGM(MSG_ON);
  998. else
  999. lcdprintPGM(MSG_OFF);
  1000. }
  1001. if((activeline!=line) )
  1002. break;
  1003. if(CLICKED)
  1004. {
  1005. autotemp_enabled=!autotemp_enabled;
  1006. lcd.setCursor(13,line);
  1007. if(autotemp_enabled)
  1008. lcdprintPGM(MSG_ON);
  1009. else
  1010. lcdprintPGM(MSG_OFF);
  1011. BLOCK;
  1012. }
  1013. }break;
  1014. #endif //autotemp
  1015. #if (HEATER_BED_PIN > -1)
  1016. case ItemCT_bed:
  1017. {
  1018. if(force_lcd_update)
  1019. {
  1020. lcd.setCursor(0,line);lcdprintPGM(MSG_BED);
  1021. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  1022. }
  1023. if((activeline!=line) )
  1024. break;
  1025. if(CLICKED)
  1026. {
  1027. linechanging=!linechanging;
  1028. if(linechanging)
  1029. {
  1030. encoderpos=intround(degTargetBed());
  1031. }
  1032. else
  1033. {
  1034. setTargetBed(encoderpos);
  1035. encoderpos=activeline*lcdslow;
  1036. beepshort();
  1037. }
  1038. BLOCK;
  1039. }
  1040. if(linechanging)
  1041. {
  1042. if(encoderpos<0) encoderpos=0;
  1043. if(encoderpos>260) encoderpos=260;
  1044. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1045. }
  1046. }break;
  1047. #endif
  1048. case ItemCT_fan:
  1049. {
  1050. if(force_lcd_update)
  1051. {
  1052. lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
  1053. lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
  1054. }
  1055. if((activeline!=line) )
  1056. break;
  1057. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  1058. {
  1059. linechanging=!linechanging;
  1060. if(linechanging)
  1061. {
  1062. encoderpos=FanSpeed;
  1063. }
  1064. else
  1065. {
  1066. encoderpos=activeline*lcdslow;
  1067. beepshort();
  1068. }
  1069. BLOCK;
  1070. }
  1071. if(linechanging)
  1072. {
  1073. if(encoderpos<0) encoderpos=0;
  1074. if(encoderpos>255) encoderpos=255;
  1075. FanSpeed=encoderpos;
  1076. analogWrite(FAN_PIN, FanSpeed);
  1077. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1078. }
  1079. }break;
  1080. #ifdef PIDTEMP
  1081. case ItemCT_PID_P:
  1082. {
  1083. if(force_lcd_update)
  1084. {
  1085. lcd.setCursor(0,line);lcdprintPGM(" PID-P: ");
  1086. lcd.setCursor(13,line);lcd.print(itostr4(Kp));
  1087. }
  1088. if((activeline!=line) )
  1089. break;
  1090. if(CLICKED)
  1091. {
  1092. linechanging=!linechanging;
  1093. if(linechanging)
  1094. {
  1095. encoderpos=(int)Kp;
  1096. }
  1097. else
  1098. {
  1099. Kp= encoderpos;
  1100. encoderpos=activeline*lcdslow;
  1101. }
  1102. BLOCK;
  1103. beepshort();
  1104. }
  1105. if(linechanging)
  1106. {
  1107. if(encoderpos<1) encoderpos=1;
  1108. if(encoderpos>9990) encoderpos=9990;
  1109. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1110. }
  1111. }break;
  1112. case ItemCT_PID_I:
  1113. {
  1114. if(force_lcd_update)
  1115. {
  1116. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_I);
  1117. lcd.setCursor(13,line);lcd.print(ftostr51(Ki/PID_dT));
  1118. }
  1119. if((activeline!=line) )
  1120. break;
  1121. if(CLICKED)
  1122. {
  1123. linechanging=!linechanging;
  1124. if(linechanging)
  1125. {
  1126. encoderpos=(int)(Ki*10/PID_dT);
  1127. }
  1128. else
  1129. {
  1130. Ki= encoderpos/10.*PID_dT;
  1131. encoderpos=activeline*lcdslow;
  1132. }
  1133. BLOCK;
  1134. beepshort();
  1135. }
  1136. if(linechanging)
  1137. {
  1138. if(encoderpos<0) encoderpos=0;
  1139. if(encoderpos>9990) encoderpos=9990;
  1140. lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.));
  1141. }
  1142. }break;
  1143. case ItemCT_PID_D:
  1144. {
  1145. if(force_lcd_update)
  1146. {
  1147. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_D);
  1148. lcd.setCursor(13,line);lcd.print(itostr4(Kd*PID_dT));
  1149. }
  1150. if((activeline!=line) )
  1151. break;
  1152. if(CLICKED)
  1153. {
  1154. linechanging=!linechanging;
  1155. if(linechanging)
  1156. {
  1157. encoderpos=(int)(Kd/5./PID_dT);
  1158. }
  1159. else
  1160. {
  1161. Kd= encoderpos;
  1162. encoderpos=activeline*lcdslow;
  1163. }
  1164. BLOCK;
  1165. beepshort();
  1166. }
  1167. if(linechanging)
  1168. {
  1169. if(encoderpos<0) encoderpos=0;
  1170. if(encoderpos>9990) encoderpos=9990;
  1171. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1172. }
  1173. }break;
  1174. case ItemCT_PID_C:
  1175. #ifdef PID_ADD_EXTRUSION_RATE
  1176. {
  1177. if(force_lcd_update)
  1178. {
  1179. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_C);
  1180. lcd.setCursor(13,line);lcd.print(itostr3(Kc));
  1181. }
  1182. if((activeline!=line) )
  1183. break;
  1184. if(CLICKED)
  1185. {
  1186. linechanging=!linechanging;
  1187. if(linechanging)
  1188. {
  1189. encoderpos=(int)Kc;
  1190. }
  1191. else
  1192. {
  1193. Kc= encoderpos;
  1194. encoderpos=activeline*lcdslow;
  1195. }
  1196. BLOCK;
  1197. beepshort();
  1198. }
  1199. if(linechanging)
  1200. {
  1201. if(encoderpos<0) encoderpos=0;
  1202. if(encoderpos>990) encoderpos=990;
  1203. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1204. }
  1205. }
  1206. #endif
  1207. #endif
  1208. break;
  1209. default:
  1210. break;
  1211. }
  1212. line++;
  1213. }
  1214. #ifdef PID_ADD_EXTRUSION_RATE
  1215. updateActiveLines(ItemCT_PID_C,encoderpos);
  1216. #else
  1217. updateActiveLines(ItemCT_PID_D,encoderpos);
  1218. #endif
  1219. }
  1220. enum {
  1221. ItemCM_exit,
  1222. ItemCM_acc, ItemCM_xyjerk,
  1223. ItemCM_vmaxx, ItemCM_vmaxy, ItemCM_vmaxz, ItemCM_vmaxe,
  1224. ItemCM_vtravmin,ItemCM_vmin,
  1225. ItemCM_amaxx, ItemCM_amaxy, ItemCM_amaxz, ItemCM_amaxe,
  1226. ItemCM_aret, ItemCM_xsteps,ItemCM_ysteps, ItemCM_zsteps, ItemCM_esteps
  1227. };
  1228. void MainMenu::showControlMotion()
  1229. {
  1230. uint8_t line=0;
  1231. clearIfNecessary();
  1232. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1233. {
  1234. switch(i)
  1235. {
  1236. case ItemCM_exit:
  1237. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  1238. break;
  1239. case ItemCM_acc:
  1240. {
  1241. if(force_lcd_update)
  1242. {
  1243. lcd.setCursor(0,line);lcdprintPGM(MSG_ACC);
  1244. lcd.setCursor(13,line);lcd.print(itostr3(acceleration/100));lcdprintPGM("00");
  1245. }
  1246. if((activeline!=line) )
  1247. break;
  1248. if(CLICKED)
  1249. {
  1250. linechanging=!linechanging;
  1251. if(linechanging)
  1252. {
  1253. encoderpos=(int)acceleration/100;
  1254. }
  1255. else
  1256. {
  1257. acceleration= encoderpos*100;
  1258. encoderpos=activeline*lcdslow;
  1259. }
  1260. BLOCK;
  1261. beepshort();
  1262. }
  1263. if(linechanging)
  1264. {
  1265. if(encoderpos<5) encoderpos=5;
  1266. if(encoderpos>990) encoderpos=990;
  1267. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1268. }
  1269. }break;
  1270. case ItemCM_xyjerk: //max_xy_jerk
  1271. {
  1272. if(force_lcd_update)
  1273. {
  1274. lcd.setCursor(0,line);lcdprintPGM(MSG_VXY_JERK);
  1275. lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk));
  1276. }
  1277. if((activeline!=line) )
  1278. break;
  1279. if(CLICKED)
  1280. {
  1281. linechanging=!linechanging;
  1282. if(linechanging)
  1283. {
  1284. encoderpos=(int)max_xy_jerk;
  1285. }
  1286. else
  1287. {
  1288. max_xy_jerk= encoderpos;
  1289. encoderpos=activeline*lcdslow;
  1290. }
  1291. BLOCK;
  1292. beepshort();
  1293. }
  1294. if(linechanging)
  1295. {
  1296. if(encoderpos<1) encoderpos=1;
  1297. if(encoderpos>990) encoderpos=990;
  1298. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1299. }
  1300. }break;
  1301. case ItemCM_vmaxx:
  1302. case ItemCM_vmaxy:
  1303. case ItemCM_vmaxz:
  1304. case ItemCM_vmaxe:
  1305. {
  1306. if(force_lcd_update)
  1307. {
  1308. lcd.setCursor(0,line);lcdprintPGM(MSG_VMAX);
  1309. if(i==ItemCM_vmaxx)lcdprintPGM(MSG_X);
  1310. if(i==ItemCM_vmaxy)lcdprintPGM(MSG_Y);
  1311. if(i==ItemCM_vmaxz)lcdprintPGM(MSG_Z);
  1312. if(i==ItemCM_vmaxe)lcdprintPGM(MSG_E);
  1313. lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemCM_vmaxx]));
  1314. }
  1315. if((activeline!=line) )
  1316. break;
  1317. if(CLICKED)
  1318. {
  1319. linechanging=!linechanging;
  1320. if(linechanging)
  1321. {
  1322. encoderpos=(int)max_feedrate[i-ItemCM_vmaxx];
  1323. }
  1324. else
  1325. {
  1326. max_feedrate[i-ItemCM_vmaxx]= encoderpos;
  1327. encoderpos=activeline*lcdslow;
  1328. }
  1329. BLOCK;
  1330. beepshort();
  1331. }
  1332. if(linechanging)
  1333. {
  1334. if(encoderpos<1) encoderpos=1;
  1335. if(encoderpos>990) encoderpos=990;
  1336. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1337. }
  1338. }break;
  1339. case ItemCM_vmin:
  1340. {
  1341. if(force_lcd_update)
  1342. {
  1343. lcd.setCursor(0,line);lcdprintPGM(MSG_VMIN);
  1344. lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate));
  1345. }
  1346. if((activeline!=line) )
  1347. break;
  1348. if(CLICKED)
  1349. {
  1350. linechanging=!linechanging;
  1351. if(linechanging)
  1352. {
  1353. encoderpos=(int)(minimumfeedrate);
  1354. }
  1355. else
  1356. {
  1357. minimumfeedrate= encoderpos;
  1358. encoderpos=activeline*lcdslow;
  1359. }
  1360. BLOCK;
  1361. beepshort();
  1362. }
  1363. if(linechanging)
  1364. {
  1365. if(encoderpos<0) encoderpos=0;
  1366. if(encoderpos>990) encoderpos=990;
  1367. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1368. }
  1369. }break;
  1370. case ItemCM_vtravmin:
  1371. {
  1372. if(force_lcd_update)
  1373. {
  1374. lcd.setCursor(0,line);lcdprintPGM(MSG_VTRAV_MIN);
  1375. lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate));
  1376. }
  1377. if((activeline!=line) )
  1378. break;
  1379. if(CLICKED)
  1380. {
  1381. linechanging=!linechanging;
  1382. if(linechanging)
  1383. {
  1384. encoderpos=(int)mintravelfeedrate;
  1385. }
  1386. else
  1387. {
  1388. mintravelfeedrate= encoderpos;
  1389. encoderpos=activeline*lcdslow;
  1390. }
  1391. BLOCK;
  1392. beepshort();
  1393. }
  1394. if(linechanging)
  1395. {
  1396. if(encoderpos<0) encoderpos=0;
  1397. if(encoderpos>990) encoderpos=990;
  1398. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1399. }
  1400. }break;
  1401. case ItemCM_amaxx:
  1402. case ItemCM_amaxy:
  1403. case ItemCM_amaxz:
  1404. case ItemCM_amaxe:
  1405. {
  1406. if(force_lcd_update)
  1407. {
  1408. lcd.setCursor(0,line);lcdprintPGM(" Amax ");
  1409. if(i==ItemCM_amaxx)lcdprintPGM(MSG_X);
  1410. if(i==ItemCM_amaxy)lcdprintPGM(MSG_Y);
  1411. if(i==ItemCM_amaxz)lcdprintPGM(MSG_Z);
  1412. if(i==ItemCM_amaxe)lcdprintPGM(MSG_E);
  1413. lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100));lcdprintPGM("00");
  1414. }
  1415. if((activeline!=line) )
  1416. break;
  1417. if(CLICKED)
  1418. {
  1419. linechanging=!linechanging;
  1420. if(linechanging)
  1421. {
  1422. encoderpos=(int)max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100;
  1423. }
  1424. else
  1425. {
  1426. max_acceleration_units_per_sq_second[i-ItemCM_amaxx]= encoderpos*100;
  1427. encoderpos=activeline*lcdslow;
  1428. }
  1429. BLOCK;
  1430. beepshort();
  1431. }
  1432. if(linechanging)
  1433. {
  1434. if(encoderpos<1) encoderpos=1;
  1435. if(encoderpos>990) encoderpos=990;
  1436. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1437. }
  1438. }break;
  1439. case ItemCM_aret://float retract_acceleration = 7000;
  1440. {
  1441. if(force_lcd_update)
  1442. {
  1443. lcd.setCursor(0,line);lcdprintPGM(MSG_A_RETRACT);
  1444. lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcdprintPGM("00");
  1445. }
  1446. if((activeline!=line) )
  1447. break;
  1448. if(CLICKED)
  1449. {
  1450. linechanging=!linechanging;
  1451. if(linechanging)
  1452. {
  1453. encoderpos=(int)retract_acceleration/100;
  1454. }
  1455. else
  1456. {
  1457. retract_acceleration= encoderpos*100;
  1458. encoderpos=activeline*lcdslow;
  1459. }
  1460. BLOCK;
  1461. beepshort();
  1462. }
  1463. if(linechanging)
  1464. {
  1465. if(encoderpos<10) encoderpos=10;
  1466. if(encoderpos>990) encoderpos=990;
  1467. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1468. }
  1469. }break;
  1470. case ItemCM_xsteps://axis_steps_per_unit[i] = code_value();
  1471. {
  1472. if(force_lcd_update)
  1473. {
  1474. lcd.setCursor(0,line);lcdprintPGM(MSG_XSTEPS);
  1475. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[0]));
  1476. }
  1477. if((activeline!=line) )
  1478. break;
  1479. if(CLICKED)
  1480. {
  1481. linechanging=!linechanging;
  1482. if(linechanging)
  1483. {
  1484. encoderpos=(int)(axis_steps_per_unit[0]*100.0);
  1485. }
  1486. else
  1487. {
  1488. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[0]);
  1489. position[X_AXIS]=lround(position[X_AXIS]*factor);
  1490. //current_position[3]*=factor;
  1491. axis_steps_per_unit[X_AXIS]= encoderpos/100.0;
  1492. encoderpos=activeline*lcdslow;
  1493. }
  1494. BLOCK;
  1495. beepshort();
  1496. }
  1497. if(linechanging)
  1498. {
  1499. if(encoderpos<5) encoderpos=5;
  1500. if(encoderpos>32000) encoderpos=32000;//TODO: This is a problem, encoderpos is 16bit, but steps_per_unit for e can be wel over 800
  1501. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1502. }
  1503. }break;
  1504. case ItemCM_ysteps://axis_steps_per_unit[i] = code_value();
  1505. {
  1506. if(force_lcd_update)
  1507. {
  1508. lcd.setCursor(0,line);lcdprintPGM(MSG_YSTEPS);
  1509. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[1]));
  1510. }
  1511. if((activeline!=line) )
  1512. break;
  1513. if(CLICKED)
  1514. {
  1515. linechanging=!linechanging;
  1516. if(linechanging)
  1517. {
  1518. encoderpos=(int)(axis_steps_per_unit[1]*100.0);
  1519. }
  1520. else
  1521. {
  1522. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[1]);
  1523. position[Y_AXIS]=lround(position[Y_AXIS]*factor);
  1524. //current_position[3]*=factor;
  1525. axis_steps_per_unit[Y_AXIS]= encoderpos/100.0;
  1526. encoderpos=activeline*lcdslow;
  1527. }
  1528. BLOCK;
  1529. beepshort();
  1530. }
  1531. if(linechanging)
  1532. {
  1533. if(encoderpos<5) encoderpos=5;
  1534. if(encoderpos>9999) encoderpos=9999;
  1535. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1536. }
  1537. }break;
  1538. case ItemCM_zsteps://axis_steps_per_unit[i] = code_value();
  1539. {
  1540. if(force_lcd_update)
  1541. {
  1542. lcd.setCursor(0,line);lcdprintPGM(MSG_ZSTEPS);
  1543. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[2]));
  1544. }
  1545. if((activeline!=line) )
  1546. break;
  1547. if(CLICKED)
  1548. {
  1549. linechanging=!linechanging;
  1550. if(linechanging)
  1551. {
  1552. encoderpos=(int)(axis_steps_per_unit[2]*100.0);
  1553. }
  1554. else
  1555. {
  1556. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[2]);
  1557. position[Z_AXIS]=lround(position[Z_AXIS]*factor);
  1558. //current_position[3]*=factor;
  1559. axis_steps_per_unit[Z_AXIS]= encoderpos/100.0;
  1560. encoderpos=activeline*lcdslow;
  1561. }
  1562. BLOCK;
  1563. beepshort();
  1564. }
  1565. if(linechanging)
  1566. {
  1567. if(encoderpos<5) encoderpos=5;
  1568. if(encoderpos>9999) encoderpos=9999;
  1569. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1570. }
  1571. }break;
  1572. case ItemCM_esteps://axis_steps_per_unit[i] = code_value();
  1573. {
  1574. if(force_lcd_update)
  1575. {
  1576. lcd.setCursor(0,line);lcdprintPGM(MSG_ESTEPS);
  1577. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[3]));
  1578. }
  1579. if((activeline!=line) )
  1580. break;
  1581. if(CLICKED)
  1582. {
  1583. linechanging=!linechanging;
  1584. if(linechanging)
  1585. {
  1586. encoderpos=(int)(axis_steps_per_unit[3]*100.0);
  1587. }
  1588. else
  1589. {
  1590. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[3]);
  1591. position[E_AXIS]=lround(position[E_AXIS]*factor);
  1592. //current_position[3]*=factor;
  1593. axis_steps_per_unit[E_AXIS]= encoderpos/100.0;
  1594. encoderpos=activeline*lcdslow;
  1595. }
  1596. BLOCK;
  1597. beepshort();
  1598. }
  1599. if(linechanging)
  1600. {
  1601. if(encoderpos<5) encoderpos=5;
  1602. if(encoderpos>9999) encoderpos=9999;
  1603. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1604. }
  1605. }break;
  1606. default:
  1607. break;
  1608. }
  1609. line++;
  1610. }
  1611. updateActiveLines(ItemCM_esteps,encoderpos);
  1612. }
  1613. enum {
  1614. ItemC_exit,ItemC_temp,ItemC_move,
  1615. ItemC_store, ItemC_load,ItemC_failsafe
  1616. };
  1617. void MainMenu::showControl()
  1618. {
  1619. uint8_t line=0;
  1620. clearIfNecessary();
  1621. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1622. {
  1623. switch(i)
  1624. {
  1625. case ItemC_exit:
  1626. MENUITEM( lcdprintPGM(MSG_MAIN_WIDE) , BLOCK;status=Main_Menu;beepshort(); ) ;
  1627. break;
  1628. case ItemC_temp:
  1629. MENUITEM( lcdprintPGM(MSG_TEMPERATURE_WIDE) , BLOCK;status=Sub_TempControl;beepshort(); ) ;
  1630. break;
  1631. case ItemC_move:
  1632. MENUITEM( lcdprintPGM(MSG_MOTION_WIDE) , BLOCK;status=Sub_MotionControl;beepshort(); ) ;
  1633. break;
  1634. case ItemC_store:
  1635. {
  1636. if(force_lcd_update)
  1637. {
  1638. lcd.setCursor(0,line);lcdprintPGM(MSG_STORE_EPROM);
  1639. }
  1640. if((activeline==line) && CLICKED)
  1641. {
  1642. //enquecommand("M84");
  1643. beepshort();
  1644. BLOCK;
  1645. EEPROM_StoreSettings();
  1646. }
  1647. }break;
  1648. case ItemC_load:
  1649. {
  1650. if(force_lcd_update)
  1651. {
  1652. lcd.setCursor(0,line);lcdprintPGM(MSG_LOAD_EPROM);
  1653. }
  1654. if((activeline==line) && CLICKED)
  1655. {
  1656. //enquecommand("M84");
  1657. beepshort();
  1658. BLOCK;
  1659. EEPROM_RetrieveSettings();
  1660. }
  1661. }break;
  1662. case ItemC_failsafe:
  1663. {
  1664. if(force_lcd_update)
  1665. {
  1666. lcd.setCursor(0,line);lcdprintPGM(MSG_RESTORE_FAILSAFE);
  1667. }
  1668. if((activeline==line) && CLICKED)
  1669. {
  1670. //enquecommand("M84");
  1671. beepshort();
  1672. BLOCK;
  1673. EEPROM_RetrieveSettings(true);
  1674. }
  1675. }break;
  1676. default:
  1677. break;
  1678. }
  1679. line++;
  1680. }
  1681. updateActiveLines(ItemC_failsafe,encoderpos);
  1682. }
  1683. void MainMenu::showSD()
  1684. {
  1685. #ifdef SDSUPPORT
  1686. uint8_t line=0;
  1687. clearIfNecessary();
  1688. static uint8_t nrfiles=0;
  1689. if(force_lcd_update)
  1690. {
  1691. if(card.cardOK)
  1692. {
  1693. nrfiles=card.getnrfilenames();
  1694. }
  1695. else
  1696. {
  1697. nrfiles=0;
  1698. lineoffset=0;
  1699. }
  1700. }
  1701. bool enforceupdate=false;
  1702. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1703. {
  1704. switch(i)
  1705. {
  1706. case 0:
  1707. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  1708. break;
  1709. // case 1:
  1710. // {
  1711. // if(force_lcd_update)
  1712. // {
  1713. // lcd.setCursor(0,line);
  1714. // #ifdef CARDINSERTED
  1715. // if(CARDINSERTED)
  1716. // #else
  1717. // if(true)
  1718. // #endif
  1719. // {
  1720. // lcdprintPGM(" \004Refresh");
  1721. // }
  1722. // else
  1723. // {
  1724. // lcdprintPGM(" \004Insert Card");
  1725. // }
  1726. //
  1727. // }
  1728. // if((activeline==line) && CLICKED)
  1729. // {
  1730. // BLOCK;
  1731. // beepshort();
  1732. // card.initsd();
  1733. // force_lcd_update=true;
  1734. // nrfiles=card.getnrfilenames();
  1735. // }
  1736. // }break;
  1737. case 1:
  1738. MENUITEM( lcd.print(" ");card.getWorkDirName();
  1739. if(card.filename[0]=='/') lcdprintPGM(MSG_REFRESH);
  1740. else {
  1741. lcd.print("\005");
  1742. lcd.print(card.filename);
  1743. lcd.print("/..");
  1744. } ,
  1745. BLOCK;
  1746. if(SDCARDDETECT == -1) card.initsd();
  1747. card.updir();
  1748. enforceupdate=true;
  1749. lineoffset=0;
  1750. beepshort(); ) ;
  1751. break;
  1752. default:
  1753. {
  1754. #define FIRSTITEM 2
  1755. if(i-FIRSTITEM<nrfiles)
  1756. {
  1757. if(force_lcd_update)
  1758. {
  1759. card.getfilename(i-FIRSTITEM);
  1760. //Serial.print("Filenr:");Serial.println(i-2);
  1761. lcd.setCursor(0,line);lcdprintPGM(" ");
  1762. if(card.filenameIsDir) lcd.print("\005");
  1763. lcd.print(card.filename);
  1764. }
  1765. if((activeline==line) && CLICKED)
  1766. {
  1767. BLOCK
  1768. card.getfilename(i-FIRSTITEM);
  1769. if(card.filenameIsDir)
  1770. {
  1771. for(int8_t i=0;i<strlen(card.filename);i++)
  1772. card.filename[i]=tolower(card.filename[i]);
  1773. card.chdir(card.filename);
  1774. lineoffset=0;
  1775. enforceupdate=true;
  1776. }
  1777. else
  1778. {
  1779. char cmd[30];
  1780. for(int8_t i=0;i<strlen(card.filename);i++)
  1781. card.filename[i]=tolower(card.filename[i]);
  1782. sprintf(cmd,"M23 %s",card.filename);
  1783. //sprintf(cmd,"M115");
  1784. enquecommand(cmd);
  1785. enquecommand("M24");
  1786. beep();
  1787. status=Main_Status;
  1788. lcd_status(card.filename);
  1789. }
  1790. }
  1791. }
  1792. }
  1793. break;
  1794. }
  1795. line++;
  1796. }
  1797. updateActiveLines(FIRSTITEM+nrfiles-1,encoderpos);
  1798. if(enforceupdate)
  1799. {
  1800. force_lcd_update=true;
  1801. enforceupdate=false;
  1802. }
  1803. #endif
  1804. }
  1805. enum {ItemM_watch, ItemM_prepare, ItemM_control, ItemM_file };
  1806. void MainMenu::showMainMenu()
  1807. {
  1808. #ifndef ULTIPANEL
  1809. force_lcd_update=false;
  1810. #endif
  1811. if(tune)
  1812. {
  1813. if(!(movesplanned() || IS_SD_PRINTING))
  1814. {
  1815. force_lcd_update=true;
  1816. tune=false;
  1817. }
  1818. }
  1819. else
  1820. {
  1821. if(movesplanned() || IS_SD_PRINTING)
  1822. {
  1823. force_lcd_update=true;
  1824. tune=true;
  1825. }
  1826. }
  1827. clearIfNecessary();
  1828. for(int8_t line=0;line<LCD_HEIGHT;line++)
  1829. {
  1830. switch(line)
  1831. {
  1832. case ItemM_watch:
  1833. MENUITEM( lcdprintPGM(MSG_WATCH) , BLOCK;status=Main_Status;beepshort(); ) ;
  1834. break;
  1835. case ItemM_prepare:
  1836. MENUITEM( if(!tune) lcdprintPGM(MSG_PREPARE);else lcdprintPGM(MSG_TUNE); , BLOCK;status=Main_Prepare;beepshort(); ) ;
  1837. break;
  1838. case ItemM_control:
  1839. MENUITEM( lcdprintPGM(MSG_CONTROL_ARROW) , BLOCK;status=Main_Control;beepshort(); ) ;
  1840. break;
  1841. #ifdef SDSUPPORT
  1842. case ItemM_file:
  1843. {
  1844. if(force_lcd_update)
  1845. {
  1846. lcd.setCursor(0,line);
  1847. #ifdef CARDINSERTED
  1848. if(CARDINSERTED)
  1849. #else
  1850. if(true)
  1851. #endif
  1852. {
  1853. if(card.sdprinting)
  1854. lcdprintPGM(MSG_STOP_PRINT);
  1855. else
  1856. lcdprintPGM(MSG_CARD_MENU);
  1857. }
  1858. else
  1859. {
  1860. lcdprintPGM(MSG_NO_CARD);
  1861. }
  1862. }
  1863. #ifdef CARDINSERTED
  1864. if(CARDINSERTED)
  1865. #endif
  1866. if((activeline==line)&&CLICKED)
  1867. {
  1868. card.printingHasFinished();
  1869. BLOCK;
  1870. status=Main_SD;
  1871. beepshort();
  1872. }
  1873. }break;
  1874. #else
  1875. case ItemM_file:
  1876. break;
  1877. #endif
  1878. default:
  1879. SERIAL_ERROR_START;
  1880. SERIAL_ERRORLNPGM(MSG_SERIAL_ERROR_MENU_STRUCTURE);
  1881. break;
  1882. }
  1883. }
  1884. updateActiveLines(3,encoderpos);
  1885. }
  1886. void MainMenu::update()
  1887. {
  1888. static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
  1889. static long timeoutToStatus=0;
  1890. static bool oldcardstatus=false;
  1891. #ifdef CARDINSERTED
  1892. if((CARDINSERTED != oldcardstatus))
  1893. {
  1894. force_lcd_update=true;
  1895. oldcardstatus=CARDINSERTED;
  1896. //Serial.println("echo: SD CHANGE");
  1897. if(CARDINSERTED)
  1898. {
  1899. card.initsd();
  1900. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  1901. }
  1902. else
  1903. {
  1904. card.release();
  1905. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  1906. }
  1907. }
  1908. #endif
  1909. if(status!=oldstatus)
  1910. {
  1911. force_lcd_update=true;
  1912. encoderpos=0;
  1913. lineoffset=0;
  1914. oldstatus=status;
  1915. }
  1916. if( (encoderpos!=lastencoderpos) || CLICKED)
  1917. timeoutToStatus=millis()+STATUSTIMEOUT;
  1918. switch(status)
  1919. {
  1920. case Main_Status:
  1921. {
  1922. showStatus();
  1923. if(CLICKED)
  1924. {
  1925. linechanging=false;
  1926. BLOCK
  1927. status=Main_Menu;
  1928. timeoutToStatus=millis()+STATUSTIMEOUT;
  1929. }
  1930. }break;
  1931. case Main_Menu:
  1932. {
  1933. showMainMenu();
  1934. linechanging=false;
  1935. }break;
  1936. case Main_Prepare:
  1937. {
  1938. if(tune)
  1939. {
  1940. showTune();
  1941. }
  1942. else
  1943. {
  1944. showPrepare();
  1945. }
  1946. }break;
  1947. case Sub_PrepareMove:
  1948. {
  1949. showAxisMove();
  1950. }break;
  1951. case Main_Control:
  1952. {
  1953. showControl();
  1954. }break;
  1955. case Sub_MotionControl:
  1956. {
  1957. showControlMotion();
  1958. }break;
  1959. case Sub_TempControl:
  1960. {
  1961. showControlTemp();
  1962. }break;
  1963. case Main_SD:
  1964. {
  1965. showSD();
  1966. }break;
  1967. }
  1968. if(timeoutToStatus<millis())
  1969. status=Main_Status;
  1970. //force_lcd_update=false;
  1971. lastencoderpos=encoderpos;
  1972. }
  1973. // convert float to string with +123.4 format
  1974. char *ftostr3(const float &x)
  1975. {
  1976. //sprintf(conv,"%5.1f",x);
  1977. int xx=x;
  1978. conv[0]=(xx/100)%10+'0';
  1979. conv[1]=(xx/10)%10+'0';
  1980. conv[2]=(xx)%10+'0';
  1981. conv[3]=0;
  1982. return conv;
  1983. }
  1984. char *itostr2(const uint8_t &x)
  1985. {
  1986. //sprintf(conv,"%5.1f",x);
  1987. int xx=x;
  1988. conv[0]=(xx/10)%10+'0';
  1989. conv[1]=(xx)%10+'0';
  1990. conv[2]=0;
  1991. return conv;
  1992. }
  1993. // convert float to string with +123.4 format
  1994. char *ftostr31(const float &x)
  1995. {
  1996. int xx=x*10;
  1997. conv[0]=(xx>=0)?'+':'-';
  1998. xx=abs(xx);
  1999. conv[1]=(xx/1000)%10+'0';
  2000. conv[2]=(xx/100)%10+'0';
  2001. conv[3]=(xx/10)%10+'0';
  2002. conv[4]='.';
  2003. conv[5]=(xx)%10+'0';
  2004. conv[6]=0;
  2005. return conv;
  2006. }
  2007. char *ftostr32(const float &x)
  2008. {
  2009. int xx=x*100;
  2010. conv[0]=(xx>=0)?'+':'-';
  2011. xx=abs(xx);
  2012. conv[1]=(xx/100)%10+'0';
  2013. conv[2]='.';
  2014. conv[3]=(xx/10)%10+'0';
  2015. conv[4]=(xx)%10+'0';
  2016. conv[6]=0;
  2017. return conv;
  2018. }
  2019. char *itostr31(const int &xx)
  2020. {
  2021. conv[0]=(xx>=0)?'+':'-';
  2022. conv[1]=(xx/1000)%10+'0';
  2023. conv[2]=(xx/100)%10+'0';
  2024. conv[3]=(xx/10)%10+'0';
  2025. conv[4]='.';
  2026. conv[5]=(xx)%10+'0';
  2027. conv[6]=0;
  2028. return conv;
  2029. }
  2030. char *itostr3(const int &xx)
  2031. {
  2032. conv[0]=(xx/100)%10+'0';
  2033. conv[1]=(xx/10)%10+'0';
  2034. conv[2]=(xx)%10+'0';
  2035. conv[3]=0;
  2036. return conv;
  2037. }
  2038. char *itostr4(const int &xx)
  2039. {
  2040. conv[0]=(xx/1000)%10+'0';
  2041. conv[1]=(xx/100)%10+'0';
  2042. conv[2]=(xx/10)%10+'0';
  2043. conv[3]=(xx)%10+'0';
  2044. conv[4]=0;
  2045. return conv;
  2046. }
  2047. // convert float to string with +1234.5 format
  2048. char *ftostr51(const float &x)
  2049. {
  2050. int xx=x*10;
  2051. conv[0]=(xx>=0)?'+':'-';
  2052. xx=abs(xx);
  2053. conv[1]=(xx/10000)%10+'0';
  2054. conv[2]=(xx/1000)%10+'0';
  2055. conv[3]=(xx/100)%10+'0';
  2056. conv[4]=(xx/10)%10+'0';
  2057. conv[5]='.';
  2058. conv[6]=(xx)%10+'0';
  2059. conv[7]=0;
  2060. return conv;
  2061. }
  2062. // convert float to string with +123.45 format
  2063. char *ftostr52(const float &x)
  2064. {
  2065. int xx=x*100;
  2066. conv[0]=(xx>=0)?'+':'-';
  2067. xx=abs(xx);
  2068. conv[1]=(xx/10000)%10+'0';
  2069. conv[2]=(xx/1000)%10+'0';
  2070. conv[3]=(xx/100)%10+'0';
  2071. conv[4]='.';
  2072. conv[5]=(xx/10)%10+'0';
  2073. conv[6]=(xx)%10+'0';
  2074. conv[7]=0;
  2075. return conv;
  2076. }
  2077. #endif //ULTRA_LCD