Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into armin-fx-geek_mode
  • Loading branch information
TinkerGnome committed Mar 20, 2016
2 parents 8e604fa + d286fb0 commit 9125514
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 97 deletions.
2 changes: 1 addition & 1 deletion Marlin/SdFileExt.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Defines for long (vfat) filenames
*/
/** Number of VFAT entries used. Every entry has 13 UTF-16 characters */
#define MAX_VFAT_ENTRIES (2)
#define MAX_VFAT_ENTRIES (4)
/** Total size of the buffer used to store the long filenames */
#define LONG_FILENAME_LENGTH (13*MAX_VFAT_ENTRIES+1)

Expand Down
69 changes: 59 additions & 10 deletions Marlin/UltiLCD2_hi_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,32 @@ void eeprom_write_float(const float* addr, float f)
}
#endif

uint16_t lineEntryPos = 0;
int8_t lineEntryWait = 0;
void line_entry_pos_update (uint16_t maxStep)
{
if (lineEntryPos > maxStep) lineEntryPos = 0;
//
lineEntryWait++;
if (lineEntryWait >= LINE_ENTRY_WAIT_END)
{
lineEntryWait = LINE_ENTRY_WAIT_END;
lineEntryPos += LINE_ENTRY_STEP;
if (lineEntryPos > maxStep)
{
lineEntryPos = maxStep;
lineEntryWait = -lineEntryWait;
}
}
else if (lineEntryWait == 0 && lineEntryPos > 0)
{
lineEntryPos -= LINE_ENTRY_STEP;
lineEntryWait--;
}
}

inline void line_entry_pos_reset () { lineEntryPos = lineEntryWait = 0; }

