Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 128 additions & 46 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
"command": "peripheral-inspector.svd.clearIgnoredPeripherals",
"title": "Clear Ignored Peripherals (Workspace)",
"icon": "$(clear-all)"
},
{
"command": "peripheral-inspector.svd.periodicRefreshMode",
"title": "Set Periodic Refresh Mode",
"icon": "$(refresh)"
},
{
"command": "peripheral-inspector.svd.periodicRefreshInterval",
"title": "Set Periodic Refresh Interval",
"icon": "$(calendar)"
}
],
"menus": {
Expand Down Expand Up @@ -277,70 +287,142 @@
"when": "view =~ /peripheral-inspector.peripheral-*/ && debugState == stopped",
"group": "navigation@4"
},
{
"command": "peripheral-inspector.svd.periodicRefreshMode",
"when": "view =~ /peripheral-inspector.peripheral-*/",
"group": "more@1"
},
{
"command": "peripheral-inspector.svd.periodicRefreshInterval",
"when": "view =~ /peripheral-inspector.peripheral-*/",
"group": "more@2"
},
{
"command": "peripheral-inspector.svd.clearIgnoredPeripherals",
"when": "view =~ /peripheral-inspector.peripheral-*/ && debugState == stopped && peripheral-inspector.ignoredPeripheralsLength > 0",
"group": "more"
"group": "more@3"
}
],
"webview/context": [
{
"command": "peripheral-inspector.svd.setFormat",
"when": "webviewId =~ /peripheral-inspector.peripheral-*/ && webviewSection == tree-item && cdtTreeItemType !== peripheral-session-node",
"group": "navigation"
"group": "navigation@0.1"
},
{
"submenu": "peripheral-inspector.svd.periodicRefresh",
"when": "webviewId =~ /peripheral-inspector.peripheral-*/",
"group": "navigation@0.2"
},
{
"command": "peripheral-inspector.svd.ignorePeripheral",
"when": "webviewId =~ /peripheral-inspector.peripheral-*/ && webviewSection == tree-item && cdtTreeItemType === peripheral-node",
"group": "navigation"
"group": "navigation@0.3"
}
],
"peripheral-inspector.svd.periodicRefresh": [
{
"command": "peripheral-inspector.svd.periodicRefreshMode",
"when": "true",
"group": "navigation@1"
},
{
"command": "peripheral-inspector.svd.periodicRefreshInterval",
"when": "true",
"group": "navigation@2"
}
]
},
"configuration": {
"title": "Peripheral Inspector",
"properties": {
"peripheral-inspector.definitionPathConfig": {
"type": "string",
"default": "definitionPath",
"description": "Debug configuration key to use to get the path for the definition file"
},
"peripheral-inspector.deviceConfig": {
"type": "string",
"default": "deviceName",
"description": "Debug configuration key to use to get the device name"
},
"peripheral-inspector.processorConfig": {
"type": "string",
"default": "processorName",
"description": "Debug configuration key to use to get the processor name"
},
"peripheral-inspector.packAssetUrl": {
"type": "string",
"default": "https://pack-content.cmsis.io",
"description": "Base URL for CMSIS pack assets"
},
"peripheral-inspector.svdAddrGapThreshold": {
"type": "number",
"default": 16,
"multipleOf": 1,
"minimum": -1,
"maximum": 32,
"description": "If the gap between registers is less than this threshold (multiple of 8), combine into a single read from device. -1 means never combine registers and is very slow"
},
"peripheral-inspector.saveLayout": {
"type": "boolean",
"default": true,
"description": "Save layout of peripheral view between sessions"
},
"peripheral-inspector.ignorePeripherals": {
"type": "array",
"items": {
"type": "string"
"submenus": [
{
"id": "peripheral-inspector.svd.periodicRefresh",
"label": "Periodic Refresh (Workspace)",
"icon": "$(refresh)"
}
],
"configuration": [
{
"title": "Peripheral Inspector"
},
{
"title": "Keys",
"properties": {
"peripheral-inspector.definitionPathConfig": {
"type": "string",
"default": "definitionPath",
"description": "Debug configuration key to use to get the path for the definition file"
},
"peripheral-inspector.deviceConfig": {
"type": "string",
"default": "deviceName",
"description": "Debug configuration key to use to get the device name"
},
"description": "List of case insensitive peripheral names to ignore"
"peripheral-inspector.processorConfig": {
"type": "string",
"default": "processorName",
"description": "Debug configuration key to use to get the processor name"
}
}
},
{
"title": "General",
"properties": {
"peripheral-inspector.packAssetUrl": {
"type": "string",
"default": "https://pack-content.cmsis.io",
"description": "Base URL for CMSIS pack assets"
},
"peripheral-inspector.svdAddrGapThreshold": {
"type": "number",
"default": 16,
"multipleOf": 1,
"minimum": -1,
"maximum": 32,
"description": "If the gap between registers is less than this threshold (multiple of 8), combine into a single read from device. -1 means never combine registers and is very slow"
},
"peripheral-inspector.saveLayout": {
"type": "boolean",
"default": true,
"description": "Save layout of peripheral view between sessions"
},
"peripheral-inspector.ignorePeripherals": {
"type": "array",
"items": {
"type": "string"
},
"description": "List of case insensitive peripheral names to ignore"
}
}
},
{
"title": "Periodic Refresh",
"properties": {
"peripheral-inspector.periodicRefreshMode": {
"type": "string",
"enum": [
"always",
"while running",
"off"
],
"markdownEnumDescriptions": [
"Always refresh automatically after the configured `#peripheral-inspector.periodicRefreshInterval#`",
"Refresh automatically after the configured `#peripheral-inspector.periodicRefreshInterval#` while the CPU is running",
"Do not automatically refresh after the configured delay"
],
"default": "off",
"markdownDescription": "Refresh Peripheral Inspectors after the configured `#peripheral-inspector.periodicRefreshInterval#`.",
"order": 0
},
"peripheral-inspector.periodicRefreshInterval": {
"type": "number",
"default": 500,
"minimum": 500,
"markdownDescription": "Controls the delay in milliseconds after which a Peripheral Inspector is refreshed automatically. Only applies when `#peripheral-inspector.periodicRefreshMode#` is enabled.",
"order": 1
}
}
}
}
]
},
"activationEvents": [
"onDebug",
Expand All @@ -350,4 +432,4 @@
"workspace",
"ui"
]
}
}
47 changes: 27 additions & 20 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,27 @@

