c++ header files are .hh

This commit is contained in:
Neale Pickett 2023-12-31 20:33:29 -07:00
parent d5b1addddc
commit 8622cfdef0
6 changed files with 52 additions and 26 deletions

View File

@ -2,14 +2,20 @@
#include <Arduino.h>
#include <PluggableUSB.h>
#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;
}
}

View File

@ -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.

View File

View File