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

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