ultralcd.ino 63 KB

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