Skip to content

Commit

Permalink
Detect if the controller is connected via USB
Browse files Browse the repository at this point in the history
  • Loading branch information
dualshock-tools committed May 30, 2024
1 parent 9e48207 commit 5f7480e
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 57 deletions.
114 changes: 71 additions & 43 deletions core.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,24 @@ var lang_disabled = true;
var gj = 0;
var gu = 0;

// Alphabetical order
var available_langs = {
"bg_bg": { "name": "Български", "file": "bg_bg.json"},
"de_de": { "name": "Deutsch", "file": "de_de.json"},
"pl_pl": { "name": "Polski", "file": "pl_pl.json"},
"es_es": { "name": "Español", "file": "es_es.json"},
"fr_fr": { "name": "Français", "file": "fr_fr.json"},
"hu_hu": { "name": "Magyar", "file": "hu_hu.json"},
"it_it": { "name": "Italiano", "file": "it_it.json"},
"jp_jp": { "name": "日本語", "file": "jp_jp.json"},
"pl_pl": { "name": "Polski", "file": "pl_pl.json"},
"pt_br": { "name": "Português do Brasil", "file": "pt_br.json"},
"ru_ru": { "name": "Русский", "file": "ru_ru.json"},
"tr_tr": { "name": "Türkçe", "file": "tr_tr.json"},
"zh_cn": { "name": "中文", "file": "zh_cn.json"},
};

function buf2hex(buffer) {
return [...new Uint8Array(buffer)] .map(x => x.toString(16).padStart(2, '0')) .join('');
return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')) .join('');
}

