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

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