void lcd_tripple_menu(const char* left, const char* right, const char* bottom)
{
if (lcd_lib_encoder_pos != ENCODER_NO_SELECTION)
Expand Down Expand Up @@ -176,14 +202,37 @@ void lcd_progressbar(uint8_t progress)

void lcd_draw_scroll_entry(uint8_t offsetY, char * buffer, uint8_t flags)
{
if (flags & MENU_SELECTED)
{
//lcd_lib_set(3, drawOffset+8*n-1, 62, drawOffset+8*n+7);
lcd_lib_set(LCD_CHAR_MARGIN_LEFT-1, offsetY-1, LCD_GFX_WIDTH-LCD_CHAR_MARGIN_RIGHT, offsetY+7);
lcd_lib_clear_string(LCD_CHAR_MARGIN_LEFT, offsetY, buffer);
}else{
lcd_lib_draw_string(LCD_CHAR_MARGIN_LEFT, offsetY, buffer);
}
uint8_t buffer_len = (uint8_t) strlen(buffer);
char backup = '\0';
uint8_t backup_pos = 0;
if (flags & MENU_SELECTED)
{
if (buffer_len > LINE_ENTRY_TEXT_LENGHT)
{
line_entry_pos_update(LINE_ENTRY_MAX_STEP(buffer_len - LINE_ENTRY_TEXT_LENGHT));
buffer += LINE_ENTRY_TEXT_BEGIN();
backup_pos = LINE_ENTRY_TEXT_LENGHT+LINE_ENTRY_TEXT_OFFSET();
backup = buffer[backup_pos];
buffer[backup_pos] = '\0';
}
//
lcd_lib_set(LCD_CHAR_MARGIN_LEFT-1, offsetY-1, LCD_GFX_WIDTH-LCD_CHAR_MARGIN_RIGHT, offsetY+7);
lcd_lib_clear_string(LCD_CHAR_MARGIN_LEFT+LINE_ENTRY_GFX_BEGIN(), offsetY, buffer);
//
if (backup != '\0')
buffer[backup_pos] = backup;
}else{
if (buffer_len > LINE_ENTRY_TEXT_LENGHT)
{
backup = buffer[LINE_ENTRY_TEXT_LENGHT];
buffer[LINE_ENTRY_TEXT_LENGHT] = '\0';
}
//
lcd_lib_draw_string(LCD_CHAR_MARGIN_LEFT, offsetY, buffer);
//
if (backup != '\0')
buffer[LINE_ENTRY_TEXT_LENGHT] = backup;
}
}

void lcd_scroll_menu(const char* menuNameP, int8_t entryCount, scrollDrawCallback_t entryDrawCallback, entryDetailsCallback_t entryDetailsCallback)
Expand All @@ -208,8 +257,8 @@ void lcd_scroll_menu(const char* menuNameP, int8_t entryCount, scrollDrawCallbac
viewPos += viewDiff / 4;
// if (viewDiff > 0) { viewPos ++; led_glow = led_glow_dir = 0; }
// if (viewDiff < 0) { viewPos --; led_glow = led_glow_dir = 0; }
if (viewDiff > 0) { ++viewPos; }
else if (viewDiff < 0) { --viewPos; }
if (viewDiff > 0) { ++viewPos; line_entry_pos_reset(); }
else if (viewDiff < 0) { --viewPos; line_entry_pos_reset(); }

uint8_t drawOffset = 10 - (uint16_t(viewPos) % 8);
uint8_t itemOffset = uint16_t(viewPos) / 8;
Expand Down
121 changes: 67 additions & 54 deletions Marlin/UltiLCD2_hi_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,65 +46,78 @@ extern menuFunc_t postMenuCheck;
extern uint8_t minProgress;

#define LCD_EDIT_SETTING(_setting, _name, _postfix, _min, _max) do { \
menu.add_menu(menu_t(lcd_menu_edit_setting)); \
lcd_setting_name = PSTR(_name); \
lcd_setting_postfix = PSTR(_postfix); \
lcd_setting_ptr = &_setting; \
lcd_setting_type = sizeof(_setting); \
lcd_setting_start_value = lcd_lib_encoder_pos = _setting; \
lcd_setting_min = _min; \
lcd_setting_max = _max; \
} while(0)
menu.add_menu(menu_t(lcd_menu_edit_setting)); \
lcd_setting_name = PSTR(_name); \
lcd_setting_postfix = PSTR(_postfix); \
lcd_setting_ptr = &_setting; \
lcd_setting_type = sizeof(_setting); \
lcd_setting_start_value = lcd_lib_encoder_pos = _setting; \
lcd_setting_min = _min; \
lcd_setting_max = _max; \
} while(0)
#define LCD_EDIT_SETTING_BYTE_PERCENT(_setting, _name, _postfix, _min, _max) do { \
menu.add_menu(menu_t(lcd_menu_edit_setting)); \
lcd_setting_name = PSTR(_name); \
lcd_setting_postfix = PSTR(_postfix); \
lcd_setting_ptr = &_setting; \
lcd_setting_type = 5; \
lcd_setting_start_value = lcd_lib_encoder_pos = int(_setting) * 100 / 255; \
lcd_setting_min = _min; \
lcd_setting_max = _max; \
} while(0)
menu.add_menu(menu_t(lcd_menu_edit_setting)); \
lcd_setting_name = PSTR(_name); \
lcd_setting_postfix = PSTR(_postfix); \
lcd_setting_ptr = &_setting; \
lcd_setting_type = 5; \
lcd_setting_start_value = lcd_lib_encoder_pos = int(_setting) * 100 / 255; \
lcd_setting_min = _min; \
lcd_setting_max = _max; \
} while(0)
#define LCD_EDIT_SETTING_FLOAT001(_setting, _name, _postfix, _min, _max) do { \
menu.add_menu(menu_t(lcd_menu_edit_setting)); \
lcd_setting_name = PSTR(_name); \
lcd_setting_postfix = PSTR(_postfix); \
lcd_setting_ptr = &_setting; \
lcd_setting_type = 3; \
lcd_setting_start_value = lcd_lib_encoder_pos = (_setting) * 100.0 + 0.5; \
lcd_setting_min = (_min) * 100; \
lcd_setting_max = (_max) * 100; \
} while(0)
menu.add_menu(menu_t(lcd_menu_edit_setting)); \
lcd_setting_name = PSTR(_name); \
lcd_setting_postfix = PSTR(_postfix); \
lcd_setting_ptr = &_setting; \
lcd_setting_type = 3; \
lcd_setting_start_value = lcd_lib_encoder_pos = (_setting) * 100.0 + 0.5; \
lcd_setting_min = (_min) * 100; \
lcd_setting_max = (_max) * 100; \
} while(0)
#define LCD_EDIT_SETTING_FLOAT100(_setting, _name, _postfix, _min, _max) do { \
menu.add_menu(menu_t(lcd_menu_edit_setting)); \
lcd_setting_name = PSTR(_name); \
lcd_setting_postfix = PSTR("00" _postfix); \
lcd_setting_ptr = &(_setting); \
lcd_setting_type = 7; \
lcd_setting_start_value = lcd_lib_encoder_pos = (_setting) / 100 + 0.5; \
lcd_setting_min = (_min) / 100 + 0.5; \
lcd_setting_max = (_max) / 100 + 0.5; \
} while(0)
menu.add_menu(menu_t(lcd_menu_edit_setting)); \
lcd_setting_name = PSTR(_name); \
lcd_setting_postfix = PSTR("00" _postfix); \
lcd_setting_ptr = &(_setting); \
lcd_setting_type = 7; \
lcd_setting_start_value = lcd_lib_encoder_pos = (_setting) / 100 + 0.5; \
lcd_setting_min = (_min) / 100 + 0.5; \
lcd_setting_max = (_max) / 100 + 0.5; \
} while(0)
#define LCD_EDIT_SETTING_FLOAT1(_setting, _name, _postfix, _min, _max) do { \
menu.add_menu(menu_t(lcd_menu_edit_setting)); \
lcd_setting_name = PSTR(_name); \
lcd_setting_postfix = PSTR(_postfix); \
lcd_setting_ptr = &(_setting); \
lcd_setting_type = 8; \
lcd_setting_start_value = lcd_lib_encoder_pos = (_setting) + 0.5; \
lcd_setting_min = (_min) + 0.5; \
lcd_setting_max = (_max) + 0.5; \
} while(0)
menu.add_menu(menu_t(lcd_menu_edit_setting)); \
lcd_setting_name = PSTR(_name); \
lcd_setting_postfix = PSTR(_postfix); \
lcd_setting_ptr = &(_setting); \
lcd_setting_type = 8; \
lcd_setting_start_value = lcd_lib_encoder_pos = (_setting) + 0.5; \
lcd_setting_min = (_min) + 0.5; \
lcd_setting_max = (_max) + 0.5; \
} while(0)
#define LCD_EDIT_SETTING_SPEED(_setting, _name, _postfix, _min, _max) do { \
menu.add_menu(menu_t(lcd_menu_edit_setting)); \
lcd_setting_name = PSTR(_name); \
lcd_setting_postfix = PSTR(_postfix); \
lcd_setting_ptr = &(_setting); \
lcd_setting_type = 6; \
lcd_setting_start_value = lcd_lib_encoder_pos = (_setting) / 60 + 0.5; \
lcd_setting_min = (_min) / 60 + 0.5; \
lcd_setting_max = (_max) / 60 + 0.5; \
} while(0)
menu.add_menu(menu_t(lcd_menu_edit_setting)); \
lcd_setting_name = PSTR(_name); \
lcd_setting_postfix = PSTR(_postfix); \
lcd_setting_ptr = &(_setting); \
lcd_setting_type = 6; \
lcd_setting_start_value = lcd_lib_encoder_pos = (_setting) / 60 + 0.5; \
lcd_setting_min = (_min) / 60 + 0.5; \
lcd_setting_max = (_max) / 60 + 0.5; \
} while(0)

