-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
396 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <NintendoExtensionCtrl.h> | ||
|
||
GuitarController guitar; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
while (!guitar.begin()) { | ||
Serial.println("Guitar controller not detected!"); | ||
delay(1000); | ||
} | ||
} | ||
|
||
void loop() { | ||
boolean success = guitar.update(); // Get new data from the controller | ||
|
||
if (success == true) { // We've got data! | ||
guitar.printDebug(); // Print all of the values! | ||
} | ||
else { // Data is bad :( | ||
Serial.println("Controller Disconnected!"); | ||
guitar.reconnect(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#include <NintendoExtensionCtrl.h> | ||
|
||
GuitarController guitar; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
while (!guitar.begin()) { | ||
Serial.println("Guitar controller not detected!"); | ||
delay(1000); | ||
} | ||
} | ||
|
||
void loop() { | ||
Serial.println("----- Guitar Controller Demo -----"); // Making things easier to read | ||
|
||
boolean success = guitar.update(); // Get new data from the controller | ||
|
||
if (!success) { // Ruh roh | ||
Serial.println("Controller disconnected!"); | ||
delay(1000); | ||
} | ||
else { | ||
// Read the strum bar (up/down, or neither) | ||
Serial.print("The strum bar is "); | ||
|
||
if (guitar.strumUp()) { | ||
Serial.println("pressed up"); | ||
} | ||
else if (guitar.strumDown()) { | ||
Serial.println("pressed down"); | ||
} | ||
else { | ||
Serial.println("not pressed"); | ||
} | ||
|
||
// Read the fret buttons (Green, Red, Yellow, Blue, Orange) | ||
boolean green = guitar.fretGreen(); | ||
|
||
Serial.print("The green fret button is "); | ||
if (green == 1) { | ||
Serial.println("pressed"); | ||
} | ||
else if (green == 0) { | ||
Serial.println("released"); | ||
} | ||
|
||
// Read the touchbar (if the controller has one) | ||
if (guitar.supportsTouchbar()) { | ||
|
||
// Touchbar raw value (0-31) | ||
uint8_t touchbarValue = guitar.touchbar(); | ||
|
||
Serial.print("The touchbar is at "); | ||
Serial.println(touchbarValue); | ||
|
||
// Touchbar zones (Green, Red, Yellow, Blue, Orange) | ||
boolean touchGreen = guitar.touchGreen(); | ||
|
||
Serial.print("The green touch zone is "); | ||
if (touchGreen == 1) { | ||
Serial.println("pressed"); | ||
} | ||
else if (touchGreen == 0) { | ||
Serial.println("not pressed"); | ||
} | ||
} | ||
|
||
// Read the whammy bar (0-31) | ||
uint8_t whammy = guitar.whammyBar(); | ||
|
||
Serial.print("The whammy bar's position is "); | ||
Serial.println(whammy); | ||
|
||
// Read the joystick axis (0-63 XY) | ||
int joyVal = guitar.joyX(); | ||
|
||
Serial.print("The joystick's X axis is at "); | ||
Serial.println(joyVal); | ||
|
||
// Read a button (Plus/Minus) | ||
boolean plusButton = guitar.buttonPlus(); | ||
|
||
Serial.print("The plus button is "); | ||
if (plusButton == 1) { | ||
Serial.println("pressed"); | ||
} | ||
else if (plusButton == 0) { | ||
Serial.println("released"); | ||
} | ||
|
||
// Print all the values! | ||
guitar.printDebug(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* | ||
* Project Nintendo Extension Controller Library | ||
* @author David Madison | ||
* @link github.com/dmadison/NintendoExtensionCtrl | ||
* @license LGPLv3 - Copyright (c) 2018 David Madison | ||
* | ||
* This file is part of the Nintendo Extension Controller Library. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "GuitarController.h" | ||
|
||
GuitarController::GuitarController() : ExtensionController(NXC_GuitarController, 6) {} | ||
|
||
uint8_t GuitarController::joyX() { | ||
return controlData[0] & 0x3F; | ||
} | ||
|
||
uint8_t GuitarController::joyY() { | ||
return controlData[1] & 0x3F; | ||
} | ||
|
||
boolean GuitarController::strum() { | ||
return strumUp() | strumDown(); | ||
} | ||
|
||
boolean GuitarController::strumUp() { | ||
return extractBit(5, 0); | ||
} | ||
|
||
boolean GuitarController::strumDown() { | ||
return extractBit(4, 6); | ||
} | ||
|
||
boolean GuitarController::fretGreen() { | ||
return extractBit(5, 4); | ||
} | ||
|
||
boolean GuitarController::fretRed() { | ||
return extractBit(5, 6); | ||
} | ||
|
||
boolean GuitarController::fretYellow() { | ||
return extractBit(5, 3); | ||
} | ||
|
||
boolean GuitarController::fretBlue() { | ||
return extractBit(5, 5); | ||
} | ||
|
||
boolean GuitarController::fretOrange() { | ||
return extractBit(5, 7); | ||
} | ||
|
||
uint8_t GuitarController::whammyBar() { | ||
return controlData[3] & 0x1F; | ||
} | ||
|
||
uint8_t GuitarController::touchbar() { | ||
return controlData[2] & 0x1F; | ||
} | ||
|
||
boolean GuitarController::touchGreen() { | ||
return touchbar() != 0 && touchbar() <= 7; | ||
} | ||
|
||
boolean GuitarController::touchRed() { | ||
return touchbar() >= 7 && touchbar() <= 13; | ||
} | ||
|
||
boolean GuitarController::touchYellow() { | ||
return touchbar() >= 12 && touchbar() <= 21 | ||
&& touchbar() != 15; // The "not touched" value | ||
} | ||
|
||
boolean GuitarController::touchBlue() { | ||
return touchbar() >= 20 && touchbar() <= 26; | ||
} | ||
|
||
boolean GuitarController::touchOrange() { | ||
return touchbar() >= 26; | ||
} | ||
|
||
boolean GuitarController::buttonPlus() { | ||
return extractBit(4, 2); | ||
} | ||
|
||
boolean GuitarController::buttonMinus() { | ||
return extractBit(4, 4); | ||
} | ||
|
||
boolean GuitarController::supportsTouchbar() { | ||
if (touchbarData) { | ||
return true; | ||
} | ||
else if (touchbar() > 0) { | ||
touchbarData = true; | ||
} | ||
return false; | ||
} | ||
|
||
void GuitarController::printDebug(Stream& stream) { | ||
const char fillCharacter = '_'; | ||
|
||
char buffer[20]; | ||
|
||
stream.print("Guitar: "); | ||
|
||
// Strum + Fret Buttons | ||
char strumPrint = fillCharacter; | ||
if (strumUp()) { | ||
strumPrint = '^'; | ||
} | ||
else if (strumDown()) { // Mutually exclusive | ||
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; | ||
|
||
sprintf(buffer, | ||
"%c | %c%c%c%c%c | ", | ||
strumPrint, | ||
greenPrint, redPrint, yellowPrint, bluePrint, orangePrint); | ||
stream.print(buffer); | ||
buffer[0] = 0; | ||
|
||
// 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; | ||
|
||
sprintf(buffer, | ||
"Touch:%2u - %c%c%c%c%c | ", | ||
touchbar(), | ||
greenPrint, redPrint, yellowPrint, bluePrint, orangePrint); | ||
stream.print(buffer); | ||
buffer[0] = 0; | ||
} | ||
|
||
// Joy + Plus/Minus | ||
char plusPrint = buttonPlus() ? '+' : fillCharacter; | ||
char minusPrint = buttonMinus() ? '-' : fillCharacter; | ||
|
||
sprintf(buffer, | ||
"%c%c | Joy:(%2u, %2u)", | ||
plusPrint, minusPrint, | ||
joyX(), joyY()); | ||
stream.println(buffer); | ||
} |
Oops, something went wrong.