Skip to content

Commit 30daf02

Browse files
committed
Use helper function for printDebug string fill
1 parent 23d57f9 commit 30daf02

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/XInput.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,15 @@ void XInputController::reset() {
559559
autoSendOption = true;
560560
}
561561

562+
static void fillBuffer(char* buff, const char fill) {
563+
uint8_t i = 0;
564+
while (true) {
565+
if (buff[i] == 0) break;
566+
buff[i] = fill;
567+
i++;
568+
}
569+
}
570+
562571
void XInputController::printDebug(Print &output) const {
563572
const char fillCharacter = '_';
564573

@@ -584,14 +593,8 @@ void XInputController::printDebug(Print &output) const {
584593
char leftBumper[3] = "LB";
585594
char rightBumper[3] = "RB";
586595

587-
if (!getButton(BUTTON_LB)) {
588-
leftBumper[0] = fillCharacter;
589-
leftBumper[1] = fillCharacter;
590-
}
591-
if (!getButton(BUTTON_RB)) {
592-
rightBumper[0] = fillCharacter;
593-
rightBumper[1] = fillCharacter;
594-
}
596+
if (!getButton(BUTTON_LB)) fillBuffer(leftBumper, fillCharacter);
597+
if (!getButton(BUTTON_RB)) fillBuffer(rightBumper, fillCharacter);
595598

596599
output.print("XInput Debug: ");
597600
sprintf(buffer,

0 commit comments

Comments
 (0)