Skip to content

Commit

Permalink
TEMP SQUASHED COMMIT
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Dec 7, 2023
1 parent 15fec30 commit 1537800
Show file tree
Hide file tree
Showing 21 changed files with 1,168 additions and 630 deletions.
16 changes: 13 additions & 3 deletions src/App.vue
Expand Up @@ -148,7 +148,11 @@ import { useRoute } from 'vue-router'
import ConfigurationMenu from '@/components/ConfigurationMenu.vue'
import { coolMissionNames } from '@/libs/funny-name/words'
import { CockpitAction, registerActionCallback, unregisterActionCallback } from '@/libs/joystick/protocols'
import {
availableCockpitActions,
registerActionCallback,
unregisterActionCallback,
} from '@/libs/joystick/protocols/cockpit-actions'
import { useMissionStore } from '@/stores/mission'
import Dialog from './components/Dialog.vue'
Expand All @@ -175,7 +179,10 @@ const routerSection = ref()
const { isFullscreen, toggle: toggleFullscreen } = useFullscreen()
const debouncedToggleFullScreen = useDebounceFn(() => toggleFullscreen(), 10)
const fullScreenCallbackId = registerActionCallback(CockpitAction.TOGGLE_FULL_SCREEN, debouncedToggleFullScreen)
const fullScreenCallbackId = registerActionCallback(
availableCockpitActions.toggle_full_screen,
debouncedToggleFullScreen
)
onBeforeUnmount(() => unregisterActionCallback(fullScreenCallbackId))
const fullScreenToggleIcon = computed(() => (isFullscreen.value ? 'mdi-fullscreen-exit' : 'mdi-overscan'))
Expand Down Expand Up @@ -209,7 +216,10 @@ watch([() => widgetStore.currentView, () => widgetStore.currentView.showBottomBa
showBottomBarNow.value = widgetStore.currentView.showBottomBarOnBoot
})
const debouncedToggleBottomBar = useDebounceFn(() => (showBottomBarNow.value = !showBottomBarNow.value), 25)
const bottomBarToggleCallbackId = registerActionCallback(CockpitAction.TOGGLE_BOTTOM_BAR, debouncedToggleBottomBar)
const bottomBarToggleCallbackId = registerActionCallback(
availableCockpitActions.toggle_bottom_bar,
debouncedToggleBottomBar
)
onBeforeUnmount(() => unregisterActionCallback(bottomBarToggleCallbackId))
// Start datalogging
Expand Down
95 changes: 63 additions & 32 deletions src/assets/joystick-profiles.ts
@@ -1,38 +1,69 @@
import { JoystickModel } from '@/libs/joystick/manager'
import { CockpitAction, MAVLinkAxis } from '@/libs/joystick/protocols'
import { type GamepadToCockpitStdMapping, type ProtocolControllerMapping, JoystickProtocol } from '@/types/joystick'
import { availableCockpitActions } from '@/libs/joystick/protocols/cockpit-actions'
import {
availableMavlinkManualControlButtonFunctions,
mavlinkManualControlAxes,
} from '@/libs/joystick/protocols/mavlink-manual-control'
import { modifierKeyActions, otherAvailableActions } from '@/libs/joystick/protocols/other'
import {
type GamepadToCockpitStdMapping,
type JoystickProtocolActionsMapping,
CockpitModifierKeyOption,
JoystickAxis,
JoystickButton,
} from '@/types/joystick'

