@@ -19,6 +19,7 @@ import { BoardsConfig } from '../boards/boards-config';
19
19
import { MonitorModel } from './monitor-model' ;
20
20
import { ThemeService } from '@theia/core/lib/browser/theming' ;
21
21
import { nls } from '@theia/core/lib/browser/nls' ;
22
+ import { CoreService } from '../../common/protocol' ;
22
23
23
24
@injectable ( )
24
25
export class SerialConnectionManager {
@@ -64,7 +65,8 @@ export class SerialConnectionManager {
64
65
@inject ( BoardsServiceProvider )
65
66
protected readonly boardsServiceProvider : BoardsServiceProvider ,
66
67
@inject ( MessageService ) protected messageService : MessageService ,
67
- @inject ( ThemeService ) protected readonly themeService : ThemeService
68
+ @inject ( ThemeService ) protected readonly themeService : ThemeService ,
69
+ @inject ( CoreService ) protected readonly core : CoreService
68
70
) {
69
71
this . monitorServiceClient . onWebSocketChanged (
70
72
this . handleWebSocketChanged . bind ( this )
@@ -121,20 +123,25 @@ export class SerialConnectionManager {
121
123
*
122
124
* @param newConfig the porperties of the config that has changed
123
125
*/
124
- setConfig ( newConfig : Partial < MonitorConfig > ) : void {
126
+ async setConfig ( newConfig : Partial < MonitorConfig > ) : Promise < void > {
125
127
let configHasChanged = false ;
126
128
Object . keys ( this . config ) . forEach ( ( key : keyof MonitorConfig ) => {
127
129
if ( newConfig [ key ] !== this . config [ key ] ) {
128
130
configHasChanged = true ;
129
131
this . config = { ...this . config , [ key ] : newConfig [ key ] } ;
130
132
}
131
133
} ) ;
132
- if ( configHasChanged && this . isSerialOpen ( ) ) {
134
+ if (
135
+ configHasChanged &&
136
+ this . isSerialOpen ( ) &&
137
+ ! ( await this . core . isUploading ( ) )
138
+ ) {
133
139
this . monitorService . updateWsConfigParam ( {
134
140
currentBaudrate : this . config . baudRate ,
135
141
serialPort : this . config . port ?. address ,
136
142
} ) ;
137
- this . disconnect ( ) . then ( ( ) => this . connect ( ) ) ;
143
+ await this . disconnect ( ) ;
144
+ await this . connect ( ) ;
138
145
}
139
146
}
140
147
@@ -176,22 +183,25 @@ export class SerialConnectionManager {
176
183
/**
177
184
* Sets the types of connections needed by the client.
178
185
*
179
- * @param s The new types of connections (can be 'Monitor', 'Plotter', none or both).
186
+ * @param newState The new types of connections (can be 'Monitor', 'Plotter', none or both).
180
187
* If the previuos state was empty and 's' is not, it tries to reconnect to the serial service
181
188
* If the provios state was NOT empty and now it is, it disconnects to the serial service
182
189
* @returns The status of the operation
183
190
*/
184
- protected async setState ( s : Serial . State ) : Promise < Status > {
191
+ protected async setState ( newState : Serial . State ) : Promise < Status > {
185
192
const oldState = deepClone ( this . _state ) ;
186
- this . _state = s ;
187
193
let status = Status . OK ;
188
194
189
- if ( this . isSerialOpen ( oldState ) && ! this . isSerialOpen ( ) ) {
195
+ if ( this . isSerialOpen ( oldState ) && ! this . isSerialOpen ( newState ) ) {
190
196
status = await this . disconnect ( ) ;
191
- } else if ( ! this . isSerialOpen ( oldState ) && this . isSerialOpen ( ) ) {
197
+ } else if ( ! this . isSerialOpen ( oldState ) && this . isSerialOpen ( newState ) ) {
198
+ if ( await this . core . isUploading ( ) ) {
199
+ this . messageService . error ( `Cannot open serial port when uploading` ) ;
200
+ return Status . NOT_CONNECTED ;
201
+ }
192
202
status = await this . connect ( ) ;
193
203
}
194
-
204
+ this . _state = newState ;
195
205
return status ;
196
206
}
197
207
@@ -226,6 +236,12 @@ export class SerialConnectionManager {
226
236
* @returns the status of the operation
227
237
*/
228
238
async openSerial ( type : Serial . Type ) : Promise < Status > {
239
+ if ( ! isMonitorConfig ( this . config ) ) {
240
+ this . messageService . error (
241
+ `Please select a board and a port to open the serial connection.`
242
+ ) ;
243
+ return Status . NOT_CONNECTED ;
244
+ }
229
245
if ( this . state . includes ( type ) ) return Status . OK ;
230
246
const newState = deepClone ( this . state ) ;
231
247
newState . push ( type ) ;
@@ -360,12 +376,7 @@ export class SerialConnectionManager {
360
376
361
377
async connect ( ) : Promise < Status > {
362
378
if ( this . connected ) return Status . ALREADY_CONNECTED ;
363
- if ( ! isMonitorConfig ( this . config ) ) {
364
- this . messageService . error (
365
- `Please select a board and a port to open the serial connection.`
366
- ) ;
367
- return Status . NOT_CONNECTED ;
368
- }
379
+ if ( ! isMonitorConfig ( this . config ) ) return Status . NOT_CONNECTED ;
369
380
370
381
console . info (
371
382
`>>> Creating serial connection for ${ Board . toString (
0 commit comments