@@ -73,11 +73,9 @@ var WebSerialDaemon = /*#__PURE__*/function (_Daemon) {
7373 ports : ports
7474 } ) ;
7575 } ) ;
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+ } ) ;
8179 }
8280 } , {
8381 key : "handleAppMessage" ,
@@ -132,7 +130,9 @@ var WebSerialDaemon = /*#__PURE__*/function (_Daemon) {
132130 return ;
133131 }
134132
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+ } ) ;
136136
137137 if ( ! serialPort ) {
138138 return this . serialMonitorError . next ( "Can't find port " . concat ( port ) ) ;
@@ -149,22 +149,77 @@ var WebSerialDaemon = /*#__PURE__*/function (_Daemon) {
149149 _this3 . serialMonitorError . next ( "Failed to open serial " . concat ( port ) ) ;
150150 }
151151 } ) ;
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+ } ) ;
152207 }
153208 } , {
154209 key : "cdcReset" ,
155210 value : function cdcReset ( _ref ) {
156- var _this4 = this ;
211+ var _this5 = this ;
157212
158213 var fqbn = _ref . fqbn ;
159214 return this . uploader . cdcReset ( {
160215 fqbn : fqbn
161216 } ) . then ( function ( ) {
162- _this4 . uploading . next ( {
163- status : _this4 . CDC_RESET_DONE ,
217+ _this5 . uploading . next ( {
218+ status : _this5 . CDC_RESET_DONE ,
164219 msg : 'Touch operation succeeded'
165220 } ) ;
166221 } ) [ "catch" ] ( function ( error ) {
167- _this4 . notifyUploadError ( error . message ) ;
222+ _this5 . notifyUploadError ( error . message ) ;
168223 } ) ;
169224 }
170225 /** A proxy method to get info from the specified SerialPort object */
@@ -187,15 +242,15 @@ var WebSerialDaemon = /*#__PURE__*/function (_Daemon) {
187242 } , {
188243 key : "_upload" ,
189244 value : function _upload ( uploadPayload ) {
190- var _this5 = this ;
245+ var _this6 = this ;
191246
192247 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 ,
195250 msg : 'Sketch uploaded'
196251 } ) ;
197252 } ) [ "catch" ] ( function ( error ) {
198- _this5 . notifyUploadError ( error . message ) ;
253+ _this6 . notifyUploadError ( error . message ) ;
199254 } ) ;
200255 }
201256 } ] ) ;
0 commit comments