mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-23 19:26:35 +00:00
add MonitorSettingsProvider interface
This commit is contained in:
parent
1982609c87
commit
7bf4ea0637
@ -5,8 +5,8 @@ import {
|
|||||||
Monitor,
|
Monitor,
|
||||||
MonitorManagerProxyClient,
|
MonitorManagerProxyClient,
|
||||||
MonitorManagerProxyFactory,
|
MonitorManagerProxyFactory,
|
||||||
MonitorSettings,
|
|
||||||
} from '../common/protocol/monitor-service';
|
} from '../common/protocol/monitor-service';
|
||||||
|
import { MonitorSettings } from '../node/monitor-settings/monitor-settings-provider';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class MonitorManagerProxyClientImpl
|
export class MonitorManagerProxyClientImpl
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import { Emitter, Event } from "@theia/core";
|
import { Emitter, Event } from '@theia/core';
|
||||||
import { FrontendApplicationContribution, LocalStorageService } from "@theia/core/lib/browser";
|
import {
|
||||||
import { inject, injectable } from "@theia/core/shared/inversify";
|
FrontendApplicationContribution,
|
||||||
|
LocalStorageService,
|
||||||
|
} from '@theia/core/lib/browser';
|
||||||
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class MonitorModel implements FrontendApplicationContribution {
|
export class MonitorModel implements FrontendApplicationContribution {
|
||||||
@ -9,7 +12,9 @@ export class MonitorModel implements FrontendApplicationContribution {
|
|||||||
@inject(LocalStorageService)
|
@inject(LocalStorageService)
|
||||||
protected readonly localStorageService: LocalStorageService;
|
protected readonly localStorageService: LocalStorageService;
|
||||||
|
|
||||||
protected readonly onChangeEmitter: Emitter<MonitorModel.State.Change<keyof MonitorModel.State>>;
|
protected readonly onChangeEmitter: Emitter<
|
||||||
|
MonitorModel.State.Change<keyof MonitorModel.State>
|
||||||
|
>;
|
||||||
|
|
||||||
protected _autoscroll: boolean;
|
protected _autoscroll: boolean;
|
||||||
protected _timestamp: boolean;
|
protected _timestamp: boolean;
|
||||||
@ -65,7 +70,7 @@ export class MonitorModel implements FrontendApplicationContribution {
|
|||||||
this.storeState().then(() => {
|
this.storeState().then(() => {
|
||||||
this.onChangeEmitter.fire({
|
this.onChangeEmitter.fire({
|
||||||
property: 'autoscroll',
|
property: 'autoscroll',
|
||||||
value: this._timestamp
|
value: this._timestamp,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,9 @@ import { SerialMonitorSendInput } from './serial-monitor-send-input';
|
|||||||
import { SerialMonitorOutput } from './serial-monitor-send-output';
|
import { SerialMonitorOutput } from './serial-monitor-send-output';
|
||||||
import { BoardsServiceProvider } from '../../boards/boards-service-provider';
|
import { BoardsServiceProvider } from '../../boards/boards-service-provider';
|
||||||
import { nls } from '@theia/core/lib/common';
|
import { nls } from '@theia/core/lib/common';
|
||||||
import {
|
import { MonitorManagerProxyClient } from '../../../common/protocol';
|
||||||
MonitorManagerProxyClient,
|
|
||||||
MonitorSettings,
|
|
||||||
} from '../../../common/protocol';
|
|
||||||
import { MonitorModel } from '../../monitor-model';
|
import { MonitorModel } from '../../monitor-model';
|
||||||
|
import { MonitorSettings } from '../../../node/monitor-settings/monitor-settings-provider';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class MonitorWidget extends ReactWidget {
|
export class MonitorWidget extends ReactWidget {
|
||||||
|
@ -91,7 +91,7 @@ export class PlotterFrontendContribution extends Contribution {
|
|||||||
const settings = this.monitorManagerProxy.getCurrentSettings(board, port);
|
const settings = this.monitorManagerProxy.getCurrentSettings(board, port);
|
||||||
if ('baudrate' in settings) {
|
if ('baudrate' in settings) {
|
||||||
// Convert from string to numbers
|
// Convert from string to numbers
|
||||||
baudrates = settings['baudrate'].values.map(b => +b);
|
baudrates = settings['baudrate'].values.map((b) => +b);
|
||||||
currentBaudrate = +settings['baudrate'].selectedValue;
|
currentBaudrate = +settings['baudrate'].selectedValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Event, JsonRpcServer } from '@theia/core';
|
import { Event, JsonRpcServer } from '@theia/core';
|
||||||
|
import { MonitorSettings } from '../../node/monitor-settings/monitor-settings-provider';
|
||||||
import { Board, Port } from './boards-service';
|
import { Board, Port } from './boards-service';
|
||||||
|
|
||||||
export const MonitorManagerProxyFactory = Symbol('MonitorManagerProxyFactory');
|
export const MonitorManagerProxyFactory = Symbol('MonitorManagerProxyFactory');
|
||||||
@ -53,8 +54,6 @@ export interface MonitorSetting {
|
|||||||
selectedValue: string;
|
selectedValue: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MonitorSettings = Record<string, MonitorSetting>;
|
|
||||||
|
|
||||||
export namespace Monitor {
|
export namespace Monitor {
|
||||||
export enum Command {
|
export enum Command {
|
||||||
SEND_MESSAGE = 'MONITOR_SEND_MESSAGE',
|
SEND_MESSAGE = 'MONITOR_SEND_MESSAGE',
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { inject, injectable } from "@theia/core/shared/inversify";
|
import { inject, injectable } from '@theia/core/shared/inversify';
|
||||||
import { MonitorManagerProxy, MonitorManagerProxyClient, MonitorSettings, Status } from "../common/protocol";
|
import {
|
||||||
import { Board, Port } from "../common/protocol";
|
MonitorManagerProxy,
|
||||||
import { MonitorManager } from "./monitor-manager";
|
MonitorManagerProxyClient,
|
||||||
|
Status,
|
||||||
|
} from '../common/protocol';
|
||||||
|
import { Board, Port } from '../common/protocol';
|
||||||
|
import { MonitorManager } from './monitor-manager';
|
||||||
|
import { MonitorSettings } from './monitor-settings/monitor-settings-provider';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class MonitorManagerProxyImpl implements MonitorManagerProxy {
|
export class MonitorManagerProxyImpl implements MonitorManagerProxy {
|
||||||
@ -9,9 +14,8 @@ export class MonitorManagerProxyImpl implements MonitorManagerProxy {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@inject(MonitorManager)
|
@inject(MonitorManager)
|
||||||
protected readonly manager: MonitorManager,
|
protected readonly manager: MonitorManager
|
||||||
) {
|
) {}
|
||||||
}
|
|
||||||
|
|
||||||
dispose(): void {
|
dispose(): void {
|
||||||
this.client?.disconnect();
|
this.client?.disconnect();
|
||||||
@ -25,7 +29,11 @@ export class MonitorManagerProxyImpl implements MonitorManagerProxy {
|
|||||||
* @param port port to monitor
|
* @param port port to monitor
|
||||||
* @param settings map of supported configuration by the monitor
|
* @param settings map of supported configuration by the monitor
|
||||||
*/
|
*/
|
||||||
async startMonitor(board: Board, port: Port, settings?: MonitorSettings): Promise<void> {
|
async startMonitor(
|
||||||
|
board: Board,
|
||||||
|
port: Port,
|
||||||
|
settings?: MonitorSettings
|
||||||
|
): Promise<void> {
|
||||||
if (settings) {
|
if (settings) {
|
||||||
await this.changeMonitorSettings(board, port, settings);
|
await this.changeMonitorSettings(board, port, settings);
|
||||||
}
|
}
|
||||||
@ -43,7 +51,11 @@ export class MonitorManagerProxyImpl implements MonitorManagerProxy {
|
|||||||
* @param port port monitored
|
* @param port port monitored
|
||||||
* @param settings map of supported configuration by the monitor
|
* @param settings map of supported configuration by the monitor
|
||||||
*/
|
*/
|
||||||
async changeMonitorSettings(board: Board, port: Port, settings: MonitorSettings): Promise<void> {
|
async changeMonitorSettings(
|
||||||
|
board: Board,
|
||||||
|
port: Port,
|
||||||
|
settings: MonitorSettings
|
||||||
|
): Promise<void> {
|
||||||
if (!this.manager.isStarted(board, port)) {
|
if (!this.manager.isStarted(board, port)) {
|
||||||
// Monitor is not running, no need to change settings
|
// Monitor is not running, no need to change settings
|
||||||
return;
|
return;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { ILogger } from '@theia/core';
|
import { ILogger } from '@theia/core';
|
||||||
import { inject, injectable, named } from '@theia/core/shared/inversify';
|
import { inject, injectable, named } from '@theia/core/shared/inversify';
|
||||||
import { Board, Port, Status, MonitorSettings } from '../common/protocol';
|
import { Board, Port, Status } from '../common/protocol';
|
||||||
import { CoreClientAware } from './core-client-provider';
|
import { CoreClientAware } from './core-client-provider';
|
||||||
import { MonitorService } from './monitor-service';
|
import { MonitorService } from './monitor-service';
|
||||||
|
import { MonitorSettings } from './monitor-settings/monitor-settings-provider';
|
||||||
|
|
||||||
type MonitorID = string;
|
type MonitorID = string;
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ export class MonitorManager extends CoreClientAware {
|
|||||||
if (!monitor) {
|
if (!monitor) {
|
||||||
monitor = this.createMonitor(board, port);
|
monitor = this.createMonitor(board, port);
|
||||||
}
|
}
|
||||||
return await monitor.start();
|
return await monitor.start(monitorID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,7 +135,7 @@ export class MonitorManager extends CoreClientAware {
|
|||||||
return Status.NOT_CONNECTED;
|
return Status.NOT_CONNECTED;
|
||||||
}
|
}
|
||||||
monitor.setUploadInProgress(false);
|
monitor.setUploadInProgress(false);
|
||||||
return await monitor.start();
|
return await monitor.start(monitorID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,13 +1,7 @@
|
|||||||
import { ClientDuplexStream } from '@grpc/grpc-js';
|
import { ClientDuplexStream } from '@grpc/grpc-js';
|
||||||
import { Disposable, Emitter, ILogger } from '@theia/core';
|
import { Disposable, Emitter, ILogger } from '@theia/core';
|
||||||
import { inject, named } from '@theia/core/shared/inversify';
|
import { inject, named } from '@theia/core/shared/inversify';
|
||||||
import {
|
import { Board, Port, Status, Monitor } from '../common/protocol';
|
||||||
Board,
|
|
||||||
Port,
|
|
||||||
Status,
|
|
||||||
MonitorSettings,
|
|
||||||
Monitor,
|
|
||||||
} from '../common/protocol';
|
|
||||||
import {
|
import {
|
||||||
EnumerateMonitorPortSettingsRequest,
|
EnumerateMonitorPortSettingsRequest,
|
||||||
EnumerateMonitorPortSettingsResponse,
|
EnumerateMonitorPortSettingsResponse,
|
||||||
@ -20,6 +14,10 @@ import { CoreClientAware, CoreClientProvider } from './core-client-provider';
|
|||||||
import { WebSocketProvider } from './web-socket/web-socket-provider';
|
import { WebSocketProvider } from './web-socket/web-socket-provider';
|
||||||
import { Port as gRPCPort } from 'arduino-ide-extension/src/node/cli-protocol/cc/arduino/cli/commands/v1/port_pb';
|
import { Port as gRPCPort } from 'arduino-ide-extension/src/node/cli-protocol/cc/arduino/cli/commands/v1/port_pb';
|
||||||
import WebSocketProviderImpl from './web-socket/web-socket-provider-impl';
|
import WebSocketProviderImpl from './web-socket/web-socket-provider-impl';
|
||||||
|
import {
|
||||||
|
MonitorSettings,
|
||||||
|
MonitorSettingsProvider,
|
||||||
|
} from './monitor-settings/monitor-settings-provider';
|
||||||
|
|
||||||
export const MonitorServiceName = 'monitor-service';
|
export const MonitorServiceName = 'monitor-service';
|
||||||
|
|
||||||
@ -50,6 +48,10 @@ export class MonitorService extends CoreClientAware implements Disposable {
|
|||||||
protected readonly onDisposeEmitter = new Emitter<void>();
|
protected readonly onDisposeEmitter = new Emitter<void>();
|
||||||
readonly onDispose = this.onDisposeEmitter.event;
|
readonly onDispose = this.onDisposeEmitter.event;
|
||||||
|
|
||||||
|
@inject(MonitorSettingsProvider)
|
||||||
|
protected readonly monitorSettingsProvider: MonitorSettingsProvider;
|
||||||
|
|
||||||
|
// TODO: use dependency injection
|
||||||
protected readonly webSocketProvider: WebSocketProvider =
|
protected readonly webSocketProvider: WebSocketProvider =
|
||||||
new WebSocketProviderImpl();
|
new WebSocketProviderImpl();
|
||||||
|
|
||||||
@ -75,11 +77,6 @@ export class MonitorService extends CoreClientAware implements Disposable {
|
|||||||
this.dispose();
|
this.dispose();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Sets default settings for this monitor
|
|
||||||
this.portMonitorSettings(port.protocol, board.fqbn!).then(
|
|
||||||
(settings) => (this.settings = settings)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setUploadInProgress(status: boolean): void {
|
setUploadInProgress(status: boolean): void {
|
||||||
@ -108,9 +105,10 @@ export class MonitorService extends CoreClientAware implements Disposable {
|
|||||||
* Start and connects a monitor using currently set board and port.
|
* Start and connects a monitor using currently set board and port.
|
||||||
* If a monitor is already started or board fqbn, port address and/or protocol
|
* If a monitor is already started or board fqbn, port address and/or protocol
|
||||||
* are missing nothing happens.
|
* are missing nothing happens.
|
||||||
|
* @param id
|
||||||
* @returns a status to verify connection has been established.
|
* @returns a status to verify connection has been established.
|
||||||
*/
|
*/
|
||||||
async start(): Promise<Status> {
|
async start(monitorID: string): Promise<Status> {
|
||||||
if (this.duplex) {
|
if (this.duplex) {
|
||||||
return Status.ALREADY_CONNECTED;
|
return Status.ALREADY_CONNECTED;
|
||||||
}
|
}
|
||||||
@ -124,6 +122,10 @@ export class MonitorService extends CoreClientAware implements Disposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logger.info('starting monitor');
|
this.logger.info('starting monitor');
|
||||||
|
this.settings = await this.monitorSettingsProvider.init(
|
||||||
|
monitorID,
|
||||||
|
this.coreClientProvider
|
||||||
|
);
|
||||||
await this.coreClientProvider.initialized;
|
await this.coreClientProvider.initialized;
|
||||||
const coreClient = await this.coreClient();
|
const coreClient = await this.coreClient();
|
||||||
const { client, instance } = coreClient;
|
const { client, instance } = coreClient;
|
||||||
@ -281,6 +283,7 @@ export class MonitorService extends CoreClientAware implements Disposable {
|
|||||||
return this.settings;
|
return this.settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: move this into MonitoSettingsProvider
|
||||||
/**
|
/**
|
||||||
* Returns the possible configurations used to connect a monitor
|
* Returns the possible configurations used to connect a monitor
|
||||||
* to the board specified by fqbn using the specified protocol
|
* to the board specified by fqbn using the specified protocol
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
import { MonitorSetting } from '../../common/protocol';
|
||||||
|
import { CoreClientProvider } from '../core-client-provider';
|
||||||
|
|
||||||
|
export type MonitorSettings = Record<string, MonitorSetting>;
|
||||||
|
|
||||||
|
export const MonitorSettingsProvider = Symbol('MonitorSettingsProvider');
|
||||||
|
export interface MonitorSettingsProvider {
|
||||||
|
init(
|
||||||
|
id: string,
|
||||||
|
coreClientProvider: CoreClientProvider
|
||||||
|
): Promise<MonitorSettings>;
|
||||||
|
get(): Promise<MonitorSettings>;
|
||||||
|
set(settings: MonitorSettings): Promise<MonitorSettings>;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user