extern uint16_t lineEntryPos;
extern int8_t lineEntryWait;
#define LINE_ENTRY_STEP 2
#define LINE_ENTRY_WAIT_END 24
#define LINE_ENTRY_GFX_LENGHT (LCD_GFX_WIDTH-LCD_CHAR_MARGIN_RIGHT-LCD_CHAR_MARGIN_LEFT)
#define LINE_ENTRY_TEXT_LENGHT (LINE_ENTRY_GFX_LENGHT / LCD_CHAR_SPACING)
#define LINE_ENTRY_TEXT_OFFSET() ((lineEntryPos%LCD_CHAR_SPACING == 0) ? 0 : -1)
#define LINE_ENTRY_TEXT_BEGIN() ((lineEntryPos + LCD_CHAR_SPACING-1) / LCD_CHAR_SPACING)
#define LINE_ENTRY_GFX_BEGIN() (LCD_CHAR_SPACING-1 - (lineEntryPos + LCD_CHAR_SPACING-1) % LCD_CHAR_SPACING)
#define LINE_ENTRY_MAX_STEP(text_length) ((text_length) * LCD_CHAR_SPACING)
void line_entry_pos_update (uint16_t maxStep);
inline void line_entry_pos_reset ();

//If we have a heated bed, then the heated bed menu entries have a size of 1, else they have a size of 0.
#if TEMP_SENSOR_BED != 0
Expand Down
9 changes: 5 additions & 4 deletions Marlin/UltiLCD2_low_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "pins.h"
#include "preferences.h"
#include "UltiLCD2_low_lib.h"
#include "UltiLCD2_hi_lib.h"
#include "tinkergnome.h"

