|
22 | 22 |
|
23 | 23 | package processing.app.linux;
|
24 | 24 |
|
25 |
| -import java.io.File; |
| 25 | +import java.io.*; |
| 26 | +import java.util.Map; |
| 27 | +import java.util.Properties; |
26 | 28 |
|
27 | 29 | import javax.swing.UIManager;
|
28 | 30 |
|
| 31 | +import org.apache.commons.exec.CommandLine; |
| 32 | +import org.apache.commons.exec.DefaultExecutor; |
| 33 | +import org.apache.commons.exec.ExecuteStreamHandler; |
| 34 | +import org.apache.commons.exec.Executor; |
29 | 35 | import processing.app.Preferences;
|
| 36 | +import processing.app.debug.TargetPackage; |
30 | 37 | import processing.core.PConstants;
|
31 | 38 |
|
32 | 39 |
|
@@ -124,4 +131,51 @@ public void openFolder(File file) throws Exception {
|
124 | 131 | public String getName() {
|
125 | 132 | return PConstants.platformNames[PConstants.LINUX];
|
126 | 133 | }
|
| 134 | + |
| 135 | + @Override |
| 136 | + public String resolveDeviceAttachedTo(String serial, Map<String, TargetPackage> packages) { |
| 137 | + Executor executor = new DefaultExecutor(); |
| 138 | + |
| 139 | + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 140 | + executor.setStreamHandler(new ExecuteStreamHandler() { |
| 141 | + @Override |
| 142 | + public void setProcessInputStream(OutputStream outputStream) throws IOException { |
| 143 | + } |
| 144 | + |
| 145 | + @Override |
| 146 | + public void setProcessErrorStream(InputStream inputStream) throws IOException { |
| 147 | + } |
| 148 | + |
| 149 | + @Override |
| 150 | + public void setProcessOutputStream(InputStream inputStream) throws IOException { |
| 151 | + byte[] buf = new byte[4096]; |
| 152 | + int bytes = -1; |
| 153 | + while ((bytes = inputStream.read(buf)) != -1) { |
| 154 | + baos.write(buf, 0, bytes); |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + @Override |
| 159 | + public void start() throws IOException { |
| 160 | + } |
| 161 | + |
| 162 | + @Override |
| 163 | + public void stop() { |
| 164 | + } |
| 165 | + }); |
| 166 | + |
| 167 | + try { |
| 168 | + CommandLine toDevicePath = CommandLine.parse("udevadm info -q path -n " + serial); |
| 169 | + executor.execute(toDevicePath); |
| 170 | + String devicePath = new String(baos.toByteArray()); |
| 171 | + baos.reset(); |
| 172 | + CommandLine commandLine = CommandLine.parse("udevadm info --query=property -p " + devicePath); |
| 173 | + executor.execute(commandLine); |
| 174 | + Properties properties = new Properties(); |
| 175 | + properties.load(new ByteArrayInputStream(baos.toByteArray())); |
| 176 | + return super.resolveDeviceByVendorIdProductId(packages, properties.get("ID_VENDOR_ID").toString().toUpperCase(), properties.get("ID_MODEL_ID").toString().toUpperCase()); |
| 177 | + } catch (IOException e) { |
| 178 | + return null; |
| 179 | + } |
| 180 | + } |
127 | 181 | }
|
0 commit comments