Expose API for controlling the left and right rumble individually

This commit is contained in:
Kristian Sloth Lauszus 2021-05-02 22:34:49 +02:00
parent 2501f4c2e3
commit 7e96d9fb09
2 changed files with 40 additions and 20 deletions

View file

@ -185,25 +185,43 @@ public:
/** Set rumble off. */
void setRumbleOff() {
setRumbleOn(0, 0);
setRumble(false, false);
}
/** Toggle rumble. */
void setRumbleToggle() {
setRumbleOn(!switchProOutput.leftRumbleOn, !switchProOutput.rightRumbleOn);
setRumble(!switchProOutput.leftRumbleOn, !switchProOutput.rightRumbleOn);
}
/**
* Turn on rumble.
* @param leftRumbleOn Turn on left rumble motor.
* @param rightRumbleOn Turn on right rumble motor.
* Turn on/off rumble.
* @param leftRumbleOn Turn on/off left rumble motor.
* @param rightRumbleOn Turn on/off right rumble motor.
*/
void setRumbleOn(bool leftRumbleOn, bool rightRumbleOn) {
void setRumble(bool leftRumbleOn, bool rightRumbleOn) {
switchProOutput.leftRumbleOn = leftRumbleOn;
switchProOutput.rightRumbleOn = rightRumbleOn;
switchProOutput.ledReportChanged = true; // Set this, so the rumble effect gets changed immediately
}
/**
* Turn on/off the left rumble.
* @param on Turn on/off left rumble motor.
*/
void setRumbleLeft(bool on) {
switchProOutput.leftRumbleOn = on;
switchProOutput.ledReportChanged = true; // Set this, so the rumble effect gets changed immediately
}
/**
* Turn on/off the right rumble.
* @param on Turn on/off right rumble motor.
*/
void setRumbleRight(bool on) {
switchProOutput.rightRumbleOn = on;
switchProOutput.ledReportChanged = true; // Set this, so the rumble effect gets changed immediately
}
/**
* Set LED value without using the ::LEDEnum.
* This can also be used to flash the LEDs by setting the high 4-bits of the mask.

View file

@ -73,7 +73,7 @@ void loop() {
Serial.print(F("\r\nCapture"));
if (SwitchPro.getButtonClick(HOME)) {
Serial.print(F("\r\nHome"));
SwitchPro.setLedHomeToggle(); // Toggle the home LED
SwitchPro.setLedHomeToggle();
}
if (SwitchPro.getButtonClick(LEFT)) {
@ -102,29 +102,31 @@ void loop() {
if (SwitchPro.getButtonClick(MINUS))
Serial.print(F("\r\nMinus"));
if (SwitchPro.getButtonClick(A)) {
SwitchPro.setRumbleOn(false, true); // Turn on the right rumble motor
if (SwitchPro.getButtonClick(A))
Serial.print(F("\r\nA"));
}
if (SwitchPro.getButtonClick(B)) {
SwitchPro.setRumbleOn(true, false); // Turn on the left rumble motor
if (SwitchPro.getButtonClick(B))
Serial.print(F("\r\nB"));
}
if (SwitchPro.getButtonClick(X))
Serial.print(F("\r\nX"));
if (SwitchPro.getButtonClick(Y)) {
SwitchPro.setRumbleOn(false, false);
if (SwitchPro.getButtonClick(Y))
Serial.print(F("\r\nY"));
}
if (SwitchPro.getButtonClick(L))
if (SwitchPro.getButtonClick(L)) {
SwitchPro.setRumbleLeft(false);
Serial.print(F("\r\nL"));
if (SwitchPro.getButtonClick(R))
}
if (SwitchPro.getButtonClick(R)) {
SwitchPro.setRumbleRight(false);
Serial.print(F("\r\nR"));
if (SwitchPro.getButtonClick(ZL))
}
if (SwitchPro.getButtonClick(ZL)) {
SwitchPro.setRumbleLeft(true);
Serial.print(F("\r\nZL"));
if (SwitchPro.getButtonClick(ZR))
}
if (SwitchPro.getButtonClick(ZR)) {
SwitchPro.setRumbleRight(true);
Serial.print(F("\r\nZR"));
}
if (SwitchPro.getButtonClick(L3))
Serial.print(F("\r\nL3"));
if (SwitchPro.getButtonClick(R3))