Skip to content

Commit e34b131

Browse files
committed
convert hmlt utf16 to utf8
1 parent eef3bf7 commit e34b131

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

docs/examples/webusb-rgb/application.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,15 @@
1010
port.connect().then(() => {
1111
statusDisplay.textContent = '';
1212
connectButton.textContent = 'Disconnect';
13+
14+
port.onReceiveError = error => {
15+
console.error(error);
16+
};
1317
}, error => {
1418
statusDisplay.textContent = error;
1519
});
1620
}
1721

18-
function str2ab(str) {
19-
var buf = new ArrayBuffer(str.length); // 2 bytes for each char
20-
var bufView = new Uint8Array(buf);
21-
for (var i=0, strLen=str.length; i<strLen; i++) {
22-
bufView[i] = str.charCodeAt(i);
23-
}
24-
return buf;
25-
}
26-
27-
function hexToBytes(hex) {
28-
for (var bytes = [], c = 0; c < hex.length; c += 2)
29-
bytes.push(parseInt(hex.substr(c, 2), 16));
30-
return bytes;
31-
}
32-
3322
connectButton.addEventListener('click', function() {
3423
if (port) {
3524
port.disconnect();
@@ -56,11 +45,10 @@
5645
}
5746
});
5847

59-
6048
let colorPicker = document.getElementById("color_picker");
6149

6250
colorPicker.addEventListener("change", function(event) {
63-
port.send(str2ab(colorPicker.value));
51+
port.send(new TextEncoder("utf-8").encode(colorPicker.value));
6452
});
6553
});
6654
})();

0 commit comments

Comments
 (0)