function dec2hex(i) {
Expand Down Expand Up @@ -770,6 +771,8 @@ async function disconnect() {
$("#offlinebar").show();
$("#onlinebar").hide();
$("#mainmenu").hide();
$("#d-nvstatus").text = l("Unknown");
$("#d-bdaddr").text = l("Unknown");
close_calibrate_window();
}

Expand Down Expand Up @@ -857,65 +860,43 @@ function alloc_req(id, data=[]) {
return out;
}

async function connect() {
gj = crypto.randomUUID();
la("begin");
async function continue_connection(report) {
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 };
let ds5 = { vendorId: 0x054c, productId: 0x0ce6 };
let ds5edge = { vendorId: 0x054c, productId: 0x0df2 };
let requestParams = { filters: [ds4v1,ds4v2,ds5,ds5edge] };

var devices = await navigator.hid.getDevices();
if (devices.length == 0) {
devices = await navigator.hid.requestDevice(requestParams);
}

if (devices.length == 0) {
$("#btnconnect").prop("disabled", false);
$("#connectspinner").hide();
return;
}

if (devices.length > 1) {
device.oninputreport = null;
var reportLen = report.data.byteLength;

var connected = false;

// Detect if the controller is connected via USB
if(reportLen != 63) {
$("#btnconnect").prop("disabled", false);
$("#connectspinner").hide();
show_popup(l("Please connect only one controller at time."));
show_popup(l("Please connect the device using a USB cable."))
disconnect();
return;
}

await devices[0].open();

device = devices[0]
la("connect", {"p": device.productId, "v": device.vendorId});

var connected = false

if(device.productId == 0x05c4) {
if(await ds4_info()) {
connected = true
connected = true;
mode = 1;
devname = l("Sony DualShock 4 V1");
}
} else if(device.productId == 0x09cc) {
if(await ds4_info()) {
connected = true
connected = true;
mode = 1;
devname = l("Sony DualShock 4 V2");
}
} else if(device.productId == 0x0ce6) {
if(await ds5_info()) {
connected = true
connected = true;
mode = 2;
devname = l("Sony DualSense");
}
} else if(device.productId == 0x0df2) {
if(await ds5_info()) {
connected = true
connected = true;
mode = 0;
devname = l("Sony DualSense Edge");
disable_btn = true;
Expand All @@ -927,7 +908,7 @@ async function connect() {
disconnect();
return;
}

if(connected) {
$("#devname").text(devname + " (" + dec2hex(device.vendorId) + ":" + dec2hex(device.productId) + ")");
$("#offlinebar").hide();
Expand All @@ -937,17 +918,17 @@ async function connect() {
$("#d-nvstatus").text = l("Unknown");
$("#d-bdaddr").text = l("Unknown");
}

if(disable_btn) {
if(device.productId == 0x0df2) {
show_popup(l("Calibration of the DualSense Edge is not currently supported."));
} else {
show_popup(l("The device appears to be a DS4 clone. All functionalities are disabled."));
}
}

$(".ds-btn").prop("disabled", disable_btn);

$("#btnconnect").prop("disabled", false);
$("#connectspinner").hide();
} catch(error) {
Expand All @@ -958,6 +939,53 @@ async function connect() {
}
}

async function connect() {
gj = crypto.randomUUID();
la("begin");
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 };
let ds5 = { vendorId: 0x054c, productId: 0x0ce6 };
let ds5edge = { vendorId: 0x054c, productId: 0x0df2 };
let requestParams = { filters: [ds4v1,ds4v2,ds5,ds5edge] };

var devices = await navigator.hid.getDevices();
if (devices.length == 0) {
devices = await navigator.hid.requestDevice(requestParams);
}

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;
}

await devices[0].open();

device = devices[0]
la("connect", {"p": device.productId, "v": device.vendorId});

device.oninputreport = continue_connection

} catch(error) {
$("#btnconnect").prop("disabled", false);
$("#connectspinner").hide();
show_popup(l("Error: ") + error);
return;
}
}

var curModal = null

async function multi_reset() {
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ <h2 class="accordion-header">
<div class="container">
<footer>
<div class="d-flex flex-column flex-sm-row justify-content-between py-4 my-4 border-top" id="footbody">
<p><span class="ds-i18n">Version</span> 0.9 (2024-04-25) - <a href="#" class="ds-i18n" onclick="show_donate_modal();">Support this project</a>&nbsp;<span id="authorMsg"></span></p>
<p><span class="ds-i18n">Version</span> 1.0 (2024-05-30) - <a href="#" class="ds-i18n" onclick="show_donate_modal();">Support this project</a>&nbsp;<span id="authorMsg"></span></p>

<ul class="list-unstyled d-flex">
<li class="ms-3"><a class="link-body-emphasis" href="mailto:[email protected]" target="_blank"><svg class="bi" width="24" height="24"><use xlink:href="#mail"/></svg></a></li>
Expand Down
3 changes: 2 additions & 1 deletion lang/bg_bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@
"Ship me a controller you would love to add (send me an email for organization).": "Изпратете ми контролер, който бихте искали да добавите (изпратете ми имейл за организация).",
"Translate this website in your language": "Преведете този уебсайт на ваш език",
", to help more people like you!": ", за да помогнете на повече хора като вас!",
"This website uses analytics to improve the service.": "Този уебсайт използва анализи за подобряване на услугата.",

"Board Model:": "",
"This feature is experimental.": "",
"Please let me know if the board model of your controller is not detected correctly.": "",
"Board model detection thanks to": "",
"Please connect the device using a USB cable.": "",

"This website uses analytics to improve the service.": "Този уебсайт използва анализи за подобряване на услугата.",
"": ""
}
3 changes: 2 additions & 1 deletion lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@
"Ship me a controller you would love to add (send me an email for organization).": "Schicken Sie mir einen Controller, den Sie gerne hinzufügen möchten (senden Sie mir eine E-Mail zur Organisation).",
"Translate this website in your language": "Übersetzen Sie diese Website in Ihre Sprache",
", to help more people like you!": ", um mehr Menschen wie Sie zu helfen!",
"This website uses analytics to improve the service.": "Diese Website verwendet Analytics, um den Service zu verbessern.",

"Board Model:": "",
"This feature is experimental.": "",
"Please let me know if the board model of your controller is not detected correctly.": "",
"Board model detection thanks to": "",
"Please connect the device using a USB cable.": "",

"This website uses analytics to improve the service.": "Diese Website verwendet Analytics, um den Service zu verbessern.",
"": ""
}
3 changes: 2 additions & 1 deletion lang/es_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@
"Ship me a controller you would love to add (send me an email for organization).": "Enviame un mando que te gustaria añadir (envia el email para organizar).",
"Translate this website in your language": "Traduz esta web en tu idioma",
", to help more people like you!": ", para que ayude mas personas como tu!",
"This website uses analytics to improve the service.": "Este sitio web utiliza análisis para mejorar el servicio.",

"Board Model:": "",
"This feature is experimental.": "",
"Please let me know if the board model of your controller is not detected correctly.": "",
"Board model detection thanks to": "",
"Please connect the device using a USB cable.": "",

"This website uses analytics to improve the service.": "Este sitio web utiliza análisis para mejorar el servicio.",
"": ""
}
3 changes: 2 additions & 1 deletion lang/fr_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@
"Ship me a controller you would love to add (send me an email for organization).": "",
"Translate this website in your language": "",
", to help more people like you!": "",
"This website uses analytics to improve the service.": "Ce site utilise des analyses pour améliorer le service.",

