From f95c9fcedec61c16f29eddf5859a0c81ed93d609 Mon Sep 17 00:00:00 2001 From: Fred Murphy Date: Sat, 27 Feb 2016 21:10:22 +0000 Subject: [PATCH] Ensure laser TTL isn't switched off until last block of a G2/G3 --- src/modules/tools/laser/Laser.cpp | 20 ++++++++++++++++++-- src/modules/tools/laser/Laser.h | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/modules/tools/laser/Laser.cpp b/src/modules/tools/laser/Laser.cpp index f1bb05ff..98c94e00 100644 --- a/src/modules/tools/laser/Laser.cpp +++ b/src/modules/tools/laser/Laser.cpp @@ -96,19 +96,25 @@ void Laser::on_module_loaded() { this->register_for_event(ON_SPEED_CHANGE); this->register_for_event(ON_BLOCK_BEGIN); this->register_for_event(ON_BLOCK_END); + this->register_for_event(ON_HALT); } // Turn laser off laser at the end of a move void Laser::on_block_end(void* argument){ this->pwm_pin->write(this->pwm_inverting ? 1 : 0); - if (this->ttl_used) - this->ttl_pin->set(0); + if (this->ttl_used) { + Block* block = static_cast(argument); + // Only switch TTL off if this is the last block for this move - G2/3 are multiple blocks + if (block->final_rate == 0) + this->ttl_pin->set(0); + } } // Set laser power at the beginning of a block void Laser::on_block_begin(void* argument){ this->set_proportional_power(); + } // Turn laser on/off depending on received GCodes @@ -147,3 +153,13 @@ void Laser::set_proportional_power(){ this->pwm_pin->write(this->pwm_inverting ? 1 - proportional_power : proportional_power); } } + +void Laser::on_halt(void *argument) +{ + if(argument == nullptr) { + // Safety check - turn laser off on halt + this->laser_on = false; + if (this->ttl_used) + this->ttl_pin->set(this->laser_on); + } +} diff --git a/src/modules/tools/laser/Laser.h b/src/modules/tools/laser/Laser.h index 911c66f9..d1f7736f 100644 --- a/src/modules/tools/laser/Laser.h +++ b/src/modules/tools/laser/Laser.h @@ -24,6 +24,7 @@ class Laser : public Module{ void on_block_begin(void* argument); void on_gcode_execute(void* argument); void on_speed_change(void* argument); + void on_halt(void* argument); private: void set_proportional_power(); -- 2.20.1