Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for the legacy rumble mode #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Support for the legacy rumble mode
This mode is present on the japanese SCPH-1150 and uses a single motor.
Both DualShock and DualShock2 supports this rumble mode.
Entering config mode will disable this mode on the controller and it will require a power cycle to be used again.
`MOTOR_OLD_1` and `MOTOR_OLD_2` constants can be changed but some bits must be set. I've set a note on this.
sonik-br authored Mar 1, 2023
commit e508505bee949e3801beede1026d43b138d5ff6c
35 changes: 32 additions & 3 deletions src/PsxNewLib.h
Original file line number Diff line number Diff line change
@@ -68,6 +68,20 @@ const unsigned long COMMAND_RETRY_INTERVAL = 10;
*/
const unsigned long MODE_SWITCH_DELAY = 500;

/** \brief Motor value for old rumble method.
*
* If changing this value: bit7 must be clear, bit6 mut be set.
* 7.5v must be supplied to pin 3!
*/
const byte MOTOR_OLD_1 = 0x40;

/** \brief Motor value for old rumble method.
*
* If changing this value: bit0 must be set.
* 7.5v must be supplied to pin 3!
*/
const byte MOTOR_OLD_2 = 0x01;


/** \brief Type that is used to represent a single button in most places
*/
@@ -738,13 +752,28 @@ class PsxController {
* This function sets internal variables that set the requested motor power of the rumble motors.
* NOTE this does nothing if rumble has not been enabled with enableRumble(), rumble motors will
* activate or deactivate to match the arguments of this function with the next call to read()
*
* NOTE it's possible to use single motor rumble on the japanese SCPH-1150.
* DualShock is also backwards compatible with this mode. This function will use the "old rumble"
* when rumbleEnabled is not set. After entering Config Mode, the old rumble will not work
* anymore until the controller is powered off and on again.
*
* \param[in] enabled true to activate motor 1, false to deactivate.
* \param[in] requested motor power of motor 2, where 0x00 to 0xFF corresponds to 0 to 100%.
*/
void setRumble(bool motor1Active = true, byte motor2Power = 0xff) {
motor1Level = motor1Active ? 0xff : 0x00;
motor2Level = motor2Power;
if (rumbleEnabled) {
motor1Level = motor1Active ? 0xff : 0x00;
motor2Level = motor2Power;
} else { //Old rumble method. Single motor
if (motor1Active) {
motor1Level = MOTOR_OLD_1;
motor2Level = MOTOR_OLD_2;
} else {
motor1Level = 0x0;
motor2Level = 0x0;
}
}
}

/** \brief Enable (or disable) analog buttons
@@ -898,7 +927,7 @@ class PsxController {

attention ();
byte *in = nullptr;
if(rumbleEnabled) {
if(rumbleEnabled || (motor1Level == MOTOR_OLD_1 && motor2Level == MOTOR_OLD_2)) {
byte out[sizeof (poll)];
memcpy(out, poll, sizeof(poll));
out[3] = motor1Level;