"Board Model:": "",
"This feature is experimental.": "",
"Please let me know if the board model of your controller is not detected correctly.": "",
"Board model detection thanks to": "",
"Please connect the device using a USB cable.": "",

"This website uses analytics to improve the service.": "Ce site utilise des analyses pour améliorer le service.",
"": ""
}
3 changes: 2 additions & 1 deletion lang/hu_hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@
"Ship me a controller you would love to add (send me an email for organization).": "Küldj a fejlesztőnek egy kontrollert, amelyet szívesen látnál a támogatott kontrollerek listájában (küldj e-mailt a fejlesztőnek).",
"Translate this website in your language": "Fordítsd le ezt a webhelyet a saját nyelvedre",
", to help more people like you!": ", hogy több hozzád hasonló embernek segítsen!",
"This website uses analytics to improve the service.": "Ez a weboldal analitikát használ a szolgáltatás javításához.",

"Board Model:": "Alaplap verzió",
"This feature is experimental.": "Ez egy kisérleti funkció",
"Please let me know if the board model of your controller is not detected correctly.": "Kérlek értesítsd a fejlesztőt, ha az alaplap verziója nem egyezik meg a felimert verzióval!",
"Board model detection thanks to": "Az alaplapfelismerési funkciőért köszönet neki:",

"This website uses analytics to improve the service.": "Ez a weboldal analitikát használ a szolgáltatás javításához.",
"Please connect the device using a USB cable.": "",
"": ""
}
3 changes: 2 additions & 1 deletion lang/it_it.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@
"Ship me a controller you would love to add (send me an email for organization).": "Spediscimi un controller che vorresti aggiungere (mandami un'email per l'organizzazione).",
"Translate this website in your language": "Traduci questo sito web nella tua lingua",
", to help more people like you!": ", per aiutare più persone come te!",
"This website uses analytics to improve the service.": "Questo sito web utilizza analytics per migliorare il servizio.",

"Board Model:": "Modello scheda:",
"This feature is experimental.": "Questa funzionalità è sperimentale.",
"Please let me know if the board model of your controller is not detected correctly.": "Scrivimi se il modello della scheda del tuo controller non viene riconosciuto correttamente.",
"Board model detection thanks to": "Rilevamento del modello della scheda grazie a",
"Please connect the device using a USB cable.": "Connetti il controller usando un cavo USB.",

"This website uses analytics to improve the service.": "Questo sito web utilizza analytics per migliorare il servizio.",
"": ""
}
3 changes: 2 additions & 1 deletion lang/jp_jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@
"Ship me a controller you would love to add (send me an email for organization).": "追加したいコントローラーを送ってください(組織のためにメールを送ってください)。",
"Translate this website in your language": "このウェブサイトをあなたの言語に翻訳する",
", to help more people like you!": "、あなたのような多くの人々を助けるために!",
"This website uses analytics to improve the service.": "このウェブサイトはサービスを向上させるためにアナリティクスを使用しています。",

"Board Model:": "",
"This feature is experimental.": "",
"Please let me know if the board model of your controller is not detected correctly.": "",
"Board model detection thanks to": "",
"Please connect the device using a USB cable.": "",

