mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-29 14:16:39 +00:00
Moved settings to MonitorService
This commit is contained in:
parent
61b8bdeec9
commit
31b704cdb9
@ -1,7 +1,6 @@
|
||||
import { Emitter, ILogger } from "@theia/core";
|
||||
import { ILogger } from "@theia/core";
|
||||
import { inject, injectable, named } from "@theia/core/shared/inversify";
|
||||
import { Board, Port, Status, MonitorSetting, MonitorSettings } from "../common/protocol";
|
||||
import { EnumerateMonitorPortSettingsRequest, EnumerateMonitorPortSettingsResponse } from "./cli-protocol/cc/arduino/cli/commands/v1/monitor_pb";
|
||||
import { Board, Port, Status, MonitorSettings } from "../common/protocol";
|
||||
import { CoreClientAware } from "./core-client-provider";
|
||||
import { MonitorService } from "./monitor-service";
|
||||
|
||||
@ -23,43 +22,6 @@ export class MonitorManager extends CoreClientAware {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the possible configurations used to connect a monitor
|
||||
* to the board specified by fqbn using the specified protocol
|
||||
* @param protocol the protocol of the monitor we want get settings for
|
||||
* @param fqbn the fqbn of the board we want to monitor
|
||||
* @returns a map of all the settings supported by the monitor
|
||||
*/
|
||||
async portMonitorSettings(protocol: string, fqbn: string): Promise<MonitorSettings> {
|
||||
const coreClient = await this.coreClient();
|
||||
const { client, instance } = coreClient;
|
||||
const req = new EnumerateMonitorPortSettingsRequest();
|
||||
req.setInstance(instance);
|
||||
req.setPortProtocol(protocol);
|
||||
req.setFqbn(fqbn);
|
||||
|
||||
const res = await new Promise<EnumerateMonitorPortSettingsResponse>((resolve, reject) => {
|
||||
client.enumerateMonitorPortSettings(req, (err, resp) => {
|
||||
if (!!err) {
|
||||
reject(err)
|
||||
}
|
||||
resolve(resp)
|
||||
})
|
||||
});
|
||||
|
||||
let settings: MonitorSettings = {};
|
||||
for (const iterator of res.getSettingsList()) {
|
||||
settings[iterator.getSettingId()] = {
|
||||
'id': iterator.getSettingId(),
|
||||
'label': iterator.getLabel(),
|
||||
'type': iterator.getType(),
|
||||
'values': iterator.getEnumValuesList(),
|
||||
'selectedValue': iterator.getValue(),
|
||||
}
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to know if a monitor is started
|
||||
* @param board board connected to port
|
||||
@ -178,7 +140,7 @@ export class MonitorManager extends CoreClientAware {
|
||||
* @param port port to monitor
|
||||
* @param settings monitor settings to change
|
||||
*/
|
||||
changeMonitorSettings(board: Board, port: Port, settings: Record<string, MonitorSetting>) {
|
||||
changeMonitorSettings(board: Board, port: Port, settings: MonitorSettings) {
|
||||
const monitorID = this.monitorID(board, port);
|
||||
let monitor = this.monitorServices.get(monitorID);
|
||||
if (!monitor) {
|
||||
@ -187,6 +149,22 @@ export class MonitorManager extends CoreClientAware {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the settings currently used by the pluggable monitor
|
||||
* that's communicating with the specified board/port combination.
|
||||
* @param board board connected to port
|
||||
* @param port port monitored
|
||||
* @returns map of current monitor settings
|
||||
*/
|
||||
currentMonitorSettings(board: Board, port: Port): MonitorSettings {
|
||||
const monitorID = this.monitorID(board, port);
|
||||
const monitor = this.monitorServices.get(monitorID);
|
||||
if (!monitor) {
|
||||
return {};
|
||||
}
|
||||
return monitor.currentSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a MonitorService that handles the lifetime and the
|
||||
* communication via WebSocket with the frontend.
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { ClientDuplexStream } from "@grpc/grpc-js";
|
||||
import { Disposable, Emitter, ILogger } from "@theia/core";
|
||||
import { inject, named } from "@theia/core/shared/inversify";
|
||||
import { Board, Port, Status, MonitorSettings } from "../common/protocol";
|
||||
import { MonitorPortConfiguration, MonitorPortSetting, MonitorRequest, MonitorResponse } from "./cli-protocol/cc/arduino/cli/commands/v1/monitor_pb";
|
||||
import { Board, Port, Status, MonitorSettings, Monitor } from "../common/protocol";
|
||||
import { EnumerateMonitorPortSettingsRequest, EnumerateMonitorPortSettingsResponse, MonitorPortConfiguration, MonitorPortSetting, MonitorRequest, MonitorResponse } from "./cli-protocol/cc/arduino/cli/commands/v1/monitor_pb";
|
||||
import { CoreClientAware } from "./core-client-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'
|
||||
@ -55,6 +55,11 @@ export class MonitorService extends CoreClientAware implements Disposable {
|
||||
this.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
// Sets default settings for this monitor
|
||||
this.portMonitorSettings(port.protocol, board.fqbn!).then(
|
||||
settings => this.settings = settings
|
||||
);
|
||||
}
|
||||
|
||||
getWebsocketAddressPort(): number {
|
||||
@ -222,6 +227,51 @@ export class MonitorService extends CoreClientAware implements Disposable {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns map of current monitor settings
|
||||
*/
|
||||
currentSettings(): MonitorSettings {
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the possible configurations used to connect a monitor
|
||||
* to the board specified by fqbn using the specified protocol
|
||||
* @param protocol the protocol of the monitor we want get settings for
|
||||
* @param fqbn the fqbn of the board we want to monitor
|
||||
* @returns a map of all the settings supported by the monitor
|
||||
*/
|
||||
private async portMonitorSettings(protocol: string, fqbn: string): Promise<MonitorSettings> {
|
||||
const coreClient = await this.coreClient();
|
||||
const { client, instance } = coreClient;
|
||||
const req = new EnumerateMonitorPortSettingsRequest();
|
||||
req.setInstance(instance);
|
||||
req.setPortProtocol(protocol);
|
||||
req.setFqbn(fqbn);
|
||||
|
||||
const res = await new Promise<EnumerateMonitorPortSettingsResponse>((resolve, reject) => {
|
||||
client.enumerateMonitorPortSettings(req, (err, resp) => {
|
||||
if (!!err) {
|
||||
reject(err)
|
||||
}
|
||||
resolve(resp)
|
||||
})
|
||||
});
|
||||
|
||||
let settings: MonitorSettings = {};
|
||||
for (const iterator of res.getSettingsList()) {
|
||||
settings[iterator.getSettingId()] = {
|
||||
'id': iterator.getSettingId(),
|
||||
'label': iterator.getLabel(),
|
||||
'type': iterator.getType(),
|
||||
'values': iterator.getEnumValuesList(),
|
||||
'selectedValue': iterator.getValue(),
|
||||
}
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set monitor settings, if there is a running monitor they'll be sent
|
||||
* to it, otherwise they'll be used when starting one.
|
||||
|
Loading…
x
Reference in New Issue
Block a user