Skip to content

Commit

Permalink
Add cockpit-action to change to next view
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaellehmkuhl committed Aug 1, 2023
1 parent 6a6f7ed commit 670c664
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/libs/joystick/protocols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class MavlinkControllerState extends ProtocolControllerState {
* Possible Cockpit Actions
*/
export enum CockpitAction {
GO_TO_NEXT_VIEW = 'Go to next view',
TOGGLE_FULL_SCREEN = 'Toggle full-screen',
MAVLINK_ARM = 'Mavlink Command - Arm',
MAVLINK_DISARM = 'Mavlink Command - Disarm',
Expand Down
14 changes: 12 additions & 2 deletions src/stores/widgetManager.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import '@/libs/cosmos'

import { useStorage } from '@vueuse/core'
import { useDebounceFn, useStorage } from '@vueuse/core'
import { saveAs } from 'file-saver'
import { defineStore } from 'pinia'
import Swal from 'sweetalert2'
import { v4 as uuid4 } from 'uuid'
import { computed, ref } from 'vue'
import { computed, onBeforeUnmount, ref } from 'vue'

import { widgetProfile, widgetProfiles } from '@/assets/defaults'
import { miniWidgetsProfile } from '@/assets/defaults'
import * as Words from '@/libs/funny-name/words'
import { CockpitAction, registerActionCallback, unregisterActionCallback } from '@/libs/joystick/protocols'
import { isEqual } from '@/libs/utils'
import type { Point2D, SizeRect2D } from '@/types/general'
import { type Profile, type View, type Widget, type WidgetType, isProfile, isView } from '@/types/widgets'
Expand Down Expand Up @@ -253,6 +254,15 @@ export const useWidgetManagerStore = defineStore('widget-manager', () => {
return isEqual(widget.position, fullScreenPosition) && isEqual(widget.size, fullScreenSize)
}

const selectNextView = (): void => {
const newIndex = currentViewIndex.value === currentProfile.value.views.length - 1 ? 0 : currentViewIndex.value + 1
selectView(currentProfile.value.views[newIndex])
}
const debouncedSelectNextView = useDebounceFn(() => selectNextView(), 500)
const selectNextViewCallbackId = registerActionCallback(CockpitAction.GO_TO_NEXT_VIEW, debouncedSelectNextView)
onBeforeUnmount(() => unregisterActionCallback(selectNextViewCallbackId))


return {
editingMode,
showGrid,
Expand Down

0 comments on commit 670c664

Please sign in to comment.