Working on controller detection logic. I will support Nunchucks too.
The adapter is now able to detect the presence of either the Classic controller or the Nunchuck and react accordingly (hot-plugging) without adding overhead to the sampling (aka multiple readings).
/* Stingray - Controller Logic */
#include <NintendoExtensionCtrl.h>
ExtensionPort controller;
Nunchuk::Shared nchuk(controller); // Read Nunchuk formatted data from the port
ClassicController::Shared classic(controller); // Read Classic Controller formatted data from the port
void setup() {
Serial.begin(9600);
controller.begin();
}
void loop() {
if (controller.connect()) { // valid controller was connected
while (controller.update()) {
ExtensionType conType = controller.getControllerType();
switch (conType) {
case (ExtensionType::Nunchuk):
mapNunchuckData();
break;
case (ExtensionType::ClassicController):
mapClassicData();
break;
default:
Serial.println("Other controller connected!");
disableOutputs();
} // Switch
processControllerData();
} // while
disableOutputs();
} else { // Controller not connected}
Serial.println("No controller found!");
disableOutputs();
}
delay(200);
}
void disableOutputs() {
Serial.println("Disable Outputs");
}
void processControllerData() {
Serial.println("Process Data");
}
void mapNunchuckData() {
nchuk.printDebug();
}
void mapClassicData() {
classic.printDebug();
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.