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

ヘッダーファイル #199

wants to merge 4 commits into from

Conversation

23-yoshikawa
Copy link
Contributor

No description provided.

@23-yoshikawa 23-yoshikawa requested a review from H1rono June 1, 2024 07:01
@23-yoshikawa
Copy link
Contributor Author

.cppファイルのほうで
初期化の関数でエラーが出てしまったのですがどうすればよいかわかりませんでした。
もともとあったinputmodulesの初期化を関数にしようと思ったのですが、だめでした

@H1rono H1rono linked an issue Jun 1, 2024 that may be closed by this pull request
@H1rono
Copy link
Member

H1rono commented Jun 1, 2024

そもそもこのissueでやりたいのは、「ピン番号とセンサー・アクチュエーターとの対応関係を明示する」ということです。つまり、以下のようなリファクタリングを入れたいです。

// before
InputModules input_modules({A4, A5}, A6, {D4, D5}), output_modules({PB_4, PA_11}, {PA_9, PA_10});

// after
InputModules input_modules = InputModules::builder()
    .joy_pins(A4, A5)
    .volume_pin(A6)
    .mpu_sda_pin(D4)
    .mpu_scl_pin(D5)
    .build();

ここまで書いたものはbuilder()からmpu_scl_pin()までの実装(怪しいけど)なので、あとはbuild()だけです

class Builder {
    ...
    auto build() -> InputModules;
};

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(...

Comment on lines 13 to +21
// 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)
*/
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.

消してね

@23-yoshikawa 23-yoshikawa requested a review from H1rono June 4, 2024 08:36
Copy link
Member

@H1rono H1rono left a comment

Choose a reason for hiding this comment

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

かなり良くなってきてる!Machineのコンストラクタを変える必要があるので、そこもお願いします

before:

input_modules({A4, A5}, A6, {D4, D5}), output_modules({PB_4, PA_11}, {PA_9, PA_10}), service() {

after:

input_modules(InputModules::builder()....), ...

Comment on lines +46 to +48
auto joy_pins(const std::pair<PinName, PinName>& pins) -> Builder&;
auto volume_pin(const PinName& pin) -> Builder&;
auto mpu_pins(const std::pair<PinName, PinName>& pins) -> Builder&;
Copy link
Member

Choose a reason for hiding this comment

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

pairのfirst, secondがそれぞれ何を意味しているのか明示した版も欲しいです

auto joy_x_pin(const PinName& pin) -> Builder&; // joy_pins.first
auto joy_y_pin(const PinName& pin) -> Builder&; // joy_pins.second
auto mpu_sda_pin(const PinName& pin) -> Builder&; // mpu_pins.first
auto mpu_scl_pin(const PinName& pin) -> Builder&; // mpu_pins.second

Comment on lines 13 to +21
// 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)
*/
Copy link
Member

Choose a reason for hiding this comment

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

消してね

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

InputModulesのBuilder
2 participants