@@ -19,13 +19,20 @@ export default class WebSerialDaemon extends Daemon {
19
19
this . agentFound . next ( true ) ;
20
20
this . channelOpenStatus . next ( true ) ;
21
21
this . uploader = uploader ;
22
+ this . connectedPorts = [ ] ;
22
23
23
- this . _populateSupportedBoards ( ) ;
24
+ this . init ( ) ;
24
25
}
25
26
26
- _populateSupportedBoards ( ) {
27
+ init ( ) {
27
28
const supportedBoards = this . uploader . getSupportedBoards ( ) ;
28
29
this . appMessages . next ( { supportedBoards } ) ;
30
+
31
+ this . uploader . listBoards ( ) . then ( ports => {
32
+ this . connectedPorts = ports ;
33
+ this . appMessages . next ( { ports } ) ;
34
+ } ) ;
35
+
29
36
}
30
37
31
38
// eslint-disable-next-line class-methods-use-this
@@ -41,10 +48,35 @@ export default class WebSerialDaemon extends Daemon {
41
48
} ) ;
42
49
// this.handleListMessage(message);
43
50
}
44
-
45
- if ( message . supportedBoards ) {
51
+ else if ( message . supportedBoards ) {
46
52
this . supportedBoards . next ( message . supportedBoards ) ;
47
53
}
54
+ else if ( message . connectedSerialPort ) {
55
+ console . dir ( '******** BEGIN: web-serial-daemon:68 ********' ) ;
56
+ console . dir ( message . connectedSerialPort , { depth : null , colors : true } ) ;
57
+
58
+ const port = this . uploader . getBoardInfoFromSerialPort ( message . connectedSerialPort ) ;
59
+ this . connectedPorts . push ( port ) ;
60
+ console . dir ( this . connectedPorts , { depth : null , colors : true } ) ;
61
+ console . dir ( '******** END: web-serial-daemon:68 ********' ) ;
62
+ this . devicesList . next ( {
63
+ serial : this . connectedPorts ,
64
+ network : [ ]
65
+ } ) ;
66
+ }
67
+ else if ( message . disconnectedSerialPort ) {
68
+ console . dir ( '******** BEGIN: web-serial-daemon:79 ********' ) ;
69
+ console . dir ( message . disconnectedSerialPort , { depth : null , colors : true } ) ;
70
+ const port = this . uploader . getBoardInfoFromSerialPort ( message . disconnectedSerialPort ) ;
71
+ this . connectedPorts = this . connectedPorts . filter ( connectedPort => connectedPort . Name !== port . Name ) ;
72
+ console . dir ( this . connectedPorts , { depth : null , colors : true } ) ;
73
+ console . dir ( '******** END: web-serial-daemon:79 ********' ) ;
74
+ console . dir ( this . connectedPorts , { depth : null , colors : true } ) ;
75
+ this . devicesList . next ( {
76
+ serial : this . connectedPorts ,
77
+ network : [ ]
78
+ } ) ;
79
+ }
48
80
}
49
81
50
82
/**
@@ -90,6 +122,15 @@ export default class WebSerialDaemon extends Daemon {
90
122
} ) ;
91
123
}
92
124
125
+ /** A proxy method to get info from the specified SerialPort object */
126
+ getBoardInfoFromSerialPort ( serialPort ) {
127
+ return this . uploader . getBoardInfoFromSerialPort ( serialPort ) ;
128
+ }
129
+
130
+ connectToSerialDevice ( ) {
131
+ return this . uploader . connectToSerialDevice ( ) ;
132
+ }
133
+
93
134
/**
94
135
* @param {object } uploadPayload
95
136
* TODO: document param's shape
0 commit comments