From 2aebc843bf22830bdceed8a1756c6e7a776a3e63 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Fri, 1 Dec 2023 18:09:32 -0300 Subject: [PATCH 01/22] Use intern Vue `capitalize` method when possible Much more readable. --- src/stores/mainVehicle.ts | 4 ++-- src/views/ConfigurationAlertsView.vue | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/stores/mainVehicle.ts b/src/stores/mainVehicle.ts index 77061f8b7..ed65fcf28 100644 --- a/src/stores/mainVehicle.ts +++ b/src/stores/mainVehicle.ts @@ -1,6 +1,6 @@ import { useStorage, useTimestamp } from '@vueuse/core' import { defineStore } from 'pinia' -import { computed, onBeforeUnmount, reactive, ref, watch } from 'vue' +import { capitalize, computed, onBeforeUnmount, reactive, ref, watch } from 'vue' import { defaultGlobalAddress } from '@/assets/defaults' import * as Connection from '@/libs/connection/connection' @@ -428,7 +428,7 @@ export const useMainVehicleStore = defineStore('main-vehicle', () => { // @ts-ignore: This type is huge. Needs refactoring typing here. Object.entries(parametersTable['BTN0_FUNCTION']['Values']).forEach((param) => { const rawText = param[1] as string - const formatedText = (rawText.charAt(0).toUpperCase() + rawText.slice(1)).replace(new RegExp('_', 'g'), ' ') + const formatedText = capitalize(rawText).replace(new RegExp('_', 'g'), ' ') buttonParameterTable.push({ title: formatedText as string, value: Number(param[0]) }) }) Object.entries(currentParameters).forEach((param) => { diff --git a/src/views/ConfigurationAlertsView.vue b/src/views/ConfigurationAlertsView.vue index 88efd1740..a435bea02 100644 --- a/src/views/ConfigurationAlertsView.vue +++ b/src/views/ConfigurationAlertsView.vue @@ -6,11 +6,7 @@ Enable voice on specific alert levels:
- +
Alert voice: @@ -26,6 +22,8 @@ From e6837f4a9c881c8a9cc7c91762f3edaf2f1a398f Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Wed, 6 Dec 2023 21:46:09 -0300 Subject: [PATCH 18/22] joystick-protocol: Prevent unwanted mapping behaviors from users --- src/stores/controller.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/stores/controller.ts b/src/stores/controller.ts index ef927222a..a198d41ec 100644 --- a/src/stores/controller.ts +++ b/src/stores/controller.ts @@ -99,6 +99,37 @@ export const useControllerStore = defineStore('controller', () => { return activeActions.concat(modKeyAction) } + setInterval(() => { + // eslint-disable-next-line jsdoc/require-jsdoc + const btnsToUnmap: { modKey: CockpitModifierKeyOption; button: JoystickButton }[] = [] + Object.entries(protocolMapping.value.buttonsCorrespondencies.regular).forEach((v) => { + if (v[1].action.protocol == JoystickProtocol.CockpitModifierKey) { + btnsToUnmap.push({ modKey: v[1].action.id as CockpitModifierKeyOption, button: Number(v[0]) as JoystickButton }) + } + }) + + Object.entries(protocolMapping.value.buttonsCorrespondencies).forEach(([modKey, mapping]) => { + Object.entries(mapping).forEach(([btn, action]) => { + const modKeyAction = modifierKeyActions[modKey as CockpitModifierKeyOption] + if (JSON.stringify(action.action) !== JSON.stringify(modKeyAction)) return + Swal.fire({ text: "Cannot map modifier key to it's own layout.", icon: 'warning' }) + protocolMapping.value.buttonsCorrespondencies[modKey as CockpitModifierKeyOption][ + Number(btn) as JoystickButton + ].action = otherAvailableActions.no_function + }) + }) + + btnsToUnmap.forEach((v) => { + const actionToUnmap = protocolMapping.value.buttonsCorrespondencies[v.modKey][v.button].action + if (JSON.stringify(actionToUnmap) === JSON.stringify(otherAvailableActions.no_function)) return + Swal.fire({ + text: `Unmapping '${actionToUnmap.name} from ${v.modKey} layout. Cannot use same button as the modifier.`, + icon: 'warning', + }) + protocolMapping.value.buttonsCorrespondencies[v.modKey][v.button].action = otherAvailableActions.no_function + }) + }, 1000) + // If there's a mapping in our database that is not on the user storage, add it to the user // This will happen whenever a new joystick profile is added to Cockpit's database Object.entries(availableGamepadToCockpitMaps).forEach(([k, v]) => { From 84fea3b481672e14eeb1e4526bf005970261fce4 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Thu, 7 Dec 2023 13:20:52 -0300 Subject: [PATCH 19/22] joystick-config-view: Remove joystick image from mapping modal --- src/views/ConfigurationJoystickView.vue | 192 ++++++++++-------------- 1 file changed, 78 insertions(+), 114 deletions(-) diff --git a/src/views/ConfigurationJoystickView.vue b/src/views/ConfigurationJoystickView.vue index 9c0032bc1..362b2f507 100644 --- a/src/views/ConfigurationJoystickView.vue +++ b/src/views/ConfigurationJoystickView.vue @@ -110,127 +110,91 @@ Update mapping - - -
+
+
+ + {{ [JoystickAxis.A0, JoystickAxis.A2].includes(input.id) ? 'mdi-pan-horizontal' : 'mdi-pan-vertical' }} + + + + +
+
-
- - {{ - [JoystickAxis.A0, JoystickAxis.A2].includes(input.id) ? 'mdi-pan-horizontal' : 'mdi-pan-vertical' - }} - - - - -
-
Calibrate +

+ {{ + remappingInput + ? 'Click the button you want to use for this input.' + : justRemappedInput === undefined + ? '' + : justRemappedInput + ? 'Input remapped.' + : 'No input detected.' + }} +

+ -
- Calibrate -

- {{ - remappingInput - ? 'Click the button you want to use for this input.' - : justRemappedInput === undefined - ? '' - : justRemappedInput - ? 'Input remapped.' - : 'No input detected.' - }} -

- - {{ remappingInput ? 'Remapping' : 'Remap button' }} - -
-
- Assign -
-
- {{ protocol }} -
- -
-
+ {{ remappingInput ? 'Remapping' : 'Remap button' }} + +
+
+ Assign +
+
+ {{ protocol }} +
+
- +
From 05c9206a81264f6a54de189fc0862d50bc694e72 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Thu, 7 Dec 2023 14:45:45 -0300 Subject: [PATCH 20/22] joystick-config-view: Rework input updating modal --- src/views/ConfigurationJoystickView.vue | 116 ++++++++++++------------ 1 file changed, 59 insertions(+), 57 deletions(-) diff --git a/src/views/ConfigurationJoystickView.vue b/src/views/ConfigurationJoystickView.vue index 362b2f507..e082dc598 100644 --- a/src/views/ConfigurationJoystickView.vue +++ b/src/views/ConfigurationJoystickView.vue @@ -107,17 +107,59 @@ - - - Update mapping + + +

Input mapping

-
+
+

Button mapping

+
+
+ + {{ remappingInput ? 'Remapping' : 'Click to remap' }} + +

{{ buttonRemappingText }}

+
+
+
+
+ {{ protocol }} +
+ +
+
+
+
+
+
+

Axis mapping

+
{{ [JoystickAxis.A0, JoystickAxis.A2].includes(input.id) ? 'mdi-pan-horizontal' : 'mdi-pan-vertical' }}
-
-
- Calibrate -

- {{ - remappingInput - ? 'Click the button you want to use for this input.' - : justRemappedInput === undefined - ? '' - : justRemappedInput - ? 'Input remapped.' - : 'No input detected.' - }} -

- - {{ remappingInput ? 'Remapping' : 'Remap button' }} - -
-
- Assign -
-
- {{ protocol }} -
- -
-
-
-
-
@@ -331,4 +323,14 @@ watch(controllerStore.joysticks, () => { } currentModifierKey.value = activeModKeys[0] }) + +const buttonRemappingText = computed(() => { + return remappingInput.value + ? 'Click the button you want to use for this input.' + : justRemappedInput.value === undefined + ? '' + : justRemappedInput.value + ? 'Input remapped.' + : 'No input detected.' +}) From c804dd5da4c43882714e22d433834ea0d1ae65f8 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Thu, 7 Dec 2023 14:54:11 -0300 Subject: [PATCH 21/22] joystick-config-view: Improve feedback on input remapping --- src/views/ConfigurationJoystickView.vue | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/views/ConfigurationJoystickView.vue b/src/views/ConfigurationJoystickView.vue index e082dc598..fcb610e7a 100644 --- a/src/views/ConfigurationJoystickView.vue +++ b/src/views/ConfigurationJoystickView.vue @@ -126,7 +126,12 @@ > {{ remappingInput ? 'Remapping' : 'Click to remap' }} -

{{ buttonRemappingText }}

+ +

{{ buttonRemappingText }}

+
+ + +
@@ -151,6 +156,11 @@
+ +

+ {{ buttonFunctionAssignmentFeedback }} +

+

Axis mapping

@@ -233,6 +243,10 @@ const currentJoystick = ref() const currentButtonInputs = ref([]) const currentAxisInputs = ref([]) const remappingInput = ref(false) +const remapTimeProgress = ref() +const showButtonRemappingText = ref(false) +const buttonFunctionAssignmentFeedback = ref('') +const showButtonFunctionAssignmentFeedback = ref(false) const justRemappedInput = ref() const inputClickedDialog = ref(false) const currentModifierKey = ref(modifierKeyActions.regular) @@ -268,6 +282,8 @@ const remapInput = async (joystick: Joystick, input: JoystickInput): Promise button.value === 1) await new Promise((r) => setTimeout(r, 100)) millisPassed += 100 + remapTimeProgress.value = 100 * (millisPassed / waitingTime) } // End the remapping process remappingInput.value = false + setTimeout(() => (showButtonRemappingText.value = false), 5000) + // If a button was pressed, update the mapping of that joystick model in the controller store and return if (![undefined, -1].includes(pressedButtonIndex)) { justRemappedInput.value = true @@ -300,6 +319,9 @@ const updateButtonAction = (input: JoystickInput, action: ProtocolAction): void ].action = action showJoystickLayout.value = false nextTick(() => (showJoystickLayout.value = true)) + buttonFunctionAssignmentFeedback.value = `Button ${input.id} remapped to function '${action.name}'.` + showButtonFunctionAssignmentFeedback.value = true + setTimeout(() => (showButtonFunctionAssignmentFeedback.value = false), 5000) } // Automatically change between modifier key tabs/layouts when they are pressed From a2267c03e541176942feda2074f2a22b7f6613fc Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Thu, 7 Dec 2023 15:11:10 -0300 Subject: [PATCH 22/22] joystick-config-view: Use `setTimeout` instead of `nextTick` to reload joystick image This way, if the input is unmapped by the check routines (in the controller store), it will be right in the end. --- src/views/ConfigurationJoystickView.vue | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/views/ConfigurationJoystickView.vue b/src/views/ConfigurationJoystickView.vue index fcb610e7a..e687257ed 100644 --- a/src/views/ConfigurationJoystickView.vue +++ b/src/views/ConfigurationJoystickView.vue @@ -203,11 +203,7 @@