Skip to content

Commit

Permalink
Sync with main repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Robot authored and Robot committed Oct 15, 2023
1 parent 25ce533 commit 01683db
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ A number of hotkeys are enabled by default and if you are encountering issues wi

## Add-Ons and Additional Features

There are a number of add-ons that expand the functionality of GP2040-CE, such as [analog stick emulation](add-ons/analog) and [turbo functions](add-ons/turbo). Due to the large number of add-ons created by the community, they are located in a separate documentation page. Navigate to [Add-Ons page](add-ons) for more information on the individual add-ons.
There are a number of add-ons that expand the functionality of GP2040-CE, such as [analog stick emulation](add-ons/analog) and [turbo functions](add-ons/turbo). Due to the large number of add-ons created by the community, they are located in a separate documentation page. Navigate to [Add-Ons page](add-ons) for more information on the individual add-ons.
2 changes: 2 additions & 0 deletions headers/addons/wiiext.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ class WiiExtensionInput : public GPAddon {
bool dpadLeft = false;
bool dpadRight = false;

bool isAnalogTriggers = false;

uint16_t triggerLeft = 0;
uint16_t triggerRight = 0;
uint16_t lastTriggerLeft = 0;
Expand Down
6 changes: 4 additions & 2 deletions src/addons/keyboard_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ void KeyboardHostAddon::preprocess() {
gamepad->state.ly |= _keyboard_host_state.ly;
gamepad->state.rx |= _keyboard_host_state.rx;
gamepad->state.ry |= _keyboard_host_state.ry;
gamepad->state.lt |= _keyboard_host_state.lt;
gamepad->state.rt |= _keyboard_host_state.rt;
if (!gamepad->hasAnalogTriggers) {
gamepad->state.lt |= _keyboard_host_state.lt;
gamepad->state.rt |= _keyboard_host_state.rt;
}
}

void KeyboardHostAddon::mount(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len) {
Expand Down
9 changes: 8 additions & 1 deletion src/addons/wiiext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ void WiiExtensionInput::update() {
// WII_SET_MASK(buttonState, wii->getController()->buttons[extensionButton], value);
//}

isAnalogTriggers = false;

if (wii->extensionType == WII_EXTENSION_NUNCHUCK) {
buttonZ = wii->getController()->buttons[WiiButtons::WII_BUTTON_Z];
buttonC = wii->getController()->buttons[WiiButtons::WII_BUTTON_C];
Expand Down Expand Up @@ -136,6 +138,7 @@ void WiiExtensionInput::update() {
if (wii->extensionType == WII_EXTENSION_CLASSIC) {
triggerLeft = wii->getController()->analogState[WiiAnalogs::WII_ANALOG_LEFT_TRIGGER];
triggerRight = wii->getController()->analogState[WiiAnalogs::WII_ANALOG_RIGHT_TRIGGER];
isAnalogTriggers = true;
}

leftX = map(wii->getController()->analogState[WiiAnalogs::WII_ANALOG_LEFT_X],0,WII_ANALOG_PRECISION_3,GAMEPAD_JOYSTICK_MIN,GAMEPAD_JOYSTICK_MAX);
Expand Down Expand Up @@ -211,6 +214,8 @@ void WiiExtensionInput::update() {

triggerLeft = wii->getController()->analogState[TurntableAnalogs::TURNTABLE_EFFECTS];
triggerRight = wii->getController()->analogState[TurntableAnalogs::TURNTABLE_CROSSFADE];

isAnalogTriggers = true;
}
} else {
currentConfig = NULL;
Expand Down Expand Up @@ -330,7 +335,7 @@ void WiiExtensionInput::queueAnalogChange(uint16_t analogInput, uint16_t analogV

void WiiExtensionInput::updateAnalogState() {
Gamepad * gamepad = Storage::getInstance().GetGamepad();
gamepad->hasAnalogTriggers = true;
gamepad->hasAnalogTriggers = isAnalogTriggers;

uint16_t axisType;
uint16_t analogInput;
Expand Down Expand Up @@ -363,6 +368,8 @@ void WiiExtensionInput::updateAnalogState() {
axisToChange = WII_ANALOG_TYPE_NONE;
adjustedValue = 0;

if (!isAnalogTriggers && ((analogInput == WiiAnalogs::WII_ANALOG_LEFT_TRIGGER) || (analogInput == WiiAnalogs::WII_ANALOG_RIGHT_TRIGGER))) continue;

// define ranges
switch (analogInput) {
case WiiAnalogs::WII_ANALOG_LEFT_X:
Expand Down
4 changes: 2 additions & 2 deletions src/gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ XInputReport *Gamepad::getXInputReport()

if (hasAnalogTriggers)
{
xinputReport.lt = state.lt;
xinputReport.rt = state.rt;
xinputReport.lt = pressedL2() ? 0xFF : state.lt;
xinputReport.rt = pressedR2() ? 0xFF : state.rt;
}
else
{
Expand Down
11 changes: 6 additions & 5 deletions www/src/Addons/Wii.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ const Wii = ({ values, errors, handleChange, handleCheckbox }) => {
.reduce(
(o, i) => {
let modeID = i.value;
let joyMode = getJoystickMode(modeID);
let axes = i.getAttribute('axiscount') || 2;
let joyMode = (axes == 2 ? getJoystickMode(modeID) : null);
if (joyMode && joyMode.options) {
let r = o;
Object.keys(joyMode.options).forEach(key => {
Expand All @@ -130,10 +131,10 @@ const Wii = ({ values, errors, handleChange, handleCheckbox }) => {

const getJoystickMode = (searchValue: number) => WII_JOYSTICK_MODES.find(({ value }) => parseInt(value) === parseInt(searchValue));

const setWiiAnalogEntry = (controlID,analogID,e) => {
const setWiiAnalogEntry = (controlID,analogID,axes,e) => {
let analogEntry = {};
let modeID = e.target.value;
let joyMode = getJoystickMode(modeID);
let joyMode = (axes == 2 ? getJoystickMode(modeID) : null);
if (joyMode && joyMode.options) {
let r = analogEntry;
Object.keys(joyMode.options).forEach(key => {
Expand Down Expand Up @@ -280,7 +281,7 @@ const Wii = ({ values, errors, handleChange, handleCheckbox }) => {
<div className="col-sm-12 col-md-6 col-lg-2 mb-2">
{analogObj.axes?.length == 1 &&
<div className="row">
<select className="form-select-sm form-control wii-analogs" controlid={`${controlObj.id.toLowerCase()}`} analogid={`${analogObj.id}`} axisid={`${analogObj.axes[0].axis}`} id={`wiiExtensionController${controlObj.id}Analog${analogObj.id}`} value={wiiControls[controlObj.id.toLowerCase()+'.analog'+analogObj.id+'.axisType']} onChange={(e) => setWiiAnalogEntry(controlObj.id, analogObj.id, e)}>
<select className="form-select-sm form-control wii-analogs" controlid={`${controlObj.id.toLowerCase()}`} analogid={`${analogObj.id}`} axisid={`${analogObj.axes[0].axis}`} axiscount={analogObj.axes?.length} id={`wiiExtensionController${controlObj.id}Analog${analogObj.id}`} value={wiiControls[controlObj.id.toLowerCase()+'.analog'+analogObj.id+'.axisType']} onChange={(e) => setWiiAnalogEntry(controlObj.id, analogObj.id, analogObj.axes?.length, e)}>
{ANALOG_SINGLE_AXIS_MODES.map((o,i) => (
<option key={`wiiSingleAxisMode${controlObj.id}${analogID}${i}`} value={o.value}>{o.label}</option>
))}
Expand All @@ -289,7 +290,7 @@ const Wii = ({ values, errors, handleChange, handleCheckbox }) => {
}
{analogObj.axes?.length == 2 &&
<div className="row">
<select className="form-select-sm form-control wii-analogs" controlid={`${controlObj.id.toLowerCase()}`} analogid={`${analogObj.id}`} axisid={`${analogObj.axes[0].axis}`} id={`wiiExtensionController${controlObj.id}Analog${analogObj.id}`} value={getJoystickModeValue(controlObj, analogObj)} onChange={(e) => setWiiAnalogEntry(controlObj.id, analogObj.id, e)}>
<select className="form-select-sm form-control wii-analogs" controlid={`${controlObj.id.toLowerCase()}`} analogid={`${analogObj.id}`} axisid={`${analogObj.axes[0].axis}`} axiscount={analogObj.axes?.length} id={`wiiExtensionController${controlObj.id}Analog${analogObj.id}`} value={getJoystickModeValue(controlObj, analogObj)} onChange={(e) => setWiiAnalogEntry(controlObj.id, analogObj.id, analogObj.axes?.length, e)}>
{WII_JOYSTICK_MODES.map((o,i) => (
<option key={`wiiJoystickMode${controlObj.id}${analogID}${i}`} value={o.value}>{o.label}</option>
))}
Expand Down

0 comments on commit 01683db

Please sign in to comment.