Skip to content

Commit

Permalink
GamepadAuxState functionality (#1084)
Browse files Browse the repository at this point in the history
* Started implementation of GamepadAuxState to store values that are outside of normal Gamepad button/analog functions, such as IMU (accelerometer, gyroscope) and rumble state.

* Added gyroscope values for future Wii Motion Plus implementation.

* Reduced additional PS sensor fields until necessary.
Renamed PS gyro_accel_misc to sensor_data.
Changed sensor fields to u16.

* Refactored Wii data handler & added Motion Plus support

* Implemented rumble, gyro, and accelerometer data structure usage if enabled

* Refactor how Motion Plus and standard Extensions are detected. Prioritize Motion Plus if both are available.

* Added missing report types and OUT report endpoint to PS4.

* Added UDraw Wii Tablet support to WiiExtension library

* Implemented touch counter for PS4 touchpad usage.

* Added "active" state to Aux sensors to be used when a sensor is enabled, but not actively sending data.

* Added sensor types for relative values

* Added A3 & A4 button bindings to keyboard host
Keyboard host now implements mouse bindings for left, middle, right buttons
Relative mouse movements stored in the GamepadAux mouse sensor for later usage
Added exclusion list for KeyboardMapper control to filter out unused entries

* Temporarily removed GamepadAuxState from gamepad.h to resolve conflict

* Removed blank space for resolving merge

* Reimplemented GamepadAuxState in gamepad.h

* Changed length checks on PS4 get reports to return max of request value and array size.

* Replaced GamepadRumbleState with GamepadAuxHaptics structures.
Implemented haptics control in PS4 and OGXbox modes.

* Fix indentation on PS4 descriptors. Comment out debug outputs.

* Added WiiExtension wrapper for new I2C interface
Fixed initial states for MotionPlus gyro

* Added PS4 accelerometer and gyrometer known range values

* DS3 additions

* Removed HID report repeating as this could cause incorrect report parsing to occur

* Removed old quirks mode PS3 descriptors in favor of DS3 specific ones.
This change would make PS3 mode specifically PS3, and standard HID/"DInput" should no longer use this mode. Still to do: better define and explain what each report blob is used for.

* Updated PS3/PS4 device constants to not conflict with HID defines.
Included state checking for Aux gyro and accel sensors.

* Remove USB report repeat sample code

* Added haptic enable state checks on most modes supporting it

* Clean up debug code for PS4 expansion

* Fix tabs for keyboard host mouse definitions

* Started cleaning up naming of PS3 report IDs for documentation.
Removed btaddr values for actual PS3 devices.

* Removed hard-coded data for BT device details (0xF2) in favor of a data struct.
Randomized BT addresses on start for 0xF2 and 0xF5 reports.

* Update all drivers to remove feature data parameter in process().
Added player ID & LED data to main Aux structure.
Set default values of zero on integer Aux values.
Deprecated Storage::*FeatureData methods in favor of Aux values.

* Updated DRV8833 to validate left/right motor pins and enable the Aux haptics if valid.

* Aligned forced player number to new Aux storage, but functionally still not working as expected.

* Updated XInput, PS3 & PS4 feature outputs to store LED & rumble status on processed gamepad.

* Added new speed settings and a custom blink timing mode to PlayerLEDs.
Added on/off blink timing to DS4 lightbar usage in RGB PLEDs.

* Added PS4 configuration switch between Console and Emulation modes

* Added PS4 ID mode help text and included option in PS5 mode.

* Removed XInput reference from Player LED as other modes now make use of it.

* Set active state to true when Wii gyro/accel sensors are being fed data
  • Loading branch information
mikepparks authored Sep 17, 2024
1 parent 1848523 commit 32be222
Show file tree
Hide file tree
Showing 75 changed files with 2,603 additions and 727 deletions.
3 changes: 2 additions & 1 deletion headers/addons/drv8833_rumble.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string>
#include "gpaddon.h"
#include "gamepad/GamepadState.h"
#include "gamepad/GamepadAuxState.h"

#ifndef DRV8833_RUMBLE_ENABLED
#define DRV8833_RUMBLE_ENABLED 0
Expand Down Expand Up @@ -68,7 +69,7 @@ class DRV8833RumbleAddon : public GPAddon
float dutyMin;
float dutyMax;
uint32_t sysClock;
GamepadRumbleState currentRumbleState;
GamepadAuxHaptics currentRumbleState;
};

