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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197
  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 X-105 Y-105 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(170);setTargetBed(70);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. clearIfNecessary();
  470. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  471. {
  472. switch(i)
  473. {
  474. case ItemAM_exit:
  475. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  476. break;
  477. case ItemAM_X:
  478. // MENUITEM( lcdprintPGM(" X+") , BLOCK;enquecommand("G92 X0");enquecommand("G1 F700 X10");beepshort(); ) ;
  479. {
  480. if(force_lcd_update)
  481. {
  482. lcd.setCursor(0,line);lcdprintPGM(" X:");
  483. lcd.setCursor(13,line);lcd.print(ftostr3(current_position[X_AXIS]));
  484. }
  485. if((activeline!=line) )
  486. break;
  487. if(CLICKED)
  488. {
  489. linechanging=!linechanging;
  490. if(linechanging)
  491. {
  492. encoderpos=current_position[X_AXIS];
  493. }
  494. else
  495. {
  496. enquecommand("G1 F700 X"+encoderpos);
  497. encoderpos=activeline*lcdslow;
  498. beepshort();
  499. }
  500. BLOCK;
  501. }
  502. if(linechanging)
  503. {
  504. if(encoderpos<1) encoderpos=1;
  505. if(encoderpos>200) encoderpos=200;
  506. lcd.setCursor(13,line);lcd.print(current_position[X_AXIS]);
  507. }
  508. }
  509. break;
  510. case ItemAM_Y:
  511. //MENUITEM( lcdprintPGM(" Y+") , BLOCK;enquecommand("G92 Y0");enquecommand("G1 F700 Y10");beepshort(); ) ;
  512. {
  513. if(force_lcd_update)
  514. {
  515. lcd.setCursor(0,line);lcdprintPGM(" Y:");
  516. lcd.setCursor(13,line);lcd.print(ftostr3(current_position[Y_AXIS]));
  517. }
  518. if((activeline!=line) )
  519. break;
  520. if(CLICKED)
  521. {
  522. linechanging=!linechanging;
  523. if(linechanging)
  524. {
  525. encoderpos=current_position[Y_AXIS];
  526. }
  527. else
  528. {
  529. enquecommand("G1 F700 Y"+encoderpos);
  530. encoderpos=activeline*lcdslow;
  531. beepshort();
  532. }
  533. BLOCK;
  534. }
  535. if(linechanging)
  536. {
  537. if(encoderpos<1) encoderpos=1;
  538. if(encoderpos>200) encoderpos=200;
  539. lcd.setCursor(13,line);lcd.print(current_position[Y_AXIS]);
  540. }
  541. }
  542. break;
  543. case ItemAM_Z:
  544. //MENUITEM( lcdprintPGM(" Z+") , BLOCK;enquecommand("G92 Z0");enquecommand("G1 F700 Z10");beepshort(); ) ;
  545. {
  546. if(force_lcd_update)
  547. {
  548. lcd.setCursor(0,line);lcdprintPGM(" Z:");
  549. lcd.setCursor(13,line);lcd.print(ftostr3(current_position[Z_AXIS]));
  550. }
  551. if((activeline!=line) )
  552. break;
  553. if(CLICKED)
  554. {
  555. linechanging=!linechanging;
  556. if(linechanging)
  557. {
  558. encoderpos=current_position[Z_AXIS];
  559. }
  560. else
  561. {
  562. enquecommand("G1 F700 Z"+encoderpos);
  563. encoderpos=activeline*lcdslow;
  564. beepshort();
  565. }
  566. BLOCK;
  567. }
  568. if(linechanging)
  569. {
  570. if(encoderpos<1) encoderpos=1;
  571. if(encoderpos>170) encoderpos=170;
  572. lcd.setCursor(13,line);lcd.print(current_position[Z_AXIS]);
  573. }
  574. }
  575. break;
  576. case ItemAM_E:
  577. MENUITEM( lcdprintPGM(" Extrude") , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E10");beepshort(); ) ;
  578. break;
  579. default:
  580. break;
  581. }
  582. line++;
  583. }
  584. updateActiveLines(ItemAM_E,encoderpos);
  585. }
  586. enum {ItemT_exit,ItemT_speed,ItemT_flow,ItemT_nozzle,
  587. #if (HEATER_BED_PIN > -1)
  588. ItemT_bed,
  589. #endif
  590. ItemT_fan};
  591. void MainMenu::showTune()
  592. {
  593. uint8_t line=0;
  594. clearIfNecessary();
  595. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  596. {
  597. //Serial.println((int)(line-lineoffset));
  598. switch(i)
  599. {
  600. case ItemT_exit:
  601. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  602. break;
  603. case ItemT_speed:
  604. {
  605. if(force_lcd_update)
  606. {
  607. lcd.setCursor(0,line);lcdprintPGM(" Speed:");
  608. lcd.setCursor(13,line);lcd.print(ftostr3(feedmultiply));
  609. }
  610. if((activeline!=line) )
  611. break;
  612. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  613. {
  614. linechanging=!linechanging;
  615. if(linechanging)
  616. {
  617. encoderpos=feedmultiply;
  618. }
  619. else
  620. {
  621. encoderpos=activeline*lcdslow;
  622. beepshort();
  623. }
  624. BLOCK;
  625. }
  626. if(linechanging)
  627. {
  628. if(encoderpos<1) encoderpos=1;
  629. if(encoderpos>400) encoderpos=400;
  630. feedmultiply = encoderpos;
  631. feedmultiplychanged=true;
  632. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  633. }
  634. }break;
  635. case ItemT_nozzle:
  636. {
  637. if(force_lcd_update)
  638. {
  639. lcd.setCursor(0,line);lcdprintPGM(" \002Nozzle:");
  640. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  641. }
  642. if((activeline!=line) )
  643. break;
  644. if(CLICKED)
  645. {
  646. linechanging=!linechanging;
  647. if(linechanging)
  648. {
  649. encoderpos=intround(degTargetHotend0());
  650. }
  651. else
  652. {
  653. setTargetHotend0(encoderpos);
  654. encoderpos=activeline*lcdslow;
  655. beepshort();
  656. }
  657. BLOCK;
  658. }
  659. if(linechanging)
  660. {
  661. if(encoderpos<0) encoderpos=0;
  662. if(encoderpos>260) encoderpos=260;
  663. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  664. }
  665. }break;
  666. #if (HEATER_BED_PIN > -1)
  667. case ItemT_bed:
  668. {
  669. if(force_lcd_update)
  670. {
  671. lcd.setCursor(0,line);lcdprintPGM(" \002Bed:");
  672. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  673. }
  674. if((activeline!=line) )
  675. break;
  676. if(CLICKED)
  677. {
  678. linechanging=!linechanging;
  679. if(linechanging)
  680. {
  681. encoderpos=intround(degTargetBed());
  682. }
  683. else
  684. {
  685. setTargetBed(encoderpos);
  686. encoderpos=activeline*lcdslow;
  687. beepshort();
  688. }
  689. BLOCK;
  690. }
  691. if(linechanging)
  692. {
  693. if(encoderpos<0) encoderpos=0;
  694. if(encoderpos>260) encoderpos=260;
  695. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  696. }
  697. }break;
  698. #endif
  699. case ItemT_fan:
  700. {
  701. if(force_lcd_update)
  702. {
  703. lcd.setCursor(0,line);lcdprintPGM(" Fan speed:");
  704. lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
  705. }
  706. if((activeline!=line) )
  707. break;
  708. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  709. {
  710. linechanging=!linechanging;
  711. if(linechanging)
  712. {
  713. encoderpos=fanpwm;
  714. }
  715. else
  716. {
  717. encoderpos=activeline*lcdslow;
  718. beepshort();
  719. }
  720. BLOCK;
  721. }
  722. if(linechanging)
  723. {
  724. if(encoderpos<0) encoderpos=0;
  725. if(encoderpos>255) encoderpos=255;
  726. fanpwm=encoderpos;
  727. analogWrite(FAN_PIN, fanpwm);
  728. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  729. }
  730. }break;
  731. case ItemT_flow://axis_steps_per_unit[i] = code_value();
  732. {
  733. if(force_lcd_update)
  734. {
  735. lcd.setCursor(0,line);lcdprintPGM(" Flow:");
  736. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3]));
  737. }
  738. if((activeline!=line) )
  739. break;
  740. if(CLICKED)
  741. {
  742. linechanging=!linechanging;
  743. if(linechanging)
  744. {
  745. encoderpos=(int)axis_steps_per_unit[3];
  746. }
  747. else
  748. {
  749. float factor=float(encoderpos)/float(axis_steps_per_unit[3]);
  750. position[E_AXIS]=lround(position[E_AXIS]*factor);
  751. //current_position[3]*=factor;
  752. axis_steps_per_unit[E_AXIS]= encoderpos;
  753. encoderpos=activeline*lcdslow;
  754. }
  755. BLOCK;
  756. beepshort();
  757. }
  758. if(linechanging)
  759. {
  760. if(encoderpos<5) encoderpos=5;
  761. if(encoderpos>9999) encoderpos=9999;
  762. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  763. }
  764. }break;
  765. default:
  766. break;
  767. }
  768. line++;
  769. }
  770. updateActiveLines(ItemT_fan,encoderpos);
  771. }
  772. //does not work
  773. // #define MENUCHANGEITEM(repaint_action, enter_action, accept_action, change_action) \
  774. // {\
  775. // if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  776. // if(activeline==line) \
  777. // { \
  778. // if(CLICKED) \
  779. // { \
  780. // linechanging=!linechanging; \
  781. // if(linechanging) {enter_action;} \
  782. // else {accept_action;} \
  783. // } \
  784. // else \
  785. // if(linechanging) {change_action};}\
  786. // }
  787. //
  788. enum {
  789. ItemCT_exit,ItemCT_nozzle,
  790. #ifdef AUTOTEMP
  791. ItemCT_autotempactive,
  792. ItemCT_autotempmin,ItemCT_autotempmax,ItemCT_autotempfact,
  793. #endif
  794. #if (HEATER_BED_PIN > -1)
  795. ItemCT_bed,
  796. #endif
  797. ItemCT_fan,
  798. ItemCT_PID_P,ItemCT_PID_I,ItemCT_PID_D,ItemCT_PID_C
  799. };
  800. void MainMenu::showControlTemp()
  801. {
  802. uint8_t line=0;
  803. clearIfNecessary();
  804. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  805. {
  806. switch(i)
  807. {
  808. case ItemCT_exit:
  809. MENUITEM( lcdprintPGM(" Control \003") , BLOCK;status=Main_Control;beepshort(); ) ;
  810. break;
  811. case ItemCT_nozzle:
  812. {
  813. if(force_lcd_update)
  814. {
  815. lcd.setCursor(0,line);lcdprintPGM(" \002Nozzle:");
  816. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  817. }
  818. if((activeline!=line) )
  819. break;
  820. if(CLICKED)
  821. {
  822. linechanging=!linechanging;
  823. if(linechanging)
  824. {
  825. encoderpos=intround(degTargetHotend0());
  826. }
  827. else
  828. {
  829. setTargetHotend0(encoderpos);
  830. encoderpos=activeline*lcdslow;
  831. beepshort();
  832. }
  833. BLOCK;
  834. }
  835. if(linechanging)
  836. {
  837. if(encoderpos<0) encoderpos=0;
  838. if(encoderpos>260) encoderpos=260;
  839. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  840. }
  841. }break;
  842. #ifdef AUTOTEMP
  843. case ItemCT_autotempmin:
  844. {
  845. if(force_lcd_update)
  846. {
  847. lcd.setCursor(0,line);lcdprintPGM(" \002 Min:");
  848. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_min));
  849. }
  850. if((activeline!=line) )
  851. break;
  852. if(CLICKED)
  853. {
  854. linechanging=!linechanging;
  855. if(linechanging)
  856. {
  857. encoderpos=intround(autotemp_min);
  858. }
  859. else
  860. {
  861. autotemp_min=encoderpos;
  862. encoderpos=activeline*lcdslow;
  863. beepshort();
  864. }
  865. BLOCK;
  866. }
  867. if(linechanging)
  868. {
  869. if(encoderpos<0) encoderpos=0;
  870. if(encoderpos>260) encoderpos=260;
  871. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  872. }
  873. }break;
  874. case ItemCT_autotempmax:
  875. {
  876. if(force_lcd_update)
  877. {
  878. lcd.setCursor(0,line);lcdprintPGM(" \002 Max:");
  879. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_max));
  880. }
  881. if((activeline!=line) )
  882. break;
  883. if(CLICKED)
  884. {
  885. linechanging=!linechanging;
  886. if(linechanging)
  887. {
  888. encoderpos=intround(autotemp_max);
  889. }
  890. else
  891. {
  892. autotemp_max=encoderpos;
  893. encoderpos=activeline*lcdslow;
  894. beepshort();
  895. }
  896. BLOCK;
  897. }
  898. if(linechanging)
  899. {
  900. if(encoderpos<0) encoderpos=0;
  901. if(encoderpos>260) encoderpos=260;
  902. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  903. }
  904. }break;
  905. case ItemCT_autotempfact:
  906. {
  907. if(force_lcd_update)
  908. {
  909. lcd.setCursor(0,line);lcdprintPGM(" \002 Fact:");
  910. lcd.setCursor(13,line);lcd.print(ftostr32(autotemp_factor));
  911. }
  912. if((activeline!=line) )
  913. break;
  914. if(CLICKED)
  915. {
  916. linechanging=!linechanging;
  917. if(linechanging)
  918. {
  919. encoderpos=intround(autotemp_factor*100);
  920. }
  921. else
  922. {
  923. autotemp_max=encoderpos;
  924. encoderpos=activeline*lcdslow;
  925. beepshort();
  926. }
  927. BLOCK;
  928. }
  929. if(linechanging)
  930. {
  931. if(encoderpos<0) encoderpos=0;
  932. if(encoderpos>99) encoderpos=99;
  933. lcd.setCursor(13,line);lcd.print(ftostr32(encoderpos/100.));
  934. }
  935. }break;
  936. case ItemCT_autotempactive:
  937. {
  938. if(force_lcd_update)
  939. {
  940. lcd.setCursor(0,line);lcdprintPGM(" Autotemp:");
  941. lcd.setCursor(13,line);
  942. if(autotemp_enabled)
  943. lcdprintPGM("On");
  944. else
  945. lcdprintPGM("Off");
  946. }
  947. if((activeline!=line) )
  948. break;
  949. if(CLICKED)
  950. {
  951. autotemp_enabled=!autotemp_enabled;
  952. lcd.setCursor(13,line);
  953. if(autotemp_enabled)
  954. lcdprintPGM("On ");
  955. else
  956. lcdprintPGM("Off");
  957. BLOCK;
  958. }
  959. }break;
  960. #endif //autotemp
  961. #if (HEATER_BED_PIN > -1)
  962. case ItemCT_bed:
  963. {
  964. if(force_lcd_update)
  965. {
  966. lcd.setCursor(0,line);lcdprintPGM(" \002Bed:");
  967. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  968. }
  969. if((activeline!=line) )
  970. break;
  971. if(CLICKED)
  972. {
  973. linechanging=!linechanging;
  974. if(linechanging)
  975. {
  976. encoderpos=intround(degTargetBed());
  977. }
  978. else
  979. {
  980. setTargetBed(encoderpos);
  981. encoderpos=activeline*lcdslow;
  982. beepshort();
  983. }
  984. BLOCK;
  985. }
  986. if(linechanging)
  987. {
  988. if(encoderpos<0) encoderpos=0;
  989. if(encoderpos>260) encoderpos=260;
  990. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  991. }
  992. }break;
  993. #endif
  994. case ItemCT_fan:
  995. {
  996. if(force_lcd_update)
  997. {
  998. lcd.setCursor(0,line);lcdprintPGM(" Fan speed:");
  999. lcd.setCursor(13,line);lcd.print(ftostr3(fanpwm));
  1000. }
  1001. if((activeline!=line) )
  1002. break;
  1003. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  1004. {
  1005. linechanging=!linechanging;
  1006. if(linechanging)
  1007. {
  1008. encoderpos=fanpwm;
  1009. }
  1010. else
  1011. {
  1012. encoderpos=activeline*lcdslow;
  1013. beepshort();
  1014. }
  1015. BLOCK;
  1016. }
  1017. if(linechanging)
  1018. {
  1019. if(encoderpos<0) encoderpos=0;
  1020. if(encoderpos>255) encoderpos=255;
  1021. fanpwm=encoderpos;
  1022. analogWrite(FAN_PIN, fanpwm);
  1023. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1024. }
  1025. }break;
  1026. case ItemCT_PID_P:
  1027. {
  1028. if(force_lcd_update)
  1029. {
  1030. lcd.setCursor(0,line);lcdprintPGM(" PID-P: ");
  1031. lcd.setCursor(13,line);lcd.print(itostr4(Kp));
  1032. }
  1033. if((activeline!=line) )
  1034. break;
  1035. if(CLICKED)
  1036. {
  1037. linechanging=!linechanging;
  1038. if(linechanging)
  1039. {
  1040. encoderpos=(int)Kp;
  1041. }
  1042. else
  1043. {
  1044. Kp= encoderpos;
  1045. encoderpos=activeline*lcdslow;
  1046. }
  1047. BLOCK;
  1048. beepshort();
  1049. }
  1050. if(linechanging)
  1051. {
  1052. if(encoderpos<1) encoderpos=1;
  1053. if(encoderpos>9990) encoderpos=9990;
  1054. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1055. }
  1056. }break;
  1057. case ItemCT_PID_I:
  1058. {
  1059. if(force_lcd_update)
  1060. {
  1061. lcd.setCursor(0,line);lcdprintPGM(" PID-I: ");
  1062. lcd.setCursor(13,line);lcd.print(ftostr51(Ki/PID_dT));
  1063. }
  1064. if((activeline!=line) )
  1065. break;
  1066. if(CLICKED)
  1067. {
  1068. linechanging=!linechanging;
  1069. if(linechanging)
  1070. {
  1071. encoderpos=(int)(Ki*10/PID_dT);
  1072. }
  1073. else
  1074. {
  1075. Ki= encoderpos/10.*PID_dT;
  1076. encoderpos=activeline*lcdslow;
  1077. }
  1078. BLOCK;
  1079. beepshort();
  1080. }
  1081. if(linechanging)
  1082. {
  1083. if(encoderpos<0) encoderpos=0;
  1084. if(encoderpos>9990) encoderpos=9990;
  1085. lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.));
  1086. }
  1087. }break;
  1088. case ItemCT_PID_D:
  1089. {
  1090. if(force_lcd_update)
  1091. {
  1092. lcd.setCursor(0,line);lcdprintPGM(" PID-D: ");
  1093. lcd.setCursor(13,line);lcd.print(itostr4(Kd*PID_dT));
  1094. }
  1095. if((activeline!=line) )
  1096. break;
  1097. if(CLICKED)
  1098. {
  1099. linechanging=!linechanging;
  1100. if(linechanging)
  1101. {
  1102. encoderpos=(int)(Kd/5./PID_dT);
  1103. }
  1104. else
  1105. {
  1106. Kd= encoderpos;
  1107. encoderpos=activeline*lcdslow;
  1108. }
  1109. BLOCK;
  1110. beepshort();
  1111. }
  1112. if(linechanging)
  1113. {
  1114. if(encoderpos<0) encoderpos=0;
  1115. if(encoderpos>9990) encoderpos=9990;
  1116. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1117. }
  1118. }break;
  1119. case ItemCT_PID_C:
  1120. #ifdef PID_ADD_EXTRUSION_RATE
  1121. {
  1122. if(force_lcd_update)
  1123. {
  1124. lcd.setCursor(0,line);lcdprintPGM(" PID-C: ");
  1125. lcd.setCursor(13,line);lcd.print(itostr3(Kc));
  1126. }
  1127. if((activeline!=line) )
  1128. break;
  1129. if(CLICKED)
  1130. {
  1131. linechanging=!linechanging;
  1132. if(linechanging)
  1133. {
  1134. encoderpos=(int)Kc;
  1135. }
  1136. else
  1137. {
  1138. Kc= encoderpos;
  1139. encoderpos=activeline*lcdslow;
  1140. }
  1141. BLOCK;
  1142. beepshort();
  1143. }
  1144. if(linechanging)
  1145. {
  1146. if(encoderpos<0) encoderpos=0;
  1147. if(encoderpos>990) encoderpos=990;
  1148. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1149. }
  1150. }
  1151. #endif
  1152. break;
  1153. default:
  1154. break;
  1155. }
  1156. line++;
  1157. }
  1158. #ifdef PID_ADD_EXTRUSION_RATE
  1159. updateActiveLines(ItemCT_PID_C,encoderpos);
  1160. #else
  1161. updateActiveLines(ItemCT_PID_D,encoderpos);
  1162. #endif
  1163. }
  1164. enum {
  1165. ItemCM_exit,
  1166. ItemCM_acc, ItemCM_xyjerk,
  1167. ItemCM_vmaxx, ItemCM_vmaxy, ItemCM_vmaxz, ItemCM_vmaxe,
  1168. ItemCM_vtravmin,ItemCM_vmin,
  1169. ItemCM_amaxx, ItemCM_amaxy, ItemCM_amaxz, ItemCM_amaxe,
  1170. ItemCM_aret, ItemCM_xsteps,ItemCM_ysteps, ItemCM_zsteps, ItemCM_esteps
  1171. };
  1172. void MainMenu::showControlMotion()
  1173. {
  1174. uint8_t line=0;
  1175. clearIfNecessary();
  1176. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1177. {
  1178. switch(i)
  1179. {
  1180. case ItemCM_exit:
  1181. MENUITEM( lcdprintPGM(" Control \003") , BLOCK;status=Main_Control;beepshort(); ) ;
  1182. break;
  1183. case ItemCM_acc:
  1184. {
  1185. if(force_lcd_update)
  1186. {
  1187. lcd.setCursor(0,line);lcdprintPGM(" Acc:");
  1188. lcd.setCursor(13,line);lcd.print(itostr3(acceleration/100));lcdprintPGM("00");
  1189. }
  1190. if((activeline!=line) )
  1191. break;
  1192. if(CLICKED)
  1193. {
  1194. linechanging=!linechanging;
  1195. if(linechanging)
  1196. {
  1197. encoderpos=(int)acceleration/100;
  1198. }
  1199. else
  1200. {
  1201. acceleration= encoderpos*100;
  1202. encoderpos=activeline*lcdslow;
  1203. }
  1204. BLOCK;
  1205. beepshort();
  1206. }
  1207. if(linechanging)
  1208. {
  1209. if(encoderpos<5) encoderpos=5;
  1210. if(encoderpos>990) encoderpos=990;
  1211. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1212. }
  1213. }break;
  1214. case ItemCM_xyjerk: //max_xy_jerk
  1215. {
  1216. if(force_lcd_update)
  1217. {
  1218. lcd.setCursor(0,line);lcdprintPGM(" Vxy-jerk: ");
  1219. lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk));
  1220. }
  1221. if((activeline!=line) )
  1222. break;
  1223. if(CLICKED)
  1224. {
  1225. linechanging=!linechanging;
  1226. if(linechanging)
  1227. {
  1228. encoderpos=(int)max_xy_jerk;
  1229. }
  1230. else
  1231. {
  1232. max_xy_jerk= encoderpos;
  1233. encoderpos=activeline*lcdslow;
  1234. }
  1235. BLOCK;
  1236. beepshort();
  1237. }
  1238. if(linechanging)
  1239. {
  1240. if(encoderpos<1) encoderpos=1;
  1241. if(encoderpos>990) encoderpos=990;
  1242. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1243. }
  1244. }break;
  1245. case ItemCM_vmaxx:
  1246. case ItemCM_vmaxy:
  1247. case ItemCM_vmaxz:
  1248. case ItemCM_vmaxe:
  1249. {
  1250. if(force_lcd_update)
  1251. {
  1252. lcd.setCursor(0,line);lcdprintPGM(" Vmax ");
  1253. if(i==ItemCM_vmaxx)lcdprintPGM("x:");
  1254. if(i==ItemCM_vmaxy)lcdprintPGM("y:");
  1255. if(i==ItemCM_vmaxz)lcdprintPGM("z:");
  1256. if(i==ItemCM_vmaxe)lcdprintPGM("e:");
  1257. lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemCM_vmaxx]));
  1258. }
  1259. if((activeline!=line) )
  1260. break;
  1261. if(CLICKED)
  1262. {
  1263. linechanging=!linechanging;
  1264. if(linechanging)
  1265. {
  1266. encoderpos=(int)max_feedrate[i-ItemCM_vmaxx];
  1267. }
  1268. else
  1269. {
  1270. max_feedrate[i-ItemCM_vmaxx]= encoderpos;
  1271. encoderpos=activeline*lcdslow;
  1272. }
  1273. BLOCK;
  1274. beepshort();
  1275. }
  1276. if(linechanging)
  1277. {
  1278. if(encoderpos<1) encoderpos=1;
  1279. if(encoderpos>990) encoderpos=990;
  1280. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1281. }
  1282. }break;
  1283. case ItemCM_vmin:
  1284. {
  1285. if(force_lcd_update)
  1286. {
  1287. lcd.setCursor(0,line);lcdprintPGM(" Vmin:");
  1288. lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate));
  1289. }
  1290. if((activeline!=line) )
  1291. break;
  1292. if(CLICKED)
  1293. {
  1294. linechanging=!linechanging;
  1295. if(linechanging)
  1296. {
  1297. encoderpos=(int)(minimumfeedrate);
  1298. }
  1299. else
  1300. {
  1301. minimumfeedrate= encoderpos;
  1302. encoderpos=activeline*lcdslow;
  1303. }
  1304. BLOCK;
  1305. beepshort();
  1306. }
  1307. if(linechanging)
  1308. {
  1309. if(encoderpos<0) encoderpos=0;
  1310. if(encoderpos>990) encoderpos=990;
  1311. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1312. }
  1313. }break;
  1314. case ItemCM_vtravmin:
  1315. {
  1316. if(force_lcd_update)
  1317. {
  1318. lcd.setCursor(0,line);lcdprintPGM(" VTrav min:");
  1319. lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate));
  1320. }
  1321. if((activeline!=line) )
  1322. break;
  1323. if(CLICKED)
  1324. {
  1325. linechanging=!linechanging;
  1326. if(linechanging)
  1327. {
  1328. encoderpos=(int)mintravelfeedrate;
  1329. }
  1330. else
  1331. {
  1332. mintravelfeedrate= encoderpos;
  1333. encoderpos=activeline*lcdslow;
  1334. }
  1335. BLOCK;
  1336. beepshort();
  1337. }
  1338. if(linechanging)
  1339. {
  1340. if(encoderpos<0) encoderpos=0;
  1341. if(encoderpos>990) encoderpos=990;
  1342. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1343. }
  1344. }break;
  1345. case ItemCM_amaxx:
  1346. case ItemCM_amaxy:
  1347. case ItemCM_amaxz:
  1348. case ItemCM_amaxe:
  1349. {
  1350. if(force_lcd_update)
  1351. {
  1352. lcd.setCursor(0,line);lcdprintPGM(" Amax ");
  1353. if(i==ItemCM_amaxx)lcdprintPGM("x:");
  1354. if(i==ItemCM_amaxy)lcdprintPGM("y:");
  1355. if(i==ItemCM_amaxz)lcdprintPGM("z:");
  1356. if(i==ItemCM_amaxe)lcdprintPGM("e:");
  1357. lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100));lcdprintPGM("00");
  1358. }
  1359. if((activeline!=line) )
  1360. break;
  1361. if(CLICKED)
  1362. {
  1363. linechanging=!linechanging;
  1364. if(linechanging)
  1365. {
  1366. encoderpos=(int)max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100;
  1367. }
  1368. else
  1369. {
  1370. max_acceleration_units_per_sq_second[i-ItemCM_amaxx]= encoderpos*100;
  1371. encoderpos=activeline*lcdslow;
  1372. }
  1373. BLOCK;
  1374. beepshort();
  1375. }
  1376. if(linechanging)
  1377. {
  1378. if(encoderpos<1) encoderpos=1;
  1379. if(encoderpos>990) encoderpos=990;
  1380. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1381. }
  1382. }break;
  1383. case ItemCM_aret://float retract_acceleration = 7000;
  1384. {
  1385. if(force_lcd_update)
  1386. {
  1387. lcd.setCursor(0,line);lcdprintPGM(" A-retract:");
  1388. lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcdprintPGM("00");
  1389. }
  1390. if((activeline!=line) )
  1391. break;
  1392. if(CLICKED)
  1393. {
  1394. linechanging=!linechanging;
  1395. if(linechanging)
  1396. {
  1397. encoderpos=(int)retract_acceleration/100;
  1398. }
  1399. else
  1400. {
  1401. retract_acceleration= encoderpos*100;
  1402. encoderpos=activeline*lcdslow;
  1403. }
  1404. BLOCK;
  1405. beepshort();
  1406. }
  1407. if(linechanging)
  1408. {
  1409. if(encoderpos<10) encoderpos=10;
  1410. if(encoderpos>990) encoderpos=990;
  1411. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1412. }
  1413. }break;
  1414. case ItemCM_xsteps://axis_steps_per_unit[i] = code_value();
  1415. {
  1416. if(force_lcd_update)
  1417. {
  1418. lcd.setCursor(0,line);lcdprintPGM(" X steps/mm:");
  1419. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[0]));
  1420. }
  1421. if((activeline!=line) )
  1422. break;
  1423. if(CLICKED)
  1424. {
  1425. linechanging=!linechanging;
  1426. if(linechanging)
  1427. {
  1428. encoderpos=(int)axis_steps_per_unit[0];
  1429. }
  1430. else
  1431. {
  1432. float factor=float(encoderpos)/float(axis_steps_per_unit[0]);
  1433. position[X_AXIS]=lround(position[X_AXIS]*factor);
  1434. //current_position[3]*=factor;
  1435. axis_steps_per_unit[X_AXIS]= encoderpos;
  1436. encoderpos=activeline*lcdslow;
  1437. }
  1438. BLOCK;
  1439. beepshort();
  1440. }
  1441. if(linechanging)
  1442. {
  1443. if(encoderpos<5) encoderpos=5;
  1444. if(encoderpos>9999) encoderpos=9999;
  1445. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1446. }
  1447. }break;
  1448. case ItemCM_ysteps://axis_steps_per_unit[i] = code_value();
  1449. {
  1450. if(force_lcd_update)
  1451. {
  1452. lcd.setCursor(0,line);lcdprintPGM(" Y steps/mm:");
  1453. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[1]));
  1454. }
  1455. if((activeline!=line) )
  1456. break;
  1457. if(CLICKED)
  1458. {
  1459. linechanging=!linechanging;
  1460. if(linechanging)
  1461. {
  1462. encoderpos=(int)axis_steps_per_unit[1];
  1463. }
  1464. else
  1465. {
  1466. float factor=float(encoderpos)/float(axis_steps_per_unit[1]);
  1467. position[Y_AXIS]=lround(position[Y_AXIS]*factor);
  1468. //current_position[3]*=factor;
  1469. axis_steps_per_unit[Y_AXIS]= encoderpos;
  1470. encoderpos=activeline*lcdslow;
  1471. }
  1472. BLOCK;
  1473. beepshort();
  1474. }
  1475. if(linechanging)
  1476. {
  1477. if(encoderpos<5) encoderpos=5;
  1478. if(encoderpos>9999) encoderpos=9999;
  1479. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1480. }
  1481. }break;
  1482. case ItemCM_zsteps://axis_steps_per_unit[i] = code_value();
  1483. {
  1484. if(force_lcd_update)
  1485. {
  1486. lcd.setCursor(0,line);lcdprintPGM(" Z steps/mm:");
  1487. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[2]));
  1488. }
  1489. if((activeline!=line) )
  1490. break;
  1491. if(CLICKED)
  1492. {
  1493. linechanging=!linechanging;
  1494. if(linechanging)
  1495. {
  1496. encoderpos=(int)axis_steps_per_unit[2];
  1497. }
  1498. else
  1499. {
  1500. float factor=float(encoderpos)/float(axis_steps_per_unit[2]);
  1501. position[Z_AXIS]=lround(position[Z_AXIS]*factor);
  1502. //current_position[3]*=factor;
  1503. axis_steps_per_unit[Z_AXIS]= encoderpos;
  1504. encoderpos=activeline*lcdslow;
  1505. }
  1506. BLOCK;
  1507. beepshort();
  1508. }
  1509. if(linechanging)
  1510. {
  1511. if(encoderpos<5) encoderpos=5;
  1512. if(encoderpos>9999) encoderpos=9999;
  1513. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1514. }
  1515. }break;
  1516. case ItemCM_esteps://axis_steps_per_unit[i] = code_value();
  1517. {
  1518. if(force_lcd_update)
  1519. {
  1520. lcd.setCursor(0,line);lcdprintPGM(" E steps/mm:");
  1521. lcd.setCursor(13,line);lcd.print(itostr4(axis_steps_per_unit[3]));
  1522. }
  1523. if((activeline!=line) )
  1524. break;
  1525. if(CLICKED)
  1526. {
  1527. linechanging=!linechanging;
  1528. if(linechanging)
  1529. {
  1530. encoderpos=(int)axis_steps_per_unit[3];
  1531. }
  1532. else
  1533. {
  1534. float factor=float(encoderpos)/float(axis_steps_per_unit[3]);
  1535. position[E_AXIS]=lround(position[E_AXIS]*factor);
  1536. //current_position[3]*=factor;
  1537. axis_steps_per_unit[E_AXIS]= encoderpos;
  1538. encoderpos=activeline*lcdslow;
  1539. }
  1540. BLOCK;
  1541. beepshort();
  1542. }
  1543. if(linechanging)
  1544. {
  1545. if(encoderpos<5) encoderpos=5;
  1546. if(encoderpos>9999) encoderpos=9999;
  1547. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1548. }
  1549. }break;
  1550. default:
  1551. break;
  1552. }
  1553. line++;
  1554. }
  1555. updateActiveLines(ItemCM_esteps,encoderpos);
  1556. }
  1557. enum {
  1558. ItemC_exit,ItemC_temp,ItemC_move,
  1559. ItemC_store, ItemC_load,ItemC_failsafe
  1560. };
  1561. void MainMenu::showControl()
  1562. {
  1563. uint8_t line=0;
  1564. clearIfNecessary();
  1565. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1566. {
  1567. switch(i)
  1568. {
  1569. case ItemC_exit:
  1570. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  1571. break;
  1572. case ItemC_temp:
  1573. MENUITEM( lcdprintPGM(" Temperature \x7E") , BLOCK;status=Sub_TempControl;beepshort(); ) ;
  1574. break;
  1575. case ItemC_move:
  1576. MENUITEM( lcdprintPGM(" Motion \x7E") , BLOCK;status=Sub_MotionControl;beepshort(); ) ;
  1577. break;
  1578. case ItemC_store:
  1579. {
  1580. if(force_lcd_update)
  1581. {
  1582. lcd.setCursor(0,line);lcdprintPGM(" Store EPROM");
  1583. }
  1584. if((activeline==line) && CLICKED)
  1585. {
  1586. //enquecommand("M84");
  1587. beepshort();
  1588. BLOCK;
  1589. EEPROM_StoreSettings();
  1590. }
  1591. }break;
  1592. case ItemC_load:
  1593. {
  1594. if(force_lcd_update)
  1595. {
  1596. lcd.setCursor(0,line);lcdprintPGM(" Load EPROM");
  1597. }
  1598. if((activeline==line) && CLICKED)
  1599. {
  1600. //enquecommand("M84");
  1601. beepshort();
  1602. BLOCK;
  1603. EEPROM_RetrieveSettings();
  1604. }
  1605. }break;
  1606. case ItemC_failsafe:
  1607. {
  1608. if(force_lcd_update)
  1609. {
  1610. lcd.setCursor(0,line);lcdprintPGM(" Restore Failsafe");
  1611. }
  1612. if((activeline==line) && CLICKED)
  1613. {
  1614. //enquecommand("M84");
  1615. beepshort();
  1616. BLOCK;
  1617. EEPROM_RetrieveSettings(true);
  1618. }
  1619. }break;
  1620. default:
  1621. break;
  1622. }
  1623. line++;
  1624. }
  1625. updateActiveLines(ItemC_failsafe,encoderpos);
  1626. }
  1627. void MainMenu::showSD()
  1628. {
  1629. #ifdef SDSUPPORT
  1630. uint8_t line=0;
  1631. clearIfNecessary();
  1632. static uint8_t nrfiles=0;
  1633. if(force_lcd_update)
  1634. {
  1635. if(card.cardOK)
  1636. {
  1637. nrfiles=card.getnrfilenames();
  1638. }
  1639. else
  1640. {
  1641. nrfiles=0;
  1642. lineoffset=0;
  1643. }
  1644. }
  1645. bool enforceupdate=false;
  1646. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1647. {
  1648. switch(i)
  1649. {
  1650. case 0:
  1651. MENUITEM( lcdprintPGM(" Main \003") , BLOCK;status=Main_Menu;beepshort(); ) ;
  1652. break;
  1653. // case 1:
  1654. // {
  1655. // if(force_lcd_update)
  1656. // {
  1657. // lcd.setCursor(0,line);
  1658. // #ifdef CARDINSERTED
  1659. // if(CARDINSERTED)
  1660. // #else
  1661. // if(true)
  1662. // #endif
  1663. // {
  1664. // lcdprintPGM(" \004Refresh");
  1665. // }
  1666. // else
  1667. // {
  1668. // lcdprintPGM(" \004Insert Card");
  1669. // }
  1670. //
  1671. // }
  1672. // if((activeline==line) && CLICKED)
  1673. // {
  1674. // BLOCK;
  1675. // beepshort();
  1676. // card.initsd();
  1677. // force_lcd_update=true;
  1678. // nrfiles=card.getnrfilenames();
  1679. // }
  1680. // }break;
  1681. case 1:
  1682. 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(); ) ;
  1683. break;
  1684. default:
  1685. {
  1686. #define FIRSTITEM 2
  1687. if(i-FIRSTITEM<nrfiles)
  1688. {
  1689. if(force_lcd_update)
  1690. {
  1691. card.getfilename(i-FIRSTITEM);
  1692. //Serial.print("Filenr:");Serial.println(i-2);
  1693. lcd.setCursor(0,line);lcdprintPGM(" ");
  1694. if(card.filenameIsDir) lcd.print("\005");
  1695. lcd.print(card.filename);
  1696. }
  1697. if((activeline==line) && CLICKED)
  1698. {
  1699. BLOCK
  1700. card.getfilename(i-FIRSTITEM);
  1701. if(card.filenameIsDir)
  1702. {
  1703. for(int8_t i=0;i<strlen(card.filename);i++)
  1704. card.filename[i]=tolower(card.filename[i]);
  1705. card.chdir(card.filename);
  1706. lineoffset=0;
  1707. enforceupdate=true;
  1708. }
  1709. else
  1710. {
  1711. char cmd[30];
  1712. for(int8_t i=0;i<strlen(card.filename);i++)
  1713. card.filename[i]=tolower(card.filename[i]);
  1714. sprintf(cmd,"M23 %s",card.filename);
  1715. //sprintf(cmd,"M115");
  1716. enquecommand(cmd);
  1717. enquecommand("M24");
  1718. beep();
  1719. status=Main_Status;
  1720. lcd_status(card.filename);
  1721. }
  1722. }
  1723. }
  1724. }
  1725. break;
  1726. }
  1727. line++;
  1728. }
  1729. updateActiveLines(FIRSTITEM+nrfiles-1,encoderpos);
  1730. if(enforceupdate)
  1731. {
  1732. force_lcd_update=true;
  1733. enforceupdate=false;
  1734. }
  1735. #endif
  1736. }
  1737. enum {ItemM_watch, ItemM_prepare, ItemM_control, ItemM_file };
  1738. void MainMenu::showMainMenu()
  1739. {
  1740. #ifndef ULTIPANEL
  1741. force_lcd_update=false;
  1742. #endif
  1743. if(tune)
  1744. {
  1745. if(!(movesplanned() ||card.sdprinting))
  1746. {
  1747. force_lcd_update=true;
  1748. tune=false;
  1749. }
  1750. }
  1751. else
  1752. {
  1753. if(movesplanned() ||card.sdprinting)
  1754. {
  1755. force_lcd_update=true;
  1756. tune=true;
  1757. }
  1758. }
  1759. clearIfNecessary();
  1760. for(int8_t line=0;line<LCD_HEIGHT;line++)
  1761. {
  1762. switch(line)
  1763. {
  1764. case ItemM_watch:
  1765. MENUITEM( lcdprintPGM(" Watch \003") , BLOCK;status=Main_Status;beepshort(); ) ;
  1766. break;
  1767. case ItemM_prepare:
  1768. MENUITEM( if(!tune) lcdprintPGM(" Prepare \x7E");else lcdprintPGM(" Tune \x7E"); , BLOCK;status=Main_Prepare;beepshort(); ) ;
  1769. break;
  1770. case ItemM_control:
  1771. MENUITEM( lcdprintPGM(" Control \x7E") , BLOCK;status=Main_Control;beepshort(); ) ;
  1772. break;
  1773. #ifdef SDSUPPORT
  1774. case ItemM_file:
  1775. {
  1776. if(force_lcd_update)
  1777. {
  1778. lcd.setCursor(0,line);
  1779. #ifdef CARDINSERTED
  1780. if(CARDINSERTED)
  1781. #else
  1782. if(true)
  1783. #endif
  1784. {
  1785. if(card.sdprinting)
  1786. lcdprintPGM(" Stop Print \x7E");
  1787. else
  1788. lcdprintPGM(" Card Menu \x7E");
  1789. }
  1790. else
  1791. {
  1792. lcdprintPGM(" No Card");
  1793. }
  1794. }
  1795. #ifdef CARDINSERTED
  1796. if(CARDINSERTED)
  1797. #endif
  1798. if((activeline==line)&&CLICKED)
  1799. {
  1800. card.printingHasFinished();
  1801. BLOCK;
  1802. status=Main_SD;
  1803. beepshort();
  1804. }
  1805. }break;
  1806. #else
  1807. case ItemM_file:
  1808. break;
  1809. #endif
  1810. default:
  1811. SERIAL_ERROR_START;
  1812. SERIAL_ERRORLNPGM("Something is wrong in the MenuStructure.");
  1813. break;
  1814. }
  1815. }
  1816. updateActiveLines(3,encoderpos);
  1817. }
  1818. void MainMenu::update()
  1819. {
  1820. static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
  1821. static long timeoutToStatus=0;
  1822. static bool oldcardstatus=false;
  1823. #ifdef CARDINSERTED
  1824. if((CARDINSERTED != oldcardstatus))
  1825. {
  1826. force_lcd_update=true;
  1827. oldcardstatus=CARDINSERTED;
  1828. //Serial.println("echo: SD CHANGE");
  1829. if(CARDINSERTED)
  1830. {
  1831. card.initsd();
  1832. LCD_MESSAGEPGM("Card inserted");
  1833. }
  1834. else
  1835. {
  1836. card.release();
  1837. LCD_MESSAGEPGM("Card removed");
  1838. }
  1839. }
  1840. #endif
  1841. if(status!=oldstatus)
  1842. {
  1843. force_lcd_update=true;
  1844. encoderpos=0;
  1845. lineoffset=0;
  1846. oldstatus=status;
  1847. }
  1848. if( (encoderpos!=lastencoderpos) || CLICKED)
  1849. timeoutToStatus=millis()+STATUSTIMEOUT;
  1850. switch(status)
  1851. {
  1852. case Main_Status:
  1853. {
  1854. showStatus();
  1855. if(CLICKED)
  1856. {
  1857. linechanging=false;
  1858. BLOCK
  1859. status=Main_Menu;
  1860. timeoutToStatus=millis()+STATUSTIMEOUT;
  1861. }
  1862. }break;
  1863. case Main_Menu:
  1864. {
  1865. showMainMenu();
  1866. linechanging=false;
  1867. }break;
  1868. case Main_Prepare:
  1869. {
  1870. if(tune)
  1871. {
  1872. showTune();
  1873. }
  1874. else
  1875. {
  1876. showPrepare();
  1877. }
  1878. }break;
  1879. case Sub_PrepareMove:
  1880. {
  1881. showAxisMove();
  1882. }break;
  1883. case Main_Control:
  1884. {
  1885. showControl();
  1886. }break;
  1887. case Sub_MotionControl:
  1888. {
  1889. showControlMotion();
  1890. }break;
  1891. case Sub_TempControl:
  1892. {
  1893. showControlTemp();
  1894. }break;
  1895. case Main_SD:
  1896. {
  1897. showSD();
  1898. }break;
  1899. }
  1900. if(timeoutToStatus<millis())
  1901. status=Main_Status;
  1902. //force_lcd_update=false;
  1903. lastencoderpos=encoderpos;
  1904. }
  1905. // convert float to string with +123.4 format
  1906. char *ftostr3(const float &x)
  1907. {
  1908. //sprintf(conv,"%5.1f",x);
  1909. int xx=x;
  1910. conv[0]=(xx/100)%10+'0';
  1911. conv[1]=(xx/10)%10+'0';
  1912. conv[2]=(xx)%10+'0';
  1913. conv[3]=0;
  1914. return conv;
  1915. }
  1916. char *itostr2(const uint8_t &x)
  1917. {
  1918. //sprintf(conv,"%5.1f",x);
  1919. int xx=x;
  1920. conv[0]=(xx/10)%10+'0';
  1921. conv[1]=(xx)%10+'0';
  1922. conv[2]=0;
  1923. return conv;
  1924. }
  1925. // convert float to string with +123.4 format
  1926. char *ftostr31(const float &x)
  1927. {
  1928. int xx=x*10;
  1929. conv[0]=(xx>=0)?'+':'-';
  1930. xx=abs(xx);
  1931. conv[1]=(xx/1000)%10+'0';
  1932. conv[2]=(xx/100)%10+'0';
  1933. conv[3]=(xx/10)%10+'0';
  1934. conv[4]='.';
  1935. conv[5]=(xx)%10+'0';
  1936. conv[6]=0;
  1937. return conv;
  1938. }
  1939. char *ftostr32(const float &x)
  1940. {
  1941. int xx=x*100;
  1942. conv[0]=(xx>=0)?'+':'-';
  1943. xx=abs(xx);
  1944. conv[1]=(xx/100)%10+'0';
  1945. conv[2]='.';
  1946. conv[3]=(xx/10)%10+'0';
  1947. conv[4]=(xx)%10+'0';
  1948. conv[6]=0;
  1949. return conv;
  1950. }
  1951. char *itostr31(const int &xx)
  1952. {
  1953. conv[0]=(xx>=0)?'+':'-';
  1954. conv[1]=(xx/1000)%10+'0';
  1955. conv[2]=(xx/100)%10+'0';
  1956. conv[3]=(xx/10)%10+'0';
  1957. conv[4]='.';
  1958. conv[5]=(xx)%10+'0';
  1959. conv[6]=0;
  1960. return conv;
  1961. }
  1962. char *itostr3(const int &xx)
  1963. {
  1964. conv[0]=(xx/100)%10+'0';
  1965. conv[1]=(xx/10)%10+'0';
  1966. conv[2]=(xx)%10+'0';
  1967. conv[3]=0;
  1968. return conv;
  1969. }
  1970. char *itostr4(const int &xx)
  1971. {
  1972. conv[0]=(xx/1000)%10+'0';
  1973. conv[1]=(xx/100)%10+'0';
  1974. conv[2]=(xx/10)%10+'0';
  1975. conv[3]=(xx)%10+'0';
  1976. conv[4]=0;
  1977. return conv;
  1978. }
  1979. // convert float to string with +1234.5 format
  1980. char *ftostr51(const float &x)
  1981. {
  1982. int xx=x*10;
  1983. conv[0]=(xx>=0)?'+':'-';
  1984. xx=abs(xx);
  1985. conv[1]=(xx/10000)%10+'0';
  1986. conv[2]=(xx/1000)%10+'0';
  1987. conv[3]=(xx/100)%10+'0';
  1988. conv[4]=(xx/10)%10+'0';
  1989. conv[5]='.';
  1990. conv[6]=(xx)%10+'0';
  1991. conv[7]=0;
  1992. return conv;
  1993. }
  1994. #endif //ULTRA_LCD