Skip to content

Commit

Permalink
change handling of default cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ion098 committed May 27, 2024
1 parent 565ade4 commit 9ad720f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/gamepad/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class Controller {
Button L1 {}, L2 {}, R1 {}, R2 {}, Up {}, Down {}, Left {}, Right {}, X {}, B {}, Y {}, A {};
float LeftX = 0, LeftY = 0, RightX = 0, RightY = 0;
private:
Button Fake{};
static Button Controller::*button_to_ptr(pros::controller_digital_e_t button);
void updateButton(pros::controller_digital_e_t button_id);
pros::Controller controller;
Expand Down
12 changes: 9 additions & 3 deletions src/gamepad/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ float Controller::operator[](pros::controller_analog_e_t axis) {
case ANALOG_LEFT_X: return this->LeftX;
case ANALOG_LEFT_Y: return this->LeftY;
case ANALOG_RIGHT_X: return this->RightX;
case ANALOG_RIGHT_Y: return this->RightY; TODO("change handling for default")
default: std::exit(1);
case ANALOG_RIGHT_Y: return this->RightY;
default:
TODO("add error logging")
errno = EINVAL;
return 0;
}
}

Expand All @@ -94,7 +97,10 @@ Button Controller::*Controller::button_to_ptr(pros::controller_digital_e_t butto
case DIGITAL_B: return &Controller::B;
case DIGITAL_Y: return &Controller::Y;
case DIGITAL_A: return &Controller::A; TODO("change handling for default")
default: std::exit(1);
default:
TODO("add error logging")
errno = EINVAL;
return &Controller::Fake;
}
}
} // namespace Gamepad

0 comments on commit 9ad720f

Please sign in to comment.