"This website uses analytics to improve the service.": "このウェブサイトはサービスを向上させるためにアナリティクスを使用しています。",
"": ""
}
3 changes: 2 additions & 1 deletion lang/pl_pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@
"Ship me a controller you would love to add (send me an email for organization).": "Wyślij mi kontroler, który chciałbyś dodać (wyślij mi e-mail do organizacji).",
"Translate this website in your language": "Przetłumacz tę stronę na swój język",
", to help more people like you!": ", aby pomóc większej ilości osób takich jak ty!",
"This website uses analytics to improve the service.": "Ta strona korzysta z analiz w celu ulepszenia usług.",

"Board Model:": "Model płytki:",
"This feature is experimental.": "Ta funkcja jest eksperymentalna.",
"Please let me know if the board model of your controller is not detected correctly.": "Proszę daj mi znać jaki model płytki kontrolera nie został wykryty poprawnie",
"Board model detection thanks to": "Podziękowania dla osoby która wykryła model płytki",

"This website uses analytics to improve the service.": "Ta strona korzysta z analiz w celu ulepszenia usług.",
"Please connect the device using a USB cable.": "",
"": ""
}
5 changes: 3 additions & 2 deletions lang/pt_br.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@
"Ship me a controller you would love to add (send me an email for organization).": "Envie-me um controle que você adoraria adicionar (envie-me um e-mail para organização).",
"Translate this website in your language": "Traduza este site para o seu idioma",
", to help more people like you!": ", para ajudar mais pessoas como você!",
"This website uses analytics to improve the service.": "Este site utiliza análises para melhorar o serviço.",

":": "",
"Board Model:": "",
"This feature is experimental.": "",
"Please let me know if the board model of your controller is not detected correctly.": "",
"Board model detection thanks to": "",
"Please connect the device using a USB cable.": "",

"This website uses analytics to improve the service.": "Este site utiliza análises para melhorar o serviço.",
"": ""
}
3 changes: 2 additions & 1 deletion lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@
"Ship me a controller you would love to add (send me an email for organization).": "Отправьте мне контроллер, который вы хотели бы добавить (отправьте мне электронное письмо для организации).",
"Translate this website in your language": "Переведите этот сайт на свой язык",
", to help more people like you!": ", чтобы помочь большему числу людей, подобных вам!",
"This website uses analytics to improve the service.": "Этот сайт использует аналитику для улучшения сервиса.",

"Board Model:": "",
"This feature is experimental.": "",
"Please let me know if the board model of your controller is not detected correctly.": "",
"Board model detection thanks to": "",
"Please connect the device using a USB cable.": "",

"This website uses analytics to improve the service.": "Этот сайт использует аналитику для улучшения сервиса.",
"": ""
}
3 changes: 2 additions & 1 deletion lang/tr_tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@
"Ship me a controller you would love to add (send me an email for organization).": "Eklemek istediğiniz bir denetleyiciyi var ise bana gönderin (organizasyon için bana bir e-posta gönderin).",
"Translate this website in your language": "Bu web sitesini kendi dilinize çevirin",
", to help more people like you!": ", sizin gibi daha fazla insanın faydalanması için!",
"This website uses analytics to improve the service.": "Bu web sitesi hizmeti iyileştirmek için analiz kullanıyor.",

"Board Model:": "",
"This feature is experimental.": "",
"Please let me know if the board model of your controller is not detected correctly.": "",
"Board model detection thanks to": "",
"Please connect the device using a USB cable.": "",

"This website uses analytics to improve the service.": "Bu web sitesi hizmeti iyileştirmek için analiz kullanıyor.",
"": ""
}
3 changes: 2 additions & 1 deletion lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@
"Ship me a controller you would love to add (send me an email for organization).": "给我寄送一个您想添加的手柄(发送电子邮件给我进行安排)。",
"Translate this website in your language": "将这个网站翻译成您的语言",
", to help more people like you!": "以帮助更多像您一样的人!",
"This website uses analytics to improve the service.": "该网站使用分析工具来改善服务。",

"Board Model:": "主板型号",
"This feature is experimental.": "此功能为实验性质。",
"Please let me know if the board model of your controller is not detected correctly.": "如果您的手柄的主板型号没有被正确检测,请告诉我。",
"Board model detection thanks to": "主板型号检测功能需要感谢",

"This website uses analytics to improve the service.": "该网站使用分析工具来改善服务。",
"Please connect the device using a USB cable.": "",
"": ""
}

0 comments on commit 5f7480e

Please sign in to comment.