import * as vscode from 'vscode';
import { NumberFormat } from './common/format';
import { TreeNotificationContext } from './common/notification';
import { PERIPHERAL_ID_SEP } from './common/peripheral-dto';
import { VSCodeContextKeys } from './common/vscode-context';
import { CTDTreeMessengerType, CTDTreeWebviewContext } from './components/tree/types';
import { getFilePath } from './fileUtils';
import { Commands } from './manifest';
import { PeripheralBaseNode } from './plugin/peripheral/nodes';
import { PeripheralConfigurationProvider } from './plugin/peripheral/tree/peripheral-configuration-provider';
import { PeripheralDataTracker } from './plugin/peripheral/tree/peripheral-data-tracker';
import { PeripheralsTreeTableWebView } from './plugin/peripheral/webview/peripheral-tree-webview-main';
import { getFilePath } from './fileUtils';
import * as manifest from './manifest';
import { VSCodeContextKeys } from './common/vscode-context';

export class PeripheralCommands {
public constructor(
protected readonly dataTracker: PeripheralDataTracker,
protected readonly config: PeripheralConfigurationProvider,
protected readonly webview: PeripheralsTreeTableWebView) {
}

public async activate(context: vscode.ExtensionContext): Promise<void> {
this.updateIgnoredPeripheralsContext();
context.subscriptions.push(
vscode.workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(`${manifest.PACKAGE_NAME}.${manifest.IGNORE_PERIPHERALS}`)) {
this.updateIgnoredPeripheralsContext();
}
}),
this.config.onDidChangeIgnorePeripherals(() => this.updateIgnoredPeripheralsContext()),

// VSCode specific commands
vscode.commands.registerCommand(Commands.FIND_COMMAND_ID, () => this.find()),
Expand All @@ -41,19 +37,21 @@ export class PeripheralCommands {
vscode.commands.registerCommand(Commands.EXPORT_ALL_COMMAND_ID, () => this.peripheralsExportAll()),
vscode.commands.registerCommand(Commands.IGNORE_PERIPHERAL_ID, (context) => this.ignorePeripheral(context)),
vscode.commands.registerCommand(Commands.CLEAR_IGNORED_PERIPHERAL_ID, () => this.clearIgnoredPeripherals()),
vscode.commands.registerCommand(Commands.PERIODIC_REFRESH_ID, (context) => this.periodicRefreshMode(context)),
vscode.commands.registerCommand(Commands.PERIODIC_REFRESH_INTERVAL_ID, (context) => this.periodicRefreshInterval(context)),

// Commands manually rendered in the DOM
vscode.commands.registerCommand(Commands.UPDATE_NODE_COMMAND.commandId, (node, value) => this.peripheralsUpdateNode(node, value)),
vscode.commands.registerCommand(Commands.EXPORT_NODE_COMMAND.commandId, node => this.peripheralsExportNode(node)),
vscode.commands.registerCommand(Commands.COPY_VALUE_COMMAND.commandId, (node, value) => this.peripheralsCopyValue(node, value)),
vscode.commands.registerCommand(Commands.FORCE_REFRESH_COMMAND.commandId, (node) => this.peripheralsForceRefresh(node)),
vscode.commands.registerCommand(Commands.PIN_COMMAND.commandId, (node, _, context) => this.peripheralsTogglePin(node, context)),
vscode.commands.registerCommand(Commands.UNPIN_COMMAND.commandId, (node, _, context) => this.peripheralsTogglePin(node, context)),
vscode.commands.registerCommand(Commands.PIN_COMMAND.commandId, (node) => this.peripheralsTogglePin(node)),
vscode.commands.registerCommand(Commands.UNPIN_COMMAND.commandId, (node) => this.peripheralsTogglePin(node)),
);
}