#endif
17 changes: 17 additions & 0 deletions headers/addons/keyboard_host_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class KeyboardHostListener : public USBListener {
GamepadState _keyboard_host_state;
bool _keyboard_host_enabled;
uint8_t getKeycodeFromModifier(uint8_t modifier);
void preprocess_report();
void process_kbd_report(uint8_t dev_addr, hid_keyboard_report_t const *report);
void process_mouse_report(uint8_t dev_addr, hid_mouse_report_t const *report);

KeyboardButtonMapping _keyboard_host_mapDpadUp;
KeyboardButtonMapping _keyboard_host_mapDpadDown;
Expand All @@ -58,9 +60,24 @@ class KeyboardHostListener : public USBListener {
KeyboardButtonMapping _keyboard_host_mapButtonR3;
KeyboardButtonMapping _keyboard_host_mapButtonA1;
KeyboardButtonMapping _keyboard_host_mapButtonA2;
KeyboardButtonMapping _keyboard_host_mapButtonA3;
KeyboardButtonMapping _keyboard_host_mapButtonA4;

uint8_t _keyboard_dev_addr;
uint8_t _keyboard_instance;

bool _mouse_host_enabled;
uint8_t _mouse_dev_addr;
uint8_t _mouse_instance;

uint16_t mouseLeftMapping;
uint16_t mouseMiddleMapping;
uint16_t mouseRightMapping;

int16_t mouseX = 0;
int16_t mouseY = 0;
int16_t mouseZ = 0;
bool mouseActive = false;
};

#endif // _KeyboardHost_H_
39 changes: 39 additions & 0 deletions headers/addons/wiiext.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,28 @@ class WiiExtensionInput : public GPAddon {
}
}
},
{
WiiExtensionController::WII_EXTENSION_DRAWSOME,
{
{
{WiiButtons::WII_BUTTON_A, GAMEPAD_MASK_B2},
{WiiButtons::WII_BUTTON_L, GAMEPAD_MASK_L2},
{WiiButtons::WII_BUTTON_R, GAMEPAD_MASK_R2},
},
{}
}
},
{
WiiExtensionController::WII_EXTENSION_UDRAW,
{
{
{WiiButtons::WII_BUTTON_A, GAMEPAD_MASK_B2},
{WiiButtons::WII_BUTTON_L, GAMEPAD_MASK_L2},
{WiiButtons::WII_BUTTON_R, GAMEPAD_MASK_R2},
},
{}
}
},
};
WiiExtensionConfig* currentConfig = NULL;

Expand All @@ -295,6 +317,9 @@ class WiiExtensionInput : public GPAddon {
bool dpadRight = false;

bool isAnalogTriggers = false;
bool isGyroscope = false;
bool isAccelerometer = false;
bool isTouch = false;

uint16_t triggerLeft = 0;
uint16_t triggerRight = 0;
Expand All @@ -314,6 +339,19 @@ class WiiExtensionInput : public GPAddon {
uint16_t rightY = 0;
uint16_t lastRightY = 0;

uint16_t accelerometerX = 0;
uint16_t accelerometerY = 0;
uint16_t accelerometerZ = 0;

uint16_t gyroscopeX = 0;
uint16_t gyroscopeY = 0;
uint16_t gyroscopeZ = 0;

uint16_t touchX = 0;
uint16_t touchY = 0;
uint16_t touchZ = 0;
bool touchPressed = false;

std::map<uint16_t, std::vector<WiiAnalogChange>> analogChanges = {
{WII_ANALOG_TYPE_LEFT_STICK_X,{}},
{WII_ANALOG_TYPE_LEFT_STICK_Y,{}},
Expand Down Expand Up @@ -344,6 +382,7 @@ class WiiExtensionInput : public GPAddon {
void setButtonState(bool buttonState, uint16_t buttonMask);
void queueAnalogChange(uint16_t analogInput, uint16_t analogValue, uint16_t lastAnalogValue);
void updateAnalogState();
void updateMotionState();
void reloadConfig();

uint16_t getAverage(std::vector<WiiAnalogChange> const& changes);
Expand Down
2 changes: 1 addition & 1 deletion headers/drivers/astro/AstroDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class AstroDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual void process(Gamepad * gamepad);
virtual void initializeAux() {}
virtual void processAux() {}
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
Expand Down
2 changes: 1 addition & 1 deletion headers/drivers/egret/EgretDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class EgretDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual void process(Gamepad * gamepad);
virtual void initializeAux() {}
virtual void processAux() {}
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
Expand Down
2 changes: 1 addition & 1 deletion headers/drivers/hid/HIDDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class HIDDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual void process(Gamepad * gamepad);
virtual void initializeAux() {}
virtual void processAux() {}
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
Expand Down
2 changes: 1 addition & 1 deletion headers/drivers/keyboard/KeyboardDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class KeyboardDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual void process(Gamepad * gamepad);
virtual void initializeAux() {}
virtual void processAux() {}
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
Expand Down
2 changes: 1 addition & 1 deletion headers/drivers/mdmini/MDMiniDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class MDMiniDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual void process(Gamepad * gamepad);
virtual void initializeAux() {}
virtual void processAux() {}
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
Expand Down
2 changes: 1 addition & 1 deletion headers/drivers/neogeo/NeoGeoDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class NeoGeoDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual void process(Gamepad * gamepad);
virtual void initializeAux() {}
virtual void processAux() {}
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
Expand Down
2 changes: 1 addition & 1 deletion headers/drivers/net/NetDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class NetDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual void process(Gamepad * gamepad);
virtual void initializeAux() {}
virtual void processAux() {}
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
Expand Down
2 changes: 1 addition & 1 deletion headers/drivers/pcengine/PCEngineDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class PCEngineDriver : public GPDriver {
public:
virtual void initialize();
virtual void process(Gamepad * gamepad, uint8_t * outBuffer);
virtual void process(Gamepad * gamepad);
virtual void initializeAux() {}
virtual void processAux() {}
virtual uint16_t get_report(uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen);
Expand Down
Loading

0 comments on commit 32be222

Please sign in to comment.