From: Jim Morris Date: Mon, 5 Mar 2018 14:50:08 +0000 (+0000) Subject: Merge pull request #1278 from wolfmanjm/upstreamedge X-Git-Url: https://git.hcoop.net/clinton/Smoothieware.git/commitdiff_plain/da684624485246f77bd49973c6c3001bdacd116a?hp=8daf94fac989dc7b3f6d46bdc549b5bf4d9147ff Merge pull request #1278 from wolfmanjm/upstreamedge fix bad formatting from laser PR --- diff --git a/src/modules/tools/laser/Laser.cpp b/src/modules/tools/laser/Laser.cpp index 6706c80c..117cd9e7 100644 --- a/src/modules/tools/laser/Laser.cpp +++ b/src/modules/tools/laser/Laser.cpp @@ -42,8 +42,8 @@ Laser::Laser() { laser_on = false; - scale= 1; - manual_fire= false; + scale = 1; + manual_fire = false; fire_duration = 0; } @@ -91,7 +91,7 @@ void Laser::on_module_loaded() } - uint32_t period= THEKERNEL->config->value(laser_module_pwm_period_checksum)->by_default(20)->as_number(); + uint32_t period = THEKERNEL->config->value(laser_module_pwm_period_checksum)->by_default(20)->as_number(); this->pwm_pin->period_us(period); this->pwm_pin->write(this->pwm_inverting ? 1 : 0); this->laser_maximum_power = THEKERNEL->config->value(laser_module_maximum_power_checksum)->by_default(1.0f)->as_number() ; @@ -114,8 +114,8 @@ void Laser::on_module_loaded() this->register_for_event(ON_GET_PUBLIC_DATA); // no point in updating the power more than the PWM frequency, but not faster than 1KHz - ms_per_tick = 1000 / std::min(1000UL, 1000000/period); - THEKERNEL->slow_ticker->attach(std::min(1000UL, 1000000/period), this, &Laser::set_proportional_power); + ms_per_tick = 1000 / std::min(1000UL, 1000000 / period); + THEKERNEL->slow_ticker->attach(std::min(1000UL, 1000000 / period), this, &Laser::set_proportional_power); } void Laser::on_console_line_received( void *argument ) @@ -143,26 +143,26 @@ void Laser::on_console_line_received( void *argument ) float p; fire_duration = 0; // By default unlimited if(power == "status") { - msgp->stream->printf("laser manual state: %s\n", manual_fire ? "on" : "off"); - return; + msgp->stream->printf("laser manual state: %s\n", manual_fire ? "on" : "off"); + return; } if(power == "off" || power == "0") { - p= 0; + p = 0; msgp->stream->printf("turning laser off and returning to auto mode\n"); - }else{ - p= strtof(power.c_str(), NULL); - p= confine(p, 0.0F, 100.0F); + } else { + p = strtof(power.c_str(), NULL); + p = confine(p, 0.0F, 100.0F); string duration = shift_parameter(possible_command); if(!duration.empty()) { - fire_duration=atoi(duration.c_str()); + fire_duration = atoi(duration.c_str()); // Avoid negative values, its just incorrect if (fire_duration < ms_per_tick) { - msgp->stream->printf("WARNING: Minimal duration is %ld ms, not firing\n", ms_per_tick); - return; + msgp->stream->printf("WARNING: Minimal duration is %ld ms, not firing\n", ms_per_tick); + return; } // rounding to minimal value if (fire_duration % ms_per_tick != 0) { - fire_duration = (fire_duration / ms_per_tick) * ms_per_tick; + fire_duration = (fire_duration / ms_per_tick) * ms_per_tick; } msgp->stream->printf("WARNING: Firing laser at %1.2f%% power, for %ld ms, use fire off to stop test fire earlier\n", p, fire_duration); } else { @@ -170,8 +170,8 @@ void Laser::on_console_line_received( void *argument ) } } - p= p/100.0F; - manual_fire= set_laser_power(p); + p = p / 100.0F; + manual_fire = set_laser_power(p); } } @@ -194,7 +194,7 @@ void Laser::on_gcode_received(void *argument) if (gcode->has_m) { if (gcode->m == 221) { // M221 S100 change laser power by percentage S if(gcode->has_letter('S')) { - this->scale= gcode->get_value('S') / 100.0F; + this->scale = gcode->get_value('S') / 100.0F; } else { gcode->stream->printf("Laser power scale at %6.2f %%\n", this->scale * 100.0F); @@ -207,19 +207,19 @@ void Laser::on_gcode_received(void *argument) float Laser::current_speed_ratio(const Block *block) const { // find the primary moving actuator (the one with the most steps) - size_t pm= 0; - uint32_t max_steps= 0; + size_t pm = 0; + uint32_t max_steps = 0; for (size_t i = 0; i < THEROBOT->get_number_registered_motors(); i++) { // find the motor with the most steps if(block->steps[i] > max_steps) { - max_steps= block->steps[i]; - pm= i; + max_steps = block->steps[i]; + pm = i; } } // figure out the ratio of its speed, from 0 to 1 based on where it is on the trapezoid, // this is based on the fraction it is of the requested rate (nominal rate) - float ratio= block->get_trapezoid_rate(pm) / block->nominal_rate; + float ratio = block->get_trapezoid_rate(pm) / block->nominal_rate; return ratio; } @@ -232,7 +232,7 @@ bool Laser::get_laser_power(float& power) const // Note to avoid a race condition where the block is being cleared we check the is_ready flag which gets cleared first, // as this is an interrupt if that flag is not clear then it cannot be cleared while this is running and the block will still be valid (albeit it may have finished) if(block != nullptr && block->is_ready && block->is_g123) { - float requested_power = ((float)block->s_value/(1<<11)) / this->laser_maximum_s_value; // s_value is 1.11 Fixed point + float requested_power = ((float)block->s_value / (1 << 11)) / this->laser_maximum_s_value; // s_value is 1.11 Fixed point float ratio = current_speed_ratio(block); power = requested_power * ratio * scale; @@ -246,17 +246,17 @@ bool Laser::get_laser_power(float& power) const uint32_t Laser::set_proportional_power(uint32_t dummy) { if(manual_fire) { - // If we have fire duration set - if (fire_duration) { - // Decrease it each ms - fire_duration -= ms_per_tick; - // And if it turned 0, disable laser and manual fire mode - if (fire_duration <= 0) { - set_laser_power(0); - manual_fire = false; + // If we have fire duration set + if (fire_duration) { + // Decrease it each ms + fire_duration -= ms_per_tick; + // And if it turned 0, disable laser and manual fire mode + if (fire_duration <= 0) { + set_laser_power(0); + manual_fire = false; + } } - } - return 0; + return 0; } float power; @@ -275,14 +275,14 @@ uint32_t Laser::set_proportional_power(uint32_t dummy) bool Laser::set_laser_power(float power) { // Ensure power is >=0 and <= 1 - power= confine(power, 0.0F, 1.0F); + power = confine(power, 0.0F, 1.0F); if(power > 0.00001F) { this->pwm_pin->write(this->pwm_inverting ? 1 - power : power); if(!laser_on && this->ttl_used) this->ttl_pin->set(true); laser_on = true; - }else{ + } else { this->pwm_pin->write(this->pwm_inverting ? 1 : 0); if (this->ttl_used) this->ttl_pin->set(false); laser_on = false; @@ -295,12 +295,12 @@ void Laser::on_halt(void *argument) { if(argument == nullptr) { set_laser_power(0); - manual_fire= false; + manual_fire = false; } } float Laser::get_current_power() const { - float p= pwm_pin->read(); + float p = pwm_pin->read(); return (this->pwm_inverting ? 1 - p : p) * 100; }