File tree Expand file tree Collapse file tree 1 file changed +5
-17
lines changed Expand file tree Collapse file tree 1 file changed +5
-17
lines changed Original file line number Diff line number Diff line change 10
10
port . connect ( ) . then ( ( ) => {
11
11
statusDisplay . textContent = '' ;
12
12
connectButton . textContent = 'Disconnect' ;
13
+
14
+ port . onReceiveError = error => {
15
+ console . error ( error ) ;
16
+ } ;
13
17
} , error => {
14
18
statusDisplay . textContent = error ;
15
19
} ) ;
16
20
}
17
21
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
-
33
22
connectButton . addEventListener ( 'click' , function ( ) {
34
23
if ( port ) {
35
24
port . disconnect ( ) ;
56
45
}
57
46
} ) ;
58
47
59
-
60
48
let colorPicker = document . getElementById ( "color_picker" ) ;
61
49
62
50
colorPicker . addEventListener ( "change" , function ( event ) {
63
- port . send ( str2ab ( colorPicker . value ) ) ;
51
+ port . send ( new TextEncoder ( "utf-8" ) . encode ( colorPicker . value ) ) ;
64
52
} ) ;
65
53
} ) ;
66
54
} ) ( ) ;
You can’t perform that action at this time.
0 commit comments