diff --git a/WiiGuitarController.ino b/MockBand.ino similarity index 76% rename from WiiGuitarController.ino rename to MockBand.ino index f93ba1b..0307471 100644 --- a/WiiGuitarController.ino +++ b/MockBand.ino @@ -2,14 +2,20 @@ #include #include -#include "hid.h" // Modified HID library: doesn't prefix each packet with ID -#include "instrument.h" +#include "hid.hh" // Modified HID library: doesn't prefix each packet with ID +#include "instrument.hh" -//#include "blue.h" // Ginnie's blue guitar -#include "standard.h" // Standard pins +//#include "blue.hh" // Ginnie's blue guitar +#include "standard.hh" // Standard pins + +// How often do you want to send an update? +// Bigger number: lower latency, but more bounces +// Smaller number: higher latency +// 50Hz feels pretty good to me +#define UPDATE_FREQ_HZ 50 +#define UPDATE_INTERVAL_MS (1000 / UPDATE_FREQ_HZ) InstrumentButtonState buttonState; -InstrumentButtonState lastState; void setup() { pinMode(STRUM_DOWN, INPUT_PULLUP); @@ -49,10 +55,12 @@ void setup() { // and hope we don't miss anything while we're doing USB stuff. void loop() { register uint16_t buttons = 0; - register uint16_t buttons_prior = 0; + unsigned long next = 0; while (1) { - buttons = (0 + unsigned long now = millis(); + + buttons |= ~(0 | (digitalRead(BUTTON_BLUE) << 0) | (digitalRead(BUTTON_GREEN) << 1) | (digitalRead(BUTTON_RED) << 2) @@ -70,36 +78,28 @@ void loop() { | (digitalRead(SOLO_ORANGE) << 14) // Not in USB packet ); - if (buttons == buttons_prior) { + if (now < next) { continue; } - buttons_prior = buttons; - - // Open pullup reads 1, so invert everything we've read - buttons = ~buttons; + next = now + 20; buttonState.buttons = (buttons & 0b1100111111); // All directly-mappable bits buttonState.buttons |= ((buttons >> 10) & 0b11111); // Solo keys bitWrite(buttonState.buttons, 6, (buttons >> 10) & 0b11111); // Solo bit // I don't understand why any rational engineer would have done this. - if (bitRead(buttons, 6)) { - buttonState.hatAndConstant = 0x00; // up - } else if (false) { - buttonState.hatAndConstant = 0x02; // right - } else if (bitRead(buttons, 7)) { - buttonState.hatAndConstant = 0x04; // down - } else if (false) { - buttonState.hatAndConstant = 0x06; // left - } else { - buttonState.hatAndConstant = 0x08; // nothing - } + buttonState.hatAndConstant = (0x08 + ^ (bitRead(buttons, 6) << 4) // up + // right << 3 + ^ (bitRead(buttons, 7) << 2) // down + // left << 1 + ); buttonState.axis[2] = analogRead(ANALOG_WAMMY) / 4; // Send an update HID().SendReport(0, (uint8_t *)&buttonState, 27); - + buttons = 0; } } diff --git a/README.md b/README.md index bd2be41..0e3a943 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,28 @@ -# WiiGuitarController -Microcontroller Firmware to emulate guitar controllers from the Wii version of the Rock Band games +# Mock Band + +Microcontroller Firmware to emulate guitar and drum kit controllers from the +Wii version of the Rock Band games. + +This is based on the foundational work done by Nicholas Angle on the +[Wii Guitar Controller](https://github.com/NianZo/WiiGuitarController) +([text article](https://www.niangames.com/articles/reverse-engineering-rockband-guitar-controllers)). +All I did was speed up the loop code to detect drum pad strikes, +which are very quick! + + +# Parts Needed + +* A [Sparkfun Pro Micro](https://www.sparkfun.com/products/12640) +* A physical controller + + +## Sample controllers + +I used the following: + +* [MiniCaster](https://www.printables.com/model/479046-minicaster-mini-clone-heromidi-controller) + by Vlad the Inhaler: + it comes with full build instructions. + +* [Cheap children's drum toy](https://www.amazon.com/Electronic-Sboet-Practice-Headphone-Christmas/dp/B0CHJMYCH9/), + each pad is a momentary switch. diff --git a/blue.h b/blue.hh similarity index 100% rename from blue.h rename to blue.hh diff --git a/hid.h b/hid.hh similarity index 100% rename from hid.h rename to hid.hh diff --git a/instrument.h b/instrument.hh similarity index 100% rename from instrument.h rename to instrument.hh diff --git a/standard.h b/standard.hh similarity index 100% rename from standard.h rename to standard.hh