Skip to content

Commit

Permalink
use local variables as string buffer whenever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
TinkerGnome committed Feb 18, 2015
1 parent 49eb0a5 commit e3d4bbb
Show file tree
Hide file tree
Showing 13 changed files with 450 additions and 441 deletions.
2 changes: 1 addition & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// build by the user have been successfully uploaded into firmware.
#define STRING_VERSION_CONFIG_H __DATE__ " " __TIME__ // build date and time
#ifndef STRING_CONFIG_H_AUTHOR
#define STRING_CONFIG_H_AUTHOR "Tinker 15.01a" // Who made the changes.
#define STRING_CONFIG_H_AUTHOR "Tinker_15.02-RC1" // Who made the changes.
#endif

// SERIAL_PORT selects which serial port should be used for communication with the host.
Expand Down
4 changes: 2 additions & 2 deletions Marlin/SdBaseFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
//If we have a longFilename buffer, mark it as invalid. If we find a long filename it will be filled automaticly.
if (longFilename != NULL)
{
longFilename[0] = '\0';
memset( longFilename, '\0', LONG_FILENAME_LENGTH );
}

while (1) {
Expand Down Expand Up @@ -1151,7 +1151,7 @@ int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
longFilename[n+12] = VFAT->name3[2];
//If this VFAT entry is the last one, add a NUL terminator at the end of the string
if (VFAT->sequenceNumber & 0x40)
longFilename[n+13] = '\0';
longFilename[n+13] = '\0';
}
}
// return if normal file or subdirectory
Expand Down
4 changes: 2 additions & 2 deletions Marlin/UltiLCD2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ static void lcd_main_maintenance()

