|
1 | 1 | <template> |
2 | | - <v-card> |
3 | | - <v-card-title><v-icon>mdi-45hammer-screwdriver</v-icon> Spindles</v-card-title> |
4 | | - <v-card-text> |
5 | | - <v-simple-table> |
6 | | - <thead> |
7 | | - <th>Spindle Name</th> |
8 | | - <th>Active</th> |
9 | | - <th>Current RPM</th> |
10 | | - <th>Set RPM</th> |
11 | | - </thead> |
12 | | - <tbody> |
13 | | - <tr v-for="(spindle, index) in spindles" :key="index" :class="{'spindle-active' : spindle.current > 0 }"> |
14 | | - <td>{{getName(spindle)}}</td> |
15 | | - <td> |
16 | | - <v-btn v-if="spindle.current <= 0" :value="1" block @click="spindleOn(spindle, index)">On</v-btn> |
17 | | - <v-btn v-else :value="0" block @click="spindleOff(index)">Off</v-btn> |
| 2 | + <v-card> |
| 3 | + <v-card-title> |
| 4 | + <v-icon>mdi-45hammer-screwdriver</v-icon>Spindles |
| 5 | + </v-card-title> |
| 6 | + <v-card-text> |
| 7 | + <v-simple-table> |
| 8 | + <thead> |
| 9 | + <th>{{$t('panel.spindle.spindle')}}</th> |
| 10 | + <th>{{$t('panel.spindle.active')}}</th> |
| 11 | + <th v-show="hasReverseableSpindle">{{$t('panel.spindle.direction')}}</th> |
| 12 | + <th>{{$t('panel.spindle.currentRPM')}}</th> |
| 13 | + <th>{{$t('panel.spindle.setRPM')}}</th> |
| 14 | + </thead> |
| 15 | + <tbody> |
| 16 | + <tr :class="{'spindle-active' : spindle.current > 0 && spindle.active > 0 }" :key="index" v-for="(spindle, index) in spindles" v-show="spindleIsConfigured(index)"> |
| 17 | + <td>{{getName(index)}}</td> |
| 18 | + <td> |
| 19 | + <v-btn @click="spindleOff(index)" block v-if="spindleActive(index)">On</v-btn> |
| 20 | + <v-btn @click="spindleOn(index)" block v-else>Off</v-btn> |
| 21 | + </td> |
| 22 | + <td v-show="hasReverseableSpindle"> |
| 23 | + <v-btn-toggle mandatory v-model="spindleDir[index]" v-show="hasReverseableSpindle && spindle.canReverse"> |
| 24 | + <v-btn>{{$t('panel.spindle.forward')}}</v-btn> |
| 25 | + <v-btn>{{$t('panel.spindle.reverse')}}</v-btn> |
| 26 | + </v-btn-toggle> |
18 | 27 | </td> |
19 | | - <td>{{spindle.current}}</td> |
| 28 | + <td>{{spindle.current}}</td> |
20 | 29 | <td> |
21 | | - <v-combobox :items="rpmInRange(spindle)" :value="spindle.active" @input="setActiveRPM($event, index)"> |
22 | | - </v-combobox> |
23 | | - </td> |
24 | | - </tr> |
25 | | - </tbody> |
26 | | - </v-simple-table> |
27 | | - </v-card-text> |
28 | | - </v-card> |
| 30 | + <v-combobox :items="rpmInRange(spindle)" :value="spindle.active" @input="setActiveRPM($event, index)"></v-combobox> |
| 31 | + </td> |
| 32 | + </tr> |
| 33 | + </tbody> |
| 34 | + </v-simple-table> |
| 35 | + </v-card-text> |
| 36 | + </v-card> |
29 | 37 | </template> |
30 | 38 |
|
31 | | -<style scoped> |
| 39 | +<style scoped lang="scss"> |
| 40 | +tbody { |
| 41 | + tr:hover { |
| 42 | + background-color: transparent !important; |
| 43 | + } |
| 44 | +} |
| 45 | +
|
32 | 46 | td { |
33 | 47 | text-align: center; |
34 | 48 | vertical-align: middle; |
35 | 49 | } |
36 | 50 |
|
37 | | -.spindle-active { |
38 | | - background-color : #00BB00; |
| 51 | +.spindle-active { |
| 52 | + background-color: #00bb00; |
39 | 53 | } |
40 | 54 |
|
41 | 55 | .spindle-on { |
|
50 | 64 | visibility: hidden; |
51 | 65 | } |
52 | 66 |
|
53 | | -
|
54 | 67 | @keyframes spindle-on-pulse { |
55 | 68 | 0% { |
56 | | - background-color: #00AA00; |
| 69 | + background-color: #00aa00; |
57 | 70 | } |
58 | 71 | 50% { |
59 | | - background-color: #00FF00; |
| 72 | + background-color: #00ff00; |
60 | 73 | } |
61 | 74 | 100% { |
62 | | - background-color: #00AA00; |
| 75 | + background-color: #00aa00; |
63 | 76 | } |
64 | 77 | } |
65 | 78 | </style> |
66 | 79 |
|
67 | 80 | <script> |
68 | | -import { mapActions, mapState } from 'vuex'; |
69 | | -//import store from '../../store' |
| 81 | +import {mapActions, mapState} from 'vuex'; |
| 82 | +import {SpindleState} from '../../store/machine/modelEnums.js'; |
| 83 | +import Vue from 'vue'; |
| 84 | +
|
70 | 85 | export default { |
| 86 | + data: function () { |
| 87 | + return { |
| 88 | + spindleDir: [0, 0, 0, 0], |
| 89 | + }; |
| 90 | + }, |
| 91 | + mounted() { |
| 92 | + this.updateSpindleDirection(); |
| 93 | + }, |
71 | 94 | computed: { |
72 | 95 | ...mapState('machine/model', { |
73 | | - spindles: state => state.spindles.filter(spindle => spindle.tool >= 0), |
74 | | - currentTool: state => state.state.currentTool, |
| 96 | + spindles: (state) => state.spindles, |
75 | 97 | }), |
76 | | - ...mapState('machine',{ |
77 | | - spindleRPMs: state => state.settings.spindleRPM |
| 98 | + ...mapState('machine', { |
| 99 | + spindleRPMs: (state) => state.settings.spindleRPM, |
78 | 100 | }), |
| 101 | + hasReverseableSpindle() { |
| 102 | + return this.spindles.some((spindle) => spindle.canReverse); |
| 103 | + }, |
79 | 104 | }, |
80 | 105 | methods: { |
81 | 106 | ...mapActions('machine', ['sendCode']), |
82 | | - getName(spindle) { |
83 | | - return `Spindle ${spindle.tool}`; |
| 107 | + getName(index) { |
| 108 | + return `Spindle ${index}`; |
| 109 | + }, |
| 110 | + spindleIsConfigured(index) { |
| 111 | + return this.spindles[index].state !== SpindleState.unconfigured; |
84 | 112 | }, |
85 | | - spindleState(spindle) { |
86 | | - return spindle.active; |
| 113 | + spindleActive(index) { |
| 114 | + return this.spindles[index].state == SpindleState.forward || this.spindles[index].state == SpindleState.reverse; |
87 | 115 | }, |
88 | | - async setActiveRPM(value, index){ |
89 | | - let code = `M3 P${index} S${value}`; |
| 116 | + async setActiveRPM(value, index) { |
| 117 | + let code = `${this.spindleDir[index] ? 'M4' : 'M3'} P${index} S${value}`; |
90 | 118 | await this.sendCode(code); |
91 | 119 | }, |
92 | | - async spindleOn(spindle, index) { |
93 | | - let code = `M3 P${index} S${spindle.active}`; |
| 120 | + async spindleOn(index) { |
| 121 | + let code = `${this.spindleDir[index] ? 'M4' : 'M3'} P${index} S${this.spindles[index].active}`; |
94 | 122 | await this.sendCode(code); |
95 | 123 | }, |
96 | | - async spindleOff( index) { |
| 124 | + async spindleOff(index) { |
97 | 125 | this.sendCode(`M5 P${index}`); |
98 | 126 | }, |
99 | | - rpmInRange(spindle){ |
100 | | - let rpms = this.spindleRPMs.filter(rpm => rpm >= spindle.min && rpm <= spindle.max).reverse(); |
101 | | - if(!rpms.includes(0)){ |
102 | | - rpms.unshift(0); |
103 | | - } |
| 127 | + rpmInRange(spindle) { |
| 128 | + let rpms = this.spindleRPMs.filter((rpm) => rpm >= spindle.min && rpm <= spindle.max).reverse(); |
| 129 | + if (!rpms.includes(0)) { |
| 130 | + rpms.unshift(0); |
| 131 | + } |
104 | 132 | return rpms; |
105 | | - } |
| 133 | + }, |
| 134 | + updateSpindleDirection() { |
| 135 | + for (let spindleIdx = 0; spindleIdx < 4; spindleIdx++) { |
| 136 | + if (this.spindles[spindleIdx].state) { |
| 137 | + switch (this.spindles[spindleIdx].state) { |
| 138 | + case SpindleState.forward: |
| 139 | + Vue.set(this.spindleDir, spindleIdx, 0); |
| 140 | + break; |
| 141 | + case SpindleState.reverse: |
| 142 | + Vue.set(this.spindleDir, spindleIdx, 1); |
| 143 | + break; |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + }, |
| 148 | + }, |
| 149 | + watch: { |
| 150 | + spindles: { |
| 151 | + deep: true, |
| 152 | + handler() { |
| 153 | + this.updateSpindleDirection(); |
| 154 | + }, |
| 155 | + }, |
106 | 156 | }, |
107 | 157 | }; |
108 | 158 | </script> |
|
0 commit comments