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

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