| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
package processing.app; |
| 24 |
|
| 25 |
import cc.arduino.packages.BoardPort; |
| 26 |
import processing.app.debug.TargetBoard; |
| 27 |
import processing.app.debug.TargetPackage; |
| 28 |
import processing.app.debug.TargetPlatform; |
| 29 |
import processing.app.legacy.PConstants; |
| 30 |
|
| 31 |
import javax.swing.*; |
| 32 |
import java.io.File; |
| 33 |
import java.io.IOException; |
| 34 |
import java.util.*; |
| 35 |
|
| 36 |
import static processing.app.I18n.tr; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public class Platform { |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public void setLookAndFeel() throws Exception { |
| 68 |
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
public void init() throws Exception { |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
public File getSettingsFolder() throws Exception { |
| 77 |
|
| 78 |
File home = new File(System.getProperty("user.home")); |
| 79 |
File dataFolder = new File(home, ".arduino15"); |
| 80 |
return dataFolder; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public File getDefaultSketchbookFolder() throws Exception { |
| 104 |
return null; |
| 105 |
} |
| 106 |
|
| 107 |
public void openURL(File folder, String url) throws Exception { |
| 108 |
if (!url.startsWith("file://./")) { |
| 109 |
openURL(url); |
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
url = url.replaceAll("file://./", folder.getCanonicalFile().toURI().toASCIIString()); |
| 114 |
openURL(url); |
| 115 |
} |
| 116 |
|
| 117 |
public void openURL(String url) throws Exception { |
| 118 |
String launcher = PreferencesData.get("launcher"); |
| 119 |
if (launcher != null) { |
| 120 |
Runtime.getRuntime().exec(new String[]{launcher, url}); |
| 121 |
} else { |
| 122 |
showLauncherWarning(); |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
public boolean openFolderAvailable() { |
| 128 |
return PreferencesData.get("launcher") != null; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
public void openFolder(File file) throws Exception { |
| 133 |
String launcher = PreferencesData.get("launcher"); |
| 134 |
if (launcher != null) { |
| 135 |
String folder = file.getAbsolutePath(); |
| 136 |
Runtime.getRuntime().exec(new String[]{launcher, folder}); |
| 137 |
} else { |
| 138 |
showLauncherWarning(); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
static { |
| 143 |
System.loadLibrary("listSerialsj"); |
| •144 |
} |
| 145 |
|
| 146 |
private static void loadLib(File lib) { |
| 147 |
try { |
| 148 |
System.load(lib.getAbsolutePath()); |
| 149 |
} catch (UnsatisfiedLinkError e) { |
| 150 |
e.printStackTrace(); |
| 151 |
System.out.println(e.getMessage()); |
| 152 |
System.out.println("Cannot load native library " + lib.getAbsolutePath()); |
| 153 |
System.out.println("The program has terminated!"); |
| 154 |
System.exit(1); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
private native String resolveDeviceAttachedToNative(String serial); |
| 159 |
|
| 160 |
private native String[] listSerialsNative(); |
| 161 |
|
| 162 |
public String preListAllCandidateDevices() { |
| 163 |
return null; |
| 164 |
} |
| 165 |
|
| 166 |
public List<String> listSerials() { |
| 167 |
return new ArrayList<>(Arrays.asList(listSerialsNative())); |
| 168 |
} |
| 169 |
|
| 170 |
public List<String> listSerialsNames() { |
| 171 |
List<String> list = new LinkedList<>(); |
| 172 |
for (String port : listSerialsNative()) { |
| 173 |
list.add(port.split("_")[0]); |
| 174 |
} |
| 175 |
return list; |
| 176 |
} |
| 177 |
|
| 178 |
public synchronized Map<String, Object> resolveDeviceByVendorIdProductId(String serial, Map<String, TargetPackage> packages) { |
| 179 |
String vid_pid_iSerial = resolveDeviceAttachedToNative(serial); |
| 180 |
for (TargetPackage targetPackage : packages.values()) { |
| 181 |
for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) { |
| 182 |
for (TargetBoard board : targetPlatform.getBoards().values()) { |
| 183 |
List<String> vids = new LinkedList<>(board.getPreferences().subTree("vid", 1).values()); |
| 184 |
if (!vids.isEmpty()) { |
| 185 |
List<String> pids = new LinkedList<>(board.getPreferences().subTree("pid", 1).values()); |
| 186 |
List<String> descriptors = new LinkedList<>(board.getPreferences().subTree("descriptor", 1).values()); |
| 187 |
for (int i = 0; i < vids.size(); i++) { |
| 188 |
String vidPid = vids.get(i) + "_" + pids.get(i); |
| 189 |
if (vid_pid_iSerial.toUpperCase().contains(vidPid.toUpperCase())) { |
| 190 |
if (!descriptors.isEmpty()) { |
| 191 |
boolean matched = false; |
| 192 |
for (int j = 0; j < descriptors.size(); j++) { |
| 193 |
if (vid_pid_iSerial.toUpperCase().contains(descriptors.get(j).toUpperCase())) { |
| 194 |
matched = true; |
| 195 |
break; |
| 196 |
} |
| 197 |
} |
| 198 |
if (matched == false) { |
| 199 |
continue; |
| 200 |
} |
| 201 |
} |
| 202 |
Map<String, Object> boardData = new HashMap<>(); |
| 203 |
boardData.put("board", board); |
| 204 |
|
| 205 |
boardData.put("vid", vids.get(i).replaceAll("0x", "")); |
| 206 |
boardData.put("pid", pids.get(i).replaceAll("0x", "")); |
| 207 |
String extrafields = vid_pid_iSerial.substring(vidPid.length() + 1); |
| 208 |
String[] parts = extrafields.split("_"); |
| 209 |
boardData.put("iserial", parts[0]); |
| 210 |
return boardData; |
| 211 |
} |
| 212 |
} |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
} |
| 217 |
return null; |
| 218 |
} |
| 219 |
|
| 220 |
public String resolveDeviceByBoardID(Map<String, TargetPackage> packages, String boardId) { |
| 221 |
assert packages != null; |
| 222 |
assert boardId != null; |
| 223 |
for (TargetPackage targetPackage : packages.values()) { |
| 224 |
for (TargetPlatform targetPlatform : targetPackage.getPlatforms().values()) { |
| 225 |
for (TargetBoard board : targetPlatform.getBoards().values()) { |
| 226 |
if (boardId.equals(board.getId())) { |
| 227 |
return board.getName(); |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
} |
| 232 |
return null; |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
public String getName() { |
| 238 |
return PConstants.platformNames[PConstants.OTHER]; |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
protected void showLauncherWarning() { |
| 246 |
BaseNoGui.showWarning(tr("No launcher available"), |
| 247 |
tr("Unspecified platform, no launcher available.\nTo enable opening URLs or folders, add a \n\"launcher=/path/to/app\" line to preferences.txt"), |
| 248 |
null); |
| 249 |
} |
| 250 |
|
| 251 |
public List<BoardPort> filterPorts(List<BoardPort> ports, boolean aBoolean) { |
| 252 |
return new LinkedList<>(ports); |
| 253 |
} |
| 254 |
|
| 255 |
public void fixPrefsFilePermissions(File prefsFile) throws IOException, InterruptedException { |
| 256 |
Process process = Runtime.getRuntime().exec(new String[]{"chmod", "600", prefsFile.getAbsolutePath()}, null, null); |
| 257 |
process.waitFor(); |
| 258 |
} |
| 259 |
|
| 260 |
public List<File> postInstallScripts(File folder) { |
| 261 |
List<File> scripts = new LinkedList<>(); |
| 262 |
scripts.add(new File(folder, "install_script.sh")); |
| 263 |
scripts.add(new File(folder, "post_install.sh")); |
| 264 |
return scripts; |
| 265 |
} |
| 266 |
|
| 267 |
public List<File> preUninstallScripts(File folder) { |
| 268 |
List<File> scripts = new LinkedList<>(); |
| 269 |
scripts.add(new File(folder, "pre_uninstall.sh")); |
| 270 |
return scripts; |
| 271 |
} |
| 272 |
|
| 273 |
public String getOsName() { |
| 274 |
return System.getProperty("os.name"); |
| 275 |
} |
| 276 |
|
| 277 |
public String getOsArch() { |
| 278 |
return System.getProperty("os.arch"); |
| 279 |
} |
| 280 |
|
| 281 |
public void symlink(String something, File somewhere) throws IOException, InterruptedException { |
| 282 |
Process process = Runtime.getRuntime().exec(new String[]{"ln", "-s", something, somewhere.getAbsolutePath()}, null, somewhere.getParentFile()); |
| 283 |
process.waitFor(); |
| 284 |
} |
| 285 |
|
| 286 |
public void link(File something, File somewhere) throws IOException, InterruptedException { |
| 287 |
Process process = Runtime.getRuntime().exec(new String[]{"ln", something.getAbsolutePath(), somewhere.getAbsolutePath()}, null, null); |
| 288 |
process.waitFor(); |
| 289 |
} |
| 290 |
|
| 291 |
public void chmod(File file, int mode) throws IOException, InterruptedException { |
| 292 |
Process process = Runtime.getRuntime().exec(new String[]{"chmod", Integer.toOctalString(mode), file.getAbsolutePath()}, null, null); |
| 293 |
process.waitFor(); |
| 294 |
} |
| 295 |
|
| 296 |
public void fixSettingsLocation() throws Exception { |
| 297 |
|
| 298 |
} |
| 299 |
|
| 300 |
public int getSystemDPI() { |
| 301 |
return 96; |
| 302 |
} |
| 303 |
|
| 304 |
} |