1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-31 10:01:48 +02:00

Fixed a few more implicit casts, removed a few unused variables

This commit is contained in:
Stefan de Bruijn
2021-07-03 23:00:44 +02:00
parent 9a9f9db18c
commit 412cff88f3
20 changed files with 335 additions and 925 deletions

View File

@@ -163,7 +163,7 @@ const int TOOL_LENGTH_OFFSET_AXIS = Z_AXIS; // Default z-axis. Valid values are
// limits or angle between neighboring block line move directions. This is useful for machines that can't // limits or angle between neighboring block line move directions. This is useful for machines that can't
// tolerate the tool dwelling for a split second, i.e. 3d printers or laser cutters. If used, this value // tolerate the tool dwelling for a split second, i.e. 3d printers or laser cutters. If used, this value
// should not be much greater than zero or to the minimum value necessary for the machine to work. // should not be much greater than zero or to the minimum value necessary for the machine to work.
const double MINIMUM_JUNCTION_SPEED = 0.0; // (mm/min) const float MINIMUM_JUNCTION_SPEED = 0.0f; // (mm/min)
// Sets the minimum feed rate the planner will allow. Any value below it will be set to this minimum // Sets the minimum feed rate the planner will allow. Any value below it will be set to this minimum
// value. This also ensures that a planned motion always completes and accounts for any floating-point // value. This also ensures that a planned motion always completes and accounts for any floating-point

View File