// TODO: Adjust mapping for PS5 controller
export const cockpitStandardToProtocols: ProtocolControllerMapping = {
name: 'Cockpit Standard Gamepad to Protocols',
axesCorrespondencies: [
{ protocol: JoystickProtocol.MAVLinkManualControl, value: MAVLinkAxis.Y },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: MAVLinkAxis.X },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: MAVLinkAxis.R },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: MAVLinkAxis.Z },
],
axesMins: [-1000, 1000, -1000, 1000],
axesMaxs: [1000, -1000, 1000, 0],
buttonsCorrespondencies: [
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 0 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 1 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 2 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 3 },
{ protocol: JoystickProtocol.CockpitAction, value: CockpitAction.GO_TO_PREVIOUS_VIEW },
{ protocol: JoystickProtocol.CockpitAction, value: CockpitAction.GO_TO_NEXT_VIEW },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 9 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 10 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 4 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 6 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 7 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 8 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 11 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 12 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 13 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 14 },
{ protocol: JoystickProtocol.MAVLinkManualControl, value: 5 },
{ protocol: JoystickProtocol.CockpitAction, value: CockpitAction.TOGGLE_FULL_SCREEN },
],
export const cockpitStandardToProtocols: JoystickProtocolActionsMapping = {
name: 'Standard for ArduSub',
axesCorrespondencies: {
[JoystickAxis.A0]: { action: mavlinkManualControlAxes.axis_y, min: -1000, max: +1000 },
[JoystickAxis.A1]: { action: mavlinkManualControlAxes.axis_x, min: +1000, max: -1000 },
[JoystickAxis.A2]: { action: mavlinkManualControlAxes.axis_r, min: -1000, max: +1000 },
[JoystickAxis.A3]: { action: mavlinkManualControlAxes.axis_z, min: +1000, max: 0 },
},
buttonsCorrespondencies: {
[CockpitModifierKeyOption.regular]: {
[JoystickButton.B0]: { action: availableMavlinkManualControlButtonFunctions['Arm'] },
[JoystickButton.B1]: { action: otherAvailableActions.no_function },
[JoystickButton.B2]: { action: availableMavlinkManualControlButtonFunctions['Mount tilt up'] },
[JoystickButton.B3]: { action: availableMavlinkManualControlButtonFunctions['Mount tilt down'] },
[JoystickButton.B4]: { action: availableCockpitActions.go_to_previous_view },
[JoystickButton.B5]: { action: otherAvailableActions.no_function },
[JoystickButton.B6]: { action: availableMavlinkManualControlButtonFunctions['Gain inc'] },
[JoystickButton.B7]: { action: availableMavlinkManualControlButtonFunctions['Gain dec'] },
[JoystickButton.B8]: { action: availableMavlinkManualControlButtonFunctions['Lights1 brighter'] },
[JoystickButton.B9]: { action: availableMavlinkManualControlButtonFunctions['Lights1 dimmer'] },
[JoystickButton.B10]: { action: availableCockpitActions.toggle_full_screen },
[JoystickButton.B11]: { action: otherAvailableActions.no_function },
[JoystickButton.B12]: { action: otherAvailableActions.no_function },
[JoystickButton.B13]: { action: modifierKeyActions.shift },
[JoystickButton.B14]: { action: otherAvailableActions.no_function },
[JoystickButton.B15]: { action: otherAvailableActions.no_function },
[JoystickButton.B16]: { action: otherAvailableActions.no_function },
[JoystickButton.B17]: { action: otherAvailableActions.no_function },
},
[CockpitModifierKeyOption.shift]: {
[JoystickButton.B0]: { action: otherAvailableActions.no_function },
[JoystickButton.B1]: { action: otherAvailableActions.no_function },
[JoystickButton.B2]: { action: otherAvailableActions.no_function },
[JoystickButton.B3]: { action: otherAvailableActions.no_function },
[JoystickButton.B4]: { action: otherAvailableActions.no_function },
[JoystickButton.B5]: { action: otherAvailableActions.no_function },
[JoystickButton.B6]: { action: otherAvailableActions.no_function },
[JoystickButton.B7]: { action: otherAvailableActions.no_function },
[JoystickButton.B8]: { action: otherAvailableActions.no_function },
[JoystickButton.B9]: { action: otherAvailableActions.no_function },
[JoystickButton.B10]: { action: otherAvailableActions.no_function },
[JoystickButton.B11]: { action: otherAvailableActions.no_function },
[JoystickButton.B12]: { action: otherAvailableActions.no_function },
[JoystickButton.B13]: { action: modifierKeyActions.shift },
[JoystickButton.B14]: { action: otherAvailableActions.no_function },
[JoystickButton.B15]: { action: otherAvailableActions.no_function },
[JoystickButton.B16]: { action: otherAvailableActions.no_function },
[JoystickButton.B17]: { action: otherAvailableActions.no_function },
},
},
}