static const menu_t & get_main_menuoption(uint8_t nr, menu_t &opt)
{
menu_index = 0;
uint8_t menu_index = 0;
if (nr == menu_index++)
{
opt.setData(MENU_NORMAL, lcd_main_print);
Expand All @@ -274,7 +274,7 @@ static const menu_t & get_main_menuoption(uint8_t nr, menu_t &opt)

void drawMainSubmenu(uint8_t nr, uint8_t &flags)
{
menu_index = 0;
uint8_t menu_index = 0;
if (nr == menu_index++)
{
LCDMenu::drawMenuString_P(LCD_CHAR_MARGIN_LEFT+3
Expand Down
3 changes: 2 additions & 1 deletion Marlin/UltiLCD2_hi_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,14 @@ void lcd_scroll_menu(const char* menuNameP, int8_t entryCount, entryNameCallback

uint8_t drawOffset = 10 - (uint16_t(viewPos) % 8);
uint8_t itemOffset = uint16_t(viewPos) / 8;
char buffer[32];
for(uint8_t n=0; n<6; n++)
{
uint8_t itemIdx = n + itemOffset;
if (itemIdx >= entryCount)
continue;

char* ptr = entryNameCallback(itemIdx);
char* ptr = entryNameCallback(itemIdx, buffer);
//ptr[10] = '\0';
ptr[20] = '\0';
if (itemIdx == selIndex)
Expand Down
8 changes: 4 additions & 4 deletions Marlin/UltiLCD2_menu_first_run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,11 @@ static void lcd_menu_first_run_material_select_1()
lcd_lib_update_screen();
}

static char* lcd_material_select_callback(uint8_t nr)
static char* lcd_material_select_callback(uint8_t nr, char *buffer)
{
eeprom_read_block(LCD_CACHE_FILENAME(0), EEPROM_MATERIAL_NAME_OFFSET(nr), 8);
LCD_CACHE_FILENAME(0)[8] = '\0';
return LCD_CACHE_FILENAME(0);
eeprom_read_block(buffer, EEPROM_MATERIAL_NAME_OFFSET(nr), 8);
buffer[8] = '\0';
return buffer;
}

static void lcd_material_select_details_callback(uint8_t nr)
Expand Down
129 changes: 64 additions & 65 deletions Marlin/UltiLCD2_menu_maintenance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,103 +46,101 @@ void lcd_menu_maintenance()
lcd_lib_update_screen();
}

static char* lcd_advanced_item(uint8_t nr)
static char* lcd_advanced_item(uint8_t nr, char *buffer)
{
uint8_t index(0);
if (nr == index++)
{
strcpy_P(card.longFilename, PSTR("< RETURN"));
strcpy_P(buffer, PSTR("< RETURN"));
}
else if (nr == index++)
{
strcpy_P(card.longFilename, PSTR("LED settings"));
strcpy_P(buffer, PSTR("LED settings"));
}
else if (nr == index++)
#if EXTRUDERS < 2
strcpy_P(card.longFilename, PSTR("Heatup nozzle"));
strcpy_P(buffer, PSTR("Heatup nozzle"));
#else
strcpy_P(card.longFilename, PSTR("Heatup first nozzle"));
strcpy_P(buffer, PSTR("Heatup first nozzle"));
else if (nr == index++)
strcpy_P(card.longFilename, PSTR("Heatup second nozzle"));
strcpy_P(buffer, PSTR("Heatup second nozzle"));
#endif
#if TEMP_SENSOR_BED != 0
else if (nr == index++)
strcpy_P(card.longFilename, PSTR("Heatup buildplate"));
strcpy_P(buffer, PSTR("Heatup buildplate"));
#endif
else if (nr == index++)
strcpy_P(card.longFilename, PSTR("Home head"));
strcpy_P(buffer, PSTR("Home head"));
else if (nr == index++)
strcpy_P(card.longFilename, PSTR("Lower buildplate"));
strcpy_P(buffer, PSTR("Lower buildplate"));
else if (nr == index++)
strcpy_P(card.longFilename, PSTR("Raise buildplate"));
strcpy_P(buffer, PSTR("Raise buildplate"));
else if (nr == index++)
strcpy_P(card.longFilename, PSTR("Insert material"));
strcpy_P(buffer, PSTR("Insert material"));
else if (nr == index++)
#if EXTRUDERS < 2
strcpy_P(card.longFilename, PSTR("Move material"));
strcpy_P(buffer, PSTR("Move material"));
#else
strcpy_P(card.longFilename, PSTR("Move material (1)"));
strcpy_P(buffer, PSTR("Move material (1)"));
else if (nr == index++)
strcpy_P(card.longFilename, PSTR("Move material (2)"));
strcpy_P(buffer, PSTR("Move material (2)"));
#endif
else if (nr == index++)
strcpy_P(card.longFilename, PSTR("Set fan speed"));
strcpy_P(buffer, PSTR("Set fan speed"));
else if (nr == index++)
strcpy_P(card.longFilename, PSTR("Retraction settings"));
strcpy_P(buffer, PSTR("Retraction settings"));
else if (nr == index++)
strcpy_P(card.longFilename, PSTR("Motion settings"));
strcpy_P(buffer, PSTR("Motion settings"));
else if ((ui_mode & UI_MODE_EXPERT) && (nr == index++))
strcpy_P(card.longFilename, PSTR("Adjust buildplate"));
strcpy_P(buffer, PSTR("Adjust buildplate"));
else if (nr == index++)
strcpy_P(card.longFilename, PSTR("Expert settings"));
strcpy_P(buffer, PSTR("Expert settings"));
else if (nr == index++)
strcpy_P(card.longFilename, PSTR("Version"));
strcpy_P(buffer, PSTR("Version"));
else if (nr == index++)
strcpy_P(card.longFilename, PSTR("Runtime stats"));
strcpy_P(buffer, PSTR("Runtime stats"));
else if (nr == index++)
strcpy_P(card.longFilename, PSTR("Factory reset"));
strcpy_P(buffer, PSTR("Factory reset"));
else
strcpy_P(card.longFilename, PSTR("???"));
strcpy_P(buffer, PSTR("???"));

return card.longFilename;
return buffer;
}

static void lcd_advanced_details(uint8_t nr)
{
LCD_CACHE_FILENAME(1)[0] = '\0';
char buffer[32];
buffer[0] = '\0';
if (!(ui_mode & UI_MODE_EXPERT) && (nr > 8+BED_MENU_OFFSET+2*EXTRUDERS))
++nr;

if (nr == 1)
{
int_to_string(led_brightness_level, LCD_CACHE_FILENAME(1), PSTR("%"));
int_to_string(led_brightness_level, buffer, PSTR("%"));
}else if (nr == 2)
{
int_to_string(int(dsp_temperature[0]), LCD_CACHE_FILENAME(1), PSTR("C/"));
int_to_string(int(target_temperature[0]), LCD_CACHE_FILENAME(1)+strlen(LCD_CACHE_FILENAME(1)), PSTR("C"));
int_to_string(int(target_temperature[0]), int_to_string(int(dsp_temperature[0]), buffer, PSTR("C/")), PSTR("C"));
#if EXTRUDERS > 1
}else if (nr == 3)
{
int_to_string(int(dsp_temperature[1]), LCD_CACHE_FILENAME(1), PSTR("C/"));
int_to_string(int(target_temperature[1]), LCD_CACHE_FILENAME(1)+strlen(LCD_CACHE_FILENAME(1)), PSTR("C"));
int_to_string(int(target_temperature[1]), int_to_string(int(dsp_temperature[1]), buffer, PSTR("C/")), PSTR("C"));
#endif
#if TEMP_SENSOR_BED != 0
}else if (nr == 2 + EXTRUDERS)
{
int_to_string(int(dsp_temperature_bed), LCD_CACHE_FILENAME(1), PSTR("C/"));
int_to_string(int(target_temperature_bed), LCD_CACHE_FILENAME(1)+strlen(LCD_CACHE_FILENAME(1)), PSTR("C"));
int_to_string(int(target_temperature_bed), int_to_string(int(dsp_temperature_bed), buffer, PSTR("C/")), PSTR("C"));
#endif
}else if (nr == 6 + BED_MENU_OFFSET + EXTRUDERS * 2)
{
int_to_string(int(fanSpeed) * 100 / 255, LCD_CACHE_FILENAME(1), PSTR("%"));
int_to_string(int(fanSpeed) * 100 / 255, buffer, PSTR("%"));
}else if (nr == 11 + BED_MENU_OFFSET + EXTRUDERS * 2)
{
lcd_lib_draw_stringP(5, BOTTOM_MENU_YPOS, PSTR(STRING_CONFIG_H_AUTHOR));
return;
}else{
return;
}
lcd_lib_draw_string_left(BOTTOM_MENU_YPOS, LCD_CACHE_FILENAME(1));
lcd_lib_draw_string_left(BOTTOM_MENU_YPOS, buffer);
}

static void homeHead()
Expand Down Expand Up @@ -313,9 +311,10 @@ static void lcd_menu_maintenance_extrude()
lcd_lib_draw_string_centerP(40, PSTR("Rotate to extrude"));
lcd_lib_draw_string_centerP(BOTTOM_MENU_YPOS, PSTR("Click to return"));

int_to_string(int(dsp_temperature[active_extruder]), LCD_CACHE_FILENAME(0), PSTR("C/"));
int_to_string(int(target_temperature[active_extruder]), LCD_CACHE_FILENAME(0)+strlen(LCD_CACHE_FILENAME(0)), PSTR("C"));
lcd_lib_draw_string_center(20, LCD_CACHE_FILENAME(0));
char buffer[32];
;
int_to_string(int(target_temperature[active_extruder]), int_to_string(int(dsp_temperature[active_extruder]), buffer, PSTR("C/")), PSTR("C"));
lcd_lib_draw_string_center(20, buffer);
lcd_lib_draw_heater(LCD_GFX_WIDTH/2-2, 30, getHeaterPower(active_extruder));
lcd_lib_update_screen();
}
Expand Down Expand Up @@ -418,17 +417,17 @@ static void lcd_menu_advanced_factory_reset()
lcd_lib_update_screen();
}

static char* lcd_retraction_item(uint8_t nr)
static char* lcd_retraction_item(uint8_t nr, char *buffer)
{
if (nr == 0)
strcpy_P(card.longFilename, PSTR("< RETURN"));
strcpy_P(buffer, PSTR("< RETURN"));
else if (nr == 1)
strcpy_P(card.longFilename, PSTR("Retract length"));
strcpy_P(buffer, PSTR("Retract length"));
else if (nr == 2)
strcpy_P(card.longFilename, PSTR("Retract speed"));
strcpy_P(buffer, PSTR("Retract speed"));
else
strcpy_P(card.longFilename, PSTR("???"));
return card.longFilename;
strcpy_P(buffer, PSTR("???"));
return buffer;
}

static void lcd_retraction_details(uint8_t nr)
Expand Down Expand Up @@ -460,29 +459,29 @@ static void lcd_menu_maintenance_retraction()
}
}

static char* lcd_motion_item(uint8_t nr)
static char* lcd_motion_item(uint8_t nr, char *buffer)
{
if (nr == 0)
strcpy_P(card.longFilename, PSTR("< RETURN"));
strcpy_P(buffer, PSTR("< RETURN"));
else if (nr == 1)
strcpy_P(card.longFilename, PSTR("Acceleration"));
strcpy_P(buffer, PSTR("Acceleration"));
else if (nr == 2)
strcpy_P(card.longFilename, PSTR("X/Y Jerk"));
strcpy_P(buffer, PSTR("X/Y Jerk"));
else if (nr == 3)
strcpy_P(card.longFilename, PSTR("Max speed X"));
strcpy_P(buffer, PSTR("Max speed X"));
else if (nr == 4)
strcpy_P(card.longFilename, PSTR("Max speed Y"));
strcpy_P(buffer, PSTR("Max speed Y"));
else if (nr == 5)
strcpy_P(card.longFilename, PSTR("Max speed Z"));
strcpy_P(buffer, PSTR("Max speed Z"));
else if (nr == 6)
strcpy_P(card.longFilename, PSTR("Current X/Y"));
strcpy_P(buffer, PSTR("Current X/Y"));
else if (nr == 7)
strcpy_P(card.longFilename, PSTR("Current Z"));
strcpy_P(buffer, PSTR("Current Z"));
else if (nr == 8)
strcpy_P(card.longFilename, PSTR("Current E"));
strcpy_P(buffer, PSTR("Current E"));
else
strcpy_P(card.longFilename, PSTR("???"));
return card.longFilename;
strcpy_P(buffer, PSTR("???"));
return buffer;
}

static void lcd_motion_details(uint8_t nr)
Expand Down Expand Up @@ -541,25 +540,25 @@ static void lcd_menu_maintenance_motion()
}
}

