|
| 1 | +<template> |
| 2 | + <div class="align-center"> |
| 3 | + GPIOs can be used for Relays, Leak detection, and other functions not yet supported by this UI. |
| 4 | + This servo ({{ servo_number }}) gpio is {{ this_servo_gpio }}. |
| 5 | + |
| 6 | + In use by {{ function_type_using_this_gpio?.name }} |
| 7 | + |
| 8 | + <v-row align="end"> |
| 9 | + <v-col cols="6"> |
| 10 | + <span style="font-size: 1.0rem;">Change function for this servo's GPIO</span> |
| 11 | + </v-col> |
| 12 | + <v-col cols="6"> |
| 13 | + <v-select |
| 14 | + v-model="selected_function_type" |
| 15 | + :items="options" |
| 16 | + item-text="text" |
| 17 | + item-value="value" |
| 18 | + return-object |
| 19 | + hide-details |
| 20 | + @change="onChange" |
| 21 | + /> |
| 22 | + </v-col> |
| 23 | + </v-row> |
| 24 | + |
| 25 | + </div> |
| 26 | +</template> |
| 27 | + |
| 28 | +<script lang="ts"> |
| 29 | +import Vue from 'vue' |
| 30 | +
|
| 31 | +import mavlink2rest from '@/libs/MAVLink2Rest' |
| 32 | +import autopilot_data from '@/store/autopilot' |
| 33 | +import autopilot from '@/store/autopilot_manager' |
| 34 | +import Parameter from '@/types/autopilot/parameter' |
| 35 | +
|
| 36 | +import LeakSetup from './LeakSetup.vue' |
| 37 | +import RelaySetup from './RelaySetup.vue' |
| 38 | +
|
| 39 | +export default Vue.extend({ |
| 40 | + name: 'ServoFunctionGpioEditor', |
| 41 | + components: { |
| 42 | + LeakSetup, |
| 43 | + RelaySetup, |
| 44 | + }, |
| 45 | + props: { |
| 46 | + param: { |
| 47 | + type: Object as () => Parameter, |
| 48 | + required: true, |
| 49 | + }, |
| 50 | + }, |
| 51 | + data() { |
| 52 | + return { |
| 53 | + selected_function_type: undefined as {text: string, value: Parameter, disabled?: boolean} | undefined, |
| 54 | + } |
| 55 | + }, |
| 56 | + computed: { |
| 57 | + pin_parameters(): Parameter[] { |
| 58 | + return autopilot_data.parameterRegex('^.*_PIN$') as Parameter[] |
| 59 | + }, |
| 60 | + servo_number(): number | undefined { |
| 61 | + const option_name = this.param.name.match(/SERVO(\d+)_FUNCTION/)?.[1] |
| 62 | + return option_name ? parseInt(option_name, 10) : undefined |
| 63 | + }, |
| 64 | + board_name(): string | undefined { |
| 65 | + return autopilot.current_board?.name |
| 66 | + }, |
| 67 | + this_servo_gpio(): number | undefined { |
| 68 | + if (!this.servo_number) return undefined |
| 69 | + if (this.board_name?.startsWith('Navigator')) { |
| 70 | + return this.servo_number |
| 71 | + } |
| 72 | + // We are assuming most boards follow the same GPIO numbering scheme as the Pixhawk1 |
| 73 | + // Aux channels start at 50, and Main channels start at 101 |
| 74 | +
|
| 75 | + if (this.servo_number <= 8) { |
| 76 | + return this.servo_number + 100 |
| 77 | + } |
| 78 | + return this.servo_number - 9 + 50 |
| 79 | + }, |
| 80 | + function_pin_parameter_using_this_gpio(): Parameter | undefined { |
| 81 | + return this.pin_parameters.find((param) => param.value === this.this_servo_gpio) |
| 82 | + }, |
| 83 | + function_type_using_this_gpio(): Parameter | undefined { |
| 84 | + const param_name = this.function_pin_parameter_using_this_gpio?.name.split('_')[0] |
| 85 | + let new_param_name: string | undefined |
| 86 | + if (param_name?.includes('RELAY')) { |
| 87 | + new_param_name = `${param_name}_FUNCTION` |
| 88 | + } |
| 89 | + if (param_name?.includes('LEAK')) { |
| 90 | + new_param_name = `${param_name}_TYPE` |
| 91 | + } |
| 92 | + return new_param_name |
| 93 | + ? autopilot_data.parameter(new_param_name as string) |
| 94 | + : this.function_pin_parameter_using_this_gpio |
| 95 | + }, |
| 96 | + relay_parameters(): Parameter[] { |
| 97 | + return autopilot_data.parameterRegex('^RELAY(\\d+)_FUNCTION$') as Parameter[] |
| 98 | + }, |
| 99 | + leak_parameters(): Parameter[] { |
| 100 | + return autopilot_data.parameterRegex('^LEAK(\\d+)_TYPE$') as Parameter[] |
| 101 | + }, |
| 102 | + options(): {text: string, value: Parameter, disabled?: boolean}[] { |
| 103 | + const supportedOptions: {text: string, value: Parameter, disabled?: boolean}[] = [ |
| 104 | + ...this.relay_parameters, |
| 105 | + ...this.leak_parameters, |
| 106 | + ].map((param) => ({ |
| 107 | + text: param.name.split('_')[0].toLowerCase().toTitle(), |
| 108 | + value: param, |
| 109 | + })) |
| 110 | + // If the current GPIO is used by an unsupported parameter, add it to the options |
| 111 | + const pinParam = this.function_pin_parameter_using_this_gpio |
| 112 | + if (pinParam && !this.isSupportedParam(pinParam)) { |
| 113 | + supportedOptions.unshift({ |
| 114 | + text: `${pinParam.name} (not supported)`, |
| 115 | + value: pinParam, |
| 116 | + disabled: true, |
| 117 | + }) |
| 118 | + } |
| 119 | + return supportedOptions |
| 120 | + }, |
| 121 | + }, |
| 122 | + watch: { |
| 123 | + function_type_using_this_gpio: { |
| 124 | + handler(new_value: Parameter | undefined) { |
| 125 | + if (!new_value) { |
| 126 | + this.selected_function_type = undefined |
| 127 | + return |
| 128 | + } |
| 129 | + const isSupported = this.isSupportedParam(new_value) |
| 130 | + this.selected_function_type = { |
| 131 | + text: isSupported |
| 132 | + ? new_value.name.split('_')[0].toLowerCase().toTitle() |
| 133 | + : `${new_value.name} (not supported)`, |
| 134 | + value: new_value, |
| 135 | + } |
| 136 | + }, |
| 137 | + immediate: true, |
| 138 | + }, |
| 139 | + }, |
| 140 | + methods: { |
| 141 | + isSupportedParam(param: Parameter): boolean { |
| 142 | + return param.name.includes('RELAY') || param.name.includes('LEAK') |
| 143 | + }, |
| 144 | + onChange(value: {text: string, value: Parameter}) { |
| 145 | + const is_relay = value.value.name.includes('RELAY') |
| 146 | + const is_leak = value.value.name.includes('LEAK') |
| 147 | + if (!this.this_servo_gpio) { |
| 148 | + console.warn('No GPIO found for servo', this.servo_number) |
| 149 | + return |
| 150 | + } |
| 151 | + if (!is_relay && !is_leak) { |
| 152 | + // Unsupported parameter type, don't handle |
| 153 | + return |
| 154 | + } |
| 155 | + if (is_relay) { |
| 156 | + const paramName = value.value.name |
| 157 | + const paramType = value.value.paramType.type |
| 158 | + mavlink2rest.setParam(paramName, 1 /* Relay */, autopilot_data.system_id, paramType) |
| 159 | + const pin_param_name = paramName.replace('FUNCTION', 'PIN') |
| 160 | + const gpio = this.this_servo_gpio |
| 161 | + mavlink2rest.setParam(pin_param_name, gpio, autopilot_data.system_id, 'MAV_PARAM_TYPE_INT8') |
| 162 | + const pinParam = this.function_pin_parameter_using_this_gpio |
| 163 | + if (pinParam) { |
| 164 | + mavlink2rest.setParam(pinParam.name, -1, autopilot_data.system_id, 'MAV_PARAM_TYPE_INT8') |
| 165 | + } |
| 166 | + } |
| 167 | + if (is_leak) { |
| 168 | + const paramName = value.value.name |
| 169 | + const paramType = value.value.paramType.type |
| 170 | + mavlink2rest.setParam(paramName, 1 /* Digital */, autopilot_data.system_id, paramType) |
| 171 | + const pin_param_name = paramName.replace('TYPE', 'PIN') |
| 172 | + const gpio = this.this_servo_gpio |
| 173 | + mavlink2rest.setParam(pin_param_name, gpio, autopilot_data.system_id, 'MAV_PARAM_TYPE_INT8') |
| 174 | + const pinParam = this.function_pin_parameter_using_this_gpio |
| 175 | + if (pinParam) { |
| 176 | + mavlink2rest.setParam(pinParam.name, -1, autopilot_data.system_id, 'MAV_PARAM_TYPE_INT8') |
| 177 | + } |
| 178 | + } |
| 179 | + }, |
| 180 | + }, |
| 181 | +}) |
| 182 | +</script> |
0 commit comments