void SimpleShell::on_gcode_received(void *argument) { Gcode *gcode = static_cast<Gcode *>(argument); string args = get_arguments(gcode->get_command()); if (gcode->has_m) { if (gcode->m == 20) { // list sd card gcode->stream->printf("Begin file list\r\n"); ls_command("/sd", gcode->stream); gcode->stream->printf("End file list\r\n"); } else if (gcode->m == 30) { // remove file rm_command("/sd/" + args, gcode->stream); } else if(gcode->m == 501) { // load config override if(args.empty()) { load_command("/sd/config-override", gcode->stream); } else { load_command("/sd/config-override." + args, gcode->stream); } } else if(gcode->m == 504) { // save to specific config override file if(args.empty()) { save_command("/sd/config-override", gcode->stream); } else { save_command("/sd/config-override." + args, gcode->stream); } } } }
void Panel::on_gcode_received(void *argument) { Gcode *gcode = static_cast<Gcode *>(argument); if ( gcode->has_m) { if ( gcode->m == 117 ) { // set LCD message this->message = get_arguments(gcode->get_command()); if (this->message.size() > 20) this->message = this->message.substr(0, 20); gcode->mark_as_taken(); } } }
void Player::on_gcode_received(void *argument) { Gcode *gcode = static_cast<Gcode *>(argument); string args = get_arguments(gcode->get_command()); if (gcode->has_m) { if (gcode->m == 21) { // Dummy code; makes Octoprint happy -- supposed to initialize SD card mounter.remount(); gcode->stream->printf("SD card ok\r\n"); } else if (gcode->m == 23) { // select file this->filename = "/sd/" + args; // filename is whatever is in args this->current_stream = nullptr; if(this->current_file_handler != NULL) { this->playing_file = false; fclose(this->current_file_handler); } this->current_file_handler = fopen( this->filename.c_str(), "r"); if(this->current_file_handler == NULL) { gcode->stream->printf("file.open failed: %s\r\n", this->filename.c_str()); return; } else { // get size of file int result = fseek(this->current_file_handler, 0, SEEK_END); if (0 != result) { this->file_size = 0; } else { this->file_size = ftell(this->current_file_handler); fseek(this->current_file_handler, 0, SEEK_SET); } gcode->stream->printf("File opened:%s Size:%ld\r\n", this->filename.c_str(), this->file_size); gcode->stream->printf("File selected\r\n"); } this->played_cnt = 0; this->elapsed_secs = 0; } else if (gcode->m == 24) { // start print if (this->current_file_handler != NULL) { this->playing_file = true; // this would be a problem if the stream goes away before the file has finished, // so we attach it to the kernel stream, however network connections from pronterface // do not connect to the kernel streams so won't see this FIXME this->reply_stream = THEKERNEL->streams; } } else if (gcode->m == 25) { // pause print this->playing_file = false; } else if (gcode->m == 26) { // Reset print. Slightly different than M26 in Marlin and the rest if(this->current_file_handler != NULL) { string currentfn = this->filename.c_str(); unsigned long old_size = this->file_size; // abort the print abort_command("", gcode->stream); if(!currentfn.empty()) { // reload the last file opened this->current_file_handler = fopen(currentfn.c_str() , "r"); if(this->current_file_handler == NULL) { gcode->stream->printf("file.open failed: %s\r\n", currentfn.c_str()); } else { this->filename = currentfn; this->file_size = old_size; this->current_stream = nullptr; } } } else { gcode->stream->printf("No file loaded\r\n"); } } else if (gcode->m == 27) { // report print progress, in format used by Marlin progress_command("-b", gcode->stream); } else if (gcode->m == 32) { // select file and start print // Get filename this->filename = "/sd/" + args; // filename is whatever is in args including spaces this->current_stream = nullptr; if(this->current_file_handler != NULL) { this->playing_file = false; fclose(this->current_file_handler); } this->current_file_handler = fopen( this->filename.c_str(), "r"); if(this->current_file_handler == NULL) { gcode->stream->printf("file.open failed: %s\r\n", this->filename.c_str()); } else { this->playing_file = true; // get size of file int result = fseek(this->current_file_handler, 0, SEEK_END); if (0 != result) { file_size = 0; } else { file_size = ftell(this->current_file_handler); fseek(this->current_file_handler, 0, SEEK_SET); } } this->played_cnt = 0; this->elapsed_secs = 0; } else if (gcode->m == 600) { // suspend print, Not entirely Marlin compliant, M600.1 will leave the heaters on this->suspend_command((gcode->subcode == 1)?"h":"", gcode->stream); } else if (gcode->m == 601) { // resume print this->resume_command("", gcode->stream); } }else if(gcode->has_g) { if(gcode->g == 28) { // homing cancels suspend if(this->suspended) { // clean up this->suspended= false; THEROBOT->pop_state(); this->saved_temperatures.clear(); this->was_playing_file= false; this->suspend_loops= 0; } } } }