Skip to content

Commit

Permalink
some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TinkerGnome committed Feb 15, 2015
1 parent 3ebcd38 commit c844371
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 49 deletions.
57 changes: 53 additions & 4 deletions Marlin/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,9 @@ void process_commands()
unsigned long codenum; //throw away variable
char *starpos = NULL;

printing_state = PRINT_STATE_NORMAL;
if (printing_state != PRINT_STATE_RECOVER)
printing_state = PRINT_STATE_NORMAL;

if(code_seen('G'))
{
switch((int)code_value())
Expand All @@ -908,6 +910,9 @@ void process_commands()
return;
}
case 4: // G4 dwell
if (printing_state == PRINT_STATE_RECOVER)
break;

LCD_MESSAGEPGM(MSG_DWELL);
codenum = 0;
if(code_seen('P')) codenum = code_value(); // milliseconds to wait
Expand Down Expand Up @@ -964,6 +969,9 @@ void process_commands()
break;
#endif //FWRETRACT
case 28: //G28 Home all Axis one at a time
if (printing_state == PRINT_STATE_RECOVER)
break;

printing_state = PRINT_STATE_HOMING;
saved_feedrate = feedrate;
saved_feedmultiply = feedmultiply;
Expand Down Expand Up @@ -1156,6 +1164,9 @@ void process_commands()
case 0: // M0 - Unconditional stop - Wait for user button press on LCD
case 1: // M1 - Conditional stop - Wait for user button press on LCD
{
if (printing_state == PRINT_STATE_RECOVER)
break;

printing_state = PRINT_STATE_WAIT_USER;
LCD_MESSAGEPGM(MSG_USERWAIT);
codenum = 0;
Expand Down Expand Up @@ -1188,6 +1199,9 @@ void process_commands()
case 0: // M0 - Unconditional stop - Wait for user button press on LCD
case 1: // M1 - Conditional stop - Wait for user button press on LCD
{
if (printing_state == PRINT_STATE_RECOVER)
break;

card.pause = true;
while(card.pause)
{
Expand All @@ -1200,6 +1214,8 @@ void process_commands()
break;
#endif
case 17:
if (printing_state == PRINT_STATE_RECOVER)
break;
LCD_MESSAGEPGM(MSG_NO_MOVE);
enable_x();
enable_y();
Expand All @@ -1211,39 +1227,54 @@ void process_commands()

#ifdef SDSUPPORT
case 20: // M20 - list SD card
if (printing_state == PRINT_STATE_RECOVER)
break;
SERIAL_PROTOCOLLNPGM(MSG_BEGIN_FILE_LIST);
card.ls();
SERIAL_PROTOCOLLNPGM(MSG_END_FILE_LIST);
break;
case 21: // M21 - init SD card
if (printing_state == PRINT_STATE_RECOVER)
break;

card.initsd();

break;
case 22: //M22 - release SD card
if (printing_state == PRINT_STATE_RECOVER)
break;
card.release();

break;
case 23: //M23 - Select file
if (printing_state == PRINT_STATE_RECOVER)
break;
starpos = (strchr(strchr_pointer + 4,'*'));
if(starpos!=NULL)
*(starpos-1)='\0';
card.openFile(strchr_pointer + 4,true);
break;
case 24: //M24 - Start SD print
if (printing_state == PRINT_STATE_RECOVER)
break;
card.startFileprint();
starttime=millis();
break;
case 25: //M25 - Pause SD print
if (printing_state == PRINT_STATE_RECOVER)
break;
//card.pauseSDPrint();
card.closefile();
break;
case 26: //M26 - Set SD index
if (printing_state == PRINT_STATE_RECOVER)
break;
if(card.isOk() && code_seen('S')) {
card.setIndex(code_value_long());
}
break;
case 27: //M27 - Get SD status
if (printing_state == PRINT_STATE_RECOVER)
break;
card.getStatus();
break;
case 28: //M28 - Start SD write
Expand All @@ -1260,6 +1291,8 @@ void process_commands()
//card,saving = false;
break;
case 30: //M30 <filename> Delete File
if (printing_state == PRINT_STATE_RECOVER)
break;
if (card.isOk()){
card.closefile();
starpos = (strchr(strchr_pointer + 4,'*'));
Expand All @@ -1272,6 +1305,8 @@ void process_commands()
}
break;
case 923: //M923 - Select file and start printing
if (printing_state == PRINT_STATE_RECOVER)
break;
starpos = (strchr(strchr_pointer + 4,'*'));
if(starpos!=NULL)
*(starpos-1)='\0';
Expand Down Expand Up @@ -1394,9 +1429,7 @@ void process_commands()
}
#endif
if (printing_state == PRINT_STATE_RECOVER)
{
break;
}

printing_state = PRINT_STATE_HEATING;
LCD_MESSAGEPGM(MSG_HEATING);
Expand Down Expand Up @@ -1506,6 +1539,8 @@ void process_commands()
// PWM for HEATER_1_PIN
#if defined(HEATER_1_PIN) && HEATER_1_PIN > -1
case 126: //M126 valve open
if (printing_state == PRINT_STATE_RECOVER)
break;
if (code_seen('S')){
ValvePressure=constrain(code_value(),0,255);
}
Expand All @@ -1514,13 +1549,17 @@ void process_commands()
}
break;
case 127: //M127 valve closed
if (printing_state == PRINT_STATE_RECOVER)
break;
ValvePressure = 0;
break;
#endif //HEATER_1_PIN

// PWM for HEATER_2_PIN
#if defined(HEATER_2_PIN) && HEATER_2_PIN > -1
case 128: //M128 valve open
if (printing_state == PRINT_STATE_RECOVER)
break;
if (code_seen('S')){
EtoPPressure=constrain(code_value(),0,255);
}
Expand All @@ -1529,6 +1568,8 @@ void process_commands()
}
break;
case 129: //M129 valve closed
if (printing_state == PRINT_STATE_RECOVER)
break;
EtoPPressure = 0;
break;
#endif //HEATER_2_PIN
Expand Down Expand Up @@ -1560,6 +1601,8 @@ void process_commands()
break;
case 18: //compatibility
case 84: // M84
if (printing_state == PRINT_STATE_RECOVER)
break;
if(code_seen('S')){
stepper_inactive_time = code_value() * 1000;
}
Expand Down Expand Up @@ -1992,6 +2035,9 @@ void process_commands()
#ifdef FILAMENTCHANGEENABLE
case 600: //Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal]
{
if (printing_state == PRINT_STATE_RECOVER)
break;

float target[4];
float lastpos[4];
target[X_AXIS]=current_position[X_AXIS];
Expand Down Expand Up @@ -2118,6 +2164,9 @@ void process_commands()
#ifdef ENABLE_ULTILCD2
case 601: //M601 Pause in UltiLCD2, X[pos] Y[pos] Z[relative lift] L[later retract distance]
{
if (printing_state == PRINT_STATE_RECOVER)
break;

st_synchronize();
float target[4];
float lastpos[4];
Expand Down
6 changes: 5 additions & 1 deletion Marlin/UltiLCD2_menu_maintenance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,15 @@ void lcd_menu_maintenance_advanced()
set_extrude_min_temp(0);
active_extruder = 0;
enquecommand_P(PSTR("G92 E0"));
target_temperature[active_extruder] = material[active_extruder].temperature;
if (ui_mode & UI_MODE_EXPERT)
{
if (current_temperature[active_extruder] < (material[active_extruder].temperature / 2))
{
target_temperature[active_extruder] = material[active_extruder].temperature;
}
menu.add_menu(menu_t(lcd_menu_expert_extrude));
}else{
target_temperature[active_extruder] = material[active_extruder].temperature;
menu.add_menu(menu_t(lcd_menu_maintenance_extrude, MAIN_MENU_ITEM_POS(0)));
}
}
Expand Down
1 change: 1 addition & 0 deletions Marlin/UltiLCD2_menu_material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ bool lcd_material_verify_material_settings()
return false;

eeprom_read_block(LCD_CACHE_FILENAME(0), EEPROM_MATERIAL_NAME_OFFSET(cnt), 8);
LCD_CACHE_FILENAME(0)[8] = '\0';
if (strcmp_P(LCD_CACHE_FILENAME(0), PSTR("UPET")) == 0)
hasUPET = true;
}
Expand Down
29 changes: 16 additions & 13 deletions Marlin/UltiLCD2_menu_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,19 @@
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_START ((LCD_CACHE_COUNT*(LONG_FILENAME_LENGTH+2))+1)
#define LCD_DETAIL_CACHE_ID() lcd_cache[LCD_DETAIL_CACHE_START]
#define LCD_DETAIL_CACHE_MATERIAL(n) (*(uint32_t*)&lcd_cache[LCD_DETAIL_CACHE_START+5+4*n])

