From 412cff88f350532cdcb6db36d1a9e00acebf1f12 Mon Sep 17 00:00:00 2001 From: Stefan de Bruijn Date: Sat, 3 Jul 2021 23:00:44 +0200 Subject: [PATCH] Fixed a few more implicit casts, removed a few unused variables --- Grbl_Esp32/src/Config.h | 2 +- .../src/Configuration/JsonGenerator.cpp | 2 +- Grbl_Esp32/src/NutsBolts.cpp | 4 +- Grbl_Esp32/src/NutsBolts.h | 2 +- Grbl_Esp32/src/ProcessSettings.cpp | 4 +- Grbl_Esp32/src/Report.cpp | 5 +- Grbl_Esp32/src/SDCard.cpp | 3 +- Grbl_Esp32/src/Settings.cpp | 4 +- Grbl_Esp32/src/Spindles/PWMSpindle.cpp | 2 +- Grbl_Esp32/src/Spindles/Spindle.cpp | 14 +- Grbl_Esp32/src/Spindles/VFDSpindle.cpp | 11 +- Grbl_Esp32/src/Spindles/VFDSpindle.h | 4 +- Grbl_Esp32/src/Stepper.cpp | 41 +- Grbl_Esp32/src/StepperPrivate.h | 12 +- Grbl_Esp32/src/System.cpp | 4 +- Grbl_Esp32/src/UserOutput.cpp | 2 +- Grbl_Esp32/src/UserOutput.h | 4 +- Grbl_Esp32/src/WebUI/Commands.cpp | 2 +- UnitTests.vcxproj | 6 +- UnitTests.vcxproj.filters | 1132 ++++------------- 20 files changed, 335 insertions(+), 925 deletions(-) diff --git a/Grbl_Esp32/src/Config.h b/Grbl_Esp32/src/Config.h index 595dbca9..dcab48f5 100644 --- a/Grbl_Esp32/src/Config.h +++ b/Grbl_Esp32/src/Config.h @@ -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 // 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. -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 // value. This also ensures that a planned motion always completes and accounts for any floating-point diff --git a/Grbl_Esp32/src/Configuration/JsonGenerator.cpp b/Grbl_Esp32/src/Configuration/JsonGenerator.cpp index edce5852..fbea1d01 100644 --- a/Grbl_Esp32/src/Configuration/JsonGenerator.cpp +++ b/Grbl_Esp32/src/Configuration/JsonGenerator.cpp @@ -82,7 +82,7 @@ namespace Configuration { void JsonGenerator::item(const char* name, int& value, int32_t minValue, int32_t maxValue) { enter(name); char buf[32]; - _itoa(value, buf, 10); + itoa(value, buf, 10); _encoder.begin_webui(name, _currentPath, "I", buf, minValue, maxValue); _encoder.end_object(); leave(); diff --git a/Grbl_Esp32/src/NutsBolts.cpp b/Grbl_Esp32/src/NutsBolts.cpp index bd04848d..097e0447 100644 --- a/Grbl_Esp32/src/NutsBolts.cpp +++ b/Grbl_Esp32/src/NutsBolts.cpp @@ -171,7 +171,7 @@ float limit_acceleration_by_axis_maximum(float* unit_vec) { for (idx = 0; idx < n_axis; idx++) { auto axisSetting = config->_axes->_axis[idx]; 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, @@ -188,7 +188,7 @@ float limit_rate_by_axis_maximum(float* unit_vec) { for (idx = 0; idx < n_axis; idx++) { auto axisSetting = config->_axes->_axis[idx]; 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; diff --git a/Grbl_Esp32/src/NutsBolts.h b/Grbl_Esp32/src/NutsBolts.h index 4008cf1a..9e4a239a 100644 --- a/Grbl_Esp32/src/NutsBolts.h +++ b/Grbl_Esp32/src/NutsBolts.h @@ -61,7 +61,7 @@ static inline int toMotor2(int axis) { // Conversions const float MM_PER_INCH = (25.40f); -const double INCH_PER_MM = (0.0393701); +const float INCH_PER_MM = (0.0393701f); // Useful macros #define clear_vector(a) memset(a, 0, sizeof(a)) diff --git a/Grbl_Esp32/src/ProcessSettings.cpp b/Grbl_Esp32/src/ProcessSettings.cpp index e19d02e3..66b8fedc 100644 --- a/Grbl_Esp32/src/ProcessSettings.cpp +++ b/Grbl_Esp32/src/ProcessSettings.cpp @@ -389,7 +389,7 @@ Error listAlarms(const char* value, WebUI::AuthenticationLevel auth_level, WebUI } if (value) { char* endptr = NULL; - uint8_t alarmNumber = strtol(value, &endptr, 10); + uint8_t alarmNumber = uint8_t(strtol(value, &endptr, 10)); if (*endptr) { grbl_sendf(out->client(), "Malformed alarm number: %s\r\n", value); return Error::InvalidValue; @@ -418,7 +418,7 @@ const char* errorString(Error errorNumber) { Error listErrors(const char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) { if (value) { char* endptr = NULL; - uint8_t errorNumber = strtol(value, &endptr, 10); + uint8_t errorNumber = uint8_t(strtol(value, &endptr, 10)); if (*endptr) { grbl_sendf(out->client(), "Malformed error number: %s\r\n", value); return Error::InvalidValue; diff --git a/Grbl_Esp32/src/Report.cpp b/Grbl_Esp32/src/Report.cpp index 1c14f33e..5d2e186e 100644 --- a/Grbl_Esp32/src/Report.cpp +++ b/Grbl_Esp32/src/Report.cpp @@ -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 rpt[0] = '\0'; 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 } 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) { String rpt = ""; uint8_t idx; - char axisVal[coordStringLen]; float unit_conv = 1.0; // unit conversion multiplier..default is mm int decimals = 3; // Default - report mm to 3 decimal places 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 } auto n_axis = config->_axes->_numberAxis; diff --git a/Grbl_Esp32/src/SDCard.cpp b/Grbl_Esp32/src/SDCard.cpp index 3ca8686c..5882fdb7 100644 --- a/Grbl_Esp32/src/SDCard.cpp +++ b/Grbl_Esp32/src/SDCard.cpp @@ -28,7 +28,8 @@ #include #include -struct SDCard::FileWrap { +class SDCard::FileWrap { +public: FileWrap() : _file(nullptr) {} File _file; }; diff --git a/Grbl_Esp32/src/Settings.cpp b/Grbl_Esp32/src/Settings.cpp index 4df84e57..af2daa00 100644 --- a/Grbl_Esp32/src/Settings.cpp +++ b/Grbl_Esp32/src/Settings.cpp @@ -235,7 +235,7 @@ void StringSetting::setDefault() { } 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; } Error err = check(s); @@ -330,7 +330,7 @@ Error EnumSetting::setStringValue(char* s) { return Error::BadNumberFormat; } char* endptr; - uint8_t num = strtol(s, &endptr, 10); + uint8_t num = uint8_t(strtol(s, &endptr, 10)); // Disallow non-numeric characters in string if (*endptr) { return Error::BadNumberFormat; diff --git a/Grbl_Esp32/src/Spindles/PWMSpindle.cpp b/Grbl_Esp32/src/Spindles/PWMSpindle.cpp index b5f6172d..3cdb781b 100644 --- a/Grbl_Esp32/src/Spindles/PWMSpindle.cpp +++ b/Grbl_Esp32/src/Spindles/PWMSpindle.cpp @@ -153,7 +153,7 @@ namespace Spindles { } // 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++; } diff --git a/Grbl_Esp32/src/Spindles/Spindle.cpp b/Grbl_Esp32/src/Spindles/Spindle.cpp index 6a05e94a..2ad3cb97 100644 --- a/Grbl_Esp32/src/Spindles/Spindle.cpp +++ b/Grbl_Esp32/src/Spindles/Spindle.cpp @@ -79,18 +79,18 @@ namespace Spindles { offset = _speeds[i].percent / 100.0 * max_dev_speed; _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 scale = deltaRPM == 0.0 ? 0.0 : (deltaPercent / deltaRPM); + float scale = deltaRPM == 0.0f ? 0.0f : (deltaPercent / deltaRPM); scale *= max_dev_speed; // float scale = deltaPercent * max_dev_speed; - scaler = scale * 65536; + scaler = uint32_t(scale * 65536); _speeds[i].scale = scaler; } // 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; scaler = 0; _speeds[i].scale = scaler; @@ -99,14 +99,14 @@ namespace Spindles { void Spindle::afterParse() {} void Spindle::shelfSpeeds(SpindleSpeed min, SpindleSpeed max) { - float minPercent = 100.0 * min / max; + float minPercent = 100.0f * min / max; _speeds.clear(); - _speeds.push_back({ 0, 0.0 }); + _speeds.push_back({ 0, 0.0f }); _speeds.push_back({ 0, minPercent }); if (min) { _speeds.push_back({ min, minPercent }); } - _speeds.push_back({ max, 100.0 }); + _speeds.push_back({ max, 100.0f }); } uint32_t Spindle::mapSpeed(SpindleSpeed speed) { diff --git a/Grbl_Esp32/src/Spindles/VFDSpindle.cpp b/Grbl_Esp32/src/Spindles/VFDSpindle.cpp index 531126f4..a6062db7 100644 --- a/Grbl_Esp32/src/Spindles/VFDSpindle.cpp +++ b/Grbl_Esp32/src/Spindles/VFDSpindle.cpp @@ -51,13 +51,13 @@ namespace Spindles { QueueHandle_t VFD::vfd_cmd_queue = 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 report_hex_msg(cmd.msg, "RS485 Tx: ", cmd.tx_length); report_hex_msg(rx_message, "RS485 Rx: ", read_length); #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 report_hex_msg(cmd.msg, "RS485 Tx: ", cmd.tx_length); report_hex_msg(rx_message, "RS485 Rx: ", read_length); @@ -189,8 +189,8 @@ namespace Spindles { uart.flushTxTimed(response_ticks); // Read the response - uint16_t read_length = 0; - uint16_t current_read = uart.readBytes(rx_message, next_cmd.rx_length, response_ticks); + size_t read_length = 0; + size_t current_read = uart.readBytes(rx_message, next_cmd.rx_length, response_ticks); read_length += current_read; // 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); read_length += current_read; } - if (current_read < 0) { - read_length = 0; - } // Generate crc16 for the response: auto crc16response = ModRTU_CRC(rx_message, next_cmd.rx_length - 2); diff --git a/Grbl_Esp32/src/Spindles/VFDSpindle.h b/Grbl_Esp32/src/Spindles/VFDSpindle.h index 9923fa15..e326dc76 100644 --- a/Grbl_Esp32/src/Spindles/VFDSpindle.h +++ b/Grbl_Esp32/src/Spindles/VFDSpindle.h @@ -63,8 +63,8 @@ namespace Spindles { bool prepareSetModeCommand(SpindleState mode, ModbusCommand& data); bool prepareSetSpeedCommand(uint32_t speed, ModbusCommand& data); - static void reportParsingErrors(ModbusCommand cmd, uint8_t* rx_message, uint16_t read_length); - static void reportCmdErrors(ModbusCommand cmd, uint8_t* rx_message, uint16_t read_length, uint8_t id); + static void reportParsingErrors(ModbusCommand cmd, uint8_t* rx_message, size_t read_length); + static void reportCmdErrors(ModbusCommand cmd, uint8_t* rx_message, size_t read_length, uint8_t id); protected: // Commands: diff --git a/Grbl_Esp32/src/Stepper.cpp b/Grbl_Esp32/src/Stepper.cpp index 6f67cd51..5409a8cd 100644 --- a/Grbl_Esp32/src/Stepper.cpp +++ b/Grbl_Esp32/src/Stepper.cpp @@ -564,7 +564,7 @@ void st_prep_buffer() { pl_block->entry_speed_sqr = prep.exit_speed * prep.exit_speed; prep.recalculate_flag.decelOverride = 0; } 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 @@ -573,7 +573,7 @@ void st_prep_buffer() { if (config->_laserMode) { if (pl_block->spindle == SpindleState::Ccw) { // 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; } } @@ -585,7 +585,7 @@ void st_prep_buffer() { 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. - 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] // Compute velocity profile parameters for a feed hold in-progress. This profile overrides // 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; if (decel_dist < 0.0) { // 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 { prep.mm_complete = decel_dist; // End of feed hold. 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. } else { 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); 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. 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. @@ -622,7 +622,7 @@ void st_prep_buffer() { // prep.decelerate_after = pl_block->millimeters; // prep.maximum_speed = prep.current_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. // TODO: Determine correct handling of parameters in deceleration-only. // 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 prep.accelerate_until = 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 prep.ramp_type = RAMP_DECEL; @@ -702,12 +702,12 @@ void st_prep_buffer() { switch (prep.ramp_type) { case RAMP_DECEL_OVERRIDE: 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; if ((mm_remaining < prep.accelerate_until) || (mm_var <= 0)) { // Cruise or cruise-deceleration types only for deceleration override. 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.current_speed = prep.maximum_speed; } else { // Mid-deceleration override ramp. @@ -717,11 +717,11 @@ void st_prep_buffer() { case RAMP_ACCEL: // NOTE: Acceleration ramp only computes during first do-while loop. 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. // Acceleration-cruise, acceleration-deceleration ramp junction, or end of block. 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) { prep.ramp_type = RAMP_DECEL; } else { @@ -751,15 +751,15 @@ void st_prep_buffer() { 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. // Compute distance from end of segment to end of block. - mm_var = mm_remaining - time_var * (prep.current_speed - 0.5 * speed_var); // (mm) - if (mm_var > prep.mm_complete) { // Typical case. In deceleration ramp. + 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. mm_remaining = mm_var; prep.current_speed -= speed_var; break; // Segment complete. Exit switch-case statement. Continue do-while loop. } } // 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; prep.current_speed = prep.exit_speed; } @@ -802,7 +802,6 @@ void st_prep_buffer() { sys.step_control.updateSpindleSpeed = false; } 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 /* ----------------------------------------------------------------------------------- @@ -815,10 +814,10 @@ void st_prep_buffer() { 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). */ - 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 last_n_steps_remaining = 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. + float step_dist_remaining = prep.step_per_mm * mm_remaining; // Convert mm_remaining to steps + float n_steps_remaining = float(ceil(step_dist_remaining)); // Round-up current steps remaining + float last_n_steps_remaining = float(ceil(prep.steps_remaining)); // Round-up last steps remaining + 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. if (prep_segment->n_step == 0) { @@ -849,7 +848,7 @@ void st_prep_buffer() { // Compute CPU cycles per step for the prepped segment. // fStepperTimer is in units of timerTicks/sec, so the dimensional analysis is // 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; // Compute step timing and multi-axis smoothing level. diff --git a/Grbl_Esp32/src/StepperPrivate.h b/Grbl_Esp32/src/StepperPrivate.h index d6e23639..5e46b705 100644 --- a/Grbl_Esp32/src/StepperPrivate.h +++ b/Grbl_Esp32/src/StepperPrivate.h @@ -9,12 +9,12 @@ const int SEGMENT_BUFFER_SIZE = 6; // Some useful constants. -const double DT_SEGMENT = (1.0 / (ACCELERATION_TICKS_PER_SECOND * 60.0)); // min/segment -const double REQ_MM_INCREMENT_SCALAR = 1.25; -const int RAMP_ACCEL = 0; -const int RAMP_CRUISE = 1; -const int RAMP_DECEL = 2; -const int RAMP_DECEL_OVERRIDE = 3; +const float DT_SEGMENT = (1.0f / (float(ACCELERATION_TICKS_PER_SECOND) * 60.0f)); // min/segment +const float REQ_MM_INCREMENT_SCALAR = 1.25f; +const int RAMP_ACCEL = 0; +const int RAMP_CRUISE = 1; +const int RAMP_DECEL = 2; +const int RAMP_DECEL_OVERRIDE = 3; struct PrepFlag { uint8_t recalculate : 1; diff --git a/Grbl_Esp32/src/System.cpp b/Grbl_Esp32/src/System.cpp index 92c9779c..bca0caef 100644 --- a/Grbl_Esp32/src/System.cpp +++ b/Grbl_Esp32/src/System.cpp @@ -140,7 +140,7 @@ void sys_analog_all_off() { // io_num is the virtual analog pin# bool sys_set_analog(uint8_t io_num, float percent) { 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); } @@ -173,7 +173,7 @@ uint8_t sys_calc_pwm_precision(uint32_t freq) { uint8_t precision = 0; // 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++; } diff --git a/Grbl_Esp32/src/UserOutput.cpp b/Grbl_Esp32/src/UserOutput.cpp index c78b3a03..cac48afd 100644 --- a/Grbl_Esp32/src/UserOutput.cpp +++ b/Grbl_Esp32/src/UserOutput.cpp @@ -59,7 +59,7 @@ namespace UserOutput { // increase the precision (bits) until it exceeds allow by frequency the max or is 16 _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 is now just barely too high, so drop it down one diff --git a/Grbl_Esp32/src/UserOutput.h b/Grbl_Esp32/src/UserOutput.h index 53f0b6cd..42beb761 100644 --- a/Grbl_Esp32/src/UserOutput.h +++ b/Grbl_Esp32/src/UserOutput.h @@ -35,7 +35,7 @@ namespace UserOutput { void config_message(); uint8_t _number = UNDEFINED_OUTPUT; - Pin& _pin; + Pin& _pin; }; class AnalogOutput { @@ -49,7 +49,7 @@ namespace UserOutput { void config_message(); uint8_t _number = UNDEFINED_OUTPUT; - Pin& _pin; + Pin& _pin; uint8_t _pwm_channel = -1; // -1 means invalid or not setup float _pwm_frequency; uint8_t _resolution_bits; diff --git a/Grbl_Esp32/src/WebUI/Commands.cpp b/Grbl_Esp32/src/WebUI/Commands.cpp index 6277c32b..38c70be1 100644 --- a/Grbl_Esp32/src/WebUI/Commands.cpp +++ b/Grbl_Esp32/src/WebUI/Commands.cpp @@ -58,7 +58,7 @@ namespace WebUI { } //no space allowed - for (int i = 0; i < strlen(password); i++) { + for (size_t i = 0; i < strlen(password); i++) { c = password[i]; if (c == ' ') { return false; diff --git a/UnitTests.vcxproj b/UnitTests.vcxproj index f83928a0..98e7da4d 100644 --- a/UnitTests.vcxproj +++ b/UnitTests.vcxproj @@ -324,6 +324,7 @@ Level3 true $(MSBuildThisFileDirectory)X86TestSupport;$(MSBuildThisFileDirectory)GRBL_Esp32;%(AdditionalIncludeDirectories) + -D_CRT_SECURE_NO_WARNINGS %(AdditionalOptions) true @@ -341,6 +342,7 @@ Level3 true $(MSBuildThisFileDirectory)X86TestSupport;$(MSBuildThisFileDirectory)GRBL_Esp32;%(AdditionalIncludeDirectories) + -D_CRT_SECURE_NO_WARNINGS %(AdditionalOptions) true @@ -357,6 +359,7 @@ ProgramDatabase $(MSBuildThisFileDirectory)X86TestSupport;$(MSBuildThisFileDirectory)GRBL_Esp32;%(AdditionalIncludeDirectories) true + -D_CRT_SECURE_NO_WARNINGS %(AdditionalOptions) true @@ -375,6 +378,7 @@ ProgramDatabase $(MSBuildThisFileDirectory)X86TestSupport;$(MSBuildThisFileDirectory)GRBL_Esp32;%(AdditionalIncludeDirectories) true + -D_CRT_SECURE_NO_WARNINGS %(AdditionalOptions) true @@ -389,4 +393,4 @@ - + \ No newline at end of file diff --git a/UnitTests.vcxproj.filters b/UnitTests.vcxproj.filters index a734a8d8..2c19bf16 100644 --- a/UnitTests.vcxproj.filters +++ b/UnitTests.vcxproj.filters @@ -1,869 +1,279 @@ - + - - {d251c8e1-710b-4299-bf32-211cbc23e1d2} - - - {0a063b22-59ea-4f6c-a573-7e4aef718f3b} - - - {cc13daa8-4fd4-4995-a724-77db03c229af} - - - {a166a529-634f-48dc-b368-6c03f6f0a36f} - - - {6ae3ae24-fdcd-49f4-9797-a0b0f973c2dc} - - - {1876cb4d-22d0-44a9-907d-4dabd762367e} - - - {765754ab-2627-4625-be41-4e49201ad239} - - - {8f8fa64a-6eda-4fd7-8a1a-23d10f603b46} - - - {2d3e3a50-3fe8-4f32-81c2-2128d6d6ad3e} - - - {f39d1497-2e49-4e08-89e4-8926b7a04295} - - - {bb6be066-8250-4ca8-967c-ea9b2e6746c0} - - - {4bf7d2ce-26dc-40f5-8bd4-60c7b4f4ca89} - - - {53e8ad3f-34ef-4802-b6db-6d60ca941a46} - - - {521f05f1-3e07-4301-be76-2a81cdf1f135} - - - {af53d407-844a-47ec-8f6d-de797e13e2db} - - - {1d2d56d1-0078-44c4-be29-447de0ece1e5} - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - test - - - test - - - X86TestSupport - - - X86TestSupport - - - X86TestSupport - - - X86TestSupport - - - X86TestSupport\driver - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Motors - - - src\Motors - - - src\Motors - - - src\Motors - - - src\Motors - - - src\Motors - - - src\Motors - - - src\Motors - - - src\Motors - - - src\Motors - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\StackTrace - - - src\StackTrace - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - X86TestSupport\freertos - - - X86TestSupport - - - src - - - X86TestSupport - - - X86TestSupport\freertos - - - X86TestSupport - - - X86TestSupport\driver - - - X86TestSupport - - - X86TestSupport\freertos - - - X86TestSupport\soc - - - X86TestSupport\soc - - - X86TestSupport\soc - - - X86TestSupport\soc - - - X86TestSupport\soc - - - X86TestSupport - - - X86TestSupport - - - X86TestSupport - - - X86TestSupport - - - X86TestSupport\TMC - - - X86TestSupport\TMC - - - X86TestSupport\soc - - - X86TestSupport\driver - - - X86TestSupport\driver - - - X86TestSupport - - - X86TestSupport - - - X86TestSupport - - - X86TestSupport - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - test - - - test - - - test\Pins - - - test\Pins - - - test\Pins - - - X86TestSupport - - - X86TestSupport - - - X86TestSupport - - - test\Pins - - - test - - - test\Configuration - - - test\Configuration - - - test\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Machine - - - src\Motors - - - src\Motors - - - src\Motors - - - src\Motors - - - src\Motors - - - src\Motors - - - src\Motors - - - src\Motors - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Pins - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\Spindles - - - src\StackTrace - - - src\StackTrace - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src\WebUI - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - src - - - test\Pins - - - X86TestSupport - - - X86TestSupport - - - X86TestSupport - - - - - test - + + + + + + + + + - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Configuration - - - src\Motors - - - src\Spindles - - - src - - - src - - + \ No newline at end of file