Xbox Cloud Gaming app for PS5 Homebrew
C
Trigger vibration and dead zone testers in Settings
Rafael Abud Ferreira4e16f5f6d9c1
diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cppindex 5e7ccb2..163c1de 100644--- a/src/app/autoplay.cpp+++ b/src/app/autoplay.cpp@@ -27,7 +27,8 @@ bool settingsShot = false; // "settingstest": save the screen nowuint64_t homeSince = 0, launchSince = 0;bool launchSaved = false;const char* pickerShot = nullptr;-bool confirmShot = false, confirmHome = false; // "confirmtest": save confirm2.ppm / check the home screen // "pickertest": save this screen next, once drawn+bool confirmShot = false, confirmHome = false;+const char* tuneShot = nullptr; // "tunetest": save this screen next // "confirmtest": save confirm2.ppm / check the home screen // "pickertest": save this screen next, once drawnbool acceptUpdate = false; // "updatetest": Cross on the pop-up, next pass ("updateskip": Circle)} // namespace@@ -80,6 +81,7 @@ void loadAutoplay() {if (opt == "pickertest") g_autoplay.pickerTest = true;if (opt == "menushot") g_autoplay.menuShot = true;if (opt == "confirmtest") g_autoplay.confirmTest = true;+ if (opt == "tunetest") g_autoplay.tuneTest = true;if (opt == "norestart") g_autoplay.noRestart = true;if (opt.rfind("threads=", 0) == 0) g_autoplay.decodeThreads = std::atoi(opt.c_str() + 8);}@@ -126,6 +128,35 @@ void autoplayPad(input::ControllerState& pad) {// Autoplay runs unattended: the physical pad must not interfere// (unless "pad": someone is playing along, and each press is logged).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.+ static uint64_t since = 0;+ uint64_t now = platform::nowMs();+ if (!since) since = now;+ uint64_t t = now - since;+ auto in = [&](uint64_t at, uint64_t len) { return t >= at && t < at + len; };+ auto pulses = [&](uint64_t from, int n) {+ for (int i = 0; i < n; ++i)+ if (in(from + 300u * static_cast<unsigned>(i), 120)) return true;+ 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)) {+ g_autoplay.tuneTest = false;+ XC_LOGI("AUTOPLAY END: tune test");+ }+ }if (g_autoplay.confirmTest && uiSaved) {// The buttons as the hands press them, swapped as input::poll swaps// them: Settings, down to the confirm button; Cross opens its list,@@ -386,6 +417,10 @@ void autoplayScreens(const ui::Canvas& canvas, uint64_t now) {saveCanvas("ui.ppm");}}+ if (tuneShot) {+ saveCanvas(tuneShot);+ tuneShot = nullptr;+ }if (confirmShot) {confirmShot = false;saveCanvas("confirm2.ppm");diff --git a/src/app/autoplay.h b/src/app/autoplay.hindex a626fd1..53ad25d 100644--- a/src/app/autoplay.h+++ b/src/app/autoplay.h@@ -60,6 +60,7 @@ struct Autoplay {bool updateTest = false; // updatetest: accept the update pop-up, save update.ppm / updating.ppmbool updateSkip = false; // updateskip: "Not now" on the update pop-upbool settingsUpdate = false; // settingsupdate: Settings > Updates, Cross+ bool tuneTest = false; // tunetest: the dead zone's stick tester and the trigger tester (sticks.ppm, triggers.ppm)bool confirmTest = false; // confirmtest: physical Cross / Circle presses through Settings > Confirm buttonbool menuShot = false; // menushot: the game menu open over the 10 s snapshot (screen.ppm)bool pickerTest = false; // pickertest: the confirm button's list (confirm.ppm), the lightdiff --git a/src/app/ps5_main.cpp b/src/app/ps5_main.cppindex 56f58be..6e047a9 100644--- a/src/app/ps5_main.cpp+++ b/src/app/ps5_main.cpp@@ -13,12 +13,14 @@#include "display/display.h"#include "display/gpu.h"#include "input/controller.h"+#include "input/tuning.h"#include "net/http.h"#include "platform/platform.h"#include "ui/app_ui.h"#include "ui/strings.h"#include "util/log.h"+#include <algorithm>#include <cmath>#include <cstdlib>#include <memory>@@ -59,19 +61,11 @@ namespace {std::unique_ptr<ui::ImageCache> g_images;-// The dead zone setting (percent) as an index into ui::kDeadzonePercent.-int deadzoneIndex(int percent) {- int best = 0;- for (int i = 0; i < static_cast<int>(std::size(ui::kDeadzonePercent)); ++i)- if (std::abs(ui::kDeadzonePercent[i] - percent) < std::abs(ui::kDeadzonePercent[best] - percent)) best = i;- return best;-}-// 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::setTriggerRumbleEnabled(g_settings.triggerRumble);+ input::setTriggerFeel(g_settings.triggerStrength, input::kTriggerHz[std::clamp(g_settings.triggerHz, 0, 2)]);input::setCircleConfirms(g_settings.circleConfirms);if (g_ui) g_ui->setCircleConfirms(g_settings.circleConfirms);}@@ -87,8 +81,9 @@ 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 = ui::kDeadzonePercent[choice.deadzone];- g_settings.triggerRumble = choice.triggerRumble;+ g_settings.deadzone = choice.deadzone;+ g_settings.triggerStrength = choice.triggerStrength;+ g_settings.triggerHz = choice.triggerHz;g_settings.circleConfirms = choice.circleConfirms;g_settings.lightBarMode = choice.lightBarMode;g_settings.lightBarColour = choice.lightBarColour;@@ -169,8 +164,9 @@ 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 = deadzoneIndex(g_settings.deadzone);- choice.triggerRumble = g_settings.triggerRumble;+ choice.deadzone = std::clamp(g_settings.deadzone, 0, ui::kMaxDeadzone);+ choice.triggerStrength = g_settings.triggerStrength;+ choice.triggerHz = g_settings.triggerHz;choice.circleConfirms = g_settings.circleConfirms;choice.lightBarMode = g_settings.lightBarMode;choice.lightBarColour = g_settings.lightBarColour;@@ -198,7 +194,7 @@ int main(int argc, char** argv) {// Never return from main: the app is closed from the home screen.input::ControllerState prev{}, pad{};- Repeater up, down, left, right;+ Repeater up, down, left, right, dpadLeft, dpadRight;StreamScreen streamScreen(fonts); // the game's menu and what is laid over ituint64_t padsCheckedAt = 0;unsigned padChecks = 0;@@ -268,6 +264,10 @@ int main(int argc, char** argv) {nav.touchpad = pad.btnTouchpad;nav.stickX = pad.leftStickX;nav.stickY = pad.leftStickY;+ nav.dpadLeft = dpadLeft.update(pad.dpadLeft, now);+ nav.dpadRight = dpadRight.update(pad.dpadRight, now);+ nav.rawLX = pad.rawLeftX, nav.rawLY = pad.rawLeftY, nav.rawRX = pad.rawRightX, nav.rawRY = pad.rawRightY;+ nav.l2Analog = pad.triggerL2, nav.r2Analog = pad.triggerR2;nav.nowMs = now;bool menuCombo = pad.btnOptions && pad.btnTouchpad && !(prev.btnOptions && prev.btnTouchpad);prev = pad;@@ -280,6 +280,20 @@ 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)]);+ float l2, r2;+ static bool testing = false;+ 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;+ } else if (testing) {+ input::setTriggerRumble(0, 0, 0);+ testing = false;+ }+ }if (bool circle = g_ui->circleConfirms(); circle != input::circleConfirms()) {// The confirm button just changed in Settings: the pad follows at// once, and a button still held from choosing it isn't a new press.diff --git a/src/app/settings.cpp b/src/app/settings.cppindex f81717e..7988d88 100644--- a/src/app/settings.cpp+++ b/src/app/settings.cpp@@ -30,7 +30,10 @@ bool Settings::load(const std::string& path) {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));- triggerRumble = (*j)["triggerRumble"].asBool(triggerRumble);+ // "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));circleConfirms = (*j)["circleConfirms"].asBool(circleConfirms);// "lightBar" (on/off) until the colour could be chosen.lightBarMode = (*j)["lightBar"].asBool(true) ? 0 : 2;@@ -76,7 +79,8 @@ bool Settings::save(const std::string& path) const {v.set("deband", deband);v.set("upscaler", upscaler);v.set("deadzone", deadzone);- v.set("triggerRumble", triggerRumble);+ v.set("triggerStrength", triggerStrength);+ v.set("triggerHz", triggerHz);v.set("circleConfirms", circleConfirms);v.set("lightBarMode", lightBarMode);char hex[8];diff --git a/src/app/settings.h b/src/app/settings.hindex bcea7e6..770298a 100644--- a/src/app/settings.h+++ b/src/app/settings.h@@ -33,7 +33,10 @@ struct Settings {// Controller: stick dead zone (percent), vibration in the triggers,// Circle as the confirm button (Xbox A).int deadzone = 15;- bool triggerRumble = true;+ // Trigger vibration: strength 0 (off) .. 4 (max), its frequency as an+ // index into input::kTriggerHz (input/tuning.h).+ int triggerStrength = 2;+ int triggerHz = 1;bool 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 cbead29..9c0f91c 100644--- a/src/input/controller.cpp+++ b/src/input/controller.cpp@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-3.0-or-later// Copyright (C) 2026 RafaelNGP#include "input/controller.h"+#include "input/tuning.h"#include "util/log.h"#include <algorithm>@@ -101,18 +102,6 @@ namespace xc::input {namespace {-constexpr uint8_t kTriggerVibrationHz = 60;--// Xbox impulse-trigger level (0..255) -> DualSense trigger amplitude (1..8).-// Games ask for little (Halo's shots: 15 %), which the Xbox's trigger motors-// turn into a clear kick; linearly it would be amplitude 1, which drowns-// under the grip motors. A square-root curve: 15 % -> 4, 50 % -> 6.-uint8_t triggerAmplitude(uint8_t level) {- if (!level) return 0;- int a = static_cast<int>(std::ceil(8.0 * std::sqrt(level / 255.0)));- return static_cast<uint8_t>(std::clamp(a, 2, 8));-}-// A rumble request: packed as a << 8 | b, and when it ends (0 = never).struct Rumble {std::atomic<uint32_t> wanted{0};@@ -152,14 +141,13 @@ struct Pad {};Pad g_pads[kMaxPads];std::atomic<float> g_deadzone{0.15f};-std::atomic<bool> g_circleConfirms{false}, g_triggerRumble{true};-bool g_rumbleLogged = false, g_triggerLogged = false;+std::atomic<bool> g_circleConfirms{false};+std::atomic<int> g_triggerStrength{kTriggerMedium}, g_triggerHz{60};+bool g_rumbleLogged = false;inline float normStick(uint8_t val) {- // 0..255 -> -1.0 .. 1.0, nothing inside the dead zone- float v = (static_cast<float>(val) - 128.0f) / 128.0f;- if (std::abs(v) < g_deadzone.load(std::memory_order_relaxed)) return 0.0f;- return std::clamp(v, -1.0f, 1.0f);+ // 0..255 -> -1.0 .. 1.0+ return std::clamp((static_cast<float>(val) - 128.0f) / 128.0f, -1.0f, 1.0f);}inline float normTrigger(uint8_t val) {@@ -242,16 +230,21 @@ void applyRumble(Pad& pad) {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) {- if (!level[t]) continue; // mode 0: off+ uint8_t amplitude = triggerAmplitude(level[t], strength);+ if (!amplitude) continue; // mode 0: offp.command[t].mode = 3;p.command[t].data[0] = 0; // from the top of the travel- p.command[t].data[1] = triggerAmplitude(level[t]);- p.command[t].data[2] = kTriggerVibrationHz;+ 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);- if (!g_triggerLogged || rc != 0) XC_LOGI("scePadSetTriggerEffect(%u, %u): 0x%08x", level[0], level[1], rc);- g_triggerLogged = true;+ 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;}}@@ -262,7 +255,7 @@ void setRumble(uint8_t large, uint8_t small, uint32_t durationMs, int pad) {}void setTriggerRumble(uint8_t left, uint8_t right, uint32_t durationMs, int pad) {- if (!g_triggerRumble) left = right = 0;+ if (g_triggerStrength <= 0) left = right = 0;if (pad >= 0 && pad < kMaxPads) g_pads[pad].triggers.set(left, right, durationMs);}@@ -284,10 +277,15 @@ std::string padUserName(int index) {return index >= 0 && index < kMaxPads && g_pads[index].handle >= 0 ? g_pads[index].name : "";}-void setTriggerRumbleEnabled(bool on) {- g_triggerRumble = on;- if (!on)- for (Pad& p : g_pads) p.triggers.set(0, 0, 0);+void setTriggerFeel(int strength, int hz) {+ if (strength == g_triggerStrength && hz == g_triggerHz) return;+ 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;+ }}void setDeadzone(float deadzone) { g_deadzone = std::clamp(deadzone, 0.0f, 0.5f); }@@ -383,10 +381,13 @@ bool pollPad(int index, ControllerState& out) {out.btnTouchpad = (b & 0x100000) != 0;// Analog- out.leftStickX = normStick(pad.leftStick.x);- out.leftStickY = normStick(pad.leftStick.y);- out.rightStickX = normStick(pad.rightStick.x);- out.rightStickY = normStick(pad.rightStick.y);+ out.rawLeftX = out.leftStickX = normStick(pad.leftStick.x);+ 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);out.triggerL2 = normTrigger(pad.l2);out.triggerR2 = normTrigger(pad.r2);@@ -425,7 +426,7 @@ 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 setTriggerRumbleEnabled(bool) {}+void setTriggerFeel(int, int) {}} // namespace xc::input#endifdiff --git a/src/input/controller.h b/src/input/controller.hindex efa1ae4..9edfc21 100644--- a/src/input/controller.h+++ b/src/input/controller.h@@ -30,11 +30,13 @@ struct ControllerState {bool btnTouchpad = false; // View / Selectbool btnNexus = false; // the Xbox button (from the game menu; the PS button stays the system's)- // Analog axes [-1.0 .. 1.0]+ // Analog axes [-1.0 .. 1.0], after the dead zonefloat leftStickX = 0.0f;float leftStickY = 0.0f;float rightStickX = 0.0f;float rightStickY = 0.0f;+ // The same before it (the Settings stick tester)+ float rawLeftX = 0.0f, rawLeftY = 0.0f, rawRightX = 0.0f, rawRightY = 0.0f;// Triggers [0.0 .. 1.0]float triggerL2 = 0.0f;@@ -73,8 +75,9 @@ void setDeadzone(float deadzone);// Circle reported as Cross (Xbox A) and Cross as Circle, everywhere.void setCircleConfirms(bool on);bool circleConfirms();-// Off: setTriggerRumble() is ignored.-void setTriggerRumbleEnabled(bool on);+// 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);// 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.hnew file mode 100644index 0000000..3d5b78e--- /dev/null+++ b/src/input/tuning.h@@ -0,0 +1,47 @@+// SPDX-License-Identifier: GPL-3.0-or-later+// Copyright (C) 2026 RafaelNGP+// How the stick dead zone and the trigger vibration are worked out: shared+// by the controller code, the Settings testers that show them, and the tests.+#pragma once++#include <algorithm>+#include <cmath>+#include <cstdint>++namespace xc::input {++// A radial dead zone with rescaling: nothing while the stick is within+// `deadzone` (0..1) of the centre, then 0..1 over the rest of the travel, in+// the direction the stick points (no axis snaps to zero near the other).+inline void radialDeadzone(float& x, float& y, float deadzone) {+ float m = std::hypot(x, y);+ if (m <= deadzone || m <= 0) {+ x = y = 0;+ return;+ }+ float k = std::min(1.0f, (m - deadzone) / (1.0f - deadzone)) / m;+ x = std::clamp(x * k, -1.0f, 1.0f);+ y = std::clamp(y * k, -1.0f, 1.0f);+}++// Trigger vibration strengths (Settings): off, light, medium, strong, max.+constexpr int kTriggerStrengths = 5;+constexpr int kTriggerMedium = 2;+// The vibration's frequency choices, Hz: low (a thump), medium, high (a buzz).+constexpr int kTriggerHz[] = {30, 60, 120};++// Xbox impulse-trigger level (0..255) -> DualSense trigger amplitude (0..8).+// Games ask for little (Halo's shots: 15 %), which the Xbox's trigger motors+// turn into a clear kick; linearly it would be amplitude 1, which drowns+// under the grip motors. A square-root curve: 15 % -> 4, 50 % -> 6 at medium+// strength; light halves it, strong is 1.5 times, max always 8.+inline uint8_t triggerAmplitude(uint8_t level, int strength = kTriggerMedium) {+ if (!level || strength <= 0) return 0;+ if (strength >= 4) return 8;+ static constexpr float kScale[] = {0, 0.5f, 1.0f, 1.5f};+ float a = std::ceil(8.0f * std::sqrt(level / 255.0f));+ a = std::max(a, 2.0f) * kScale[strength];+ return static_cast<uint8_t>(std::clamp(static_cast<int>(std::lround(a)), 1, 8));+}++} // namespace xc::inputdiff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cppindex 207ab68..39a812e 100644--- a/src/ui/app_ui.cpp+++ b/src/ui/app_ui.cpp@@ -2,6 +2,7 @@// Copyright (C) 2026 RafaelNGP#include "ui/app_ui.h"+#include "input/tuning.h"#include "ui/accent_color.h"#include "ui/brand.h"@@ -705,6 +706,61 @@ bool AppUi::settingsLightBar(int& mode, Color& colour) const {return true;}+bool AppUi::settingsTriggerFeel(int& strength, int& hzIndex) const {+ std::lock_guard<std::mutex> lock(mutex_);+ if (screen_ != Screen::Settings) return false;+ strength = settings_.triggerStrength;+ hzIndex = settings_.triggerHz;+ return true;+}++bool AppUi::triggerTest(float& l2, float& r2) const {+ std::lock_guard<std::mutex> lock(mutex_);+ if (screen_ != Screen::Settings || tester_ != Tester::Triggers) return false;+ l2 = testL2_;+ r2 = testR2_;+ return true;+}++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;+ dirty_ = true;+}++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;+ 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;+ 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) 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];+ }+ if (in.accept || in.back) {+ tester_ = Tester::None;+ testL2_ = testR2_ = 0;+ dirty_ = true;+ }+}+void AppUi::openColourPicker(int previousMode) {// Caller holds mutex_. Starts on the colour saved.float h, s, v;@@ -874,9 +930,10 @@ 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 : kDeadzonePercent) out.push_back(std::to_string(p) + " %");+ for (int p = 0; p <= kMaxDeadzone; ++p) out.push_back(std::to_string(p) + " %");} else if (row == 4) {- out = {tr(Str::Activated), tr(Str::Deactivated)};+ out = {tr(Str::Deactivated), tr(Str::TriggerLight), tr(Str::TriggerMedium), tr(Str::TriggerStrong),+ tr(Str::TriggerMax)};} else if (row == 5) {out = {"", ""}; // Cross, Circle: drawn as the buttons} else if (row == 6) {@@ -901,7 +958,7 @@ int AppUi::settingSelected(int row) const {if (kResolutionOrder[i] == settings_.resolution) return i;}if (row == 3) return settings_.deadzone;- if (row == 4) return settings_.triggerRumble ? 0 : 1;+ if (row == 4) return settings_.triggerStrength;if (row == 5) return settings_.circleConfirms ? 1 : 0;if (row == 6) return settings_.lightBarMode;if (row == 7) return 0;@@ -920,7 +977,7 @@ void AppUi::applySetting(int row, int index) {} else if (row == 3) {settings_.deadzone = index;} else if (row == 4) {- settings_.triggerRumble = index == 0;+ settings_.triggerStrength = index;} else if (row == 5) {settings_.circleConfirms = index == 1;circleConfirms_ = settings_.circleConfirms; // in force at once: the next press already uses it@@ -1273,6 +1330,10 @@ UiEvent AppUi::handle(const NavInput& in) {handleColourPicker(in);break;}+ if (tester_ != Tester::None) {+ handleTester(in);+ break;+ }if (dropdownOpen_) {// The list: up / down, Cross picks, Circle closes it unchanged.int n = static_cast<int>(settingOptions(settingsRow_).size());@@ -1289,7 +1350,10 @@ UiEvent AppUi::handle(const NavInput& in) {if (in.up && settingsRow_ > 0) --settingsRow_, dirty_ = true;if (in.right) changeSetting(+1);if (in.left) changeSetting(-1);- if (in.accept && settingsRow_ == 7) {+ if (in.accept && (settingsRow_ == 3 || settingsRow_ == 4)) {+ // Dead zone, trigger vibration: their testers instead of a list.+ openTester(settingsRow_ == 3 ? Tester::Sticks : Tester::Triggers);+ } else if (in.accept && settingsRow_ == 7) {// Updates: a newer version is installed (the settings saved first).if (!updateAvailable_.empty() && !updateChecking_) {ev.action = Action::UpdateNow;@@ -2228,6 +2292,8 @@ void AppUi::drawSettings(Canvas& c) {drawColourPicker(c);return;}+ if (tester_ == Tester::Sticks) return drawStickTester(c);+ if (tester_ == Tester::Triggers) return drawTriggerTester(c);if (dropdownOpen_) {// The list under (or, near the bottom, over) the row, right-aligned// with it; scrolls past kVisible choices.@@ -2305,6 +2371,96 @@ void AppUi::drawUpdatePrompt(Canvas& c) {drawHints(c, {{kIconCross, tr(Str::Select)}, {kIconCircle, tr(Str::NotNow)}});}+Rect AppUi::drawModal(Canvas& c, int w, int h, const std::string& title) {+ c.fillRect({0, 0, kW, kH}, rgba(0, 0, 0, 160));+ Rect panel{(kW - w) / 2, (kH - h) / 2 - 30, w, h};+ c.fillRect({panel.x + 8, panel.y + 12, panel.w, panel.h}, rgba(0, 0, 0, 120), 26); // shadow+ c.fillRect(panel, kPanel, 24);+ c.strokeRect(panel, rgba(255, 255, 255, 50), 2, 24);+ fonts_.bold.draw(c, title, panel.x + 56, panel.y + 44, 40, kWhite);+ c.fillRect({0, kH - 80, kW, 80}, kBg); // Settings' hints, under the panel's+ drawHints(c, {{kIconCross, tr(Str::Select)}, {kIconCircle, tr(Str::Back)}});+ return panel;+}++void AppUi::drawStickTester(Canvas& c) {+ Rect panel = drawModal(c, 1240, 700, std::string(tr(Str::Deadzone)) + ": " + std::to_string(settings_.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));+ 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));+ // The dead zone: nothing reaches the game in there.+ if (dz > 0) {+ c.fillCircle(cx, cy, dz * R, rgba(230, 70, 70, 60));+ c.strokeArc(cx, cy, dz * R, 2, 0, 6.2832f, rgba(230, 90, 90, 180));+ }+ float x = testSticks_[2 * s], y = testSticks_[2 * s + 1], gx = x, gy = y;+ input::radialDeadzone(gx, gy, dz);+ c.fillCircle(cx + x * R, cy + y * R, 9, raw);+ c.fillCircle(cx + gx * R, cy + gy * R, 12, game);+ const char* name = tr(s ? Str::StickRight : Str::StickLeft);+ fonts_.semibold.draw(c, name, static_cast<int>(cx) - fonts_.semibold.measure(name, 26) / 2, static_cast<int>(cy) + R + 22,+ 26, kWhite);+ // How far each one is, in percent of the travel.+ auto pct = [](float a, float b) { return std::to_string(static_cast<int>(std::lround(std::min(1.0f, std::hypot(a, b)) * 100))) + " %"; };+ std::string line = pct(x, y) + " \xE2\x86\x92 " + pct(gx, gy);+ int tw = fonts_.regular.measure(line, 24);+ fonts_.regular.draw(c, line, static_cast<int>(cx) - tw / 2, static_cast<int>(cy) + R + 58, 24, kGray);+ }+ // The legend, then the help.+ int ly = panel.y + panel.h - 92, lx = panel.x + 56;+ c.fillCircle(lx + 9.0f, ly + 13.0f, 9, raw);+ fonts_.regular.draw(c, tr(Str::StickPosition), lx + 28, ly, 24, kGray);+ lx += 28 + fonts_.regular.measure(tr(Str::StickPosition), 24) + 48;+ c.fillCircle(lx + 12.0f, ly + 13.0f, 12, game);+ fonts_.regular.draw(c, tr(Str::StickGameGets), lx + 32, ly, 24, kGray);+ fonts_.regular.draw(c, tr(Str::StickTestHelp), panel.x + 56, ly + 44, 22, kDim);+}++void AppUi::drawTriggerTester(Canvas& c) {+ Rect panel = drawModal(c, 1100, 700, 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 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) {+ 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);+ if (on) c.strokeRect({r.x - 5, r.y - 5, r.w + 10, r.h + 10}, kWhite, 3, 20);+ fonts_.semibold.draw(c, labels[i], r.x + 36, fonts_.semibold.centeredY(r.y, r.h, 30), 30, kWhite);+ std::string v = "\xE2\x80\xB9 " + values[i] + " \xE2\x80\xBA"; // ‹ value ›+ int w = fonts_.regular.measure(v, 30);+ fonts_.regular.draw(c, v, r.x + r.w - 36 - w, fonts_.regular.centeredY(r.y, r.h, 30), 30, on ? kWhite : kGray);+ }+ // 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;+ 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);+ if (fill > 0) c.fillRect({bx, by + kBarH - fill, kBarW, fill}, level ? rgba(90, 220, 110) : rgba(120, 120, 120), 16);+ std::string name = t ? "R2" : "L2";+ fonts_.bold.draw(c, name, bx + (kBarW - fonts_.bold.measure(name, 26)) / 2, by + kBarH + 14, 26, kWhite);+ std::string lv = trf(Str::TriggerLevel, std::to_string(level) + " / 8");+ fonts_.regular.draw(c, lv, bx + (kBarW - fonts_.regular.measure(lv, 22)) / 2, by + kBarH + 48, 22, kGray);+ }+ auto help = fonts_.regular.wrap(tr(Str::TriggerTestHelp), 22, panel.w - 112, 2);+ for (size_t i = 0; i < help.size(); ++i)+ fonts_.regular.draw(c, help[i], panel.x + 56, panel.y + panel.h - 70 + static_cast<int>(i) * 30, 22, kDim);+}+void AppUi::drawColourPicker(Canvas& c) {c.fillRect({0, 0, kW, kH}, rgba(0, 0, 0, 160));constexpr int kPanelW = 1000, kPanelH = 540;diff --git a/src/ui/app_ui.h b/src/ui/app_ui.hindex c842418..5fb7117 100644--- a/src/ui/app_ui.h+++ b/src/ui/app_ui.h@@ -70,6 +70,11 @@ struct NavInput {bool l2 = false, r2 = false; // pressed (triggers past halfway)bool touchpad = false; // held right now (sign out needs a 5 s hold)float stickX = 0, stickY = 0; // the left stick, -1..1 (the colour picker)+ // For the Settings testers: the D-pad alone (with repeat), the sticks+ // before the dead zone, and how far the triggers are pressed (0..1).+ bool dpadLeft = false, dpadRight = false;+ float rawLX = 0, rawLY = 0, rawRX = 0, rawRY = 0;+ float l2Analog = 0, r2Analog = 0;uint64_t nowMs = 0;};@@ -78,15 +83,16 @@ 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 = 3; // index into kDeadzonePercent (15 %)- bool triggerRumble = true;+ 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::kTriggerHzbool 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);};-// The stick dead zones Settings offers, in percent of the travel.-constexpr int kDeadzonePercent[] = {0, 5, 10, 15, 20, 25};+// The largest stick dead zone Settings offers, in percent of the travel.+constexpr int kMaxDeadzone = 30;constexpr int kSettingRows = 8; // language, resolution, region, dead zone, triggers, confirm, light bar, updates// ConsolesShown: "My consoles" opened (its list is refreshed). UpdateNow@@ -185,6 +191,11 @@ public:// While Settings is open: the light bar being chosen there (the colour// picker's colour as it moves), so the pad shows it at once.bool settingsLightBar(int& mode, Color& colour) const;+ // 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 triggerTest(float& l2, float& r2) const;// Regions offered by the account's xCloud login; `defaultRegion` is the// one "Automatic" picks.void setRegions(std::vector<std::string> regions, const std::string& defaultRegion);@@ -275,6 +286,14 @@ private:void handleColourPicker(const NavInput& in);Color pickerColour() const;void drawColourPicker(Canvas& c);+ // The testers that Dead zone and Trigger vibration open in Settings.+ enum class Tester { None, Sticks, Triggers };+ void openTester(Tester t);+ void handleTester(const NavInput& in);+ void drawStickTester(Canvas& c);+ void drawTriggerTester(Canvas& c);+ // A modal panel over Settings with its title; returns its rectangle.+ Rect drawModal(Canvas& c, int w, int h, const std::string& title);void drawUpdating(Canvas& c, uint64_t nowMs);void changeSetting(int delta);// Settings drop-downs: the choices of a row, the chosen one, choosing.@@ -350,6 +369,10 @@ private:int promptFocus_ = 0; // 0 Update now, 1 Not nowstd::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+ 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 = saturationfloat pickValue_ = 1; // brightnessdiff --git a/src/ui/strings.cpp b/src/ui/strings.cppindex 51fb7d1..62d9fa6 100644--- a/src/ui/strings.cpp+++ b/src/ui/strings.cpp@@ -195,6 +195,21 @@ constexpr Column kEnglish = {"Custom colour", // LightBarCustom"Light bar colour", // LightBarColour"Left stick or D-pad: colour L2 / R2: brightness", // ColourPickerHelp+ "Light", // TriggerLight+ "Medium", // TriggerMedium+ "Strong", // TriggerStrong+ "Max", // TriggerMax+ "Intensity", // TriggerIntensity+ "Frequency", // TriggerFrequency+ "Low", // FrequencyLow+ "High", // FrequencyHigh+ "Press L2 / R2 to feel it: the deeper, the stronger the game would ask", // TriggerTestHelp+ "Level %s", // TriggerLevel+ "Left stick", // StickLeft+ "Right stick", // StickRight+ "Stick position", // StickPosition+ "What the game gets", // StickGameGets+ "D-pad ← / →: adjust Move the sticks to see it", // StickTestHelp};constexpr Column kPortugueseBR = {@@ -360,6 +375,21 @@ constexpr Column kPortugueseBR = {"Cor personalizada","Cor da barra de luz","Analógico esquerdo ou direcional: cor L2 / R2: brilho",+ "Leve",+ "Média",+ "Forte",+ "Máxima",+ "Intensidade",+ "Frequência",+ "Grave",+ "Aguda",+ "Aperte L2 / R2 para sentir: quanto mais fundo, mais forte o jogo pediria",+ "Nível %s",+ "Analógico esquerdo",+ "Analógico direito",+ "Posição real",+ "O que o jogo recebe",+ "Direcional ← / →: ajustar Mova os analógicos para ver",};constexpr Column kSpanish = {@@ -525,6 +555,21 @@ constexpr Column kSpanish = {"Color personalizado","Color de la barra de luz","Stick izquierdo o cruceta: color L2 / R2: brillo",+ "Suave",+ "Media",+ "Fuerte",+ "Máxima",+ "Intensidad",+ "Frecuencia",+ "Grave",+ "Aguda",+ "Pulsa L2 / R2 para sentirlo: cuanto más a fondo, más fuerte lo pediría el juego",+ "Nivel %s",+ "Stick izquierdo",+ "Stick derecho",+ "Posición real",+ "Lo que recibe el juego",+ "Cruceta ← / →: ajustar Mueve los sticks para verlo",};constexpr Column kFrench = {@@ -690,6 +735,21 @@ constexpr Column kFrench = {"Couleur personnalisée","Couleur de la barre lumineuse","Joystick gauche ou croix : couleur L2 / R2 : luminosité",+ "Légère",+ "Moyenne",+ "Forte",+ "Maximale",+ "Intensité",+ "Fréquence",+ "Grave",+ "Aiguë",+ "Appuyez sur L2 / R2 pour le sentir : plus vous enfoncez, plus le jeu le demanderait fort",+ "Niveau %s",+ "Joystick gauche",+ "Joystick droit",+ "Position réelle",+ "Ce que reçoit le jeu",+ "Croix ← / → : régler Bougez les joysticks pour le voir",};constexpr Column kGerman = {@@ -855,6 +915,21 @@ constexpr Column kGerman = {"Eigene Farbe","Farbe der Lichtleiste","Linker Stick oder Steuerkreuz: Farbe L2 / R2: Helligkeit",+ "Leicht",+ "Mittel",+ "Stark",+ "Maximal",+ "Stärke",+ "Frequenz",+ "Tief",+ "Hoch",+ "L2 / R2 drücken zum Fühlen: je tiefer, desto stärker würde es das Spiel verlangen",+ "Stufe %s",+ "Linker Stick",+ "Rechter Stick",+ "Tatsächliche Position",+ "Was das Spiel bekommt",+ "Steuerkreuz ← / →: einstellen Sticks bewegen zum Sehen",};constexpr Column kItalian = {@@ -1020,6 +1095,21 @@ constexpr Column kItalian = {"Colore personalizzato","Colore della barra luminosa","Levetta sinistra o croce: colore L2 / R2: luminosità",+ "Leggera",+ "Media",+ "Forte",+ "Massima",+ "Intensità",+ "Frequenza",+ "Bassa",+ "Alta",+ "Premi L2 / R2 per sentirlo: più a fondo, più forte lo chiederebbe il gioco",+ "Livello %s",+ "Levetta sinistra",+ "Levetta destra",+ "Posizione reale",+ "Ciò che riceve il gioco",+ "Croce ← / →: regolare Muovi le levette per vederlo",};constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,diff --git a/src/ui/strings.h b/src/ui/strings.hindex d3827a4..350d7d4 100644--- a/src/ui/strings.h+++ b/src/ui/strings.h@@ -172,6 +172,21 @@ enum class Str {LightBarCustom, // Settings > Light bar: one the user picksLightBarColour, // the colour picker's titleColourPickerHelp, // under the colour picker+ TriggerLight, // trigger vibration strengths (after Deactivated)+ TriggerMedium, // also the middle frequency+ TriggerStrong,+ TriggerMax,+ TriggerIntensity, // the trigger tester's rows+ TriggerFrequency,+ FrequencyLow,+ FrequencyHigh,+ TriggerTestHelp, // under the trigger tester+ TriggerLevel, // "%s" = 0..8, the strength sent to the trigger+ StickLeft, // the stick tester+ StickRight,+ StickPosition, // legend: the grey dot+ StickGameGets, // legend: the green dot+ StickTestHelp, // under the stick testerCount};diff --git a/tests/test_main.cpp b/tests/test_main.cppindex 65902d9..1a2c87b 100644--- a/tests/test_main.cpp+++ b/tests/test_main.cpp@@ -5,6 +5,7 @@#include "app/settings.h"#include "app/update_check.h"#include "app/updater.h"+#include "input/tuning.h"#include "net/http.h"#include "platform/platform.h"#include "stream/input_packet.h"@@ -17,6 +18,7 @@#include "xcloud/prices.h"#include "xcloud/regions.h"+#include <cmath>#include <cstdio>#include <cstdlib>#include <vector>@@ -236,6 +238,8 @@ static void testSettingsMigration() {CHECK(old.save(path));xc::app::Settings again;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);// 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;@@ -380,6 +384,29 @@ static void testUpdater() {std::system(("rm -rf " + dir).c_str());}+static void testControllerTuning() {+ using xc::input::radialDeadzone;+ using xc::input::triggerAmplitude;+ auto near = [](float a, float b) { return std::abs(a - b) < 0.01f; };+ float x = 0.1f, y = 0.1f;+ radialDeadzone(x, y, 0.15f); // |0.14| < 0.15: nothing+ CHECK(x == 0 && y == 0);+ x = 1, y = 0;+ radialDeadzone(x, y, 0.15f); // the edge stays the edge+ CHECK(near(x, 1) && y == 0);+ x = 0.575f, y = 0;+ radialDeadzone(x, y, 0.15f); // halfway out of the dead zone -> 0.5, from 0 (no jump)+ CHECK(near(x, 0.5f));+ x = 0.6f, y = 0.1f; // a diagonal near the X axis keeps its Y (no snapping to the axis)+ radialDeadzone(x, y, 0.15f);+ CHECK(y > 0.05f && near(y / x, 0.1f / 0.6f));++ CHECK(triggerAmplitude(38) == 4 && triggerAmplitude(128) == 6); // medium: as before+ 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);+}+static void testAutoDeband() {using xc::app::debandForMbps;CHECK(debandForMbps(0.3, 1) == -1); // starting or standing still: no measure@@ -406,6 +433,7 @@ static void testAutoDeband() {int main() {testAutoDeband();+ testControllerTuning();testUpdater();testAccentColor();testVersions();