Beispiel #1
0
Printer::Printer(QObject *parent)
{
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName ("UTF-8"));
    PortSettings settings = {BAUD9600, DATA_8, PAR_NONE, STOP_1, FLOW_OFF, 10};
    this->portObj = new QextSerialPort("",settings);
    this->isPrinting=false;
    this->isPaused=true;
    this->connectionActive=false;
    this->temperatureTimer = new QTimer(this);
    this->temperatureTimer->setInterval(2000);
    connect(temperatureTimer, SIGNAL(timeout()), this, SLOT(getTemperature()));

    this->readTimer = new QTimer(this);
    this->readTimer->setInterval(5);
    connect(this->readTimer, SIGNAL(timeout()), this, SLOT(readFromPort()));

    connect(this, SIGNAL(newResponce(QString)), this, SLOT(processResponce(QString)));
    connect(this, SIGNAL(clearToSend()), this, SLOT(send_next()));
    curr_pos.setX(0);
    curr_pos.setY(0);
    curr_pos.setZ(0);
    last_bed_temp = 0;
    last_head_temp = 0;
    inBuffer.clear();
    responseBuffer.clear();
    writeNext=true;
}
Beispiel #2
0
//proper parsing of responce
void Printer::processResponce(QString responce){
    if(!this->connectionActive){
        this->connectionActive=true;
        emit connected(true);
    }
    //add data to buffer
    inBuffer.append(responce);

    //send full responces to fifo
    if(inBuffer.contains("\n")){
        responseBuffer.append(inBuffer.left(inBuffer.lastIndexOf("\n")+1).split("\n",QString::SkipEmptyParts));
    }
    //clear buffer
    inBuffer.remove(0,inBuffer.lastIndexOf("\n")+1);

    //proccess all responces from fifo
    while(responseBuffer.size()>0){
        QString lastResponse=responseBuffer.takeFirst();
        emit write_to_console("Got responce: "+ lastResponse);
        //if its temp status
        if(lastResponse.contains("T:") || lastResponse.contains("B:")){
            bool ok;

            double bed_temp = lastResponse.mid(lastResponse.indexOf("B:")+2,lastResponse.indexOf(" ",lastResponse.indexOf("B:"))-lastResponse.indexOf("B:")-2).toDouble(&ok);
            if(ok){
                last_bed_temp=bed_temp;
            }
            double head_temp = lastResponse.mid(lastResponse.indexOf("T:")+2,lastResponse.indexOf(" ",lastResponse.indexOf("T:"))-lastResponse.indexOf("T:")-2).toDouble(&ok);
            if(ok){
                last_head_temp=head_temp;
            }
            emit currentTemp(last_head_temp,0.0,last_bed_temp);
        }
        //if its response for position command
        //if we are printing then continue
        if(lastResponse.startsWith("ok")){
            if(!this->isPaused){
                emit clearToSend();
            }
        }
        //if its error
        else if(lastResponse.startsWith("Error")){

        }
        //resend line
        else if(lastResponse.toLower().startsWith("resend") || lastResponse.startsWith("rs")){
            bool ok;
            int toResend;
           // toResend=QString::number(lastResponse.toLower().remove(QRegExp("[\\D]")));
           toResend=lastResponse.toLower().remove(QRegExp("[\\D]")).toInt(&ok);
           if(ok){
               this->resendFrom=toResend;
           }
           else{
               write_to_console(tr("something is horribly wrong"));
           }
        }
    }
}
Beispiel #3
0
//proper parsing of responce
void Printer::processResponce(QString responce){
    if(!this->connectionActive){
        this->connectionActive=true;
        emit connected(true);
    }
    //add data to buffer
    inBuffer.append(responce);

    //send full responces to fifo
    if(inBuffer.contains("\n")){
        responseBuffer.append(inBuffer.left(inBuffer.lastIndexOf("\n")+1).split("\n",QString::SkipEmptyParts));
    }
    //clear buffer
    inBuffer.remove(0,inBuffer.lastIndexOf("\n")+1);

    //proccess all responces from fifo
    while(responseBuffer.size()>0){
        QString lastResponse=responseBuffer.takeFirst();
        emit write_to_console("Got responce: "+ lastResponse);
        //if its temp status
        if(lastResponse.contains("T:") || lastResponse.contains("B:")){
            bool ok;

            double bed_temp = lastResponse.mid(lastResponse.indexOf("B:")+2,lastResponse.indexOf(" ",lastResponse.indexOf("B:"))-lastResponse.indexOf("B:")-2).toDouble(&ok);
            if(ok){
                last_bed_temp=bed_temp;
            }
            double head_temp = lastResponse.mid(lastResponse.indexOf("T:")+2,lastResponse.indexOf(" ",lastResponse.indexOf("T:"))-lastResponse.indexOf("T:")-2).toDouble(&ok);
            if(ok){
                last_head_temp=head_temp;
            }
            emit currentTemp(last_head_temp,0.0,last_bed_temp);
        }
        //if its something about sd card
        if(lastResponse.contains("Begin file list")){
            this->sdFiles.clear();
            this->updatingFileList=true;
        }
        if(this->updatingFileList){
            this->sdFiles.append(lastResponse.toLower());
        }
        if(lastResponse.contains("End file list")){
            this->updatingFileList=false;
            this->sdFiles.removeFirst();
            this->sdFiles.removeLast();
            emit SDFileList(this->sdFiles);
        }
        if(lastResponse.contains("SD printing byte")){
            QString prog=lastResponse.right(lastResponse.length()-lastResponse.lastIndexOf(" ")-1);
            QStringList values = prog.split("/");
            emit progress(values.at(0).toInt(), values.at(1).toInt());
            if(values.at(0).toInt()==values.at(1).toInt()){
                emit printFinished(true);
                this->sdPrint=false;
            }
        }
        //if its response for position command
        //if we are printing then continue
        if(lastResponse.startsWith("ok")){
            if(!this->isPaused){
                emit clearToSend();
            }
        }
        //if its error
        else if(lastResponse.startsWith("Error")){

        }
        //resend line
        else if(lastResponse.toLower().startsWith("resend") || lastResponse.startsWith("rs")){
            bool ok;
            int toResend;
           // toResend=QString::number(lastResponse.toLower().remove(QRegExp("[\\D]")));
           toResend=lastResponse.toLower().remove(QRegExp("[\\D]")).toInt(&ok);
           if(ok){
               this->resendFrom=toResend;
               if(!this->isPaused){
                   emit clearToSend();
               }
           }
           else{
               emit write_to_console(tr("something is horribly wrong"));
           }
        }
    }
}