@@ -73,11 +73,9 @@ var WebSerialDaemon = /*#__PURE__*/function (_Daemon) {
73
73
ports : ports
74
74
} ) ;
75
75
} ) ;
76
- } // eslint-disable-next-line class-methods-use-this
77
-
78
- } , {
79
- key : "closeSerialMonitor" ,
80
- value : function closeSerialMonitor ( ) { // TODO: it's a NO OP at the moment
76
+ this . uploader . on ( 'data' , function ( data ) {
77
+ return _this2 . serialMonitorMessages . next ( data ) ;
78
+ } ) ;
81
79
}
82
80
} , {
83
81
key : "handleAppMessage" ,
@@ -132,7 +130,9 @@ var WebSerialDaemon = /*#__PURE__*/function (_Daemon) {
132
130
return ;
133
131
}
134
132
135
- var serialPort = this . devicesList . getValue ( ) . serial [ 0 ] ; // .find(p => p.Name === port);
133
+ var serialPort = this . devicesList . getValue ( ) . serial . find ( function ( p ) {
134
+ return p . Name === port ;
135
+ } ) ;
136
136
137
137
if ( ! serialPort ) {
138
138
return this . serialMonitorError . next ( "Can't find port " . concat ( port ) ) ;
@@ -149,22 +149,77 @@ var WebSerialDaemon = /*#__PURE__*/function (_Daemon) {
149
149
_this3 . serialMonitorError . next ( "Failed to open serial " . concat ( port ) ) ;
150
150
}
151
151
} ) ;
152
+ this . uploader . openPort ( serialPort ) . then ( function ( ports ) {
153
+ _this3 . appMessages . next ( {
154
+ portOpenStatus : 'success'
155
+ } ) ;
156
+
157
+ _this3 . appMessages . next ( {
158
+ ports : ports
159
+ } ) ;
160
+ } ) [ "catch" ] ( function ( ) {
161
+ return _this3 . appMessages . next ( {
162
+ portOpenStatus : 'error'
163
+ } ) ;
164
+ } ) ;
165
+ }
166
+ } , {
167
+ key : "closeSerialMonitor" ,
168
+ value : function closeSerialMonitor ( port ) {
169
+ var _this4 = this ;
170
+
171
+ if ( ! this . serialMonitorOpened . getValue ( ) ) {
172
+ return ;
173
+ }
174
+
175
+ var serialPort = this . devicesList . getValue ( ) . serial . find ( function ( p ) {
176
+ return p . Name === port ;
177
+ } ) ;
178
+
179
+ if ( ! serialPort ) {
180
+ return this . serialMonitorError . next ( "Can't find port " . concat ( port ) ) ;
181
+ }
182
+
183
+ this . appMessages . pipe ( takeUntil ( this . serialMonitorOpened . pipe ( filter ( function ( open ) {
184
+ return ! open ;
185
+ } ) ) ) ) . subscribe ( function ( message ) {
186
+ if ( message . portCloseStatus === 'success' ) {
187
+ _this4 . serialMonitorOpened . next ( false ) ;
188
+ }
189
+
190
+ if ( message . portCloseStatus === 'error' ) {
191
+ _this4 . serialMonitorError . next ( "Failed to close serial " . concat ( port ) ) ;
192
+ }
193
+ } ) ;
194
+ this . uploader . closePort ( serialPort ) . then ( function ( ports ) {
195
+ _this4 . appMessages . next ( {
196
+ portCloseStatus : 'success'
197
+ } ) ;
198
+
199
+ _this4 . appMessages . next ( {
200
+ ports : ports
201
+ } ) ;
202
+ } ) [ "catch" ] ( function ( ) {
203
+ return _this4 . appMessages . next ( {
204
+ portCloseStatus : 'error'
205
+ } ) ;
206
+ } ) ;
152
207
}
153
208
} , {
154
209
key : "cdcReset" ,
155
210
value : function cdcReset ( _ref ) {
156
- var _this4 = this ;
211
+ var _this5 = this ;
157
212
158
213
var fqbn = _ref . fqbn ;
159
214
return this . uploader . cdcReset ( {
160
215
fqbn : fqbn
161
216
} ) . then ( function ( ) {
162
- _this4 . uploading . next ( {
163
- status : _this4 . CDC_RESET_DONE ,
217
+ _this5 . uploading . next ( {
218
+ status : _this5 . CDC_RESET_DONE ,
164
219
msg : 'Touch operation succeeded'
165
220
} ) ;
166
221
} ) [ "catch" ] ( function ( error ) {
167
- _this4 . notifyUploadError ( error . message ) ;
222
+ _this5 . notifyUploadError ( error . message ) ;
168
223
} ) ;
169
224
}
170
225
/** A proxy method to get info from the specified SerialPort object */
@@ -187,15 +242,15 @@ var WebSerialDaemon = /*#__PURE__*/function (_Daemon) {
187
242
} , {
188
243
key : "_upload" ,
189
244
value : function _upload ( uploadPayload ) {
190
- var _this5 = this ;
245
+ var _this6 = this ;
191
246
192
247
return this . uploader . upload ( uploadPayload ) . then ( function ( ) {
193
- _this5 . uploading . next ( {
194
- status : _this5 . UPLOAD_DONE ,
248
+ _this6 . uploading . next ( {
249
+ status : _this6 . UPLOAD_DONE ,
195
250
msg : 'Sketch uploaded'
196
251
} ) ;
197
252
} ) [ "catch" ] ( function ( error ) {
198
- _this5 . notifyUploadError ( error . message ) ;
253
+ _this6 . notifyUploadError ( error . message ) ;
199
254
} ) ;
200
255
}
201
256
} ] ) ;
0 commit comments