From 5b838f32a4e3c0672edba076dc92f08bd558546b Mon Sep 17 00:00:00 2001 From: caila-marashaj Date: Mon, 4 Mar 2024 11:05:38 -0500 Subject: [PATCH] use error code instead of new error msg --- .../thermocycler-gen2/thermocycler-gen2/errors.hpp | 1 + .../thermocycler-gen2/thermocycler-gen2/motor_task.hpp | 8 +++++--- .../firmware/motor_task/freertos_motor_task.cpp | 7 +------ .../firmware/motor_task/motor_hardware.c | 9 ++------- stm32-modules/thermocycler-gen2/src/errors.cpp | 3 +++ 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/errors.hpp b/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/errors.hpp index 72c5864e0..f2870f38b 100644 --- a/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/errors.hpp +++ b/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/errors.hpp @@ -61,6 +61,7 @@ enum class ErrorCode { SEAL_MOTOR_STALL = 506, LID_CLOSED = 507, SEAL_MOTOR_SWITCH = 508, + UNEXPECTED_LID_STATE = 509, }; auto errorstring(ErrorCode code) -> const char*; diff --git a/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/motor_task.hpp b/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/motor_task.hpp index e308ebca6..ec1a85569 100644 --- a/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/motor_task.hpp +++ b/stm32-modules/include/thermocycler-gen2/thermocycler-gen2/motor_task.hpp @@ -26,7 +26,7 @@ namespace motor_task { /* * The MotorExecutionPolicy is how the portable task interacts * with the hardware. It is defined as a concept so it can be - * passed as a reference paramter to run_once(), which means the + * passed as a reference parameter to run_once(), which means the * type of policy in actual use does not have to be part of the class's * type signature (which is used all over the place), just run_once's * type signature, which is used just by the rtos task and the test @@ -1289,8 +1289,10 @@ class MotorTask { motor_util::LidStepper::Position::CLOSED; // The overall lid state machine can advance now error = handle_lid_state_end(policy); - // TODO(Frank, Mar-7-2022) check if the lid didn't make it in - // all the way + // if the lid isn't actually closed, overwrite error status + if (!policy.lid_read_closed_switch()) { + error = errors::ErrorCode::UNEXPECTED_LID_STATE; + } break; case LidStepperState::Status::LIFT_NUDGE: policy.lid_stepper_start( diff --git a/stm32-modules/thermocycler-gen2/firmware/motor_task/freertos_motor_task.cpp b/stm32-modules/thermocycler-gen2/firmware/motor_task/freertos_motor_task.cpp index 21f7546ae..d262409cc 100644 --- a/stm32-modules/thermocycler-gen2/firmware/motor_task/freertos_motor_task.cpp +++ b/stm32-modules/thermocycler-gen2/firmware/motor_task/freertos_motor_task.cpp @@ -47,12 +47,7 @@ static MotorPolicy _policy(false); * @brief This function is called after the lid stepper has stepped the * requested number of steps. */ -static void handle_lid_stepper(bool lid_stepper_error) { - if (error) { - static_cast(_task.get_message_queue().try_send_from_isr( - messages::MotorMessage(messages::LidStepperError{}))); - } - +static void handle_lid_stepper() { static_cast(_task.get_message_queue().try_send_from_isr( messages::MotorMessage(messages::LidStepperComplete{}))); } diff --git a/stm32-modules/thermocycler-gen2/firmware/motor_task/motor_hardware.c b/stm32-modules/thermocycler-gen2/firmware/motor_task/motor_hardware.c index 40ea436bf..b4a78fc58 100644 --- a/stm32-modules/thermocycler-gen2/firmware/motor_task/motor_hardware.c +++ b/stm32-modules/thermocycler-gen2/firmware/motor_task/motor_hardware.c @@ -248,7 +248,6 @@ void motor_hardware_lid_stepper_stop() { void motor_hardware_lid_increment() { bool done = false; - bool sensor_triggered = false; _motor_hardware.lid_stepper.step_count++; // Only check stop switches if this is NOT an overdrive if(!_motor_hardware.lid_stepper.overdrive) { @@ -256,13 +255,11 @@ void motor_hardware_lid_increment() { // Check if lid is open if(motor_hardware_lid_read_open()) { done = true; - sensor_triggered = true; } } else { // Check if lid is closed if(motor_hardware_lid_read_closed()) { done = true; - sensor_triggered = true; } } } @@ -272,10 +269,8 @@ void motor_hardware_lid_increment() { done = true; } - if (done) { - bool error = !sensor_triggered; - // throw an error if stepping is finished but neither sensor is triggered - motor_hardware_lid_stepper_stop(error); + if(done) { + motor_hardware_lid_stepper_stop(); _motor_hardware.callbacks.lid_stepper_complete(); } } diff --git a/stm32-modules/thermocycler-gen2/src/errors.cpp b/stm32-modules/thermocycler-gen2/src/errors.cpp index 4da9a8274..4b15d9c86 100644 --- a/stm32-modules/thermocycler-gen2/src/errors.cpp +++ b/stm32-modules/thermocycler-gen2/src/errors.cpp @@ -87,6 +87,8 @@ const char* const SEAL_MOTOR_SWITCH = "ERR508:seal:Seal switch should not be engaged OK\n"; const char* const UNKNOWN_ERROR = "ERR-1:unknown error code OK\n"; +const char* const UNEXPECTED_LID_STATE = + "ERR509:lid:Lid status does not match expected open/closed status"; // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define HANDLE_CASE(errname) \ @@ -144,6 +146,7 @@ auto errors::errorstring(ErrorCode code) -> const char* { HANDLE_CASE(SEAL_MOTOR_STALL); HANDLE_CASE(LID_CLOSED); HANDLE_CASE(SEAL_MOTOR_SWITCH); + HANDLE_CASE(UNEXPECTED_LID_STATE); } return UNKNOWN_ERROR; }