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

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