Skip to content

Commit

Permalink
use error code instead of new error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
caila-marashaj committed Mar 4, 2024
1 parent f004401 commit 5b838f3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>(_task.get_message_queue().try_send_from_isr(
messages::MotorMessage(messages::LidStepperError{})));
}

static void handle_lid_stepper() {
static_cast<void>(_task.get_message_queue().try_send_from_isr(
messages::MotorMessage(messages::LidStepperComplete{})));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,18 @@ 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) {
if(_motor_hardware.lid_stepper.direction) {
// 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;
}
}
}
Expand All @@ -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();
}
}
Expand Down
3 changes: 3 additions & 0 deletions stm32-modules/thermocycler-gen2/src/errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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;
}

0 comments on commit 5b838f3

Please sign in to comment.