21
21
import org .eclipse .ui .PartInitException ;
22
22
import org .eclipse .ui .PlatformUI ;
23
23
24
+ import it .baeyens .arduino .common .Common ;
24
25
import it .baeyens .arduino .common .Const ;
25
26
import it .baeyens .arduino .common .InstancePreferences ;
26
- import it .baeyens .arduino .common .Common ;
27
27
import it .baeyens .arduino .listeners .ProjectExplorerListener ;
28
28
29
29
/**
30
- * This is a handler to connect the plugin.xml to the code for opening the
31
- * serial monitor
30
+ * This is a handler to connect the plugin.xml to the code for opening the serial monitor
32
31
*
33
32
*
34
- * The code looks for all selected projects for the com port and the baudrate
35
- * and connects if they both are found
33
+ * The code looks for all selected projects for the com port and the baudrate and connects if they both are found
36
34
*
37
35
* @author jan
38
36
*
@@ -43,8 +41,7 @@ public class OpenSerialMonitorHandler extends AbstractHandler {
43
41
public Object execute (ExecutionEvent event ) throws ExecutionException {
44
42
try {
45
43
46
- PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getActivePage ()
47
- .showView ("it.baeyens.arduino.monitor.views.SerialMonitor" ); //$NON-NLS-1$
44
+ PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getActivePage ().showView ("it.baeyens.arduino.monitor.views.SerialMonitor" ); //$NON-NLS-1$
48
45
// find all projects
49
46
IProject SelectedProjects [] = ProjectExplorerListener .getSelectedProjects ();
50
47
// if there are project selected and the autoConnectScope feature is
@@ -53,8 +50,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
53
50
for (IProject curproject : SelectedProjects ) {
54
51
int baud = getBaudRate (curproject );
55
52
if (baud > 0 ) {
56
- String comPort = Common .getBuildEnvironmentVariable (curproject ,
57
- Const .ENV_KEY_JANTJE_COM_PORT , "" );
53
+ String comPort = Common .getBuildEnvironmentVariable (curproject , Const .ENV_KEY_JANTJE_COM_PORT , Const .EMPTY_STRING );
58
54
if (!comPort .isEmpty ()) {
59
55
it .baeyens .arduino .monitor .SerialConnection .add (comPort , baud );
60
56
}
@@ -68,20 +64,18 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
68
64
}
69
65
70
66
/**
71
- * given a project look in the source code for the line of code that sets
72
- * the baud rate on the board Serial.begin([baudRate]);
67
+ * given a project look in the source code for the line of code that sets the baud rate on the board Serial.begin([baudRate]);
73
68
*
74
69
*
75
70
*
76
- * return the integer value of [baudrate] or in case of error a negative
77
- * value
71
+ * return the integer value of [baudrate] or in case of error a negative value
78
72
*
79
73
* @param iProject
80
74
* @return
81
75
*/
82
- private int getBaudRate (IProject iProject ) {
83
- String setupFunctionName = "setup" ;
84
- String serialVariable = "Serial.begin" ;
76
+ private static int getBaudRate (IProject iProject ) {
77
+ String setupFunctionName = "setup" ; //$NON-NLS-1$
78
+ String serialVariable = "Serial.begin" ; //$NON-NLS-1$
85
79
86
80
ICProject curProject = CoreModel .getDefault ().getCModel ().getCProject (iProject .getName ());
87
81
@@ -90,8 +84,7 @@ private int getBaudRate(IProject iProject) {
90
84
index = CCorePlugin .getIndexManager ().getIndex (curProject );
91
85
index .acquireReadLock ();
92
86
// find bindings for name
93
- IIndexBinding [] bindings = index .findBindings (setupFunctionName .toCharArray (), IndexFilter .ALL_DECLARED ,
94
- new NullProgressMonitor ());
87
+ IIndexBinding [] bindings = index .findBindings (setupFunctionName .toCharArray (), IndexFilter .ALL_DECLARED , new NullProgressMonitor ());
95
88
ICPPFunction setupFunc = null ;
96
89
for (IIndexBinding curbinding : bindings ) {
97
90
if (curbinding instanceof ICPPFunction ) {
@@ -113,12 +106,11 @@ private int getBaudRate(IProject iProject) {
113
106
String SetupFileContent = FileUtils .readFileToString (new File (SetupFileName ));
114
107
int serialBeginStart = SetupFileContent .indexOf (serialVariable );
115
108
if (serialBeginStart != -1 ) {
116
- int serialBeginStartbraket = SetupFileContent .indexOf ("(" , serialBeginStart );
109
+ int serialBeginStartbraket = SetupFileContent .indexOf ("(" , serialBeginStart ); //$NON-NLS-1$
117
110
if (serialBeginStartbraket != -1 ) {
118
- int serialBeginCloseBraket = SetupFileContent .indexOf (")" , serialBeginStartbraket );
111
+ int serialBeginCloseBraket = SetupFileContent .indexOf (")" , serialBeginStartbraket ); //$NON-NLS-1$
119
112
if (serialBeginCloseBraket != -1 ) {
120
- String baudrate = SetupFileContent .substring (serialBeginStartbraket + 1 , serialBeginCloseBraket )
121
- .trim ();
113
+ String baudrate = SetupFileContent .substring (serialBeginStartbraket + 1 , serialBeginCloseBraket ).trim ();
122
114
return Integer .parseInt (baudrate );
123
115
}
124
116
}
0 commit comments