Skip to content

Commit 689fb7b

Browse files
authored
Improve debug logging (#4354)
* Improve debug logging * Remove condition * Update logHead
1 parent 517bf75 commit 689fb7b

File tree

7 files changed

+166
-144
lines changed

7 files changed

+166
-144
lines changed

src/js/port_handler.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const DEFAULT_PORT = "noselection";
99
const DEFAULT_BAUDS = 115200;
1010

1111
const PortHandler = new (function () {
12+
this.logHead = "[PORTHANDLER]";
13+
1214
this.currentSerialPorts = [];
1315
this.currentUsbPorts = [];
1416
this.currentBluetoothPorts = [];
@@ -118,15 +120,15 @@ PortHandler.updateCurrentSerialPortsList = async function () {
118120
const ports = await serial.getDevices();
119121
const orderedPorts = this.sortPorts(ports);
120122
this.portAvailable = orderedPorts.length > 0;
121-
123+
console.log(`${this.logHead} Found serial port`, orderedPorts);
122124
this.currentSerialPorts = [...orderedPorts];
123125
};
124126

125127
PortHandler.updateCurrentUsbPortsList = async function () {
126128
const ports = await usb.getDevices();
127129
const orderedPorts = this.sortPorts(ports);
128130
this.dfuAvailable = orderedPorts.length > 0;
129-
131+
console.log(`${this.logHead} Found DFU port`, orderedPorts);
130132
this.currentUsbPorts = [...orderedPorts];
131133
};
132134

@@ -135,7 +137,7 @@ PortHandler.updateCurrentBluetoothPortsList = async function () {
135137
const ports = await BT.getDevices();
136138
const orderedPorts = this.sortPorts(ports);
137139
this.bluetoothAvailable = orderedPorts.length > 0;
138-
140+
console.log(`${this.logHead} Found bluetooth port`, orderedPorts);
139141
this.currentBluetoothPorts = [...orderedPorts];
140142
}
141143
};
@@ -236,11 +238,10 @@ PortHandler.selectActivePort = function (suggestedDevice) {
236238
// Return the default port if no other port was selected
237239
this.portPicker.selectedPort = selectedPort || DEFAULT_PORT;
238240

239-
console.log(`[PORTHANDLER] automatically selected device is '${this.portPicker.selectedPort}'`);
240-
241-
// hack to update Vue component
242-
const p = document.getElementById("port");
243-
p.value = this.portPicker.selectedPort;
241+
console.log(
242+
`${this.logHead} Automatically selected device is '${this.portPicker.selectedPort}' - suggested:`,
243+
suggestedDevice,
244+
);
244245

245246
return selectedPort;
246247
};

src/js/protocols/bluetooth.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class BT extends EventTarget {
5858
constructor() {
5959
super();
6060

61+
this.logHead = "[BLUETOOTH]";
62+
6163
if (!this.bluetooth && window && window.navigator && window.navigator.bluetooth) {
6264
this.bluetooth = navigator.bluetooth;
6365
} else {
@@ -77,8 +79,6 @@ class BT extends EventTarget {
7779
this.bytesReceived = 0;
7880
this.failed = 0;
7981

80-
this.logHead = "[BLUETOOTH]";
81-
8282
this.portCounter = 0;
8383
this.devices = [];
8484
this.device = null;

src/js/protocols/websocket.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ class WebsocketSerial extends EventTarget {
22
constructor() {
33
super();
44

5+
this.logHead = "[WEBSOCKET]";
6+
57
this.connected = false;
68
this.connectionInfo = null;
79

@@ -10,8 +12,6 @@ class WebsocketSerial extends EventTarget {
1012
this.bytesReceived = 0;
1113
this.failed = 0;
1214

13-
this.logHead = "[WEBSOCKET] ";
14-
1515
this.address = "ws://localhost:5761";
1616

1717
this.ws = null;

0 commit comments

Comments
 (0)