Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ヘッダーファイル #199

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/device/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,27 @@ class InputModules {
* @param volume_pin ツマミのピン
* @param mpu_pins MPU6050のピン (sda, scl)
*/
class Builder {
private:
std::pair<PinName, PinName> joy_pins;
PinName volume_pin;
std::pair<PinName, PinName> mpu_pins;

public:
auto joy_pins(const PinName& pin) -> Builder&;
auto volume_pin(const PinName& pin) -> Builder&;
auto mpu_pins(const PinName& pin) -> Builder&;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MPU6050のピン設定はSDA, SCLの2ピンなのでPinNameの値を2つ受け取る必要があります。これはjoyの方も同様です

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

で、この2つも区別しづらいので別々に受け取りたいですね

auto joy_x_pin(...
auto joy_y_pin(...
auto mpu_sda_pin(...
auto mpu_scl_pin(...

};

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

public:
static auto builder() -> Builder;
InputModules(Builder builder);

InputModules() = delete;
~InputModules() = default;
InputModules(const InputModules&) = delete;
Expand Down
21 changes: 20 additions & 1 deletion src/device/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,32 @@ auto device::InputModules::read_gyro() -> std::array<float, 3> {
}

// NOLINTBEGIN(bugprone-easily-swappable-parameters)
device::InputModules::InputModules(
/**device::InputModules::InputModules(
const std::pair<PinName, PinName>& joy_pins, const PinName& volume_pin,
const std::pair<PinName, PinName>& mpu_pins) :
joy(joy_pins.first, joy_pins.second),
volume(volume_pin),
mpu(mpu_pins.first, mpu_pins.second) {}
// NOLINTEND(bugprone-easily-swappable-parameters)
*/
Comment on lines 15 to +23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ消しちゃっていいです

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

消してね

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));
return *this;
}

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

auto device::InputModules::Builder::mpu_pins(const PinName& pin) -> Builder& {
this->mpu_pins = MPU6050(mpu_pins.first, mpu_pins.second);
return *this;
}
auto device::InputModules::builder() -> Builder {
return Builder();
}

auto device::InputModules::mpu_whoami() -> bool {
return this->mpu.testConnection();
Expand Down
Loading