ADD: Key mapping comms according to spec
This commit is contained in:
@@ -18,45 +18,39 @@
|
|||||||
<ActionGroup :actions="actionsHeld" class="p-2" />
|
<ActionGroup :actions="actionsHeld" class="p-2" />
|
||||||
</ConfigSection>
|
</ConfigSection>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup lang="ts">
|
||||||
import { PanelBottomClose, PanelBottomOpen, Clock2 } from 'lucide-vue-next'
|
import { PanelBottomClose, PanelBottomOpen, Clock2 } from 'lucide-vue-next'
|
||||||
import ConfigSection from '@renderer/components/common/ConfigSection.vue'
|
import ConfigSection from '@renderer/components/common/ConfigSection.vue'
|
||||||
import { useAppStore } from '@renderer/appStore'
|
import { useAppStore } from '@renderer/appStore'
|
||||||
import { ref } from 'vue'
|
import { useDeviceStore } from '@renderer/deviceStore'
|
||||||
import ActionGroup from '@renderer/components/config/actions/ActionGroup.vue'
|
import ActionGroup from '@renderer/components/config/actions/ActionGroup.vue'
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import { Action } from '@renderer/deviceStore'
|
||||||
|
|
||||||
const appStore = useAppStore()
|
const appStore = useAppStore()
|
||||||
const actionsPressed = ref([
|
const deviceStore = useDeviceStore()
|
||||||
{
|
const actionsPressed = computed({
|
||||||
id: '1'
|
get() {
|
||||||
|
return deviceStore.keyActions(appStore.selectedKey).pressedActions as Action[]
|
||||||
},
|
},
|
||||||
{
|
set(newValue) {
|
||||||
id: '2'
|
deviceStore.setKeyPressedActions(appStore.selectedKey, newValue)
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '3'
|
|
||||||
}
|
}
|
||||||
])
|
})
|
||||||
const actionsReleased = ref([
|
const actionsReleased = computed({
|
||||||
{
|
get() {
|
||||||
id: '4'
|
return deviceStore.keyActions(appStore.selectedKey).releasedActions as Action[]
|
||||||
},
|
},
|
||||||
{
|
set(newValue) {
|
||||||
id: '5'
|
deviceStore.setKeyReleasedActions(appStore.selectedKey, newValue)
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '6'
|
|
||||||
}
|
}
|
||||||
])
|
})
|
||||||
const actionsHeld = ref([
|
const actionsHeld = computed({
|
||||||
{
|
get() {
|
||||||
id: '7'
|
return deviceStore.keyActions(appStore.selectedKey).heldActions as Action[]
|
||||||
},
|
},
|
||||||
{
|
set(newValue) {
|
||||||
id: '8'
|
deviceStore.setKeyHeldActions(appStore.selectedKey, newValue)
|
||||||
},
|
|
||||||
{
|
|
||||||
id: '9'
|
|
||||||
}
|
}
|
||||||
])
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { randomName } from '@renderer/randomName'
|
|||||||
|
|
||||||
// Generated from https://github.com/katbinaris/NanoD_RatchetH1/blob/runger/communications.md
|
// Generated from https://github.com/katbinaris/NanoD_RatchetH1/blob/runger/communications.md
|
||||||
// Using https://app.quicktype.io/
|
// Using https://app.quicktype.io/
|
||||||
|
// WARNING: The tool does 80% of the work, but you need to make sure the types are correct
|
||||||
export interface Profile {
|
export interface Profile {
|
||||||
version: number
|
version: number
|
||||||
name: string
|
name: string
|
||||||
@@ -38,9 +39,9 @@ export interface Profile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface Key {
|
export interface Key {
|
||||||
pressedActions: Action[]
|
pressed?: Action[]
|
||||||
releasedActions: Action[]
|
released?: Action[]
|
||||||
heldActions: Action[]
|
held?: Action[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Action {
|
export interface Action {
|
||||||
@@ -111,6 +112,17 @@ export const useDeviceStore = defineStore('device', {
|
|||||||
keyColor: (state) => (key: string, pressed: boolean) => {
|
keyColor: (state) => (key: string, pressed: boolean) => {
|
||||||
const propertyName = `button${key.toUpperCase()}${pressed ? 'Press' : 'Idle'}`
|
const propertyName = `button${key.toUpperCase()}${pressed ? 'Press' : 'Idle'}`
|
||||||
return state.currentProfile ? state.currentProfile[propertyName] : 0
|
return state.currentProfile ? state.currentProfile[propertyName] : 0
|
||||||
|
},
|
||||||
|
keyActions: (state) => (key: string) => {
|
||||||
|
const keyIndex = state.keyLabels.indexOf(key)
|
||||||
|
return (
|
||||||
|
state.currentProfile?.keys[keyIndex] ||
|
||||||
|
({
|
||||||
|
pressed: [],
|
||||||
|
released: [],
|
||||||
|
held: []
|
||||||
|
} as Key)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
@@ -311,6 +323,48 @@ export const useDeviceStore = defineStore('device', {
|
|||||||
)
|
)
|
||||||
this.setDirtyState(true)
|
this.setDirtyState(true)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
setKeyPressedActions(key: string, actions: Action[], updateDevice: boolean = true) {
|
||||||
|
const keyIndex = this.keyLabels.indexOf(key)
|
||||||
|
this.currentProfile!.keys[keyIndex].pressed = actions
|
||||||
|
if (updateDevice) {
|
||||||
|
sendDebounced(
|
||||||
|
this.currentDeviceId!,
|
||||||
|
JSON.stringify({
|
||||||
|
profile: this.currentProfileName,
|
||||||
|
updates: { keys: this.currentProfile!.keys }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
this.setDirtyState(true)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setKeyReleasedActions(key: string, actions: Action[], updateDevice: boolean = true) {
|
||||||
|
const keyIndex = this.keyLabels.indexOf(key)
|
||||||
|
this.currentProfile!.keys[keyIndex].released = actions
|
||||||
|
if (updateDevice) {
|
||||||
|
sendDebounced(
|
||||||
|
this.currentDeviceId!,
|
||||||
|
JSON.stringify({
|
||||||
|
profile: this.currentProfileName,
|
||||||
|
updates: { keys: this.currentProfile!.keys }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
this.setDirtyState(true)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setKeyHeldActions(key: string, actions: Action[], updateDevice: boolean = true) {
|
||||||
|
const keyIndex = this.keyLabels.indexOf(key)
|
||||||
|
this.currentProfile!.keys[keyIndex].held = actions
|
||||||
|
if (updateDevice) {
|
||||||
|
sendDebounced(
|
||||||
|
this.currentDeviceId!,
|
||||||
|
JSON.stringify({
|
||||||
|
profile: this.currentProfileName,
|
||||||
|
updates: { keys: this.currentProfile!.keys }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
this.setDirtyState(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user