Пример #1
0
void SimpleShell::calc_thermistor_command( string parameters, StreamOutput *stream)
{
    string s = shift_parameter( parameters );
    int saveto= -1;
    // see if we have -sn as first argument
    if(s.find("-s", 0, 2) != string::npos) {
        // save the results to thermistor n
        saveto= strtol(s.substr(2).c_str(), nullptr, 10);
    }else{
        parameters= s;
    }

    std::vector<float> trl= parse_number_list(parameters.c_str());
    if(trl.size() == 6) {
        // calculate the coefficients
        float c1, c2, c3;
        std::tie(c1, c2, c3) = Thermistor::calculate_steinhart_hart_coefficients(trl[0], trl[1], trl[2], trl[3], trl[4], trl[5]);
        stream->printf("Steinhart Hart coefficients:  I%1.18f J%1.18f K%1.18f\n", c1, c2, c3);
        if(saveto == -1) {
            stream->printf("  Paste the above in the M305 S0 command, then save with M500\n");
        }else{
            char buf[80];
            int n = snprintf(buf, sizeof(buf), "M305 S%d I%1.18f J%1.18f K%1.18f", saveto, c1, c2, c3);
            string g(buf, n);
            Gcode gcode(g, &(StreamOutput::NullStream));
            THEKERNEL->call_event(ON_GCODE_RECEIVED, &gcode );
            stream->printf("  Setting Thermistor %d to those settings, save with M500\n", saveto);
        }

    }else{
        // give help
        stream->printf("Usage: calc_thermistor T1,R1,T2,R2,T3,R3\n");
    }
}
Пример #2
0
void BrPrint3D::openFile()
{   BigButton *btn = qobject_cast<BigButton*>(sender());
    QString typeGcode("*.gcode");
    QString typeAll("*.gcode *.stl *.STL");
    if(btn==bt_import){
        filePath = QFileDialog::getOpenFileName(this, "Open File", QDir::homePath(), typeGcode);
    }
    if(btn==bt_open){
        filePath = QFileDialog::getOpenFileName(this, "Open File", QDir::homePath(), typeAll);
    }
        if (!filePath.isEmpty() && QFileInfo(filePath).completeSuffix() == "gcode") {
            QFile gcode(filePath);
            if (gcode.open(QFile::ReadOnly | QFile::Text)) {
                QTextStream in(&gcode);
                QString text = in.readAll();
                vtkView->renderGcode(text);
                gcode.close();
                emit callFilCount(filePath);
                ui->_ManualControl->setGcodePreview(text);
                if (bt_connect->isChecked())
                    bt_play->setEnabled(true);

            }
        }

    else if(QFileInfo(filePath).completeSuffix()=="STL" ||QFileInfo(filePath).completeSuffix()=="stl"){
        vtkView->renderSTL(filePath);
    }
}
Пример #3
0
// Generate function epilog
void gfunc_epilog(void) {
  // Mark end of code
  gbranch(CodeEnd);
  
  // Output code for function
  gcode();

  // Clear code buffer
  clear_code_buf();
}
Пример #4
0
// When a new line is received, check if it is a command, and if it is, act upon it
void SimpleShell::on_console_line_received( void *argument )
{
    SerialMessage new_message = *static_cast<SerialMessage *>(argument);
    string possible_command = new_message.message;

    // ignore anything that is not lowercase or a $ as it is not a command
    if(possible_command.size() == 0 || (!islower(possible_command[0]) && possible_command[0] != '$')) {
        return;
    }

    // it is a grbl compatible command
    if(possible_command[0] == '$' && possible_command.size() >= 2) {
        switch(possible_command[1]) {
            case 'G':
                // issue get state
                get_command("state", new_message.stream);
                break;

            case 'X':
                THEKERNEL->call_event(ON_HALT, (void *)1); // clears on_halt
                new_message.stream->printf("[Caution: Unlocked]\n");
                break;

            case '#':
                grblDP_command("", new_message.stream);
                break;

            case 'H':
                if(THEKERNEL->is_grbl_mode()) {
                    // issue G28.2 which is force homing cycle
                    Gcode gcode("G28.2", new_message.stream);
                    THEKERNEL->call_event(ON_GCODE_RECEIVED, &gcode);
                }else{
                    new_message.stream->printf("error:only supported in GRBL mode\n");
                }
                break;

            default:
                new_message.stream->printf("error:Invalid statement\n");
                break;
        }

    }else{

        //new_message.stream->printf("Received %s\r\n", possible_command.c_str());
        string cmd = shift_parameter(possible_command);

        // find command and execute it
        if(!parse_command(cmd.c_str(), possible_command, new_message.stream)) {
            new_message.stream->printf("error:Unsupported command\n");
        }
    }
}
Пример #5
0
int main(int argc, char *argv[]){
        gcode(100, 200, 44, 33);
        return 0;
}
Пример #6
0
bool CMyControl::Parse(CStreamReader* reader, Stream* output)
{
	CGCodeParserBase gcode(reader,output);
	return ParseAndPrintResult(&gcode,output);
}
Пример #7
0
/**
resume the suspended print
1. restore the temperatures and wait for them to get up to temp
2. optionally run before_resume gcode if specified
3. restore the position it was at and E and any other saved state
4. resume sd print or send resume upstream
*/
void Player::resume_command(string parameters, StreamOutput *stream )
{
    if(!suspended) {
        stream->printf("Not suspended\n");
        return;
    }

    stream->printf("resuming print...\n");

    // wait for them to reach temp
    if(!this->saved_temperatures.empty()) {
        // set heaters to saved temps
        for(auto& h : this->saved_temperatures) {
            float t= h.second;
            PublicData::set_value( temperature_control_checksum, h.first, &t );
        }
        stream->printf("Waiting for heaters...\n");
        bool wait= true;
        uint32_t tus= us_ticker_read(); // mbed call
        while(wait) {
            wait= false;

            bool timeup= false;
            if((us_ticker_read() - tus) >= 1000000) { // print every 1 second
                timeup= true;
                tus= us_ticker_read(); // mbed call
            }

            for(auto& h : this->saved_temperatures) {
                struct pad_temperature temp;
                if(PublicData::get_value( temperature_control_checksum, current_temperature_checksum, h.first, &temp )) {
                    if(timeup)
                        stream->printf("%s:%3.1f /%3.1f @%d ", temp.designator.c_str(), temp.current_temperature, ((temp.target_temperature == -1) ? 0.0 : temp.target_temperature), temp.pwm);
                    wait= wait || (temp.current_temperature < h.second);
                }
            }
            if(timeup) stream->printf("\n");

            if(wait)
                THEKERNEL->call_event(ON_IDLE, this);

            if(THEKERNEL->is_halted()) {
                // abort temp wait and rest of resume
                THEKERNEL->streams->printf("Resume aborted by kill\n");
                THEKERNEL->robot->pop_state();
                this->saved_temperatures.clear();
                suspended= false;
                return;
            }
        }
    }

    // execute optional gcode if defined
    if(!before_resume_gcode.empty()) {
        stream->printf("Executing before resume gcode...\n");
        struct SerialMessage message;
        message.message = before_resume_gcode;
        message.stream = &(StreamOutput::NullStream);
        THEKERNEL->call_event(ON_CONSOLE_LINE_RECEIVED, &message );
    }

    // Restore position
    stream->printf("Restoring saved XYZ positions and state...\n");
    THEKERNEL->robot->pop_state();
    bool abs_mode= THEKERNEL->robot->absolute_mode; // what mode we were in
    // force absolute mode for restoring position, then set to the saved relative/absolute mode
    THEKERNEL->robot->absolute_mode= true;
    {
        char buf[128];
        int n = snprintf(buf, sizeof(buf), "G1 X%f Y%f Z%f", saved_position[0], saved_position[1], saved_position[2]);
        string g(buf, n);
        Gcode gcode(g, &(StreamOutput::NullStream));
        THEKERNEL->call_event(ON_GCODE_RECEIVED, &gcode );
    }
    THEKERNEL->robot->absolute_mode= abs_mode;

    // restore extruder state
    PublicData::set_value( extruder_checksum, restore_state_checksum, nullptr );

    stream->printf("Resuming print\n");

    if(this->was_playing_file) {
        this->playing_file = true;
        this->was_playing_file= false;
    }else{
        // Send resume to host
        THEKERNEL->streams->printf("// action:resume\r\n");
    }

    // clean up
    this->saved_temperatures.clear();
    suspended= false;
}