This commit is contained in:
Alex Voinea 2019-11-21 21:32:52 +02:00
parent 6538262e75
commit 8a806bceea
2 changed files with 36 additions and 144 deletions

View File

@ -162,7 +162,7 @@ void menu_submenu_scroll(menu_func_t submenu)
{ {
menu_stack[menu_depth].menu = menu_menu; menu_stack[menu_depth].menu = menu_menu;
menu_stack[menu_depth++].position = lcd_encoder; menu_stack[menu_depth++].position = lcd_encoder;
menu_goto(submenu, menu_row, false, true); menu_goto(submenu, 0, false, false);
} }
} }

View File

@ -313,33 +313,32 @@ bool bSettings; // flag (i.e. 'fake parameter'
const char STR_SEPARATOR[] PROGMEM = "------------"; const char STR_SEPARATOR[] PROGMEM = "------------";
typedef struct
{
int8_t status;
bool isDir = 0;
uint8_t row = 0;
} _menu_data_scroll_t;
static_assert(sizeof(menu_data)>= sizeof(_menu_data_scroll_t),"_menu_data_scroll_t doesn't fit into menu_data");
static void lcd_filename_scroll() //this is a submenu static void lcd_filename_scroll() //this is a submenu
{ {
typedef struct _menu_data_scroll_t* _md = (_menu_data_scroll_t*)&(menu_data[0]);
{
int8_t status;
int encoderInitial;
} _menu_data_t;
static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data");
_menu_data_t* _md = (_menu_data_t*)&(menu_data[0]);
if (_md->status == 0) if (_md->status == 0)
{ {
_md->status = 1; _md->status = 1;
_md->encoderInitial = lcd_encoder;
lcd_scrollTimer.start(); lcd_scrollTimer.start();
} }
if (LCD_CLICKED || (_md->encoderInitial != lcd_encoder)) //go back to sd_menu. if (LCD_CLICKED || (lcd_encoder != 0)) //go back to sd_menu.
{ {
lcd_scrollTimer.start(); lcd_scrollTimer.start();
// menu_depth--; menu_back_scroll(lcd_encoder);
// menu_goto(menu_stack[menu_depth].menu, menu_stack[menu_depth].position + lcd_encoder_diff / ENCODER_PULSES_PER_STEP, false, true);
menu_back_scroll(lcd_encoder - _md->encoderInitial);
} }
if(lcd_scrollTimer.expired(200) && (scrollPointer != NULL)) if(lcd_scrollTimer.expired(200) && (scrollPointer != NULL))
{ {
uint8_t i = LCD_WIDTH - 1; uint8_t i = LCD_WIDTH - 1;
lcd_set_cursor(0, _md->encoderInitial = lcd_encoder); lcd_set_cursor(0, _md->row);
lcd_print('>'); lcd_print('>');
for (; i != 0; i--) for (; i != 0; i--)
{ {
@ -363,75 +362,12 @@ static void lcd_filename_scroll() //this is a submenu
scrollPointer++; scrollPointer++;
} }
} }
/*
static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, const char* filename, char* longFilename)
{
char c;
int enc_dif = lcd_encoder_diff / ENCODER_PULSES_PER_STEP;
uint8_t n = LCD_WIDTH - 1;
for(uint_least8_t g = 0; g<4;g++){
lcd_set_cursor(0, g);
lcd_print(' ');
}
lcd_set_cursor(0, row);
lcd_print('>');
if (longFilename[0] == '\0')
{
longFilename = filename;
}
int i = 1;
int j = 0;
char* longFilenameTMP = longFilename;
while((c = *longFilenameTMP) != '\0')
{
lcd_set_cursor(i, row);
lcd_print(c);
i++;
longFilenameTMP++;
if(i==LCD_WIDTH){
i=1;
j++;
longFilenameTMP = longFilename + j;
n = LCD_WIDTH - 1;
for(int g = 0; g<300 ;g++){
manage_heater();
if(LCD_CLICKED || ( enc_dif != (lcd_encoder_diff / ENCODER_PULSES_PER_STEP))){
longFilenameTMP = longFilename;
*(longFilenameTMP + LCD_WIDTH - 2) = '\0';
i = 1;
j = 0;
break;
}else{
if (j == 1) _delay_ms(3); //wait around 1.2 s to start scrolling text
_delay_ms(1); //then scroll with redrawing every 300 ms
}
}
}
}
if(c!='\0'){
lcd_set_cursor(i, row);
lcd_print(c);
i++;
}
n=n-i+1;
while(n--)
lcd_print(' ');
}
*/
static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* longFilename) static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* longFilename)
{ {
char c; char c;
uint8_t n = LCD_WIDTH - 1; uint8_t n = LCD_WIDTH - 1;
lcd_set_cursor(0, row); lcd_set_cursor(0, row);
if (lcd_encoder == menu_item) lcd_print('>'); lcd_print((lcd_encoder == menu_item)?'>':' ');
else lcd_print(' ');
// lcd_print((lcd_encoder == menu_item)?'>':' ');
while( ((c = *longFilename) != '\0') && (n>0) ) while( ((c = *longFilename) != '\0') && (n>0) )
{ {
lcd_print(c); lcd_print(c);
@ -441,43 +377,17 @@ static void lcd_implementation_drawmenu_sdfile(uint8_t row, const char* longFile
while(n--) while(n--)
lcd_print(' '); lcd_print(' ');
} }
static void lcd_implementation_drawmenu_sddirectory_selected(uint8_t row, const char* filename, char* longFilename) static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* longFilename)
{ {
char c; char c;
uint8_t n = LCD_WIDTH - 2; uint8_t n = LCD_WIDTH - 2;
lcd_set_cursor(0, row); lcd_set_cursor(0, row);
lcd_print('>'); lcd_print((lcd_encoder == menu_item)?'>':' ');
lcd_print(LCD_STR_FOLDER[0]); lcd_print(LCD_STR_FOLDER[0]);
if (longFilename[0] != '\0') while( ((c = *longFilename) != '\0') && (n>0) )
{
filename = longFilename;
longFilename[LCD_WIDTH-2] = '\0';
}
while( ((c = *filename) != '\0') && (n>0) )
{ {
lcd_print(c); lcd_print(c);
filename++; longFilename++;
n--;
}
while(n--)
lcd_print(' ');
}
static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* filename, char* longFilename)
{
char c;
uint8_t n = LCD_WIDTH - 2;
lcd_set_cursor(0, row);
lcd_print(' ');
lcd_print(LCD_STR_FOLDER[0]);
if (longFilename[0] != '\0')
{
filename = longFilename;
longFilename[LCD_WIDTH-2] = '\0';
}
while( ((c = *filename) != '\0') && (n>0) )
{
lcd_print(c);
filename++;
n--; n--;
} }
while(n--) while(n--)
@ -487,46 +397,26 @@ static void lcd_implementation_drawmenu_sddirectory(uint8_t row, const char* fil
#define MENU_ITEM_SDDIR(str_fn, str_fnl) do { if (menu_item_sddir(str_fn, str_fnl)) return; } while (0) #define MENU_ITEM_SDDIR(str_fn, str_fnl) do { if (menu_item_sddir(str_fn, str_fnl)) return; } while (0)
//#define MENU_ITEM_SDDIR(str, str_fn, str_fnl) MENU_ITEM(sddirectory, str, str_fn, str_fnl)
//extern uint8_t menu_item_sddir(const char* str, const char* str_fn, char* str_fnl);
#define MENU_ITEM_SDFILE(str_fn, str_fnl) do { if (menu_item_sdfile(str_fn, str_fnl)) return; } while (0) #define MENU_ITEM_SDFILE(str_fn, str_fnl) do { if (menu_item_sdfile(str_fn, str_fnl)) return; } while (0)
uint8_t menu_item_sddir(const char* str_fn, char* str_fnl) uint8_t menu_item_sddir(const char* str_fn, char* str_fnl)
{ {
#ifdef NEW_SD_MENU
// str_fnl[18] = 0;
// printf_P(PSTR("menu dir %d '%s' '%s'\n"), menu_row, str_fn, str_fnl);
if (menu_item == menu_line) if (menu_item == menu_line)
{ {
if (lcd_draw_update) if (lcd_draw_update || !lcd_scrollTimer.running())
{ {
lcd_set_cursor(0, menu_row); scrollPointer = (str_fnl[0] == '\0') ? str_fn : str_fnl;
int cnt = lcd_printf_P(PSTR("%c%c%-18s"), (lcd_encoder == menu_item)?'>':' ', LCD_STR_FOLDER[0], str_fnl[0]?str_fnl:str_fn); if (lcd_encoder == menu_item && !lcd_scrollTimer.running())
// int cnt = lcd_printf_P(PSTR("%c%c%-18s"), (lcd_encoder == menu_item)?'>':' ', LCD_STR_FOLDER[0], str_fn); {
} // lcd_beeper_quick_feedback();
if (menu_clicked && (lcd_encoder == menu_item)) _menu_data_scroll_t* _md = (_menu_data_scroll_t*)&(menu_data[0]);
{ _md->isDir = 1;
uint8_t depth = (uint8_t)card.getWorkDirDepth(); _md->row = menu_row;
strcpy(dir_names[depth], str_fn); menu_submenu_scroll(lcd_filename_scroll);
// printf_P(PSTR("%s\n"), dir_names[depth]); return 1;
card.chdir(str_fn); }
lcd_encoder = 0; else lcd_implementation_drawmenu_sddirectory(menu_row, scrollPointer);
return menu_item_ret();
}
}
menu_item++;
return 0;
#else //NEW_SD_MENU
if (menu_item == menu_line)
{
if (lcd_draw_update)
{
if (lcd_encoder == menu_item)
lcd_implementation_drawmenu_sddirectory_selected(menu_row, str_fn, str_fnl);
else
lcd_implementation_drawmenu_sddirectory(menu_row, str_fn, str_fnl);
} }
if (menu_clicked && (lcd_encoder == menu_item)) if (menu_clicked && (lcd_encoder == menu_item))
{ {
@ -534,13 +424,12 @@ uint8_t menu_item_sddir(const char* str_fn, char* str_fnl)
lcd_update_enabled = 0; lcd_update_enabled = 0;
menu_action_sddirectory(str_fn); menu_action_sddirectory(str_fn);
lcd_update_enabled = 1; lcd_update_enabled = 1;
return menu_item_ret(); // return menu_item_ret();
return 1;
} }
} }
menu_item++; menu_item++;
return 0; return 0;
#endif //NEW_SD_MENU
} }
static uint8_t menu_item_sdfile(const char* str_fn, char* str_fnl) static uint8_t menu_item_sdfile(const char* str_fn, char* str_fnl)
@ -553,6 +442,9 @@ static uint8_t menu_item_sdfile(const char* str_fn, char* str_fnl)
if (lcd_encoder == menu_item && !lcd_scrollTimer.running()) if (lcd_encoder == menu_item && !lcd_scrollTimer.running())
{ {
// lcd_beeper_quick_feedback(); // lcd_beeper_quick_feedback();
_menu_data_scroll_t* _md = (_menu_data_scroll_t*)&(menu_data[0]);
_md->isDir = 0;
_md->row = menu_row;
menu_submenu_scroll(lcd_filename_scroll); menu_submenu_scroll(lcd_filename_scroll);
return 1; return 1;
} }