Skip to content

Commit

Permalink
Unitialized variable bug: when filament load/unload is canceled, stop…
Browse files Browse the repository at this point in the history
…Motor() would be called. But startMotor() may not have been called in which case state saved by startMotor() is not initialized. Thus, when that state is used by stopMotor() undefined things can happen -- motors disabled that shouldn't be, digipots set to invalid values, etc.
  • Loading branch information
dcnewman committed Oct 25, 2014
1 parent 435a63d commit 128cee9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
37 changes: 24 additions & 13 deletions firmware/src/MightyBoard/shared/Menu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -633,18 +633,28 @@ void FilamentScreen::startMotor(){
steppers::setTargetNew(target, 0, interval, 0x1f);
filamentTimer.clear();
filamentTimer.start(300000000); //5 minutes

motorStarted = true;
}

void FilamentScreen::stopMotor(){
steppers::abort();
steppers::deprimeEnable(true);
void FilamentScreen::stopMotor() {
if ( !motorStarted ) return;

// Next call will disable all the axes
steppers::abort();

// Next call isn't presently needed: steppers::abort() will do it
// steppers::deprimeEnable(true);

//Restore the enabled axis
for (uint8_t i = 0; i < STEPPER_COUNT; i++)
steppers::enableAxis(i, restoreAxesEnabled & _BV(i));
//Restore the enabled axis
for (uint8_t i = 0; i < STEPPER_COUNT; i++)
steppers::enableAxis(i, restoreAxesEnabled & _BV(i));

//Restore the digi pot setting from entry
steppers::setAxisPotValue(axisID, digiPotOnEntry);
// Force enable
stepperAxisSetHardwareEnabledToMatch(restoreAxesEnabled);

//Restore the digi pot setting from entry
steppers::setAxisPotValue(axisID, digiPotOnEntry);
}

void FilamentScreen::update(LiquidCrystalSerial& lcd, bool forceRedraw) {
Expand Down Expand Up @@ -750,6 +760,7 @@ void FilamentScreen::update(LiquidCrystalSerial& lcd, bool forceRedraw) {
stopMotor();
Motherboard::interfaceBlinkOff();
_delay_us(1000000);
interface::popScreen();
break;
case FILAMENT_TIMEOUT:
/// filament motor has been running for 5 minutes
Expand All @@ -771,22 +782,22 @@ void FilamentScreen::setScript(FilamentScript script) {
switch(script) {
case FILAMENT_RIGHT_FOR:
toolID = 0;
axisID = 3;
axisID = A_AXIS;
forward = true;
break;
case FILAMENT_LEFT_FOR:
toolID = 1;
axisID = 4;
axisID = B_AXIS;
forward = true;
break;
case FILAMENT_RIGHT_REV:
toolID = 0;
axisID = 3;
axisID = A_AXIS;
forward = false;
break;
case FILAMENT_LEFT_REV:
toolID = 1;
axisID = 4;
axisID = B_AXIS;
forward = false;
break;
}
Expand Down Expand Up @@ -834,6 +845,7 @@ void FilamentScreen::notifyButtonPressed(ButtonArray::ButtonName button) {
}

void FilamentScreen::reset() {
motorStarted = false;
needsRedraw = false;
toggleBlink = false;
lastHeatIndex = 0;
Expand Down Expand Up @@ -3171,7 +3183,6 @@ void CancelBuildMenu::handleSelect(uint8_t index) {
if ( state != 0 ) {
// We're merely paused while printing
interface::popScreen();
interface::popScreen();
if ( (state != 2) || (0 == eeprom::getEeprom8(eeprom_offsets::HEAT_DURING_PAUSE, DEFAULT_HEAT_DURING_PAUSE)) )
// Turn heat off if cancelling a utility filament load/unload or if canceling
// a filament load during pause and HEAT_DURING_PAUSE is disabled
Expand Down
1 change: 1 addition & 0 deletions firmware/src/MightyBoard/shared/Menu.hh
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ private:
bool forward;
bool helpText;
bool needsRedraw;
bool motorStarted;

void startMotor();
void stopMotor();
Expand Down

0 comments on commit 128cee9

Please sign in to comment.