diff --git a/Marlin/ultralcd.h b/Marlin/ultralcd.h index 6bae43dcc..d3496bec9 100644 --- a/Marlin/ultralcd.h +++ b/Marlin/ultralcd.h @@ -72,6 +72,55 @@ int8_t lastlineoffset; bool linechanging; + + private: + inline void updateActiveLines(const uint8_t &maxlines,volatile int &encoderpos) + { + if(linechanging) return; // an item is changint its value, do not switch lines hence + lastlineoffset=lineoffset; + int curencoderpos=encoderpos; + force_lcd_update=false; + if( (abs(curencoderpos-lastencoderpos)(LCD_HEIGHT-1+1)*lcdslow) + { + lineoffset++; + curencoderpos=(LCD_HEIGHT-1)*lcdslow; + if(lineoffset>(maxlines+1-LCD_HEIGHT)) + lineoffset=maxlines+1-LCD_HEIGHT; + if(curencoderpos>maxlines*lcdslow) + curencoderpos=maxlines*lcdslow; + force_lcd_update=true; + } + lastencoderpos=encoderpos=curencoderpos; + activeline=curencoderpos/lcdslow; + if(activeline<0) activeline=0; + if(activeline>LCD_HEIGHT-1) activeline=LCD_HEIGHT-1; + if(activeline>maxlines) + { + activeline=maxlines; + curencoderpos=maxlines*lcdslow; + } + lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003'); + } + } + + inline void clearIfNecessary() + { + if(lastlineoffset!=lineoffset ||force_lcd_update) + { + force_lcd_update=true; + lcd.clear(); + } + } }; //conversion routines, could need some overworking diff --git a/Marlin/ultralcd.pde b/Marlin/ultralcd.pde index c4ea23488..aa30a3dd0 100644 --- a/Marlin/ultralcd.pde +++ b/Marlin/ultralcd.pde @@ -279,7 +279,6 @@ MainMenu::MainMenu() linechanging=false; } - void MainMenu::showStatus() { #if LCD_HEIGHT==4 @@ -426,131 +425,46 @@ void MainMenu::showStatus() enum {ItemP_exit, ItemP_home, ItemP_origin, ItemP_preheat, ItemP_extrude, ItemP_disstep}; +//any action must not contain a ',' character anywhere, or this breaks: +#define MENUITEM(repaint_action, click_action) \ + {\ + if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \ + if((activeline==line) && CLICKED) {click_action} \ + } + void MainMenu::showPrepare() { uint8_t line=0; - if(lastlineoffset!=lineoffset) - { - force_lcd_update=true; - clear(); - } + clearIfNecessary(); for(int8_t i=lineoffset;i3) - { - lineoffset++; - encoderpos=3*lcdslow; - if(lineoffset>(ItemP_disstep+1-LCD_HEIGHT)) - lineoffset=ItemP_disstep+1-LCD_HEIGHT; - force_lcd_update=true; - } - //encoderpos=encoderpos%LCD_HEIGHT; - lastencoderpos=encoderpos; - activeline=encoderpos/lcdslow; - lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003'); - } + updateActiveLines(ItemP_disstep,encoderpos); } enum { ItemC_exit, ItemC_nozzle, @@ -563,31 +477,35 @@ enum { ItemC_aret,ItemC_esteps, ItemC_store, ItemC_load,ItemC_failsafe }; +//does not work +// #define MENUCHANGEITEM(repaint_action, enter_action, accept_action, change_action) \ +// {\ +// if(force_lcd_update) { lcd.setCursor(0,line); repaint_action; } \ +// if(activeline==line) \ +// { \ +// if(CLICKED) \ +// { \ +// linechanging=!linechanging; \ +// if(linechanging) {enter_action;} \ +// else {accept_action;} \ +// } \ +// else \ +// if(linechanging) {change_action};}\ +// } +// + + void MainMenu::showControl() { uint8_t line=0; - if((lastlineoffset!=lineoffset)||force_lcd_update) - { - force_lcd_update=true; - clear(); - } + clearIfNecessary(); for(int8_t i=lineoffset;i3) - { - lineoffset++; - encoderpos=3*lcdslow; - if(lineoffset>(ItemC_failsafe+1-LCD_HEIGHT)) - lineoffset=ItemC_failsafe+1-LCD_HEIGHT; - force_lcd_update=true; - } - //encoderpos=encoderpos%LCD_HEIGHT; - lastencoderpos=encoderpos; - activeline=encoderpos/lcdslow; - if(activeline>3) activeline=3; - lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003'); - } + updateActiveLines(ItemC_failsafe,encoderpos); } @@ -1175,14 +1065,11 @@ void MainMenu::showSD() #ifdef SDSUPPORT uint8_t line=0; - if(lastlineoffset!=lineoffset) - { - force_lcd_update=true; - } + clearIfNecessary(); static uint8_t nrfiles=0; if(force_lcd_update) { - clear(); + clear(); if(card.cardOK) { nrfiles=card.getnrfilenames(); @@ -1192,7 +1079,6 @@ void MainMenu::showSD() nrfiles=0; lineoffset=0; } - //Serial.print("Nr files:"); Serial.println((int)nrfiles); } for(int8_t i=lineoffset;i3) - { - lineoffset++; - encoderpos=3*lcdslow; - if(lineoffset>(1+nrfiles+1-LCD_HEIGHT)) - lineoffset=1+nrfiles+1-LCD_HEIGHT; - force_lcd_update=true; - - } - lastencoderpos=encoderpos; - activeline=encoderpos; - if(activeline>3) - { - activeline=3; - } - if(activeline<0) - { - activeline=0; - } - if(activeline>1+nrfiles) activeline=1+nrfiles; - if(lineoffset>1+nrfiles) lineoffset=1+nrfiles; - lcd.setCursor(0,activeline);lcd.print((activeline+lineoffset)?'>':'\003'); - - } + updateActiveLines(1+nrfiles,encoderpos); #endif } enum {ItemM_watch, ItemM_prepare, ItemM_control, ItemM_file }; void MainMenu::showMainMenu() { - //if(int(encoderpos/lcdslow)!=int(lastencoderpos/lcdslow)) - // force_lcd_update=true; + #ifndef ULTIPANEL force_lcd_update=false; #endif - //Serial.println((int)activeline); - if(force_lcd_update) - clear(); + + clearIfNecessary(); for(int8_t line=0;line=LCD_HEIGHT) - activeline=LCD_HEIGHT-1; - if((encoderpos!=lastencoderpos)||force_lcd_update) - { - lcd.setCursor(0,activeline);lcd.print(activeline?' ':' '); - if(encoderpos<0) encoderpos=0; - if(encoderpos>3*lcdslow) - encoderpos=3*lcdslow; - activeline=abs(encoderpos/lcdslow)%LCD_HEIGHT; - if(activeline<0) - activeline=0; - if(activeline>=LCD_HEIGHT) - activeline=LCD_HEIGHT-1; - lastencoderpos=encoderpos; - lcd.setCursor(0,activeline);lcd.print(activeline?'>':'\003'); - } + updateActiveLines(3,encoderpos); } void MainMenu::update() @@ -1433,20 +1235,18 @@ void MainMenu::update() if(CARDINSERTED) { card.initsd(); - lcd_status("Card inserted"); + LCD_MESSAGEPGM("Card inserted"); } else { card.release(); - lcd_status("Card removed"); + LCD_MESSAGEPGM("Card removed"); } } #endif if(status!=oldstatus) { - //Serial.println(status); - //clear(); force_lcd_update=true; encoderpos=0; lineoffset=0;