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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698
  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, ItemAM_ERetract
  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_Prepare;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 F70 E1");beepshort(); ) ;
  654. break;
  655. case ItemAM_ERetract:
  656. // ErikDB: TODO: this length should be changed for volumetric.
  657. MENUITEM( lcdprintPGM(MSG_RETRACT) , BLOCK;enquecommand("G92 E0");enquecommand("G1 F700 E-1");beepshort(); ) ;
  658. break;
  659. default:
  660. break;
  661. }
  662. line++;
  663. }
  664. updateActiveLines(ItemAM_ERetract,encoderpos);
  665. }
  666. enum {ItemT_exit,ItemT_speed,ItemT_flow,ItemT_nozzle,
  667. #if (HEATER_BED_PIN > -1)
  668. ItemT_bed,
  669. #endif
  670. ItemT_fan};
  671. void MainMenu::showTune()
  672. {
  673. uint8_t line=0;
  674. clearIfNecessary();
  675. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  676. {
  677. //Serial.println((int)(line-lineoffset));
  678. switch(i)
  679. {
  680. case ItemT_exit:
  681. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  682. break;
  683. case ItemT_speed:
  684. {
  685. if(force_lcd_update)
  686. {
  687. lcd.setCursor(0,line);lcdprintPGM(MSG_SPEED);
  688. lcd.setCursor(13,line);lcd.print(ftostr3(feedmultiply));
  689. }
  690. if((activeline!=line) )
  691. break;
  692. if(CLICKED) //AnalogWrite(FAN_PIN, fanpwm);
  693. {
  694. linechanging=!linechanging;
  695. if(linechanging)
  696. {
  697. encoderpos=feedmultiply;
  698. }
  699. else
  700. {
  701. encoderpos=activeline*lcdslow;
  702. beepshort();
  703. }
  704. BLOCK;
  705. }
  706. if(linechanging)
  707. {
  708. if(encoderpos<1) encoderpos=1;
  709. if(encoderpos>400) encoderpos=400;
  710. feedmultiply = encoderpos;
  711. feedmultiplychanged=true;
  712. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  713. }
  714. }break;
  715. case ItemT_nozzle:
  716. {
  717. if(force_lcd_update)
  718. {
  719. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE);
  720. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  721. }
  722. if((activeline!=line) )
  723. break;
  724. if(CLICKED)
  725. {
  726. linechanging=!linechanging;
  727. if(linechanging)
  728. {
  729. encoderpos=intround(degTargetHotend0());
  730. }
  731. else
  732. {
  733. setTargetHotend0(encoderpos);
  734. encoderpos=activeline*lcdslow;
  735. beepshort();
  736. }
  737. BLOCK;
  738. }
  739. if(linechanging)
  740. {
  741. if(encoderpos<0) encoderpos=0;
  742. if(encoderpos>260) encoderpos=260;
  743. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  744. }
  745. }break;
  746. #if (HEATER_BED_PIN > -1)
  747. case ItemT_bed:
  748. {
  749. if(force_lcd_update)
  750. {
  751. lcd.setCursor(0,line);lcdprintPGM(MSG_BED);
  752. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  753. }
  754. if((activeline!=line) )
  755. break;
  756. if(CLICKED)
  757. {
  758. linechanging=!linechanging;
  759. if(linechanging)
  760. {
  761. encoderpos=intround(degTargetBed());
  762. }
  763. else
  764. {
  765. setTargetBed(encoderpos);
  766. encoderpos=activeline*lcdslow;
  767. beepshort();
  768. }
  769. BLOCK;
  770. }
  771. if(linechanging)
  772. {
  773. if(encoderpos<0) encoderpos=0;
  774. if(encoderpos>260) encoderpos=260;
  775. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  776. }
  777. }break;
  778. #endif
  779. case ItemT_fan:
  780. {
  781. if(force_lcd_update)
  782. {
  783. lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
  784. lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
  785. }
  786. if((activeline!=line) )
  787. break;
  788. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  789. {
  790. linechanging=!linechanging;
  791. if(linechanging)
  792. {
  793. encoderpos=FanSpeed;
  794. }
  795. else
  796. {
  797. encoderpos=activeline*lcdslow;
  798. beepshort();
  799. }
  800. BLOCK;
  801. }
  802. if(linechanging)
  803. {
  804. if(encoderpos<0) encoderpos=0;
  805. if(encoderpos>255) encoderpos=255;
  806. FanSpeed=encoderpos;
  807. analogWrite(FAN_PIN, FanSpeed);
  808. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  809. }
  810. }break;
  811. case ItemT_flow://axis_steps_per_unit[i] = code_value();
  812. {
  813. if(force_lcd_update)
  814. {
  815. lcd.setCursor(0,line);lcdprintPGM(MSG_FLOW);
  816. lcd.setCursor(13,line);lcd.print(ftostr52(axis_steps_per_unit[E_AXIS]));
  817. }
  818. if((activeline!=line) )
  819. break;
  820. if(CLICKED)
  821. {
  822. linechanging=!linechanging;
  823. if(linechanging)
  824. {
  825. encoderpos=(long)(axis_steps_per_unit[E_AXIS]*100.0);
  826. }
  827. else
  828. {
  829. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[E_AXIS]);
  830. position[E_AXIS]=lround(position[E_AXIS]*factor);
  831. //current_position[E_AXIS]*=factor;
  832. axis_steps_per_unit[E_AXIS]= encoderpos/100.0;
  833. encoderpos=activeline*lcdslow;
  834. }
  835. BLOCK;
  836. beepshort();
  837. }
  838. if(linechanging)
  839. {
  840. if(encoderpos<5) encoderpos=5;
  841. if(encoderpos>999999) encoderpos=999999;
  842. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.0));
  843. }
  844. }break;
  845. default:
  846. break;
  847. }
  848. line++;
  849. }
  850. updateActiveLines(ItemT_fan,encoderpos);
  851. }
  852. //does not work
  853. // #define MENUCHANGEITEM(repaint_action, enter_action, accept_action, change_action) \
  854. // {\
  855. // if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \
  856. // if(activeline==line) \
  857. // { \
  858. // if(CLICKED) \
  859. // { \
  860. // linechanging=!linechanging; \
  861. // if(linechanging) {enter_action;} \
  862. // else {accept_action;} \
  863. // } \
  864. // else \
  865. // if(linechanging) {change_action};}\
  866. // }
  867. //
  868. enum {
  869. ItemCT_exit,ItemCT_nozzle0,
  870. #ifdef AUTOTEMP
  871. ItemCT_autotempactive,
  872. ItemCT_autotempmin,ItemCT_autotempmax,ItemCT_autotempfact,
  873. #endif
  874. #if EXTRUDERS > 1
  875. ItemCT_nozzle1,
  876. #endif
  877. #if EXTRUDERS > 2
  878. ItemCT_nozzle2,
  879. #endif
  880. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  881. ItemCT_bed,
  882. #endif
  883. ItemCT_fan,
  884. ItemCT_PID_P,ItemCT_PID_I,ItemCT_PID_D,ItemCT_PID_C
  885. };
  886. void MainMenu::showControlTemp()
  887. {
  888. uint8_t line=0;
  889. clearIfNecessary();
  890. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  891. {
  892. switch(i)
  893. {
  894. case ItemCT_exit:
  895. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  896. break;
  897. case ItemCT_nozzle0:
  898. {
  899. if(force_lcd_update)
  900. {
  901. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE);
  902. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend0())));
  903. }
  904. if((activeline!=line) )
  905. break;
  906. if(CLICKED)
  907. {
  908. linechanging=!linechanging;
  909. if(linechanging)
  910. {
  911. encoderpos=intround(degTargetHotend0());
  912. }
  913. else
  914. {
  915. setTargetHotend0(encoderpos);
  916. encoderpos=activeline*lcdslow;
  917. beepshort();
  918. }
  919. BLOCK;
  920. }
  921. if(linechanging)
  922. {
  923. if(encoderpos<0) encoderpos=0;
  924. if(encoderpos>260) encoderpos=260;
  925. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  926. }
  927. }break;
  928. #if EXTRUDERS > 1
  929. case ItemCT_nozzle1:
  930. {
  931. if(force_lcd_update)
  932. {
  933. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE1);
  934. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend1())));
  935. }
  936. if((activeline!=line) )
  937. break;
  938. if(CLICKED)
  939. {
  940. linechanging=!linechanging;
  941. if(linechanging)
  942. {
  943. encoderpos=intround(degTargetHotend1());
  944. }
  945. else
  946. {
  947. setTargetHotend1(encoderpos);
  948. encoderpos=activeline*lcdslow;
  949. beepshort();
  950. }
  951. BLOCK;
  952. }
  953. if(linechanging)
  954. {
  955. if(encoderpos<0) encoderpos=0;
  956. if(encoderpos>260) encoderpos=260;
  957. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  958. }
  959. }break;
  960. #endif
  961. #if EXTRUDERS > 2
  962. case ItemCT_nozzle2:
  963. {
  964. if(force_lcd_update)
  965. {
  966. lcd.setCursor(0,line);lcdprintPGM(MSG_NOZZLE2);
  967. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetHotend2())));
  968. }
  969. if((activeline!=line) )
  970. break;
  971. if(CLICKED)
  972. {
  973. linechanging=!linechanging;
  974. if(linechanging)
  975. {
  976. encoderpos=intround(degTargetHotend2());
  977. }
  978. else
  979. {
  980. setTargetHotend1(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. #ifdef AUTOTEMP
  995. case ItemCT_autotempmin:
  996. {
  997. if(force_lcd_update)
  998. {
  999. lcd.setCursor(0,line);lcdprintPGM(MSG_MIN);
  1000. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_min));
  1001. }
  1002. if((activeline!=line) )
  1003. break;
  1004. if(CLICKED)
  1005. {
  1006. linechanging=!linechanging;
  1007. if(linechanging)
  1008. {
  1009. encoderpos=intround(autotemp_min);
  1010. }
  1011. else
  1012. {
  1013. autotemp_min=encoderpos;
  1014. encoderpos=activeline*lcdslow;
  1015. beepshort();
  1016. }
  1017. BLOCK;
  1018. }
  1019. if(linechanging)
  1020. {
  1021. if(encoderpos<0) encoderpos=0;
  1022. if(encoderpos>260) encoderpos=260;
  1023. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1024. }
  1025. }break;
  1026. case ItemCT_autotempmax:
  1027. {
  1028. if(force_lcd_update)
  1029. {
  1030. lcd.setCursor(0,line);lcdprintPGM(MSG_MAX);
  1031. lcd.setCursor(13,line);lcd.print(ftostr3(autotemp_max));
  1032. }
  1033. if((activeline!=line) )
  1034. break;
  1035. if(CLICKED)
  1036. {
  1037. linechanging=!linechanging;
  1038. if(linechanging)
  1039. {
  1040. encoderpos=intround(autotemp_max);
  1041. }
  1042. else
  1043. {
  1044. autotemp_max=encoderpos;
  1045. encoderpos=activeline*lcdslow;
  1046. beepshort();
  1047. }
  1048. BLOCK;
  1049. }
  1050. if(linechanging)
  1051. {
  1052. if(encoderpos<0) encoderpos=0;
  1053. if(encoderpos>260) encoderpos=260;
  1054. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1055. }
  1056. }break;
  1057. case ItemCT_autotempfact:
  1058. {
  1059. if(force_lcd_update)
  1060. {
  1061. lcd.setCursor(0,line);lcdprintPGM(MSG_FACTOR);
  1062. lcd.setCursor(13,line);lcd.print(ftostr32(autotemp_factor));
  1063. }
  1064. if((activeline!=line) )
  1065. break;
  1066. if(CLICKED)
  1067. {
  1068. linechanging=!linechanging;
  1069. if(linechanging)
  1070. {
  1071. encoderpos=intround(autotemp_factor*100);
  1072. }
  1073. else
  1074. {
  1075. autotemp_max=encoderpos;
  1076. encoderpos=activeline*lcdslow;
  1077. beepshort();
  1078. }
  1079. BLOCK;
  1080. }
  1081. if(linechanging)
  1082. {
  1083. if(encoderpos<0) encoderpos=0;
  1084. if(encoderpos>99) encoderpos=99;
  1085. lcd.setCursor(13,line);lcd.print(ftostr32(encoderpos/100.));
  1086. }
  1087. }break;
  1088. case ItemCT_autotempactive:
  1089. {
  1090. if(force_lcd_update)
  1091. {
  1092. lcd.setCursor(0,line);lcdprintPGM(MSG_AUTOTEMP);
  1093. lcd.setCursor(13,line);
  1094. if(autotemp_enabled)
  1095. lcdprintPGM(MSG_ON);
  1096. else
  1097. lcdprintPGM(MSG_OFF);
  1098. }
  1099. if((activeline!=line) )
  1100. break;
  1101. if(CLICKED)
  1102. {
  1103. autotemp_enabled=!autotemp_enabled;
  1104. lcd.setCursor(13,line);
  1105. if(autotemp_enabled)
  1106. lcdprintPGM(MSG_ON);
  1107. else
  1108. lcdprintPGM(MSG_OFF);
  1109. BLOCK;
  1110. }
  1111. }break;
  1112. #endif //autotemp
  1113. #if defined BED_USES_THERMISTOR || defined BED_USES_AD595
  1114. case ItemCT_bed:
  1115. {
  1116. if(force_lcd_update)
  1117. {
  1118. lcd.setCursor(0,line);lcdprintPGM(MSG_BED);
  1119. lcd.setCursor(13,line);lcd.print(ftostr3(intround(degTargetBed())));
  1120. }
  1121. if((activeline!=line) )
  1122. break;
  1123. if(CLICKED)
  1124. {
  1125. linechanging=!linechanging;
  1126. if(linechanging)
  1127. {
  1128. encoderpos=intround(degTargetBed());
  1129. }
  1130. else
  1131. {
  1132. setTargetBed(encoderpos);
  1133. encoderpos=activeline*lcdslow;
  1134. beepshort();
  1135. }
  1136. BLOCK;
  1137. }
  1138. if(linechanging)
  1139. {
  1140. if(encoderpos<0) encoderpos=0;
  1141. if(encoderpos>260) encoderpos=260;
  1142. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1143. }
  1144. }break;
  1145. #endif
  1146. case ItemCT_fan:
  1147. {
  1148. if(force_lcd_update)
  1149. {
  1150. lcd.setCursor(0,line);lcdprintPGM(MSG_FAN_SPEED);
  1151. lcd.setCursor(13,line);lcd.print(ftostr3(FanSpeed));
  1152. }
  1153. if((activeline!=line) )
  1154. break;
  1155. if(CLICKED) //nalogWrite(FAN_PIN, fanpwm);
  1156. {
  1157. linechanging=!linechanging;
  1158. if(linechanging)
  1159. {
  1160. encoderpos=FanSpeed;
  1161. }
  1162. else
  1163. {
  1164. encoderpos=activeline*lcdslow;
  1165. beepshort();
  1166. }
  1167. BLOCK;
  1168. }
  1169. if(linechanging)
  1170. {
  1171. if(encoderpos<0) encoderpos=0;
  1172. if(encoderpos>255) encoderpos=255;
  1173. FanSpeed=encoderpos;
  1174. analogWrite(FAN_PIN, FanSpeed);
  1175. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1176. }
  1177. }break;
  1178. #ifdef PIDTEMP
  1179. case ItemCT_PID_P:
  1180. {
  1181. if(force_lcd_update)
  1182. {
  1183. lcd.setCursor(0,line);lcdprintPGM(" PID-P: ");
  1184. lcd.setCursor(13,line);lcd.print(itostr4(Kp));
  1185. }
  1186. if((activeline!=line) )
  1187. break;
  1188. if(CLICKED)
  1189. {
  1190. linechanging=!linechanging;
  1191. if(linechanging)
  1192. {
  1193. encoderpos=(long)Kp;
  1194. }
  1195. else
  1196. {
  1197. Kp= encoderpos;
  1198. encoderpos=activeline*lcdslow;
  1199. }
  1200. BLOCK;
  1201. beepshort();
  1202. }
  1203. if(linechanging)
  1204. {
  1205. if(encoderpos<1) encoderpos=1;
  1206. if(encoderpos>9990) encoderpos=9990;
  1207. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1208. }
  1209. }break;
  1210. case ItemCT_PID_I:
  1211. {
  1212. if(force_lcd_update)
  1213. {
  1214. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_I);
  1215. lcd.setCursor(13,line);lcd.print(ftostr51(Ki/PID_dT));
  1216. }
  1217. if((activeline!=line) )
  1218. break;
  1219. if(CLICKED)
  1220. {
  1221. linechanging=!linechanging;
  1222. if(linechanging)
  1223. {
  1224. encoderpos=(long)(Ki*10/PID_dT);
  1225. }
  1226. else
  1227. {
  1228. Ki= encoderpos/10.*PID_dT;
  1229. encoderpos=activeline*lcdslow;
  1230. }
  1231. BLOCK;
  1232. beepshort();
  1233. }
  1234. if(linechanging)
  1235. {
  1236. if(encoderpos<0) encoderpos=0;
  1237. if(encoderpos>9990) encoderpos=9990;
  1238. lcd.setCursor(13,line);lcd.print(ftostr51(encoderpos/10.));
  1239. }
  1240. }break;
  1241. case ItemCT_PID_D:
  1242. {
  1243. if(force_lcd_update)
  1244. {
  1245. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_D);
  1246. lcd.setCursor(13,line);lcd.print(itostr4(Kd*PID_dT));
  1247. }
  1248. if((activeline!=line) )
  1249. break;
  1250. if(CLICKED)
  1251. {
  1252. linechanging=!linechanging;
  1253. if(linechanging)
  1254. {
  1255. encoderpos=(long)(Kd/5./PID_dT);
  1256. }
  1257. else
  1258. {
  1259. Kd= encoderpos;
  1260. encoderpos=activeline*lcdslow;
  1261. }
  1262. BLOCK;
  1263. beepshort();
  1264. }
  1265. if(linechanging)
  1266. {
  1267. if(encoderpos<0) encoderpos=0;
  1268. if(encoderpos>9990) encoderpos=9990;
  1269. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos));
  1270. }
  1271. }break;
  1272. case ItemCT_PID_C:
  1273. #ifdef PID_ADD_EXTRUSION_RATE
  1274. {
  1275. if(force_lcd_update)
  1276. {
  1277. lcd.setCursor(0,line);lcdprintPGM(MSG_PID_C);
  1278. lcd.setCursor(13,line);lcd.print(itostr3(Kc));
  1279. }
  1280. if((activeline!=line) )
  1281. break;
  1282. if(CLICKED)
  1283. {
  1284. linechanging=!linechanging;
  1285. if(linechanging)
  1286. {
  1287. encoderpos=(long)Kc;
  1288. }
  1289. else
  1290. {
  1291. Kc= encoderpos;
  1292. encoderpos=activeline*lcdslow;
  1293. }
  1294. BLOCK;
  1295. beepshort();
  1296. }
  1297. if(linechanging)
  1298. {
  1299. if(encoderpos<0) encoderpos=0;
  1300. if(encoderpos>990) encoderpos=990;
  1301. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1302. }
  1303. }
  1304. #endif
  1305. #endif
  1306. break;
  1307. default:
  1308. break;
  1309. }
  1310. line++;
  1311. }
  1312. #ifdef PID_ADD_EXTRUSION_RATE
  1313. updateActiveLines(ItemCT_PID_C,encoderpos);
  1314. #else
  1315. updateActiveLines(ItemCT_PID_D,encoderpos);
  1316. #endif
  1317. }
  1318. enum {
  1319. ItemCM_exit,
  1320. ItemCM_acc, ItemCM_xyjerk,
  1321. ItemCM_vmaxx, ItemCM_vmaxy, ItemCM_vmaxz, ItemCM_vmaxe,
  1322. ItemCM_vtravmin,ItemCM_vmin,
  1323. ItemCM_amaxx, ItemCM_amaxy, ItemCM_amaxz, ItemCM_amaxe,
  1324. ItemCM_aret, ItemCM_xsteps,ItemCM_ysteps, ItemCM_zsteps, ItemCM_esteps
  1325. };
  1326. void MainMenu::showControlMotion()
  1327. {
  1328. uint8_t line=0;
  1329. clearIfNecessary();
  1330. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1331. {
  1332. switch(i)
  1333. {
  1334. case ItemCM_exit:
  1335. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  1336. break;
  1337. case ItemCM_acc:
  1338. {
  1339. if(force_lcd_update)
  1340. {
  1341. lcd.setCursor(0,line);lcdprintPGM(MSG_ACC);
  1342. lcd.setCursor(13,line);lcd.print(itostr3(acceleration/100));lcdprintPGM("00");
  1343. }
  1344. if((activeline!=line) )
  1345. break;
  1346. if(CLICKED)
  1347. {
  1348. linechanging=!linechanging;
  1349. if(linechanging)
  1350. {
  1351. encoderpos=(long)acceleration/100;
  1352. }
  1353. else
  1354. {
  1355. acceleration= encoderpos*100;
  1356. encoderpos=activeline*lcdslow;
  1357. }
  1358. BLOCK;
  1359. beepshort();
  1360. }
  1361. if(linechanging)
  1362. {
  1363. if(encoderpos<5) encoderpos=5;
  1364. if(encoderpos>990) encoderpos=990;
  1365. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1366. }
  1367. }break;
  1368. case ItemCM_xyjerk: //max_xy_jerk
  1369. {
  1370. if(force_lcd_update)
  1371. {
  1372. lcd.setCursor(0,line);lcdprintPGM(MSG_VXY_JERK);
  1373. lcd.setCursor(13,line);lcd.print(itostr3(max_xy_jerk));
  1374. }
  1375. if((activeline!=line) )
  1376. break;
  1377. if(CLICKED)
  1378. {
  1379. linechanging=!linechanging;
  1380. if(linechanging)
  1381. {
  1382. encoderpos=(long)max_xy_jerk;
  1383. }
  1384. else
  1385. {
  1386. max_xy_jerk= encoderpos;
  1387. encoderpos=activeline*lcdslow;
  1388. }
  1389. BLOCK;
  1390. beepshort();
  1391. }
  1392. if(linechanging)
  1393. {
  1394. if(encoderpos<1) encoderpos=1;
  1395. if(encoderpos>990) encoderpos=990;
  1396. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1397. }
  1398. }break;
  1399. case ItemCM_vmaxx:
  1400. case ItemCM_vmaxy:
  1401. case ItemCM_vmaxz:
  1402. case ItemCM_vmaxe:
  1403. {
  1404. if(force_lcd_update)
  1405. {
  1406. lcd.setCursor(0,line);lcdprintPGM(MSG_VMAX);
  1407. if(i==ItemCM_vmaxx)lcdprintPGM(MSG_X);
  1408. if(i==ItemCM_vmaxy)lcdprintPGM(MSG_Y);
  1409. if(i==ItemCM_vmaxz)lcdprintPGM(MSG_Z);
  1410. if(i==ItemCM_vmaxe)lcdprintPGM(MSG_E);
  1411. lcd.setCursor(13,line);lcd.print(itostr3(max_feedrate[i-ItemCM_vmaxx]));
  1412. }
  1413. if((activeline!=line) )
  1414. break;
  1415. if(CLICKED)
  1416. {
  1417. linechanging=!linechanging;
  1418. if(linechanging)
  1419. {
  1420. encoderpos=(long)max_feedrate[i-ItemCM_vmaxx];
  1421. }
  1422. else
  1423. {
  1424. max_feedrate[i-ItemCM_vmaxx]= encoderpos;
  1425. encoderpos=activeline*lcdslow;
  1426. }
  1427. BLOCK;
  1428. beepshort();
  1429. }
  1430. if(linechanging)
  1431. {
  1432. if(encoderpos<1) encoderpos=1;
  1433. if(encoderpos>990) encoderpos=990;
  1434. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1435. }
  1436. }break;
  1437. case ItemCM_vmin:
  1438. {
  1439. if(force_lcd_update)
  1440. {
  1441. lcd.setCursor(0,line);lcdprintPGM(MSG_VMIN);
  1442. lcd.setCursor(13,line);lcd.print(itostr3(minimumfeedrate));
  1443. }
  1444. if((activeline!=line) )
  1445. break;
  1446. if(CLICKED)
  1447. {
  1448. linechanging=!linechanging;
  1449. if(linechanging)
  1450. {
  1451. encoderpos=(long)(minimumfeedrate);
  1452. }
  1453. else
  1454. {
  1455. minimumfeedrate= encoderpos;
  1456. encoderpos=activeline*lcdslow;
  1457. }
  1458. BLOCK;
  1459. beepshort();
  1460. }
  1461. if(linechanging)
  1462. {
  1463. if(encoderpos<0) encoderpos=0;
  1464. if(encoderpos>990) encoderpos=990;
  1465. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1466. }
  1467. }break;
  1468. case ItemCM_vtravmin:
  1469. {
  1470. if(force_lcd_update)
  1471. {
  1472. lcd.setCursor(0,line);lcdprintPGM(MSG_VTRAV_MIN);
  1473. lcd.setCursor(13,line);lcd.print(itostr3(mintravelfeedrate));
  1474. }
  1475. if((activeline!=line) )
  1476. break;
  1477. if(CLICKED)
  1478. {
  1479. linechanging=!linechanging;
  1480. if(linechanging)
  1481. {
  1482. encoderpos=(long)mintravelfeedrate;
  1483. }
  1484. else
  1485. {
  1486. mintravelfeedrate= encoderpos;
  1487. encoderpos=activeline*lcdslow;
  1488. }
  1489. BLOCK;
  1490. beepshort();
  1491. }
  1492. if(linechanging)
  1493. {
  1494. if(encoderpos<0) encoderpos=0;
  1495. if(encoderpos>990) encoderpos=990;
  1496. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));
  1497. }
  1498. }break;
  1499. case ItemCM_amaxx:
  1500. case ItemCM_amaxy:
  1501. case ItemCM_amaxz:
  1502. case ItemCM_amaxe:
  1503. {
  1504. if(force_lcd_update)
  1505. {
  1506. lcd.setCursor(0,line);lcdprintPGM(" Amax ");
  1507. if(i==ItemCM_amaxx)lcdprintPGM(MSG_X);
  1508. if(i==ItemCM_amaxy)lcdprintPGM(MSG_Y);
  1509. if(i==ItemCM_amaxz)lcdprintPGM(MSG_Z);
  1510. if(i==ItemCM_amaxe)lcdprintPGM(MSG_E);
  1511. lcd.setCursor(13,line);lcd.print(itostr3(max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100));lcdprintPGM("00");
  1512. }
  1513. if((activeline!=line) )
  1514. break;
  1515. if(CLICKED)
  1516. {
  1517. linechanging=!linechanging;
  1518. if(linechanging)
  1519. {
  1520. encoderpos=(long)max_acceleration_units_per_sq_second[i-ItemCM_amaxx]/100;
  1521. }
  1522. else
  1523. {
  1524. max_acceleration_units_per_sq_second[i-ItemCM_amaxx]= encoderpos*100;
  1525. encoderpos=activeline*lcdslow;
  1526. }
  1527. BLOCK;
  1528. beepshort();
  1529. }
  1530. if(linechanging)
  1531. {
  1532. if(encoderpos<1) encoderpos=1;
  1533. if(encoderpos>990) encoderpos=990;
  1534. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1535. }
  1536. }break;
  1537. case ItemCM_aret://float retract_acceleration = 7000;
  1538. {
  1539. if(force_lcd_update)
  1540. {
  1541. lcd.setCursor(0,line);lcdprintPGM(MSG_A_RETRACT);
  1542. lcd.setCursor(13,line);lcd.print(ftostr3(retract_acceleration/100));lcdprintPGM("00");
  1543. }
  1544. if((activeline!=line) )
  1545. break;
  1546. if(CLICKED)
  1547. {
  1548. linechanging=!linechanging;
  1549. if(linechanging)
  1550. {
  1551. encoderpos=(long)retract_acceleration/100;
  1552. }
  1553. else
  1554. {
  1555. retract_acceleration= encoderpos*100;
  1556. encoderpos=activeline*lcdslow;
  1557. }
  1558. BLOCK;
  1559. beepshort();
  1560. }
  1561. if(linechanging)
  1562. {
  1563. if(encoderpos<10) encoderpos=10;
  1564. if(encoderpos>990) encoderpos=990;
  1565. lcd.setCursor(13,line);lcd.print(itostr3(encoderpos));lcdprintPGM("00");
  1566. }
  1567. }break;
  1568. case ItemCM_xsteps://axis_steps_per_unit[i] = code_value();
  1569. {
  1570. if(force_lcd_update)
  1571. {
  1572. lcd.setCursor(0,line);lcdprintPGM(MSG_XSTEPS);
  1573. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[X_AXIS]));
  1574. }
  1575. if((activeline!=line) )
  1576. break;
  1577. if(CLICKED)
  1578. {
  1579. linechanging=!linechanging;
  1580. if(linechanging)
  1581. {
  1582. encoderpos=(long)(axis_steps_per_unit[X_AXIS]*100.0);
  1583. }
  1584. else
  1585. {
  1586. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[X_AXIS]);
  1587. position[X_AXIS]=lround(position[X_AXIS]*factor);
  1588. //current_position[X_AXIS]*=factor;
  1589. axis_steps_per_unit[X_AXIS]= encoderpos/100.0;
  1590. encoderpos=activeline*lcdslow;
  1591. }
  1592. BLOCK;
  1593. beepshort();
  1594. }
  1595. if(linechanging)
  1596. {
  1597. if(encoderpos<5) encoderpos=5;
  1598. if(encoderpos>999999) encoderpos=999999;
  1599. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1600. }
  1601. }break;
  1602. case ItemCM_ysteps://axis_steps_per_unit[i] = code_value();
  1603. {
  1604. if(force_lcd_update)
  1605. {
  1606. lcd.setCursor(0,line);lcdprintPGM(MSG_YSTEPS);
  1607. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[Y_AXIS]));
  1608. }
  1609. if((activeline!=line) )
  1610. break;
  1611. if(CLICKED)
  1612. {
  1613. linechanging=!linechanging;
  1614. if(linechanging)
  1615. {
  1616. encoderpos=(long)(axis_steps_per_unit[Y_AXIS]*100.0);
  1617. }
  1618. else
  1619. {
  1620. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[Y_AXIS]);
  1621. position[Y_AXIS]=lround(position[Y_AXIS]*factor);
  1622. //current_position[Y_AXIS]*=factor;
  1623. axis_steps_per_unit[Y_AXIS]= encoderpos/100.0;
  1624. encoderpos=activeline*lcdslow;
  1625. }
  1626. BLOCK;
  1627. beepshort();
  1628. }
  1629. if(linechanging)
  1630. {
  1631. if(encoderpos<5) encoderpos=5;
  1632. if(encoderpos>999999) encoderpos=999999;
  1633. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1634. }
  1635. }break;
  1636. case ItemCM_zsteps://axis_steps_per_unit[i] = code_value();
  1637. {
  1638. if(force_lcd_update)
  1639. {
  1640. lcd.setCursor(0,line);lcdprintPGM(MSG_ZSTEPS);
  1641. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[Z_AXIS]));
  1642. }
  1643. if((activeline!=line) )
  1644. break;
  1645. if(CLICKED)
  1646. {
  1647. linechanging=!linechanging;
  1648. if(linechanging)
  1649. {
  1650. encoderpos=(long)(axis_steps_per_unit[Z_AXIS]*100.0);
  1651. }
  1652. else
  1653. {
  1654. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[Z_AXIS]);
  1655. position[Z_AXIS]=lround(position[Z_AXIS]*factor);
  1656. //current_position[Z_AXIS]*=factor;
  1657. axis_steps_per_unit[Z_AXIS]= encoderpos/100.0;
  1658. encoderpos=activeline*lcdslow;
  1659. }
  1660. BLOCK;
  1661. beepshort();
  1662. }
  1663. if(linechanging)
  1664. {
  1665. if(encoderpos<5) encoderpos=5;
  1666. if(encoderpos>999999) encoderpos=999999;
  1667. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1668. }
  1669. }break;
  1670. case ItemCM_esteps://axis_steps_per_unit[i] = code_value();
  1671. {
  1672. if(force_lcd_update)
  1673. {
  1674. lcd.setCursor(0,line);lcdprintPGM(MSG_ESTEPS);
  1675. lcd.setCursor(11,line);lcd.print(ftostr52(axis_steps_per_unit[E_AXIS]));
  1676. }
  1677. if((activeline!=line) )
  1678. break;
  1679. if(CLICKED)
  1680. {
  1681. linechanging=!linechanging;
  1682. if(linechanging)
  1683. {
  1684. encoderpos=(long)(axis_steps_per_unit[E_AXIS]*100.0);
  1685. }
  1686. else
  1687. {
  1688. float factor=float(encoderpos)/100.0/float(axis_steps_per_unit[E_AXIS]);
  1689. position[E_AXIS]=lround(position[E_AXIS]*factor);
  1690. //current_position[E_AXIS]*=factor;
  1691. axis_steps_per_unit[E_AXIS]= encoderpos/100.0;
  1692. encoderpos=activeline*lcdslow;
  1693. }
  1694. BLOCK;
  1695. beepshort();
  1696. }
  1697. if(linechanging)
  1698. {
  1699. if(encoderpos<5) encoderpos=5;
  1700. if(encoderpos>999999) encoderpos=999999;
  1701. lcd.setCursor(11,line);lcd.print(ftostr52(encoderpos/100.0));
  1702. }
  1703. }break;
  1704. default:
  1705. break;
  1706. }
  1707. line++;
  1708. }
  1709. updateActiveLines(ItemCM_esteps,encoderpos);
  1710. }
  1711. enum {
  1712. ItemR_exit,
  1713. ItemR_autoretract,
  1714. ItemR_retract_length,ItemR_retract_feedrate,ItemR_retract_zlift,
  1715. ItemR_unretract_length,ItemR_unretract_feedrate,
  1716. };
  1717. void MainMenu::showControlRetract()
  1718. {
  1719. #ifdef FWRETRACT
  1720. uint8_t line=0;
  1721. clearIfNecessary();
  1722. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1723. {
  1724. switch(i)
  1725. {
  1726. case ItemR_exit:
  1727. MENUITEM( lcdprintPGM(MSG_CONTROL) , BLOCK;status=Main_Control;beepshort(); ) ;
  1728. break;
  1729. //float retract_length=2, retract_feedrate=1200, retract_zlift=0.4;
  1730. //float retract_recover_length=0, retract_recover_feedrate=500;
  1731. case ItemR_autoretract:
  1732. {
  1733. if(force_lcd_update)
  1734. {
  1735. lcd.setCursor(0,line);lcdprintPGM(MSG_AUTORETRACT);
  1736. lcd.setCursor(13,line);
  1737. if(autoretract_enabled)
  1738. lcdprintPGM(MSG_ON);
  1739. else
  1740. lcdprintPGM(MSG_OFF);
  1741. }
  1742. if((activeline!=line) )
  1743. break;
  1744. if(CLICKED)
  1745. {
  1746. autoretract_enabled=!autoretract_enabled;
  1747. lcd.setCursor(13,line);
  1748. if(autoretract_enabled)
  1749. lcdprintPGM(MSG_ON);
  1750. else
  1751. lcdprintPGM(MSG_OFF);
  1752. BLOCK;
  1753. }
  1754. }break;
  1755. case ItemR_retract_length:
  1756. {
  1757. if(force_lcd_update)
  1758. {
  1759. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT);
  1760. lcd.setCursor(13,line);lcd.print(ftostr52(retract_length));
  1761. }
  1762. if((activeline!=line) )
  1763. break;
  1764. if(CLICKED)
  1765. {
  1766. linechanging=!linechanging;
  1767. if(linechanging)
  1768. {
  1769. encoderpos=(long)(retract_length*100);
  1770. }
  1771. else
  1772. {
  1773. retract_length= encoderpos/100.;
  1774. encoderpos=activeline*lcdslow;
  1775. }
  1776. BLOCK;
  1777. beepshort();
  1778. }
  1779. if(linechanging)
  1780. {
  1781. if(encoderpos<1) encoderpos=1;
  1782. if(encoderpos>990) encoderpos=990;
  1783. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.));
  1784. }
  1785. }break;
  1786. case ItemR_retract_feedrate:
  1787. {
  1788. if(force_lcd_update)
  1789. {
  1790. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACTF);
  1791. lcd.setCursor(13,line);lcd.print(itostr4(retract_feedrate));
  1792. }
  1793. if((activeline!=line) )
  1794. break;
  1795. if(CLICKED)
  1796. {
  1797. linechanging=!linechanging;
  1798. if(linechanging)
  1799. {
  1800. encoderpos=(long)(retract_feedrate/5);
  1801. }
  1802. else
  1803. {
  1804. retract_feedrate= encoderpos*5.;
  1805. encoderpos=activeline*lcdslow;
  1806. }
  1807. BLOCK;
  1808. beepshort();
  1809. }
  1810. if(linechanging)
  1811. {
  1812. if(encoderpos<1) encoderpos=1;
  1813. if(encoderpos>990) encoderpos=990;
  1814. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
  1815. }
  1816. }break;
  1817. case ItemR_retract_zlift://float retract_acceleration = 7000;
  1818. {
  1819. if(force_lcd_update)
  1820. {
  1821. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_ZLIFT);
  1822. lcd.setCursor(13,line);lcd.print(ftostr52(retract_zlift));;
  1823. }
  1824. if((activeline!=line) )
  1825. break;
  1826. if(CLICKED)
  1827. {
  1828. linechanging=!linechanging;
  1829. if(linechanging)
  1830. {
  1831. encoderpos=(long)(retract_zlift*10);
  1832. }
  1833. else
  1834. {
  1835. retract_zlift= encoderpos/10.;
  1836. encoderpos=activeline*lcdslow;
  1837. }
  1838. BLOCK;
  1839. beepshort();
  1840. }
  1841. if(linechanging)
  1842. {
  1843. if(encoderpos<0) encoderpos=0;
  1844. if(encoderpos>990) encoderpos=990;
  1845. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/10.));
  1846. }
  1847. }break;
  1848. case ItemR_unretract_length:
  1849. {
  1850. if(force_lcd_update)
  1851. {
  1852. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_RECOVER);
  1853. lcd.setCursor(13,line);lcd.print(ftostr52(retract_recover_length));;
  1854. }
  1855. if((activeline!=line) )
  1856. break;
  1857. if(CLICKED)
  1858. {
  1859. linechanging=!linechanging;
  1860. if(linechanging)
  1861. {
  1862. encoderpos=(long)(retract_recover_length*100);
  1863. }
  1864. else
  1865. {
  1866. retract_recover_length= encoderpos/100.;
  1867. encoderpos=activeline*lcdslow;
  1868. }
  1869. BLOCK;
  1870. beepshort();
  1871. }
  1872. if(linechanging)
  1873. {
  1874. if(encoderpos<0) encoderpos=0;
  1875. if(encoderpos>990) encoderpos=990;
  1876. lcd.setCursor(13,line);lcd.print(ftostr52(encoderpos/100.));
  1877. }
  1878. }break;
  1879. case ItemR_unretract_feedrate:
  1880. {
  1881. if(force_lcd_update)
  1882. {
  1883. lcd.setCursor(0,line);lcdprintPGM(MSG_CONTROL_RETRACT_RECOVERF);
  1884. lcd.setCursor(13,line);lcd.print(itostr4(retract_recover_feedrate));
  1885. }
  1886. if((activeline!=line) )
  1887. break;
  1888. if(CLICKED)
  1889. {
  1890. linechanging=!linechanging;
  1891. if(linechanging)
  1892. {
  1893. encoderpos=(long)retract_recover_feedrate/5;
  1894. }
  1895. else
  1896. {
  1897. retract_recover_feedrate= encoderpos*5.;
  1898. encoderpos=activeline*lcdslow;
  1899. }
  1900. BLOCK;
  1901. beepshort();
  1902. }
  1903. if(linechanging)
  1904. {
  1905. if(encoderpos<1) encoderpos=1;
  1906. if(encoderpos>990) encoderpos=990;
  1907. lcd.setCursor(13,line);lcd.print(itostr4(encoderpos*5));
  1908. }
  1909. }break;
  1910. default:
  1911. break;
  1912. }
  1913. line++;
  1914. }
  1915. updateActiveLines(ItemR_unretract_feedrate,encoderpos);
  1916. #endif
  1917. }
  1918. enum {
  1919. ItemC_exit,ItemC_temp,ItemC_move,
  1920. #ifdef FWRETRACT
  1921. ItemC_rectract,
  1922. #endif
  1923. ItemC_store, ItemC_load,ItemC_failsafe
  1924. };
  1925. void MainMenu::showControl()
  1926. {
  1927. uint8_t line=0;
  1928. clearIfNecessary();
  1929. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  1930. {
  1931. switch(i)
  1932. {
  1933. case ItemC_exit:
  1934. MENUITEM( lcdprintPGM(MSG_MAIN_WIDE) , BLOCK;status=Main_Menu;beepshort(); ) ;
  1935. break;
  1936. case ItemC_temp:
  1937. MENUITEM( lcdprintPGM(MSG_TEMPERATURE_WIDE) , BLOCK;status=Sub_TempControl;beepshort(); ) ;
  1938. break;
  1939. case ItemC_move:
  1940. MENUITEM( lcdprintPGM(MSG_MOTION_WIDE) , BLOCK;status=Sub_MotionControl;beepshort(); ) ;
  1941. break;
  1942. #ifdef FWRETRACT
  1943. case ItemC_rectract:
  1944. MENUITEM( lcdprintPGM(MSG_RECTRACT_WIDE) , BLOCK;status=Sub_RetractControl;beepshort(); ) ;
  1945. break;
  1946. #endif
  1947. case ItemC_store:
  1948. {
  1949. if(force_lcd_update)
  1950. {
  1951. lcd.setCursor(0,line);lcdprintPGM(MSG_STORE_EPROM);
  1952. }
  1953. if((activeline==line) && CLICKED)
  1954. {
  1955. //enquecommand("M84");
  1956. beepshort();
  1957. BLOCK;
  1958. EEPROM_StoreSettings();
  1959. }
  1960. }break;
  1961. case ItemC_load:
  1962. {
  1963. if(force_lcd_update)
  1964. {
  1965. lcd.setCursor(0,line);lcdprintPGM(MSG_LOAD_EPROM);
  1966. }
  1967. if((activeline==line) && CLICKED)
  1968. {
  1969. //enquecommand("M84");
  1970. beepshort();
  1971. BLOCK;
  1972. EEPROM_RetrieveSettings();
  1973. }
  1974. }break;
  1975. case ItemC_failsafe:
  1976. {
  1977. if(force_lcd_update)
  1978. {
  1979. lcd.setCursor(0,line);lcdprintPGM(MSG_RESTORE_FAILSAFE);
  1980. }
  1981. if((activeline==line) && CLICKED)
  1982. {
  1983. //enquecommand("M84");
  1984. beepshort();
  1985. BLOCK;
  1986. EEPROM_RetrieveSettings(true);
  1987. }
  1988. }break;
  1989. default:
  1990. break;
  1991. }
  1992. line++;
  1993. }
  1994. updateActiveLines(ItemC_failsafe,encoderpos);
  1995. }
  1996. void MainMenu::showSD()
  1997. {
  1998. #ifdef SDSUPPORT
  1999. uint8_t line=0;
  2000. clearIfNecessary();
  2001. static uint8_t nrfiles=0;
  2002. if(force_lcd_update)
  2003. {
  2004. if(card.cardOK)
  2005. {
  2006. nrfiles=card.getnrfilenames();
  2007. }
  2008. else
  2009. {
  2010. nrfiles=0;
  2011. lineoffset=0;
  2012. }
  2013. }
  2014. bool enforceupdate=false;
  2015. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  2016. {
  2017. switch(i)
  2018. {
  2019. case 0:
  2020. MENUITEM( lcdprintPGM(MSG_MAIN) , BLOCK;status=Main_Menu;beepshort(); ) ;
  2021. break;
  2022. // case 1:
  2023. // {
  2024. // if(force_lcd_update)
  2025. // {
  2026. // lcd.setCursor(0,line);
  2027. // #ifdef CARDINSERTED
  2028. // if(CARDINSERTED)
  2029. // #else
  2030. // if(true)
  2031. // #endif
  2032. // {
  2033. // lcdprintPGM(" \004Refresh");
  2034. // }
  2035. // else
  2036. // {
  2037. // lcdprintPGM(" \004Insert Card");
  2038. // }
  2039. //
  2040. // }
  2041. // if((activeline==line) && CLICKED)
  2042. // {
  2043. // BLOCK;
  2044. // beepshort();
  2045. // card.initsd();
  2046. // force_lcd_update=true;
  2047. // nrfiles=card.getnrfilenames();
  2048. // }
  2049. // }break;
  2050. case 1:
  2051. MENUITEM( lcd.print(" ");card.getWorkDirName();
  2052. if(card.filename[0]=='/') lcdprintPGM(MSG_REFRESH);
  2053. else {
  2054. lcd.print("\005");
  2055. lcd.print(card.filename);
  2056. lcd.print("/..");
  2057. } ,
  2058. BLOCK;
  2059. if(SDCARDDETECT == -1) card.initsd();
  2060. card.updir();
  2061. enforceupdate=true;
  2062. lineoffset=0;
  2063. beepshort(); ) ;
  2064. break;
  2065. default:
  2066. {
  2067. #define FIRSTITEM 2
  2068. if(i-FIRSTITEM<nrfiles)
  2069. {
  2070. if(force_lcd_update)
  2071. {
  2072. card.getfilename(i-FIRSTITEM);
  2073. //Serial.print("Filenr:");Serial.println(i-2);
  2074. lcd.setCursor(0,line);lcdprintPGM(" ");
  2075. if(card.filenameIsDir) lcd.print("\005");
  2076. lcd.print(card.filename);
  2077. }
  2078. if((activeline==line) && CLICKED)
  2079. {
  2080. BLOCK
  2081. card.getfilename(i-FIRSTITEM);
  2082. if(card.filenameIsDir)
  2083. {
  2084. for(int8_t i=0;i<strlen(card.filename);i++)
  2085. card.filename[i]=tolower(card.filename[i]);
  2086. card.chdir(card.filename);
  2087. lineoffset=0;
  2088. enforceupdate=true;
  2089. }
  2090. else
  2091. {
  2092. char cmd[30];
  2093. for(int8_t i=0;i<strlen(card.filename);i++)
  2094. card.filename[i]=tolower(card.filename[i]);
  2095. sprintf(cmd,"M23 %s",card.filename);
  2096. //sprintf(cmd,"M115");
  2097. enquecommand(cmd);
  2098. enquecommand("M24");
  2099. beep();
  2100. status=Main_Status;
  2101. lcd_status(card.filename);
  2102. }
  2103. }
  2104. }
  2105. }
  2106. break;
  2107. }
  2108. line++;
  2109. }
  2110. updateActiveLines(FIRSTITEM+nrfiles-1,encoderpos);
  2111. if(enforceupdate)
  2112. {
  2113. force_lcd_update=true;
  2114. enforceupdate=false;
  2115. }
  2116. #endif
  2117. }
  2118. enum {ItemM_watch, ItemM_prepare, ItemM_control, ItemM_file, ItemM_pause};
  2119. void MainMenu::showMainMenu()
  2120. {
  2121. #ifndef ULTIPANEL
  2122. force_lcd_update=false;
  2123. #endif
  2124. if(tune)
  2125. {
  2126. if(!(movesplanned() || IS_SD_PRINTING))
  2127. {
  2128. force_lcd_update=true;
  2129. tune=false;
  2130. }
  2131. }
  2132. else
  2133. {
  2134. if(movesplanned() || IS_SD_PRINTING)
  2135. {
  2136. force_lcd_update=true;
  2137. tune=true;
  2138. }
  2139. }
  2140. clearIfNecessary();
  2141. uint8_t line=0;
  2142. for(int8_t i=lineoffset;i<lineoffset+LCD_HEIGHT;i++)
  2143. {
  2144. switch(i)
  2145. {
  2146. case ItemM_watch:
  2147. MENUITEM( lcdprintPGM(MSG_WATCH) , BLOCK;status=Main_Status;beepshort(); ) ;
  2148. break;
  2149. case ItemM_prepare:
  2150. MENUITEM( if(!tune) lcdprintPGM(MSG_PREPARE);else lcdprintPGM(MSG_TUNE); , BLOCK;status=Main_Prepare;beepshort(); ) ;
  2151. break;
  2152. case ItemM_control:
  2153. MENUITEM( lcdprintPGM(MSG_CONTROL_ARROW) , BLOCK;status=Main_Control;beepshort(); ) ;
  2154. break;
  2155. #ifdef SDSUPPORT
  2156. case ItemM_file:
  2157. {
  2158. if(force_lcd_update)
  2159. {
  2160. lcd.setCursor(0,line);
  2161. #ifdef CARDINSERTED
  2162. if(CARDINSERTED)
  2163. #else
  2164. if(true)
  2165. #endif
  2166. {
  2167. if(card.sdprinting)
  2168. lcdprintPGM(MSG_STOP_PRINT);
  2169. else
  2170. lcdprintPGM(MSG_CARD_MENU);
  2171. }
  2172. else
  2173. {
  2174. lcdprintPGM(MSG_NO_CARD);
  2175. }
  2176. }
  2177. #ifdef CARDINSERTED
  2178. if(CARDINSERTED)
  2179. #endif
  2180. if((activeline==line)&&CLICKED)
  2181. {
  2182. card.printingHasFinished();
  2183. BLOCK;
  2184. status=Main_SD;
  2185. beepshort();
  2186. }
  2187. }break;
  2188. case ItemM_pause:
  2189. {
  2190. if(force_lcd_update)
  2191. {
  2192. lcd.setCursor(0,line);
  2193. #ifdef CARDINSERTED
  2194. if(CARDINSERTED)
  2195. #else
  2196. if(true)
  2197. #endif
  2198. {
  2199. if(card.sdprinting)
  2200. lcdprintPGM(MSG_PAUSE_PRINT);
  2201. else
  2202. lcdprintPGM(MSG_RESUME_PRINT);
  2203. }
  2204. else
  2205. {
  2206. //lcdprintPGM(MSG_NO_CARD);
  2207. }
  2208. }
  2209. #ifdef CARDINSERTED
  2210. if(CARDINSERTED)
  2211. #endif
  2212. if((activeline==line) && CLICKED)
  2213. {
  2214. if(card.sdprinting)
  2215. {
  2216. card.pauseSDPrint();
  2217. beepshort();
  2218. status = Main_Status;
  2219. }
  2220. else
  2221. {
  2222. card.startFileprint();
  2223. starttime=millis();
  2224. beepshort();
  2225. status = Main_Status;
  2226. }
  2227. }
  2228. }break;
  2229. #else
  2230. case ItemM_file:
  2231. break;
  2232. case ItemM_pause:
  2233. break;
  2234. #endif
  2235. default:
  2236. SERIAL_ERROR_START;
  2237. SERIAL_ERRORLNPGM(MSG_SERIAL_ERROR_MENU_STRUCTURE);
  2238. break;
  2239. }
  2240. line++;
  2241. }
  2242. uint8_t numberOfLines = 4;
  2243. #ifdef SDSUPPORT
  2244. numberOfLines = 4;
  2245. #else
  2246. numberOfLines = 3;
  2247. #endif
  2248. updateActiveLines(numberOfLines,encoderpos);
  2249. }
  2250. void MainMenu::update()
  2251. {
  2252. static MainStatus oldstatus=Main_Menu; //init automatically causes foce_lcd_update=true
  2253. static long timeoutToStatus=0;
  2254. static bool oldcardstatus=false;
  2255. #ifdef CARDINSERTED
  2256. if((CARDINSERTED != oldcardstatus))
  2257. {
  2258. force_lcd_update=true;
  2259. oldcardstatus=CARDINSERTED;
  2260. lcd_init(); // to maybe revive the lcd if static electricty killed it.
  2261. //Serial.println("echo: SD CHANGE");
  2262. if(CARDINSERTED)
  2263. {
  2264. card.initsd();
  2265. LCD_MESSAGEPGM(MSG_SD_INSERTED);
  2266. }
  2267. else
  2268. {
  2269. card.release();
  2270. LCD_MESSAGEPGM(MSG_SD_REMOVED);
  2271. }
  2272. }
  2273. #endif
  2274. if(status!=oldstatus)
  2275. {
  2276. force_lcd_update=true;
  2277. encoderpos=0;
  2278. lineoffset=0;
  2279. oldstatus=status;
  2280. }
  2281. if( (encoderpos!=lastencoderpos) || CLICKED)
  2282. timeoutToStatus=millis()+STATUSTIMEOUT;
  2283. switch(status)
  2284. {
  2285. case Main_Status:
  2286. {
  2287. showStatus();
  2288. if(CLICKED)
  2289. {
  2290. linechanging=false;
  2291. BLOCK
  2292. status=Main_Menu;
  2293. timeoutToStatus=millis()+STATUSTIMEOUT;
  2294. }
  2295. }break;
  2296. case Main_Menu:
  2297. {
  2298. showMainMenu();
  2299. linechanging=false;
  2300. }break;
  2301. case Main_Prepare:
  2302. {
  2303. if(tune)
  2304. {
  2305. showTune();
  2306. }
  2307. else
  2308. {
  2309. showPrepare();
  2310. }
  2311. }break;
  2312. case Sub_PrepareMove:
  2313. {
  2314. showAxisMove();
  2315. }break;
  2316. case Main_Control:
  2317. {
  2318. showControl();
  2319. }break;
  2320. case Sub_MotionControl:
  2321. {
  2322. showControlMotion();
  2323. }break;
  2324. case Sub_RetractControl:
  2325. {
  2326. showControlRetract();
  2327. }break;
  2328. case Sub_TempControl:
  2329. {
  2330. showControlTemp();
  2331. }break;
  2332. case Main_SD:
  2333. {
  2334. showSD();
  2335. }break;
  2336. }
  2337. if(timeoutToStatus<millis())
  2338. status=Main_Status;
  2339. //force_lcd_update=false;
  2340. lastencoderpos=encoderpos;
  2341. }
  2342. // convert float to string with +123.4 format
  2343. char *ftostr3(const float &x)
  2344. {
  2345. //sprintf(conv,"%5.1f",x);
  2346. int xx=x;
  2347. conv[0]=(xx/100)%10+'0';
  2348. conv[1]=(xx/10)%10+'0';
  2349. conv[2]=(xx)%10+'0';
  2350. conv[3]=0;
  2351. return conv;
  2352. }
  2353. char *itostr2(const uint8_t &x)
  2354. {
  2355. //sprintf(conv,"%5.1f",x);
  2356. int xx=x;
  2357. conv[0]=(xx/10)%10+'0';
  2358. conv[1]=(xx)%10+'0';
  2359. conv[2]=0;
  2360. return conv;
  2361. }
  2362. // convert float to string with +123.4 format
  2363. char *ftostr31(const float &x)
  2364. {
  2365. int xx=x*10;
  2366. conv[0]=(xx>=0)?'+':'-';
  2367. xx=abs(xx);
  2368. conv[1]=(xx/1000)%10+'0';
  2369. conv[2]=(xx/100)%10+'0';
  2370. conv[3]=(xx/10)%10+'0';
  2371. conv[4]='.';
  2372. conv[5]=(xx)%10+'0';
  2373. conv[6]=0;
  2374. return conv;
  2375. }
  2376. char *ftostr32(const float &x)
  2377. {
  2378. int xx=x*100;
  2379. conv[0]=(xx>=0)?'+':'-';
  2380. xx=abs(xx);
  2381. conv[1]=(xx/100)%10+'0';
  2382. conv[2]='.';
  2383. conv[3]=(xx/10)%10+'0';
  2384. conv[4]=(xx)%10+'0';
  2385. conv[6]=0;
  2386. return conv;
  2387. }
  2388. char *itostr31(const int &xx)
  2389. {
  2390. conv[0]=(xx>=0)?'+':'-';
  2391. conv[1]=(xx/1000)%10+'0';
  2392. conv[2]=(xx/100)%10+'0';
  2393. conv[3]=(xx/10)%10+'0';
  2394. conv[4]='.';
  2395. conv[5]=(xx)%10+'0';
  2396. conv[6]=0;
  2397. return conv;
  2398. }
  2399. char *itostr3(const int &xx)
  2400. {
  2401. conv[0]=(xx/100)%10+'0';
  2402. conv[1]=(xx/10)%10+'0';
  2403. conv[2]=(xx)%10+'0';
  2404. conv[3]=0;
  2405. return conv;
  2406. }
  2407. char *itostr4(const int &xx)
  2408. {
  2409. conv[0]=(xx/1000)%10+'0';
  2410. conv[1]=(xx/100)%10+'0';
  2411. conv[2]=(xx/10)%10+'0';
  2412. conv[3]=(xx)%10+'0';
  2413. conv[4]=0;
  2414. return conv;
  2415. }
  2416. // convert float to string with +1234.5 format
  2417. char *ftostr51(const float &x)
  2418. {
  2419. int xx=x*10;
  2420. conv[0]=(xx>=0)?'+':'-';
  2421. xx=abs(xx);
  2422. conv[1]=(xx/10000)%10+'0';
  2423. conv[2]=(xx/1000)%10+'0';
  2424. conv[3]=(xx/100)%10+'0';
  2425. conv[4]=(xx/10)%10+'0';
  2426. conv[5]='.';
  2427. conv[6]=(xx)%10+'0';
  2428. conv[7]=0;
  2429. return conv;
  2430. }
  2431. // convert float to string with +123.45 format
  2432. char *ftostr52(const float &x)
  2433. {
  2434. int xx=x*100;
  2435. conv[0]=(xx>=0)?'+':'-';
  2436. xx=abs(xx);
  2437. conv[1]=(xx/10000)%10+'0';
  2438. conv[2]=(xx/1000)%10+'0';
  2439. conv[3]=(xx/100)%10+'0';
  2440. conv[4]='.';
  2441. conv[5]=(xx/10)%10+'0';
  2442. conv[6]=(xx)%10+'0';
  2443. conv[7]=0;
  2444. return conv;
  2445. }
  2446. #endif //ULTRA_LCD