Skip to content

Commit 3d958dc

Browse files
committed
tranformed to 150 line width
1 parent 0563654 commit 3d958dc

File tree

6 files changed

+409
-466
lines changed

6 files changed

+409
-466
lines changed

it.baeyens.arduino.common/src/it/baeyens/arduino/arduino/Serial.java

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ public Serial(String iname, int irate) {
8484
this(iname, irate, 'N', 8, 1.0f);
8585
}
8686

87-
public Serial(String iname, int irate, char iparity, int idatabits,
88-
float istopbits) {
87+
public Serial(String iname, int irate, char iparity, int idatabits, float istopbits) {
8988
PortName = iname;
9089
this.rate = irate;
9190

@@ -107,57 +106,40 @@ public Serial(String iname, int irate, char iparity, int idatabits,
107106
}
108107

109108
private void registerService() {
110-
fServiceRegistration = FrameworkUtil.getBundle(getClass())
111-
.getBundleContext().registerService(Serial.class, this, null);
109+
fServiceRegistration = FrameworkUtil.getBundle(getClass()).getBundleContext().registerService(Serial.class, this, null);
112110
}
113111

114112
public void connect() {
115113
if (port == null) {
116114
try {
117-
CommPortEnumerator portList = CommPortIdentifier
118-
.getPortIdentifiers();
115+
CommPortEnumerator portList = CommPortIdentifier.getPortIdentifiers();
119116
while (portList.hasMoreElements()) {
120-
CommPortIdentifier portId = (CommPortIdentifier) portList
121-
.nextElement();
117+
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
122118

123119
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
124120
if (portId.getName().equals(PortName)) {
125-
port = (SerialPort) portId.open("serial madness",
126-
2000);
121+
port = (SerialPort) portId.open("serial madness", 2000);
127122
input = port.getInputStream();
128123
output = port.getOutputStream();
129-
port.setSerialPortParams(rate, databits, stopbits,
130-
parity);
124+
port.setSerialPortParams(rate, databits, stopbits, parity);
131125
port.addEventListener(this);
132126
port.notifyOnDataAvailable(true);
133127
}
134128
}
135129
}
136130
} catch (PortInUseException e) {
137-
Common.log(new Status(
138-
IStatus.ERROR,
139-
ArduinoConst.CORE_PLUGIN_ID,
140-
"Serial port "
141-
+ PortName
142-
+ " already in use. Try quiting any programs that may be using it",
143-
e));
131+
Common.log(new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID, "Serial port " + PortName
132+
+ " already in use. Try quiting any programs that may be using it", e));
144133
return;
145134
} catch (Exception e) {
146-
Common.log(new Status(IStatus.ERROR,
147-
ArduinoConst.CORE_PLUGIN_ID,
148-
"Error opening serial port " + PortName, e));
135+
Common.log(new Status(IStatus.ERROR, ArduinoConst.CORE_PLUGIN_ID, "Error opening serial port " + PortName, e));
149136
return;
150137
}
151138

152139
if (port == null) {
153140
// jaba 28 feb 2012. I made the log below a warning for issue #7
154-
Common.log(new Status(
155-
IStatus.WARNING,
156-
ArduinoConst.CORE_PLUGIN_ID,
157-
"Serial port "
158-
+ PortName
159-
+ " not found. Did you select the right one from the project properties -> Arduino -> Arduino?",
160-
null));
141+
Common.log(new Status(IStatus.WARNING, ArduinoConst.CORE_PLUGIN_ID, "Serial port " + PortName
142+
+ " not found. Did you select the right one from the project properties -> Arduino -> Arduino?", null));
161143
return;
162144
}
163145
}
@@ -392,11 +374,8 @@ public int readBytesUntil(int interesting, byte outgoing[]) {
392374

393375
int length = found - bufferIndex + 1;
394376
if (length > outgoing.length) {
395-
Common.log(new Status(IStatus.WARNING,
396-
ArduinoConst.CORE_PLUGIN_ID,
397-
"readBytesUntil() byte buffer is too small for the "
398-
+ length + " bytes up to and including char "
399-
+ interesting, null));
377+
Common.log(new Status(IStatus.WARNING, ArduinoConst.CORE_PLUGIN_ID, "readBytesUntil() byte buffer is too small for the " + length
378+
+ " bytes up to and including char " + interesting, null));
400379
return -1;
401380
}
402381
// byte outgoing[] = new byte[length];
@@ -479,8 +458,7 @@ public void write(String what) {
479458
}
480459

481460
public void write(String what, String LineEnd) {
482-
notifyConsumers(System.getProperty("line.separator") + ">>Send to "
483-
+ PortName + ": \"" + what + "\"<<"
461+
notifyConsumers(System.getProperty("line.separator") + ">>Send to " + PortName + ": \"" + what + "\"<<"
484462
+ System.getProperty("line.separator"));
485463
write(what.getBytes());
486464
if (LineEnd.length() > 0) {
@@ -504,11 +482,9 @@ public void setRTS(boolean state) {
504482
static public Vector<String> list() {
505483
Vector<String> list = new Vector<String>();
506484
try {
507-
CommPortEnumerator portList = CommPortIdentifier
508-
.getPortIdentifiers();
485+
CommPortEnumerator portList = CommPortIdentifier.getPortIdentifiers();
509486
while (portList.hasMoreElements()) {
510-
CommPortIdentifier portId = (CommPortIdentifier) portList
511-
.nextElement();
487+
CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
512488

513489
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
514490
String name = portId.getName();
@@ -533,8 +509,7 @@ static public Vector<String> list() {
533509
* something slightly more intelligent to do.
534510
*/
535511
static public void errorMessage(String where, Throwable e) {
536-
Common.log(new Status(IStatus.WARNING, ArduinoConst.CORE_PLUGIN_ID,
537-
"Error inside Serial. " + where, e));
512+
Common.log(new Status(IStatus.WARNING, ArduinoConst.CORE_PLUGIN_ID, "Error inside Serial. " + where, e));
538513

539514
}
540515

it.baeyens.arduino.core/src/it/baeyens/arduino/actions/OpenScopeHandler.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@
77
import org.eclipse.ui.PlatformUI;
88

99
/**
10-
* This is a handler to connect the plugin.xml to the code for opening the serial monitor
10+
* This is a handler to connect the plugin.xml to the code for opening the
11+
* serial monitor
1112
*
1213
* @author jan
1314
*
1415
*/
1516
public class OpenScopeHandler extends AbstractHandler {
1617

17-
@Override
18-
public Object execute(ExecutionEvent event) throws ExecutionException {
19-
try {
20-
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("it.baeyens.arduino.monitor.views.ScopeView");
21-
} catch (PartInitException e) {
22-
e.printStackTrace();
18+
@Override
19+
public Object execute(ExecutionEvent event) throws ExecutionException {
20+
try {
21+
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("it.baeyens.arduino.monitor.views.ScopeView");
22+
} catch (PartInitException e) {
23+
e.printStackTrace();
24+
}
25+
return null;
2326
}
24-
return null;
25-
}
2627

2728
}

it.baeyens.arduino.monitor/src/it/baeyens/arduino/monitor/views/ScopeListener.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ public class ScopeListener implements MessageConsumer {
1313
private OscilloscopeDispatcher dispatcher;
1414
private Integer fDelayLoop = 10;
1515
private boolean fTailFade = false;
16-
private Pattern fCommandPattern = Pattern
17-
.compile(".*?\\\"(setscope\\s.*?)\\\".*");
16+
private Pattern fCommandPattern = Pattern.compile(".*?\\\"(setscope\\s.*?)\\\".*");
1817

1918
public ScopeListener(Oscilloscope oscilloscope) {
2019
dispatcher = new OscilloscopeDispatcher(0, oscilloscope) {
@@ -49,8 +48,7 @@ public void message(String s) {
4948
}
5049
}
5150
value = Integer.valueOf(builder.toString());
52-
dispatcher.getOscilloscope().setValue(dispatcher.getChannel(),
53-
value);
51+
dispatcher.getOscilloscope().setValue(dispatcher.getChannel(), value);
5452
} catch (Exception e) {
5553
System.out.println("Invalid value " + s);
5654
}
@@ -59,7 +57,7 @@ public void message(String s) {
5957
private void setCommand(String s) {
6058

6159
String command = null;
62-
s= s.replaceAll("\r\n", "");
60+
s = s.replaceAll("\r\n", "");
6361
Matcher matcher = fCommandPattern.matcher(s);
6462
if (matcher.matches()) {
6563
command = matcher.group(1);
@@ -70,8 +68,7 @@ private void setCommand(String s) {
7068
}
7169

7270
if (command.startsWith("setscope delayLoop ")) {
73-
fDelayLoop = Integer.valueOf(command
74-
.replaceAll("setscope delayLoop ", ""));
71+
fDelayLoop = Integer.valueOf(command.replaceAll("setscope delayLoop ", ""));
7572
}
7673

7774
if (command.startsWith("setscope toggleTailFade")) {

it.baeyens.arduino.monitor/src/it/baeyens/arduino/monitor/views/ScopeView.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,12 @@ public ScopeView() {
2626
public void createPartControl(Composite parent) {
2727
parent.setLayout(new GridLayout(1, false));
2828
oscilloscope = new Oscilloscope(parent, SWT.NONE);
29-
oscilloscope.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true,
30-
1, 1));
29+
oscilloscope.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
3130
registerSerialTracker();
3231
}
3332

3433
private void registerSerialTracker() {
35-
FrameworkUtil.getBundle(getClass()).getBundleContext()
36-
.addServiceListener(this);
34+
FrameworkUtil.getBundle(getClass()).getBundleContext().addServiceListener(this);
3735
}
3836

3937
@Override
@@ -52,8 +50,7 @@ public void serviceChanged(ServiceEvent event) {
5250

5351
private void unregisterSerialService(ServiceEvent event) {
5452
final ServiceReference<?> reference = event.getServiceReference();
55-
final Object service = FrameworkUtil.getBundle(getClass())
56-
.getBundleContext().getService(reference);
53+
final Object service = FrameworkUtil.getBundle(getClass()).getBundleContext().getService(reference);
5754
if (service instanceof Serial) {
5855
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
5956
@Override
@@ -66,8 +63,7 @@ public void run() {
6663

6764
private void registerSerialService(ServiceEvent event) {
6865
final ServiceReference<?> reference = event.getServiceReference();
69-
final Object service = FrameworkUtil.getBundle(getClass())
70-
.getBundleContext().getService(reference);
66+
final Object service = FrameworkUtil.getBundle(getClass()).getBundleContext().getService(reference);
7167
if (service instanceof Serial) {
7268
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
7369
@Override

it.baeyens.arduino.monitor/src/it/baeyens/arduino/monitor/views/SerialListener.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,29 @@
55
import org.eclipse.swt.widgets.Display;
66

77
public class SerialListener implements MessageConsumer {
8-
SerialMonitor TheMonitor;
9-
int theColorIndex;
10-
11-
SerialListener(SerialMonitor Monitor, int ColorIndex) {
12-
TheMonitor = Monitor;
13-
theColorIndex = ColorIndex;
14-
}
15-
16-
@Override
17-
public void message(String info) {
18-
19-
final String TempString = info;
20-
Display.getDefault().asyncExec(new Runnable() {
21-
@Override
22-
public void run() {
23-
try {
24-
TheMonitor.ReportSerialActivity(TempString, theColorIndex);
25-
} catch (Exception e) {// ignore as we get errors when closing
26-
// down
27-
}
28-
}
29-
});
30-
31-
}
8+
SerialMonitor TheMonitor;
9+
int theColorIndex;
10+
11+
SerialListener(SerialMonitor Monitor, int ColorIndex) {
12+
TheMonitor = Monitor;
13+
theColorIndex = ColorIndex;
14+
}
15+
16+
@Override
17+
public void message(String info) {
18+
19+
final String TempString = info;
20+
Display.getDefault().asyncExec(new Runnable() {
21+
@Override
22+
public void run() {
23+
try {
24+
TheMonitor.ReportSerialActivity(TempString, theColorIndex);
25+
} catch (Exception e) {// ignore as we get errors when closing
26+
// down
27+
}
28+
}
29+
});
30+
31+
}
3232

3333
}

0 commit comments

Comments
 (0)