Optimisation: make constructors constexpr

Cppcheck was complaining some member variables
are not initialised in the constructor.

Change in memory:
Flash: -186 bytes
SRAM: -15 bytes
pull/292/head
Guðni Már Gilbert 2023-08-20 14:44:04 +00:00
parent 0d76a0ea23
commit fff1c471b4
16 changed files with 31 additions and 23 deletions

View File

@ -28,7 +28,7 @@ ErrorCode AddErrorAxisBit(ErrorCode ec, uint8_t axis);
/// These tasks report their progress and only one of these tasks is allowed to run at once. /// These tasks report their progress and only one of these tasks is allowed to run at once.
class CommandBase { class CommandBase {
public: public:
inline CommandBase() inline constexpr CommandBase()
: state(ProgressCode::OK) : state(ProgressCode::OK)
, error(ErrorCode::OK) , error(ErrorCode::OK)
, deferredErrorCode(ErrorCode::OK) , deferredErrorCode(ErrorCode::OK)

View File

@ -11,8 +11,10 @@ namespace logic {
/// @brief A high-level command state machine - handles the complex logic of cutting filament /// @brief A high-level command state machine - handles the complex logic of cutting filament
class CutFilament : public CommandBase { class CutFilament : public CommandBase {
public: public:
inline CutFilament() inline constexpr CutFilament()
: CommandBase() {} : CommandBase()
, cutSlot(0)
, savedSelectorFeedRate_mm_s(0) {}
/// Restart the automaton /// Restart the automaton
/// @param param index of filament slot to perform cut onto /// @param param index of filament slot to perform cut onto

View File

@ -26,8 +26,9 @@ static constexpr modules::motion::P_speed_t ejectSpeed = 1000.0_P_mm_s; //@@TODO
/// The Eject message is not an error, but we'll leverage existing infrastructure of error screens + user input to model a nice UI dialog. /// The Eject message is not an error, but we'll leverage existing infrastructure of error screens + user input to model a nice UI dialog.
class EjectFilament : public CommandBase { class EjectFilament : public CommandBase {
public: public:
inline EjectFilament() inline constexpr EjectFilament()
: CommandBase() {} : CommandBase()
, slot(0) {}
/// Restart the automaton /// Restart the automaton
/// @param param index of filament slot to eject /// @param param index of filament slot to eject

View File

@ -30,7 +30,7 @@ struct FeedToBondtech {
// PulleyStalled // PulleyStalled
}; };
inline FeedToBondtech() inline constexpr FeedToBondtech()
: state(OK) : state(OK)
, maxRetries(1) {} , maxRetries(1) {}

View File

@ -23,9 +23,10 @@ struct FeedToFinda {
Stopped Stopped
}; };
inline FeedToFinda() inline constexpr FeedToFinda()
: state(OK) : state(OK)
, feedPhaseLimited(true) {} , feedPhaseLimited(true)
, haltAtEnd(0) {}
/// Restart the automaton /// Restart the automaton
/// @param feedPhaseLimited /// @param feedPhaseLimited

View File

@ -20,7 +20,7 @@ namespace logic {
/// This high-level command is just a way to invoke re-homing from the printer while all safety measures are kept. /// This high-level command is just a way to invoke re-homing from the printer while all safety measures are kept.
class Home : public CommandBase { class Home : public CommandBase {
public: public:
inline Home() inline constexpr Home()
: CommandBase() {} : CommandBase() {}
/// Restart the automaton /// Restart the automaton

View File

@ -14,7 +14,7 @@ namespace logic {
class HWSanity : public CommandBase { class HWSanity : public CommandBase {
public: public:
inline HWSanity() inline constexpr HWSanity()
: CommandBase() {} : CommandBase() {}
/// Restart the automaton /// Restart the automaton
@ -44,7 +44,7 @@ private:
static void PrepareAxis(config::Axis axis); static void PrepareAxis(config::Axis axis);
uint8_t test_step = 0; uint8_t test_step = 0;
config::Axis axis; config::Axis axis = config::Axis::Pulley;
uint8_t fault_masks[3] = { 0 }; uint8_t fault_masks[3] = { 0 };
ProgressCode next_state = ProgressCode::HWTestBegin; ProgressCode next_state = ProgressCode::HWTestBegin;
uint16_t wait_start = 0; uint16_t wait_start = 0;

View File

@ -10,9 +10,10 @@ namespace logic {
/// @brief A high-level command state machine - handles the complex logic of loading filament into a filament slot. /// @brief A high-level command state machine - handles the complex logic of loading filament into a filament slot.
class LoadFilament : public CommandBase { class LoadFilament : public CommandBase {
public: public:
inline LoadFilament() inline constexpr LoadFilament()
: CommandBase() : CommandBase()
, verifyLoadedFilament(0) {} , verifyLoadedFilament(0)
, result(ResultCode::OK) {}
/// Restart the automaton - performs unlimited rotation of the Pulley /// Restart the automaton - performs unlimited rotation of the Pulley
/// @param param index of filament slot to load /// @param param index of filament slot to load

View File

@ -15,7 +15,7 @@ namespace logic {
/// and/or from the MMU's buttons while all safety measures are kept. /// and/or from the MMU's buttons while all safety measures are kept.
class MoveSelector : public CommandBase { class MoveSelector : public CommandBase {
public: public:
inline MoveSelector() inline constexpr MoveSelector()
: CommandBase() {} : CommandBase() {}
/// Restart the automaton /// Restart the automaton

View File

@ -8,7 +8,7 @@ namespace logic {
/// @brief A dummy No-command operation just to make the init of the firmware consistent (and cleaner code during processing). /// @brief A dummy No-command operation just to make the init of the firmware consistent (and cleaner code during processing).
class NoCommand : public CommandBase { class NoCommand : public CommandBase {
public: public:
inline NoCommand() inline constexpr NoCommand()
: CommandBase() {} : CommandBase() {}
/// Restart the automaton /// Restart the automaton

View File

@ -20,7 +20,7 @@ struct RetractFromFinda {
Failed Failed
}; };
inline RetractFromFinda() inline constexpr RetractFromFinda()
: state(OK) {} : state(OK) {}
/// Restart the automaton /// Restart the automaton

View File

@ -13,7 +13,7 @@ namespace logic {
/// (regardless of how long it takes it to finish) - that implies no motor moves are being performed while M0/M1 is being applied. /// (regardless of how long it takes it to finish) - that implies no motor moves are being performed while M0/M1 is being applied.
class SetMode : public CommandBase { class SetMode : public CommandBase {
public: public:
inline SetMode() inline constexpr SetMode()
: CommandBase() {} : CommandBase() {}
/// Restart the automaton /// Restart the automaton

View File

@ -8,7 +8,7 @@ namespace logic {
/// @brief Firmware start up sequence with error handling & reporting /// @brief Firmware start up sequence with error handling & reporting
class StartUp : public CommandBase { class StartUp : public CommandBase {
public: public:
inline StartUp() inline constexpr StartUp()
: CommandBase() {} : CommandBase() {}
/// Restart the automaton /// Restart the automaton

View File

@ -11,8 +11,9 @@ namespace logic {
/// @brief A high-level command state machine - handles the complex logic of tool change - which is basically a chain of an Unload and a Load operation. /// @brief A high-level command state machine - handles the complex logic of tool change - which is basically a chain of an Unload and a Load operation.
class ToolChange : public CommandBase { class ToolChange : public CommandBase {
public: public:
inline ToolChange() inline constexpr ToolChange()
: CommandBase() {} : CommandBase()
, plannedSlot(-1) {}
/// Restart the automaton /// Restart the automaton
/// @param param index of filament slot to change to - i.e. to load /// @param param index of filament slot to change to - i.e. to load

View File

@ -11,7 +11,7 @@ namespace logic {
/// @brief A high-level command state machine - handles the complex logic of unloading filament /// @brief A high-level command state machine - handles the complex logic of unloading filament
class UnloadFilament : public CommandBase { class UnloadFilament : public CommandBase {
public: public:
inline UnloadFilament() inline constexpr UnloadFilament()
: CommandBase() {} : CommandBase() {}
/// Restart the automaton /// Restart the automaton

View File

@ -21,8 +21,10 @@ struct UnloadToFinda {
FailedFINDA, FailedFINDA,
FailedFSensor FailedFSensor
}; };
inline UnloadToFinda() inline constexpr UnloadToFinda()
: maxTries(3) {} : state(OK)
, maxTries(3)
, unloadStart_mm(0) {}
/// Restart the automaton /// Restart the automaton
/// @param maxTries maximum number of retried attempts before reporting a fail /// @param maxTries maximum number of retried attempts before reporting a fail