From b10d6da3e1434b2efaddce20f84fcaea97041cbb Mon Sep 17 00:00:00 2001 From: dualshock-tools Date: Mon, 22 Apr 2024 00:05:05 +0200 Subject: [PATCH] Add board model detection --- core.js | 106 ++++++++++++++++++++++++++++++++++++------------ index.html | 11 ++++- lang/de_de.json | 6 ++- lang/fr_fr.json | 6 +++ lang/it_it.json | 5 +++ lang/jp_jp.json | 5 +++ lang/tr_tr.json | 5 +++ lang/zh_cn.json | 6 +++ 8 files changed, 122 insertions(+), 28 deletions(-) diff --git a/core.js b/core.js index 38a4119..c40cffb 100644 --- a/core.js +++ b/core.js @@ -28,36 +28,74 @@ function dec2hex8(i) { return (i+0x100).toString(16).substr(-2).toUpperCase(); } +function ds4_hw_to_bm(hw_ver) { + a = hw_ver >> 8; + if(a == 0x31) { + return "JDM-001"; + } else if(a == 0x43) { + return "JDM-011"; + } else if(a == 0x54) { + return "JDM-030"; + } else if(a == 0x64) { + return "JDM-040"; + } else if(a == 0xa4) { + return "JDM-050"; + } else if(a == 0xb4) { + return "JDM-055"; + } else { + return l("Unknown"); + } +} + async function ds4_info() { - const view = await device.receiveFeatureReport(0xa3); - - var cmd = view.getUint8(0, true); - if(cmd != 0xa3 || view.buffer.byteLength != 49) - return false; - - var k1 = new TextDecoder().decode(view.buffer.slice(1, 0x10)); - var k2 = new TextDecoder().decode(view.buffer.slice(0x10, 0x20)); - k1=k1.replace(/\0/g, ''); - k2=k2.replace(/\0/g, ''); - - var hw_ver_major= view.getUint16(0x21, true) - var hw_ver_minor= view.getUint16(0x23, true) - var sw_ver_major= view.getUint32(0x25, true) - var sw_ver_minor= view.getUint16(0x25+4, true) - var ooc = l("unknown"); - try { - const view = await device.receiveFeatureReport(0x81); + const view = await device.receiveFeatureReport(0xa3); + + var cmd = view.getUint8(0, true); + if(cmd != 0xa3 || view.buffer.byteLength != 49) + return false; + + var k1 = new TextDecoder().decode(view.buffer.slice(1, 0x10)); + var k2 = new TextDecoder().decode(view.buffer.slice(0x10, 0x20)); + k1=k1.replace(/\0/g, ''); + k2=k2.replace(/\0/g, ''); + + var hw_ver_major= view.getUint16(0x21, true) + var hw_ver_minor= view.getUint16(0x23, true) + var sw_ver_major= view.getUint32(0x25, true) + var sw_ver_minor= view.getUint16(0x25+4, true) + var ooc = l("unknown"); + ooc = l("original"); + + var is_clone = false; + try { + const view = await device.receiveFeatureReport(0x81); + ooc = l("original"); + } catch(e) { + is_clone = true; + ooc = "" + l("clone") + ""; + disable_btn = true; + } + + clear_info(); + append_info(l("Build Date:"), k1 + " " + k2); + append_info(l("HW Version:"), "" + dec2hex(hw_ver_major) + ":" + dec2hex(hw_ver_minor)); + append_info(l("SW Version:"), dec2hex32(sw_ver_major) + ":" + dec2hex(sw_ver_minor)); + append_info(l("Device Type:"), ooc); + if(!is_clone) { + b_info = ' ' + + ''; + append_info(l("Board Model:"), ds4_hw_to_bm(hw_ver_minor) + b_info); + + // All ok, safe to query NVS Status and BD Addr + await ds4_nvstatus(); + await ds4_getbdaddr(); + } } catch(e) { ooc = "" + l("clone") + ""; disable_btn = true; } - clear_info(); - append_info(l("Build Date:"), k1 + " " + k2); - append_info(l("HW Version:"), "" + dec2hex(hw_ver_major) + ":" + dec2hex(hw_ver_minor)); - append_info(l("SW Version:"), dec2hex32(sw_ver_major) + ":" + dec2hex(sw_ver_minor)); - append_info(l("Device Type:"), ooc); return true; } @@ -707,6 +745,8 @@ function alloc_req(id, data=[]) { async function connect() { try { $("#btnconnect").prop("disabled", true); + $("#connectspinner").show(); + await new Promise(r => setTimeout(r, 100)); let ds4v1 = { vendorId: 0x054c, productId: 0x05c4 }; let ds4v2 = { vendorId: 0x054c, productId: 0x09cc }; @@ -721,11 +761,13 @@ try { if (devices.length == 0) { $("#btnconnect").prop("disabled", false); + $("#connectspinner").hide(); return; } if (devices.length > 1) { $("#btnconnect").prop("disabled", false); + $("#connectspinner").hide(); show_popup(l("Please connect only one controller at time.")); return; } @@ -762,6 +804,7 @@ try { } } else { $("#btnconnect").prop("disabled", false); + $("#connectspinner").hide(); show_popup(l("Connected invalid device: ") + dec2hex(device.vendorId) + ":" + dec2hex(device.productId)) disconnect(); return; @@ -788,8 +831,10 @@ try { $(".ds-btn").prop("disabled", disable_btn); $("#btnconnect").prop("disabled", false); + $("#connectspinner").hide(); } catch(error) { $("#btnconnect").prop("disabled", false); + $("#connectspinner").hide(); show_popup(l("Error: ") + error); return; } @@ -927,8 +972,12 @@ function append_info(key, value) { $("#fwinfo").html($("#fwinfo").html() + s); } -function show_popup(text) { - $("#popupBody").text(text); +function show_popup(text, is_html = false) { + if(is_html) { + $("#popupBody").html(text); + } else { + $("#popupBody").text(text); + } new bootstrap.Modal(document.getElementById('popupModal'), {}).show() } @@ -938,6 +987,13 @@ function show_faq_modal() { function discord_popup() { show_popup(l("My handle on discord is: the_al")); } +function board_model_info() { + l1 = l("This feature is experimental."); + l2 = l("Please let me know if the board model of your controller is not detected correctly."); + l3 = l("Board model detection thanks to") + ' Battle Beaver Customs.'; + show_popup(l3 + "

" + l1 + " " + l2, true); +} + function calib_perm_changes() { return $("#calibPermanentChanges").is(':checked') } function reset_calib_perm_changes() { diff --git a/index.html b/index.html index 82b56e9..25d2529 100644 --- a/index.html +++ b/index.html @@ -24,6 +24,9 @@ + + + @@ -79,7 +82,11 @@