From 4f9aed3996a87e3ceb7984fafccb5529d0a7ac68 Mon Sep 17 00:00:00 2001 From: Adrian Scripca Date: Fri, 5 May 2023 11:33:00 +0300 Subject: [PATCH] Set selected work offset when running program. --- grbl_machine.cpp | 11 ++++++++--- grbl_machine.h | 2 +- main.cpp | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/grbl_machine.cpp b/grbl_machine.cpp index 8167d02..e2e9fac 100644 --- a/grbl_machine.cpp +++ b/grbl_machine.cpp @@ -96,10 +96,16 @@ void grbl::machine::check_program(const grbl::program& pgm) { switch_to_state(grbl_machine_state::check_program); } -void grbl::machine::run_program(const grbl::program& pgm) { +void grbl::machine::run_program(const grbl::program& pgm, std::string work_offset) { running_program = pgm; std::cout << "running program (" << running_program.filename << ") with " << running_program.number_of_instructions() << " instructions" - << std::endl; + << " on work offset " << work_offset << std::endl; + + // set desired offset + while (awaiting_responses > 0); + pipe->send(work_offset); + while (awaiting_responses > 0); + switch_to_state(grbl_machine_state::run_program); } @@ -821,7 +827,6 @@ void grbl::machine_state_run_program::on_enter(grbl::machine *m) { } void grbl::machine_state_run_program::on_exit(grbl::machine *m) { - } void grbl::machine_state_run_program::move_to_next_run_stage() { diff --git a/grbl_machine.h b/grbl_machine.h index 356622c..0c9fb9f 100644 --- a/grbl_machine.h +++ b/grbl_machine.h @@ -228,7 +228,7 @@ struct machine : public transport_callbacks { void set_listener(grbl::machine_listener *listener); void connect(); - void run_program(const grbl::program& pgm); + void run_program(const grbl::program& pgm, std::string work_offset); void check_program(const grbl::program& pgm); void request_jog(jog_state jog) const; void cancel_jog() const; diff --git a/main.cpp b/main.cpp index e51f97c..7e83359 100644 --- a/main.cpp +++ b/main.cpp @@ -248,7 +248,7 @@ public: btnRunProgram = new Button(pgm_actions, "Run"); btnRunProgram->set_enabled(false); btnRunProgram->set_callback([&] { - cnc.run_program(pgm); + cnc.run_program(pgm, "G" + std::to_string(cboOffset->selected_index() + 54)); }); btnRunProgram->set_tooltip("Execute program");