35
35
import processing .app .PreferencesData ;
36
36
import processing .app .Editor ;
37
37
import processing .app .Base ;
38
+ import processing .app .BaseNoGui ;
38
39
import processing .app .Platform ;
39
40
import processing .app .Sketch ;
40
41
import processing .app .tools .Tool ;
@@ -57,7 +58,7 @@ public void init(Editor editor) {
57
58
public String getMenuTitle () {
58
59
return "ESP8266 Sketch Data Upload" ;
59
60
}
60
-
61
+
61
62
private int listenOnProcess (String [] arguments ){
62
63
try {
63
64
final Process p = ProcessUtils .exec (arguments );
@@ -79,7 +80,7 @@ public void run() {
79
80
return -1 ;
80
81
}
81
82
}
82
-
83
+
83
84
private void sysExec (final String [] arguments ){
84
85
Thread thread = new Thread () {
85
86
public void run () {
@@ -96,25 +97,25 @@ public void run() {
96
97
};
97
98
thread .start ();
98
99
}
99
-
100
-
100
+
101
+
101
102
private long getIntPref (String name ){
102
- String data = Base .getBoardPreferences ().get (name );
103
+ String data = BaseNoGui .getBoardPreferences ().get (name );
103
104
if (data == null || data .contentEquals ("" )) return 0 ;
104
105
if (data .startsWith ("0x" )) return Long .parseLong (data .substring (2 ), 16 );
105
106
else return Integer .parseInt (data );
106
107
}
107
-
108
+
108
109
private void createAndUpload (){
109
110
if (!PreferencesData .get ("target_platform" ).contentEquals ("esp8266" )){
110
111
System .err .println ();
111
112
editor .statusError ("SPIFFS Not Supported on " +PreferencesData .get ("target_platform" ));
112
113
return ;
113
114
}
114
-
115
- if (!Base .getBoardPreferences ().containsKey ("build.spiffs_start" ) || !Base .getBoardPreferences ().containsKey ("build.spiffs_end" )){
115
+
116
+ if (!BaseNoGui .getBoardPreferences ().containsKey ("build.spiffs_start" ) || !BaseNoGui .getBoardPreferences ().containsKey ("build.spiffs_end" )){
116
117
System .err .println ();
117
- editor .statusError ("SPIFFS Not Defined for " +Base .getBoardPreferences ().get ("name" ));
118
+ editor .statusError ("SPIFFS Not Defined for " +BaseNoGui .getBoardPreferences ().get ("name" ));
118
119
return ;
119
120
}
120
121
long spiStart , spiEnd , spiPage , spiBlock ;
@@ -129,9 +130,9 @@ private void createAndUpload(){
129
130
editor .statusError (e );
130
131
return ;
131
132
}
132
-
133
- TargetPlatform platform = Base .getTargetPlatform ();
134
-
133
+
134
+ TargetPlatform platform = BaseNoGui .getTargetPlatform ();
135
+
135
136
File esptool ;
136
137
if (!PreferencesData .get ("runtime.os" ).contentEquals ("windows" )) esptool = new File (platform .getFolder ()+"/tools" , "esptool" );
137
138
else esptool = new File (platform .getFolder ()+"/tools" , "esptool.exe" );
@@ -140,7 +141,7 @@ private void createAndUpload(){
140
141
editor .statusError ("SPIFFS Error: esptool not found!" );
141
142
return ;
142
143
}
143
-
144
+
144
145
File tool ;
145
146
if (!PreferencesData .get ("runtime.os" ).contentEquals ("windows" )) tool = new File (platform .getFolder ()+"/tools" , "mkspiffs" );
146
147
else tool = new File (platform .getFolder ()+"/tools" , "mkspiffs.exe" );
@@ -160,34 +161,34 @@ private void createAndUpload(){
160
161
}
161
162
}
162
163
}
163
-
164
+
164
165
String dataPath = dataFolder .getAbsolutePath ();
165
166
String toolPath = tool .getAbsolutePath ();
166
167
String esptoolPath = esptool .getAbsolutePath ();
167
168
String sketchName = editor .getSketch ().getName ();
168
- String buildPath = Base .getBuildFolder ().getAbsolutePath ();
169
+ String buildPath = BaseNoGui .getBuildFolder ().getAbsolutePath ();
169
170
String imagePath = buildPath +"/" +sketchName +".spiffs.bin" ;
170
171
String serialPort = PreferencesData .get ("serial.port" );
171
- String resetMethod = Base .getBoardPreferences ().get ("upload.resetmethod" );
172
- String uploadSpeed = Base .getBoardPreferences ().get ("upload.speed" );
173
- String uploadAddress = Base .getBoardPreferences ().get ("build.spiffs_start" );
174
-
172
+ String resetMethod = BaseNoGui .getBoardPreferences ().get ("upload.resetmethod" );
173
+ String uploadSpeed = BaseNoGui .getBoardPreferences ().get ("upload.speed" );
174
+ String uploadAddress = BaseNoGui .getBoardPreferences ().get ("build.spiffs_start" );
175
+
175
176
Object [] options = { "Yes" , "No" };
176
177
String title = "SPIFFS Create" ;
177
178
String message = "No files have been found in your data folder!\n Are you sure you want to create an empty SPIFFS image?" ;
178
-
179
+
179
180
if (fileCount == 0 && JOptionPane .showOptionDialog (editor , message , title , JOptionPane .YES_NO_OPTION , JOptionPane .QUESTION_MESSAGE , null , options , options [1 ]) != JOptionPane .YES_OPTION ){
180
181
System .err .println ();
181
182
editor .statusError ("SPIFFS Warning: mkspiffs canceled!" );
182
183
return ;
183
184
}
184
-
185
+
185
186
editor .statusNotice ("SPIFFS Creating Image..." );
186
187
System .out .println ("[SPIFFS] data : " +dataPath );
187
188
System .out .println ("[SPIFFS] size : " +((spiEnd - spiStart )/1024 ));
188
189
System .out .println ("[SPIFFS] page : " +spiPage );
189
190
System .out .println ("[SPIFFS] block : " +spiBlock );
190
-
191
+
191
192
try {
192
193
if (listenOnProcess (new String []{toolPath , "-c" , dataPath , "-p" , spiPage +"" , "-b" , spiBlock +"" , "-s" , (spiEnd - spiStart )+"" , imagePath }) != 0 ){
193
194
System .err .println ();
@@ -199,18 +200,18 @@ private void createAndUpload(){
199
200
editor .statusError ("SPIFFS Create Failed!" );
200
201
return ;
201
202
}
202
-
203
+
203
204
editor .statusNotice ("SPIFFS Uploading Image..." );
204
205
System .out .println ("[SPIFFS] upload : " +imagePath );
205
206
System .out .println ("[SPIFFS] reset : " +resetMethod );
206
207
System .out .println ("[SPIFFS] port : " +serialPort );
207
208
System .out .println ("[SPIFFS] speed : " +uploadSpeed );
208
209
System .out .println ("[SPIFFS] address: " +uploadAddress );
209
210
System .out .println ();
210
-
211
+
211
212
sysExec (new String []{esptoolPath , "-cd" , resetMethod , "-cb" , uploadSpeed , "-cp" , serialPort , "-ca" , uploadAddress , "-cf" , imagePath });
212
213
}
213
-
214
+
214
215
public void run () {
215
216
createAndUpload ();
216
217
}
0 commit comments