void doCooldown();//TODO
static void lcd_menu_print_heatup();
static void lcd_menu_print_printing();
static void lcd_menu_print_error();
static void lcd_menu_print_classic_warning();
static void lcd_menu_print_ready_cooled_down();
static void lcd_menu_print_tune_retraction();

bool primed = false;
static bool primed = false;
static bool pauseRequested = false;


void lcd_clear_cache()
{
for(uint8_t n=0; n<LCD_CACHE_COUNT; n++)
Expand Down Expand Up @@ -112,18 +109,20 @@ static void checkPrintFinished()

void doStartPrint()
{
// zero the extruder position
current_position[E_AXIS] = 0.0;
plan_set_e_position(0);
primed = false;

if (printing_state == PRINT_STATE_RECOVER)
{
printing_state = PRINT_STATE_NORMAL;
}
else
{
// zero the extruder position
current_position[E_AXIS] = 0.0;
plan_set_e_position(0);
}

// since we are going to prime the nozzle, forget about any G10/G11 retractions that happened at end of previous print
retracted = false;
primed = false;

for(uint8_t e = 0; e<EXTRUDERS; e++)
{
Expand Down Expand Up @@ -197,7 +196,10 @@ static char* lcd_sd_menu_filename_callback(uint8_t nr)
for(uint8_t idx=0; idx<LCD_CACHE_COUNT; idx++)
{
if (LCD_CACHE_ID(idx) == nr)
{
strcpy(card.longFilename, LCD_CACHE_FILENAME(idx));
break;
}
}
if (card.longFilename[0] == '\0')
{
Expand Down Expand Up @@ -261,12 +263,12 @@ void lcd_sd_menu_details_callback(uint8_t nr)
buffer[sizeof(buffer)-1] = '\0';
while (strlen(buffer) > 0 && buffer[strlen(buffer)-1] < ' ') buffer[strlen(buffer)-1] = '\0';
if (strncmp_P(buffer, PSTR(";TIME:"), 6) == 0)
LCD_DETAIL_CACHE_TIME() = atol(buffer + 6);
LCD_DETAIL_CACHE_TIME() = strtol(buffer + 6, 0, 0);
else if (strncmp_P(buffer, PSTR(";MATERIAL:"), 10) == 0)
LCD_DETAIL_CACHE_MATERIAL(0) = atol(buffer + 10);
LCD_DETAIL_CACHE_MATERIAL(0) = strtol(buffer + 10, 0, 0);
#if EXTRUDERS > 1
else if (strncmp_P(buffer, PSTR(";MATERIAL2:"), 11) == 0)
LCD_DETAIL_CACHE_MATERIAL(1) = atol(buffer + 11);
LCD_DETAIL_CACHE_MATERIAL(1) = strtol(buffer + 11 ,0 ,0);
#endif
}
}
Expand Down Expand Up @@ -952,7 +954,8 @@ void lcd_print_pause()
else
enquecommand_P(PSTR("M601 X10 Y200 Z0 L20"));
}
else{
else if (!pauseRequested)
{
lcd_lib_beep();
pauseRequested = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/UltiLCD2_menu_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ void doStartPrint();
void lcd_change_to_menu_change_material_return();
void lcd_menu_print_pause();

extern bool primed;
//extern bool primed;

#endif//ULTI_LCD2_MENU_PRINT_H
Loading

0 comments on commit c844371

Please sign in to comment.