/**
Expand Down
25 changes: 13 additions & 12 deletions src/components/joysticks/JoystickPS.vue
Expand Up @@ -7,9 +7,13 @@ import { v4 as uuid4 } from 'uuid'
import { computed, onBeforeUnmount, ref, toRefs, watch } from 'vue'
import { JoystickModel } from '@/libs/joystick/manager'
import type { InputWithPrettyName } from '@/libs/joystick/protocols'
import { scale } from '@/libs/utils'
import { type JoystickInput, type ProtocolControllerMapping, JoystickAxis, JoystickButton } from '@/types/joystick'
import {
type JoystickButtonActionCorrespondency,
type JoystickInput,
JoystickAxis,
JoystickButton,
} from '@/types/joystick'
import { InputType } from '@/types/joystick'
const textColor = '#747474'
Expand Down Expand Up @@ -97,8 +101,7 @@ const props = defineProps<{
leftAxisVert?: number // State of the vertical left axis as a floating point number, between -1 and +1
rightAxisHoriz?: number // State of the horizontal right axis as a floating point number, between -1 and +1
rightAxisVert?: number // State of the vertical right axis as a floating point number, between -1 and +1
protocolMapping: ProtocolControllerMapping // Mapping from the Cockpit standard to the protocol functions
buttonLabelCorrespondency: InputWithPrettyName[] // Mapping from the protocol functions to human readable names
buttonsActionsCorrespondency: JoystickButtonActionCorrespondency // Mapping from the Cockpit standard to the protocol functions
}>()
const emit = defineEmits<{
Expand All @@ -109,10 +112,10 @@ const emit = defineEmits<{
const findInputFromPath = (path: string): JoystickInput[] => {
const inputs: JoystickInput[] = []
Object.entries(buttonPath).filter(([, v]) => v === path).forEach((button) => {
inputs.push({ type: InputType.Button, value: button[0] as unknown as JoystickButton })
inputs.push({ type: InputType.Button, id: button[0] as unknown as JoystickButton })
})
Object.entries(axisPath.value).filter(([, v]) => v === path).forEach((axis) => {
inputs.push({ type: InputType.Axis, value: axis[0] as unknown as JoystickAxis })
inputs.push({ type: InputType.Axis, id: axis[0] as unknown as JoystickAxis })
})
return inputs
}
Expand Down Expand Up @@ -194,17 +197,15 @@ watch(
() => updateButtonsState()
)
const buttonLabelCorrespondency = toRefs(props).buttonLabelCorrespondency
const protocolMapping = toRefs(props).protocolMapping
const joystickModel = toRefs(props).model
watch([protocolMapping, buttonLabelCorrespondency], () => updateLabelsState())
const buttonsActionsCorrespondency = toRefs(props).buttonsActionsCorrespondency
watch(buttonsActionsCorrespondency, () => updateLabelsState())
const updateLabelsState = (): void => {
Object.values(JoystickButton).forEach((button) => {
if (isNaN(Number(button))) return
const protocolButton = props.protocolMapping.buttonsCorrespondencies[button as JoystickButton] || undefined
const param = props.buttonLabelCorrespondency.find((btn) => btn.input.protocol === protocolButton.protocol && btn.input.value === protocolButton.value)
const functionName = param === undefined ? `${protocolButton.value} (${protocolButton.protocol})` : param.prettyName
const buttonActionCorrespondency = buttonsActionsCorrespondency.value[button as JoystickButton] || undefined
const functionName = buttonActionCorrespondency === undefined ? 'unassigned' : buttonActionCorrespondency.action.name
if (!svg) return
// @ts-ignore: we already check if button is a number and so if button is a valid index
const labelId = buttonPath[button].replace('path', 'text')
Expand Down
30 changes: 15 additions & 15 deletions src/composables/webRTC.ts
Expand Up @@ -59,7 +59,7 @@ export class WebRTCManager {
* @param {RTCConfiguration} rtcConfiguration
*/
constructor(webRTCSignallingURI: Connection.URI, rtcConfiguration: RTCConfiguration) {
console.debug('[WebRTC] Trying to connect to signalling server.')
// console.debug('[WebRTC] Trying to connect to signalling server.')
this.rtcConfiguration = rtcConfiguration
this.signaller = new Signaller(
webRTCSignallingURI,
Expand Down Expand Up @@ -96,7 +96,7 @@ export class WebRTCManager {
}

const msg = `Selected stream changed from "${oldStream?.id}" to "${newStream?.id}".`
console.debug('[WebRTC] ' + msg)
// console.debug('[WebRTC] ' + msg)
if (oldStream !== undefined) {
this.stopSession(msg)
}
Expand All @@ -112,7 +112,7 @@ export class WebRTCManager {
}

const msg = `Selected IPs changed from "${oldIps}" to "${newIps}".`
console.debug('[WebRTC] ' + msg)
// console.debug('[WebRTC] ' + msg)

this.selectedICEIPs = newIps

Expand All @@ -139,7 +139,7 @@ export class WebRTCManager {
* @param {string} newStatus
*/
private updateStreamStatus(newStatus: string): void {
console.debug(`[WebRTC] Stream status updated from "${this.streamStatus.value}" to "${newStatus}"`)
// console.debug(`[WebRTC] Stream status updated from "${this.streamStatus.value}" to "${newStatus}"`)
const time = new Date().toTimeString().split(' ').first()
this.streamStatus.value = `${newStatus} (${time})`
}
Expand All @@ -149,7 +149,7 @@ export class WebRTCManager {
* @param {string} newStatus
*/
private updateSignallerStatus(newStatus: string): void {
console.debug(`[WebRTC] Signaller status updated from "${this.signallerStatus.value}" to "${newStatus}"`)
// console.debug(`[WebRTC] Signaller status updated from "${this.signallerStatus.value}" to "${newStatus}"`)
const time = new Date().toTimeString().split(' ').first()
this.signallerStatus.value = `${newStatus} (${time})`
}
Expand Down Expand Up @@ -228,10 +228,10 @@ export class WebRTCManager {
})

console.groupCollapsed('[WebRTC] Track added')
console.debug('Event:', event)
console.debug('Settings:', event.track.getSettings?.())
console.debug('Constraints:', event.track.getConstraints?.())
console.debug('Capabilities:', event.track.getCapabilities?.())
// console.debug('Event:', event)
// console.debug('Settings:', event.track.getSettings?.())
// console.debug('Constraints:', event.track.getConstraints?.())
// console.debug('Capabilities:', event.track.getCapabilities?.())
console.groupEnd()
}

Expand All @@ -241,7 +241,7 @@ export class WebRTCManager {
* @param {string} consumerId
*/
private requestSession(stream: Stream, consumerId: string): void {
console.debug(`[WebRTC] Requesting stream:`, stream)
// console.debug(`[WebRTC] Requesting stream:`, stream)

// Requests a new Session ID
this.signaller.requestSessionId(
Expand Down Expand Up @@ -285,7 +285,7 @@ export class WebRTCManager {

const msg = `Starting session with producer "${stream.id}" ("${this.streamName}")`
this.updateStreamStatus(msg)
console.debug('[WebRTC] ' + msg)
// console.debug('[WebRTC] ' + msg)

if (this.consumerId === undefined) {
const error =
Expand Down Expand Up @@ -342,7 +342,7 @@ export class WebRTCManager {
producerId,
this.session.id,
(sessionId, reason) => {
console.debug(`[WebRTC] Session ${sessionId} ended. Reason: ${reason}`)
// console.debug(`[WebRTC] Session ${sessionId} ended. Reason: ${reason}`)
this.session = undefined
this.hasEnded = true
},
Expand All @@ -360,7 +360,7 @@ export class WebRTCManager {
)

const msg = `Session ${this.session.id} successfully started`
console.debug('[WebRTC] ' + msg)
// console.debug('[WebRTC] ' + msg)
this.updateStreamStatus(msg)
}

Expand All @@ -370,12 +370,12 @@ export class WebRTCManager {
*/
private stopSession(reason: string): void {
if (this.session === undefined) {
console.debug('[WebRTC] Stopping an undefined session, probably it was already stopped?')
// console.debug('[WebRTC] Stopping an undefined session, probably it was already stopped?')
return
}
const msg = `Stopping session ${this.session.id}. Reason: ${reason}`
this.updateStreamStatus(msg)
console.debug('[WebRTC] ' + msg)
// console.debug('[WebRTC] ' + msg)

this.session.end()
this.session = undefined
Expand Down

0 comments on commit 1537800

Please sign in to comment.