Search in sources :

Example 1 with DeviceSelector

use of net.sourceforge.usbdm.deviceDatabase.ui.DeviceSelector in project usbdm-eclipse-plugins by podonoghue.

the class DevicePeripheralSelectionDialogue method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    // Create the manager and bind to main composite
    resManager = new LocalResourceManager(JFaceResources.getResources(), parent);
    Composite container = (Composite) super.createDialogArea(parent);
    GridLayout layout = new GridLayout(1, false);
    layout.marginRight = 5;
    layout.marginLeft = 5;
    container.setLayout(layout);
    /*
       * Create Internal group
       */
    grpInternal = new Group(container, SWT.NONE);
    grpInternal.setText("Internal SVD Files");
    grpInternal.setLayout(new GridLayout(3, false));
    grpInternal.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label label = new Label(grpInternal, SWT.NONE);
    // $NON-NLS-1$
    label.setText("Manufacturer:");
    comboManufacturerSelect = new Combo(grpInternal, SWT.BORDER | SWT.READ_ONLY);
    comboManufacturerSelect.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(grpInternal, SWT.NONE);
    providerIds = devicePeriperalsProviderInterface.getProviderIDs();
    for (String pd : providerIds) {
        comboManufacturerSelect.add(devicePeriperalsProviderInterface.getProviderName(pd));
    }
    comboManufacturerSelect.select(0);
    comboManufacturerSelect.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            manufacturerChanged();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    label = new Label(grpInternal, SWT.NONE);
    // $NON-NLS-1$
    label.setText("Target Device:");
    comboDeviceName = new Combo(grpInternal, SWT.BORDER | SWT.READ_ONLY);
    comboDeviceName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    populateDeviceList();
    comboDeviceName.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            // Selected device has changed
            updateSvdId();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    btnDeviceSelect = new Button(grpInternal, SWT.NONE);
    btnDeviceSelect.setText("Device...");
    btnDeviceSelect.setToolTipText("Select internal USBDM\ndevice by category");
    btnDeviceSelect.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            // Open dialogue to select device
            DeviceSelector ds = new DeviceSelector(getShell(), targetType, comboDeviceName.getText());
            if (ds.open() == Window.OK) {
                // Map device name to SVD file name
                String message = null;
                try {
                    IPeripheralDescriptionProvider provider = devicePeriperalsProviderInterface.getProvider(UsbdmPeripheralDescriptionProvider.ID);
                    String mappedName = provider.getMappedDeviceName(ds.getText());
                    if (mappedName == null) {
                        message = "Cannot locate SVD file for device";
                    } else {
                        // System.err.println("Mapped name = " + mappedName);
                        int providerIndex = providerIds.indexOf(UsbdmPeripheralDescriptionProvider.ID);
                        if (providerIndex < 0) {
                            providerIndex = 0;
                        }
                        comboManufacturerSelect.select(providerIndex);
                        populateDeviceList();
                        comboDeviceName.setText(mappedName);
                        updateSvdId();
                    }
                } catch (Exception e) {
                    message = "Cannot locate SVD for device\nReason " + e.getMessage();
                }
                if (message != null) {
                    MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_ERROR | SWT.CANCEL);
                    messageBox.setText("Error");
                    messageBox.setMessage(message);
                    messageBox.open();
                }
            }
            validate();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    chkUseExternalSVDFile = new Button(container, SWT.CHECK);
    chkUseExternalSVDFile.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    chkUseExternalSVDFile.setText("Use external SVD file");
    chkUseExternalSVDFile.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            updateSvdId();
        }
    });
    /*
       * Create External group
       */
    grpExternal = new Group(container, SWT.NONE);
    grpExternal.setText("External SVD File");
    grpExternal.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    grpExternal.setLayout(new GridLayout(3, false));
    label = new Label(grpExternal, SWT.NONE);
    // $NON-NLS-1$
    label.setText("External File:");
    txtFilePath = new Text(grpExternal, SWT.BORDER | SWT.READ_ONLY);
    txtFilePath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    btnFileBrowse = new Button(grpExternal, SWT.PUSH);
    btnFileBrowse.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    btnFileBrowse.setText("Browse...");
    btnFileBrowse.setToolTipText("Select external file...");
    btnFileBrowse.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final String[] filterExts = { "*.svd;*.xml" };
            FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
            fd.setText("Locate SVD file describing device");
            fd.setFilterPath(txtFilePath.getText());
            fd.setFilterExtensions(filterExts);
            String directoryPath = fd.open();
            if (directoryPath != null) {
                txtFilePath.setText(directoryPath);
                updateSvdId();
            }
        }
    });
    setSvdIdentifier(fSvdIdentifier);
    return container;
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) DeviceSelector(net.sourceforge.usbdm.deviceDatabase.ui.DeviceSelector) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) MessageBox(org.eclipse.swt.widgets.MessageBox) IPeripheralDescriptionProvider(net.sourceforge.usbdm.peripheralDatabase.IPeripheralDescriptionProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileDialog(org.eclipse.swt.widgets.FileDialog) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 2 with DeviceSelector

use of net.sourceforge.usbdm.deviceDatabase.ui.DeviceSelector in project usbdm-eclipse-plugins by podonoghue.

the class LaunchParameterUtilities method createLaunchConfig.

/**
 * Creates a launch configuration as a physical file<br>
 * It attempts to deduce the device name from project files and asks the user to select/confirm the device choice.
 *
 * @param shell   Shell for dialogues
 * @param project Project to create launch configuration within
 * @param bin Path to binary
 * @param build   String describing build e.g. debug or release. Used in naming launch configuration
 *
 * @return A launch configuration
 * @throws Exception
 */
public static ILaunchConfiguration createLaunchConfig(final Shell shell, final IProject project, IBinary bin) throws Exception {
    IPath binPath = bin.getResource().getProjectRelativePath();
    String buildName = "Default";
    if (binPath.segmentCount() >= 2) {
        // Use containing folder as build name
        buildName = binPath.segment(binPath.segmentCount() - 2);
    }
    // Directories to create launch configuration in (order of preference)
    String[] folders = { "Project_Settings/Debugger", "Project_Settings" };
    IContainer folder = null;
    for (String trialFolder : folders) {
        IFolder t = project.getFolder(trialFolder);
        if (t.exists()) {
            folder = t;
            break;
        }
    }
    if (folder == null) {
        // System.err.println("'Project_Settings folder' doesn't exist, creating launch config in root directory");
        folder = project;
    }
    // Create launch file name e.g. project_debug_USBDM.launch
    IFile launchFile = folder.getFile(new Path(project.getName() + "_" + buildName + "_USBDM.launch"));
    if (launchFile.exists()) {
        // System.err.println("File " + launchFile + " already exists");
        throw new Exception("Launch configuration \n\"" + launchFile.getName() + "\"\nalready exists");
    }
    // Try to get device name from existing project files
    String deviceName = scrapeDeviceName(project);
    // Ask user to select/confirm device
    DeviceSelector deviceSelector = new DeviceSelector(shell, TargetType.T_ARM, deviceName);
    int rc = deviceSelector.open();
    if (rc != Window.OK) {
        return null;
    }
    Device device = deviceSelector.getDevice();
    // Map used to hold variable for launch file creation
    Map<String, String> variableMap = new HashMap<String, String>();
    // Add device name to project creation map
    variableMap.put(UsbdmConstants.PROJECT_NAME_KEY, project.getName());
    // Add launch parameters from device information
    LaunchParameterUtilities.addLaunchParameters(variableMap, device, binPath);
    // Create launch file and let the system know about it
    InputStream contents = getLaunchFile(variableMap);
    launchFile.create(contents, true, null);
    launchFile.refreshLocal(IResource.DEPTH_ONE, null);
    project.refreshLocal(IResource.DEPTH_INFINITE, null);
    // Return the launch configuration
    return DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(launchFile);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) DeviceSelector(net.sourceforge.usbdm.deviceDatabase.ui.DeviceSelector) HashMap(java.util.HashMap) Device(net.sourceforge.usbdm.deviceDatabase.Device) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) CModelException(org.eclipse.cdt.core.model.CModelException) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with DeviceSelector

