Skip to content

Commit

Permalink
Merge branch 'armin-fx-geek_mode' into geek_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
TinkerGnome committed Feb 18, 2017
2 parents c99deb1 + 9125514 commit e1a20c3
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 97 deletions.
2 changes: 1 addition & 1 deletion Marlin/SdFatConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ uint8_t const SOFT_SPI_SCK_PIN = 13;
* 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)
#endif // SdFatConfig_h
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 @@ -37,6 +37,32 @@ void eeprom_write_float(const float* addr, float f)
eeprom_write_dword((uint32_t*)addr, n.i);
}

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 @@ -175,14 +201,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 @@ -207,8 +256,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 = 11 - (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 @@ -509,12 +510,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 @@ -581,12 +582,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
64 changes: 41 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 @@ -37,8 +34,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 @@ -243,7 +242,7 @@ static void cardUpdir()

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 @@ -254,42 +253,61 @@ 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.currentLongFileName()[0])
card.getFilenameFromNr(buffer, nr - 1);
idx = nr % LCD_CACHE_COUNT;
LCD_CACHE_ID(idx) = nr;
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())
{
strncpy(buffer, card.currentLongFileName(), LONG_FILENAME_LENGTH-1);
} else {
strncpy(buffer, card.currentFileName(), LONG_FILENAME_LENGTH-1);
// 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.clearLongFilename();
}
if (!card.filenameIsDir())
}
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 (strrchr(buffer, '.')) strrchr(buffer, '.')[0] = '\0';
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;
}
}

uint8_t idx = nr % LCD_CACHE_COUNT;
LCD_CACHE_ID(idx) = nr;
strncpy(LCD_CACHE_FILENAME(idx), buffer, LONG_FILENAME_LENGTH-1);
LCD_CACHE_TYPE(idx) = card.filenameIsDir() ? 1 : 0;
// nothing in cache - load from card
card.getFilenameFromNr(buffer, nr - 1);
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 try to keep going with short file name. (not pretty, but these read errors are annoying as hell)
card.clearError();
LCD_CACHE_ID(idx) = 0xFF;
card.clearLongFilename();
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:;
}
buffer[20] = '\0';
}
lcd_draw_scroll_entry(offsetY, buffer, flags);
}
Expand Down
Loading

0 comments on commit e1a20c3

Please sign in to comment.