My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ultralcd.pde 38KB

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