From 7b13ccdd18c179704aee8df8a587824780e41b6e Mon Sep 17 00:00:00 2001 From: dualshock-tools Date: Tue, 18 Jun 2024 11:34:05 +0200 Subject: [PATCH] Add joystick information --- core.js | 299 +++++++++++++++++++++++++++++++++++++++++++++++- index.html | 57 ++++++++- lang/bg_bg.json | 19 +-- lang/de_de.json | 19 +-- lang/es_es.json | 19 +-- lang/fr_fr.json | 98 ++++++++-------- lang/hu_hu.json | 12 +- lang/it_it.json | 5 +- lang/jp_jp.json | 19 +-- lang/pl_pl.json | 4 + lang/pt_br.json | 19 +-- lang/ru_ru.json | 19 +-- lang/tr_tr.json | 19 +-- lang/zh_cn.json | 4 + 14 files changed, 493 insertions(+), 119 deletions(-) diff --git a/core.js b/core.js index 934b217..b012f0c 100644 --- a/core.js +++ b/core.js @@ -780,7 +780,7 @@ async function disconnect() { device.close(); device = null; disable_btn = false; - + reset_circularity(); $("#offlinebar").show(); $("#onlinebar").hide(); $("#mainmenu").hide(); @@ -845,6 +845,8 @@ function gboot() { window.addEventListener('DOMContentLoaded', function() { lang_init(); welcome_modal(); + $("#checkCircularity").on('change', on_circ_check_change); + on_circ_check_change(); }); if (!("hid" in navigator)) { @@ -873,6 +875,286 @@ function alloc_req(id, data=[]) { return out; } +var last_lx = 0, last_ly = 0, last_rx = 0, last_ry = 0; +var ll_updated = false; + +var ll_data=new Array(48); +var rr_data=new Array(48); +var enable_circ_test = false; + +function reset_circularity() { + for(i=0;i 0.2) { + lcounter += 1; + ofl += Math.pow(ll_data[i] - 1, 2); + } + for (i=0;i 0.2) { + rcounter += 1; + ofr += Math.pow(rr_data[i] - 1, 2); + } + } + if(lcounter > 0) + ofl = Math.sqrt(ofl / lcounter) * 100; + if(rcounter > 0) + ofr = Math.sqrt(ofr / rcounter) * 100; + + el = ofl.toFixed(2) + "%"; + er = ofr.toFixed(2) + "%"; + $("#el-lbl").text(el); + $("#er-lbl").text(er); + } +} + +function circ_checked() { return $("#checkCircularity").is(':checked') } + +function on_circ_check_change() { + enable_circ_test = circ_checked(); + for(i=0;i= -0.004) return "+0.00"; + return (f<0?"":"+") + f.toFixed(2); +} + +var on_delay = false; + +function timeout_ok() { + on_delay = false; + if(ll_updated) + refresh_stick_pos(); +} + +function refresh_sticks() { + if(on_delay) + return; + + refresh_stick_pos(); + on_delay = true; + setTimeout(timeout_ok, 20); +} + +function process_ds4_input(data) { + var lx = data.data.getUint8(0); + var ly = data.data.getUint8(1); + var rx = data.data.getUint8(2); + var ry = data.data.getUint8(3); + + var new_lx = Math.round((lx - 127.5) / 128 * 100) / 100; + var new_ly = Math.round((ly - 127.5) / 128 * 100) / 100; + var new_rx = Math.round((rx - 127.5) / 128 * 100) / 100; + var new_ry = Math.round((ry - 127.5) / 128 * 100) / 100; + + if(last_lx != new_lx || last_ly != new_ly || last_rx != new_rx || last_ry != new_ry) { + last_lx = new_lx; + last_ly = new_ly; + last_rx = new_rx; + last_ry = new_ry; + ll_updated = true; + refresh_sticks(); + } +} + +function process_ds_input(data) { + var lx = data.data.getUint8(0); + var ly = data.data.getUint8(1); + var rx = data.data.getUint8(2); + var ry = data.data.getUint8(3); + + var new_lx = Math.round((lx - 127.5) / 128 * 100) / 100; + var new_ly = Math.round((ly - 127.5) / 128 * 100) / 100; + var new_rx = Math.round((rx - 127.5) / 128 * 100) / 100; + var new_ry = Math.round((ry - 127.5) / 128 * 100) / 100; + + if(last_lx != new_lx || last_ly != new_ly || last_rx != new_rx || last_ry != new_ry) { + last_lx = new_lx; + last_ly = new_ly; + last_rx = new_rx; + last_ry = new_ry; + ll_updated = true; + refresh_sticks(); + } +} + async function continue_connection(report) { try { device.oninputreport = null; @@ -894,18 +1176,21 @@ async function continue_connection(report) { connected = true; mode = 1; devname = l("Sony DualShock 4 V1"); + device.oninputreport = process_ds4_input; } } else if(device.productId == 0x09cc) { if(await ds4_info()) { connected = true; mode = 1; devname = l("Sony DualShock 4 V2"); + device.oninputreport = process_ds4_input; } } else if(device.productId == 0x0ce6) { if(await ds5_info()) { connected = true; mode = 2; devname = l("Sony DualSense"); + device.oninputreport = process_ds_input; } } else if(device.productId == 0x0df2) { if(await ds5_info()) { @@ -962,6 +1247,7 @@ async function continue_connection(report) { async function connect() { gj = crypto.randomUUID(); + reset_circularity(); la("begin"); try { $("#btnconnect").prop("disabled", true); @@ -1059,9 +1345,10 @@ async function multi_calib_sticks_begin(pc) { async function multi_calib_sticks_end(pc) { if(mode == 1) - return ds4_calibrate_sticks_end(pc); + await ds4_calibrate_sticks_end(pc); else - return ds5_calibrate_sticks_end(pc); + await ds5_calibrate_sticks_end(pc); + on_circ_check_change(); } async function multi_calib_sticks_sample() { @@ -1092,9 +1379,10 @@ async function multi_calibrate_range(perm_ch) { async function multi_calibrate_range_on_close() { if(mode == 1) - ds4_calibrate_range_end(last_perm_ch); + await ds4_calibrate_range_end(last_perm_ch); else - ds5_calibrate_range_end(last_perm_ch); + await ds5_calibrate_range_end(last_perm_ch); + on_circ_check_change(); } @@ -1391,4 +1679,5 @@ function lang_translate(target_file, target_lang) { } $("#curLang").html(available_langs[target_lang]["name"]); }); + } diff --git a/index.html b/index.html index 41225a1..00f512b 100644 --- a/index.html +++ b/index.html @@ -112,16 +112,67 @@
-
+
- +
+ +
+
Joystick Info
+
+
+ +
+
+
+
+
+ LX: +

+                            
+ +
+ LY: +

+                            
+ +
+ RX: +

+                            
+ +
+ RY: +

+                            
+
+
+
+
+ + +
+
+ Err R: +

+                            
+ +
+ Err L: +

+                            
+
+
+
+
+
+
@@ -457,7 +508,7 @@