-
Notifications
You must be signed in to change notification settings - Fork 131
Add reverse checkbox to ServoFunctionEditorDialog #3444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,112 @@ | ||||||||||||||||||||||||||||||||||||||||||
| <template> | ||||||||||||||||||||||||||||||||||||||||||
| <div class="d-flex align-center"> | ||||||||||||||||||||||||||||||||||||||||||
| <div class="flex-grow-1"> | ||||||||||||||||||||||||||||||||||||||||||
| <v-checkbox | ||||||||||||||||||||||||||||||||||||||||||
| v-model="internal_value" | ||||||||||||||||||||||||||||||||||||||||||
| dense | ||||||||||||||||||||||||||||||||||||||||||
| hide-details | ||||||||||||||||||||||||||||||||||||||||||
| :indeterminate="waiting_for_param_update" | ||||||||||||||||||||||||||||||||||||||||||
| :label="label ?? param?.name ?? 'Parameter not found'" | ||||||||||||||||||||||||||||||||||||||||||
| :true-value="checkedValue" | ||||||||||||||||||||||||||||||||||||||||||
| :false-value="uncheckedValue" | ||||||||||||||||||||||||||||||||||||||||||
| @change="onCheckboxChange" | ||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||||||||||
| </template> | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| <script lang="ts"> | ||||||||||||||||||||||||||||||||||||||||||
| import Vue, { PropType } from 'vue' | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import mavlink2rest from '@/libs/MAVLink2Rest' | ||||||||||||||||||||||||||||||||||||||||||
| import autopilot_data from '@/store/autopilot' | ||||||||||||||||||||||||||||||||||||||||||
| import Parameter from '@/types/autopilot/parameter' | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export default Vue.extend({ | ||||||||||||||||||||||||||||||||||||||||||
| name: 'ParameterCheckbox', | ||||||||||||||||||||||||||||||||||||||||||
| model: { | ||||||||||||||||||||||||||||||||||||||||||
| prop: 'value', | ||||||||||||||||||||||||||||||||||||||||||
| event: 'change', | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| props: { | ||||||||||||||||||||||||||||||||||||||||||
| param: { | ||||||||||||||||||||||||||||||||||||||||||
| type: Object as PropType<Parameter>, | ||||||||||||||||||||||||||||||||||||||||||
| required: true, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| label: { | ||||||||||||||||||||||||||||||||||||||||||
| type: String as PropType<string | undefined>, | ||||||||||||||||||||||||||||||||||||||||||
| default: undefined, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| checkedValue: { | ||||||||||||||||||||||||||||||||||||||||||
| type: Number, | ||||||||||||||||||||||||||||||||||||||||||
| default: 1, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| uncheckedValue: { | ||||||||||||||||||||||||||||||||||||||||||
| type: Number, | ||||||||||||||||||||||||||||||||||||||||||
| default: 0, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| data() { | ||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||
| internal_value: undefined as number | undefined, | ||||||||||||||||||||||||||||||||||||||||||
| last_sent_value: undefined as number | undefined, | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| computed: { | ||||||||||||||||||||||||||||||||||||||||||
| waiting_for_param_update(): boolean { | ||||||||||||||||||||||||||||||||||||||||||
| // Don't show loading state if the value was just set and we're waiting for vehicle to catch up | ||||||||||||||||||||||||||||||||||||||||||
| if (!this.last_sent_value || this.param_value === this.last_sent_value) { | ||||||||||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| return this.param?.value !== this.internal_value | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| param_value(): number { | ||||||||||||||||||||||||||||||||||||||||||
| return this.param?.value ?? this.uncheckedValue | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| watch: { | ||||||||||||||||||||||||||||||||||||||||||
| param(newParam) { | ||||||||||||||||||||||||||||||||||||||||||
| if (newParam) { | ||||||||||||||||||||||||||||||||||||||||||
| this.internal_value = newParam.value | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+68
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): The watcher on 'param' may overwrite user input. If 'param' changes during user interaction, 'internal_value' may be reset and overwrite user input. Consider updating 'internal_value' only for external changes, not user actions. |
||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| param_value() { | ||||||||||||||||||||||||||||||||||||||||||
| if (this.last_sent_value === undefined) { | ||||||||||||||||||||||||||||||||||||||||||
| this.internal_value = this.param_value | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| mounted() { | ||||||||||||||||||||||||||||||||||||||||||
| this.internal_value = this.param?.value ?? this.uncheckedValue | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| methods: { | ||||||||||||||||||||||||||||||||||||||||||
| onCheckboxChange(value: number): void { | ||||||||||||||||||||||||||||||||||||||||||
| if (this.param_value === value) { | ||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| this.internal_value = value | ||||||||||||||||||||||||||||||||||||||||||
| this.saveEditedParam() | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| async saveEditedParam(): Promise<void> { | ||||||||||||||||||||||||||||||||||||||||||
| if (this.param_value === this.internal_value) { | ||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if (this.param === undefined || this.internal_value === undefined) { | ||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| if (this.param?.rebootRequired) { | ||||||||||||||||||||||||||||||||||||||||||
| autopilot_data.setRebootRequired(true) | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| this.last_sent_value = this.internal_value | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| await mavlink2rest.setParam( | ||||||||||||||||||||||||||||||||||||||||||
| this.param.name, | ||||||||||||||||||||||||||||||||||||||||||
| this.internal_value, | ||||||||||||||||||||||||||||||||||||||||||
| autopilot_data.system_id, | ||||||||||||||||||||||||||||||||||||||||||
| this.param.paramType.type, | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+103
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): No error handling for failed parameter save. Add error handling for 'mavlink2rest.setParam' failures to provide user feedback or implement a retry mechanism.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||
| </script> | ||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,14 +15,26 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <v-icon>mdi-close</v-icon> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </v-btn> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </v-card-title> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <v-card-text> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <inline-parameter-editor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :auto-set="true" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :label="param.name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :param="param" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <v-row> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <v-col cols="6"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <inline-parameter-editor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :auto-set="true" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :label="param.name" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :param="param" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </v-col> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <v-col cols="6"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <parameter-checkbox | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :param="reverse_param" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| label="Reverse Direction" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :checked-value="1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| :unchecked-value="0" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </v-col> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Splitting the editor and checkbox into two columns may cause layout issues on small screens. Consider applying Vuetify's grid breakpoints to stack these components vertically on small screens for better responsiveness.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </v-row> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| </v-card-text> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <v-card-text> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <v-card class="mt-4 mb-4"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <v-card-text> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| <div class="d-flex align-center mb-4"> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -150,6 +162,7 @@ import autopilot from '@/store/autopilot' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import Parameter from '@/types/autopilot/parameter' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import InlineParameterEditor from './InlineParameterEditor.vue' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import ParameterCheckbox from './ParameterCheckbox.vue' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type ParamType = 'min' | 'trim' | 'max' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type ParamValueKey = 'minValue' | 'trimValue' | 'maxValue' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -167,6 +180,7 @@ export default Vue.extend({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'ServoFunctionEditorDialog', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| components: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| InlineParameterEditor, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ParameterCheckbox, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| prop: 'value', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -202,6 +216,9 @@ export default Vue.extend({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| min_param(): Parameter | undefined { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.getParamByType('_MIN') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| reverse_param(): Parameter | undefined { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.getParamByType('_REVERSED') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| minPercent(): number { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this.calculatePercentage(this.minValue) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Defaulting 'param_value' to 'uncheckedValue' could mask issues.
Defaulting to 'uncheckedValue' when 'param' is undefined may hide errors. Consider returning undefined or throwing to surface issues during development.
Suggested implementation:
If you prefer to throw an error instead of returning
undefined, replace the body ofparam_valuewith:You may also need to update any code that uses
param_valueto handle the possibility ofundefinedor the thrown error.