diff --git a/Configuration.h b/Configuration.h index 85e94e1..dcb91b9 100644 --- a/Configuration.h +++ b/Configuration.h @@ -24,8 +24,8 @@ Licence: GPL #define CONFIGURATION_H #define NAME "RepRapFirmware" -#define VERSION "0.78j-dc42" -#define DATE "2014-08-17" +#define VERSION "0.78k-dc42" +#define DATE "2014-08-18" #define AUTHORS "reprappro, dc42, zpl" // Other firmware that we might switch to be compatible with. diff --git a/GCodes.cpp b/GCodes.cpp index afb51c7..3ef9873 100644 --- a/GCodes.cpp +++ b/GCodes.cpp @@ -1877,7 +1877,6 @@ bool GCodes::HandleMcode(GCodeBuffer* gb) } break; - case 21: // Initialise SD - ignore break; @@ -2849,6 +2848,21 @@ bool GCodes::HandleMcode(GCodeBuffer* gb) } break; + case 569: // Set/report axis direction + if(gb->Seen('P')) + { + int8_t drive = gb->GetIValue(); + if(gb->Seen('S')) + { + platform->SetDirectionValue(drive, gb->GetIValue()); + } + else + { + reply.printf("A %d sends drive %d forwards.", (int)platform->GetDirectionValue(drive), drive); + } + } + break; + case 906: // Set/report Motor currents { bool seen = false; diff --git a/Move.cpp b/Move.cpp index 7d1644e..3abbb90 100644 --- a/Move.cpp +++ b/Move.cpp @@ -1199,7 +1199,8 @@ void DDA::Step() if(active) { - timeStep = move->stepDistances[drivesMoving]/velocity; + timeStep = distance/(totalSteps * velocity); // dc42 use the average distance per step + //timeStep = move->stepDistances[drivesMoving]/velocity; // Simple Euler integration to get velocities. // Maybe one day do a Runge-Kutta? diff --git a/Platform.cpp b/Platform.cpp index 98e2ca9..2adae27 100644 --- a/Platform.cpp +++ b/Platform.cpp @@ -182,6 +182,7 @@ void Platform::Init() stepPins = STEP_PINS; directionPins = DIRECTION_PINS; + directions = DIRECTIONS; enablePins = ENABLE_PINS; disableDrives = DISABLE_DRIVES; lowStopPins = LOW_STOP_PINS; @@ -986,13 +987,15 @@ void Platform::SetDirection(byte drive, bool direction) { if(directionPins[drive] < 0) return; + + bool d = (direction == FORWARDS) ? directions[drive] : !directions[drive]; if(drive == E0_DRIVE) //DIRECTION_PINS {15, 26, 4, X3, 35, 53, 51, 48} { - digitalWriteNonDue(directionPins[drive], direction); + digitalWriteNonDue(directionPins[drive], d); } else { - digitalWrite(directionPins[drive], direction); + digitalWrite(directionPins[drive], d); } } @@ -1014,9 +1017,13 @@ void Platform::Step(byte drive) if(!driveEnabled[drive] && enablePins[drive] >= 0) { if(drive == Z_AXIS || drive==E0_DRIVE || drive==E2_DRIVE) //ENABLE_PINS {29, 27, X1, X0, 37, X8, 50, 47} + { digitalWriteNonDue(enablePins[drive], ENABLE); + } else + { digitalWrite(enablePins[drive], ENABLE); + } driveEnabled[drive] = true; } if(drive == E0_DRIVE || drive == E3_DRIVE) //STEP_PINS {14, 25, 5, X2, 41, 39, X4, 49} @@ -1469,7 +1476,7 @@ bool MassStorage::FindNext(FileInfo &file_info) file_info.year = (entry.fdate >> 9) + 1980; if (file_info.fileName[0] == 0) { - strncpy(file_info.fileName, entry.fname, ARRAY_UPB(file_info.fileName)); + strncpy(file_info.fileName, entry.fname, ARRAY_SIZE(file_info.fileName)); } return true; @@ -1571,44 +1578,21 @@ bool FileStore::Open(const char* directory, const char* fileName, bool write) const char* location = (directory != NULL) ? platform->GetMassStorage()->CombineName(directory, fileName) : fileName; - writing = write; lastBufferEntry = FILE_BUF_LEN - 1; - FRESULT openReturn; - - if (writing) + FRESULT openReturn = f_open(&file, location, (writing) ? FA_CREATE_ALWAYS | FA_WRITE : FA_OPEN_EXISTING | FA_READ); + if (openReturn != FR_OK) { - openReturn = f_open(&file, location, FA_CREATE_ALWAYS | FA_WRITE); - if (openReturn != FR_OK) - { - char errString[10]; // don't use scratch_string for this because that may be holding the original filename - platform->Message(HOST_MESSAGE, "Can't open "); - platform->Message(HOST_MESSAGE, location); - platform->Message(HOST_MESSAGE, " to write to, error code "); - snprintf(errString, ARRAY_SIZE(errString), "%d", openReturn); - platform->Message(HOST_MESSAGE, errString); - platform->Message(HOST_MESSAGE, "\n"); - return false; - } - bufferPointer = 0; - } - else - { - openReturn = f_open(&file, location, FA_OPEN_EXISTING | FA_READ); - if (openReturn != FR_OK) - { - char errString[10]; // don't use scratch_string for this because that may be holding the original filename - platform->Message(HOST_MESSAGE, "Can't open "); - platform->Message(HOST_MESSAGE, location); - platform->Message(HOST_MESSAGE, " to read from, error code "); - snprintf(errString, ARRAY_SIZE(errString), "%d", openReturn); - platform->Message(HOST_MESSAGE, errString); - platform->Message(HOST_MESSAGE, "\n"); - return false; - } - bufferPointer = FILE_BUF_LEN; + char errString[12]; // don't use scratch_string for this because that may be holding the original filename + platform->Message(BOTH_MESSAGE, "Can't open "); + platform->AppendMessage(BOTH_MESSAGE, location); + platform->AppendMessage(BOTH_MESSAGE, (writing) ? " to write to, error code " : " to read from, error code "); + snprintf(errString, ARRAY_SIZE(errString), "%d\n", openReturn); + platform->AppendMessage(BOTH_MESSAGE, errString); + return false; } + bufferPointer = (writing) ? 0 : FILE_BUF_LEN; inUse = true; openCount = 1; return true; diff --git a/Platform.h b/Platform.h index 58033b9..45df81e 100644 --- a/Platform.h +++ b/Platform.h @@ -78,7 +78,8 @@ Licence: GPL #define STEP_PINS {14, 25, 5, X2, 41, 39, X4, 49} #define DIRECTION_PINS {15, 26, 4, X3, 35, 53, 51, 48} #define FORWARDS true // What to send to go... -#define BACKWARDS false // ...in each direction +#define BACKWARDS (!FORWARDS) // ...in each direction +#define DIRECTIONS {false, true, true, true, true, true, true, true} #define ENABLE_PINS {29, 27, X1, X0, 37, X8, 50, 47} #define ENABLE false // What to send to enable... #define DISABLE true // ...and disable a drive @@ -592,6 +593,8 @@ public: void EmergencyStop(); void SetDirection(byte drive, bool direction); + void SetDirectionValue(byte drive, bool dVal); + bool GetDirectionValue(byte drive) const; void Step(byte drive); void Disable(byte drive); // There is no drive enable; drives get enabled automatically the first time they are used. void SetMotorCurrent(byte drive, float current); @@ -704,6 +707,7 @@ private: int8_t enablePins[DRIVES]; bool disableDrives[DRIVES]; bool driveEnabled[DRIVES]; + bool directions[DRIVES]; int8_t lowStopPins[DRIVES]; int8_t highStopPins[DRIVES]; float maxFeedrates[DRIVES]; @@ -972,6 +976,16 @@ inline bool Platform::HighStopButNotLow(int8_t axis) const } #endif +inline void Platform::SetDirectionValue(byte drive, bool dVal) +{ + directions[drive] = dVal; +} + +inline bool Platform::GetDirectionValue(byte drive) const +{ + return directions[drive]; +} + inline float Platform::HomeFeedRate(int8_t axis) const { return homeFeedrates[axis]; diff --git a/Release/RepRapFirmware-078i-dc42.bin b/Release/RepRapFirmware-078k-dc42.bin similarity index 50% rename from Release/RepRapFirmware-078i-dc42.bin rename to Release/RepRapFirmware-078k-dc42.bin index 8e03909..5cad559 100644 Binary files a/Release/RepRapFirmware-078i-dc42.bin and b/Release/RepRapFirmware-078k-dc42.bin differ diff --git a/Webserver.cpp b/Webserver.cpp index 481a432..42d7bbd 100644 --- a/Webserver.cpp +++ b/Webserver.cpp @@ -343,7 +343,7 @@ void Webserver::ProcessGcode(const char* gc) char c; size_t i = 0; bool reading_whitespace = false; - while (i < ARRAY_UPB(gcodeReply) && configFile->Read(c)) + while (i < gcodeReply.Length() - 1 && configFile->Read(c)) { if (!reading_whitespace || (c != ' ' && c != '\t')) {