static char* lcd_led_item(uint8_t nr)
static char* lcd_led_item(uint8_t nr, char *buffer)
{
if (nr == 0)
strcpy_P(card.longFilename, PSTR("< RETURN"));
strcpy_P(buffer, PSTR("< RETURN"));
else if (nr == 1)
strcpy_P(card.longFilename, PSTR("Brightness"));
strcpy_P(buffer, PSTR("Brightness"));
else if (nr == 2)
strcpy_P(card.longFilename, PSTR(" Always On"));
strcpy_P(buffer, PSTR(" Always On"));
else if (nr == 3)
strcpy_P(card.longFilename, PSTR(" Always Off"));
strcpy_P(buffer, PSTR(" Always Off"));
else if (nr == 4)
strcpy_P(card.longFilename, PSTR(" On while printing"));
strcpy_P(buffer, PSTR(" On while printing"));
else if (nr == 5)
strcpy_P(card.longFilename, PSTR(" Glow when done"));
strcpy_P(buffer, PSTR(" Glow when done"));
else
strcpy_P(card.longFilename, PSTR("???"));
strcpy_P(buffer, PSTR("???"));
if (nr - 2 == led_mode)
card.longFilename[0] = '>';
return card.longFilename;
buffer[0] = '>';
return buffer;
}

static void lcd_led_details(uint8_t nr)
Expand Down
Loading

0 comments on commit e3d4bbb

Please sign in to comment.