Skip to content

Commit c72e3a6

Browse files
Create lights setup component
1 parent ab128de commit c72e3a6

File tree

2 files changed

+98
-1
lines changed

2 files changed

+98
-1
lines changed

core/frontend/src/components/vehiclesetup/Configure.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import Vue from 'vue'
2929
3030
import ParamSets from './overview/ParamSets.vue'
31+
import LightsConfigration from './configuration/lights.vue'
3132
3233
export interface Item {
3334
title: string,
@@ -39,6 +40,7 @@ export default Vue.extend({
3940
name: 'Configure',
4041
components: {
4142
ParamSets,
43+
LightsConfigration
4244
},
4345
data() {
4446
return {
@@ -49,7 +51,7 @@ export default Vue.extend({
4951
{ title: 'Compass', component: undefined },
5052
{ title: 'Baro', component: undefined },
5153
{ title: 'Gripper', component: undefined },
52-
{ title: 'Lights', component: undefined },
54+
{ title: 'Lights', component: LightsConfigration },
5355
{ title: 'Camera Mount', component: undefined },
5456
] as Item[],
5557
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<template>
2+
<div>
3+
<p> Lights Setup goes here </p>
4+
<v-card>
5+
<v-card-title> Lights 1 </v-card-title>
6+
<v-card-text>
7+
Here you can configure what pin outputs the signal for the first set of lights. {{ lights1_new_param }}
8+
<v-select
9+
:items="recommended_params"
10+
:item-text="friendlyName"
11+
:item-value="'name'"
12+
v-model="lights1_new_param"
13+
label="Lights 1"
14+
></v-select>
15+
</v-card-text>
16+
</v-card>
17+
<v-card>
18+
<p> Lights 2 </p>
19+
<span v-for="param in servo_params" :key="param.name">
20+
<p>{{ param.name }} {{ printParam(param) }}</p>
21+
</span>
22+
</v-card>
23+
</div>
24+
</template>
25+
26+
<script lang="ts">
27+
import mavlink2rest from '@/libs/MAVLink2Rest'
28+
import autopilot_data from '@/store/autopilot'
29+
import Parameter, { printParam } from '@/types/autopilot/parameter'
30+
31+
enum Lights {
32+
Lights1 = 59, // RCIN9
33+
Lights2 = 60, // RCIN10
34+
DISABLED = 0,
35+
}
36+
37+
export default {
38+
name: 'LightsConfigration',
39+
data() {
40+
return {
41+
lights1_new_param: undefined as (string | undefined), // item-value must be a primitive
42+
lights2_new_param: undefined as (string | undefined),
43+
}
44+
},
45+
methods: {
46+
friendlyName(param: Parameter): string {
47+
return `${param.name.replace('SERVO', 'Servo ').replace('_FUNCTION', '')} (${printParam(param)})`
48+
},
49+
printParam,
50+
},
51+
watch: {
52+
lights1_param(new_value: Parameter | undefined) {
53+
this.lights1_new_param = new_value?.name
54+
},
55+
lights2_param(new_value: Parameter | undefined) {
56+
this.lights2_new_param = new_value?.name
57+
},
58+
// todo: refactor these two methods into one
59+
lights1_new_param(new_param_name: string | undefined) {
60+
if (new_param_name) {
61+
//reset any other parameter using lights1 to undefined
62+
for (let old_param of this.servo_params) {
63+
if (old_param.name === new_param_name) {
64+
continue
65+
}
66+
if (old_param.value === Lights.Lights1) {
67+
// set the old parameter to DISABLED
68+
mavlink2rest.setParam(old_param.name, Lights.DISABLED, autopilot_data.system_id)
69+
}
70+
}
71+
mavlink2rest.setParam(new_param_name, Lights.Lights1 , autopilot_data.system_id)
72+
}
73+
},
74+
},
75+
computed: {
76+
recommended_params(): Parameter[] {
77+
// return parameters in servo_params that are on channel 9 and higher
78+
return this.servo_params.filter((param) => {
79+
const servoNumber = parseInt(param.name.replace('SERVO', '').split('_')[0]);
80+
return servoNumber >= 9;
81+
});
82+
83+
},
84+
servo_params(): Parameter[] {
85+
return autopilot_data.parameterRegex('SERVO[0-9]+_FUNCTION')
86+
},
87+
lights1_param(): Parameter | undefined {
88+
return this.servo_params.filter((param) => param.value === Lights.Lights1)[0]
89+
},
90+
lights2_param(): Parameter | undefined {
91+
return this.servo_params.filter((param) => param.value === Lights.Lights2)[0]
92+
},
93+
},
94+
}
95+
</script>

0 commit comments

Comments
 (0)