Changed plotter contribution to use new manager proxy

This commit is contained in:
Silvano Cerza 2022-03-10 17:03:30 +01:00 committed by Alberto Iannaccone
parent ad781f0bfc
commit 6b7b33356d

View File

@ -6,15 +6,14 @@ import {
MaybePromise, MaybePromise,
MenuModelRegistry, MenuModelRegistry,
} from '@theia/core'; } from '@theia/core';
import { SerialModel } from '../serial-model';
import { ArduinoMenus } from '../../menu/arduino-menus'; import { ArduinoMenus } from '../../menu/arduino-menus';
import { Contribution } from '../../contributions/contribution'; import { Contribution } from '../../contributions/contribution';
import { Endpoint, FrontendApplication } from '@theia/core/lib/browser'; import { Endpoint, FrontendApplication } from '@theia/core/lib/browser';
import { ipcRenderer } from '@theia/electron/shared/electron'; import { ipcRenderer } from '@theia/electron/shared/electron';
import { SerialConfig } from '../../../common/protocol'; import { MonitorManagerProxyClient } from '../../../common/protocol';
import { SerialConnectionManager } from '../serial-connection-manager';
import { SerialPlotter } from './protocol'; import { SerialPlotter } from './protocol';
import { BoardsServiceProvider } from '../../boards/boards-service-provider'; import { BoardsServiceProvider } from '../../boards/boards-service-provider';
import { MonitorModel } from '../../monitor-model';
const queryString = require('query-string'); const queryString = require('query-string');
export namespace SerialPlotterContribution { export namespace SerialPlotterContribution {
@ -33,14 +32,14 @@ export class PlotterFrontendContribution extends Contribution {
protected url: string; protected url: string;
protected wsPort: number; protected wsPort: number;
@inject(SerialModel) @inject(MonitorModel)
protected readonly model: SerialModel; protected readonly model: MonitorModel;
@inject(ThemeService) @inject(ThemeService)
protected readonly themeService: ThemeService; protected readonly themeService: ThemeService;
@inject(SerialConnectionManager) @inject(MonitorManagerProxyClient)
protected readonly serialConnection: SerialConnectionManager; protected readonly monitorManagerProxy: MonitorManagerProxyClient;
@inject(BoardsServiceProvider) @inject(BoardsServiceProvider)
protected readonly boardsServiceProvider: BoardsServiceProvider; protected readonly boardsServiceProvider: BoardsServiceProvider;
@ -75,7 +74,7 @@ export class PlotterFrontendContribution extends Contribution {
this.window.focus(); this.window.focus();
return; return;
} }
const wsPort = this.serialConnection.getWsPort(); const wsPort = this.monitorManagerProxy.getWebSocketPort();
if (wsPort) { if (wsPort) {
this.open(wsPort); this.open(wsPort);
} else { } else {
@ -84,14 +83,27 @@ export class PlotterFrontendContribution extends Contribution {
} }
protected async open(wsPort: number): Promise<void> { protected async open(wsPort: number): Promise<void> {
const board = this.boardsServiceProvider.boardsConfig.selectedBoard;
const port = this.boardsServiceProvider.boardsConfig.selectedPort;
let baudrates: number[] = [];
let currentBaudrate = -1;
if (board && port) {
const settings = this.monitorManagerProxy.getCurrentSettings(board, port);
if ('baudrate' in settings) {
// Convert from string to numbers
baudrates = settings['baudrate'].values.map(b => +b);
currentBaudrate = +settings['baudrate'].selectedValue;
}
}
const initConfig: Partial<SerialPlotter.Config> = { const initConfig: Partial<SerialPlotter.Config> = {
baudrates: SerialConfig.BaudRates.map((b) => b), baudrates,
currentBaudrate: this.model.baudRate, currentBaudrate,
currentLineEnding: this.model.lineEnding, currentLineEnding: this.model.lineEnding,
darkTheme: this.themeService.getCurrentTheme().type === 'dark', darkTheme: this.themeService.getCurrentTheme().type === 'dark',
wsPort, wsPort,
interpolate: this.model.interpolate, interpolate: this.model.interpolate,
connected: await this.serialConnection.isBESerialConnected(), connected: await this.monitorManagerProxy.isWSConnected(),
serialPort: this.boardsServiceProvider.boardsConfig.selectedPort?.address, serialPort: this.boardsServiceProvider.boardsConfig.selectedPort?.address,
}; };
const urlWithParams = queryString.stringifyUrl( const urlWithParams = queryString.stringifyUrl(