Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Changed Serial to accept multiple MessageConsumers
Added the Nebula Oscilloscope jar to lib folder
Added a Scope View
Added a ScopeListener to handle the OscilloScope
Connected the Scope View to the Serial
Added "Open Scope" to the toolbar with icon
Changed the Serial Monitor view icon
Added scope control commands to the serial monitor view
   Added the "setscope toggleTailFade" serial command
   Added the "setscope delayLoop nnn" serial command
  • Loading branch information
wimjongman committed Oct 20, 2013
commit 056365445dbc2cfb15a08b86112d0da726e80ea3
890 changes: 477 additions & 413 deletions it.baeyens.arduino.common/src/it/baeyens/arduino/arduino/Serial.java

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions it.baeyens.arduino.core/OSGI-INF/l10n/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ tool.announcement.5 = Printing size:
tool.name.5 = Arduino tool Print Size
content-type.name = HEX Dump for EEPROM
content-type.name.0 = HEX Dump for Flash ROM
command.label.4 = Open the Oscilloscope
Binary file added it.baeyens.arduino.core/icons/scope.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions it.baeyens.arduino.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@
description="%command.description.3"
id="it.baeyens.arduino.actions.AddLibraryAction"
name="%command.name.3">
</command>
<command
categoryId="it.baeyens.arduino.commands"
defaultHandler="it.baeyens.arduino.actions.OpenScopeHandler"
description="%command.description.2"
id="it.baeyens.arduino.actions.OpenScopeAction"
name="%command.name.2">
</command>
</extension>

Expand Down Expand Up @@ -286,6 +293,12 @@
label="%command.label.2"
style="push">
</command>
<command
commandId="it.baeyens.arduino.actions.OpenScopeAction"
icon="icons/scope.png"
label="%command.label.4"
style="push">
</command>
</toolbar>
</menuContribution>
<menuContribution locationURI="menu:org.eclipse.ui.main.menu??after=Run">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package it.baeyens.arduino.actions;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

/**
* This is a handler to connect the plugin.xml to the code for opening the serial monitor
*
* @author jan
*
*/
public class OpenScopeHandler extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
try {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("it.baeyens.arduino.monitor.views.ScopeView");
} catch (PartInitException e) {
e.printStackTrace();
}
return null;
}

}
1 change: 1 addition & 0 deletions it.baeyens.arduino.monitor/.classpath
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry exported="true" kind="lib" path="lib/org.eclipse.nebula.widgets.oscilloscope_1.2.0.201310192144.jar" sourcepath="/org.eclipse.nebula.widgets.oscilloscope"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
Expand Down
2 changes: 2 additions & 0 deletions it.baeyens.arduino.monitor/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ Export-Package: it.baeyens.arduino.monitor;uses:="org.eclipse.jface.resource,org
org.eclipse.swt.widgets,
it.baeyens.arduino.common,
org.eclipse.jface.dialogs"
Bundle-ClassPath: .,
lib/org.eclipse.nebula.widgets.oscilloscope_1.2.0.201310192144.jar
3 changes: 2 additions & 1 deletion it.baeyens.arduino.monitor/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ bin.includes = META-INF/,\
.,\
icons/,\
contexts.xml,\
plugin.xml
plugin.xml,\
lib/org.eclipse.nebula.widgets.oscilloscope_1.2.0.201310192144.jar
src.includes = icons/,\
contexts.xml
Binary file added it.baeyens.arduino.monitor/icons/Oscilloscope.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added it.baeyens.arduino.monitor/icons/arduino.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
17 changes: 15 additions & 2 deletions it.baeyens.arduino.monitor/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,25 @@
<view id="it.baeyens.arduino.monitor.views.SerialMonitor"
category="it.baeyens.arduino.monitor"
class="it.baeyens.arduino.monitor.views.SerialMonitor"
icon="icons/sample.gif"
icon="icons/arduino.png"
name="Serial monitor view">
</view>
<view
category="it.baeyens.arduino.monitor"
class="it.baeyens.arduino.monitor.views.ScopeView"
icon="icons/Oscilloscope.png"
id="it.baeyens.arduino.monitor.views.ScopeView"
name="Scope"
restorable="true">
</view>