/**
Expand Down Expand Up @@ -508,12 +509,12 @@ void lcd_lib_clear_string(uint8_t x, uint8_t y, const char* str)

void lcd_lib_draw_string_center(uint8_t y, const char* str)
{
lcd_lib_draw_string(64 - strlen(str) * 3, y, str);
lcd_lib_draw_string(LCD_GFX_WIDTH/2 - min(strlen(str), LINE_ENTRY_TEXT_LENGHT) * (LCD_CHAR_SPACING/2), y, str);
}

void lcd_lib_clear_string_center(uint8_t y, const char* str)
{
lcd_lib_clear_string(64 - strlen(str) * 3, y, str);
lcd_lib_clear_string(LCD_GFX_WIDTH/2 - min(strlen(str), LINE_ENTRY_TEXT_LENGHT) * (LCD_CHAR_SPACING/2), y, str);
}

void lcd_lib_draw_stringP(uint8_t x, uint8_t y, const char* pstr)
Expand Down Expand Up @@ -580,12 +581,12 @@ void lcd_lib_clear_stringP(uint8_t x, uint8_t y, const char* pstr)

void lcd_lib_draw_string_centerP(uint8_t y, const char* pstr)
{
lcd_lib_draw_stringP(64 - strlen_P(pstr) * 3, y, pstr);
lcd_lib_draw_stringP(LCD_GFX_WIDTH/2 - strlen_P(pstr) * (LCD_CHAR_SPACING/2), y, pstr);
}

void lcd_lib_clear_string_centerP(uint8_t y, const char* pstr)
{
lcd_lib_clear_stringP(64 - strlen_P(pstr) * 3, y, pstr);
lcd_lib_clear_stringP(LCD_GFX_WIDTH/2 - strlen_P(pstr) * (LCD_CHAR_SPACING/2), y, pstr);
}

void lcd_lib_draw_string_center_atP(uint8_t x, uint8_t y, const char* pstr)
Expand Down
80 changes: 57 additions & 23 deletions Marlin/UltiLCD2_menu_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
#include "tinkergnome.h"

uint8_t lcd_cache[LCD_CACHE_SIZE];
#define LCD_CACHE_NR_OF_FILES() lcd_cache[(LCD_CACHE_COUNT*(LONG_FILENAME_LENGTH+2))]
#define LCD_CACHE_TYPE(n) lcd_cache[LCD_CACHE_COUNT + (n)]
#define LCD_DETAIL_CACHE_ID() lcd_cache[LCD_DETAIL_CACHE_START]

unsigned long predictedTime = 0;

Expand All @@ -38,8 +35,10 @@ static bool primed = false;

void lcd_clear_cache()
{
for(uint8_t n=0; n<LCD_CACHE_COUNT; n++)
for(uint8_t n=0; n<LCD_CACHE_COUNT; ++n)
LCD_CACHE_ID(n) = 0xFF;
for(uint8_t n=0; n<LCD_CACHE_REMAIN_COUNT; ++n)
LCD_CACHE_REMAIN_ID(n) = 0xFF;
LCD_DETAIL_CACHE_ID() = 0;
LCD_CACHE_NR_OF_FILES() = 0xFF;
}
Expand Down Expand Up @@ -240,9 +239,24 @@ static void cardUpdir()
card.updir();
}

void getFilenameFromNr(char* buffer, uint8_t nr)
{
card.getfilename(nr);
if (card.longFilename[0])
{
strncpy(buffer, card.longFilename, LONG_FILENAME_LENGTH-1);
} else {
strncpy(buffer, card.filename, LONG_FILENAME_LENGTH-1);
}
if (!card.filenameIsDir)
{
if (strrchr(buffer, '.')) strrchr(buffer, '.')[0] = '\0';
}
}

static void lcd_sd_menu_filename_callback(uint8_t nr, uint8_t offsetY, uint8_t flags)
{
char buffer[32] = {0};
char buffer[LONG_FILENAME_LENGTH] = {0};
memset(buffer, '\0', sizeof(buffer));
if (nr == 0)
{
Expand All @@ -253,42 +267,62 @@ static void lcd_sd_menu_filename_callback(uint8_t nr, uint8_t offsetY, uint8_t f
strcpy_P(buffer, PSTR("< BACK"));
}
}else{
// buffer[0] = '\0';
for(uint8_t idx=0; idx<LCD_CACHE_COUNT; ++idx)
uint8_t idx;
for(idx=0; idx<LCD_CACHE_COUNT; ++idx)
{
if (LCD_CACHE_ID(idx) == nr)
{
strncpy(buffer, LCD_CACHE_FILENAME(idx), LONG_FILENAME_LENGTH-1);
strncpy(buffer, LCD_CACHE_FILENAME(idx), LCD_CACHE_TEXT_SIZE_SHORT);
break;
}
}
if (buffer[0] == '\0')
{
card.getfilename(nr - 1);
if (card.longFilename[0])
{
strncpy(buffer, card.longFilename, LONG_FILENAME_LENGTH-1);
} else {
strncpy(buffer, card.filename, LONG_FILENAME_LENGTH-1);
}
if (!card.filenameIsDir)
{
if (strrchr(buffer, '.')) strrchr(buffer, '.')[0] = '\0';
}
getFilenameFromNr(buffer, nr - 1);

uint8_t idx = nr % LCD_CACHE_COUNT;
idx = nr % LCD_CACHE_COUNT;
LCD_CACHE_ID(idx) = nr;
strncpy(LCD_CACHE_FILENAME(idx), buffer, LONG_FILENAME_LENGTH-1);
strncpy(LCD_CACHE_FILENAME(idx), buffer, LCD_CACHE_TEXT_SIZE_SHORT);
if (strlen(buffer) < LCD_CACHE_TEXT_SIZE_SHORT)
LCD_CACHE_FILENAME(idx)[LCD_CACHE_TEXT_SIZE_SHORT-1] = '\0';
LCD_CACHE_TYPE(idx) = card.filenameIsDir ? 1 : 0;
if (card.errorCode() && card.sdInserted)
{
//On a read error reset the file position and try to keep going. (not pretty, but these read errors are annoying as hell)
// On a read error reset the file position and try to keep going. (not pretty, but these read errors are annoying as hell)
card.clearError();
LCD_CACHE_ID(idx) = 0xFF;
card.longFilename[0] = '\0';
}
}
buffer[20] = '\0';
if (flags & MENU_SELECTED)
{ // full filename length is needed
// check if filename is short enough
if (buffer[LCD_CACHE_TEXT_SIZE_SHORT-1] == '\0')
goto far_break;
// load from cache
for(idx=0; idx<LCD_CACHE_REMAIN_COUNT; ++idx)
{
if (LCD_CACHE_REMAIN_ID(idx) == nr)
{
strncpy(buffer+LCD_CACHE_TEXT_SIZE_SHORT, LCD_CACHE_REMAIN_FILENAME(idx), LCD_CACHE_TEXT_SIZE_REMAIN);
goto far_break;
}
}
// nothing in cache - load from card
getFilenameFromNr(buffer, nr - 1);
if (card.errorCode() && card.sdInserted)
{
// On a read error try to keep going with short file name. (not pretty, but these read errors are annoying as hell)
card.clearError();
card.longFilename[0] = '\0';
goto far_break;
}
idx = nr % LCD_CACHE_REMAIN_COUNT;
LCD_CACHE_REMAIN_ID(idx) = nr;
strncpy(LCD_CACHE_REMAIN_FILENAME(idx), buffer+LCD_CACHE_TEXT_SIZE_SHORT, LCD_CACHE_TEXT_SIZE_REMAIN);

far_break:;
}
}
lcd_draw_scroll_entry(offsetY, buffer, flags);
}
Expand Down
Loading

0 comments on commit 9125514

Please sign in to comment.