| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1019,6 +1019,9 @@ protected JMenu addInternalTools(JMenu menu) { | |||
| 1019 | 1019 | addToolMenuItem(menu, "processing.app.tools.Archiver"); | |
| 1020 | 1020 | ||
| 1021 | 1021 | if (Base.isMacOS()) { | |
| 1022 | + if (SerialFixer.isNeeded()) { | ||
| 1023 | + addToolMenuItem(menu, "processing.app.tools.SerialFixer"); | ||
| 1024 | + } | ||
| 1022 | 1025 | addToolMenuItem(menu, "processing.app.tools.InstallCommander"); | |
| 1023 | 1026 | } | |
| 1024 | 1027 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,89 @@ | |||
| 1 | + /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ | ||
| 2 | + | ||
| 3 | + /* | ||
| 4 | + Part of the Processing project - http://processing.org | ||
| 5 | + | ||
| 6 | + Copyright (c) 2012 The Processing Foundation | ||
| 7 | + | ||
| 8 | + This program is free software; you can redistribute it and/or modify | ||
| 9 | + it under the terms of the GNU General Public License as published by | ||
| 10 | + the Free Software Foundation, version 2. | ||
| 11 | + | ||
| 12 | + This program is distributed in the hope that it will be useful, | ||
| 13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | + GNU General Public License for more details. | ||
| 16 | + | ||
| 17 | + You should have received a copy of the GNU General Public License | ||
| 18 | + along with this program; if not, write to the Free Software Foundation, | ||
| 19 | + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 20 | + */ | ||
| 21 | + | ||
| 22 | + package processing.app.tools; | ||
| 23 | + | ||
| 24 | + import java.io.File; | ||
| 25 | + | ||
| 26 | + import javax.swing.JOptionPane; | ||
| 27 | + | ||
| 28 | + import processing.app.Base; | ||
| 29 | + import processing.app.Editor; | ||
| 30 | + import processing.core.PApplet; | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + public class SerialFixer implements Tool { | ||
| 34 | + Editor editor; | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + public String getMenuTitle() { | ||
| 38 | + return "Fix the Serial Library"; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + | ||
| 42 | + public void init(Editor editor) { | ||
| 43 | + this.editor = editor; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + | ||
| 47 | + public void run() { | ||
| 48 | + final String primary = | ||
| 49 | + "Attempt to fix common serial port problems?"; | ||
| 50 | + final String secondary = | ||
| 51 | + "Click “OK” to perform additional installation steps to enable " + | ||
| 52 | + "the Serial library. An administrator password will be required."; | ||
| 53 | + | ||
| 54 | + int result = | ||
| 55 | + JOptionPane.showConfirmDialog(editor, | ||
| 56 | + "<html> " + | ||
| 57 | + "<head> <style type=\"text/css\">"+ | ||
| 58 | + "b { font: 13pt \"Lucida Grande\" }"+ | ||
| 59 | + "p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"+ | ||
| 60 | + "</style> </head>" + | ||
| 61 | + "<b>" + primary + "</b>" + | ||
| 62 | + "<p>" + secondary + "</p>", | ||
| 63 | + "Commander", | ||
| 64 | + JOptionPane.OK_CANCEL_OPTION, | ||
| 65 | + JOptionPane.QUESTION_MESSAGE); | ||
| 66 | + | ||
| 67 | + if (result == JOptionPane.OK_OPTION) { | ||
| 68 | + String shellScript = "mkdir -p /var/lock && chmod 777 /var/lock"; | ||
| 69 | + String appleScript = | ||
| 70 | + "do shell script \"" + shellScript + "\" with administrator privileges"; | ||
| 71 | + PApplet.exec(new String[] { "osascript", "-e", appleScript }); | ||
| 72 | + } | ||
| 73 | + editor.statusNotice("Finished."); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + | ||
| 77 | + static public boolean isNeeded() { | ||
| 78 | + if (Base.isMacOS()) { | ||
| 79 | + File lockFolder = new File("/var/lock"); | ||
| 80 | + if (!lockFolder.exists() || | ||
| 81 | + !lockFolder.canRead() || | ||
| 82 | + !lockFolder.canWrite() || | ||
| 83 | + !lockFolder.canExecute()) { | ||
| 84 | + return true; | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + return false; | ||
| 88 | + } | ||
| 89 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -100,13 +100,15 @@ public Serial(PApplet parent) { | |||
| 100 | 100 | this(parent, dname, drate, dparity, ddatabits, dstopbits); | |
| 101 | 101 | } | |
| 102 | 102 | ||
| 103 | + | ||
| 103 | 104 | /** | |
| 104 | 105 | * @param irate 9600 is the default | |
| 105 | 106 | */ | |
| 106 | 107 | public Serial(PApplet parent, int irate) { | |
| 107 | 108 | this(parent, dname, irate, dparity, ddatabits, dstopbits); | |
| 108 | 109 | } | |
| 109 | 110 | ||
| 111 | + | ||
| 110 | 112 | /** | |
| 111 | 113 | * @param iname name of the port (COM1 is the default) | |
| 112 | 114 | */ | |
@@ -118,6 +120,7 @@ public Serial(PApplet parent, String iname) { | |||
| 118 | 120 | this(parent, iname, drate, dparity, ddatabits, dstopbits); | |
| 119 | 121 | } | |
| 120 | 122 | ||
| 123 | + | ||
| 121 | 124 | /** | |
| 122 | 125 | * @param iparity 'N' for none, 'E' for even, 'O' for odd ('N' is the default) | |
| 123 | 126 | * @param idatabits 8 is the default | |
@@ -143,8 +146,11 @@ public Serial(PApplet parent, String iname, int irate, | |||
| 143 | 146 | "sudo mkdir -p /var/lock\n" + | |
| 144 | 147 | "sudo chmod 777 /var/lock"; | |
| 145 | 148 | System.err.println(MESSAGE); | |
| 146 | - throw new RuntimeException("Additional installation required to " + | ||
| 147 | - "use serial, read the console below."); | ||
| 149 | + //throw new RuntimeException("Additional installation required to " + | ||
| 150 | + // "use serial, read the console below."); | ||
| 151 | + final String msg = | ||
| 152 | + "Please use Tools \u2192 Fix the Serial Library."; | ||
| 153 | + throw new RuntimeException(msg); | ||
| 148 | 154 | } | |
| 149 | 155 | } | |
| 150 | 156 | ||
@@ -189,7 +195,7 @@ public Serial(PApplet parent, String iname, int irate, | |||
| 189 | 195 | output = null; | |
| 190 | 196 | } | |
| 191 | 197 | ||
| 192 | - parent.registerDispose(this); | ||
| 198 | + parent.registerMethod("dispose", this); | ||
| 193 | 199 | ||
| 194 | 200 | // reflection to check whether host applet has a call for | |
| 195 | 201 | // public void serialEvent(processing.serial.Serial) | |
@@ -240,18 +246,19 @@ public void dispose() { | |||
| 240 | 246 | ||
| 241 | 247 | ||
| 242 | 248 | /** | |
| 243 | - * Set the DTR line. Addition from Tom Hulbert. | ||
| 244 | - */ | ||
| 249 | + * Set the DTR line. Addition from Tom Hulbert. | ||
| 250 | + */ | ||
| 245 | 251 | public void setDTR(boolean state) { | |
| 246 | - port.setDTR(state); | ||
| 252 | + port.setDTR(state); | ||
| 247 | 253 | } | |
| 248 | 254 | ||
| 249 | - /** | ||
| 250 | - * @generate serialEvent.xml | ||
| 251 | - * @webref serial:events | ||
| 252 | - * @usage web_application | ||
| 253 | - * @param serialEvent the port where new data is available | ||
| 254 | - */ | ||
| 255 | + | ||
| 256 | + /** | ||
| 257 | + * @generate serialEvent.xml | ||
| 258 | + * @webref serial:events | ||
| 259 | + * @usage web_application | ||
| 260 | + * @param serialEvent the port where new data is available | ||
| 261 | + */ | ||
| 255 | 262 | synchronized public void serialEvent(SerialPortEvent serialEvent) { | |
| 256 | 263 | if (serialEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) { | |
| 257 | 264 | try { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments