Fixed slow printing over USB
Fixed printing over USB and via HTTP so that it uses the same lookahead mechanism as for printing from SD provided the data arrives fast enough. Added an incoming buffer for data arriving from USB. NOTE: Pronterface needs to be patched to send the data fast enough for this to work well. Also changed signatures of some member functions to be const-correct
This commit is contained in:
parent
1e444839e0
commit
c09afc035b
4 changed files with 55 additions and 34 deletions
26
GCodes.h
26
GCodes.h
|
@ -41,9 +41,9 @@ class GCodeBuffer
|
|||
char* GetUnprecedentedString();
|
||||
char* GetString();
|
||||
char* Buffer();
|
||||
bool Finished();
|
||||
bool Finished() const;
|
||||
void SetFinished(bool f);
|
||||
char* WritingFileDirectory();
|
||||
char* WritingFileDirectory() const;
|
||||
void SetWritingFileDirectory(char* wfd);
|
||||
|
||||
private:
|
||||
|
@ -75,8 +75,9 @@ class GCodes
|
|||
void QueueFileToPrint(char* fileName);
|
||||
bool GetProbeCoordinates(int count, float& x, float& y, float& z);
|
||||
char* GetCurrentCoordinates();
|
||||
bool PrintingAFile();
|
||||
bool PrintingAFile() const;
|
||||
void Diagnostics();
|
||||
bool HaveIncomingData() const;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -97,7 +98,7 @@ class GCodes
|
|||
bool SetOffsets(GCodeBuffer *gb);
|
||||
bool SetPositions(GCodeBuffer *gb);
|
||||
void LoadMoveBufferFromGCode(GCodeBuffer *gb, bool doingG92);
|
||||
bool NoHome();
|
||||
bool NoHome() const;
|
||||
bool Push();
|
||||
bool Pop();
|
||||
bool DisableDrives();
|
||||
|
@ -110,7 +111,7 @@ class GCodes
|
|||
void WriteHTMLToFile(char b, GCodeBuffer *gb);
|
||||
bool OffsetAxes(GCodeBuffer *gb);
|
||||
|
||||
int8_t Heater(int8_t head);
|
||||
int8_t Heater(int8_t head) const;
|
||||
Platform* platform;
|
||||
bool active;
|
||||
Webserver* webserver;
|
||||
|
@ -172,7 +173,7 @@ inline char* GCodeBuffer::Buffer()
|
|||
return gcodeBuffer;
|
||||
}
|
||||
|
||||
inline bool GCodeBuffer::Finished()
|
||||
inline bool GCodeBuffer::Finished() const
|
||||
{
|
||||
return finished;
|
||||
}
|
||||
|
@ -182,7 +183,7 @@ inline void GCodeBuffer::SetFinished(bool f)
|
|||
finished = f;
|
||||
}
|
||||
|
||||
inline char* GCodeBuffer::WritingFileDirectory()
|
||||
inline char* GCodeBuffer::WritingFileDirectory() const
|
||||
{
|
||||
return writingFileDirectory;
|
||||
}
|
||||
|
@ -192,12 +193,17 @@ inline void GCodeBuffer::SetWritingFileDirectory(char* wfd)
|
|||
writingFileDirectory = wfd;
|
||||
}
|
||||
|
||||
inline bool GCodes::PrintingAFile()
|
||||
inline bool GCodes::PrintingAFile() const
|
||||
{
|
||||
return fileBeingPrinted != NULL;
|
||||
}
|
||||
|
||||
inline bool GCodes::NoHome()
|
||||
inline bool GCodes::HaveIncomingData() const
|
||||
{
|
||||
return fileBeingPrinted != NULL || webserver->GCodeAvailable() || (platform->GetLine()->Status() & byteAvailable);
|
||||
}
|
||||
|
||||
inline bool GCodes::NoHome() const
|
||||
{
|
||||
return !(homeX || homeY || homeZ || homeAxisMoveCount);
|
||||
}
|
||||
|
@ -205,7 +211,7 @@ inline bool GCodes::NoHome()
|
|||
// This function takes care of the fact that the heater and head indices
|
||||
// don't match because the bed is heater 0.
|
||||
|
||||
inline int8_t GCodes::Heater(int8_t head)
|
||||
inline int8_t GCodes::Heater(int8_t head) const
|
||||
{
|
||||
return head+1;
|
||||
}
|
||||
|
|
8
Move.cpp
8
Move.cpp
|
@ -441,7 +441,7 @@ void Move::DoLookAhead()
|
|||
// or both to the maximum that can be achieved because of the requirements of
|
||||
// the adjacent moves.
|
||||
|
||||
if(addNoMoreMoves || !gCodes->PrintingAFile() || lookAheadRingCount > LOOK_AHEAD)
|
||||
if(addNoMoreMoves || !gCodes->HaveIncomingData() || lookAheadRingCount > LOOK_AHEAD)
|
||||
{
|
||||
|
||||
// Run up the moves
|
||||
|
@ -497,7 +497,7 @@ void Move::DoLookAhead()
|
|||
// If there are any new unprocessed moves in there, set their end speeds
|
||||
// according to the cosine of the angle between them.
|
||||
|
||||
if(addNoMoreMoves || !gCodes->PrintingAFile() || lookAheadRingCount > 1)
|
||||
if(addNoMoreMoves || !gCodes->HaveIncomingData() || lookAheadRingCount > 1)
|
||||
{
|
||||
n1 = lookAheadRingGetPointer;
|
||||
n0 = n1->Previous();
|
||||
|
@ -531,7 +531,7 @@ void Move::DoLookAhead()
|
|||
|
||||
// If we are just doing one isolated move, set its end velocity to InstantDv(Z_AXIS).
|
||||
|
||||
if(addNoMoreMoves || !gCodes->PrintingAFile())
|
||||
if(addNoMoreMoves || !gCodes->HaveIncomingData())
|
||||
{
|
||||
n1->SetV(platform->InstantDv(Z_AXIS));
|
||||
n1->SetProcessed(complete);
|
||||
|
@ -1163,7 +1163,7 @@ void LookAhead::Init(long ep[], float f, float vv, bool ce, int8_t mt)
|
|||
// are printing a file, so set processed
|
||||
// complete when we aren't.
|
||||
|
||||
if(reprap.GetGCodes()->PrintingAFile())
|
||||
if(reprap.GetGCodes()->HaveIncomingData())
|
||||
processed = unprocessed;
|
||||
else
|
||||
processed = complete|vCosineSet|upPass;
|
||||
|
|
|
@ -835,6 +835,8 @@ Line::Line()
|
|||
|
||||
void Line::Init()
|
||||
{
|
||||
getIndex = 0;
|
||||
numChars = 0;
|
||||
// alternateInput = NULL;
|
||||
// alternateOutput = NULL;
|
||||
SerialUSB.begin(BAUD_RATE);
|
||||
|
@ -1087,7 +1089,7 @@ void Network::ReceiveInput(char* data, int length, void* pbuf, void* pcb, void*
|
|||
|
||||
|
||||
|
||||
bool Network::CanWrite()
|
||||
bool Network::CanWrite() const
|
||||
{
|
||||
return writeEnabled;
|
||||
}
|
||||
|
@ -1138,7 +1140,7 @@ void Network::Close()
|
|||
//Reset();
|
||||
}
|
||||
|
||||
int8_t Network::Status()
|
||||
int8_t Network::Status() const
|
||||
{
|
||||
if(inputPointer >= inputLength)
|
||||
return status;
|
||||
|
|
49
Platform.h
49
Platform.h
|
@ -183,13 +183,15 @@ Licence: GPL
|
|||
|
||||
#define BAUD_RATE 115200 // Communication speed of the USB if needed.
|
||||
|
||||
const uint16_t lineBufsize = 256; // use a power of 2 for good performance
|
||||
|
||||
/****************************************************************************************************/
|
||||
|
||||
enum EndStopHit
|
||||
{
|
||||
noStop = 0,
|
||||
lowHit = 1,
|
||||
highHit = 2
|
||||
noStop = 0, // no enstop hit
|
||||
lowHit = 1, // low switch hit, or Z-probe in use and above threshold
|
||||
highHit = 2 // high stop hit
|
||||
};
|
||||
|
||||
/***************************************************************************************************/
|
||||
|
@ -264,9 +266,9 @@ class Network //: public InputOutput
|
|||
{
|
||||
public:
|
||||
|
||||
int8_t Status(); // Returns OR of IOStatus
|
||||
int8_t Status() const; // Returns OR of IOStatus
|
||||
bool Read(char& b);
|
||||
bool CanWrite();
|
||||
bool CanWrite() const;
|
||||
void SetWriteEnable(bool enable);
|
||||
void Write(char b);
|
||||
void Write(char* s);
|
||||
|
@ -274,7 +276,7 @@ public:
|
|||
void ReceiveInput(char* data, int length, void* pb, void* pc, void* h);
|
||||
void InputBufferReleased(void* pb);
|
||||
void ConnectionError(void* h);
|
||||
bool Active();
|
||||
bool Active() const;
|
||||
bool LinkIsUp();
|
||||
|
||||
friend class Platform;
|
||||
|
@ -308,7 +310,7 @@ class Line //: public InputOutput
|
|||
{
|
||||
public:
|
||||
|
||||
int8_t Status(); // Returns OR of IOStatus
|
||||
int8_t Status() const; // Returns OR of IOStatus
|
||||
int Read(char& b);
|
||||
void Write(char b);
|
||||
void Write(char* s);
|
||||
|
@ -324,6 +326,9 @@ protected:
|
|||
void Spin();
|
||||
|
||||
private:
|
||||
char buffer[lineBufsize];
|
||||
uint16_t getIndex;
|
||||
uint16_t numChars;
|
||||
};
|
||||
|
||||
class MassStorage
|
||||
|
@ -981,16 +986,24 @@ inline Line* Platform::GetLine()
|
|||
|
||||
inline void Line::Spin()
|
||||
{
|
||||
// Read the serial data in blocks to avoid excessive flow control
|
||||
if (numChars <= lineBufsize/2)
|
||||
{
|
||||
while (SerialUSB.available() > 0 && numChars < lineBufsize)
|
||||
{
|
||||
int incomingByte = SerialUSB.read();
|
||||
if (incomingByte < 0) break;
|
||||
buffer[(getIndex + numChars) % lineBufsize] = (char)incomingByte;
|
||||
++numChars;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline int8_t Line::Status()
|
||||
inline int8_t Line::Status() const
|
||||
{
|
||||
// if(alternateInput != NULL)
|
||||
// return alternateInput->Status();
|
||||
|
||||
if(SerialUSB.available() > 0)
|
||||
return byteAvailable;
|
||||
return nothing;
|
||||
return numChars == 0 ? nothing : byteAvailable;
|
||||
}
|
||||
|
||||
inline int Line::Read(char& b)
|
||||
|
@ -998,11 +1011,11 @@ inline int Line::Read(char& b)
|
|||
// if(alternateInput != NULL)
|
||||
// return alternateInput->Read(b);
|
||||
|
||||
int incomingByte = SerialUSB.read();
|
||||
if(incomingByte < 0)
|
||||
return 0;
|
||||
b = (char)incomingByte;
|
||||
return true;
|
||||
if (numChars == 0) return 0;
|
||||
b = buffer[getIndex];
|
||||
getIndex = (getIndex + 1) % lineBufsize;
|
||||
--numChars;
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline void Line::Write(char b)
|
||||
|
@ -1046,7 +1059,7 @@ inline bool Network::LinkIsUp()
|
|||
return status_link_up();
|
||||
}
|
||||
|
||||
inline bool Network::Active()
|
||||
inline bool Network::Active() const
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
|
Reference in a new issue