Xbox Cloud Gaming app for PS5 Homebrew
C
Each stick's own dead zone; trigger resistance and force pulses
Rafael Abud Ferreira2b1ddbd818cd
diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cppindex 163c1de..c3e8133 100644--- a/src/app/autoplay.cpp+++ b/src/app/autoplay.cpp@@ -130,9 +130,10 @@ void autoplayPad(input::ControllerState& pad) {if (!g_autoplay.title.empty() && !g_autoplay.pad) pad = input::ControllerState{};if (g_autoplay.tuneTest && uiSaved) {// Settings, down to the dead zone, its tester: the left stick inside- // the dead zone, the right one out, the dead zone 15 -> 20 % (saved),- // Circle. Down to the trigger vibration, its tester: strong, high- // frequency, L2 a little and R2 60 % (saved), Circle.+ // its dead zone, the right one out; left 15 -> 20 %, R1, right 15 ->+ // 12 % (saved), Circle. Down to the trigger vibration, its tester:+ // strong, high frequency, strong resistance, force pulses; L2 alone,+ // then R2 alone (saved), Circle.static uint64_t since = 0;uint64_t now = platform::nowMs();if (!since) since = now;@@ -144,15 +145,18 @@ void autoplayPad(input::ControllerState& pad) {return false;};pad.btnOptions = in(500, 150);- pad.dpadDown = pulses(1000, 3) || in(6500, 120) || in(7900, 120);- pad.btnA = in(2000, 150) || in(7000, 150);- pad.btnB = in(5500, 150) || in(11500, 150);- pad.dpadRight = pulses(3000, 5) || in(7500, 120) || in(8300, 120);- if (in(2500, 3500)) pad.rawLeftX = 0.1f, pad.rawLeftY = 0.06f, pad.rawRightX = 0.7f, pad.rawRightY = -0.4f;- if (in(8700, 2300)) pad.triggerL2 = 0.15f, pad.triggerR2 = 0.6f;- if (in(5000, 20)) tuneShot = "sticks.ppm";- if (in(10000, 20)) tuneShot = "triggers.ppm";- if (in(12500, 20)) {+ pad.dpadDown = pulses(1000, 3) || in(8000, 120) || in(9400, 120) || in(10200, 120) || in(11600, 120);+ pad.btnA = in(2000, 150) || in(8500, 150);+ pad.btnB = in(7500, 150) || in(16500, 150);+ pad.btnR1 = in(4600, 150);+ pad.dpadRight = pulses(3000, 5) || in(9000, 120) || in(9800, 120) || pulses(10600, 3) || in(12000, 120);+ pad.dpadLeft = pulses(5000, 3);+ if (in(2500, 5000)) pad.rawLeftX = 0.1f, pad.rawLeftY = 0.06f, pad.rawRightX = 0.7f, pad.rawRightY = -0.4f;+ if (in(12500, 1500)) pad.triggerL2 = 0.5f; // each trigger alone: the log shows each one+ if (in(14500, 1500)) pad.triggerR2 = 0.6f;+ if (in(6500, 20)) tuneShot = "sticks.ppm";+ if (in(15500, 20)) tuneShot = "triggers.ppm";+ if (in(17500, 20)) {g_autoplay.tuneTest = false;XC_LOGI("AUTOPLAY END: tune test");}diff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cppindex 6e047a9..f75c79c 100644--- a/src/app/ps5_main.cpp+++ b/src/app/ps5_main.cpp@@ -64,8 +64,8 @@ std::unique_ptr<ui::ImageCache> g_images;// Dead zone, trigger vibration and confirm button from g_settings.void applyControllerSettings() {std::lock_guard<std::mutex> lock(g_settingsMutex);- input::setDeadzone(g_settings.deadzone / 100.0f);- input::setTriggerFeel(g_settings.triggerStrength, input::kTriggerHz[std::clamp(g_settings.triggerHz, 0, 2)]);+ input::setDeadzone(g_settings.deadzoneLeft / 100.0f, g_settings.deadzoneRight / 100.0f);+ input::setTriggerFeel(g_settings.triggerStrength, g_settings.triggerHz, g_settings.triggerResistance, g_settings.triggerPulses);input::setCircleConfirms(g_settings.circleConfirms);if (g_ui) g_ui->setCircleConfirms(g_settings.circleConfirms);}@@ -81,9 +81,12 @@ bool saveSettings(const ui::SettingsChoice& choice) {g_settings.language = code;g_settings.resolution = choice.resolution == 1 ? "720p" : choice.resolution == 2 ? "1440p" : "1080p";g_settings.region = choice.region;- g_settings.deadzone = choice.deadzone;+ g_settings.deadzoneLeft = choice.deadzone[0];+ g_settings.deadzoneRight = choice.deadzone[1];g_settings.triggerStrength = choice.triggerStrength;g_settings.triggerHz = choice.triggerHz;+ g_settings.triggerResistance = choice.triggerResistance;+ g_settings.triggerPulses = choice.triggerPulses;g_settings.circleConfirms = choice.circleConfirms;g_settings.lightBarMode = choice.lightBarMode;g_settings.lightBarColour = choice.lightBarColour;@@ -164,9 +167,12 @@ int main(int argc, char** argv) {choice.language = static_cast<int>(ui::language());choice.resolution = g_settings.resolution == "720p" ? 1 : g_settings.resolution == "1440p" ? 2 : 0;choice.region = g_settings.region;- choice.deadzone = std::clamp(g_settings.deadzone, 0, ui::kMaxDeadzone);+ choice.deadzone[0] = std::clamp(g_settings.deadzoneLeft, 0, ui::kMaxDeadzone);+ choice.deadzone[1] = std::clamp(g_settings.deadzoneRight, 0, ui::kMaxDeadzone);choice.triggerStrength = g_settings.triggerStrength;choice.triggerHz = g_settings.triggerHz;+ choice.triggerResistance = g_settings.triggerResistance;+ choice.triggerPulses = g_settings.triggerPulses;choice.circleConfirms = g_settings.circleConfirms;choice.lightBarMode = g_settings.lightBarMode;choice.lightBarColour = g_settings.lightBarColour;@@ -280,12 +286,15 @@ int main(int argc, char** argv) {streamScreen.idle();ui::UiEvent ev = g_ui->handle(nav);- if (int strength, hz; g_ui->settingsTriggerFeel(strength, hz)) {- // Settings: the trigger vibration as chosen there, at once; its- // tester makes the triggers vibrate as far as they are pressed.- input::setTriggerFeel(strength, input::kTriggerHz[std::clamp(hz, 0, 2)]);+ int strength, hz, resistance;+ bool pulses;+ if (g_ui->settingsTriggerFeel(strength, hz, resistance, pulses)) {+ // Settings: the triggers' feel as chosen there, at once; their+ // tester makes them vibrate as far as they are pressed.+ input::setTriggerFeel(strength, hz, resistance, pulses);float l2, r2;static bool testing = false;+ input::setTriggerLogging(g_ui->triggerTest(l2, r2));if (g_ui->triggerTest(l2, r2)) {input::setTriggerRumble(static_cast<uint8_t>(std::lround(l2 * 255)), static_cast<uint8_t>(std::lround(r2 * 255)), 500);testing = true;diff --git a/src/app/settings.cpp b/src/app/settings.cppindex 7988d88..c30945e 100644--- a/src/app/settings.cpp+++ b/src/app/settings.cpp@@ -29,11 +29,16 @@ bool Settings::load(const std::string& path) {sharpness = static_cast<int>(std::clamp<int64_t>((*j)["sharpness"].asInt(sharpness), 0, 3));deband = static_cast<int>(std::clamp<int64_t>((*j)["deband"].asInt(deband), 0, 3));upscaler = static_cast<int>(std::clamp<int64_t>((*j)["upscaler"].asInt(upscaler), 0, 3));- deadzone = static_cast<int>(std::clamp<int64_t>((*j)["deadzone"].asInt(deadzone), 0, 50));+ // "deadzone": one for both sticks, until each could have its own.+ int both = static_cast<int>(std::clamp<int64_t>((*j)["deadzone"].asInt(15), 0, 50));+ deadzoneLeft = static_cast<int>(std::clamp<int64_t>((*j)["deadzoneLeft"].asInt(both), 0, 50));+ deadzoneRight = static_cast<int>(std::clamp<int64_t>((*j)["deadzoneRight"].asInt(both), 0, 50));// "triggerRumble" (on/off) until the strength could be chosen.triggerStrength = (*j)["triggerRumble"].asBool(true) ? 2 : 0;triggerStrength = static_cast<int>(std::clamp<int64_t>((*j)["triggerStrength"].asInt(triggerStrength), 0, 4));triggerHz = static_cast<int>(std::clamp<int64_t>((*j)["triggerHz"].asInt(triggerHz), 0, 2));+ triggerResistance = static_cast<int>(std::clamp<int64_t>((*j)["triggerResistance"].asInt(0), 0, 3));+ triggerPulses = (*j)["triggerPulses"].asBool(false);circleConfirms = (*j)["circleConfirms"].asBool(circleConfirms);// "lightBar" (on/off) until the colour could be chosen.lightBarMode = (*j)["lightBar"].asBool(true) ? 0 : 2;@@ -78,9 +83,12 @@ bool Settings::save(const std::string& path) const {v.set("sharpness", sharpness);v.set("deband", deband);v.set("upscaler", upscaler);- v.set("deadzone", deadzone);+ v.set("deadzoneLeft", deadzoneLeft);+ v.set("deadzoneRight", deadzoneRight);v.set("triggerStrength", triggerStrength);v.set("triggerHz", triggerHz);+ v.set("triggerResistance", triggerResistance);+ v.set("triggerPulses", triggerPulses);v.set("circleConfirms", circleConfirms);v.set("lightBarMode", lightBarMode);char hex[8];diff --git a/src/app/settings.h b/src/app/settings.hindex 770298a..6b5cdcf 100644--- a/src/app/settings.h+++ b/src/app/settings.h@@ -32,11 +32,13 @@ struct Settings {int upscaler = 2;// Controller: stick dead zone (percent), vibration in the triggers,// Circle as the confirm button (Xbox A).- int deadzone = 15;+ int deadzoneLeft = 15, deadzoneRight = 15; // percent, each stick's own// Trigger vibration: strength 0 (off) .. 4 (max), its frequency as an// index into input::kTriggerHz (input/tuning.h).int triggerStrength = 2;int triggerHz = 1;+ int triggerResistance = 0; // 0 off .. 3 strong (the triggers' weight)+ bool triggerPulses = false; // pulses of the resistance instead of the motor vibratingbool circleConfirms = false;// The DualSense light bar: 0 the colour of the game in focus, 1// lightBarColour, 2 off.diff --git a/src/input/controller.cpp b/src/input/controller.cppindex 9c0f91c..5b82331 100644--- a/src/input/controller.cpp+++ b/src/input/controller.cpp@@ -112,6 +112,16 @@ struct Rumble {untilMs = durationMs ? platform::nowMs() + durationMs : 0;wanted = (uint32_t(a) << 8) | b;}+ // The value wanted now (0 once its time is up).+ uint32_t current() {+ uint32_t want = wanted;+ uint64_t until = untilMs;+ if (want && until && platform::nowMs() >= until) {+ wanted.compare_exchange_strong(want, 0);+ want = 0;+ }+ return want;+ }// The value to apply now, or false when it hasn't changed.bool due(uint32_t& out) {uint32_t want = wanted;@@ -132,6 +142,9 @@ struct Pad {std::atomic<bool> connected{false}; // the last poll's answerchar name[32] = {}; // the user's, read when openedRumble motors, triggers;+ TriggerCommand triggerSent[2]; // L2, R2 as last told+ bool triggerFresh = false; // triggerSent is what the pad has+ bool triggerVibrating[2] = {false, false};// Light bar: wanted colour (r << 16 | g << 8 | b, bit 24 = set) and the// one shown, easing towards it.std::atomic<uint32_t> lightWanted{0};@@ -140,9 +153,10 @@ struct Pad {bool lightStarted = false;};Pad g_pads[kMaxPads];-std::atomic<float> g_deadzone{0.15f};+std::atomic<float> g_deadzone[2] = {0.15f, 0.15f};std::atomic<bool> g_circleConfirms{false};-std::atomic<int> g_triggerStrength{kTriggerMedium}, g_triggerHz{60};+std::atomic<int> g_triggerStrength{kTriggerMedium}, g_triggerHz{1}, g_triggerResistance{0};+std::atomic<bool> g_triggerPulses{false}, g_triggerLogging{false};bool g_rumbleLogged = false;inline float normStick(uint8_t val) {@@ -167,6 +181,7 @@ bool openPad(Pad& pad, int32_t userId, int slot) {pad.handle = h;if (sceUserServiceGetUserName(userId, pad.name, sizeof pad.name) != 0) pad.name[0] = 0;pad.motors.applied = pad.triggers.applied = 0;+ pad.triggerFresh = false;XC_LOGI("pad %d opened (handle %d, rumble mode 0x%08x)", slot, h, static_cast<unsigned>(mode));return true;}@@ -226,26 +241,37 @@ void applyRumble(Pad& pad) {if (!g_rumbleLogged || rc != 0) XC_LOGI("scePadSetVibration(%u, %u): 0x%08x", p.largeMotor, p.smallMotor, rc);g_rumbleLogged = true;}- if (pad.triggers.due(v)) {- ScePadTriggerEffectParam p{};- p.triggerMask = 3;- const uint8_t level[2] = {static_cast<uint8_t>(v >> 8), static_cast<uint8_t>(v)};- int strength = g_triggerStrength, hz = g_triggerHz;- for (int t = 0; t < 2; ++t) {- uint8_t amplitude = triggerAmplitude(level[t], strength);- if (!amplitude) continue; // mode 0: off- p.command[t].mode = 3;- p.command[t].data[0] = 0; // from the top of the travel- p.command[t].data[1] = amplitude;- p.command[t].data[2] = static_cast<uint8_t>(std::clamp(hz, 1, 255));- }- int rc = scePadSetTriggerEffect(pad.handle, &p);- static int logged = 0; // the first few: what the game asked, and what the triggers got- if (logged < 12 || rc != 0)- XC_LOGI("scePadSetTriggerEffect(%u, %u -> amplitude %u, %u at %d Hz): 0x%08x", level[0], level[1], p.command[0].data[1],- p.command[1].data[1], hz, rc);- ++logged;+ // The triggers, worked out on every poll (the pulses change on their+ // own) and sent when either changes.+ v = pad.triggers.current();+ const uint8_t level[2] = {static_cast<uint8_t>(v >> 8), static_cast<uint8_t>(v)};+ int strength = g_triggerStrength, hz = g_triggerHz, resistance = g_triggerResistance;+ bool pulses = g_triggerPulses;+ uint64_t now = platform::nowMs();+ TriggerCommand want[2];+ for (int t = 0; t < 2; ++t) want[t] = triggerCommand(level[t], strength, hz, resistance, pulses, now);+ if (pad.triggerFresh && want[0] == pad.triggerSent[0] && want[1] == pad.triggerSent[1]) return;+ ScePadTriggerEffectParam p{};+ p.triggerMask = 3;+ for (int t = 0; t < 2; ++t) {+ p.command[t].mode = want[t].mode;+ std::copy(want[t].data, want[t].data + 4, p.command[t].data);+ }+ int rc = scePadSetTriggerEffect(pad.handle, &p);+ static int failures = 0; // a refused effect is sent again each poll: logged a few times+ for (int t = 0; t < 2; ++t) {+ // Vibrating: the motor, or pulses (a feedback while there is a request).+ bool was = pad.triggerFresh && pad.triggerVibrating[t];+ bool is = level[t] && triggerAmplitude(level[t], strength);+ if ((g_triggerLogging && was != is) || (rc != 0 && failures < 6))+ XC_LOGI("trigger %s: %s (mode %d, %u %u %u %u): 0x%08x", t ? "R2" : "L2", is ? "vibrating" : "still", want[t].mode,+ want[t].data[0], want[t].data[1], want[t].data[2], want[t].data[3], static_cast<unsigned>(rc));}+ for (int t = 0; t < 2; ++t) pad.triggerVibrating[t] = level[t] && triggerAmplitude(level[t], strength);+ pad.triggerSent[0] = want[0];+ pad.triggerSent[1] = want[1];+ pad.triggerFresh = rc == 0;+ if (rc != 0) ++failures;}} // namespace@@ -277,18 +303,22 @@ std::string padUserName(int index) {return index >= 0 && index < kMaxPads && g_pads[index].handle >= 0 ? g_pads[index].name : "";}-void setTriggerFeel(int strength, int hz) {- if (strength == g_triggerStrength && hz == g_triggerHz) return;+void setTriggerFeel(int strength, int hzIndex, int resistance, bool pulses) {g_triggerStrength = std::clamp(strength, 0, kTriggerStrengths - 1);- g_triggerHz = hz;- // What vibrates now is sent again in the new feel (or stopped).- for (Pad& p : g_pads) {- if (!g_triggerStrength) p.triggers.set(0, 0, 0);- p.triggers.applied = ~0u;- }+ g_triggerHz = std::clamp(hzIndex, 0, 2);+ g_triggerResistance = std::clamp(resistance, 0, kTriggerResistances - 1);+ g_triggerPulses = pulses;+ if (!g_triggerStrength)+ for (Pad& p : g_pads) p.triggers.set(0, 0, 0);+ // The next poll works the triggers out in the new feel.}-void setDeadzone(float deadzone) { g_deadzone = std::clamp(deadzone, 0.0f, 0.5f); }+void setTriggerLogging(bool on) { g_triggerLogging = on; }++void setDeadzone(float left, float right) {+ g_deadzone[0] = std::clamp(left, 0.0f, 0.5f);+ g_deadzone[1] = std::clamp(right, 0.0f, 0.5f);+}bool init() {int rc = scePadInit();@@ -385,9 +415,8 @@ bool pollPad(int index, ControllerState& out) {out.rawLeftY = out.leftStickY = normStick(pad.leftStick.y);out.rawRightX = out.rightStickX = normStick(pad.rightStick.x);out.rawRightY = out.rightStickY = normStick(pad.rightStick.y);- float dz = g_deadzone.load(std::memory_order_relaxed);- radialDeadzone(out.leftStickX, out.leftStickY, dz);- radialDeadzone(out.rightStickX, out.rightStickY, dz);+ radialDeadzone(out.leftStickX, out.leftStickY, g_deadzone[0].load(std::memory_order_relaxed));+ radialDeadzone(out.rightStickX, out.rightStickY, g_deadzone[1].load(std::memory_order_relaxed));out.triggerL2 = normTrigger(pad.l2);out.triggerR2 = normTrigger(pad.r2);@@ -419,14 +448,15 @@ bool pollPad(int index, ControllerState& out) {void refreshPads() {}void setRumble(uint8_t, uint8_t, uint32_t, int) {}void setTriggerRumble(uint8_t, uint8_t, uint32_t, int) {}-void setDeadzone(float) {}+void setDeadzone(float, float) {}void setCircleConfirms(bool) {}bool circleConfirms() { return false; }void setLightBar(uint8_t, uint8_t, uint8_t, int) {}void resetLightBar(int) {}bool padConnected(int index) { return index == 0; }std::string padUserName(int index) { return index == 0 ? "Player" : ""; }-void setTriggerFeel(int, int) {}+void setTriggerFeel(int, int, int, bool) {}+void setTriggerLogging(bool) {}} // namespace xc::input#endifdiff --git a/src/input/controller.h b/src/input/controller.hindex 9edfc21..1abf19c 100644--- a/src/input/controller.h+++ b/src/input/controller.h@@ -71,13 +71,19 @@ void setRumble(uint8_t large, uint8_t small, uint32_t durationMs, int pad = 0);// DualSense's adaptive triggers vibrate along their whole travel.void setTriggerRumble(uint8_t left, uint8_t right, uint32_t durationMs, int pad = 0);// Stick dead zone, 0..0.5 of the travel.-void setDeadzone(float deadzone);+// Each stick's own dead zone (0..1 of the travel): a drifting stick can+// have a bigger one.+void setDeadzone(float left, float right);// Circle reported as Cross (Xbox A) and Cross as Circle, everywhere.void setCircleConfirms(bool on);bool circleConfirms();-// How the triggers vibrate: strength 0 (off: setTriggerRumble() is ignored)-// to kTriggerStrengths - 1, and the frequency in Hz (input/tuning.h).-void setTriggerFeel(int strength, int hz);+// How the triggers feel (input/tuning.h): vibration strength 0 (off:+// setTriggerRumble() is ignored) to kTriggerStrengths - 1, the frequency+// choice (index), the resistance (weight) and the style (pulses of the+// resistance instead of the motor vibrating).+void setTriggerFeel(int strength, int hzIndex, int resistance, bool pulses);+// Logs each time a trigger starts or stops vibrating (the Settings tester).+void setTriggerLogging(bool on);// The light bar eases (~0.4 s) to this colour; reset gives it back to the// system (the player's colour). Any thread; polling applies it.void setLightBar(uint8_t r, uint8_t g, uint8_t b, int pad = 0);diff --git a/src/input/tuning.h b/src/input/tuning.hindex 3d5b78e..674bd04 100644--- a/src/input/tuning.h+++ b/src/input/tuning.h@@ -44,4 +44,54 @@ inline uint8_t triggerAmplitude(uint8_t level, int strength = kTriggerMedium) {return static_cast<uint8_t>(std::clamp(static_cast<int>(std::lround(a)), 1, 8));}+// Resistance (the triggers' weight): off, light, medium, strong. The+// DualSense pushes back from a point of the travel on, earlier and harder+// the stronger it is; the Xbox's triggers have none, so it is the user's+// choice. (The console takes the trigger modes 0..3 only: the slope and+// per-position modes of Sony's PC headers are refused, 0x80920001.)+constexpr int kTriggerResistances = 4;++// What one trigger is told to do (ScePadTriggerEffectCommand: its mode and+// the first bytes of its parameters, the rest zero).+struct TriggerCommand {+ int32_t mode = 0; // 0 off, 1 feedback (resistance), 3 vibration+ uint8_t data[4] = {0, 0, 0, 0};+ bool operator==(const TriggerCommand& o) const {+ return mode == o.mode && data[0] == o.data[0] && data[1] == o.data[1] && data[2] == o.data[2] && data[3] == o.data[3];+ }+ bool operator!=(const TriggerCommand& o) const { return !(*this == o); }+};++// The pulses' rate for a frequency choice: the pad is updated ~120 times a+// second, so the push / release can't go faster than this.+constexpr int kTriggerPulseHz[] = {10, 20, 30};++// One trigger at a moment: `level` the game's request (0..255), and the+// user's strength, frequency choice (index), resistance, and style: the+// motor vibrating (resistance gone while it does), or pulses of the+// resistance itself (pushing harder and letting go at kTriggerPulseHz),+// which keep the weight.+inline TriggerCommand triggerCommand(uint8_t level, int strength, int hzIndex, int resistance, bool pulses, uint64_t nowMs) {+ // Resistance: where it starts (0..9) and how hard (0..8).+ static constexpr uint8_t kFeedback[kTriggerResistances][2] = {{0, 0}, {4, 2}, {3, 4}, {2, 6}};+ static constexpr uint8_t kBase[kTriggerResistances] = {0, 2, 3, 4};+ resistance = std::clamp(resistance, 0, kTriggerResistances - 1);+ hzIndex = std::clamp(hzIndex, 0, 2);+ TriggerCommand c;+ uint8_t amplitude = triggerAmplitude(level, strength);+ if (amplitude && !pulses) {+ c.mode = 3; // vibration: from the top of the travel+ c.data[1] = amplitude;+ c.data[2] = static_cast<uint8_t>(kTriggerHz[hzIndex]);+ } else if (amplitude) {+ bool push = (nowMs * static_cast<uint64_t>(kTriggerPulseHz[hzIndex]) * 2 / 1000) % 2 == 0;+ int s = push ? std::min(8, kBase[resistance] + amplitude) : kBase[resistance];+ if (s) c.mode = 1, c.data[1] = static_cast<uint8_t>(s); // feedback from position 0+ } else if (resistance) {+ c.mode = 1; // feedback: the weight from its point on+ c.data[0] = kFeedback[resistance][0], c.data[1] = kFeedback[resistance][1];+ }+ return c;+}+} // namespace xc::inputdiff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex 39a812e..20677e2 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -706,11 +706,13 @@ bool AppUi::settingsLightBar(int& mode, Color& colour) const {return true;}-bool AppUi::settingsTriggerFeel(int& strength, int& hzIndex) const {+bool AppUi::settingsTriggerFeel(int& strength, int& hzIndex, int& resistance, bool& pulses) const {std::lock_guard<std::mutex> lock(mutex_);if (screen_ != Screen::Settings) return false;strength = settings_.triggerStrength;hzIndex = settings_.triggerHz;+ resistance = settings_.triggerResistance;+ pulses = settings_.triggerPulses;return true;}@@ -726,8 +728,8 @@ void AppUi::openTester(Tester t) {// Caller holds mutex_. Circle puts back what was there.tester_ = t;testerRow_ = 0;- testerBackup_[0] = t == Tester::Sticks ? settings_.deadzone : settings_.triggerStrength;- testerBackup_[1] = settings_.triggerHz;+ testerStick_ = 0;+ testerBackup_ = settings_;dirty_ = true;}@@ -735,24 +737,32 @@ void AppUi::handleTester(const NavInput& in) {// Caller holds mutex_. Changes apply as they are made (the pad follows);// Cross keeps them, Circle puts the old ones back.if (tester_ == Tester::Sticks) {- // The D-pad only: the sticks are what is being tried.- int dz = std::clamp(settings_.deadzone + (in.dpadRight ? 1 : 0) - (in.dpadLeft ? 1 : 0), 0, kMaxDeadzone);- if (dz != settings_.deadzone) settings_.deadzone = dz, dirty_ = true;+ // L1 / R1 pick the stick, the D-pad (only: the sticks are what is+ // being tried) changes its dead zone.+ if (in.l1 || in.r1) testerStick_ = in.r1 ? 1 : 0, dirty_ = true;+ int& zone = settings_.deadzone[testerStick_];+ int dz = std::clamp(zone + (in.dpadRight ? 1 : 0) - (in.dpadLeft ? 1 : 0), 0, kMaxDeadzone);+ if (dz != zone) zone = dz, dirty_ = true;const float now[4] = {in.rawLX, in.rawLY, in.rawRX, in.rawRY};for (int i = 0; i < 4; ++i)if (now[i] != testSticks_[i]) testSticks_[i] = now[i], dirty_ = true;} else {- if (in.up || in.down) testerRow_ = 1 - testerRow_, dirty_ = true;+ if (in.up && testerRow_ > 0) --testerRow_, dirty_ = true;+ if (in.down && testerRow_ < 3) ++testerRow_, dirty_ = true;int delta = (in.right ? 1 : 0) - (in.left ? 1 : 0);if (delta && testerRow_ == 0)settings_.triggerStrength = std::clamp(settings_.triggerStrength + delta, 0, input::kTriggerStrengths - 1);if (delta && testerRow_ == 1) settings_.triggerHz = std::clamp(settings_.triggerHz + delta, 0, 2);+ if (delta && testerRow_ == 2)+ settings_.triggerResistance = std::clamp(settings_.triggerResistance + delta, 0, input::kTriggerResistances - 1);+ if (delta && testerRow_ == 3) settings_.triggerPulses = !settings_.triggerPulses;if (delta) dirty_ = true;if (in.l2Analog != testL2_ || in.r2Analog != testR2_) testL2_ = in.l2Analog, testR2_ = in.r2Analog, dirty_ = true;}if (in.back) {- if (tester_ == Tester::Sticks) settings_.deadzone = testerBackup_[0];- else settings_.triggerStrength = testerBackup_[0], settings_.triggerHz = testerBackup_[1];+ settings_.deadzone[0] = testerBackup_.deadzone[0], settings_.deadzone[1] = testerBackup_.deadzone[1];+ settings_.triggerStrength = testerBackup_.triggerStrength, settings_.triggerHz = testerBackup_.triggerHz;+ settings_.triggerResistance = testerBackup_.triggerResistance, settings_.triggerPulses = testerBackup_.triggerPulses;}if (in.accept || in.back) {tester_ = Tester::None;@@ -930,7 +940,8 @@ std::vector<std::string> AppUi::settingOptions(int row) const {out = {tr(Str::Res720), tr(Str::Res1080)}; // kResolutionOrderif (allow1440_) out.push_back(tr(Str::Res1440));} else if (row == 3) {- for (int p = 0; p <= kMaxDeadzone; ++p) out.push_back(std::to_string(p) + " %");+ // Left and right stick (the tester changes them).+ out = {std::to_string(settings_.deadzone[0]) + " % \xC2\xB7 " + std::to_string(settings_.deadzone[1]) + " %"};} else if (row == 4) {out = {tr(Str::Deactivated), tr(Str::TriggerLight), tr(Str::TriggerMedium), tr(Str::TriggerStrong),tr(Str::TriggerMax)};@@ -957,7 +968,7 @@ int AppUi::settingSelected(int row) const {for (int i = 0; i < 3; ++i)if (kResolutionOrder[i] == settings_.resolution) return i;}- if (row == 3) return settings_.deadzone;+ if (row == 3) return 0;if (row == 4) return settings_.triggerStrength;if (row == 5) return settings_.circleConfirms ? 1 : 0;if (row == 6) return settings_.lightBarMode;@@ -975,7 +986,7 @@ void AppUi::applySetting(int row, int index) {} else if (row == 1) {settings_.resolution = kResolutionOrder[index];} else if (row == 3) {- settings_.deadzone = index;+ (void)index; // the tester sets each stick's} else if (row == 4) {settings_.triggerStrength = index;} else if (row == 5) {@@ -2384,16 +2395,21 @@ Rect AppUi::drawModal(Canvas& c, int w, int h, const std::string& title) {}void AppUi::drawStickTester(Canvas& c) {- Rect panel = drawModal(c, 1240, 700, std::string(tr(Str::Deadzone)) + ": " + std::to_string(settings_.deadzone) + " %");+ Rect panel = drawModal(c, 1240, 740, tr(Str::Deadzone));constexpr int R = 180;const Color raw = rgba(170, 170, 170), game = rgba(90, 220, 110);- const float dz = settings_.deadzone / 100.0f;for (int s = 0; s < 2; ++s) {- const float cx = panel.x + (s ? 930.0f : 310.0f), cy = panel.y + 130.0f + R;- c.fillCircle(cx, cy, R, rgba(255, 255, 255, 14));+ const float dz = settings_.deadzone[s] / 100.0f;+ const bool chosen = s == testerStick_;+ const float cx = panel.x + (s ? 930.0f : 310.0f), cy = panel.y + 170.0f + R;+ // Its dead zone above it, in white on the stick being adjusted.+ std::string value = std::to_string(settings_.deadzone[s]) + " %";+ fonts_.bold.draw(c, value, static_cast<int>(cx) - fonts_.bold.measure(value, 34) / 2, static_cast<int>(cy) - R - 56, 34,+ chosen ? kWhite : kDim);+ c.fillCircle(cx, cy, R, rgba(255, 255, 255, chosen ? 22 : 10));c.line(cx - R, cy, cx + R, cy, 1, rgba(255, 255, 255, 30));c.line(cx, cy - R, cx, cy + R, 1, rgba(255, 255, 255, 30));- c.strokeArc(cx, cy, R, 2, 0, 6.2832f, rgba(255, 255, 255, 90));+ c.strokeArc(cx, cy, R, chosen ? 4.0f : 2.0f, 0, 6.2832f, chosen ? kWhite : rgba(255, 255, 255, 70));// The dead zone: nothing reaches the game in there.if (dz > 0) {c.fillCircle(cx, cy, dz * R, rgba(230, 70, 70, 60));@@ -2423,16 +2439,20 @@ void AppUi::drawStickTester(Canvas& c) {}void AppUi::drawTriggerTester(Canvas& c) {- Rect panel = drawModal(c, 1100, 700, tr(Str::TriggerRumble));+ Rect panel = drawModal(c, 1100, 830, tr(Str::TriggerRumble));// The two choices, as Settings' rows: up / down picks one, left / right changes it.const char* strengths[] = {tr(Str::Deactivated), tr(Str::TriggerLight), tr(Str::TriggerMedium), tr(Str::TriggerStrong),tr(Str::TriggerMax)};const char* freqs[] = {tr(Str::FrequencyLow), tr(Str::TriggerMedium), tr(Str::FrequencyHigh)};- const char* labels[] = {tr(Str::TriggerIntensity), tr(Str::TriggerFrequency)};+ const char* labels[] = {tr(Str::TriggerIntensity), tr(Str::TriggerFrequency), tr(Str::TriggerResistance),+ tr(Str::TriggerStyle)};+ // Pulses go at their own, slower rates.+ int hz = settings_.triggerPulses ? input::kTriggerPulseHz[settings_.triggerHz] : input::kTriggerHz[settings_.triggerHz];const std::string values[] = {strengths[settings_.triggerStrength],- std::string(freqs[settings_.triggerHz]) + " (" +- std::to_string(input::kTriggerHz[settings_.triggerHz]) + " Hz)"};- for (int i = 0; i < 2; ++i) {+ std::string(freqs[settings_.triggerHz]) + " (" + std::to_string(hz) + " Hz)",+ strengths[settings_.triggerResistance], // off, light, medium, strong+ tr(settings_.triggerPulses ? Str::StylePulses : Str::StyleVibration)};+ for (int i = 0; i < 4; ++i) {Rect r{panel.x + 56, panel.y + 120 + i * 84, panel.w - 112, 70};bool on = i == testerRow_;c.fillRect(r, on ? rgba(255, 255, 255, 36) : rgba(255, 255, 255, 14), 16);@@ -2445,8 +2465,8 @@ void AppUi::drawTriggerTester(Canvas& c) {// L2 and R2: how far each is pressed, and the level it sends to the trigger.const float pressed[2] = {testL2_, testR2_};for (int t = 0; t < 2; ++t) {- constexpr int kBarW = 90, kBarH = 220;- int bx = panel.x + panel.w / 2 + (t ? 80 : -80 - kBarW), by = panel.y + 330;+ constexpr int kBarW = 90, kBarH = 170;+ int bx = panel.x + panel.w / 2 + (t ? 80 : -80 - kBarW), by = panel.y + 490;c.fillRect({bx, by, kBarW, kBarH}, rgba(255, 255, 255, 20), 16);int fill = static_cast<int>(kBarH * std::clamp(pressed[t], 0.0f, 1.0f));int level = input::triggerAmplitude(static_cast<uint8_t>(std::lround(pressed[t] * 255)), settings_.triggerStrength);diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex 5fb7117..47d6bb7 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -83,9 +83,11 @@ struct SettingsChoice {int language = 0; // ui::Languageint resolution = 0; // 0 = 1080p, 1 = 720p, 2 = 1440p (experimental)std::string region; // gssv region name; empty = automatic- int deadzone = 15; // percent of the stick's travel, 0..kMaxDeadzone- int triggerStrength = 2; // 0 off .. 4 max (input/tuning.h)- int triggerHz = 1; // index into input::kTriggerHz+ int deadzone[2] = {15, 15}; // left, right stick: percent of the travel, 0..kMaxDeadzone+ int triggerStrength = 2; // 0 off .. 4 max (input/tuning.h)+ int triggerHz = 1; // index into input::kTriggerHz+ int triggerResistance = 0; // 0 off .. 3 strong+ bool triggerPulses = false; // force pulses instead of the motor vibratingbool circleConfirms = false; // Circle is Xbox A (and Cross is B)int lightBarMode = 0; // 0 the game's colour, 1 lightBarColour, 2 offColor lightBarColour = rgba(0, 112, 220);@@ -194,7 +196,7 @@ public:// The same for the trigger vibration (strength, frequency index), and,// while its tester is open, how far each trigger is pressed: the app// makes them vibrate as a game asking that much would.- bool settingsTriggerFeel(int& strength, int& hzIndex) const;+ bool settingsTriggerFeel(int& strength, int& hzIndex, int& resistance, bool& pulses) const;bool triggerTest(float& l2, float& r2) const;// Regions offered by the account's xCloud login; `defaultRegion` is the// one "Automatic" picks.@@ -370,8 +372,9 @@ private:std::string updatingTo_, updateStatus_;float updateFraction_ = -1;Tester tester_ = Tester::None;- int testerBackup_[2] = {0, 0}; // what Circle puts back- int testerRow_ = 0; // the trigger tester: 0 intensity, 1 frequency+ SettingsChoice testerBackup_; // what Circle puts back+ int testerRow_ = 0; // the trigger tester's row: intensity, frequency, resistance, style+ int testerStick_ = 0; // the stick tester: the one being adjusted (L1 / R1)float testSticks_[4] = {0, 0, 0, 0}, testL2_ = 0, testR2_ = 0;bool pickerOpen_ = false;float pickU_ = 0, pickV_ = 0; // on the wheel: angle = hue, distance = saturationdiff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex 62d9fa6..eb746c0 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -209,7 +209,11 @@ constexpr Column kEnglish = {"Right stick", // StickRight"Stick position", // StickPosition"What the game gets", // StickGameGets- "D-pad ← / →: adjust Move the sticks to see it", // StickTestHelp+ "L1 / R1: choose the stick D-pad ← / →: adjust Move the sticks to see it", // StickTestHelp+ "Resistance", // TriggerResistance+ "Style", // TriggerStyle+ "Vibration", // StyleVibration+ "Force pulses", // StylePulses};constexpr Column kPortugueseBR = {@@ -389,7 +393,11 @@ constexpr Column kPortugueseBR = {"Analógico direito","Posição real","O que o jogo recebe",- "Direcional ← / →: ajustar Mova os analógicos para ver",+ "L1 / R1: escolher o analógico Direcional ← / →: ajustar Mova os analógicos para ver",+ "Resistência",+ "Estilo",+ "Vibração",+ "Pulsos de força",};constexpr Column kSpanish = {@@ -569,7 +577,11 @@ constexpr Column kSpanish = {"Stick derecho","Posición real","Lo que recibe el juego",- "Cruceta ← / →: ajustar Mueve los sticks para verlo",+ "L1 / R1: elegir el stick Cruceta ← / →: ajustar Mueve los sticks para verlo",+ "Resistencia",+ "Estilo",+ "Vibración",+ "Pulsos de fuerza",};constexpr Column kFrench = {@@ -749,7 +761,11 @@ constexpr Column kFrench = {"Joystick droit","Position réelle","Ce que reçoit le jeu",- "Croix ← / → : régler Bougez les joysticks pour le voir",+ "L1 / R1 : choisir le joystick Croix ← / → : régler Bougez les joysticks pour le voir",+ "Résistance",+ "Style",+ "Vibration",+ "Impulsions de force",};constexpr Column kGerman = {@@ -929,7 +945,11 @@ constexpr Column kGerman = {"Rechter Stick","Tatsächliche Position","Was das Spiel bekommt",- "Steuerkreuz ← / →: einstellen Sticks bewegen zum Sehen",+ "L1 / R1: Stick wählen Steuerkreuz ← / →: einstellen Sticks bewegen zum Sehen",+ "Widerstand",+ "Stil",+ "Vibration",+ "Kraftimpulse",};constexpr Column kItalian = {@@ -1109,7 +1129,11 @@ constexpr Column kItalian = {"Levetta destra","Posizione reale","Ciò che riceve il gioco",- "Croce ← / →: regolare Muovi le levette per vederlo",+ "L1 / R1: scegliere la levetta Croce ← / →: regolare Muovi le levette per vederlo",+ "Resistenza",+ "Stile",+ "Vibrazione",+ "Impulsi di forza",};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex 350d7d4..c5d1168 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -187,6 +187,10 @@ enum class Str {StickPosition, // legend: the grey dotStickGameGets, // legend: the green dotStickTestHelp, // under the stick tester+ TriggerResistance, // the trigger tester: the triggers' weight+ TriggerStyle, // the trigger tester: how the game's vibration is felt+ StyleVibration,+ StylePulses, // the resistance pushing and letting goCount};diff --git a/tests/test_main.cpp b/tests/test_main.cppindex 1a2c87b..786d673 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -240,6 +240,11 @@ static void testSettingsMigration() {CHECK(again.load(path) && again.deband == 3 && again.upscaler == 2);// The triggers' on/off before their strength could be chosen.CHECK(loadFrom(R"({"triggerRumble":false})").triggerStrength == 0 && loadFrom("{}").triggerStrength == 2);+ // One dead zone for both sticks, until each could have its own.+ auto one = loadFrom(R"({"deadzone":22})");+ CHECK(one.deadzoneLeft == 22 && one.deadzoneRight == 22);+ auto two = loadFrom(R"({"deadzone":22,"deadzoneLeft":8,"deadzoneRight":30})");+ CHECK(two.deadzoneLeft == 8 && two.deadzoneRight == 30);// The light bar's on/off before its colour could be chosen.CHECK(loadFrom(R"({"lightBar":false})").lightBarMode == 2 && loadFrom(R"({"lightBar":true})").lightBarMode == 0);xc::app::Settings custom;@@ -405,6 +410,18 @@ static void testControllerTuning() {CHECK(triggerAmplitude(38, 0) == 0 && triggerAmplitude(0, 4) == 0);CHECK(triggerAmplitude(38, 1) == 2 && triggerAmplitude(38, 3) == 6 && triggerAmplitude(38, 4) == 8);CHECK(triggerAmplitude(255, 3) == 8 && triggerAmplitude(1, 1) == 1);++ using xc::input::triggerCommand;+ auto vib = triggerCommand(38, 2, 1, 2, false, 0); // vibration style: the motor, 60 Hz+ CHECK(vib.mode == 3 && vib.data[1] == 4 && vib.data[2] == 60);+ auto still = triggerCommand(0, 2, 1, 2, false, 0); // no request: the medium resistance (from 3, strength 4)+ CHECK(still.mode == 1 && still.data[0] == 3 && still.data[1] == 4);+ CHECK(triggerCommand(0, 2, 1, 0, false, 0).mode == 0); // no resistance: off+ // Pulses (20 Hz: 25 ms push, 25 ms release) keep the weight: base 3 + amplitude 4.+ auto push = triggerCommand(38, 2, 1, 2, true, 0), release = triggerCommand(38, 2, 1, 2, true, 30);+ CHECK(push.mode == 1 && push.data[1] == 7 && release.mode == 1 && release.data[1] == 3);+ CHECK(triggerCommand(38, 2, 1, 0, true, 30).mode == 0); // no resistance: released is off+ CHECK(triggerCommand(38, 0, 1, 2, true, 0) == still); // vibration off: only the weight}static void testAutoDeband() {