33 <v-card class =" mt-4 mb-4" >
44 <v-card-text >
55 <div class =" d-flex align-center mb-4" >
6- <span class =" text-h6" >Servo Range Configuration </span >
6+ <span class =" text-h6" >{{ title }} </span >
77 <v-tooltip bottom >
88 <template #activator =" { on , attrs } " >
99 <v-icon
1515 mdi-information
1616 </v-icon >
1717 </template >
18- <span >Adjust the minimum, trim, and maximum PWM values for this servo </span >
18+ <span >{{ tooltip }} </span >
1919 </v-tooltip >
2020 </div >
2121 <div
3737 />
3838 <div
3939 v-for =" (thumbType, index) in ['min', 'trim', 'max']"
40+ v-show =" thumbType !== 'trim' || trimParam"
4041 :key =" thumbType"
4142 class =" slider-thumb"
4243 :class =" { active: activeThumb === index }"
6364 <v-card-text class =" py-2" >
6465 <inline-parameter-editor
6566 :auto-set =" true"
66- :label =" min_param ?.name"
67- :param =" min_param "
67+ :label =" minParam ?.name"
68+ :param =" minParam "
6869 />
6970 </v-card-text >
7071 </v-card >
7677 <v-card
7778 outlined
7879 class =" parameter-card"
80+ :disabled =" !trimParam"
81+ :class =" { 'disabled-card': !trimParam }"
7982 >
8083 <v-card-text class =" py-2" >
8184 <inline-parameter-editor
8285 :auto-set =" true"
83- :label =" trim_param ?.name"
84- :param =" trim_param "
86+ :label =" trimParam ?.name ?? 'Trim' "
87+ :param =" trimParam "
8588 />
8689 </v-card-text >
8790 </v-card >
97100 <v-card-text class =" py-2" >
98101 <inline-parameter-editor
99102 :auto-set =" true"
100- :label =" max_param ?.name"
101- :param =" max_param "
103+ :label =" maxParam ?.name"
104+ :param =" maxParam "
102105 />
103106 </v-card-text >
104107 </v-card >
@@ -138,6 +141,26 @@ export default Vue.extend({
138141 type: Object as () => Parameter ,
139142 required: true ,
140143 },
144+ minParam: {
145+ type: Object as () => Parameter | undefined ,
146+ default: undefined ,
147+ },
148+ trimParam: {
149+ type: Object as () => Parameter | undefined ,
150+ default: undefined ,
151+ },
152+ maxParam: {
153+ type: Object as () => Parameter | undefined ,
154+ default: undefined ,
155+ },
156+ title: {
157+ type: String ,
158+ default: ' Servo Range Configuration' ,
159+ },
160+ tooltip: {
161+ type: String ,
162+ default: ' Adjust the minimum, trim, and maximum PWM values for this servo' ,
163+ },
141164 },
142165 data() {
143166 return {
@@ -149,14 +172,14 @@ export default Vue.extend({
149172 }
150173 },
151174 computed: {
152- trim_param (): Parameter | undefined {
153- return this .getParamByType (' _TRIM' )
175+ resolvedTrimParam (): Parameter | undefined {
176+ return this .trimParam ?? this . getParamByType (' _TRIM' )
154177 },
155- max_param (): Parameter | undefined {
156- return this .getParamByType (' _MAX' )
178+ resolvedMaxParam (): Parameter | undefined {
179+ return this .maxParam ?? this . getParamByType (' _MAX' )
157180 },
158- min_param (): Parameter | undefined {
159- return this .getParamByType (' _MIN' )
181+ resolvedMinParam (): Parameter | undefined {
182+ return this .minParam ?? this . getParamByType (' _MIN' )
160183 },
161184 minPercent(): number {
162185 return this .calculatePercentage (this .minValue )
@@ -176,13 +199,28 @@ export default Vue.extend({
176199 },
177200 immediate: true ,
178201 },
179- ' min_param.value' : function onMinParamChange(newValue : number ) {
202+ minParam: {
203+ handler() {
204+ this .initializeSliderValues ()
205+ },
206+ },
207+ trimParam: {
208+ handler() {
209+ this .initializeSliderValues ()
210+ },
211+ },
212+ maxParam: {
213+ handler() {
214+ this .initializeSliderValues ()
215+ },
216+ },
217+ ' resolvedMinParam.value' : function onMinParamChange(newValue : number ) {
180218 this .updateParamValue (' min' , newValue )
181219 },
182- ' trim_param .value' : function onTrimParamChange(newValue : number ) {
220+ ' resolvedTrimParam .value' : function onTrimParamChange(newValue : number ) {
183221 this .updateParamValue (' trim' , newValue )
184222 },
185- ' max_param .value' : function onMaxParamChange(newValue : number ) {
223+ ' resolvedMaxParam .value' : function onMaxParamChange(newValue : number ) {
186224 this .updateParamValue (' max' , newValue )
187225 },
188226 },
@@ -202,9 +240,9 @@ export default Vue.extend({
202240 max: ' maxValue' ,
203241 }
204242 const paramMap: ParamMap = {
205- min: ' min_param ' ,
206- trim: ' trim_param ' ,
207- max: ' max_param ' ,
243+ min: ' resolvedMinParam ' ,
244+ trim: ' resolvedTrimParam ' ,
245+ max: ' resolvedMaxParam ' ,
208246 }
209247
210248 const valueKey = valueMap [type ]
@@ -219,10 +257,14 @@ export default Vue.extend({
219257 }
220258 },
221259 initializeSliderValues(): void {
222- if (this .min_param && this .trim_param && this .max_param ) {
223- this .minValue = Number (this .min_param .value )
224- this .trimValue = Number (this .trim_param .value )
225- this .maxValue = Number (this .max_param .value )
260+ if (this .resolvedMinParam ) {
261+ this .minValue = Number (this .resolvedMinParam .value )
262+ }
263+ if (this .resolvedTrimParam ) {
264+ this .trimValue = Number (this .resolvedTrimParam .value )
265+ }
266+ if (this .resolvedMaxParam ) {
267+ this .maxValue = Number (this .resolvedMaxParam .value )
226268 }
227269 },
228270 getThumbPosition(index : number ): number {
@@ -255,7 +297,7 @@ export default Vue.extend({
255297 findClosestThumb(value : number ): number {
256298 const distances = [
257299 Math .abs (value - this .minValue ),
258- Math .abs (value - this .trimValue ),
300+ this . resolvedTrimParam ? Math .abs (value - this .trimValue ) : Infinity ,
259301 Math .abs (value - this .maxValue ),
260302 ]
261303 return distances .indexOf (Math .min (... distances ))
@@ -269,9 +311,9 @@ export default Vue.extend({
269311 if (! this .isDragging ) return
270312
271313 const paramMap = {
272- 0 : this .min_param ,
273- 1 : this .trim_param ,
274- 2 : this .max_param ,
314+ 0 : this .resolvedMinParam ,
315+ 1 : this .resolvedTrimParam ,
316+ 2 : this .resolvedMaxParam ,
275317 }
276318 const valueMap = {
277319 0 : this .minValue ,
@@ -305,10 +347,11 @@ export default Vue.extend({
305347 this .updateValueBasedOnThumb (value )
306348 },
307349 updateValueBasedOnThumb(value : number ): void {
350+ const hasTrim = !! this .resolvedTrimParam
308351 const constraints = {
309- 0 : { min: MIN_PWM , max: this .trimValue - 1 },
352+ 0 : { min: MIN_PWM , max: hasTrim ? this .trimValue - 1 : this . maxValue - 1 },
310353 1 : { min: this .minValue + 1 , max: this .maxValue - 1 },
311- 2 : { min: this .trimValue + 1 , max: MAX_PWM },
354+ 2 : { min: hasTrim ? this .trimValue + 1 : this . minValue + 1 , max: MAX_PWM },
312355 }
313356
314357 const updateFunctions = {
@@ -326,13 +369,21 @@ export default Vue.extend({
326369 }
327370 },
328371 updateMin(value : string ): void {
329- this .updateParamWithConstraints (value , this .min_param , MIN_PWM , this .trimValue - 1 , ' minValue' )
372+ const maxConstraint = this .resolvedTrimParam ? this .trimValue - 1 : this .maxValue - 1
373+ this .updateParamWithConstraints (value , this .resolvedMinParam , MIN_PWM , maxConstraint , ' minValue' )
330374 },
331375 updateTrim(value : string ): void {
332- this .updateParamWithConstraints (value , this .trim_param , this .minValue + 1 , this .maxValue - 1 , ' trimValue' )
376+ this .updateParamWithConstraints (
377+ value ,
378+ this .resolvedTrimParam ,
379+ this .minValue + 1 ,
380+ this .maxValue - 1 ,
381+ ' trimValue' ,
382+ )
333383 },
334384 updateMax(value : string ): void {
335- this .updateParamWithConstraints (value , this .max_param , this .trimValue + 1 , MAX_PWM , ' maxValue' )
385+ const minConstraint = this .resolvedTrimParam ? this .trimValue + 1 : this .minValue + 1
386+ this .updateParamWithConstraints (value , this .resolvedMaxParam , minConstraint , MAX_PWM , ' maxValue' )
336387 },
337388 updateParamWithConstraints(
338389 value : string ,
@@ -383,6 +434,11 @@ export default Vue.extend({
383434 box-shadow : 0 2px 8px rgba (0 , 0 , 0 , 0.1 ) !important ;
384435}
385436
437+ .parameter-card.disabled-card {
438+ opacity : 0.5 ;
439+ pointer-events : none ;
440+ }
441+
386442.servo-slider {
387443 position : relative ;
388444 height : 80px ;
0 commit comments