Skip to content

Commit d19519d

Browse files
committed
[GUI] Updated vue-slider-component version number, changed display behavior of numerical values to automatically switch to scientific notation under certain conditions, fixed header menu behavior
1 parent 6e856a8 commit d19519d

File tree

9 files changed

+122
-26
lines changed

9 files changed

+122
-26
lines changed

GUI/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,19 @@ npm run electron:serve
3838
npm run electron:build
3939
```
4040

41+
### Build electron app for all platforms
42+
```
43+
npm run electron:build -- -mwl
44+
```
45+
46+
### Building for rpi and potentially other ARM platform devices
47+
48+
PhantomJS is required as a dependency, so it must be installed first:
49+
```
50+
sudo apt install phantomjs
51+
```
52+
53+
After it is installed, `npm run electron:build` can be used to build the AppImage for ARM
54+
4155
### Customize configuration
4256
See [Configuration Reference](https://cli.vuejs.org/config/).

GUI/package-lock.json

Lines changed: 40 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GUI/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"vue-context": "^5.2.0",
3131
"vue-directive-tooltip": "^1.6.3",
3232
"vue-json-component": "^0.4.1",
33-
"vue-slider-component": "^3.2.2",
33+
"vue-slider-component": "^3.2.11",
3434
"vuex": "^3.5.1"
3535
},
3636
"devDependencies": {
@@ -46,7 +46,6 @@
4646
"eslint-plugin-vue": "^6.2.2",
4747
"vue-cli-plugin-electron-builder": "~2.0.0-rc.4",
4848
"vue-cli-plugin-yaml": "^1.0.2",
49-
"vue-json-component": "^0.4.1",
5049
"vue-template-compiler": "^2.6.11"
5150
},
5251
"eslintConfig": {

GUI/src/App.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
style="display: none"
2020
/>
2121
</button>
22-
<button class="dash-button menu-item" id="importButton" @click="calcImportLeft();calcImportTop();showImport = !showImport">Import ODrive config</button>
23-
<button class="dash-button menu-item" id="exportButton" @click="calcExportLeft();calcExportTop();showExport = !showExport">Export ODrive config</button>
22+
<button class="dash-button menu-item" id="importButton" @click="calcImportLeft();calcImportTop();toggleImport()">Import ODrive config</button>
23+
<button class="dash-button menu-item" id="exportButton" @click="calcExportLeft();calcExportTop();toggleExport()">Export ODrive config</button>
2424
</div>
2525
<div class="card import-menu" :style="{top: importTop, left: importLeft}" v-show="showImport">
2626
<button v-for="odrive in Object.keys(odrives)" :key="odrive" class="dash-button" @click="importConfigWrapper">
@@ -189,6 +189,14 @@ export default {
189189
this.showExport = false;
190190
}
191191
},
192+
toggleImport() {
193+
this.showImport = !this.showImport;
194+
this.showExport = false;
195+
},
196+
toggleExport() {
197+
this.showExport = !this.showExport;
198+
this.showImport= false;
199+
},
192200
importConfigWrapper() {
193201
const inputElem = document.getElementById("inputConfig");
194202
if (inputElem) {

GUI/src/assets/wizard/configTemplate.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"mode": null,
1919
"use_index": null,
2020
"cpr": null,
21-
"calib_scan_distance": null
21+
"calib_scan_distance": null,
22+
"abs_spi_cs_gpio_pin": null
2223
}
2324
},
2425
"controller": {
@@ -53,7 +54,8 @@
5354
"mode": null,
5455
"use_index": null,
5556
"cpr": null,
56-
"calib_scan_distance": null
57+
"calib_scan_distance": null,
58+
"abs_spi_cs_gpio_pin": null
5759
}
5860
},
5961
"controller": {

GUI/src/components/actions/Action.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
<button class="close-button" @click=deleteAction>X</button>
44
<span class="ctrlName">{{shortPath}}:</span>
55
<div class="right">
6-
<input v-on:change="newVal" :placeholder="initVal" :value="this.value"/>
6+
<input v-on:change="newVal" :placeholder="initVal" :value="valueDisplay" spellcheck="false"/>
77
<button class="action-button close-button" @click="putVal">Send</button>
88
</div>
99
</div>
1010
</template>
1111

1212
<script>
1313
import { putVal, parseMath } from "../../lib/odrive_utils.js";
14+
import { numberDisplay } from "../../lib/utils.js"
1415
1516
export default {
1617
name: "Action",
@@ -35,6 +36,9 @@ export default {
3536
let keys = this.path.split('.');
3637
keys.shift();
3738
return keys.join('.');
39+
},
40+
valueDisplay() {
41+
return numberDisplay(this.value);
3842
}
3943
},
4044
methods: {

GUI/src/components/controls/CtrlNumeric.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
<span class="ctrlName">{{name}}:</span>
55
<div class="right">
66
<span v-if="!writeAccess" class="ctrlVal">{{value}}</span>
7-
<input v-if="writeAccess" :placeholder="value" v-on:change="putVal" :value="value"/>
7+
<input v-if="writeAccess" :placeholder="value" v-on:change="putVal" :value="value" spellcheck="false"/>
88
<!-- <span class="unit">[{{unit}}]</span> -->
99
</div>
1010
</div>
1111
</template>
1212

1313
<script>
1414
import { getVal, getReadonly, putVal, fetchParam, getUnit, parseMath } from "../../lib/odrive_utils.js";
15+
import { numberDisplay } from "../../lib/utils.js";
1516
1617
export default {
1718
name: "CtrlNumeric",
@@ -27,7 +28,7 @@ export default {
2728
keys.shift();
2829
let val = getVal(keys.join('.'));
2930
console.log(val + ' ' + typeof val);
30-
return parseFloat(val).toFixed(3);
31+
return numberDisplay(val);
3132
},
3233
name: function () {
3334
let keys = this.path.split(".");

GUI/src/components/controls/CtrlSlider.vue

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
<span class="ctrlName">{{name}}</span>
66
</div>
77
<div class="slider-container">
8-
<input type="number" :value="min" v-on:change="setMin"/>
8+
<input type="number" :value="displayMin" v-on:change="setMin"/>
99
<!-- <vue-slider v-model="value" :min="min" :max="max" :interval="interval" /> -->
10-
<vue-slider v-model="value" :data="data" @change="putVal"/>
11-
<input type="number" :value="max" v-on:change="setMax" />
10+
<vue-slider v-model="value" :data="data" :adsorb="true" @change="putVal"/>
11+
<input type="number" :value="displayMax" v-on:change="setMax" />
1212
</div>
1313
</div>
1414
</template>
1515

1616
<script>
1717
import VueSlider from "vue-slider-component";
1818
import "vue-slider-component/theme/default.css";
19-
import { getVal, putVal } from "../../lib/odrive_utils.js";
19+
import { getVal, putVal, parseMath } from "../../lib/odrive_utils.js";
20+
import { numberDisplay } from "../../lib/utils.js";
2021
2122
export default {
2223
name: "CtrlSlider",
@@ -49,6 +50,12 @@ export default {
4950
sliderData: function () {
5051
let interval = (this.max - this.min) / 100;
5152
return Array.from(Array(101), (_, i) => this.min + interval * i);
53+
},
54+
displayMin() {
55+
return numberDisplay(this.min);
56+
},
57+
displayMax() {
58+
return numberDisplay(this.max);
5259
}
5360
},
5461
methods: {
@@ -59,27 +66,41 @@ export default {
5966
putVal(keys.join('.'), value);
6067
},
6168
setMin: function (e) {
62-
this.min = parseFloat(e.target.value);
69+
this.min = parseMath(e.target.value);
6370
this.data = Array.from(Array(101), (_, i) => this.min + (this.max-this.min) / 100 * i);
71+
this.value = this.findNearest(this.data, this.value);
6472
},
6573
setMax: function (e) {
66-
this.max = parseFloat(e.target.value);
74+
this.max = parseMath(e.target.value);
6775
this.data = Array.from(Array(101), (_, i) => this.min + (this.max-this.min) / 100 * i);
76+
this.value = this.findNearest(this.data, this.value);
6877
},
6978
deleteCtrl: function() {
7079
// commit a mutation in the store with the relevant information
7180
this.$store.commit("removeCtrlFromDash", {dashID: this.dashID, path: this.path});
81+
},
82+
findNearest(data, value) {
83+
// find item in data closest to value
84+
let diff = Number.POSITIVE_INFINITY;
85+
let retVal = value;
86+
for (const val of data) {
87+
if (Math.abs(val - value) < diff) {
88+
diff = Math.abs(val - value);
89+
retVal = val;
90+
}
91+
}
92+
return retVal;
7293
}
7394
},
7495
mounted() {
7596
let initVal = () => {
7697
let keys = this.path.split(".");
7798
keys.shift(); // don't need first key here
78-
return getVal(keys.join('.'));
99+
return parseFloat(getVal(keys.join('.')));
79100
};
80101
this.value = initVal();
81-
this.max = parseFloat((this.value * 4).toFixed(3));
82-
this.min = parseFloat((this.value / 4).toFixed(3));
102+
this.max = this.value * 4;
103+
this.min = this.value / 4;
83104
this.data = Array.from(Array(101), (_, i) => this.min + (this.max-this.min) / 100 * i);
84105
},
85106
};

GUI/src/lib/utils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,19 @@ export let pathsFromTree = (tree) => {
7575
// array path
7676
pathFromTree(tree);
7777
return flatpaths;
78+
}
79+
80+
export let numberDisplay = (val) => {
81+
// if a number can be represented with 3 decimals, return it in that form
82+
// otherwise, return scientific notation
83+
let retVal = '';
84+
try {
85+
retVal = parseFloat(val).toFixed(3);
86+
if (retVal == '0.000' && val != 0 || retVal.length > 7) {
87+
retVal = parseFloat(val).toExponential(3);
88+
}
89+
} catch (error) {
90+
console.log(error);
91+
}
92+
return retVal;
7893
}

0 commit comments

Comments
 (0)