Permalink
Browse files

the bug with the corrupted temperatures hopefully solved,the pid valu…

…es are read on start automatically.
  • Loading branch information...
1 parent e516c46 commit 26cc25768d86a5caf0827de4990063460a82c27b @bkubicek committed Nov 15, 2011
Showing with 37 additions and 29 deletions.
  1. +27 −14 mainwindow.cpp
  2. +2 −0 mainwindow.h
  3. +8 −15 tab_pid.cpp
View
@@ -53,7 +53,7 @@ MainWindow::MainWindow(QWidget *parent): QWidget(parent)
initSerial();
//port = new AbstractSerial();
- readSinceLastSend="";
+ serialBinBuffer.resize(0);
wait_reply=false;
QVBoxLayout *layout = new QVBoxLayout;
@@ -115,6 +115,7 @@ MainWindow::MainWindow(QWidget *parent): QWidget(parent)
connect(this,SIGNAL(newSerialData()),this,SLOT(processReply()));
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),tabVeltest,SLOT(checkDone()));
+ pidloaded=false;
}
MainWindow::~MainWindow()
@@ -231,7 +232,7 @@ void MainWindow::clickedConnect()
connect(timer, SIGNAL(timeout()), this, SLOT(measure()));
timer->start(1000);
- send("M301\n");
+ //getPID();
serialBuffer="";
}
@@ -260,7 +261,7 @@ void MainWindow::clickedRefresh()
foreach (QString s, list)
{
if(s.startsWith("tty"))
- portnames<<QString("/dev/%1").arg(s));
+ portnames<<QString("/dev/%1").arg(s);
}
#else
SerialDeviceEnumerator *m_sde = SerialDeviceEnumerator::instance();
@@ -301,20 +302,23 @@ void getdata(const QString &line,const QString &after, const QString &key,float
void MainWindow::slotRead()
{
QByteArray ba = comport->readAll();
- //qDebug() << "Readed is : " << ba.size() << " bytes";
- //qDebug()<<QString( ba);
- tabRaw->edit->insertPlainText(ba);
- serialBuffer=serialBuffer+QString(ba);
- readSinceLastSend.append(QString(ba));
- int n=serialBuffer.lastIndexOf("\n");
- if(n==-1) return; //not even a full line
- QStringList lines = serialBuffer.mid(0,n).split("\n",QString::SkipEmptyParts);
- serialBuffer=serialBuffer.mid(n,sizeof(serialBuffer)-n);
- foreach(QString s, lines)
+ serialBinBuffer.append(ba);
+ int lastnewlinepos=serialBinBuffer.lastIndexOf('\n');
+ qDebug()<<"newline@"<<lastnewlinepos;
+ if(lastnewlinepos<0)
+ return; //no newline read yet.
+ QString readlines=QString(serialBinBuffer.mid(0,lastnewlinepos).append((char)0));
+ readSinceLastSend.append(readlines);
+ QStringList lines=readlines.split("\n",QString::SkipEmptyParts);
+ serialBinBuffer.remove(0,lastnewlinepos);
+ tabRaw->edit->insertPlainText(readlines);
+
+ foreach(QString s, lines) //s = linecontent
{
+ qDebug()<<"read line:"<<s;
if(s.contains("endstop"))
endstopfound=true;
- if(s.startsWith("ok"))
+ if(s.startsWith("ok") ||s.startsWith("T"))
{
QStringList junks(s.remove(0,3).split(" ",QString::SkipEmptyParts));
foreach(QString j, junks)
@@ -413,6 +417,7 @@ void MainWindow::send(QString text)
void MainWindow::sendGcode(const QString &text)
{
+ qDebug()<<"gcode cue list:"<<sendcodes.size();
sendcodes<<text;
if(wait_reply)
return;
@@ -472,8 +477,16 @@ void MainWindow::processReply()
void MainWindow::measure()
{
+ //qDebug()<<"measure"
+ if(!pidloaded)
+ {
+ getPID();
+ pidloaded=true;
+ }
+ else
if(tabPID->monitor->isChecked())
sendGcode("M105");
+
}
void MainWindow::setHotend1Temp()
View
@@ -117,7 +117,9 @@ public slots:
void openSerial();
void closeSerial();
+ QByteArray serialBinBuffer;
QString readSinceLastSend;
+ bool pidloaded;
};
#endif
View
@@ -28,13 +28,15 @@ TabPID::TabPID(QWidget* parent): QWidget(parent)
//myPlot->setAxisTitle(QwtPlot::xBottom,"");
tempPlot->setAxisTitle(QwtPlot::yLeft,"Celsius");
heaterPlot= new QwtPlot(this);
- heaterPlot->setAxisTitle(QwtPlot::yLeft,"Heating Powert");
+ heaterPlot->setAxisTitle(QwtPlot::yLeft,"Heating Power");
QwtPlotGrid *myGrid=new QwtPlotGrid();
myGrid->attach(tempPlot);
QwtPlotGrid *myhGrid=new QwtPlotGrid();
myhGrid->attach(heaterPlot);
tempPlot->insertLegend(new QwtLegend());
heaterPlot->insertLegend(new QwtLegend());
+ tempPlot->setMaximumHeight(150);
+ heaterPlot->setMaximumHeight(150);
double x[2]={0,0};
double y[2]={0,0};
@@ -114,17 +116,16 @@ TabPID::TabPID(QWidget* parent): QWidget(parent)
QHBoxLayout *h2layout = new QHBoxLayout;
monitor=new QCheckBox("monitor temp",this);
h2layout->addWidget(monitor);
- differential=new QCheckBox("differential",this);
+ differential=new QCheckBox("Offset Temperature",this);
h2layout->addWidget(differential);
btClear=new QPushButton("Clear");
h2layout->addWidget(btClear);
- h2layout->addWidget(new QLabel("Period:"));
+ h2layout->addWidget(new QLabel("Period [sec]:"));
h2layout->addWidget(lPeriod=new QLabel("0"));
- h2layout->addWidget(new QLabel(" sec"));
- h2layout->addWidget(new QLabel("Amplitude:"));
+ h2layout->addWidget(new QLabel("Amplitude [C]:"));
h2layout->addWidget(lAmp=new QLabel("0"));
- h2layout->addWidget(new QLabel("last Amplitude:"));
+ h2layout->addWidget(new QLabel("last Amplitude [C]:"));
h2layout->addWidget(lAmpPrevious=new QLabel("0"));
h2layout->addWidget(new QLabel("ratio:"));
@@ -148,15 +149,7 @@ void TabPID::addData(float t1, float b, float t2, float h)
QTime now=QTime::currentTime();
float dt=starttime.msecsTo(now);
- if((fabs(t1-value_hotend1.last())<50)||(value_hotend1.size()<5))
- value_hotend1.push_back(t1);
- else
- {
- if(value_hotend1.size()<5)
- return;
- else
- value_hotend1.push_back(value_hotend1.last()); //emergency measure, not sure why this is needed.
- }
+ value_hotend1.push_back(t1);
time.push_back(dt);
value_bed.push_back(b);
value_hotend2.push_back(t2);

0 comments on commit 26cc257

Please sign in to comment.