Skip to content

Commit

Permalink
Merge pull request #70 from dmadison/printDebug
Browse files Browse the repository at this point in the history
printDebug function nitpicks
  • Loading branch information
dmadison authored May 11, 2021
2 parents 59e4c87 + 62a0f65 commit 9b0b087
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 66 deletions.
2 changes: 1 addition & 1 deletion extras/AddingControllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ boolean ClassicController_Shared::buttonB() const {
***Note:** I decided to use two different function names for generic control data and bits, just because the bits are automatically inverted. I might decide to change this in the future, but for now it seems to work fine.*

## Step #4: Add a `printDebug` Function
This should be a fun step. Create a `printDebug` function that prints out the values for your controller! Since this should only *ever* be called when debugging, I say go crazy with the formatting. Most of the other controllers use `sprintf` to make things easy, in spite of the extra overhead.
This should be a fun step. Create a `printDebug` function that prints out the values for your controller! Since this should only *ever* be called when debugging, I say go crazy with the formatting. The other controllers use `sprintf`/`snprintf` to make things easy, in spite of the extra overhead.

Here's how the Classic Controller debug line looks:
```
Expand Down
32 changes: 16 additions & 16 deletions src/controllers/ClassicController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,29 +335,29 @@ void ClassicController_Shared::printDebug(Print& output) const {

char buffer[68];

char dpadLPrint = dpadLeft() ? '<' : fillCharacter;
char dpadUPrint = dpadUp() ? '^' : fillCharacter;
char dpadDPrint = dpadDown() ? 'v' : fillCharacter;
char dpadRPrint = dpadRight() ? '>' : fillCharacter;
const char dpadLPrint = dpadLeft() ? '<' : fillCharacter;
const char dpadUPrint = dpadUp() ? '^' : fillCharacter;
const char dpadDPrint = dpadDown() ? 'v' : fillCharacter;
const char dpadRPrint = dpadRight() ? '>' : fillCharacter;

char aButtonPrint = buttonA() ? 'A' : fillCharacter;
char bButtonPrint = buttonB() ? 'B' : fillCharacter;
char xButtonPrint = buttonX() ? 'X' : fillCharacter;
char yButtonPrint = buttonY() ? 'Y' : fillCharacter;
const char aButtonPrint = buttonA() ? 'A' : fillCharacter;
const char bButtonPrint = buttonB() ? 'B' : fillCharacter;
const char xButtonPrint = buttonX() ? 'X' : fillCharacter;
const char yButtonPrint = buttonY() ? 'Y' : fillCharacter;

char plusPrint = buttonPlus() ? '+' : fillCharacter;
char minusPrint = buttonMinus() ? '-' : fillCharacter;
char homePrint = buttonHome() ? 'H' : fillCharacter;
const char plusPrint = buttonPlus() ? '+' : fillCharacter;
const char minusPrint = buttonMinus() ? '-' : fillCharacter;
const char homePrint = buttonHome() ? 'H' : fillCharacter;

char ltButtonPrint = buttonL() ? 'X' : fillCharacter;
char rtButtonPrint = buttonR() ? 'X' : fillCharacter;
const char ltButtonPrint = buttonL() ? 'X' : fillCharacter;
const char rtButtonPrint = buttonR() ? 'X' : fillCharacter;

char zlButtonPrint = buttonZL() ? 'L' : fillCharacter;
char zrButtonPrint = buttonZR() ? 'R' : fillCharacter;
const char zlButtonPrint = buttonZL() ? 'L' : fillCharacter;
const char zrButtonPrint = buttonZR() ? 'R' : fillCharacter;

output.print("Classic ");

sprintf(buffer,
snprintf(buffer, sizeof(buffer),
"%c%c%c%c | %c%c%c | %c%c%c%c L:(%3u, %3u) R:(%3u, %3u) | LT:%3u%c RT:%3u%c Z:%c%c",
dpadLPrint, dpadUPrint, dpadDPrint, dpadRPrint,
minusPrint, homePrint, plusPrint,
Expand Down
16 changes: 8 additions & 8 deletions src/controllers/DJTurntable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ void DJTurntableController_Shared::printDebug(Print& output) {
output.print(" |");
}

char plusPrint = buttonPlus() ? '+' : fillCharacter;
char minusPrint = buttonMinus() ? '-' : fillCharacter;
const char plusPrint = buttonPlus() ? '+' : fillCharacter;
const char minusPrint = buttonMinus() ? '-' : fillCharacter;

char euphoriaPrint = buttonEuphoria() ? 'E' : fillCharacter;
const char euphoriaPrint = buttonEuphoria() ? 'E' : fillCharacter;

sprintf(buffer,
snprintf(buffer, sizeof(buffer),
" Joy:(%2u, %2u) | %c | %c%c | FX: %2u | Fade: %2u",
joyX(), joyY(),
euphoriaPrint,
Expand All @@ -179,12 +179,12 @@ void DJTurntableController_Shared::printTurntable(Print& output, TurntableExpans
idPrint = 'R';
}

char greenPrint = table.buttonGreen() ? 'G' : fillCharacter;
char redPrint = table.buttonRed() ? 'R' : fillCharacter;
char bluePrint = table.buttonBlue() ? 'B' : fillCharacter;
const char greenPrint = table.buttonGreen() ? 'G' : fillCharacter;
const char redPrint = table.buttonRed() ? 'R' : fillCharacter;
const char bluePrint = table.buttonBlue() ? 'B' : fillCharacter;

char buffer[15];
sprintf(buffer,
snprintf(buffer, sizeof(buffer),
" T%c:%3d %c%c%c",
idPrint,
table.turntable(),
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/DrawsomeTablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ boolean DrawsomeTablet_Shared::penDetected() const {
void DrawsomeTablet_Shared::printDebug(Print& output) const {
char buffer[60];

char penPrint = penDetected() ? 'Y' : 'N';
const char penPrint = penDetected() ? 'Y' : 'N';

output.print("DrawsomeTablet - ");
sprintf(buffer,
snprintf(buffer, sizeof(buffer),
"Pen:(%6u, %6u) | Pressure:%4u | Pen Detect:%c",
penX(), penY(), penPressure(), penPrint);

Expand Down
18 changes: 9 additions & 9 deletions src/controllers/DrumController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ void DrumController_Shared::printDebug(Print& output) const {

output.print("Drums: ");

char redPrint = drumRed() ? 'R' : fillCharacter;
char bluePrint = drumBlue() ? 'B' : fillCharacter;
char greenPrint = drumGreen() ? 'G' : fillCharacter;
const char redPrint = drumRed() ? 'R' : fillCharacter;
const char bluePrint = drumBlue() ? 'B' : fillCharacter;
const char greenPrint = drumGreen() ? 'G' : fillCharacter;

char yellowPrint = cymbalYellow() ? 'Y' : fillCharacter;
char orangePrint = cymbalOrange() ? 'O' : fillCharacter;
const char yellowPrint = cymbalYellow() ? 'Y' : fillCharacter;
const char orangePrint = cymbalOrange() ? 'O' : fillCharacter;

char pedalPrint = bassPedal() ? 'P' : fillCharacter;
const char pedalPrint = bassPedal() ? 'P' : fillCharacter;

uint8_t velocityPrint = 0;
char velocityIDPrint = fillCharacter;
Expand Down Expand Up @@ -199,10 +199,10 @@ void DrumController_Shared::printDebug(Print& output) const {
}
}

char plusPrint = buttonPlus() ? '+' : fillCharacter;
char minusPrint = buttonMinus() ? '-' : fillCharacter;
const char plusPrint = buttonPlus() ? '+' : fillCharacter;
const char minusPrint = buttonMinus() ? '-' : fillCharacter;

sprintf(buffer,
snprintf(buffer, sizeof(buffer),
"%c\\%c%c%c/%c %c | V:%1u for %c | %c%c | Joy:(%2u, %2u)",
yellowPrint, redPrint, bluePrint, greenPrint, orangePrint, pedalPrint,
velocityPrint, velocityIDPrint,
Expand Down
30 changes: 15 additions & 15 deletions src/controllers/GuitarController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ void GuitarController_Shared::printDebug(Print& output) {
strumPrint = 'v';
}

char greenPrint = fretGreen() ? 'G' : fillCharacter;
char redPrint = fretRed() ? 'R' : fillCharacter;
char yellowPrint = fretYellow() ? 'Y' : fillCharacter;
char bluePrint = fretBlue() ? 'B' : fillCharacter;
char orangePrint = fretOrange() ? 'O' : fillCharacter;
const char greenPrint = fretGreen() ? 'G' : fillCharacter;
const char redPrint = fretRed() ? 'R' : fillCharacter;
const char yellowPrint = fretYellow() ? 'Y' : fillCharacter;
const char bluePrint = fretBlue() ? 'B' : fillCharacter;
const char orangePrint = fretOrange() ? 'O' : fillCharacter;

sprintf(buffer,
snprintf(buffer, sizeof(buffer),
"%c | %c%c%c%c%c | W:%2u ",
strumPrint,
greenPrint, redPrint, yellowPrint, bluePrint, orangePrint,
Expand All @@ -161,13 +161,13 @@ void GuitarController_Shared::printDebug(Print& output) {

// Touchbar, if World Controller
if (supportsTouchbar()) {
greenPrint = touchGreen() ? 'G' : fillCharacter;
redPrint = touchRed() ? 'R' : fillCharacter;
yellowPrint = touchYellow() ? 'Y' : fillCharacter;
bluePrint = touchBlue() ? 'B' : fillCharacter;
orangePrint = touchOrange() ? 'O' : fillCharacter;
const char greenPrint = touchGreen() ? 'G' : fillCharacter;
const char redPrint = touchRed() ? 'R' : fillCharacter;
const char yellowPrint = touchYellow() ? 'Y' : fillCharacter;
const char bluePrint = touchBlue() ? 'B' : fillCharacter;
const char orangePrint = touchOrange() ? 'O' : fillCharacter;

sprintf(buffer,
snprintf(buffer, sizeof(buffer),
"Touch:%2u - %c%c%c%c%c | ",
touchbar(),
greenPrint, redPrint, yellowPrint, bluePrint, orangePrint);
Expand All @@ -176,10 +176,10 @@ void GuitarController_Shared::printDebug(Print& output) {
}

// Joy + Plus/Minus
char plusPrint = buttonPlus() ? '+' : fillCharacter;
char minusPrint = buttonMinus() ? '-' : fillCharacter;
const char plusPrint = buttonPlus() ? '+' : fillCharacter;
const char minusPrint = buttonMinus() ? '-' : fillCharacter;

sprintf(buffer,
snprintf(buffer, sizeof(buffer),
"%c%c | Joy:(%2u, %2u)",
minusPrint, plusPrint,
joyX(), joyY());
Expand Down
11 changes: 7 additions & 4 deletions src/controllers/Nunchuk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,16 @@ float Nunchuk_Shared::pitchAngle() const {
}

void Nunchuk_Shared::printDebug(Print& output) const {
char buffer[60];
// 59 characters, 1 terminating null, and 7 extra so the compiler stops
// complaining about not having enough buffer space for the full 16 bit
// values (5 characters each) that can fit in the type
char buffer[67];

char cPrint = buttonC() ? 'C' : '-';
char zPrint = buttonZ() ? 'Z' : '-';
const char cPrint = buttonC() ? 'C' : '-';
const char zPrint = buttonZ() ? 'Z' : '-';

output.print("Nunchuk - ");
sprintf(buffer,
snprintf(buffer, sizeof(buffer),
"Joy:(%3u, %3u) | Accel XYZ:(%4u, %4u, %4u) | Buttons: %c%c",
joyX(), joyY(), accelX(), accelY(), accelZ(), cPrint, zPrint);

Expand Down
21 changes: 12 additions & 9 deletions src/controllers/uDrawTablet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ constexpr ByteMap uDrawTablet_Shared::Maps::PenY_MSB;
constexpr IndexMap uDrawTablet_Shared::Maps::Pressure_LSB;
constexpr BitMap uDrawTablet_Shared::Maps::Pressure_MSB;

constexpr BitMap uDrawTablet_Shared::Maps::buttonLower;
constexpr BitMap uDrawTablet_Shared::Maps::buttonUpper;
constexpr BitMap uDrawTablet_Shared::Maps::ButtonLower;
constexpr BitMap uDrawTablet_Shared::Maps::ButtonUpper;

uint16_t uDrawTablet_Shared::penX() const {
return (getControlData(Maps::PenX_MSB) << 8) | getControlData(Maps::PenX_LSB);
Expand All @@ -48,26 +48,29 @@ uint16_t uDrawTablet_Shared::penPressure() const {
}

boolean uDrawTablet_Shared::buttonLower() const {
return getControlBit(Maps::buttonLower);
return getControlBit(Maps::ButtonLower);
}

boolean uDrawTablet_Shared::buttonUpper() const {
return getControlBit(Maps::buttonUpper);
return getControlBit(Maps::ButtonUpper);
}

boolean uDrawTablet_Shared::penDetected() const {
return penX() < 4095 && penY() < 4095;
}

void uDrawTablet_Shared::printDebug(Print& output) const {
char buffer[60];
// 59 characters, 1 terminating null, and 4 extra so the compiler stops
// complaining about not having enough buffer space for the full 16 bit
// values (5 characters each) that can fit in the type
char buffer[64];

char penPrint = penDetected() ? 'Y' : 'N';
char lowerPrint = buttonLower() ? 'L' : '-';
char upperPrint = buttonUpper() ? 'U' : '-';
const char penPrint = penDetected() ? 'Y' : 'N';
const char lowerPrint = buttonLower() ? 'L' : '-';
const char upperPrint = buttonUpper() ? 'U' : '-';

output.print("uDrawTablet - ");
sprintf(buffer,
snprintf(buffer, sizeof(buffer),
"Pen:(%4u, %4u) | Pressure:%3u | Pen Detect:%c | Buttons:%c%c",
penX(), penY(), penPressure(), penPrint, lowerPrint, upperPrint);

Expand Down
4 changes: 2 additions & 2 deletions src/controllers/uDrawTablet.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ namespace NintendoExtensionCtrl {
constexpr static IndexMap Pressure_LSB = 3;

constexpr static BitMap Pressure_MSB = { 5, 2 };
constexpr static BitMap buttonLower = { 5, 1 };
constexpr static BitMap buttonUpper = { 5, 0 };
constexpr static BitMap ButtonLower = { 5, 1 };
constexpr static BitMap ButtonUpper = { 5, 0 };
};

uDrawTablet_Shared(ExtensionData &dataRef) :
Expand Down

0 comments on commit 9b0b087

Please sign in to comment.