</extension>
<extension
point="it.baeyens.arduino.monitor">
point="org.eclipse.ui.perspectives">
<perspective
class="it.baeyens.arduino.monitor.PerspectiveFactory1"
id="it.baeyens.arduino.monitor.perspective1"
name="name">
</perspective>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package it.baeyens.arduino.monitor.views;

import it.baeyens.arduino.arduino.MessageConsumer;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.nebula.widgets.oscilloscope.multichannel.Oscilloscope;
import org.eclipse.nebula.widgets.oscilloscope.multichannel.OscilloscopeDispatcher;

public class ScopeListener implements MessageConsumer {

private OscilloscopeDispatcher dispatcher;
private Integer fDelayLoop = 10;
private boolean fTailFade = false;
private Pattern fCommandPattern = Pattern
.compile(".*?\\\"(setscope\\s.*?)\\\".*");

public ScopeListener(Oscilloscope oscilloscope) {
dispatcher = new OscilloscopeDispatcher(0, oscilloscope) {
@Override
public int getDelayLoop() {
return fDelayLoop;
}

@Override
public boolean getFade() {
return fTailFade;
}
};
dispatcher.dispatch();
}

@Override
public void message(String s) {

Integer value = null;
try {

if (s.contains(">>")) {
setCommand(s);
return;
}

StringBuilder builder = new StringBuilder();
for (Character c : s.toCharArray()) {
if ((c >= '0' && c <= '9') || c == '-') {
builder.append(c);
}
}
value = Integer.valueOf(builder.toString());
dispatcher.getOscilloscope().setValue(dispatcher.getChannel(),
value);
} catch (Exception e) {
System.out.println("Invalid value " + s);
}
}

private void setCommand(String s) {

String command = null;
s= s.replaceAll("\r\n", "");
Matcher matcher = fCommandPattern.matcher(s);
if (matcher.matches()) {
command = matcher.group(1);
}

if (command == null) {
return;
}

if (command.startsWith("setscope delayLoop ")) {
fDelayLoop = Integer.valueOf(command
.replaceAll("setscope delayLoop ", ""));
}

if (command.startsWith("setscope toggleTailFade")) {
fTailFade = !fTailFade;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package it.baeyens.arduino.monitor.views;

import it.baeyens.arduino.arduino.Serial;

import org.eclipse.nebula.widgets.oscilloscope.multichannel.Oscilloscope;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;

public class ScopeView extends ViewPart implements ServiceListener {

private Oscilloscope oscilloscope;

public ScopeView() {
// TODO Auto-generated constructor stub
}

@Override
public void createPartControl(Composite parent) {
parent.setLayout(new GridLayout(1, false));
oscilloscope = new Oscilloscope(parent, SWT.NONE);
oscilloscope.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true,
1, 1));
registerSerialTracker();
}

private void registerSerialTracker() {
FrameworkUtil.getBundle(getClass()).getBundleContext()
.addServiceListener(this);
}

@Override
public void setFocus() {
oscilloscope.setFocus();
}

@Override
public void serviceChanged(ServiceEvent event) {
if (event.getType() == ServiceEvent.REGISTERED) {
registerSerialService(event);
} else if (event.getType() == ServiceEvent.UNREGISTERING) {
unregisterSerialService(event);
}
}

private void unregisterSerialService(ServiceEvent event) {
final ServiceReference<?> reference = event.getServiceReference();
final Object service = FrameworkUtil.getBundle(getClass())
.getBundleContext().getService(reference);
if (service instanceof Serial) {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
oscilloscope.getDispatcher(0).stop();
}
});
}
}

private void registerSerialService(ServiceEvent event) {
final ServiceReference<?> reference = event.getServiceReference();
final Object service = FrameworkUtil.getBundle(getClass())
.getBundleContext().getService(reference);
if (service instanceof Serial) {
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
Serial serial = (Serial) service;
serial.addListener(new ScopeListener(oscilloscope));
}
});
}
}
}