Пример #1
0
bool Repetier::setBedTemp(int temp)
{
    char send[bufsize], serialAns[bufsize];
    int newBedTemp;
    if (this->tempBed == temp) {
        return false;
    }
    sprintf(send, "M140 S%d", temp);
    prepareStringToSend(send, this->bufsize);
    if (isCommaDecimalMark == true) {
        commaDecimalMarkToPoint(send, this->bufsize);
    }

    communicationBool.lock();
    arduinoAccess.lock();
    arduino->writeStr(send);
    do {
        arduino->readUntil(serialAns, '\n', this->bufsize);
    } while (serialAns[0] != 'T');
    prepareStringToReceive(serialAns, bufsize);
    if (isCommaDecimalMark == true) {
        pointDecimalMarkToComma(serialAns, this->bufsize);
    }
    if (sscanf(serialAns, "TargetBed:%d", &newBedTemp) != 0) {
        if (newBedTemp == temp) {
            this->tempBed = temp;
            if (logout) {
                //this->log->insertInfo(logtxt);
                char *logtxt = (char*)malloc(101 * sizeof(char));
                sprintf(logtxt, "Temperature of bed changed to %d oC.", this->tempBed);
                try {
                    this->log->insertInfo(logtxt);
                } catch (std:: string e) {
                    throw e;
                }
            }
            arduinoAccess.unlock();
            communicationBool.unlock();
            return true;
        } else {
            if (logout) {
                //this->log->insertInfo(logtxt);
                char *logtxt = (char*)malloc(101 * sizeof(char));
                sprintf(logtxt, "Attempted to change bed temperature to %d oC.", temp);
                try {
                    this->log->insertInfo(logtxt);
                } catch (std:: string e) {
                    throw e;
                }
            }
            arduinoAccess.unlock();
            communicationBool.unlock();
            return false;
        }
    }
    arduinoAccess.unlock();
    communicationBool.unlock();
    return false;
}
Пример #2
0
void Repetier::extruderControl(double extrude, double atSpeed){
    char send[this->bufsize], serialAns[this->bufsize];
    sprintf(send, "M82\n\r");
    arduino->writeStr(send);
    do{
        arduino->readUntil(serialAns, '\n', this->bufsize);
    }while(strstr(serialAns, "ok") == NULL);
    sprintf(send, "G1 E%.4lf F%.2lf\n\r", extrude, atSpeed);
    if(this->isCommaDecimalMark == true){
        commaDecimalMarkToPoint(send, this->bufsize);
    }
    arduino->writeStr(send);
    do{
        arduino->readUntil(serialAns, '\n', this->bufsize);
    }while(strstr(serialAns, "ok") == NULL);
}
Пример #3
0
void Repetier::moveAxisToPos(char axis, double pos) throw (std::string)
{
    char send[this->bufsize], serialAns[this->bufsize], *test;
    if (axis >= 'a' && axis <= 'z') {
        axis -= 'a';
        axis += 'A';
    }
    if (axis != 'X' && axis != 'Y' && axis != 'Z') {
        std::string exc = "Repetier: Invalid axis.";
        throw exc;
    }
    sprintf(send, "G1 %c%.3lf", axis, pos);
    prepareStringToSend(send, this->bufsize);
    if (isCommaDecimalMark == true) {
        commaDecimalMarkToPoint(send, this->bufsize);
    }
    arduinoAccess.lock();
    arduino->writeStr(send);
    do {
        arduino->readUntil(serialAns, '\n', this->bufsize);
    } while (strstr(serialAns, "ok") == NULL);
    sprintf(send, "M114");
    prepareStringToSend(send, this->bufsize);
    arduino->writeStr(send);
    do {
        arduino->readUntil(serialAns, '\n', this->bufsize);
    } while (strstr(serialAns, "X:") == NULL);
    arduinoAccess.unlock();
    if (isCommaDecimalMark == true) {
        pointDecimalMarkToComma(serialAns, this->bufsize);
    }
    switch (axis) {
    case 'X':
        sscanf(serialAns, "X:%lf ", &this->currentX);
        break;
    case 'Y':
        test = strstr(serialAns, "Y:");
        sscanf(test, "Y:%lf ", &this->currentY);
        break;
    case 'Z':
        test = strstr(serialAns, "Z:");
        sscanf(test, "Z:%lf ", &this->currentZ);
        break;
    default:
        break;
    }
}
Пример #4
0
bool Repetier::setExtrTemp(int extrNo, int temp) throw (std::string){
    char serialAns[bufsize], send[bufsize];
    int tempExt;
    if(extrNo < this->nExtruders){
        if(this->tempExtr[extrNo] == temp){
            return false;
        }
        sprintf(send, "M104 S%d T%d", temp, extrNo);
        prepareStringToSend(send, this->bufsize);
        if(isCommaDecimalMark == true){
            commaDecimalMarkToPoint(send, this->bufsize);
        }
        communicationBool.lock();
        arduinoAccess.lock();
        arduino->writeStr(send);
        do{
            arduino->readUntil(serialAns, '\n', this->bufsize);
            //test = strstr(serialAns, "TargetExtr");
        }while(serialAns[0] != 'T');
        prepareStringToReceive(serialAns, this->bufsize);
        if(isCommaDecimalMark == true){
            pointDecimalMarkToComma(serialAns, this->bufsize);
        }
        sprintf(send, "TargetExtr%d:%%d", extrNo);
        if(sscanf(serialAns, send, &tempExt) != 0){
            if(tempExt == temp){
                this->tempExtr[extrNo] = tempExt;
                if(logout){
                    //this->log->insertInfo(logtxt);
                    char *logtxt = (char*)malloc(101 * sizeof(char));
                    sprintf(logtxt, "Extruder temperature %d changed to %d oC.", extrNo, this->tempExtr[extrNo]);
                    try{
                        this->log->insertInfo(logtxt);
                    }catch(std:: string e){
                        throw e;
                    }
                }
                arduinoAccess.unlock();
                communicationBool.unlock();
                return true;
            }else{
                if(logout){
                    //this->log->insertInfo(logtxt);
                    char *logtxt = (char*)malloc(101 * sizeof(char));
                    sprintf(logtxt, "Attempted to change temperature of extruder %d to %d oC.", extrNo, temp);
                    try{
                        this->log->insertInfo(logtxt);
                    }catch(std:: string e){
                        throw e;
                    }
                }
                arduinoAccess.unlock();
                communicationBool.unlock();
                return false;
            }
        }
    }
    arduinoAccess.unlock();
    communicationBool.unlock();
    std::string exc = "Repetier: Invalid extruder number.";
    throw exc;
}