Skip to content

Commit

Permalink
Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
McGiverGim committed May 16, 2024
1 parent 1d0527e commit db85a9a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/components/port-picker/PortPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PortsInput
v-model="value"
:connected-devices="connectedDevices"
:read-only="readOnly" />
:disabled="disabled" />
</div>
</template>

Expand All @@ -25,7 +25,7 @@ export default {
type: Array,
default: () => [],
},
readOnly: {
disabled: {
type: Boolean,
default: false,
},
Expand Down
6 changes: 3 additions & 3 deletions src/components/port-picker/PortsInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
id="port"
class="dropdown-select"
:title="$t('firmwareFlasherManualPort')"
:disabled="readOnly"
:disabled="disabled"
v-model="value.selectedPort"
@change="onChange"
>
Expand Down Expand Up @@ -41,7 +41,7 @@
v-model="value.selectedBauds"
class="dropdown-select"
:title="$t('firmwareFlasherBaudRate')"
:disabled="readOnly"
:disabled="disabled"
>
<option
v-for="baudRate in baudRates"
Expand Down Expand Up @@ -74,7 +74,7 @@ export default {
type: Array,
default: () => [],
},
readOnly: {
disabled: {
type: Boolean,
default: false,
},
Expand Down
2 changes: 1 addition & 1 deletion src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<port-picker
v-model="PortHandler.portPicker"
:connected-devices="PortHandler.currentPorts"
:read-only="PortHandler.readOnly"
:disabled="PortHandler.portPickerDisabled"
></port-picker>
<div class="header-wrapper">
<div id="quad-status_wrapper">
Expand Down
2 changes: 1 addition & 1 deletion src/js/port_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const PortHandler = new function () {
selectedPort: DEFAULT_PORT,
selectedBauds: DEFAULT_BAUDS,
};
this.portPickerReadOnly = false;
this.portPickerDisabled = false;
this.port_detected_callbacks = [];
this.port_removed_callbacks = [];
this.dfu_available = false;
Expand Down
6 changes: 3 additions & 3 deletions src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function initializeSerialBackend() {
GUI.connecting_to = portName;

// lock port select & baud while we are connecting / connected
PortHandler.portPickerReadOnly = true;
PortHandler.portPickerDisabled = true;
$('div.connect_controls div.connect_state').text(i18n.getMessage('connecting'));

const baudRate = selected_baud;
Expand Down Expand Up @@ -225,7 +225,7 @@ function finishClose(finishedCallback) {
$('#dialogReportProblems-closebtn').click();

// unlock port select & baud
PortHandler.portPickerReadOnly = false;
PortHandler.portPickerDisabled = false;

// reset connect / disconnect button
$('div.connect_controls a.connect').removeClass('active');
Expand Down Expand Up @@ -269,7 +269,7 @@ function abortConnection() {
$('div#connectbutton a.connect').removeClass('active');

// unlock port select & baud
PortHandler.portPickerReadOnly = false;
PortHandler.portPickerDisabled = false;

// reset data
isConnected = false;
Expand Down
34 changes: 16 additions & 18 deletions src/js/webSerial.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,22 @@ class WebSerial extends EventTarget {
this.logHead = "SERIAL: ";

this.port_counter = 0;
this.ports = null;
this.ports = [];
this.port = null;
this.reader = null;
this.writer = null;
this.reading = false;

this.connect = this.connect.bind(this);

navigator.serial.addEventListener("connect", e => this.handleNewDevice(e.target).bind(this));
navigator.serial.addEventListener("disconnect", e => this.handleRemovedDevice(e.target).bind(this));
navigator.serial.addEventListener("connect", e => this.handleNewDevice(e.target));
navigator.serial.addEventListener("disconnect", e => this.handleRemovedDevice(e.target));

this.loadDevices();
}

handleNewDevice(device) {
const added = this.createPort(device);
if (this.ports === null) {
this.ports = [];
}
this.ports.push(added);
this.dispatchEvent(new CustomEvent("addedDevice", { detail: added }));
}
Expand Down Expand Up @@ -81,6 +80,17 @@ class WebSerial extends EventTarget {
};
}

async loadDevices() {
const ports = await navigator.serial.getPorts({
filters: webSerialDevices,
});

this.port_counter = 1;
this.ports = ports.map(function (port) {
return this.createPort(port);
}, this);
};

async requestPermissionDevice() {
const permissionPort = await navigator.serial.requestPort({
filters: webSerialDevices,
Expand All @@ -90,18 +100,6 @@ class WebSerial extends EventTarget {
};

async getDevices() {

if (!this.ports) {

const ports = await navigator.serial.getPorts({
filters: webSerialDevices,
});

this.port_counter = 1;
this.ports = ports.map(function (port) {
return this.createPort(port);
}, this);
}
return this.ports;
}

Expand Down

0 comments on commit db85a9a

Please sign in to comment.