private updateIgnoredPeripheralsContext(): void {
const ignoredPeripherals = vscode.workspace.getConfiguration(manifest.PACKAGE_NAME)?.inspect<string[]>(manifest.IGNORE_PERIPHERALS)?.workspaceValue ?? [];
const ignoredPeripherals = this.config.ignorePeripherals();
vscode.commands.executeCommand('setContext', VSCodeContextKeys.IGNORED_PERIPHERALS_LENGTH, ignoredPeripherals.length);
}

Expand Down Expand Up @@ -129,27 +127,36 @@ export class PeripheralCommands {
private async peripheralsForceRefresh(node?: PeripheralBaseNode): Promise<void> {
if (node) {
const peripheral = node.getPeripheral();
const changes: PeripheralBaseNode[] = [];
if (peripheral) {
await peripheral.updateData();
await peripheral.updateData({ changes });
}
this.dataTracker.fireOnDidChange();
this.dataTracker.fireOnDidChange(changes);
} else {
await this.dataTracker.updateData();
}
}

private peripheralsTogglePin(node: PeripheralBaseNode, context?: TreeNotificationContext): void {
this.dataTracker.togglePin(node, context);
private peripheralsTogglePin(node: PeripheralBaseNode): void {
this.dataTracker.togglePin(node);
}

private ignorePeripheral(context: CTDTreeWebviewContext): void {
const node = this.dataTracker.getNodeByPath(context.cdtTreeItemId.split(PERIPHERAL_ID_SEP));

const ignoredPeripherals = vscode.workspace.getConfiguration(manifest.PACKAGE_NAME).get<string[]>(manifest.IGNORE_PERIPHERALS) ?? [];
vscode.workspace.getConfiguration(manifest.PACKAGE_NAME).update(manifest.IGNORE_PERIPHERALS, [...ignoredPeripherals, node.name]);
if (node.name) {
this.config.addIgnorePeripherals(node.name);
}
}

private clearIgnoredPeripherals(): void {
vscode.workspace.getConfiguration(manifest.PACKAGE_NAME).update(manifest.IGNORE_PERIPHERALS, undefined);
this.config.setIgnorePeripherals();
}

private periodicRefreshMode(_context?: CTDTreeWebviewContext): void {
this.config.queryPeriodicRefreshMode();
}

private periodicRefreshInterval(_context?: CTDTreeWebviewContext): void {
this.config.queryPeriodicRefreshInterval();
}
}
8 changes: 0 additions & 8 deletions src/common/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
* terms of the MIT License as outlined in the LICENSE File
********************************************************************************/

export interface TreeNotificationContext {
/**
* If true or undefined, the tree will be resynced.
*/
resync?: boolean;
}

export interface TreeNotification<T> {
context?: TreeNotificationContext;
data: T;
}

Expand Down
4 changes: 2 additions & 2 deletions src/common/peripheral-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ export namespace PeripheralRegisterNodeDTO {

export type PeripheralTreeNodeDTOs = PeripheralBaseTreeNodeDTO | PeripheralSessionNodeDTO | PeripheralNodeDTO | PeripheralRegisterNodeDTO | ClusterOrRegisterBaseNodeDTO | PeripheralClusterNodeDTO | PeripheralFieldNodeDTO;
export namespace PeripheralTreeNodeDTOs {
export function getFormat(peripheralId: string | undefined, tree: Map<string, PeripheralTreeNodeDTOs>): NumberFormat {
export function getFormat(peripheralId: string | undefined, tree: Record<string, PeripheralTreeNodeDTOs | undefined>): NumberFormat {
if (peripheralId === undefined) {
return NumberFormat.Auto;
}

const node = tree.get(peripheralId);
const node = tree[peripheralId];
if (node === undefined) {
return NumberFormat.Auto;
}
Expand Down
Loading