Skip to content

Commit

Permalink
Modify the port_handler more the Vue way
Browse files Browse the repository at this point in the history
  • Loading branch information
McGiverGim committed May 15, 2024
1 parent 61904e8 commit f3a9541
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 187 deletions.
2 changes: 2 additions & 0 deletions src/components/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import StatusBar from "./status-bar/StatusBar.vue";
import BatteryIcon from "./quad-status/BatteryIcon.vue";
import FC from '../js/fc.js';
import MSP from '../js/msp.js';
import PortHandler from '../js/port_handler.js';
import PortUsage from '../js/port_usage.js';
import PortPicker from './port-picker/PortPicker.vue';
import CONFIGURATOR from '../js/data_storage.js';
Expand All @@ -26,6 +27,7 @@ const betaflightModel = {
FC,
MSP,
PortUsage,
PortHandler,
};

i18next.on('initialized', function() {
Expand Down
29 changes: 22 additions & 7 deletions src/components/port-picker/PortPicker.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<template>
<div class="web-port-picker">
<FirmwareVirtualOption :is-virtual="port === 'virtual'" />
<PortsInput v-model="port" />
<FirmwareVirtualOption :is-virtual="value.selectedPort === 'virtual'" />
<PortsInput
v-model="value"
:connected-devices="connectedDevices"
:read-only="readOnly" />
</div>
</template>

Expand All @@ -10,15 +13,27 @@ import FirmwareVirtualOption from "./FirmwareVirtualOption.vue";
import PortsInput from "./PortsInput.vue";
export default {
props: {
value: {
type: Object,
default: {
selectedPort: "manual",
selectedBaud: 115200,
},
},
connectedDevices: {
type: Array,
default: () => [],
},
readOnly: {
type: Boolean,
default: false,
},
},
components: {
FirmwareVirtualOption,
PortsInput,
},
data() {
return {
port: 'manual',
};
},
};
</script>

Expand Down
42 changes: 36 additions & 6 deletions src/components/port-picker/PortsInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
id="port"
class="dropdown-select"
:title="$t('firmwareFlasherManualPort')"
@value="value"
@input="$emit('input', $event.target.value)"
:disabled="readOnly"
v-model="value.selectedPort"
@change="onChange"
>
<option value="manual">
{{ $t("portsSelectManual") }}
Expand All @@ -20,16 +21,27 @@
>
{{ $t("portsSelectVirtual") }}
</option>
<option
v-for="connectedDevice in connectedDevices"
:key="connectedDevice.path"
:value="connectedDevice.path"
>
{{ connectedDevice.displayName }}
</option>
<option value="requestpermission">
{{ $t("portsSelectPermission") }}
</option>
</select>
</div>
<div id="auto-connect-and-baud">
<div id="baudselect">
<div class="dropdown dropdown-dark">
<select
id="baud"
v-model="selectedBaudRate"
v-model="value.selectedBauds"
class="dropdown-select"
:title="$t('firmwareFlasherBaudRate')"
:disabled="readOnly"
>
<option
v-for="baudRate in baudRates"
Expand All @@ -52,15 +64,25 @@ import { EventBus } from '../eventBus';
export default {
props: {
value: {
type: String,
default: 'manual',
type: Object,
default: {
selectedPort: 'manual',
selectedBaud: 115200,
},
},
connectedDevices: {
type: Array,
default: () => [],
},
readOnly: {
type: Boolean,
default: false,
},
},
data() {
return {
showVirtual: false,
selectedBaudRate: "115200",
baudRates: [
{ value: "1000000", label: "1000000" },
{ value: "500000", label: "500000" },
Expand Down Expand Up @@ -88,6 +110,14 @@ export default {
setShowVirtual() {
this.showVirtual = getConfig('showVirtualMode').showVirtualMode;
},
onChange(event) {
if (event.target.value === 'requestpermission') {
event.target.value = 'manual';
EventBus.$emit('ports-input:request-permission');
} else {
EventBus.$emit('ports-input:change', event.target.value);
}
},
},
};
</script>
Expand Down
6 changes: 5 additions & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
:firmware-id="FC.CONFIG.flightControllerIdentifier"
:hardware-id="FC.CONFIG.hardwareName"
></betaflight-logo>
<port-picker></port-picker>
<port-picker
v-model="PortHandler.portPicker"
:connected-devices="PortHandler.currentPorts"
:read-only="PortHandler.readOnly"
></port-picker>
<div class="header-wrapper">
<div id="quad-status_wrapper">
<battery-icon
Expand Down
Loading

0 comments on commit f3a9541

Please sign in to comment.