Skip to content

Commit

Permalink
fix clang-format and cppcheck warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
k3kukua committed Jun 7, 2024
1 parent acdaedf commit f9a4f98
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 23 deletions.
12 changes: 6 additions & 6 deletions firmware/keira/src/utils/combo/concurrent_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ bool ComboConcurrentButtons::isTargetButton(size_t buttonIndex) {
return false;
}

bool ComboConcurrentButtons::isNonTargetButtonsPressed(_StateButtons& buttonStates) {
if(!buttonStates[Button::ANY].pressed) {
bool ComboConcurrentButtons::isNonTargetButtonsPressed(const _StateButtons& buttonStates) {
if (!buttonStates[Button::ANY].pressed) {
return false;
}
size_t size = Button::COUNT - 1; // exclude ANY button
Expand All @@ -76,14 +76,14 @@ bool ComboConcurrentButtons::isNonTargetButtonsPressed(_StateButtons& buttonStat
return false;
}

void ComboConcurrentButtons::checkAllButtonsPressed(_StateButtons& buttonStates) {
void ComboConcurrentButtons::checkAllButtonsPressed(const _StateButtons& buttonStates) {
if (isNonTargetButtonsPressed(buttonStates)) {
return;
}
bool allButtonsPressed = true;
bool anyButtonJustPressed = false;
for (size_t i = 0; i < NUM_BUTTONS; i++) {
ButtonState& bs = buttonStates[buttons[i]];
const ButtonState& bs = buttonStates[buttons[i]];
if (!bs.pressed) {
allButtonsPressed = false;
break;
Expand All @@ -99,11 +99,11 @@ void ComboConcurrentButtons::checkAllButtonsPressed(_StateButtons& buttonStates)
}
}

void ComboConcurrentButtons::checkAllButtonsReleased(_StateButtons& buttonStates) {
void ComboConcurrentButtons::checkAllButtonsReleased(const _StateButtons& buttonStates) {
bool allButtonsReleased = true;
bool anyButtonJustReleased = false;
for (size_t i = 0; i < NUM_BUTTONS; i++) {
ButtonState& bs = buttonStates[buttons[i]];
const ButtonState& bs = buttonStates[buttons[i]];
if (bs.pressed) {
allButtonsReleased = false;
break;
Expand Down
6 changes: 3 additions & 3 deletions firmware/keira/src/utils/combo/concurrent_buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class ComboConcurrentButtons : public ComboBase {

void initButtons(std::initializer_list<Button> buttonList);
bool isTargetButton(size_t buttonIndex);
bool isNonTargetButtonsPressed(_StateButtons& buttonStates);
void checkAllButtonsPressed(_StateButtons& buttonStates);
void checkAllButtonsReleased(_StateButtons& buttonStates);
bool isNonTargetButtonsPressed(const _StateButtons& buttonStates);
void checkAllButtonsPressed(const _StateButtons& buttonStates);
void checkAllButtonsReleased(const _StateButtons& buttonStates);
void onProgress();
void loopAction(State& state) override;
void resetAction() override;
Expand Down
14 changes: 4 additions & 10 deletions firmware/keira/src/utils/combo/core/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ class ComboBase {
return started;
}
void start() {
if (!started) {
started = true;
}
started = true;
}
bool isAutoStart() {
return autoStart;
Expand Down Expand Up @@ -62,15 +60,11 @@ class ComboBase {
}
};
void reset() {
if (started) {
started = false;
}
if (completed) {
completed = false;
}
started = false;
completed = false;
resetAction();
};
static bool isNonTargetButtonPressed(Button target, _StateButtons& buttonStates) {
static bool isNonTargetButtonPressed(Button target, const _StateButtons& buttonStates) {
bool anyButtonPressed = buttonStates[Button::ANY].pressed;
if (!anyButtonPressed || target == Button::ANY) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/utils/combo/one_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using ComboOneButtonProgressEventHandler = void (*)(const Button button, const B

class ComboOneButton : public ComboBase {
public:
ComboOneButton(Button button);
explicit ComboOneButton(Button button);
~ComboOneButton();

void setProgressEventHandler(ComboOneButtonProgressEventHandler handler) {
Expand Down
4 changes: 1 addition & 3 deletions firmware/keira/src/utils/combo/sequence_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ void ComboButtonSequence::loopAction(State& state) {
switch (buttonStage.getStage()) {
case WAITING:
if (bs.justPressed) {
if (!firstComboButtonAlreadyPressed) {
firstComboButtonAlreadyPressed = true;
}
firstComboButtonAlreadyPressed = true;
buttonStage.setPressedStage(bs.time);
onProgress();
if (isLastButtonProcessed()) {
Expand Down

0 comments on commit f9a4f98

Please sign in to comment.