Skip to content

Commit

Permalink
builder
Browse files Browse the repository at this point in the history
  • Loading branch information
23-yoshikawa committed Jun 4, 2024
1 parent abe7aa1 commit 34a31e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
14 changes: 7 additions & 7 deletions include/device/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ class InputModules {
*/
class Builder {
private:
std::pair<PinName, PinName> joy_pins;
PinName volume_pin;
std::pair<PinName, PinName> mpu_pins;
std::pair<PinName, PinName> _joy_pins;
PinName _volume_pin;
std::pair<PinName, PinName> _mpu_pins;

public:
auto joy_pins(const PinName& pin) -> Builder&;
auto joy_pins(const std::pair<PinName, PinName>& pins) -> Builder&;
auto volume_pin(const PinName& pin) -> Builder&;
auto mpu_pins(const PinName& pin) -> Builder&;
auto mpu_pins(const std::pair<PinName, PinName>& pins) -> Builder&;
};

private:
InputModules(
const std::pair<PinName, PinName>& joy_pins, const PinName& volume_pin,
const std::pair<PinName, PinName>& mpu_pins);
const std::pair<PinName, PinName>& _joy_pins, const PinName& _volume_pin,
const std::pair<PinName, PinName>& _mpu_pins);

public:
static auto builder() -> Builder;
Expand Down
11 changes: 5 additions & 6 deletions src/device/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@ auto device::InputModules::read_gyro() -> std::array<float, 3> {
mpu(mpu_pins.first, mpu_pins.second) {}
// NOLINTEND(bugprone-easily-swappable-parameters)
*/
auto device::InputModules::Builder::joy_pins(const PinName& pin) -> Builder& {
this->joy_pins
= std::make_pair(mbed::AnalogIn(joy_pins.first), mbed::AnalogIn(joy_pins.second));
auto device::InputModules::Builder::joy_pins(const std::pair<PinName, PinName>& pins) -> Builder& {
this->_joy_pins = std::make_pair((pins.first), (pins.second));
return *this;
}

auto device::InputModules::Builder::volume_pin(const PinName& pin) -> Builder& {
this->volume_pin = mbed::AnalogIn(volume_pin);
this->_volume_pin = pin;
return *this;
}

auto device::InputModules::Builder::mpu_pins(const PinName& pin) -> Builder& {
this->mpu_pins = MPU6050(mpu_pins.first, mpu_pins.second);
auto device::InputModules::Builder::mpu_pins(const std::pair<PinName, PinName>& pins) -> Builder& {
this->_mpu_pins = std::make_pair((pins.first), (pins.second));
return *this;
}
auto device::InputModules::builder() -> Builder {
Expand Down

0 comments on commit 34a31e1

Please sign in to comment.