My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  1. #include "ultralcd.h"
  2. #ifdef ULTRA_LCD
  3. //===========================================================================
  4. //=============================imported variables============================
  5. //===========================================================================
  6. extern volatile int feedmultiply;
  7. extern volatile bool feedmultiplychanged;
  8. extern long position[4];
  9. extern CardReader card;
  10. //===========================================================================
  11. //=============================public variables============================
  12. //===========================================================================
  13. volatile char buttons=0; //the last checked buttons in a bit array.
  14. int encoderpos=0;
  15. short lastenc=0;
  16. //===========================================================================
  17. //=============================private variables============================
  18. //===========================================================================
  19. static char messagetext[LCD_WIDTH]="";
  20. //return for string conversion routines
  21. static char conv[8];
  22. #include <LiquidCrystal.h>
  23. 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
  24. static unsigned long previous_millis_lcd=0;
  25. static long previous_millis_buttons=0;
  26. #ifdef NEWPANEL
  27. static long blocking=0;
  28. #else
  29. static long blocking[8]={0,0,0,0,0,0,0,0};
  30. #endif
  31. static MainMenu menu;
  32. //===========================================================================
  33. //=============================functions ============================
  34. //===========================================================================
  35. inline int intround(const float &x){return int(0.5+x);}
  36. void lcd_status(const char* message)
  37. {
  38. strncpy(messagetext,message,LCD_WIDTH);
  39. }
  40. inline void clear()
  41. {
  42. lcd.clear();
  43. }
  44. void lcd_init()
  45. {
  46. //beep();
  47. byte Degree[8] =
  48. {
  49. B01100,
  50. B10010,
  51. B10010,
  52. B01100,
  53. B00000,
  54. B00000,
  55. B00000,
  56. B00000
  57. };
  58. byte Thermometer[8] =
  59. {
  60. B00100,
  61. B01010,
  62. B01010,
  63. B01010,
  64. B01010,
  65. B10001,
  66. B10001,
  67. B01110
  68. };
  69. byte uplevel[8]={0x04, 0x0e, 0x1f, 0x04, 0x1c, 0x00, 0x00, 0x00};//thanks joris
  70. byte refresh[8]={0x00, 0x06, 0x19, 0x18, 0x03, 0x13, 0x0c, 0x00}; //thanks joris
  71. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  72. lcd.createChar(1,Degree);
  73. lcd.createChar(2,Thermometer);
  74. lcd.createChar(3,uplevel);
  75. lcd.createChar(4,refresh);
  76. LCD_MESSAGE(fillto(LCD_WIDTH,"UltiMarlin ready."));
  77. }
  78. void beep()
  79. {
  80. //return;
  81. #ifdef ULTIPANEL
  82. pinMode(BEEPER,OUTPUT);
  83. for(int8_t i=0;i<20;i++){
  84. WRITE(BEEPER,HIGH);
  85. delay(5);
  86. WRITE(BEEPER,LOW);
  87. delay(5);
  88. }
  89. #endif
  90. }
  91. void beepshort()
  92. {
  93. //return;
  94. #ifdef ULTIPANEL
  95. pinMode(BEEPER,OUTPUT);
  96. for(int8_t i=0;i<10;i++){
  97. WRITE(BEEPER,HIGH);
  98. delay(3);
  99. WRITE(BEEPER,LOW);
  100. delay(3);
  101. }
  102. #endif
  103. }
  104. void lcd_status()
  105. {
  106. #ifdef ULTIPANEL
  107. static uint8_t oldbuttons=0;
  108. static long previous_millis_buttons=0;
  109. static long previous_lcdinit=0;
  110. // buttons_check(); // Done in temperature interrupt
  111. //previous_millis_buttons=millis();
  112. if((buttons==oldbuttons) && ((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
  113. return;
  114. oldbuttons=buttons;
  115. #else
  116. if(((millis() - previous_millis_lcd) < LCD_UPDATE_INTERVAL) )
  117. return;
  118. #endif
  119. previous_millis_lcd=millis();
  120. menu.update();
  121. }
  122. #ifdef ULTIPANEL
  123. void buttons_init()
  124. {
  125. #ifdef NEWPANEL
  126. pinMode(BTN_EN1,INPUT);
  127. pinMode(BTN_EN2,INPUT);
  128. pinMode(BTN_ENC,INPUT);
  129. pinMode(SDCARDDETECT,INPUT);
  130. WRITE(BTN_EN1,HIGH);
  131. WRITE(BTN_EN2,HIGH);
  132. WRITE(BTN_ENC,HIGH);
  133. WRITE(SDCARDDETECT,HIGH);
  134. #else
  135. pinMode(SHIFT_CLK,OUTPUT);
  136. pinMode(SHIFT_LD,OUTPUT);
  137. pinMode(SHIFT_EN,OUTPUT);
  138. pinMode(SHIFT_OUT,INPUT);
  139. WRITE(SHIFT_OUT,HIGH);
  140. WRITE(SHIFT_LD,HIGH);
  141. WRITE(SHIFT_EN,LOW);
  142. #endif
  143. }
  144. void buttons_check()
  145. {
  146. #ifdef NEWPANEL
  147. uint8_t newbutton=0;
  148. if(READ(BTN_EN1)==0) newbutton|=EN_A;
  149. if(READ(BTN_EN2)==0) newbutton|=EN_B;
  150. if((blocking<millis()) &&(READ(BTN_ENC)==0))
  151. newbutton|=EN_C;
  152. buttons=newbutton;
  153. #else //read it from the shift register
  154. uint8_t newbutton=0;
  155. WRITE(SHIFT_LD,LOW);
  156. WRITE(SHIFT_LD,HIGH);
  157. unsigned char tmp_buttons=0;
  158. for(int8_t i=0;i<8;i++)
  159. {
  160. newbutton = newbutton>>1;
  161. if(READ(SHIFT_OUT))
  162. newbutton|=(1<<7);
  163. WRITE(SHIFT_CLK,HIGH);
  164. WRITE(SHIFT_CLK,LOW);
  165. }
  166. buttons=~newbutton; //invert it, because a pressed switch produces a logical 0
  167. #endif
  168. char enc=0;
  169. if(buttons&EN_A)
  170. enc|=(1<<0);
  171. if(buttons&EN_B)
  172. enc|=(1<<1);
  173. if(enc!=lastenc)
  174. {
  175. switch(enc)
  176. {
  177. case encrot0:
  178. if(lastenc==encrot3)
  179. encoderpos++;
  180. else if(lastenc==encrot1)
  181. encoderpos--;
  182. break;
  183. case encrot1:
  184. if(lastenc==encrot0)
  185. encoderpos++;
  186. else if(lastenc==encrot2)
  187. encoderpos--;
  188. break;
  189. case encrot2:
  190. if(lastenc==encrot1)
  191. encoderpos++;
  192. else if(lastenc==encrot3)
  193. encoderpos--;
  194. break;
  195. case encrot3:
  196. if(lastenc==encrot2)
  197. encoderpos++;
  198. else if(lastenc==encrot0)
  199. encoderpos--;
  200. break;
  201. default:
  202. ;
  203. }
  204. }
  205. lastenc=enc;
  206. }
  207. #endif
  208. MainMenu::MainMenu()
  209. {
  210. status=Main_Status;
  211. displayStartingRow=0;
  212. activeline=0;
  213. force_lcd_update=true;
  214. #ifdef ULTIPANEL
  215. buttons_init();
  216. #endif
  217. lcd_init();
  218. linechanging=false;
  219. }
  220. void MainMenu::showStatus()
  221. {
  222. #if LCD_HEIGHT==4
  223. static int olddegHotEnd0=-1;
  224. static int oldtargetHotEnd0=-1;
  225. //force_lcd_update=true;
  226. if(force_lcd_update||feedmultiplychanged) //initial display of content
  227. {
  228. feedmultiplychanged=false;
  229. encoderpos=feedmultiply;
  230. clear();
  231. lcd.setCursor(0,0);lcd.print("\002123/567\001 ");
  232. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  233. lcd.setCursor(10,0);lcd.print("B123/567\001 ");
  234. #endif
  235. }
  236. int tHotEnd0=intround(degHotend0());
  237. if((abs(tHotEnd0-olddegHotEnd0)>1)||force_lcd_update) //>1 because otherwise the lcd is refreshed to often.
  238. {
  239. lcd.setCursor(1,0);
  240. lcd.print(ftostr3(tHotEnd0));
  241. olddegHotEnd0=tHotEnd0;
  242. }
  243. int ttHotEnd0=intround(degTargetHotend0());
  244. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  245. {
  246. lcd.setCursor(5,0);
  247. lcd.print(ftostr3(ttHotEnd0));
  248. oldtargetHotEnd0=ttHotEnd0;
  249. }
  250. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  251. static int oldtBed=-1;
  252. static int oldtargetBed=-1;
  253. int tBed=intround(degBed());
  254. if((tBed!=oldtBed)||force_lcd_update)
  255. {
  256. lcd.setCursor(1,0);
  257. lcd.print(ftostr3(tBed));
  258. olddegHotEnd0=tBed;
  259. }
  260. int targetBed=intround(degTargetBed());
  261. if((targetBed!=oldtargetBed)||force_lcd_update)
  262. {
  263. lcd.setCursor(5,0);
  264. lcd.print(ftostr3(targetBed));
  265. oldtargetBed=targetBed;
  266. }
  267. #endif
  268. //starttime=2;
  269. static uint16_t oldtime=0;
  270. if(starttime!=0)
  271. {
  272. lcd.setCursor(0,1);
  273. uint16_t time=millis()/60000-starttime/60000;
  274. if(starttime!=oldtime)
  275. {
  276. lcd.print(itostr2(time/60));lcd.print("h ");lcd.print(itostr2(time%60));lcd.print("m");
  277. oldtime=time;
  278. }
  279. }
  280. static int oldzpos=0;
  281. int currentz=current_position[2]*10;
  282. if((currentz!=oldzpos)||force_lcd_update)
  283. {
  284. lcd.setCursor(10,1);
  285. lcd.print("Z:");lcd.print(itostr31(currentz));
  286. oldzpos=currentz;
  287. }
  288. static int oldfeedmultiply=0;
  289. int curfeedmultiply=feedmultiply;
  290. if(encoderpos!=curfeedmultiply||force_lcd_update)
  291. {
  292. curfeedmultiply=encoderpos;
  293. if(curfeedmultiply<10)
  294. curfeedmultiply=10;
  295. if(curfeedmultiply>999)
  296. curfeedmultiply=999;
  297. feedmultiply=curfeedmultiply;
  298. encoderpos=curfeedmultiply;
  299. }
  300. if((curfeedmultiply!=oldfeedmultiply)||force_lcd_update)
  301. {
  302. oldfeedmultiply=curfeedmultiply;
  303. lcd.setCursor(0,2);
  304. lcd.print(itostr3(curfeedmultiply));lcd.print("% ");
  305. }
  306. if(messagetext[0]!='\0')
  307. {
  308. lcd.setCursor(0,LCD_HEIGHT-1);
  309. lcd.print(fillto(LCD_WIDTH,messagetext));
  310. messagetext[0]='\0';
  311. }
  312. #else //smaller LCDS----------------------------------
  313. static int olddegHotEnd0=-1;
  314. static int oldtargetHotEnd0=-1;
  315. if(force_lcd_update) //initial display of content
  316. {
  317. encoderpos=feedmultiply;
  318. lcd.setCursor(0,0);lcd.print("\002123/567\001 ");
  319. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  320. lcd.setCursor(10,0);lcd.print("B123/567\001 ");
  321. #endif
  322. }
  323. int tHotEnd0=intround(degHotend0());
  324. int ttHotEnd0=intround(degTargetHotend0());
  325. if((abs(tHotEnd0-olddegHotEnd0)>1)||force_lcd_update)
  326. {
  327. lcd.setCursor(1,0);
  328. lcd.print(ftostr3(tHotEnd0));
  329. olddegHotEnd0=tHotEnd0;
  330. }
  331. if((ttHotEnd0!=oldtargetHotEnd0)||force_lcd_update)
  332. {
  333. lcd.setCursor(5,0);
  334. lcd.print(ftostr3(ttHotEnd0));
  335. oldtargetHotEnd0=ttHotEnd0;
  336. }
  337. if(messagetext[0]!='\0')
  338. {
  339. lcd.setCursor(0,LCD_HEIGHT-1);
  340. lcd.print(fillto(LCD_WIDTH,messagetext));
  341. messagetext[0]='\0';
  342. }
  343. #endif
  344. }
  345. enum {ItemP_exit, ItemP_home, ItemP_origin, ItemP_preheat, ItemP_extrude, ItemP_disstep};
  346. void MainMenu::showPrepare()
  347. {
  348. uint8_t line=0;
  349. if(lastlineoffset!=lineoffset)
  350. {
  351. force_lcd_update=true;
  352. clear();
  353. }
  354. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  355. {
  356. //Serial.println((int)(line-lineoffset));
  357. switch(i)
  358. {
  359. case ItemP_exit:
  360. {
  361. if(force_lcd_update)
  362. {
  363. lcd.setCursor(0,line);lcd.print(" Prepare");
  364. }
  365. if((activeline==line) && CLICKED)
  366. {
  367. BLOCK
  368. status=Main_Menu;
  369. beepshort();
  370. }
  371. }break;
  372. case ItemP_home:
  373. {
  374. if(force_lcd_update)
  375. {
  376. lcd.setCursor(0,line);lcd.print(" Auto Home");
  377. }
  378. if((activeline==line) && CLICKED)
  379. {
  380. BLOCK
  381. enquecommand("G28 X-105 Y-105 Z0");
  382. beepshort();
  383. }
  384. }break;
  385. case ItemP_origin:
  386. {
  387. if(force_lcd_update)
  388. {
  389. lcd.setCursor(0,line);lcd.print(" Set Origin");
  390. }
  391. if((activeline==line) && CLICKED)
  392. {
  393. BLOCK
  394. enquecommand("G92 X0 Y0 Z0");
  395. beepshort();
  396. }
  397. }break;
  398. case ItemP_preheat:
  399. {
  400. if(force_lcd_update)
  401. {
  402. lcd.setCursor(0,line);lcd.print(" Preheat");
  403. }
  404. if((activeline==line) && CLICKED)
  405. {
  406. BLOCK
  407. setTargetHotend0(170);
  408. beepshort();
  409. }
  410. }break;
  411. case ItemP_extrude:
  412. {
  413. if(force_lcd_update)
  414. {
  415. lcd.setCursor(0,line);lcd.print(" Extrude");
  416. }
  417. if((activeline==line) && CLICKED)
  418. {
  419. BLOCK
  420. enquecommand("G92 E0");
  421. enquecommand("G1 F700 E50");
  422. beepshort();
  423. }
  424. }break;
  425. case ItemP_disstep:
  426. {
  427. if(force_lcd_update)
  428. {
  429. lcd.setCursor(0,line);lcd.print(" Disable Steppers");
  430. }
  431. if((activeline==line) && CLICKED)
  432. {
  433. BLOCK
  434. enquecommand("M84");
  435. beepshort();
  436. }
  437. }break;
  438. default:
  439. break;
  440. }
  441. line++;
  442. }
  443. lastlineoffset=lineoffset;
  444. if((encoderpos/lcdslow!=lastencoderpos/lcdslow)||force_lcd_update)
  445. {
  446. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?' ':' ');
  447. if(encoderpos<0)
  448. {
  449. lineoffset--;
  450. if(lineoffset<0)
  451. lineoffset=0;
  452. encoderpos=0;
  453. force_lcd_update=true;
  454. }
  455. if(encoderpos/lcdslow>3)
  456. {
  457. lineoffset++;
  458. encoderpos=3*lcdslow;
  459. if(lineoffset>(ItemP_disstep+1-LCD_HEIGHT))
  460. lineoffset=ItemP_disstep+1-LCD_HEIGHT;
  461. force_lcd_update=true;
  462. }
  463. //encoderpos=encoderpos%LCD_HEIGHT;
  464. lastencoderpos=encoderpos;
  465. activeline=encoderpos/lcdslow;
  466. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003');
  467. }
  468. }
  469. enum {
  470. ItemC_exit, ItemC_nozzle,
  471. ItemC_PID_P,ItemC_PID_I,ItemC_PID_D,ItemC_PID_C,
  472. ItemC_fan,
  473. ItemC_acc, ItemC_xyjerk,
  474. ItemC_vmaxx, ItemC_vmaxy, ItemC_vmaxz, ItemC_vmaxe,
  475. ItemC_vtravmin,ItemC_vmin,
  476. ItemC_amaxx, ItemC_amaxy, ItemC_amaxz, ItemC_amaxe,
  477. ItemC_aret,ItemC_esteps, ItemC_store, ItemC_load,ItemC_failsafe
  478. };
  479. void MainMenu::showControl()
  480. {
  481. uint8_t line=0;
  482. if((lastlineoffset!=lineoffset)||force_lcd_update)
  483. {
  484. force_lcd_update=true;
  485. clear();
  486. }
  487. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  488. {
  489. switch(i)
  490. {
  491. case ItemC_exit:
  492. {
  493. if(force_lcd_update)
  494. {
  495. lcd.setCursor(0,line);lcd.print(" Control");
  496. }
  497. if((activeline==line) && CLICKED)
  498. {
  499. BLOCK
  500. status=Main_Menu;
  501. beepshort();
  502. }
  503. }break;
  504. case ItemC_nozzle:
  505. {
  506. if(force_lcd_update)
  507. {
  508. lcd.setCursor(0,line);lcd.print(" \002Nozzle:");
  509. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degHotend0())));
  510. }
  511. if((activeline==line) )
  512. {
  513. if(CLICKED)
  514. {
  515. linechanging=!linechanging;
  516. if(linechanging)
  517. {
  518. encoderpos=intround(degHotend0());
  519. }
  520. else
  521. {
  522. setTargetHotend0(encoderpos);
  523. encoderpos=activeline*lcdslow;
  524. beepshort();
  525. }
  526. BLOCK;
  527. }
  528. if(linechanging)
  529. {
  530. if(encoderpos<0) encoderpos=0;
  531. if(encoderpos>260) encoderpos=260;
  532. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  533. }
  534. }
  535. }break;
  536. case ItemC_fan:
  537. {
  538. if(force_lcd_update)
  539. {
  540. lcd.setCursor(0,line);lcd.print(" Fan speed:");
  541. lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
  542. }
  543. if((activeline==line) )
  544. {
  545. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  546. {
  547. linechanging=!linechanging;
  548. if(linechanging)
  549. {
  550. encoderpos=fanpwm;
  551. }
  552. else
  553. {
  554. fanpwm = constrain(encoderpos,0,255);
  555. encoderpos=fanpwm;
  556. analogWrite(FAN_PIN, fanpwm);
  557. beepshort();
  558. }
  559. BLOCK;
  560. }
  561. if(linechanging)
  562. {
  563. if(encoderpos<0) encoderpos=0;
  564. if(encoderpos>255) encoderpos=255;
  565. fanpwm=encoderpos;
  566. analogWrite(FAN_PIN, fanpwm);
  567. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  568. }
  569. }
  570. }break;
  571. case ItemC_acc:
  572. {
  573. if(force_lcd_update)
  574. {
  575. lcd.setCursor(0,line);lcd.print(" Acc:");
  576. lcd.setCursor(13,line);lcd.print(itostr3(acceleration/100));lcd.print("00");
  577. }
  578. if((activeline==line) )
  579. {
  580. if(CLICKED)
  581. {
  582. linechanging=!linechanging;
  583. if(linechanging)
  584. {
  585. encoderpos=(int)acceleration/100;
  586. }
  587. else
  588. {
  589. acceleration= encoderpos*100;
  590. encoderpos=activeline*lcdslow;
  591. }
  592. BLOCK;
  593. beepshort();
  594. }
  595. if(linechanging)
  596. {
  597. if(encoderpos<5) encoderpos=5;
  598. if(encoderpos>990) encoderpos=990;
  599. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcd.print("00");
  600. }
  601. }
  602. }break;
  603. case ItemC_xyjerk: //max_xy_jerk
  604. {
  605. if(force_lcd_update)
  606. {
  607. lcd.setCursor(0,line);lcd.print(" Vxy-jerk: ");
  608. lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk/60));
  609. }
  610. if((activeline==line) )
  611. {
  612. if(CLICKED)
  613. {
  614. linechanging=!linechanging;
  615. if(linechanging)
  616. {
  617. encoderpos=(int)max_xy_jerk/60;
  618. }
  619. else
  620. {
  621. max_xy_jerk= encoderpos*60;
  622. encoderpos=activeline*lcdslow;
  623. }
  624. BLOCK;
  625. beepshort();
  626. }
  627. if(linechanging)
  628. {
  629. if(encoderpos<1) encoderpos=1;
  630. if(encoderpos>990) encoderpos=990;
  631. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  632. }
  633. }
  634. }break;
  635. case ItemC_PID_P:
  636. {
  637. if(force_lcd_update)
  638. {
  639. lcd.setCursor(0,line);lcd.print(" PID-P: ");
  640. lcd.setCursor(13,line);lcd.print(itostr4(Kp));
  641. }
  642. if((activeline==line) )
  643. {
  644. if(CLICKED)
  645. {
  646. linechanging=!linechanging;
  647. if(linechanging)
  648. {
  649. encoderpos=(int)Kp/5;
  650. }
  651. else
  652. {
  653. Kp= encoderpos*5;
  654. encoderpos=activeline*lcdslow;
  655. }
  656. BLOCK;
  657. beepshort();
  658. }
  659. if(linechanging)
  660. {
  661. if(encoderpos<1) encoderpos=1;
  662. if(encoderpos>9990/5) encoderpos=9990/5;
  663. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
  664. }
  665. }
  666. }break;
  667. case ItemC_PID_I:
  668. {
  669. if(force_lcd_update)
  670. {
  671. lcd.setCursor(0,line);lcd.print(" PID-I: ");
  672. lcd.setCursor(13,line);lcd.print(ftostr51(Ki));
  673. }
  674. if((activeline==line) )
  675. {
  676. if(CLICKED)
  677. {
  678. linechanging=!linechanging;
  679. if(linechanging)
  680. {
  681. encoderpos=(int)(Ki*10);
  682. }
  683. else
  684. {
  685. Ki= encoderpos/10.;
  686. encoderpos=activeline*lcdslow;
  687. }
  688. BLOCK;
  689. beepshort();
  690. }
  691. if(linechanging)
  692. {
  693. if(encoderpos<0) encoderpos=0;
  694. if(encoderpos>9990) encoderpos=9990;
  695. lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.));
  696. }
  697. }
  698. }break;
  699. case ItemC_PID_D:
  700. {
  701. if(force_lcd_update)
  702. {
  703. lcd.setCursor(0,line);lcd.print(" PID-D: ");
  704. lcd.setCursor(13,line);lcd.print(itostr4(Kd));
  705. }
  706. if((activeline==line) )
  707. {
  708. if(CLICKED)
  709. {
  710. linechanging=!linechanging;
  711. if(linechanging)
  712. {
  713. encoderpos=(int)Kd/5;
  714. }
  715. else
  716. {
  717. Kd= encoderpos*5;
  718. encoderpos=activeline*lcdslow;
  719. }
  720. BLOCK;
  721. beepshort();
  722. }
  723. if(linechanging)
  724. {
  725. if(encoderpos<0) encoderpos=0;
  726. if(encoderpos>9990/5) encoderpos=9990/5;
  727. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
  728. }
  729. }
  730. }break;
  731. case ItemC_PID_C:
  732. {
  733. if(force_lcd_update)
  734. {
  735. lcd.setCursor(0,line);lcd.print(" PID-C: ");
  736. lcd.setCursor(13,line);lcd.print(itostr3(Kc));
  737. }
  738. if((activeline==line) )
  739. {
  740. if(CLICKED)
  741. {
  742. linechanging=!linechanging;
  743. if(linechanging)
  744. {
  745. encoderpos=(int)Kc;
  746. }
  747. else
  748. {
  749. Kc= encoderpos;
  750. encoderpos=activeline*lcdslow;
  751. }
  752. BLOCK;
  753. beepshort();
  754. }
  755. if(linechanging)
  756. {
  757. if(encoderpos<0) encoderpos=0;
  758. if(encoderpos>990) encoderpos=990;
  759. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  760. }
  761. }
  762. }break;
  763. case ItemC_vmaxx:
  764. case ItemC_vmaxy:
  765. case ItemC_vmaxz:
  766. case ItemC_vmaxe:
  767. {
  768. if(force_lcd_update)
  769. {
  770. lcd.setCursor(0,line);lcd.print(" Vmax ");
  771. if(i==ItemC_vmaxx)lcd.print("x:");
  772. if(i==ItemC_vmaxy)lcd.print("y:");
  773. if(i==ItemC_vmaxz)lcd.print("z:");
  774. if(i==ItemC_vmaxe)lcd.print("e:");
  775. lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemC_vmaxx]/60));
  776. }
  777. if((activeline==line) )
  778. {
  779. if(CLICKED)
  780. {
  781. linechanging=!linechanging;
  782. if(linechanging)
  783. {
  784. encoderpos=(int)max_feedrate[i-ItemC_vmaxx]/60;
  785. }
  786. else
  787. {
  788. max_feedrate[i-ItemC_vmaxx]= encoderpos*60;
  789. encoderpos=activeline*lcdslow;
  790. }
  791. BLOCK;
  792. beepshort();
  793. }
  794. if(linechanging)
  795. {
  796. if(encoderpos<1) encoderpos=1;
  797. if(encoderpos>990) encoderpos=990;
  798. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  799. }
  800. }
  801. }break;
  802. case ItemC_vmin:
  803. {
  804. if(force_lcd_update)
  805. {
  806. lcd.setCursor(0,line);lcd.print(" Vmin:");
  807. lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate/60));
  808. }
  809. if((activeline==line) )
  810. {
  811. if(CLICKED)
  812. {
  813. linechanging=!linechanging;
  814. if(linechanging)
  815. {
  816. encoderpos=(int)(minimumfeedrate/60.);
  817. }
  818. else
  819. {
  820. minimumfeedrate= encoderpos*60;
  821. encoderpos=activeline*lcdslow;
  822. }
  823. BLOCK;
  824. beepshort();
  825. }
  826. if(linechanging)
  827. {
  828. if(encoderpos<0) encoderpos=0;
  829. if(encoderpos>990) encoderpos=990;
  830. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  831. }
  832. }
  833. }break;
  834. case ItemC_vtravmin:
  835. {
  836. if(force_lcd_update)
  837. {
  838. lcd.setCursor(0,line);lcd.print(" VTrav min:");
  839. lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate/60));
  840. }
  841. if((activeline==line) )
  842. {
  843. if(CLICKED)
  844. {
  845. linechanging=!linechanging;
  846. if(linechanging)
  847. {
  848. encoderpos=(int)mintravelfeedrate/60;
  849. }
  850. else
  851. {
  852. mintravelfeedrate= encoderpos*60;
  853. encoderpos=activeline*lcdslow;
  854. }
  855. BLOCK;
  856. beepshort();
  857. }
  858. if(linechanging)
  859. {
  860. if(encoderpos<0) encoderpos=0;
  861. if(encoderpos>990) encoderpos=990;
  862. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  863. }
  864. }
  865. }break;
  866. case ItemC_amaxx:
  867. case ItemC_amaxy:
  868. case ItemC_amaxz:
  869. case ItemC_amaxe:
  870. {
  871. if(force_lcd_update)
  872. {
  873. lcd.setCursor(0,line);lcd.print(" Amax ");
  874. if(i==ItemC_amaxx)lcd.print("x:");
  875. if(i==ItemC_amaxy)lcd.print("y:");
  876. if(i==ItemC_amaxz)lcd.print("z:");
  877. if(i==ItemC_amaxe)lcd.print("e:");
  878. lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemC_amaxx]/100));lcd.print("00");
  879. }
  880. if((activeline==line) )
  881. {
  882. if(CLICKED)
  883. {
  884. linechanging=!linechanging;
  885. if(linechanging)
  886. {
  887. encoderpos=(int)max_acceleration_units_per_sq_second[i-ItemC_amaxx]/100;
  888. }
  889. else
  890. {
  891. max_acceleration_units_per_sq_second[i-ItemC_amaxx]= encoderpos*100;
  892. encoderpos=activeline*lcdslow;
  893. }
  894. BLOCK;
  895. beepshort();
  896. }
  897. if(linechanging)
  898. {
  899. if(encoderpos<1) encoderpos=1;
  900. if(encoderpos>990) encoderpos=990;
  901. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcd.print("00");
  902. }
  903. }
  904. }break;
  905. case ItemC_aret://float retract_acceleration = 7000;
  906. {
  907. if(force_lcd_update)
  908. {
  909. lcd.setCursor(0,line);lcd.print(" A-retract:");
  910. lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcd.print("00");
  911. }
  912. if((activeline==line) )
  913. {
  914. if(CLICKED)
  915. {
  916. linechanging=!linechanging;
  917. if(linechanging)
  918. {
  919. encoderpos=(int)retract_acceleration/100;
  920. }
  921. else
  922. {
  923. retract_acceleration= encoderpos*100;
  924. encoderpos=activeline*lcdslow;
  925. }
  926. BLOCK;
  927. beepshort();
  928. }
  929. if(linechanging)
  930. {
  931. if(encoderpos<10) encoderpos=10;
  932. if(encoderpos>990) encoderpos=990;
  933. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcd.print("00");
  934. }
  935. }
  936. }break;
  937. case ItemC_esteps://axis_steps_per_unit[i] = code_value();
  938. {
  939. if(force_lcd_update)
  940. {
  941. lcd.setCursor(0,line);lcd.print(" Esteps/mm:");
  942. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3]));
  943. }
  944. if((activeline==line) )
  945. {
  946. if(CLICKED)
  947. {
  948. linechanging=!linechanging;
  949. if(linechanging)
  950. {
  951. encoderpos=(int)axis_steps_per_unit[3];
  952. }
  953. else
  954. {
  955. float factor=float(encoderpos)/float(axis_steps_per_unit[3]);
  956. position[E_AXIS]=lround(position[E_AXIS]*factor);
  957. //current_position[3]*=factor;
  958. axis_steps_per_unit[E_AXIS]= encoderpos;
  959. encoderpos=activeline*lcdslow;
  960. }
  961. BLOCK;
  962. beepshort();
  963. }
  964. if(linechanging)
  965. {
  966. if(encoderpos<5) encoderpos=5;
  967. if(encoderpos>9999) encoderpos=9999;
  968. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  969. }
  970. }
  971. }break;
  972. case ItemC_store:
  973. {
  974. if(force_lcd_update)
  975. {
  976. lcd.setCursor(0,line);lcd.print(" Store EPROM");
  977. }
  978. if((activeline==line) && CLICKED)
  979. {
  980. //enquecommand("M84");
  981. beepshort();
  982. BLOCK;
  983. StoreSettings();
  984. }
  985. }break;
  986. case ItemC_load:
  987. {
  988. if(force_lcd_update)
  989. {
  990. lcd.setCursor(0,line);lcd.print(" Load EPROM");
  991. }
  992. if((activeline==line) && CLICKED)
  993. {
  994. //enquecommand("M84");
  995. beepshort();
  996. BLOCK;
  997. RetrieveSettings();
  998. }
  999. }break;
  1000. case ItemC_failsafe:
  1001. {
  1002. if(force_lcd_update)
  1003. {
  1004. lcd.setCursor(0,line);lcd.print(" Restore Failsafe");
  1005. }
  1006. if((activeline==line) && CLICKED)
  1007. {
  1008. //enquecommand("M84");
  1009. beepshort();
  1010. BLOCK;
  1011. RetrieveSettings(true);
  1012. }
  1013. }break;
  1014. default:
  1015. break;
  1016. }
  1017. line++;
  1018. }
  1019. lastlineoffset=lineoffset;
  1020. if(!linechanging && ((encoderpos/lcdslow!=lastencoderpos/lcdslow)||force_lcd_update))
  1021. {
  1022. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?' ':' ');
  1023. if(encoderpos<0)
  1024. {
  1025. lineoffset--;
  1026. if(lineoffset<0)
  1027. lineoffset=0;
  1028. encoderpos=0;
  1029. force_lcd_update=true;
  1030. }
  1031. if(encoderpos/lcdslow>3)
  1032. {
  1033. lineoffset++;
  1034. encoderpos=3*lcdslow;
  1035. if(lineoffset>(ItemC_failsafe+1-LCD_HEIGHT))
  1036. lineoffset=ItemC_failsafe+1-LCD_HEIGHT;
  1037. force_lcd_update=true;
  1038. }
  1039. //encoderpos=encoderpos%LCD_HEIGHT;
  1040. lastencoderpos=encoderpos;
  1041. activeline=encoderpos/lcdslow;
  1042. if(activeline>3) activeline=3;
  1043. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003');
  1044. }
  1045. }
  1046. void MainMenu::showSD()
  1047. {
  1048. #ifdef SDSUPPORT
  1049. uint8_t line=0;
  1050. if(lastlineoffset!=lineoffset)
  1051. {
  1052. force_lcd_update=true;
  1053. }
  1054. static uint8_t nrfiles=0;
  1055. if(force_lcd_update)
  1056. {
  1057. clear();
  1058. if(card.cardOK)
  1059. {
  1060. nrfiles=card.getnrfilenames();
  1061. }
  1062. else
  1063. {
  1064. nrfiles=0;
  1065. lineoffset=0;
  1066. }
  1067. //Serial.print("Nr files:"); Serial.println((int)nrfiles);
  1068. }
  1069. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1070. {
  1071. switch(i)
  1072. {
  1073. case 0:
  1074. {
  1075. if(force_lcd_update)
  1076. {
  1077. lcd.setCursor(0,line);lcd.print(" File");
  1078. }
  1079. if((activeline==line) && CLICKED)
  1080. {
  1081. BLOCK
  1082. status=Main_Menu;
  1083. beepshort();
  1084. }
  1085. }break;
  1086. case 1:
  1087. {
  1088. if(force_lcd_update)
  1089. {
  1090. lcd.setCursor(0,line);
  1091. #ifdef CARDINSERTED
  1092. if(CARDINSERTED)
  1093. #else
  1094. if(true)
  1095. #endif
  1096. {
  1097. lcd.print(" \004Refresh");
  1098. }
  1099. else
  1100. {
  1101. lcd.print(" \004Insert Card");
  1102. }
  1103. }
  1104. if((activeline==line) && CLICKED)
  1105. {
  1106. BLOCK;
  1107. beepshort();
  1108. card.initsd();
  1109. force_lcd_update=true;
  1110. nrfiles=card.getnrfilenames();
  1111. }
  1112. }break;
  1113. default:
  1114. {
  1115. if(i-2<nrfiles)
  1116. {
  1117. if(force_lcd_update)
  1118. {
  1119. card.getfilename(i-2);
  1120. //Serial.print("Filenr:");Serial.println(i-2);
  1121. lcd.setCursor(0,line);lcd.print(" ");lcd.print(card.filename);
  1122. }
  1123. if((activeline==line) && CLICKED)
  1124. {
  1125. BLOCK
  1126. card.getfilename(i-2);
  1127. char cmd[30];
  1128. for(int8_t i=0;i<strlen(card.filename);i++)
  1129. card.filename[i]=tolower(card.filename[i]);
  1130. sprintf(cmd,"M23 %s",card.filename);
  1131. //sprintf(cmd,"M115");
  1132. enquecommand(cmd);
  1133. enquecommand("M24");
  1134. beep();
  1135. status=Main_Status;
  1136. lcd_status(card.filename);
  1137. }
  1138. }
  1139. }
  1140. break;
  1141. }
  1142. line++;
  1143. }
  1144. lastlineoffset=lineoffset;
  1145. if((encoderpos!=lastencoderpos)||force_lcd_update)
  1146. {
  1147. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?' ':' ');
  1148. if(encoderpos<0)
  1149. {
  1150. lineoffset--;
  1151. if(lineoffset<0)
  1152. lineoffset=0;
  1153. encoderpos=0;
  1154. force_lcd_update=true;
  1155. }
  1156. if(encoderpos/lcdslow>3)
  1157. {
  1158. lineoffset++;
  1159. encoderpos=3*lcdslow;
  1160. if(lineoffset>(1+nrfiles+1-LCD_HEIGHT))
  1161. lineoffset=1+nrfiles+1-LCD_HEIGHT;
  1162. force_lcd_update=true;
  1163. }
  1164. lastencoderpos=encoderpos;
  1165. activeline=encoderpos;
  1166. if(activeline>3)
  1167. {
  1168. activeline=3;
  1169. }
  1170. if(activeline<0)
  1171. {
  1172. activeline=0;
  1173. }
  1174. if(activeline>1+nrfiles) activeline=1+nrfiles;
  1175. if(lineoffset>1+nrfiles) lineoffset=1+nrfiles;
  1176. lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003');
  1177. }
  1178. #endif
  1179. }
  1180. enum {ItemM_watch, ItemM_prepare, ItemM_control, ItemM_file };
  1181. void MainMenu::showMainMenu()
  1182. {
  1183. //if(int(encoderpos/lcdslow)!=int(lastencoderpos/lcdslow))
  1184. // force_lcd_update=true;
  1185. #ifndef ULTIPANEL
  1186. force_lcd_update=false;
  1187. #endif
  1188. //Serial.println((int)activeline);
  1189. if(force_lcd_update)
  1190. clear();
  1191. for(int8_t line=0;line<LCD_HEIGHT;line++)
  1192. {
  1193. switch(line)
  1194. {
  1195. case ItemM_watch:
  1196. {
  1197. if(force_lcd_update) {lcd.setCursor(0,line);lcd.print(" Watch \x7E");}
  1198. if((activeline==line)&&CLICKED)
  1199. {
  1200. BLOCK;
  1201. beepshort();
  1202. status=Main_Status;
  1203. }
  1204. } break;
  1205. case ItemM_prepare:
  1206. {
  1207. if(force_lcd_update) {lcd.setCursor(0,line);lcd.print(" Prepare \x7E");}
  1208. if((activeline==line)&&CLICKED)
  1209. {
  1210. BLOCK;
  1211. status=Main_Prepare;
  1212. beepshort();
  1213. }
  1214. } break;
  1215. case ItemM_control:
  1216. {
  1217. if(force_lcd_update) {lcd.setCursor(0,line);lcd.print(" Control \x7E");}
  1218. if((activeline==line)&&CLICKED)
  1219. {
  1220. BLOCK;
  1221. status=Main_Control;
  1222. beepshort();
  1223. }
  1224. }break;
  1225. #ifdef SDSUPPORT
  1226. case ItemM_file:
  1227. {
  1228. if(force_lcd_update)
  1229. {
  1230. lcd.setCursor(0,line);
  1231. #ifdef CARDINSERTED
  1232. if(CARDINSERTED)
  1233. #else
  1234. if(true)
  1235. #endif
  1236. {
  1237. if(card.sdprinting)
  1238. lcd.print(" Stop Print \x7E");
  1239. else
  1240. lcd.print(" Card Menu \x7E");
  1241. }
  1242. else
  1243. {
  1244. lcd.print(" No Card");
  1245. }
  1246. }
  1247. #ifdef CARDINSERTED
  1248. if(CARDINSERTED)
  1249. #endif
  1250. if((activeline==line)&&CLICKED)
  1251. {
  1252. card.sdprinting = false;
  1253. BLOCK;
  1254. status=Main_SD;
  1255. beepshort();
  1256. }
  1257. }break;
  1258. #endif
  1259. default:
  1260. SERIAL_ERRORLN("Something is wrong in the MenuStructure.");
  1261. break;
  1262. }
  1263. }
  1264. if(activeline<0)
  1265. activeline=0;
  1266. if(activeline>=LCD_HEIGHT)
  1267. activeline=LCD_HEIGHT-1;
  1268. if((encoderpos!=lastencoderpos)||force_lcd_update)
  1269. {
  1270. lcd.setCursor(0,activeline);lcd.print(activeline?' ':' ');
  1271. if(encoderpos<0) encoderpos=0;
  1272. if(encoderpos>3*lcdslow)
  1273. encoderpos=3*lcdslow;
  1274. activeline=abs(encoderpos/lcdslow)%LCD_HEIGHT;
  1275. if(activeline<0)
  1276. activeline=0;
  1277. if(activeline>=LCD_HEIGHT)
  1278. activeline=LCD_HEIGHT-1;
  1279. lastencoderpos=encoderpos;
  1280. lcd.setCursor(0,activeline);lcd.print(activeline?'>':'\003');
  1281. }
  1282. }
  1283. void MainMenu::update()
  1284. {
  1285. static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
  1286. static long timeoutToStatus=0;
  1287. static bool oldcardstatus=false;
  1288. #ifdef CARDINSERTED
  1289. if((CARDINSERTED != oldcardstatus))
  1290. {
  1291. force_lcd_update=true;
  1292. oldcardstatus=CARDINSERTED;
  1293. //Serial.println("echo: SD CHANGE");
  1294. if(CARDINSERTED)
  1295. {
  1296. card.initsd();
  1297. lcd_status("Card inserted");
  1298. }
  1299. else
  1300. {
  1301. card.release();
  1302. lcd_status("Card removed");
  1303. }
  1304. }
  1305. #endif
  1306. if(status!=oldstatus)
  1307. {
  1308. //Serial.println(status);
  1309. //clear();
  1310. force_lcd_update=true;
  1311. encoderpos=0;
  1312. lineoffset=0;
  1313. oldstatus=status;
  1314. }
  1315. if( (encoderpos!=lastencoderpos) || CLICKED)
  1316. timeoutToStatus=millis()+STATUSTIMEOUT;
  1317. switch(status)
  1318. {
  1319. case Main_Status:
  1320. {
  1321. showStatus();
  1322. if(CLICKED)
  1323. {
  1324. linechanging=false;
  1325. BLOCK
  1326. status=Main_Menu;
  1327. timeoutToStatus=millis()+STATUSTIMEOUT;
  1328. }
  1329. }break;
  1330. case Main_Menu:
  1331. {
  1332. showMainMenu();
  1333. linechanging=false;
  1334. }break;
  1335. case Main_Prepare:
  1336. {
  1337. showPrepare();
  1338. }break;
  1339. case Main_Control:
  1340. {
  1341. showControl();
  1342. }break;
  1343. case Main_SD:
  1344. {
  1345. showSD();
  1346. }break;
  1347. }
  1348. if(timeoutToStatus<millis())
  1349. status=Main_Status;
  1350. force_lcd_update=false;
  1351. lastencoderpos=encoderpos;
  1352. }
  1353. // convert float to string with +123.4 format
  1354. char *ftostr3(const float &x)
  1355. {
  1356. //sprintf(conv,"%5.1f",x);
  1357. int xx=x;
  1358. conv[0]=(xx/100)%10+'0';
  1359. conv[1]=(xx/10)%10+'0';
  1360. conv[2]=(xx)%10+'0';
  1361. conv[3]=0;
  1362. return conv;
  1363. }
  1364. char *itostr2(const uint8_t &x)
  1365. {
  1366. //sprintf(conv,"%5.1f",x);
  1367. int xx=x;
  1368. conv[0]=(xx/10)%10+'0';
  1369. conv[1]=(xx)%10+'0';
  1370. conv[2]=0;
  1371. return conv;
  1372. }
  1373. // convert float to string with +123.4 format
  1374. char *ftostr31(const float &x)
  1375. {
  1376. int xx=x*10;
  1377. conv[0]=(xx>=0)?'+':'-';
  1378. xx=abs(xx);
  1379. conv[1]=(xx/1000)%10+'0';
  1380. conv[2]=(xx/100)%10+'0';
  1381. conv[3]=(xx/10)%10+'0';
  1382. conv[4]='.';
  1383. conv[5]=(xx)%10+'0';
  1384. conv[6]=0;
  1385. return conv;
  1386. }
  1387. char *itostr31(const int &xx)
  1388. {
  1389. conv[0]=(xx>=0)?'+':'-';
  1390. conv[1]=(xx/1000)%10+'0';
  1391. conv[2]=(xx/100)%10+'0';
  1392. conv[3]=(xx/10)%10+'0';
  1393. conv[4]='.';
  1394. conv[5]=(xx)%10+'0';
  1395. conv[6]=0;
  1396. return conv;
  1397. }
  1398. char *itostr3(const int &xx)
  1399. {
  1400. conv[0]=(xx/100)%10+'0';
  1401. conv[1]=(xx/10)%10+'0';
  1402. conv[2]=(xx)%10+'0';
  1403. conv[3]=0;
  1404. return conv;
  1405. }
  1406. char *itostr4(const int &xx)
  1407. {
  1408. conv[0]=(xx/1000)%10+'0';
  1409. conv[1]=(xx/100)%10+'0';
  1410. conv[2]=(xx/10)%10+'0';
  1411. conv[3]=(xx)%10+'0';
  1412. conv[4]=0;
  1413. return conv;
  1414. }
  1415. // convert float to string with +1234.5 format
  1416. char *ftostr51(const float &x)
  1417. {
  1418. int xx=x*10;
  1419. conv[0]=(xx>=0)?'+':'-';
  1420. xx=abs(xx);
  1421. conv[1]=(xx/10000)%10+'0';
  1422. conv[2]=(xx/1000)%10+'0';
  1423. conv[3]=(xx/100)%10+'0';
  1424. conv[4]=(xx/10)%10+'0';
  1425. conv[5]='.';
  1426. conv[6]=(xx)%10+'0';
  1427. conv[7]=0;
  1428. return conv;
  1429. }
  1430. char *fillto(int8_t n,char *c)
  1431. {
  1432. static char ret[25];
  1433. bool endfound=false;
  1434. for(int8_t i=0;i<n;i++)
  1435. {
  1436. ret[i]=c[i];
  1437. if(c[i]==0)
  1438. {
  1439. endfound=true;
  1440. }
  1441. if(endfound)
  1442. {
  1443. ret[i]=' ';
  1444. }
  1445. }
  1446. ret[n]=0;
  1447. return ret;
  1448. }
  1449. #endif //ULTRA_LCD