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

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