use of net.sourceforge.usbdm.deviceDatabase.ui.DeviceSelector in project usbdm-eclipse-plugins by podonoghue.

the class UsbdmDebuggerPanel method createUsbdmParametersGroup.

/**
 * Create USBDM Parameters selection Group
 *
 * @param parent Parent of group
 */
protected void createUsbdmParametersGroup(Composite parent) {
    // System.err.println("createUsbdmControl()");
    Group group = new Group(parent, SWT.NONE);
    group.setText("USBDM Parameters");
    group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    RowLayout layout = new RowLayout();
    layout.center = true;
    layout.spacing = 10;
    layout.wrap = false;
    group.setLayout(layout);
    // 
    // Create Combo for interface
    // 
    Label label = new Label(group, SWT.NONE);
    // $NON-NLS-1$
    label.setText("Interface:");
    fComboInterfaceType = new Combo(group, SWT.BORDER | SWT.READ_ONLY);
    fInterfaceTypes = new InterfaceType[InterfaceType.values().length];
    fComboInterfaceType.select(0);
    // 
    // Create Device selection group
    // 
    label = new Label(group, SWT.NONE);
    label.setText("Target Device:");
    fTextTargetDeviceName = new Text(group, SWT.BORDER | SWT.READ_ONLY | SWT.CENTER);
    fTextTargetDeviceName.setLayoutData(new RowData(200, SWT.DEFAULT));
    fButtonTargetDeviceSelect = new Button(group, SWT.NONE);
    fButtonTargetDeviceSelect.setText("Device...");
    fButtonTargetDeviceSelect.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            InterfaceType interfaceType = getInterfaceType();
            DeviceSelector ds = new DeviceSelector(getShell(), interfaceType.targetType, fTextTargetDeviceName.getText());
            if (ds.open() == Window.OK) {
                fTextTargetDeviceName.setText(ds.getText());
                Device device = ds.getDevice();
                if (device != null) {
                    fSuspendUpdate++;
                    fClockType = device.getClockType();
                    fGdbServerParameters.setClockTrimFrequency(device.getDefaultClockTrimFreq());
                    fGdbServerParameters.setNvmClockTrimLocation(device.getDefaultClockTrimNVAddress());
                    populateTrim();
                    fSuspendUpdate--;
                    doUpdate();
                }
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) DeviceSelector(net.sourceforge.usbdm.deviceDatabase.ui.DeviceSelector) Device(net.sourceforge.usbdm.deviceDatabase.Device) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) RowData(org.eclipse.swt.layout.RowData) InterfaceType(net.sourceforge.usbdm.constants.UsbdmSharedConstants.InterfaceType) Button(org.eclipse.swt.widgets.Button) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

DeviceSelector (net.sourceforge.usbdm.deviceDatabase.ui.DeviceSelector)3 Device (net.sourceforge.usbdm.deviceDatabase.Device)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 GridData (org.eclipse.swt.layout.GridData)2 Button (org.eclipse.swt.widgets.Button)2 Combo (org.eclipse.swt.widgets.Combo)2 Group (org.eclipse.swt.widgets.Group)2 Label (org.eclipse.swt.widgets.Label)2 Text (org.eclipse.swt.widgets.Text)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 InterfaceType (net.sourceforge.usbdm.constants.UsbdmSharedConstants.InterfaceType)1 IPeripheralDescriptionProvider (net.sourceforge.usbdm.peripheralDatabase.IPeripheralDescriptionProvider)1 CModelException (org.eclipse.cdt.core.model.CModelException)1 IContainer (org.eclipse.core.resources.IContainer)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1