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<Block*>(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
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);
+ }
+}