@@ -82,7 +82,7 @@ namespace Configuration {
void JsonGenerator::item(const char* name, int& value, int32_t minValue, int32_t maxValue) { void JsonGenerator::item(const char* name, int& value, int32_t minValue, int32_t maxValue) {
enter(name); enter(name);
char buf[32]; char buf[32];
_itoa(value, buf, 10); itoa(value, buf, 10);
_encoder.begin_webui(name, _currentPath, "I", buf, minValue, maxValue); _encoder.begin_webui(name, _currentPath, "I", buf, minValue, maxValue);
_encoder.end_object(); _encoder.end_object();
leave(); leave();

View File

@@ -171,7 +171,7 @@ float limit_acceleration_by_axis_maximum(float* unit_vec) {
for (idx = 0; idx < n_axis; idx++) { for (idx = 0; idx < n_axis; idx++) {
auto axisSetting = config->_axes->_axis[idx]; auto axisSetting = config->_axes->_axis[idx];
if (unit_vec[idx] != 0) { // Avoid divide by zero. if (unit_vec[idx] != 0) { // Avoid divide by zero.
limit_value = MIN(limit_value, fabs(axisSetting->_acceleration / unit_vec[idx])); limit_value = MIN(limit_value, float(fabs(axisSetting->_acceleration / unit_vec[idx])));
} }
} }
// The acceleration setting is stored and displayed in units of mm/sec^2, // The acceleration setting is stored and displayed in units of mm/sec^2,
@@ -188,7 +188,7 @@ float limit_rate_by_axis_maximum(float* unit_vec) {
for (idx = 0; idx < n_axis; idx++) { for (idx = 0; idx < n_axis; idx++) {
auto axisSetting = config->_axes->_axis[idx]; auto axisSetting = config->_axes->_axis[idx];
if (unit_vec[idx] != 0) { // Avoid divide by zero. if (unit_vec[idx] != 0) { // Avoid divide by zero.
limit_value = MIN(limit_value, fabs(axisSetting->_maxRate / unit_vec[idx])); limit_value = MIN(limit_value, float(fabs(axisSetting->_maxRate / unit_vec[idx])));
} }
} }
return limit_value; return limit_value;

View File

@@ -61,7 +61,7 @@ static inline int toMotor2(int axis) {
// Conversions // Conversions
const float MM_PER_INCH = (25.40f); const float MM_PER_INCH = (25.40f);
const double INCH_PER_MM = (0.0393701); const float INCH_PER_MM = (0.0393701f);
// Useful macros // Useful macros
#define clear_vector(a) memset(a, 0, sizeof(a)) #define clear_vector(a) memset(a, 0, sizeof(a))

View File

@@ -389,7 +389,7 @@ Error listAlarms(const char* value, WebUI::AuthenticationLevel auth_level, WebUI
} }
if (value) { if (value) {
char* endptr = NULL; char* endptr = NULL;
uint8_t alarmNumber = strtol(value, &endptr, 10); uint8_t alarmNumber = uint8_t(strtol(value, &endptr, 10));
if (*endptr) { if (*endptr) {
grbl_sendf(out->client(), "Malformed alarm number: %s\r\n", value); grbl_sendf(out->client(), "Malformed alarm number: %s\r\n", value);
return Error::InvalidValue; return Error::InvalidValue;
@@ -418,7 +418,7 @@ const char* errorString(Error errorNumber) {
Error listErrors(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) { Error listErrors(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) {
if (value) { if (value) {
char* endptr = NULL; char* endptr = NULL;
uint8_t errorNumber = strtol(value, &endptr, 10); uint8_t errorNumber = uint8_t(strtol(value, &endptr, 10));
if (*endptr) { if (*endptr) {
grbl_sendf(out->client(), "Malformed error number: %s\r\n", value); grbl_sendf(out->client(), "Malformed error number: %s\r\n", value);
return Error::InvalidValue; return Error::InvalidValue;

View File

@@ -201,7 +201,7 @@ static void report_util_axis_values(float* axis_value, char* rpt) {
const char* format = "%4.3f"; // Default - report mm to 3 decimal places const char* format = "%4.3f"; // Default - report mm to 3 decimal places
rpt[0] = '\0'; rpt[0] = '\0';
if (config->_reportInches) { if (config->_reportInches) {
unit_conv = 1.0 / MM_PER_INCH; unit_conv = 1.0f / MM_PER_INCH;
format = "%4.4f"; // Report inches to 4 decimal places format = "%4.4f"; // Report inches to 4 decimal places
} }
auto n_axis = config->_axes->_numberAxis; auto n_axis = config->_axes->_numberAxis;
@@ -218,11 +218,10 @@ static void report_util_axis_values(float* axis_value, char* rpt) {
static String report_util_axis_values(const float* axis_value) { static String report_util_axis_values(const float* axis_value) {
String rpt = ""; String rpt = "";
uint8_t idx; uint8_t idx;
char axisVal[coordStringLen];
float unit_conv = 1.0; // unit conversion multiplier..default is mm float unit_conv = 1.0; // unit conversion multiplier..default is mm
int decimals = 3; // Default - report mm to 3 decimal places int decimals = 3; // Default - report mm to 3 decimal places
if (config->_reportInches) { if (config->_reportInches) {
unit_conv = 1.0 / MM_PER_INCH; unit_conv = 1.0f / MM_PER_INCH;
decimals = 4; // Report inches to 4 decimal places decimals = 4; // Report inches to 4 decimal places
} }
auto n_axis = config->_axes->_numberAxis; auto n_axis = config->_axes->_numberAxis;

View File

@@ -28,7 +28,8 @@
#include <SD.h> #include <SD.h>
#include <SPI.h> #include <SPI.h>
struct SDCard::FileWrap { class SDCard::FileWrap {
public:
FileWrap() : _file(nullptr) {} FileWrap() : _file(nullptr) {}
File _file; File _file;
}; };

View File

@@ -235,7 +235,7 @@ void StringSetting::setDefault() {
} }
Error StringSetting::setStringValue(char* s) { Error StringSetting::setStringValue(char* s) {
if (_minLength && _maxLength && (strlen(s) < _minLength || strlen(s) > _maxLength)) { if (_minLength && _maxLength && (strlen(s) < size_t(_minLength) || strlen(s) > size_t(_maxLength))) {
return Error::BadNumberFormat; return Error::BadNumberFormat;
} }
Error err = check(s); Error err = check(s);
@@ -330,7 +330,7 @@ Error EnumSetting::setStringValue(char* s) {
return Error::BadNumberFormat; return Error::BadNumberFormat;
} }
char* endptr; char* endptr;
uint8_t num = strtol(s, &endptr, 10); uint8_t num = uint8_t(strtol(s, &endptr, 10));
// Disallow non-numeric characters in string // Disallow non-numeric characters in string
if (*endptr) { if (*endptr) {
return Error::BadNumberFormat; return Error::BadNumberFormat;

View File

@@ -153,7 +153,7 @@ namespace Spindles {
} }
// increase the precision (bits) until it exceeds allow by frequency the max or is 16 // increase the precision (bits) until it exceeds allow by frequency the max or is 16
while ((1 << precision) < (uint32_t)(80000000 / freq) && precision <= 16) { while ((1u << precision) < uint32_t(80000000 / freq) && precision <= 16) {
precision++; precision++;
} }

View File

@@ -79,18 +79,18 @@ namespace Spindles {
offset = _speeds[i].percent / 100.0 * max_dev_speed; offset = _speeds[i].percent / 100.0 * max_dev_speed;
_speeds[i].offset = offset; _speeds[i].offset = offset;
float deltaPercent = (_speeds[i + 1].percent - _speeds[i].percent) / 100.0; float deltaPercent = (_speeds[i + 1].percent - _speeds[i].percent) / 100.0f;
float deltaRPM = _speeds[i + 1].speed - _speeds[i].speed; float deltaRPM = _speeds[i + 1].speed - _speeds[i].speed;
float scale = deltaRPM == 0.0 ? 0.0 : (deltaPercent / deltaRPM); float scale = deltaRPM == 0.0f ? 0.0f : (deltaPercent / deltaRPM);
scale *= max_dev_speed; scale *= max_dev_speed;
// float scale = deltaPercent * max_dev_speed; // float scale = deltaPercent * max_dev_speed;
scaler = scale * 65536; scaler = uint32_t(scale * 65536);
_speeds[i].scale = scaler; _speeds[i].scale = scaler;
} }
// The final scaler is 0, with the offset equal to the ending offset // The final scaler is 0, with the offset equal to the ending offset
offset = _speeds[nsegments].percent / 100.0 * max_dev_speed; offset = SpindleSpeed(_speeds[nsegments].percent / 100.0f * float(max_dev_speed));
_speeds[i].offset = offset; _speeds[i].offset = offset;
scaler = 0; scaler = 0;
_speeds[i].scale = scaler; _speeds[i].scale = scaler;
@@ -99,14 +99,14 @@ namespace Spindles {
void Spindle::afterParse() {} void Spindle::afterParse() {}
void Spindle::shelfSpeeds(SpindleSpeed min, SpindleSpeed max) { void Spindle::shelfSpeeds(SpindleSpeed min, SpindleSpeed max) {
float minPercent = 100.0 * min / max; float minPercent = 100.0f * min / max;
_speeds.clear(); _speeds.clear();
_speeds.push_back({ 0, 0.0 }); _speeds.push_back({ 0, 0.0f });
_speeds.push_back({ 0, minPercent }); _speeds.push_back({ 0, minPercent });
if (min) { if (min) {
_speeds.push_back({ min, minPercent }); _speeds.push_back({ min, minPercent });
} }
_speeds.push_back({ max, 100.0 }); _speeds.push_back({ max, 100.0f });
} }
uint32_t Spindle::mapSpeed(SpindleSpeed speed) { uint32_t Spindle::mapSpeed(SpindleSpeed speed) {

View File

@@ -51,13 +51,13 @@ namespace Spindles {
QueueHandle_t VFD::vfd_cmd_queue = nullptr; QueueHandle_t VFD::vfd_cmd_queue = nullptr;
TaskHandle_t VFD::vfd_cmdTaskHandle = nullptr; TaskHandle_t VFD::vfd_cmdTaskHandle = nullptr;
void VFD::reportParsingErrors(ModbusCommand cmd, uint8_t* rx_message, uint16_t read_length) { void VFD::reportParsingErrors(ModbusCommand cmd, uint8_t* rx_message, size_t read_length) {
#ifdef DEBUG_VFD #ifdef DEBUG_VFD
report_hex_msg(cmd.msg, "RS485 Tx: ", cmd.tx_length); report_hex_msg(cmd.msg, "RS485 Tx: ", cmd.tx_length);
report_hex_msg(rx_message, "RS485 Rx: ", read_length); report_hex_msg(rx_message, "RS485 Rx: ", read_length);
#endif #endif
} }
void VFD::reportCmdErrors(ModbusCommand cmd, uint8_t* rx_message, uint16_t read_length, uint8_t id) { void VFD::reportCmdErrors(ModbusCommand cmd, uint8_t* rx_message, size_t read_length, uint8_t id) {
#ifdef DEBUG_VFD #ifdef DEBUG_VFD
report_hex_msg(cmd.msg, "RS485 Tx: ", cmd.tx_length); report_hex_msg(cmd.msg, "RS485 Tx: ", cmd.tx_length);
report_hex_msg(rx_message, "RS485 Rx: ", read_length); report_hex_msg(rx_message, "RS485 Rx: ", read_length);
@@ -189,8 +189,8 @@ namespace Spindles {
uart.flushTxTimed(response_ticks); uart.flushTxTimed(response_ticks);
// Read the response // Read the response
uint16_t read_length = 0; size_t read_length = 0;
uint16_t current_read = uart.readBytes(rx_message, next_cmd.rx_length, response_ticks); size_t current_read = uart.readBytes(rx_message, next_cmd.rx_length, response_ticks);
read_length += current_read; read_length += current_read;
// Apparently some Huanyang report modbus errors in the correct way, and the rest not. Sigh. // Apparently some Huanyang report modbus errors in the correct way, and the rest not. Sigh.
@@ -204,9 +204,6 @@ namespace Spindles {
current_read = uart.readBytes(rx_message + read_length, next_cmd.rx_length - read_length, response_ticks); current_read = uart.readBytes(rx_message + read_length, next_cmd.rx_length - read_length, response_ticks);
read_length += current_read; read_length += current_read;
} }
if (current_read < 0) {
read_length = 0;
}
// Generate crc16 for the response: // Generate crc16 for the response:
auto crc16response = ModRTU_CRC(rx_message, next_cmd.rx_length - 2); auto crc16response = ModRTU_CRC(rx_message, next_cmd.rx_length - 2);

View File

@@ -63,8 +63,8 @@ namespace Spindles {
bool prepareSetModeCommand(SpindleState mode, ModbusCommand& data); bool prepareSetModeCommand(SpindleState mode, ModbusCommand& data);
bool prepareSetSpeedCommand(uint32_t speed, ModbusCommand& data); bool prepareSetSpeedCommand(uint32_t speed, ModbusCommand& data);
static void reportParsingErrors(ModbusCommand cmd, uint8_t* rx_message, uint16_t read_length); static void reportParsingErrors(ModbusCommand cmd, uint8_t* rx_message, size_t read_length);
static void reportCmdErrors(ModbusCommand cmd, uint8_t* rx_message, uint16_t read_length, uint8_t id); static void reportCmdErrors(ModbusCommand cmd, uint8_t* rx_message, size_t read_length, uint8_t id);
protected: protected:
// Commands: // Commands:

View File

@@ -564,7 +564,7 @@ void st_prep_buffer() {
pl_block->entry_speed_sqr = prep.exit_speed * prep.exit_speed; pl_block->entry_speed_sqr = prep.exit_speed * prep.exit_speed;
prep.recalculate_flag.decelOverride = 0; prep.recalculate_flag.decelOverride = 0;
} else { } else {
prep.current_speed = sqrt(pl_block->entry_speed_sqr); prep.current_speed = float(sqrt(pl_block->entry_speed_sqr));
} }
// prep.inv_rate is only used if is_pwm_rate_adjusted is true // prep.inv_rate is only used if is_pwm_rate_adjusted is true
@@ -573,7 +573,7 @@ void st_prep_buffer() {
if (config->_laserMode) { if (config->_laserMode) {
if (pl_block->spindle == SpindleState::Ccw) { if (pl_block->spindle == SpindleState::Ccw) {
// Pre-compute inverse programmed rate to speed up PWM updating per step segment. // Pre-compute inverse programmed rate to speed up PWM updating per step segment.
prep.inv_rate = 1.0 / pl_block->programmed_rate; prep.inv_rate = 1.0f / pl_block->programmed_rate;
st_prep_block->is_pwm_rate_adjusted = true; st_prep_block->is_pwm_rate_adjusted = true;
} }
} }
@@ -585,7 +585,7 @@ void st_prep_buffer() {
hold, override the planner velocities and decelerate to the target exit speed. hold, override the planner velocities and decelerate to the target exit speed.
*/ */
prep.mm_complete = 0.0; // Default velocity profile complete at 0.0mm from end of block. prep.mm_complete = 0.0; // Default velocity profile complete at 0.0mm from end of block.
float inv_2_accel = 0.5 / pl_block->acceleration; float inv_2_accel = 0.5f / pl_block->acceleration;
if (sys.step_control.executeHold) { // [Forced Deceleration to Zero Velocity] if (sys.step_control.executeHold) { // [Forced Deceleration to Zero Velocity]
// Compute velocity profile parameters for a feed hold in-progress. This profile overrides // Compute velocity profile parameters for a feed hold in-progress. This profile overrides
// the planner block profile, enforcing a deceleration to zero speed. // the planner block profile, enforcing a deceleration to zero speed.
@@ -594,7 +594,7 @@ void st_prep_buffer() {
float decel_dist = pl_block->millimeters - inv_2_accel * pl_block->entry_speed_sqr; float decel_dist = pl_block->millimeters - inv_2_accel * pl_block->entry_speed_sqr;
if (decel_dist < 0.0) { if (decel_dist < 0.0) {
// Deceleration through entire planner block. End of feed hold is not in this block. // Deceleration through entire planner block. End of feed hold is not in this block.
prep.exit_speed = sqrt(pl_block->entry_speed_sqr - 2 * pl_block->acceleration * pl_block->millimeters); prep.exit_speed = float(sqrt(pl_block->entry_speed_sqr - 2 * pl_block->acceleration * pl_block->millimeters));
} else { } else {
prep.mm_complete = decel_dist; // End of feed hold. prep.mm_complete = decel_dist; // End of feed hold.
prep.exit_speed = 0.0; prep.exit_speed = 0.0;
@@ -609,12 +609,12 @@ void st_prep_buffer() {
prep.exit_speed = exit_speed_sqr = 0.0; // Enforce stop at end of system motion. prep.exit_speed = exit_speed_sqr = 0.0; // Enforce stop at end of system motion.
} else { } else {
exit_speed_sqr = plan_get_exec_block_exit_speed_sqr(); exit_speed_sqr = plan_get_exec_block_exit_speed_sqr();
prep.exit_speed = sqrt(exit_speed_sqr); prep.exit_speed = float(sqrt(exit_speed_sqr));
} }
nominal_speed = plan_compute_profile_nominal_speed(pl_block); nominal_speed = plan_compute_profile_nominal_speed(pl_block);
float nominal_speed_sqr = nominal_speed * nominal_speed; float nominal_speed_sqr = nominal_speed * nominal_speed;
float intersect_distance = 0.5 * (pl_block->millimeters + inv_2_accel * (pl_block->entry_speed_sqr - exit_speed_sqr)); float intersect_distance = 0.5f * (pl_block->millimeters + inv_2_accel * (pl_block->entry_speed_sqr - exit_speed_sqr));
if (pl_block->entry_speed_sqr > nominal_speed_sqr) { // Only occurs during override reductions. if (pl_block->entry_speed_sqr > nominal_speed_sqr) { // Only occurs during override reductions.
prep.accelerate_until = pl_block->millimeters - inv_2_accel * (pl_block->entry_speed_sqr - nominal_speed_sqr); prep.accelerate_until = pl_block->millimeters - inv_2_accel * (pl_block->entry_speed_sqr - nominal_speed_sqr);
if (prep.accelerate_until <= 0.0) { // Deceleration-only. if (prep.accelerate_until <= 0.0) { // Deceleration-only.
@@ -622,7 +622,7 @@ void st_prep_buffer() {
// prep.decelerate_after = pl_block->millimeters; // prep.decelerate_after = pl_block->millimeters;
// prep.maximum_speed = prep.current_speed; // prep.maximum_speed = prep.current_speed;
// Compute override block exit speed since it doesn't match the planner exit speed. // Compute override block exit speed since it doesn't match the planner exit speed.
prep.exit_speed = sqrt(pl_block->entry_speed_sqr - 2 * pl_block->acceleration * pl_block->millimeters); prep.exit_speed = float(sqrt(pl_block->entry_speed_sqr - 2 * pl_block->acceleration * pl_block->millimeters));
prep.recalculate_flag.decelOverride = 1; // Flag to load next block as deceleration override. prep.recalculate_flag.decelOverride = 1; // Flag to load next block as deceleration override.
// TODO: Determine correct handling of parameters in deceleration-only. // TODO: Determine correct handling of parameters in deceleration-only.
// Can be tricky since entry speed will be current speed, as in feed holds. // Can be tricky since entry speed will be current speed, as in feed holds.
@@ -649,7 +649,7 @@ void st_prep_buffer() {
} else { // Triangle type } else { // Triangle type
prep.accelerate_until = intersect_distance; prep.accelerate_until = intersect_distance;
prep.decelerate_after = intersect_distance; prep.decelerate_after = intersect_distance;
prep.maximum_speed = sqrt(2.0 * pl_block->acceleration * intersect_distance + exit_speed_sqr); prep.maximum_speed = float(sqrt(2.0f * pl_block->acceleration * intersect_distance + exit_speed_sqr));
} }
} else { // Deceleration-only type } else { // Deceleration-only type
prep.ramp_type = RAMP_DECEL; prep.ramp_type = RAMP_DECEL;
@@ -702,12 +702,12 @@ void st_prep_buffer() {
switch (prep.ramp_type) { switch (prep.ramp_type) {
case RAMP_DECEL_OVERRIDE: case RAMP_DECEL_OVERRIDE:
speed_var = pl_block->acceleration * time_var; speed_var = pl_block->acceleration * time_var;
mm_var = time_var * (prep.current_speed - 0.5 * speed_var); mm_var = time_var * (prep.current_speed - 0.5f * speed_var);
mm_remaining -= mm_var; mm_remaining -= mm_var;
if ((mm_remaining < prep.accelerate_until) || (mm_var <= 0)) { if ((mm_remaining < prep.accelerate_until) || (mm_var <= 0)) {
// Cruise or cruise-deceleration types only for deceleration override. // Cruise or cruise-deceleration types only for deceleration override.
mm_remaining = prep.accelerate_until; // NOTE: 0.0 at EOB mm_remaining = prep.accelerate_until; // NOTE: 0.0 at EOB
time_var = 2.0 * (pl_block->millimeters - mm_remaining) / (prep.current_speed + prep.maximum_speed); time_var = 2.0f * (pl_block->millimeters - mm_remaining) / (prep.current_speed + prep.maximum_speed);
prep.ramp_type = RAMP_CRUISE; prep.ramp_type = RAMP_CRUISE;
prep.current_speed = prep.maximum_speed; prep.current_speed = prep.maximum_speed;
} else { // Mid-deceleration override ramp. } else { // Mid-deceleration override ramp.
@@ -717,11 +717,11 @@ void st_prep_buffer() {
case RAMP_ACCEL: case RAMP_ACCEL:
// NOTE: Acceleration ramp only computes during first do-while loop. // NOTE: Acceleration ramp only computes during first do-while loop.
speed_var = pl_block->acceleration * time_var; speed_var = pl_block->acceleration * time_var;
mm_remaining -= time_var * (prep.current_speed + 0.5 * speed_var); mm_remaining -= time_var * (prep.current_speed + 0.5f * speed_var);
if (mm_remaining < prep.accelerate_until) { // End of acceleration ramp. if (mm_remaining < prep.accelerate_until) { // End of acceleration ramp.
// Acceleration-cruise, acceleration-deceleration ramp junction, or end of block. // Acceleration-cruise, acceleration-deceleration ramp junction, or end of block.
mm_remaining = prep.accelerate_until; // NOTE: 0.0 at EOB mm_remaining = prep.accelerate_until; // NOTE: 0.0 at EOB
time_var = 2.0 * (pl_block->millimeters - mm_remaining) / (prep.current_speed + prep.maximum_speed); time_var = 2.0f * (pl_block->millimeters - mm_remaining) / (prep.current_speed + prep.maximum_speed);
if (mm_remaining == prep.decelerate_after) { if (mm_remaining == prep.decelerate_after) {
prep.ramp_type = RAMP_DECEL; prep.ramp_type = RAMP_DECEL;
} else { } else {
@@ -751,15 +751,15 @@ void st_prep_buffer() {
speed_var = pl_block->acceleration * time_var; // Used as delta speed (mm/min) speed_var = pl_block->acceleration * time_var; // Used as delta speed (mm/min)
if (prep.current_speed > speed_var) { // Check if at or below zero speed. if (prep.current_speed > speed_var) { // Check if at or below zero speed.
// Compute distance from end of segment to end of block. // Compute distance from end of segment to end of block.
mm_var = mm_remaining - time_var * (prep.current_speed - 0.5 * speed_var); // (mm) mm_var = mm_remaining - time_var * (prep.current_speed - 0.5f * speed_var); // (mm)
if (mm_var > prep.mm_complete) { // Typical case. In deceleration ramp. if (mm_var > prep.mm_complete) { // Typical case. In deceleration ramp.
mm_remaining = mm_var; mm_remaining = mm_var;
prep.current_speed -= speed_var; prep.current_speed -= speed_var;
break; // Segment complete. Exit switch-case statement. Continue do-while loop. break; // Segment complete. Exit switch-case statement. Continue do-while loop.
} }
} }
// Otherwise, at end of block or end of forced-deceleration. // Otherwise, at end of block or end of forced-deceleration.
time_var = 2.0 * (mm_remaining - prep.mm_complete) / (prep.current_speed + prep.exit_speed); time_var = 2.0f * (mm_remaining - prep.mm_complete) / (prep.current_speed + prep.exit_speed);
mm_remaining = prep.mm_complete; mm_remaining = prep.mm_complete;
prep.current_speed = prep.exit_speed; prep.current_speed = prep.exit_speed;
} }
@@ -802,7 +802,6 @@ void st_prep_buffer() {
sys.step_control.updateSpindleSpeed = false; sys.step_control.updateSpindleSpeed = false;
} }
prep_segment->spindle_speed = prep.current_spindle_speed; prep_segment->spindle_speed = prep.current_spindle_speed;
bool enabled;
prep_segment->spindle_dev_speed = spindle->mapSpeed(prep.current_spindle_speed); // Reload segment PWM value prep_segment->spindle_dev_speed = spindle->mapSpeed(prep.current_spindle_speed); // Reload segment PWM value
/* ----------------------------------------------------------------------------------- /* -----------------------------------------------------------------------------------
@@ -815,10 +814,10 @@ void st_prep_buffer() {
Fortunately, this scenario is highly unlikely and unrealistic in CNC machines Fortunately, this scenario is highly unlikely and unrealistic in CNC machines
supported by Grbl (i.e. exceeding 10 meters axis travel at 200 step/mm). supported by Grbl (i.e. exceeding 10 meters axis travel at 200 step/mm).
*/ */
float step_dist_remaining = prep.step_per_mm * mm_remaining; // Convert mm_remaining to steps float step_dist_remaining = prep.step_per_mm * mm_remaining; // Convert mm_remaining to steps
float n_steps_remaining = ceil(step_dist_remaining); // Round-up current steps remaining float n_steps_remaining = float(ceil(step_dist_remaining)); // Round-up current steps remaining
float last_n_steps_remaining = ceil(prep.steps_remaining); // Round-up last steps remaining float last_n_steps_remaining = float(ceil(prep.steps_remaining)); // Round-up last steps remaining
prep_segment->n_step = last_n_steps_remaining - n_steps_remaining; // Compute number of steps to execute. prep_segment->n_step = uint16_t(last_n_steps_remaining - n_steps_remaining); // Compute number of steps to execute.
// Bail if we are at the end of a feed hold and don't have a step to execute. // Bail if we are at the end of a feed hold and don't have a step to execute.
if (prep_segment->n_step == 0) { if (prep_segment->n_step == 0) {
@@ -849,7 +848,7 @@ void st_prep_buffer() {
// Compute CPU cycles per step for the prepped segment. // Compute CPU cycles per step for the prepped segment.
// fStepperTimer is in units of timerTicks/sec, so the dimensional analysis is // fStepperTimer is in units of timerTicks/sec, so the dimensional analysis is
// timerTicks/sec * 60 sec/minute * minutes = timerTicks // timerTicks/sec * 60 sec/minute * minutes = timerTicks
uint32_t timerTicks = ceil((fStepperTimer * 60) * inv_rate); // (timerTicks/step) uint32_t timerTicks = uint32_t(ceil((fStepperTimer * 60) * inv_rate)); // (timerTicks/step)
int level; int level;
// Compute step timing and multi-axis smoothing level. // Compute step timing and multi-axis smoothing level.

View File

@@ -9,12 +9,12 @@
const int SEGMENT_BUFFER_SIZE = 6; const int SEGMENT_BUFFER_SIZE = 6;
// Some useful constants. // Some useful constants.
const double DT_SEGMENT = (1.0 / (ACCELERATION_TICKS_PER_SECOND * 60.0)); // min/segment const float DT_SEGMENT = (1.0f / (float(ACCELERATION_TICKS_PER_SECOND) * 60.0f)); // min/segment
const double REQ_MM_INCREMENT_SCALAR = 1.25; const float REQ_MM_INCREMENT_SCALAR = 1.25f;
const int RAMP_ACCEL = 0; const int RAMP_ACCEL = 0;
const int RAMP_CRUISE = 1; const int RAMP_CRUISE = 1;
const int RAMP_DECEL = 2; const int RAMP_DECEL = 2;
const int RAMP_DECEL_OVERRIDE = 3; const int RAMP_DECEL_OVERRIDE = 3;
struct PrepFlag { struct PrepFlag {
uint8_t recalculate : 1; uint8_t recalculate : 1;

View File

@@ -140,7 +140,7 @@ void sys_analog_all_off() {
// io_num is the virtual analog pin# // io_num is the virtual analog pin#
bool sys_set_analog(uint8_t io_num, float percent) { bool sys_set_analog(uint8_t io_num, float percent) {
auto analog = myAnalogOutputs[io_num]; auto analog = myAnalogOutputs[io_num];
uint32_t numerator = percent / 100.0 * analog->denominator(); uint32_t numerator = uint32_t(percent / 100.0f * analog->denominator());
return analog->set_level(numerator); return analog->set_level(numerator);
} }
@@ -173,7 +173,7 @@ uint8_t sys_calc_pwm_precision(uint32_t freq) {
uint8_t precision = 0; uint8_t precision = 0;
// increase the precision (bits) until it exceeds allow by frequency the max or is 16 // increase the precision (bits) until it exceeds allow by frequency the max or is 16
while ((1 << precision) < (uint32_t)(80000000 / freq) && precision <= 16) { // TODO is there a named value for the 80MHz? while ((1u << precision) < uint32_t(80000000 / freq) && precision <= 16) { // TODO is there a named value for the 80MHz?
precision++; precision++;
} }

View File

@@ -59,7 +59,7 @@ namespace UserOutput {
// increase the precision (bits) until it exceeds allow by frequency the max or is 16 // increase the precision (bits) until it exceeds allow by frequency the max or is 16
_resolution_bits = 0; _resolution_bits = 0;
while ((1 << _resolution_bits) < (apb_frequency / _pwm_frequency) && _resolution_bits <= 16) { while ((1u << _resolution_bits) < (apb_frequency / _pwm_frequency) && _resolution_bits <= 16) {
++_resolution_bits; ++_resolution_bits;
} }
// _resolution_bits is now just barely too high, so drop it down one // _resolution_bits is now just barely too high, so drop it down one

View File

@@ -35,7 +35,7 @@ namespace UserOutput {
void config_message(); void config_message();
uint8_t _number = UNDEFINED_OUTPUT; uint8_t _number = UNDEFINED_OUTPUT;
Pin& _pin; Pin& _pin;
}; };
class AnalogOutput { class AnalogOutput {
@@ -49,7 +49,7 @@ namespace UserOutput {
void config_message(); void config_message();
uint8_t _number = UNDEFINED_OUTPUT; uint8_t _number = UNDEFINED_OUTPUT;
Pin& _pin; Pin& _pin;
uint8_t _pwm_channel = -1; // -1 means invalid or not setup uint8_t _pwm_channel = -1; // -1 means invalid or not setup
float _pwm_frequency; float _pwm_frequency;
uint8_t _resolution_bits; uint8_t _resolution_bits;

View File

@@ -58,7 +58,7 @@ namespace WebUI {
} }
//no space allowed //no space allowed
for (int i = 0; i < strlen(password); i++) { for (size_t i = 0; i < strlen(password); i++) {
c = password[i]; c = password[i];
if (c == ' ') { if (c == ' ') {
return false; return false;

View File

@@ -324,6 +324,7 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)X86TestSupport;$(MSBuildThisFileDirectory)GRBL_Esp32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)X86TestSupport;$(MSBuildThisFileDirectory)GRBL_Esp32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>-D_CRT_SECURE_NO_WARNINGS %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@@ -341,6 +342,7 @@
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)X86TestSupport;$(MSBuildThisFileDirectory)GRBL_Esp32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)X86TestSupport;$(MSBuildThisFileDirectory)GRBL_Esp32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalOptions>-D_CRT_SECURE_NO_WARNINGS %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@@ -357,6 +359,7 @@
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)X86TestSupport;$(MSBuildThisFileDirectory)GRBL_Esp32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)X86TestSupport;$(MSBuildThisFileDirectory)GRBL_Esp32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalOptions>-D_CRT_SECURE_NO_WARNINGS %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@@ -375,6 +378,7 @@
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)X86TestSupport;$(MSBuildThisFileDirectory)GRBL_Esp32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)X86TestSupport;$(MSBuildThisFileDirectory)GRBL_Esp32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<MultiProcessorCompilation>true</MultiProcessorCompilation> <MultiProcessorCompilation>true</MultiProcessorCompilation>
<AdditionalOptions>-D_CRT_SECURE_NO_WARNINGS %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@@ -389,4 +393,4 @@
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.3\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.3\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets'))" /> <Error Condition="!Exists('packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.3\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.3\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets'))" />
</Target> </Target>
</Project> </Project>

File diff suppressed because it is too large Load Diff