Created
August 10, 2021 03:14
-
-
Save wesalvaro/a4a21fc3d1eebe58878b6516d9357245 to your computer and use it in GitHub Desktop.
Use the Zuiki Densha-de-GO! controller for the Nintendo Switch on the PlayStation. Out of the box, it functions but the mascon values do not map correctly. This script translates the Nintendo Switch accepted values into values accepted by the PlayStation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma METAINFO("Zuiki Densha-de-GO! for PS4", 1, 0, "Wes Alvaro") | |
// Converts NS Zuiki Densha-de-GO! controller mascon values for PS4. | |
// Mascon values need conversion or else mascon positions are skipped. | |
// No changes are needed for other controls (including EB). | |
// Controls should be set to 「スタンダード」"Standard" + 「ダイレクト」"Direct". | |
#include <switch.gph> | |
// The mascon is controlled with the left analog stick's y-axis. | |
// Values are negative for braking, positive for powering, 0 when neutral. | |
#define MASCON SWITCH_LY | |
// The following values were from my controller and Titan 2. | |
// It's possible that these values are not consistent across all controllers. | |
// To account for differences, an epsilon of 5 (which is equal to half of the | |
// smallest range 10) is added when making comparisons. Sadly, the input values | |
// can't be easily recognized by a function due to their curious value jumps. | |
// Power Corrections: | |
// Input values to Titan 2 from NS Zuiki: | |
#define NS_B8 -96.08 | |
#define NS_B7 -85.10 | |
#define NS_B6 -74.90 | |
#define NS_B5 -63.92 | |
#define NS_B4 -52.94 | |
#define NS_B3 -42.75 | |
#define NS_B2 -31.76 | |
#define NS_B1 -20.78 | |
#define NS_N 00.39 | |
#define NS_P1 24.71 | |
#define NS_P2 43.53 | |
#define NS_P3 61.57 | |
#define NS_P4 80.39 | |
#define NS_P5 100.0 | |
// Output values from Titan 2 to PS4: | |
// The following values are accepted by the PS4 for Standard + Direct controls. | |
// These values don't need any adjustment as they are unrelated to hardware. | |
// The positions map 1-to-1 with the NS_ values above. | |
#define PS_B8 -100.0 | |
#define PS_B7 -90.00 | |
#define PS_B6 -75.00 | |
#define PS_B5 -65.00 | |
#define PS_B4 -60.00 | |
#define PS_B3 -50.00 | |
#define PS_B2 -40.00 | |
#define PS_B1 -30.00 | |
#define PS_N 00.00 | |
#define PS_P1 40.00 | |
#define PS_P2 50.00 | |
#define PS_P3 60.00 | |
#define PS_P4 80.00 | |
#define PS_P5 100.0 | |
// Epsilon for NS input value differences between hardware: | |
#define E 5.0 | |
#define IF_POS(NS, PS) if (pOut < NS + E) { pOut = PS; } | |
#define ELSE_IF_POS(NS, PS) else IF_POS(NS, PS) | |
main { | |
// Initialize the output to the current value of the mascon: | |
fix32 pOut = get_val(MASCON); | |
// Translate mascon position value from NS to PS values: | |
IF_POS(NS_B8, PS_B8) | |
ELSE_IF_POS(NS_B7, PS_B7) | |
ELSE_IF_POS(NS_B6, PS_B6) | |
ELSE_IF_POS(NS_B5, PS_B5) | |
ELSE_IF_POS(NS_B4, PS_B4) | |
ELSE_IF_POS(NS_B3, PS_B3) | |
ELSE_IF_POS(NS_B2, PS_B2) | |
ELSE_IF_POS(NS_B1, PS_B1) | |
ELSE_IF_POS( NS_N, PS_N) | |
ELSE_IF_POS(NS_P1, PS_P1) | |
ELSE_IF_POS(NS_P2, PS_P2) | |
ELSE_IF_POS(NS_P3, PS_P3) | |
ELSE_IF_POS(NS_P4, PS_P4) | |
ELSE_IF_POS(NS_P5, PS_P5) | |
// Set adjusted mascon position value: | |
set_val(MASCON, pOut); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't know if I had messed my configuration or if something had changed, but the old Yamanote line trains (103 & 205) are controlled by pushing the right stick right (to brake on both), and pushing the left stick left (to accelerate on 103).
I updated the script to support these also. 103 has fewer steps, so there are some gaps where intermediate steps don't change the brake value, but otherwise it seems to work fine... I mapped the acceleration gap to the last step to make it smoother, but can't do the same for braking without breaking 205.
https://gist.github.com/vlumi/906a68ae04c9e880a2354c9448b40f69
Also, for the record, my Zuiki controller has the exact same input values, so I reckon they are fixed.