Skip to content

Commit d4470a8

Browse files
committed
Feature request: clear profile from controller memory
1 parent cec515c commit d4470a8

File tree

8 files changed

+80
-13
lines changed

8 files changed

+80
-13
lines changed

src/App.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const db = new LocalIndexDB('ds-edge-profiles');
1111
provide('db', db);
1212
1313
let edgeHIDController: Ref<HIDDevice | undefined> = ref();
14+
provide('HIDController', edgeHIDController);
1415
1516
let profiles = ref();
1617
let selectedProfile = ref();
@@ -34,13 +35,14 @@ const getProfiles = async () => {
3435
cIndex++;
3536
}
3637
let foundProfiles: Array<Profile> = [];
37-
// console.log(profileCollector[2][2].slice(60), arrayCRC32LeBLE(new Uint8Array([0xA3, ...profileCollector[2][2].slice(0, 60)])));
3838
profileCollector.forEach((profile: number[][]) => {
3939
foundProfiles.push(bytesArrayToProfile(profile));
4040
});
4141
profiles.value = foundProfiles;
4242
}
4343
}
44+
// Used for refreshing profiles called by child component(s)
45+
provide('getProfiles', getProfiles);
4446
4547
const getDevice = () => {
4648
navigator.hid.requestDevice({filters: [FILTERS]}).then(devices => {
@@ -89,7 +91,6 @@ const setSelectedProfile = (setSelectedProfile: Profile, isSavedProfile: boolean
8991
}
9092
9193
const saveProfile = (newProfile: Profile) => {
92-
console.log(edgeHIDController.value);
9394
if (edgeHIDController.value) {
9495
let bytesArray = profileToBytes(newProfile);
9596

src/assets/buttons/circle.svg

+1
Loading

src/assets/buttons/cross.svg

+1
Loading

src/assets/buttons/square.svg

+1
Loading

src/assets/buttons/triangle.svg

+1
Loading

src/components/profile/Profile.vue

+9-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ defineEmits([
1414
</script>
1515
<template>
1616
<section class="item" @click="$emit('selected-profile', profile)">
17-
<p>{{ profile.getLabel() }}</p>
18-
<slot/>
17+
<p class="label">{{ profile.getLabel() }}</p>
18+
<div>
19+
<slot/>
20+
</div>
1921
</section>
2022
</template>
2123

@@ -25,6 +27,7 @@ defineEmits([
2527
justify-content: space-between;
2628
padding: 0 12px;
2729
cursor: pointer;
30+
align-items: center;
2831
}
2932
3033
.item:hover {
@@ -35,6 +38,10 @@ p {
3538
padding: 0;
3639
}
3740
41+
.label {
42+
font-weight: 600;
43+
}
44+
3845
@media (prefers-color-scheme: dark) {
3946
.item {
4047
color: #fffffe;

src/components/profile/ProfileOverview.vue

+60-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import Profile from "./Profile.vue";
44
import ProfileModel from "../../model/Profile";
55
import LocalIndexDB from "../../model/LocalIndexDB";
66
import {assembleBlankProfile, getProfileButtonSelector} from "../../helper/profileTools";
7-
import {inject, Ref, ref} from "vue";
7+
import {inject, ref} from "vue";
8+
import type {Ref} from "vue";
89
import Joystick from "../../model/Joystick";
910
import Trigger from "../../model/Trigger";
1011
import ButtonMapping from "../../model/ButtonMapping";
@@ -19,6 +20,8 @@ const savedProfiles: Ref<Array<ProfileModel>> = ref([]);
1920
const emit = defineEmits(['selected-profile', 'delete-profile']);
2021
2122
const db: LocalIndexDB = inject('db') as LocalIndexDB;
23+
const hidController = inject('HIDController') as Ref<HIDDevice>;
24+
const getProfiles = inject('getProfiles') as Function;
2225
2326
db.getAll().then((profiles: Array<ProfileModel>) => savedProfiles.value = profiles.map((profileEntry: any) => {
2427
@@ -47,6 +50,17 @@ const deleteProfileConfirm = (profile: ProfileModel) => {
4750
}
4851
}
4952
53+
const clearProfileFromControllerMemory = async (profile: ProfileModel, position: number) => {
54+
55+
if (confirm(`Are you sure you want to clear ${profile.getLabel()} from the controller memory?`) &&
56+
hidController.value) {
57+
const bytes = new Uint8Array(64);
58+
bytes[1] = 1 + position;
59+
await hidController.value?.sendFeatureReport(0x68, bytes.slice(1, bytes.length));
60+
getProfiles();
61+
}
62+
}
63+
5064
const createNewProfile = () => {
5165
let name = prompt("New profile name");
5266
if (name) {
@@ -64,9 +78,17 @@ const createNewProfile = () => {
6478
<section>
6579
<section class="profiles" v-if="profiles">
6680
<Profile @selected-profile="(selectedProfile) => $emit('selected-profile', selectedProfile)"
67-
v-for="profile in profiles"
81+
v-for="(profile, i) in profiles"
6882
:profile="profile">
69-
<p>{{ getProfileButtonSelector(profile.getProfileButtonSelector()) }}</p>
83+
<div class="profile-right">
84+
<span class="button-combination">
85+
<span class="fn-button">FN</span>
86+
<img class="action-button" :src="getProfileButtonSelector((profile as ProfileModel).getProfileButtonSelector())" alt="button">
87+
</span>
88+
<button class="clear-button" @click="$event.stopPropagation(); clearProfileFromControllerMemory(profile, i)">
89+
Clear
90+
</button>
91+
</div>
7092
</Profile>
7193
</section>
7294
<section class="profiles saved">
@@ -113,10 +135,45 @@ const createNewProfile = () => {
113135
font-weight: bold;
114136
}
115137
138+
.button-combination {
139+
display: flex;
140+
gap: 12px;
141+
padding: 8px 0;
142+
}
143+
144+
.fn-button {
145+
width: 30px;
146+
text-align: center;
147+
height: 20px;
148+
background-color: #0f0f10;
149+
color: #a4aaad;
150+
padding: 2px;
151+
border-radius: 4px;
152+
}
153+
154+
.action-button {
155+
width: 24px;
156+
height: 24px;
157+
}
158+
159+
.clear-button {
160+
all: unset;
161+
cursor: pointer;
162+
font-weight: bold;
163+
border: 1px solid #ffffff;
164+
margin-bottom: 10px;
165+
padding: 5px 12px;
166+
}
167+
168+
.clear-button:hover {
169+
background-color: #0f0f10;
170+
}
171+
116172
@media (prefers-color-scheme: dark) {
117173
.overview {
118174
background-color: #f25f4c;
119175
}
176+
120177
.create-new-profile button {
121178
background-color: #ff8906;
122179
font-weight: bold;

src/helper/profileTools.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@ export function assembleBlankProfile(label: string = "Unnamed"): Profile {
3232
export function getProfileButtonSelector(profileButtonSelector: ProfileButtonSelector): string {
3333
switch (profileButtonSelector) {
3434
case ProfileButtonSelector.FN_CIRCLE:
35-
return "FN + CIRCLE";
35+
return new URL('../assets/buttons/circle.svg', import.meta.url).href
3636
case ProfileButtonSelector.FN_CROSS:
37-
return "FN + CROSS";
37+
return new URL('../assets/buttons/cross.svg', import.meta.url).href
3838
case ProfileButtonSelector.FN_SQUARE:
39-
return "FN + SQUARE";
39+
return new URL('../assets/buttons/square.svg', import.meta.url).href
4040
case ProfileButtonSelector.FN_TRIANGLE:
41-
return "FN + TRIANGLE";
42-
case ProfileButtonSelector.UNASSIGNED:
43-
return "UNASSIGNED";
41+
return new URL('../assets/buttons/triangle.svg', import.meta.url).href
4442
default:
4543
return "UNKNOWN";
4644
}

0 commit comments

Comments
 (0)