mirror of
https://github.com/dualshock-tools/dualshock-tools.github.io.git
synced 2026-03-01 11:19:54 +03:00
Review and refactor finetune dialog
This commit is contained in:
committed by
dualshock-tools
parent
aeb0c161ea
commit
a6f1b2e503
@@ -74,7 +74,9 @@ class ControllerFactory {
|
||||
showInfo: false,
|
||||
showFinetune: false,
|
||||
showMute: false,
|
||||
showInfoTab: false
|
||||
showInfoTab: false,
|
||||
showFourStepCalib: true,
|
||||
showQuickCalib: false
|
||||
};
|
||||
|
||||
case 0x0ce6: // DS5
|
||||
@@ -83,7 +85,9 @@ class ControllerFactory {
|
||||
showInfo: true,
|
||||
showFinetune: true,
|
||||
showMute: true,
|
||||
showInfoTab: true
|
||||
showInfoTab: true,
|
||||
showFourStepCalib: false,
|
||||
showQuickCalib: true
|
||||
};
|
||||
|
||||
default:
|
||||
@@ -91,7 +95,9 @@ class ControllerFactory {
|
||||
showInfo: false,
|
||||
showFinetune: false,
|
||||
showMute: false,
|
||||
showInfoTab: false
|
||||
showInfoTab: false,
|
||||
showFourStepCalib: false,
|
||||
showQuickCalib: false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
41
js/core.js
41
js/core.js
@@ -203,10 +203,12 @@ async function continue_connection({data, device}) {
|
||||
}
|
||||
|
||||
// Helper to apply basic UI visibility based on device type
|
||||
function applyDeviceUI({ showInfo, showFinetune, showMute, showInfoTab }) {
|
||||
function applyDeviceUI({ showInfo, showFinetune, showMute, showInfoTab, showFourStepCalib, showQuickCalib }) {
|
||||
$("#infoshowall").toggle(!!showInfo);
|
||||
$("#ds5finetune").toggle(!!showFinetune);
|
||||
$("#info-tab").toggle(!!showInfoTab);
|
||||
$("#four-step-center-calib").toggle(!!showFourStepCalib);
|
||||
$("#quick-center-calib").toggle(!!showQuickCalib);
|
||||
set_mute_visibility(!!showMute);
|
||||
}
|
||||
|
||||
@@ -225,7 +227,7 @@ async function continue_connection({data, device}) {
|
||||
await controllerInstance.initializeCurrentOutputState();
|
||||
}
|
||||
} catch (error) {
|
||||
const contextMessage = device
|
||||
const contextMessage = device
|
||||
? l("Connected invalid device: ") + dec2hex(device.vendorId) + ":" + dec2hex(device.productId)
|
||||
: l("Failed to connect to device");
|
||||
throw new Error(contextMessage, { cause: error });
|
||||
@@ -529,6 +531,17 @@ function resetStickDiagrams() {
|
||||
refresh_stick_pos();
|
||||
}
|
||||
|
||||
// Helper functions to switch display modes
|
||||
function switchTo10xZoomMode() {
|
||||
$("#centerZoomMode").prop('checked', true);
|
||||
resetStickDiagrams();
|
||||
}
|
||||
|
||||
function switchToRangeMode() {
|
||||
$("#checkCircularityMode").prop('checked', true);
|
||||
resetStickDiagrams();
|
||||
}
|
||||
|
||||
const on_stick_mode_change = () => resetStickDiagrams();
|
||||
|
||||
const throttled_refresh_sticks = (() => {
|
||||
@@ -968,10 +981,26 @@ window.connect = connect;
|
||||
window.disconnect = disconnectSync;
|
||||
window.show_faq_modal = show_faq_modal;
|
||||
window.show_info_tab = show_info_tab;
|
||||
window.calibrate_range = () => calibrate_range(controller, { resetStickDiagrams, successAlert });
|
||||
window.calibrate_stick_centers = () => calibrate_stick_centers(controller, { resetStickDiagrams, show_popup, set_progress });
|
||||
window.auto_calibrate_stick_centers = () => auto_calibrate_stick_centers(controller, { resetStickDiagrams, successAlert, set_progress });
|
||||
window.ds5_finetune = () => ds5_finetune(controller, { ll_data, rr_data, clear_circularity });
|
||||
window.calibrate_range = () => calibrate_range(
|
||||
controller,
|
||||
{ resetStickDiagrams },
|
||||
(success, message) => { success && successAlert(message); success && switchToRangeMode(); }
|
||||
);
|
||||
window.calibrate_stick_centers = () => calibrate_stick_centers(
|
||||
controller,
|
||||
{ resetStickDiagrams, set_progress },
|
||||
(success, message) => { success && successAlert(message); success && switchTo10xZoomMode(); }
|
||||
);
|
||||
window.auto_calibrate_stick_centers = () => auto_calibrate_stick_centers(
|
||||
controller,
|
||||
{ resetStickDiagrams, set_progress },
|
||||
(success, message) => { success && successAlert(message); success && switchTo10xZoomMode(); }
|
||||
);
|
||||
window.ds5_finetune = () => ds5_finetune(
|
||||
controller,
|
||||
{ ll_data, rr_data, clear_circularity },
|
||||
(success) => success && switchToRangeMode()
|
||||
);
|
||||
window.flash_all_changes = flash_all_changes;
|
||||
window.reboot_controller = reboot_controller;
|
||||
window.refresh_nvstatus = refresh_nvstatus;
|
||||
|
||||
@@ -8,11 +8,11 @@ import { l } from '../translations.js';
|
||||
* Handles step-by-step manual stick center calibration
|
||||
*/
|
||||
export class CalibCenterModal {
|
||||
constructor(controllerInstance, { resetStickDiagrams, successAlert, set_progress }) {
|
||||
constructor(controllerInstance, { resetStickDiagrams, set_progress }, doneCallback = null) {
|
||||
this.controller = controllerInstance;
|
||||
this.resetStickDiagrams = resetStickDiagrams;
|
||||
this.successAlert = successAlert;
|
||||
this.set_progress = set_progress;
|
||||
this.doneCallback = doneCallback;
|
||||
|
||||
this._initEventListeners();
|
||||
|
||||
@@ -103,7 +103,7 @@ export class CalibCenterModal {
|
||||
this._updateUI(6, "Stick center calibration", "Done", true);
|
||||
yield 6;
|
||||
|
||||
this._close();
|
||||
this._close(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,12 +126,8 @@ export class CalibCenterModal {
|
||||
});
|
||||
|
||||
await sleep(500);
|
||||
this._close();
|
||||
this._close(true, result?.message);
|
||||
this.resetStickDiagrams();
|
||||
|
||||
if (result?.message) {
|
||||
this.successAlert(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +148,12 @@ export class CalibCenterModal {
|
||||
/**
|
||||
* Close the calibration modal
|
||||
*/
|
||||
_close() {
|
||||
_close(success = false, message = null) {
|
||||
// Call the done callback if provided
|
||||
if (this.doneCallback && typeof this.doneCallback === 'function') {
|
||||
this.doneCallback(success, message);
|
||||
}
|
||||
|
||||
$(".modal.show").modal("hide");
|
||||
}
|
||||
|
||||
@@ -180,6 +181,9 @@ export class CalibCenterModal {
|
||||
} else {
|
||||
$("#calibCross").hide();
|
||||
}
|
||||
|
||||
// Show/hide Quick calibrate button - only show on step 1 (welcome screen)
|
||||
$("#quickCalibBtn").toggle(step === 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,8 +220,8 @@ function destroyCurrentInstance() {
|
||||
}
|
||||
|
||||
// Legacy function exports for backward compatibility
|
||||
export async function calibrate_stick_centers(controller, dependencies) {
|
||||
currentCalibCenterInstance = new CalibCenterModal(controller, dependencies);
|
||||
export async function calibrate_stick_centers(controller, dependencies, doneCallback = null) {
|
||||
currentCalibCenterInstance = new CalibCenterModal(controller, dependencies, doneCallback);
|
||||
await currentCalibCenterInstance.open();
|
||||
}
|
||||
|
||||
@@ -227,11 +231,37 @@ async function calib_next() {
|
||||
}
|
||||
}
|
||||
|
||||
// Function to close current manual calibration and start auto calibration instead
|
||||
async function quick_calibrate_instead() {
|
||||
if (currentCalibCenterInstance) {
|
||||
// Get the callback from the current instance before closing
|
||||
const doneCallback = currentCalibCenterInstance.doneCallback;
|
||||
|
||||
// Close the current manual calibration modal (without calling callback)
|
||||
currentCalibCenterInstance.doneCallback = null; // Temporarily remove callback to avoid double-calling
|
||||
currentCalibCenterInstance._close();
|
||||
|
||||
// Get the controller and dependencies from the current instance
|
||||
const { controller } = currentCalibCenterInstance;
|
||||
const dependencies = {
|
||||
resetStickDiagrams: currentCalibCenterInstance.resetStickDiagrams,
|
||||
set_progress: currentCalibCenterInstance.set_progress
|
||||
};
|
||||
|
||||
// Destroy the current instance
|
||||
destroyCurrentInstance();
|
||||
|
||||
// Start auto calibration with the original callback
|
||||
await auto_calibrate_stick_centers(controller, dependencies, doneCallback);
|
||||
}
|
||||
}
|
||||
|
||||
// "Old" fully automatic stick center calibration
|
||||
export async function auto_calibrate_stick_centers(controller, dependencies) {
|
||||
currentCalibCenterInstance = new CalibCenterModal(controller, dependencies);
|
||||
export async function auto_calibrate_stick_centers(controller, dependencies, doneCallback = null) {
|
||||
currentCalibCenterInstance = new CalibCenterModal(controller, dependencies, doneCallback);
|
||||
await currentCalibCenterInstance.multiCalibrateSticks();
|
||||
}
|
||||
|
||||
// Legacy compatibility - expose functions to window for HTML onclick handlers
|
||||
window.calib_next = calib_next;
|
||||
window.quick_calibrate_instead = quick_calibrate_instead;
|
||||
|
||||
@@ -7,11 +7,11 @@ import { sleep } from '../utils.js';
|
||||
* Handles stick range calibration
|
||||
*/
|
||||
export class CalibRangeModal {
|
||||
constructor(controllerInstance, { resetStickDiagrams, successAlert }) {
|
||||
constructor(controllerInstance, { resetStickDiagrams }, doneCallback = null) {
|
||||
// Dependencies
|
||||
this.controller = controllerInstance;
|
||||
this.resetStickDiagrams = resetStickDiagrams;
|
||||
this.successAlert = successAlert;
|
||||
this.doneCallback = doneCallback;
|
||||
}
|
||||
|
||||
async open() {
|
||||
@@ -24,13 +24,15 @@ export class CalibRangeModal {
|
||||
await this.controller.calibrateRangeBegin();
|
||||
}
|
||||
|
||||
async onClose() {
|
||||
async onClose() {
|
||||
bootstrap.Modal.getOrCreateInstance('#rangeModal').hide();
|
||||
this.resetStickDiagrams();
|
||||
|
||||
|
||||
const result = await this.controller.calibrateRangeOnClose();
|
||||
if (result?.message) {
|
||||
this.successAlert(result.message);
|
||||
|
||||
// Call the done callback if provided (range calibration is always successful when onClose is called)
|
||||
if (this.doneCallback && typeof this.doneCallback === 'function') {
|
||||
this.doneCallback(true, result?.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,9 +48,9 @@ function destroyCurrentInstance() {
|
||||
}
|
||||
|
||||
// Legacy function exports for backward compatibility
|
||||
export async function calibrate_range(controller, dependencies) {
|
||||
export async function calibrate_range(controller, dependencies, doneCallback = null) {
|
||||
destroyCurrentInstance(); // Clean up any existing instance
|
||||
currentCalibRangeInstance = new CalibRangeModal(controller, dependencies);
|
||||
currentCalibRangeInstance = new CalibRangeModal(controller, dependencies, doneCallback);
|
||||
await currentCalibRangeInstance.open();
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user