├── .gitignore ├── examples ├── LightProbe │ ├── sketch.properties │ ├── refreshFiles.pde │ ├── getNowUTC.pde │ ├── getLocation.pde │ ├── createFile.pde │ ├── AndroidManifest.xml │ └── LightProbe.pde ├── SimpleRead │ ├── sketch.properties │ ├── AndroidManifest.xml │ └── SimpleRead.pde ├── SimpleWrite │ ├── sketch.properties │ ├── AndroidManifest.xml │ └── SimpleWrite.pde ├── SerialDuplex │ ├── sketch.properties │ ├── data │ │ └── CourierNewPSMT-24.vlw │ ├── AndroidManifest.xml │ └── SerialDuplex.pde └── SerialDuplexServer │ ├── AndroidManifest.xml │ └── SerialDuplexServer.pde ├── resources ├── code │ ├── ExampleTaglet.class │ ├── ant-contrib-1.0b3.jar │ ├── template │ │ └── library │ │ │ └── HelloLibrary.class │ ├── doc.sh │ └── ExampleTaglet.java ├── install_instructions.txt ├── library.properties ├── ChangeLog.txt ├── stylesheet.css ├── build.properties └── build.xml ├── .project ├── .classpath ├── readme.txt ├── web ├── stylesheet.css └── index.html ├── lgpl.txt ├── src └── cc │ └── arduino │ └── btserial │ ├── ConnectedThread.java │ └── BtSerial.java └── gpl.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | bin 4 | 5 | distribution 6 | 7 | .DS_Store 8 | -------------------------------------------------------------------------------- /examples/LightProbe/sketch.properties: -------------------------------------------------------------------------------- 1 | mode.id=processing.mode.android.AndroidMode 2 | mode=Android 3 | -------------------------------------------------------------------------------- /examples/SimpleRead/sketch.properties: -------------------------------------------------------------------------------- 1 | mode.id=processing.mode.android.AndroidMode 2 | mode=Android 3 | -------------------------------------------------------------------------------- /examples/SimpleWrite/sketch.properties: -------------------------------------------------------------------------------- 1 | mode.id=processing.mode.android.AndroidMode 2 | mode=Android 3 | -------------------------------------------------------------------------------- /examples/SerialDuplex/sketch.properties: -------------------------------------------------------------------------------- 1 | mode.id=processing.mode.android.AndroidMode 2 | mode=Android 3 | -------------------------------------------------------------------------------- /resources/code/ExampleTaglet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BtSerial/master/resources/code/ExampleTaglet.class -------------------------------------------------------------------------------- /resources/code/ant-contrib-1.0b3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BtSerial/master/resources/code/ant-contrib-1.0b3.jar -------------------------------------------------------------------------------- /examples/SerialDuplex/data/CourierNewPSMT-24.vlw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BtSerial/master/examples/SerialDuplex/data/CourierNewPSMT-24.vlw -------------------------------------------------------------------------------- /resources/code/template/library/HelloLibrary.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arduino/BtSerial/master/resources/code/template/library/HelloLibrary.class -------------------------------------------------------------------------------- /examples/LightProbe/refreshFiles.pde: -------------------------------------------------------------------------------- 1 | // from http://stackoverflow.com/questions/4646913/android-how-to-use-mediascannerconnection-scanfile 2 | 3 | //refresh the index of external files 4 | //(for devices that don't have SD card slots and must transfer files over MTP) 5 | void refreshFiles() { 6 | sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + android.os.Environment.getExternalStorageDirectory() + "/lumos"))); 7 | } 8 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | BtSerial 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /examples/LightProbe/getNowUTC.pde: -------------------------------------------------------------------------------- 1 | import java.text.SimpleDateFormat; 2 | 3 | //get the phone time NOW in UTC (Greenwich Mean Time), and return it as a String formatted like "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" 4 | String getNowUTC() { 5 | SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); 6 | timeFormat.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC")); 7 | Date currentTime = new Date(); 8 | return timeFormat.format(currentTime); 9 | } 10 | -------------------------------------------------------------------------------- /resources/code/doc.sh: -------------------------------------------------------------------------------- 1 | # a shell script to create a java documentation 2 | # for a processing library. 3 | # 4 | # make changes to the variables below so they 5 | # fit the structure of your library 6 | 7 | # the package name of your library 8 | package=template; 9 | 10 | # source folder location 11 | src=../src; 12 | 13 | # the destination folder of your documentation 14 | dest=../documentation; 15 | 16 | 17 | # compile the java documentation 18 | javadoc -d $dest -stylesheetfile ./stylesheet.css -sourcepath ${src} ${package} 19 | -------------------------------------------------------------------------------- /examples/LightProbe/getLocation.pde: -------------------------------------------------------------------------------- 1 | //get the phone's current location 2 | //adapted from Ketai geolocation example 3 | import ketai.sensors.*; 4 | 5 | double longitude, latitude, altitude; 6 | KetaiLocation location; 7 | boolean locationReady; 8 | 9 | void getPhoneLocation() { 10 | if (location.getProvider() == "none") { 11 | locationReady = false; 12 | } else { 13 | locationReady = true; 14 | } 15 | } 16 | 17 | void onLocationEvent(double _latitude, double _longitude, double _altitude) 18 | { 19 | locationReady = true; 20 | longitude = _longitude; 21 | latitude = _latitude; 22 | altitude = _altitude; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /examples/SerialDuplex/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/SerialDuplexServer/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/SimpleRead/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/SimpleWrite/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /examples/LightProbe/createFile.pde: -------------------------------------------------------------------------------- 1 | // Create the output file and return its full path 2 | // based on http://stackoverflow.com/questions/7887078/android-saving-file-to-external-storage 3 | 4 | String createFile(String fileName) { 5 | //get the path of the external storage directory 6 | String root = android.os.Environment.getExternalStorageDirectory().toString(); 7 | 8 | //Check to see if the directory exists 9 | try { 10 | File myDir = new File(root + "/" + filePrefix); 11 | 12 | //create the directory if it doesn't exist 13 | if (!myDir.exists()) { 14 | myDir.mkdirs(); 15 | } 16 | }catch(Exception e) { 17 | } 18 | 19 | //build the full file path and name 20 | String filePath = root + "/" + filePrefix + "/" + fileName; 21 | 22 | //create the file 23 | File outFile = new File(filePath); 24 | if (!outFile.exists()) { 25 | try { 26 | outFile.createNewFile(); 27 | } 28 | catch(Exception ex) { 29 | println(ex); 30 | } 31 | } 32 | 33 | return(filePath); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /examples/LightProbe/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | BtSerial Library for Processing for Android 2 | 3 | This library gives you access to a Bluetooth Serial port on Android devices that have Bluetooth. It's structured using Processing's Serial library API, so those familiar with Serial should be able to do the same things with this as they can with Serial. 4 | 5 | There are some differences: 6 | * You have to enable Bluetooth on your device. 7 | * You have to pair with the device you want to talk to in advance. 8 | * It is recommended to disconnect the Bluetooth connection on stop() and pause() and reconnect on resume() in order to prevent connection errors 9 | 10 | This library was based on SweetBlue, a Bluetooth library for Processing and Arduino, by Andreas Goransson & David Cuartielles at 1scale1.se. For connections between Processing for Android and Arduino without having to write your own Arduino firmware, see https://github.com/1scale1/sweetbt. It was also based in Ben Fry's Serial library for Processing(http://code.google.com/p/processing/), and on Google's BluetoothChatService example for Android (http://developer.android.com/resources/samples/BluetoothChat). 11 | Thanks to Bonifaz Kaufman, developer of Amarino (http://code.google.com/p/amarino) for many good ideas as well. 12 | BtSerial was refined and expanded by Joshua Albers (http://joshuaalbers.com) as part of Google Summer of Code 2012. 13 | 14 | 15 | BtSerial Copyright 2011, 2012 Andreas Goransson & David Cuartielles & Tom Igoe & Joshua Albers 16 | Version 0.2.0 17 | August 2012 18 | -------------------------------------------------------------------------------- /resources/install_instructions.txt: -------------------------------------------------------------------------------- 1 | How to install library ##library.name## 2 | 3 | 4 | Install with the "Add Library..." tool 5 | 6 | New for Processing 2.0: Add contributed libraries by selecting "Add Library..." 7 | from the "Import Library..." submenu within the Sketch menu. Not all available 8 | libraries have been converted to show up in this menu. If a library isn't there, 9 | it will need to be installed manually by following the instructions below. 10 | 11 | 12 | Manual Install 13 | 14 | Contributed libraries may be downloaded separately and manually placed within 15 | the "libraries" folder of your Processing sketchbook. To find (and change) the 16 | Processing sketchbook location on your computer, open the Preferences window 17 | from the Processing application (PDE) and look for the "Sketchbook location" 18 | item at the top. 19 | 20 | Copy the contributed library's folder into the "libraries" folder at this 21 | location. You will need to create the "libraries" folder if this is your first 22 | contributed library. 23 | 24 | By default the following locations are used for your sketchbook folder: 25 | For Mac users, the sketchbook folder is located inside ~/Documents/Processing. 26 | For Windows users, the sketchbook folder is located inside 27 | 'My Documents'/Processing. 28 | 29 | The folder structure for library ##library.name## should be as follows: 30 | 31 | Processing 32 | libraries 33 | ##library.name## 34 | examples 35 | library 36 | ##library.name##.jar 37 | reference 38 | src 39 | 40 | Some folders like "examples" or "src" might be missing. After library 41 | ##library.name## has been successfully installed, restart the Processing 42 | application. 43 | 44 | 45 | If you're having trouble, have a look at the Processing Wiki for more 46 | information: http://wiki.processing.org/w/How_to_Install_a_Contributed_Library 47 | -------------------------------------------------------------------------------- /examples/SerialDuplexServer/SerialDuplexServer.pde: -------------------------------------------------------------------------------- 1 | /** 2 | * Serial Duplex 3 | * by Tom Igoe. 4 | * Adapted from the Serial library example for BtSerial by Joshua Albers 5 | * 6 | * Intended to be used to connect to a device running SerialDuplex 7 | * 8 | * Sends a byte out the serial port when you type a key 9 | * listens for bytes received, and displays their value. 10 | * This is just a quick application for testing serial data 11 | * in both directions. 12 | * 13 | */ 14 | 15 | import cc.arduino.btserial.*; 16 | 17 | BtSerial bt; // the Bluetooth serial connection 18 | int whichKey = -1; // Variable to hold keystoke values 19 | int inByte = -1; // Incoming serial data 20 | String remoteAddress; //hardware address for the device being connected to 21 | byte outByte = -1; 22 | 23 | void setup() { 24 | size(displayWidth, displayHeight); 25 | // create a font with the third font available to the system: 26 | PFont myFont = createFont(PFont.list()[2], (displayWidth * .04)); 27 | textFont(myFont); 28 | 29 | bt = new BtSerial(this); 30 | 31 | println(bt.list(true)); //get list of paired devices (with extended information) 32 | 33 | bt.listen(); // listen for incoming connections from an Android device 34 | } 35 | 36 | void draw() { 37 | background(0); 38 | 39 | text("Connected to: " + bt.getRemoteName() +" [" + bt.getRemoteAddress() + "]", 10, 100); 40 | text("Last Sent: " + whichKey, 10, 150); 41 | text("Last Received: " + inByte, 10, 200); 42 | 43 | if (bt.isConnected()) { 44 | if (bt.available() > 0) { 45 | inByte = bt.read(); 46 | } 47 | } 48 | } 49 | 50 | void btSerialEvent(BtSerial bt) { 51 | inByte = bt.read(); 52 | } 53 | 54 | void mousePressed() { 55 | // Send the keystroke out: 56 | outByte++; 57 | outByte = (byte)(outByte % 255); 58 | bt.write(outByte); 59 | whichKey = outByte; 60 | } 61 | 62 | void pause() { 63 | if (bt != null) { 64 | bt.disconnect(); 65 | } 66 | println("Bluetooth disconnected"); 67 | } 68 | 69 | void stop() { 70 | if (bt != null) { 71 | bt.disconnect(); 72 | } 73 | println("Bluetooth disconnected"); 74 | } 75 | 76 | void resume() { 77 | if (bt != null) { 78 | bt.connect(remoteAddress); 79 | println("Bluetooth reconnected"); 80 | } 81 | } 82 | 83 | -------------------------------------------------------------------------------- /examples/SerialDuplex/SerialDuplex.pde: -------------------------------------------------------------------------------- 1 | /** 2 | * Serial Duplex 3 | * by Tom Igoe. 4 | * Adapted from the Serial library example for BtSerial by Joshua Albers 5 | * 6 | * Intended to be used to connect to a device running SerialDuplexServer 7 | * 8 | * Sends an incrementing byte value out the serial port when 9 | * you tap the screen. 10 | * Listens for bytes received, and displays their value. 11 | * This is just a quick application for testing serial data 12 | * in both directions. 13 | * 14 | */ 15 | 16 | import cc.arduino.btserial.*; 17 | 18 | BtSerial bt; // the Bluetooth serial connection 19 | int whichKey = -1; // Variable to hold keystoke values 20 | int inByte = -1; // Incoming serial data 21 | String remoteAddress; //hardware address for the device being connected to 22 | byte outByte = -1; 23 | 24 | void setup() { 25 | size(displayWidth, displayHeight); 26 | // create a font with the third font available to the system: 27 | PFont myFont = createFont(PFont.list()[2], (float(displayWidth)*.04)); 28 | textFont(myFont); 29 | 30 | bt = new BtSerial(this); 31 | 32 | println(bt.list(true)); //get list of paired devices (with extended information) 33 | remoteAddress = bt.list()[0]; //get only the hardware address for the specific entry 34 | 35 | bt.connect(remoteAddress); // connect to the device 36 | } 37 | 38 | void draw() { 39 | background(0); 40 | text("Connected to: " + bt.getRemoteName() +" [" + bt.getRemoteAddress() + "]", 10, 100); 41 | text("Last Sent: " + whichKey, 10, 150); 42 | text("Last Received: " + inByte, 10, 200); 43 | } 44 | 45 | void btSerialEvent(BtSerial bt){ 46 | inByte = bt.read(); 47 | } 48 | 49 | void mousePressed() { 50 | outByte++; 51 | outByte = (byte)(outByte % 255); 52 | bt.write(outByte); 53 | whichKey = outByte; 54 | } 55 | 56 | void pause() { 57 | if (bt != null) { 58 | bt.disconnect(); 59 | } 60 | println("Bluetooth disconnected"); 61 | } 62 | 63 | void stop() { 64 | if (bt != null) { 65 | bt.disconnect(); 66 | } 67 | println("Bluetooth disconnected"); 68 | } 69 | 70 | void resume() { 71 | if (bt != null) { 72 | bt.connect(remoteAddress); 73 | if (bt.isConnected()) println("Bluetooth reconnected"); 74 | else println("connection failed"); 75 | } 76 | } 77 | 78 | -------------------------------------------------------------------------------- /resources/library.properties: -------------------------------------------------------------------------------- 1 | # More on this file here: http://code.google.com/p/processing/wiki/LibraryBasics 2 | # UTF-8 supported. 3 | 4 | # The name of your library as you want it formatted. 5 | name = ##library.name## 6 | 7 | # List of authors. Links can be provided using the syntax [author name](url). 8 | authorList = [##author.name##](##author.url##) 9 | 10 | # A web page for your library, NOT a direct link to where to download it. 11 | url = ##library.url## 12 | 13 | # The category of your library, must be one (or many) of the following: 14 | # "3D" "Animation" "Compilations" "Data" 15 | # "Fabrication" "Geometry" "GUI" "Hardware" 16 | # "I/O" "Language" "Math" "Simulation" 17 | # "Sound" "Utilities" "Typography" "Video & Vision" 18 | # 19 | # If a value other than those listed is used, your library will listed as 20 | # "Other". 21 | category = ##library.category## 22 | 23 | # A short sentence (or fragment) to summarize the library's function. This will 24 | # be shown from inside the PDE when the library is being installed. Avoid 25 | # repeating the name of your library here. Also, avoid saying anything redundant 26 | # like mentioning that it's a library. This should start with a capitalized 27 | # letter, and end with a period. 28 | sentence = ##library.sentence## 29 | 30 | # Additional information suitable for the Processing website. The value of 31 | # 'sentence' always will be prepended, so you should start by writing the 32 | # second sentence here. If your library only works on certain operating systems, 33 | # mention it here. 34 | paragraph = ##library.paragraph## 35 | 36 | # Links in the 'sentence' and 'paragraph' attributes can be inserted using the 37 | # same syntax as for authors. 38 | # That is, [here is a link to Processing](http://processing.org/) 39 | 40 | 41 | # A version number that increments once with each release. This is used to 42 | # compare different versions of the same library, and check if an update is 43 | # available. You should think of it as a counter, counting the total number of 44 | # releases you've had. 45 | version = ##library.version## # This must be parsable as an int 46 | 47 | # The version as the user will see it. If blank, the version attribute will be 48 | # used here. 49 | prettyVersion = ##library.prettyVersion## # This is treated as a String 50 | -------------------------------------------------------------------------------- /examples/SimpleWrite/SimpleWrite.pde: -------------------------------------------------------------------------------- 1 | /** 2 | * Simple Write. 3 | * Adapted from the Serial library example for BtSerial by Joshua Albers 4 | * 5 | * Intended to be used to connect to a device running SerialDuplexServer 6 | * 7 | * Check if the mouse is over a rectangle and writes the status to the serial port. 8 | * This example works with the Wiring / Arduino program that follows below. 9 | * 10 | */ 11 | 12 | 13 | import cc.arduino.btserial.*; 14 | 15 | BtSerial bt; // Create object from BtSerial class 16 | String remoteAddress; // MAC address of the device to which the Android will connect 17 | int val; // Data received from the Bluetooth serial port 18 | 19 | void setup() { 20 | size(displayWidth, displayHeight); 21 | rectMode(CENTER); 22 | 23 | bt = new BtSerial(this); //create the BtSerial object that will handle the connection 24 | println(bt.list(true)); //get list of paired devices (with extended information) 25 | remoteAddress = bt.list()[3]; //get only the hardware address for the specific entry 26 | 27 | bt.connect(remoteAddress); 28 | } 29 | 30 | void draw() { 31 | background(255); 32 | if (mouseOverRect() == true) { // If mouse is over square, 33 | fill(204); // change color and 34 | bt.write('H'); // send an H to indicate mouse is over square 35 | } 36 | else { // If mouse is not over square, 37 | fill(0); // change color and 38 | bt.write('L'); // send an L otherwise 39 | } 40 | rect(width/2, height/2, 200, 200); // Draw a square 41 | } 42 | 43 | boolean mouseOverRect() { // Test if mouse is over square 44 | return ((mouseX >= (width/2-100)) && (mouseX <= (width/2+100)) && (mouseY >= (height/2-100)) && (mouseY <= (height/2+100))); 45 | } 46 | 47 | 48 | /* 49 | // Wiring/Arduino code: 50 | // Read data from the serial and turn ON or OFF a light depending on the value 51 | 52 | // Adapted for BtSerial with Processing Android by Joshua Albers 53 | 54 | #include 55 | 56 | SoftwareSerial bluetooth(8,9); // Serial Bluetooth Modem connected with TX to pin 8 and RX to pin 9 57 | 58 | char val; // Data received from the serial port 59 | int ledPin = 13; // Set the pin to digital I/O 13 60 | 61 | void setup() { 62 | pinMode(ledPin, OUTPUT); // Set pin as OUTPUT 63 | bluetooth.begin(115200); // Start serial communication at 115200 bps 64 | } 65 | 66 | void loop() { 67 | if (bluetooth.available()) { // If data is available to read, 68 | val = bluetooth.read(); // read it and store it in val 69 | } 70 | if (val == 'H') { // If H was received 71 | digitalWrite(ledPin, HIGH); // turn the LED on 72 | bluetooth.flush(); 73 | } 74 | else { 75 | digitalWrite(ledPin, LOW); // Otherwise turn it OFF 76 | bluetooth.flush(); 77 | } 78 | delay(100); // Wait 100 milliseconds for next reading 79 | } 80 | 81 | */ 82 | -------------------------------------------------------------------------------- /web/stylesheet.css: -------------------------------------------------------------------------------- 1 | /* processingLibs style by andreas schlegel, sojamo. */ 2 | 3 | 4 | * { 5 | margin:0; 6 | padding:0; 7 | border:0; 8 | } 9 | 10 | 11 | body { 12 | font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; 13 | font-size : 100%; 14 | font-size : 0.70em; 15 | font-weight : normal; 16 | line-height : normal; 17 | } 18 | 19 | 20 | 21 | #container { 22 | margin-left:64px; 23 | background-color:#fff; 24 | } 25 | 26 | #header { 27 | float:left; 28 | padding-top:24px; 29 | padding-bottom:48px; 30 | } 31 | 32 | #menu { 33 | margin-top:16px; 34 | float:left; 35 | margin-bottom:64px; 36 | } 37 | 38 | 39 | #about, 40 | #download, 41 | #examples, 42 | #demos, 43 | #misc { 44 | width:480px; 45 | float:left; 46 | margin-right:24px; 47 | } 48 | 49 | 50 | #resources, #info { 51 | width:320px; 52 | float:left; 53 | } 54 | 55 | 56 | .clear { 57 | clear:both; 58 | } 59 | 60 | #footer { 61 | margin-top:300px; 62 | height:20px; 63 | margin-bottom:32px; 64 | } 65 | 66 | 67 | ul { 68 | list-style:none; 69 | padding:0; 70 | margin:0; 71 | } 72 | 73 | 74 | #menu ul li, #subMenu ul li { 75 | float:left; 76 | padding-right:6px; 77 | } 78 | 79 | 80 | 81 | 82 | 83 | 84 | /* Headings */ 85 | 86 | h1 { 87 | font-size:2em; 88 | font-weight:normal; 89 | } 90 | 91 | 92 | h2, h3, h4, h5, th { 93 | font-size:1.3em; 94 | font-weight:normal; 95 | margin-bottom:4px; 96 | } 97 | 98 | 99 | 100 | p { 101 | font-size:1em; 102 | width:90%; 103 | margin-bottom:32px; 104 | } 105 | 106 | 107 | pre, code { 108 | font-family:"Courier New", Courier, monospace; 109 | font-size:1em; 110 | line-height:normal; 111 | } 112 | 113 | 114 | 115 | 116 | hr { 117 | border:0; 118 | height:1px; 119 | margin-bottom:24px; 120 | } 121 | 122 | 123 | a { 124 | text-decoration: underline; 125 | font-weight: normal; 126 | } 127 | 128 | 129 | a:hover, 130 | a:active { 131 | text-decoration: underline; 132 | font-weight: normal; 133 | } 134 | 135 | 136 | a:visited, 137 | a:link:visited { 138 | text-decoration: underline; 139 | font-weight: normal; 140 | } 141 | 142 | 143 | 144 | img { 145 | border: 0px solid #000000; 146 | } 147 | 148 | 149 | 150 | 151 | 152 | /* COLORS */ 153 | 154 | 155 | body { 156 | color : #333; 157 | background-color :#fff; 158 | } 159 | 160 | 161 | #header { 162 | background-color:#fff; 163 | color:#333; 164 | } 165 | 166 | 167 | 168 | h1, h2, h3, h4, h5, h6 { 169 | color:#666; 170 | } 171 | 172 | 173 | pre, code { 174 | color: #000000; 175 | } 176 | 177 | 178 | a,strong { 179 | color: #333; 180 | } 181 | 182 | 183 | a:hover, 184 | a:active { 185 | color: #333; 186 | } 187 | 188 | 189 | a:visited, 190 | a:link:visited { 191 | color: #333; 192 | } 193 | 194 | 195 | #footer, #menu { 196 | background-color:#fff; 197 | color:#333; 198 | } 199 | 200 | 201 | #footer a, #menu a { 202 | color:#333; 203 | } 204 | -------------------------------------------------------------------------------- /examples/SimpleRead/SimpleRead.pde: -------------------------------------------------------------------------------- 1 | /** 2 | * Simple Read 3 | * Adapted from the Serial library example for BtSerial by Joshua Albers 4 | * 5 | * Read data from the Bluetooth device and change the color of a rectangle 6 | * when a switch connected to a Wiring or Arduino board is pressed and released. 7 | * This example works with the Wiring / Arduino program that follows below. 8 | * 9 | */ 10 | 11 | 12 | import cc.arduino.btserial.*; 13 | 14 | BtSerial bt; // Create object from BtSerial class 15 | String remoteAddress; // MAC address of the device to which the Android will connect 16 | int val; // Data received from the Bluetooth serial port 17 | 18 | void setup() { 19 | size(displayWidth, displayHeight); 20 | rectMode(CENTER); 21 | 22 | bt = new BtSerial(this); //create the BtSerial object that will handle the connection 23 | println(bt.list(true)); //get list of paired devices (with extended information) 24 | remoteAddress = bt.list()[3]; //get only the hardware address for the specific entry 25 | 26 | bt.connect(remoteAddress); 27 | } 28 | 29 | void draw() { 30 | 31 | background(255); // Set background to white 32 | if (val == 0) { // If the serial value is 0, 33 | fill(0); // set fill to black 34 | } 35 | else { // If the serial value is not 0, 36 | fill(204); // set fill to light gray 37 | } 38 | 39 | rect(width/2, height/2, width/3, width/3); // draw a square in the center of the screen 40 | } 41 | 42 | void btSerialEvent(BtSerial bt) { 43 | val = bt.read(); //update val whenever new data is received 44 | } 45 | 46 | void pause() { 47 | if (bt != null) { 48 | bt.disconnect(); 49 | } 50 | println("Bluetooth disconnected"); 51 | } 52 | 53 | void stop() { 54 | if (bt != null) { 55 | bt.disconnect(); 56 | } 57 | println("Bluetooth disconnected"); 58 | } 59 | 60 | void resume() { 61 | if (bt != null) { 62 | while (!bt.isConnected ()) { 63 | bt.connect(remoteAddress); 64 | } 65 | println("Bluetooth reconnected"); 66 | } 67 | } 68 | 69 | 70 | 71 | /* 72 | 73 | // Wiring / Arduino Code 74 | // Code for sensing a switch status and writing the value to the serial port. 75 | // 76 | // Adapted for BtSerial with Processing Android by Joshua Albers 77 | 78 | #include 79 | 80 | SoftwareSerial bluetooth(8,9); // Serial Bluetooth Modem connected with TX to pin 8 and RX to pin 9 81 | 82 | int switchPin = 4; // Switch connected to pin 4 83 | 84 | void setup() { 85 | pinMode(switchPin, INPUT); // Set pin 0 as an input 86 | bluetooth.begin(115200); // Start serial communication at 115200 bps 87 | } 88 | 89 | void loop() { 90 | if (digitalRead(switchPin) == HIGH) { // If switch is ON, 91 | bluetooth.write(byte(1)); // send 1 to Processing 92 | } else { // If the switch is not ON, 93 | bluetooth.write(byte(0)); // send 0 to Processing 94 | } 95 | delay(100); // Wait 100 milliseconds 96 | } 97 | 98 | */ 99 | -------------------------------------------------------------------------------- /resources/ChangeLog.txt: -------------------------------------------------------------------------------- 1 | 2012-02-16 Elie Zananiri 2 | * version 0.4.7 3 | * fixed up formatting to match new tool template 4 | 5 | 2011-12-23 Elie Zananiri 6 | * version 0.4.6 7 | * changed the default Java compile version to 1.6 8 | * added a "library.paragraph" to build.properties, used in the library.properties file 9 | * added "library.sentence" and "library.paragraph" fields to index.html 10 | 11 | 2011-11-17 Elie Zananiri 12 | * version 0.4.5 13 | * updated the library categories 14 | 15 | 2011-11-10 Elie Zananiri 16 | * version 0.4.4 17 | * updated the build script to use the correct delimiter based on the OS when parsing source files 18 | 19 | 2011-11-09 Elie Zananiri 20 | * version 0.4.3 21 | * removed the "-latest" suffix from the generated file names as it could lead to confusion when unzipping the library 22 | * added the version number to the download link text to avoid confusion with the pretty version string 23 | 24 | 2011-11-07 Elie Zananiri 25 | * version 0.4.2 26 | * fixed some warnings in the Ant build script 27 | 28 | 2011-11-03 Elie Zananiri 29 | * version 0.4.1 30 | * added the library.properties file, used for the library engine in Processing 2.0 31 | * added new fields to build.properties to fill in the library.properties file 32 | * the script now generates two copies of the zip and properties file: one with the version number appended and another with "latest" appended (for the Processing 2.0 library engine) 33 | 34 | 2010-05-07 Andreas Schlegel 35 | * version 0.3.2 36 | * build.xml: removing delete tag for bin folder, did cause issues with class referencing inside eclipse 37 | * build.xml: for users using 0.3.1, comment out inside target clean 38 | 39 | 2010-05-01 Andreas Schlegel 40 | * version 0.3.1 41 | * the option to create a tool with the library template has been excluded. to create tools for processing see http://code.google.com/p/processing-tool-template 42 | * build.properties and build.xml files have been adjusted accordingly 43 | * modified: src, examples 44 | 45 | 2010-04-25 Andreas Schlegel 46 | * version 0.2.1 47 | * build.xml: zip method adjusted, tested on osx 10.x and windows xp 48 | * screencasts available for both library and tool, see wiki. 49 | 50 | 2010-04-12 Andreas Schlegel 51 | * version 0.2.0 52 | * the template now support both, processing libraries and tools 53 | * added an install file for a library/tool distribution included in the .zip file. 54 | * data: adding data folder, see README file for details 55 | * lib: adding lib folder, see README file for details 56 | * resources: excluding project related properties from build.xml, now located inside build.properties 57 | * distribution: distributions are now archived with a version number 58 | * bin: folder removed 59 | * build.xml: ant build file has been mostly rewritten, now supports tool and library 60 | * build.properties: adding properties file for build.xml. please read comments inside build.properties. 61 | * changeLog: adding ChangeLog file 62 | 63 | -------------------------------------------------------------------------------- /examples/LightProbe/LightProbe.pde: -------------------------------------------------------------------------------- 1 | /* LightProbe 2 | * 3 | * This sketch is intended to captute data from two photoresistors 4 | * attached to an Arduino through analog pins and sent to an Android 5 | * device over a Bluetooth serial connection. 6 | * 7 | * August 2012 Joshua Albers 8 | */ 9 | 10 | import ketai.sensors.*; 11 | import cc.arduino.btserial.*; 12 | import android.os.Environment; 13 | import android.content.Intent; 14 | import android.net.Uri; 15 | 16 | ArrayList devices; 17 | BtSerial bt; 18 | 19 | String remoteAddress; 20 | 21 | boolean registered = false; 22 | PFont f1; 23 | PFont f2; 24 | 25 | int leftValue = 0; 26 | int rightValue = 0; 27 | 28 | String filePrefix = "LightProbe"; 29 | String outputFilename = ""; 30 | BufferedWriter out; 31 | 32 | void setup() { 33 | orientation(LANDSCAPE); 34 | size(displayWidth, displayHeight); 35 | f1 = createFont("Droid Sans", 50, true); 36 | f2 = createFont("Droid Sans", 35, true); 37 | 38 | bt = new BtSerial(this); //create the BtSerial object that will handle the connection 39 | println(bt.list(true)); //Display a list of devices the paired devices 40 | remoteAddress = bt.list()[3]; //on my test device, the Arduino is the third paired device 41 | 42 | //build the output filename 43 | outputFilename = createFile(filePrefix + "_" + nf(year(), 4) + nf(month(), 2) + nf(day(), 2) + nf(hour(), 2) + nf(minute(), 2) + nf(second(), 2) + ".csv"); 44 | print (outputFilename); 45 | 46 | try { 47 | out = new BufferedWriter(new FileWriter(outputFilename, true), 4096); 48 | println(" output file open"); 49 | } 50 | catch (Exception e) { 51 | //e.printStackTrace(); 52 | } 53 | } 54 | 55 | void draw() { 56 | textFont(f2); 57 | float textHeight = textAscent() + textDescent(); 58 | 59 | if (!bt.isConnected()) { //if not connected, don't display the probe values 60 | background(0); 61 | fill(255); 62 | String[] pairedDevices = bt.list(); 63 | textAlign(CENTER); 64 | String statusText = "Connecting to " + remoteAddress; 65 | print(statusText); 66 | text(statusText, width/2, height/2); 67 | try { 68 | bt.connect(remoteAddress); 69 | } 70 | catch(Exception ex) { 71 | println(" connection failed"); 72 | } 73 | } 74 | else { 75 | background(64); 76 | fill(map(leftValue, 0, 1023, 0, 255)); 77 | rect(0, textHeight + 10, width/2, height); 78 | fill(map(rightValue, textHeight + 10, 1023, 0, 255)); 79 | rect(width/2, textHeight+10, width, height); 80 | } 81 | 82 | fill(255); 83 | getPhoneLocation(); 84 | 85 | if (locationReady) { 86 | textAlign(LEFT); 87 | text("Lat: " + latitude, 5, textHeight); 88 | text("Lon: " + longitude, displayWidth/2, textHeight); 89 | } 90 | else { 91 | textAlign(CENTER); 92 | text("Please enable device location", 5, textHeight); 93 | } 94 | } 95 | 96 | void newData(BtSerial bt) { 97 | // if there are incoming bytes, make sure at least 10 bytes (a complete message) 98 | // is in the buffer. 99 | if (bt.available() >= 10) { 100 | 101 | // if so, get the current timestamp from the phone 102 | String messageTime = getNowUTC(); 103 | // and read the buffer. 104 | String message = bt.readStringUntil(';'); 105 | 106 | if (message.length() == 9) { 107 | String[] fields = split(message, ','); 108 | 109 | if (fields.length == 2) { 110 | leftValue = int(fields[0]); 111 | rightValue = int(fields[1]); 112 | 113 | //build the output message 114 | String outputMessage = messageTime + "," + message + "," + longitude + "," + latitude + "\n"; 115 | 116 | //save the output message 117 | try { 118 | out.write(outputMessage); 119 | } 120 | catch(Exception ex) { 121 | println(ex); 122 | } 123 | } 124 | } 125 | } 126 | } 127 | 128 | void pause() { 129 | // disconnect on pause so you can reconnect on Resume: 130 | if (bt != null) { 131 | bt.disconnect(); 132 | println("Pause; isConnected() = " + bt.isConnected()); 133 | } 134 | 135 | // and close the file so it doesn't get stuck open 136 | try { 137 | out.close(); 138 | refreshFiles(); 139 | println("output file closed"); 140 | } 141 | catch(Exception ex) { 142 | println(ex); 143 | } 144 | } 145 | 146 | void resume() { 147 | println("Resume"); 148 | 149 | // refresh the location if necessary 150 | if (location == null) location = new KetaiLocation(this); 151 | 152 | // reopen the output file 153 | try { 154 | out = new BufferedWriter(new FileWriter(outputFilename, true), 4096); 155 | println("output file open"); 156 | } 157 | catch (Exception e) { 158 | //e.printStackTrace(); 159 | } 160 | } 161 | 162 | -------------------------------------------------------------------------------- /resources/stylesheet.css: -------------------------------------------------------------------------------- 1 | /* Javadoc style sheet */ 2 | /* Define colors, fonts and other style attributes here to override the defaults */ 3 | /* processingLibs style by andreas schlegel, sojamo */ 4 | 5 | 6 | body { 7 | margin : 0; 8 | padding : 0; 9 | padding-left : 10px; 10 | padding-right : 8px; 11 | background-color : #FFFFFF; 12 | font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; 13 | font-size : 100%; 14 | font-size : 0.7em; 15 | font-weight : normal; 16 | line-height : normal; 17 | margin-bottom:30px; 18 | } 19 | 20 | 21 | 22 | 23 | /* Headings */ 24 | h1, h2, h3, h4, h5, th { 25 | font-family :Arial, Helvetica, sans-serif; 26 | font-size:1.2em; 27 | } 28 | 29 | 30 | p { 31 | font-size : 1em; 32 | width:80%; 33 | } 34 | 35 | pre, code { 36 | font-family : "Courier New", Courier, monospace; 37 | font-size : 12px; 38 | line-height : normal; 39 | } 40 | 41 | 42 | 43 | table { 44 | border:0; 45 | margin-bottom:10px; 46 | margin-top:10px; 47 | } 48 | 49 | 50 | tr, td { 51 | border-top: 0px solid; 52 | border-left: 0px solid; 53 | padding-top:8px; 54 | padding-bottom:8px; 55 | } 56 | 57 | 58 | 59 | hr { 60 | border:0; 61 | height:1px; 62 | padding:0; 63 | margin:0; 64 | margin-bottom:4px; 65 | 66 | } 67 | 68 | 69 | 70 | dd, th, td, font { 71 | font-size:1.0em; 72 | line-height:1.0em; 73 | } 74 | 75 | 76 | 77 | dt { 78 | margin-bottom:0px; 79 | } 80 | 81 | 82 | 83 | dd { 84 | margin-top:2px; 85 | margin-bottom:4px; 86 | } 87 | 88 | 89 | 90 | a { 91 | text-decoration: underline; 92 | font-weight: normal; 93 | } 94 | 95 | a:hover, 96 | a:active { 97 | text-decoration: underline; 98 | font-weight: normal; 99 | } 100 | 101 | a:visited, 102 | a:link:visited { 103 | text-decoration: underline; 104 | font-weight: normal; 105 | } 106 | 107 | 108 | img { 109 | border: 0px solid #000000; 110 | } 111 | 112 | 113 | 114 | /* Navigation bar fonts */ 115 | .NavBarCell1 { 116 | border:0; 117 | } 118 | 119 | .NavBarCell1Rev { 120 | border:0; 121 | } 122 | 123 | .NavBarFont1 { 124 | font-family: Arial, Helvetica, sans-serif; 125 | font-size:1.1em; 126 | } 127 | 128 | 129 | .NavBarFont1 b { 130 | font-weight:normal; 131 | } 132 | 133 | 134 | 135 | .NavBarFont1:after, .NavBarFont1Rev:after { 136 | font-weight:normal; 137 | content: " \\"; 138 | } 139 | 140 | 141 | .NavBarFont1Rev { 142 | font-family: Arial, Helvetica, sans-serif; 143 | font-size:1.1em; 144 | } 145 | 146 | .NavBarFont1Rev b { 147 | font-family: Arial, Helvetica, sans-serif; 148 | font-size:1.1em; 149 | font-weight:normal; 150 | } 151 | 152 | .NavBarCell2 { 153 | font-family: Arial, Helvetica, sans-serif; 154 | } 155 | 156 | .NavBarCell3 { 157 | font-family: Arial, Helvetica, sans-serif; 158 | } 159 | 160 | 161 | 162 | font.FrameItemFont { 163 | font-family: Helvetica, Arial, sans-serif; 164 | font-size:1.1em; 165 | line-height:1.1em; 166 | } 167 | 168 | font.FrameHeadingFont { 169 | font-family: Helvetica, Arial, sans-serif; 170 | line-height:32px; 171 | } 172 | 173 | /* Font used in left-hand frame lists */ 174 | .FrameTitleFont { 175 | font-family: Helvetica, Arial, sans-serif 176 | } 177 | 178 | 179 | .toggleList { 180 | padding:0; 181 | margin:0; 182 | margin-top:12px; 183 | } 184 | 185 | .toggleList dt { 186 | font-weight:bold; 187 | font-size:12px; 188 | font-family:arial,sans-serif; 189 | padding:0px; 190 | margin:10px 0px 10px 0px; 191 | } 192 | 193 | .toggleList dt span { 194 | font-family: monospace; 195 | padding:0; 196 | margin:0; 197 | } 198 | 199 | 200 | .toggleList dd { 201 | margin:0; 202 | padding:0; 203 | } 204 | 205 | html.isjs .toggleList dd { 206 | display: none; 207 | } 208 | 209 | .toggleList pre { 210 | padding: 4px 4px 4px 4px; 211 | } 212 | 213 | 214 | 215 | 216 | 217 | /* COLORS */ 218 | 219 | pre, code { 220 | color: #000000; 221 | } 222 | 223 | 224 | body { 225 | color : #333333; 226 | background-color :#FFFFFF; 227 | } 228 | 229 | 230 | h1, h2, h3, h4, h5, h6 { 231 | color:#555; 232 | } 233 | 234 | a, 235 | .toggleList dt { 236 | color: #1a7eb0; 237 | } 238 | 239 | a:hover, 240 | a:active { 241 | color: #1a7eb0; 242 | } 243 | 244 | a:visited, 245 | a:link:visited { 246 | color: #1a7eb0; 247 | } 248 | 249 | td,tr { 250 | border-color: #999999; 251 | } 252 | 253 | hr { 254 | color:#999999; 255 | background:#999999; 256 | } 257 | 258 | 259 | .TableHeadingColor { 260 | background: #dcdcdc; 261 | color: #555; 262 | } 263 | 264 | 265 | .TableSubHeadingColor { 266 | background: #EEEEFF 267 | } 268 | 269 | .TableRowColor { 270 | background: #FFFFFF 271 | } 272 | 273 | 274 | .NavBarCell1 { 275 | background-color:#dcdcdc; 276 | color:#000; 277 | } 278 | 279 | .NavBarCell1 a { 280 | color:#333; 281 | } 282 | 283 | 284 | .NavBarCell1Rev { 285 | background-color:transparent; 286 | } 287 | 288 | .NavBarFont1 { 289 | color:#333; 290 | } 291 | 292 | 293 | .NavBarFont1Rev { 294 | color:#fff; 295 | } 296 | 297 | .NavBarCell2 { 298 | background-color:#999; 299 | } 300 | 301 | .NavBarCell2 a { 302 | color:#fff; 303 | } 304 | 305 | 306 | 307 | .NavBarCell3 { 308 | background-color:#dcdcdc; 309 | } 310 | 311 | -------------------------------------------------------------------------------- /web/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | ##library.name## 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 25 | 26 | 38 | 39 |
40 | 41 |
42 |

##library.name##

43 |

44 | A library by ##author.name## for the Processing programming environment.
45 | Last update, ##date##. 46 |

47 |

48 | ##library.sentence##
49 | ##library.paragraph##
50 | Feel free to replace this paragraph with a description of the library.
51 | Contributed libraries are developed, documented, and maintained by members of the Processing community. Further directions are included with each library. For feedback and support, please post to the Discourse. We strongly encourage all libraries to be open source, but not all of them are. 52 |

53 |
54 | 55 | 56 | 57 |
58 |

Download

59 |

60 | Download ##library.name## version ##library.prettyVersion## (##library.version##) in 61 | .zip format. 62 |

63 |

Installation

64 |

65 | Unzip and put the extracted ##library.name## folder into the libraries folder of your Processing sketches. Reference and examples are included in the ##library.name## folder. 66 |

67 |
68 | 69 | 70 |
71 |

Keywords. ##library.keywords##

72 |

Reference. Have a look at the javadoc reference here. A copy of the reference is included in the .zip as well.

73 |

Source. The source code of ##library.name## is available at ##source.host##, and its repository can be browsed here.

74 |
75 | 76 | 77 |
78 |

Examples

79 |

Find a list of examples in the current distribution of ##library.name##, or have a look at them by following the links below.

80 |
    81 | ##examples## 82 |
83 |
84 | 85 | 86 |
87 |

Tested

88 |

89 | 90 | Platform ##tested.platform## 91 | 92 | 93 |
Processing ##tested.processingVersion## 94 | 95 | 96 |
Dependencies ##library.dependencies## 97 |

98 |
99 | 100 | 101 | 102 | 114 | 115 | 116 | 121 | 122 | 123 | 127 | 128 | 129 |
130 |
131 | 132 | 135 |
136 | 137 | -------------------------------------------------------------------------------- /resources/build.properties: -------------------------------------------------------------------------------- 1 | # Create libraries for the Processing open source programming language and 2 | # environment (http://www.processing.org) 3 | # 4 | # Customize the build properties to make the ant-build-process work for your 5 | # environment. How? Please read the comments below. 6 | # 7 | # The default properties are set for OSX, for Windows-settings please refer to 8 | # comments made under (1) and (2). 9 | 10 | 11 | 12 | # (1) 13 | # Where is your Processing sketchbook located? 14 | # If you are not sure, check the sketchbook location in your Processing 15 | # application preferences. 16 | # 17 | # ${user.home} points the compiler to your home directory. 18 | # For windows the default path to your sketchbook would be 19 | # ${user.home}/My Documents/Processing (make adjustments below). 20 | 21 | sketchbook.location=${user.home}/Documents/Processing 22 | 23 | 24 | 25 | # (2) 26 | # Where are the core library files located that are required for compiling 27 | # your library such as e.g. core.jar or android-core.zip? 28 | # By default the local classpath location points to folder libs inside Eclipse's 29 | # workspace (by default found in your home directory). 30 | # For Windows the default path would be ${user.home}/workspace/libs (make 31 | # adjustments below). 32 | 33 | #classpath.local.location=${user.home}/Documents/workspace/libs 34 | 35 | 36 | # For OSX users. 37 | # The following path will direct you into Processing's application source code 38 | # folder in case you put Processing inside your Applications folder. 39 | # Uncommenting the line below will overwrite the classpath.local.location from 40 | # above. 41 | 42 | classpath.local.location=/Applications/Processing.app/Contents/Resources/Java/modes/android/ 43 | 44 | 45 | # Add the Processing Android Core file (android-core.zip) that is required for 46 | # compiling your project to the local and project classpath. This file must be 47 | # inside your classpath.local.location folder. 48 | 49 | classpath.local.include=android-core.zip 50 | 51 | 52 | 53 | # Android Platform 54 | # The following paths point to the location of the version of android.jar 55 | # required to build your project. As of Processing 2.0a6, API Level 10 is the 56 | # minimum version, but your library may require a higher level if it includes 57 | # newer features like NFC or Wi-Fi direct. 58 | 59 | # android_platform.location is dependent on where you installed the Android SDK 60 | 61 | android_platform.location=${user.home}/android-sdk-macosx/platforms/android-10/ 62 | 63 | # android_platform.include will probably always be android.jar 64 | 65 | android_platform.include=android.jar 66 | 67 | 68 | # Add processing's libraries folder to the classpath. 69 | # If you don't need to include any installed libraries in the classpath, change 70 | # change this to a path that does not exist (but note that it will be created 71 | # during the build). 72 | 73 | classpath.libraries.location=${sketchbook.location}/libraries 74 | 75 | 76 | 77 | # (3) 78 | # Set the java version that should be used to compile your library. 79 | 80 | java.target.version=1.6 81 | 82 | 83 | # Set the description of the Ant build.xml file. 84 | 85 | #jra ant.description=ProcessingLibs Ant build file. 86 | ant.description=BtSerial Ant build file. 87 | 88 | 89 | 90 | # (4) 91 | # Project details. 92 | # Give your library a name. 93 | 94 | project.name=BtSerial 95 | 96 | 97 | # Use 'normal' or 'fast' as value for project.compile. 98 | # 'fast' will only compile the project into your sketchbook. 99 | # 'normal' will compile the distribution including the javadoc-reference and all 100 | # web-files (the compile process here takes longer). 101 | 102 | project.compile=normal 103 | 104 | # All files compiled with project.compile=normal are stored 105 | # in the distribution folder. 106 | 107 | 108 | 109 | # (5) 110 | # The following items are properties that will be used to make changes to the 111 | # web document templates. Values of properties will be inserted into the 112 | # documents automatically. 113 | # If you need more control, you can edit web/index.html and 114 | # web/library.properties directly. 115 | 116 | author.name=David Cuartielles, Andreas Goransson, Tom Igoe, Joshua Albers 117 | author.url=http://github.com/joshuaalbers/BtSerial 118 | 119 | 120 | # Set the web page for your library. 121 | # This is NOT a direct link to where to download it. 122 | 123 | library.url=http://github.com/joshuaalbers/BtSerial 124 | 125 | 126 | # Set the category of your library. This must be one (or many) of the following: 127 | # "3D" "Animation" "Compilations" "Data" 128 | # "Fabrication" "Geometry" "GUI" "Hardware" 129 | # "I/O" "Language" "Math" "Simulation" 130 | # "Sound" "Utilities" "Typography" "Video & Vision" 131 | # If a value other than those listed is used, your library will listed as 132 | # "Other". 133 | 134 | library.category=Hardware 135 | 136 | 137 | # A short sentence (or fragment) to summarize the library's function. This will 138 | # be shown from inside the PDE when the library is being installed. Avoid 139 | # repeating the name of your library here. Also, avoid saying anything redundant 140 | # like mentioning that it's a library. This should start with a capitalized 141 | # letter, and end with a period. 142 | 143 | library.sentence=Streamlining serial Bluetooth connections on Android devices. 144 | 145 | 146 | # Additional information suitable for the Processing website. The value of 147 | # 'sentence' always will be prepended, so you should start by writing the 148 | # second sentence here. If your library only works on certain operating systems, 149 | # mention it here. 150 | 151 | library.paragraph= 152 | 153 | 154 | # Set the source code repository for your project. 155 | # Recommendations for storing your source code online are Google Code or GitHub. 156 | 157 | source.host=Github 158 | source.url=https://github.com/joshuaalbers/BtSerial 159 | source.repository=https://github.com/joshuaalbers/BtSerial 160 | 161 | 162 | # The current version of your library. 163 | # This number must be parsable as an int. It increments once with each release. 164 | # This is used to compare different versions of the same library, and check if 165 | # an update is available. 166 | 167 | library.version=2 168 | 169 | 170 | # The version as the user will see it. 171 | # If blank, the library.version attribute will be used here. 172 | 173 | library.prettyVersion=0.2.0 174 | 175 | 176 | library.copyright=(C) 2012 177 | library.dependencies=? 178 | library.keywords=? 179 | 180 | tested.platform=osx,windows 181 | tested.processingVersion=1.5 182 | 183 | 184 | # Include javadoc references into your project's javadocs. 185 | 186 | javadoc.java.href=http://java.sun.com/javase/6/docs/api/ 187 | javadoc.processing.href=http://processing.googlecode.com/svn/trunk/processing/build/javadoc/core/ 188 | -------------------------------------------------------------------------------- /resources/code/ExampleTaglet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or 5 | * without modification, are permitted provided that the following 6 | * conditions are met: 7 | * 8 | * -Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * -Redistribution in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in 13 | * the documentation and/or other materials provided with the 14 | * distribution. 15 | * 16 | * Neither the name of Sun Microsystems, Inc. or the names of 17 | * contributors may be used to endorse or promote products derived 18 | * from this software without specific prior written permission. 19 | * 20 | * This software is provided "AS IS," without a warranty of any 21 | * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND 22 | * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, 23 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY 24 | * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY 25 | * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR 26 | * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR 27 | * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE 28 | * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, 29 | * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER 30 | * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF 31 | * THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN 32 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 33 | * 34 | * You acknowledge that Software is not designed, licensed or 35 | * intended for use in the design, construction, operation or 36 | * maintenance of any nuclear facility. 37 | */ 38 | 39 | import com.sun.tools.doclets.Taglet; 40 | import com.sun.javadoc.*; 41 | import java.util.Map; 42 | import java.io.*; 43 | /** 44 | * A sample Taglet representing @example. This tag can be used in any kind of 45 | * {@link com.sun.javadoc.Doc}. It is not an inline tag. The text is displayed 46 | * in yellow to remind the developer to perform a task. For 47 | * example, "@example Hello" would be shown as: 48 | *
49 | *
50 | * To Do: 51 | *
Fix this! 52 | *
53 | *
54 | * 55 | * @author Jamie Ho 56 | * @since 1.4 57 | */ 58 | 59 | public class ExampleTaglet implements Taglet { 60 | 61 | private static final String NAME = "example"; 62 | private static final String HEADER = "example To Do:"; 63 | 64 | /** 65 | * Return the name of this custom tag. 66 | */ 67 | public String getName() { 68 | return NAME; 69 | } 70 | 71 | /** 72 | * Will return true since @example 73 | * can be used in field documentation. 74 | * @return true since @example 75 | * can be used in field documentation and false 76 | * otherwise. 77 | */ 78 | public boolean inField() { 79 | return true; 80 | } 81 | 82 | /** 83 | * Will return true since @example 84 | * can be used in constructor documentation. 85 | * @return true since @example 86 | * can be used in constructor documentation and false 87 | * otherwise. 88 | */ 89 | public boolean inConstructor() { 90 | return true; 91 | } 92 | 93 | /** 94 | * Will return true since @example 95 | * can be used in method documentation. 96 | * @return true since @example 97 | * can be used in method documentation and false 98 | * otherwise. 99 | */ 100 | public boolean inMethod() { 101 | return true; 102 | } 103 | 104 | /** 105 | * Will return true since @example 106 | * can be used in method documentation. 107 | * @return true since @example 108 | * can be used in overview documentation and false 109 | * otherwise. 110 | */ 111 | public boolean inOverview() { 112 | return true; 113 | } 114 | 115 | /** 116 | * Will return true since @example 117 | * can be used in package documentation. 118 | * @return true since @example 119 | * can be used in package documentation and false 120 | * otherwise. 121 | */ 122 | public boolean inPackage() { 123 | return true; 124 | } 125 | 126 | /** 127 | * Will return true since @example 128 | * can be used in type documentation (classes or interfaces). 129 | * @return true since @example 130 | * can be used in type documentation and false 131 | * otherwise. 132 | */ 133 | public boolean inType() { 134 | return true; 135 | } 136 | 137 | /** 138 | * Will return false since @example 139 | * is not an inline tag. 140 | * @return false since @example 141 | * is not an inline tag. 142 | */ 143 | 144 | public boolean isInlineTag() { 145 | return false; 146 | } 147 | 148 | /** 149 | * Register this Taglet. 150 | * @param tagletMap the map to register this tag to. 151 | */ 152 | public static void register(Map tagletMap) { 153 | ExampleTaglet tag = new ExampleTaglet(); 154 | Taglet t = (Taglet) tagletMap.get(tag.getName()); 155 | if (t != null) { 156 | tagletMap.remove(tag.getName()); 157 | } 158 | tagletMap.put(tag.getName(), tag); 159 | } 160 | 161 | /** 162 | * Given the Tag representation of this custom 163 | * tag, return its string representation. 164 | * @param tag the Tag representation of this custom tag. 165 | */ 166 | public String toString(Tag tag) { 167 | return createHTML(readFile(tag.text())); 168 | } 169 | 170 | 171 | /** 172 | * Given an array of Tags representing this custom 173 | * tag, return its string representation. 174 | * @param tags the array of Tags representing of this custom tag. 175 | */ 176 | public String toString(Tag[] tags) { 177 | if (tags.length == 0) { 178 | return null; 179 | } 180 | return createHTML(readFile(tags[0].text())); 181 | } 182 | 183 | 184 | 185 | String createHTML(String theString) { 186 | if(theString!=null) { 187 | String dd = ""; 193 | 194 | return dd+"\n
" + 195 | "
+Example
" + 196 | "
"+theString+"
" + 197 | "
"; 198 | } 199 | return ""; 200 | } 201 | 202 | 203 | /** 204 | * check if the examples directory exists and return the example as given in the tag. 205 | * @param theExample the name of the example 206 | */ 207 | String readFile(String theExample) { 208 | String record = ""; 209 | String myResult = ""; 210 | int recCount = 0; 211 | String myDir = "../examples"; 212 | File file=new File(myDir); 213 | if(file.exists()==false) { 214 | myDir = "./examples"; 215 | } 216 | try { 217 | FileReader fr = new FileReader(myDir+"/"+theExample+"/"+theExample+".pde"); 218 | BufferedReader br = new BufferedReader(fr); 219 | record = new String(); 220 | while ((record = br.readLine()) != null) { 221 | myResult += record+"\n"; 222 | } 223 | } catch (IOException e) { 224 | System.out.println(e); 225 | return null; 226 | } 227 | return myResult; 228 | } 229 | } 230 | 231 | 232 | -------------------------------------------------------------------------------- /lgpl.txt: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /src/cc/arduino/btserial/ConnectedThread.java: -------------------------------------------------------------------------------- 1 | /** 2 | * ##project.name## 3 | * ##library.sentence## 4 | * 5 | * ##copyright## 6 | * 7 | * This file is part of BtSerial. 8 | * 9 | * BtSerial is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * BtSerial is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with BtSerial. If not, see . 21 | * 22 | * @author ##author## 23 | * @modified ##date## 24 | * @version ##library.prettyVersion## 25 | */ 26 | 27 | 28 | package cc.arduino.btserial; 29 | 30 | import java.io.IOException; 31 | import java.io.InputStream; 32 | import java.io.OutputStream; 33 | import java.util.UUID; 34 | 35 | import android.bluetooth.BluetoothServerSocket; 36 | import android.bluetooth.BluetoothSocket; 37 | import android.util.Log; 38 | 39 | public class ConnectedThread extends Thread { 40 | private final BluetoothSocket mmSocket; 41 | private final int mBufferLength; 42 | protected final InputStream mmInStream; 43 | protected final OutputStream mmOutStream; 44 | 45 | private int bufferlength = 128; 46 | private byte[] rawbuffer; 47 | private byte[] buffer; 48 | private int bufferIndex; 49 | private int bufferLast; 50 | private int available; 51 | private final String TAG = "System.out"; 52 | 53 | private BtSerial mBtSerial; 54 | 55 | public ConnectedThread(BluetoothSocket socket, int bufferLength, 56 | BtSerial mBtSerial) { 57 | this.mBtSerial = mBtSerial; 58 | mmSocket = socket; 59 | 60 | InputStream tmpIn = null; 61 | OutputStream tmpOut = null; 62 | mBufferLength = bufferLength; 63 | 64 | // Get the input and output streams, using temp objects because 65 | // member streams are final 66 | try { 67 | tmpIn = socket.getInputStream(); 68 | tmpOut = socket.getOutputStream(); 69 | } catch (IOException e) { 70 | } 71 | 72 | mmInStream = tmpIn; 73 | mmOutStream = tmpOut; 74 | 75 | buffer = new byte[mBufferLength]; // buffer store for the stream 76 | // Log.i(TAG, "started"); 77 | } 78 | 79 | @Override 80 | public void run() { 81 | // Log.i(TAG, "ConnectedThread running"); 82 | 83 | // Keep listening to the InputStream until an exception occurs 84 | while (true) { 85 | try { 86 | //String outputMessage = mmInStream.available() + " bytes available"; 87 | //Log.i(TAG, outputMessage); 88 | // Read from the InputStream 89 | while (mmInStream.available() > 0) { 90 | 91 | synchronized (buffer) { 92 | if (bufferLast == buffer.length) { 93 | byte temp[] = new byte[bufferLast << 1]; 94 | System.arraycopy(buffer, 0, temp, 0, bufferLast); 95 | buffer = temp; 96 | } 97 | buffer[bufferLast++] = (byte) mmInStream.read(); 98 | } 99 | btSerialEvent(); 100 | } 101 | } catch (IOException e) { 102 | Log.e(TAG, e.getMessage()); 103 | break; 104 | } 105 | } 106 | } 107 | 108 | public void btSerialEvent() { 109 | mBtSerial.btSerialEvent(); 110 | // Log.i(TAG, "btSerialEvent called from ConnectedThread"); 111 | } 112 | 113 | /* Call this from the main Activity to send data to the remote device */ 114 | public void write(byte[] bytes) { 115 | try { 116 | for(int i=0; i outgoing.length) 177 | length = outgoing.length; 178 | System.arraycopy(buffer, bufferIndex, outgoing, 0, length); 179 | 180 | bufferIndex += length; 181 | if (bufferIndex == bufferLast) { 182 | bufferIndex = 0; // rewind 183 | bufferLast = 0; 184 | } 185 | return length; 186 | } 187 | } 188 | 189 | /** 190 | * Returns a byte buffer until the byte interesting. If the byte interesting 191 | * doesn't exist in the current buffer, null is returned. 192 | * 193 | * @param interesting 194 | * @return 195 | */ 196 | public byte[] readBytesUntil(int interesting) { 197 | if (bufferIndex == bufferLast) 198 | return null; 199 | byte what = (byte) interesting; 200 | 201 | synchronized (buffer) { 202 | int found = -1; 203 | for (int k = bufferIndex; k < bufferLast; k++) { 204 | if (buffer[k] == what) { 205 | found = k; 206 | break; 207 | } 208 | } 209 | if (found == -1) 210 | return null; 211 | 212 | int length = found - bufferIndex + 1; 213 | byte outgoing[] = new byte[length]; 214 | System.arraycopy(buffer, bufferIndex, outgoing, 0, length); 215 | 216 | bufferIndex += length; 217 | if (bufferIndex == bufferLast) { 218 | bufferIndex = 0; // rewind 219 | bufferLast = 0; 220 | } 221 | return outgoing; 222 | } 223 | } 224 | 225 | // 226 | // /** 227 | // * TODO 228 | // * 229 | // * @param b 230 | // * @param buffer 231 | // */ 232 | // public void readBytesUntil(byte b, byte[] buffer) { 233 | // Log.i(TAG, "Will do a.s.a.p."); 234 | // } 235 | 236 | /** 237 | * Sets the number of bytes to buffer. 238 | * 239 | * @param bytes 240 | * @return 241 | */ 242 | public int buffer(int bytes) { 243 | bufferlength = bytes; 244 | 245 | buffer = new byte[bytes]; 246 | rawbuffer = buffer.clone(); 247 | 248 | return bytes; 249 | } 250 | 251 | /** 252 | * Returns the last byte in the buffer. 253 | * 254 | * @return 255 | */ 256 | public int last() { 257 | if (bufferIndex == bufferLast) 258 | return -1; 259 | synchronized (buffer) { 260 | int outgoing = buffer[bufferLast - 1]; 261 | bufferIndex = 0; 262 | bufferLast = 0; 263 | return outgoing; 264 | } 265 | } 266 | 267 | /** 268 | * Reads a byte from the buffer as char. 269 | * 270 | * @return 271 | */ 272 | public char readChar() { 273 | if (bufferIndex == bufferLast) 274 | return (char) (-1); 275 | return (char) last(); 276 | } 277 | 278 | /** 279 | * Returns the last byte in the buffer as char. 280 | * 281 | * @return 282 | */ 283 | public char lastChar() { 284 | if (bufferIndex == bufferLast) 285 | return (char) (-1); 286 | return (char) last(); 287 | } 288 | 289 | public int available() { 290 | return (bufferLast - bufferIndex); 291 | } 292 | 293 | /** 294 | * Ignore all the bytes read so far and empty the buffer. 295 | */ 296 | public void clear() { 297 | bufferLast = 0; 298 | bufferIndex = 0; 299 | } 300 | 301 | /* Call this from the main Activity to shutdown the connection */ 302 | public void cancel() { 303 | try { 304 | mmSocket.close(); 305 | } catch (IOException e) { 306 | e.printStackTrace(); 307 | } 308 | } 309 | } -------------------------------------------------------------------------------- /resources/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | ${ant.description} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | ${line} 86 | Building the Processing library ${project.name} ${library.version} 87 | ${line} 88 | src path ${project.src} 89 | bin path ${project.bin} 90 | classpath.local ${classpath.local.location} 91 | sketchbook ${sketchbook.location} 92 | java version ${java.target.version} 93 | ${line} 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | ${exampleDir} 342 | 348 | 349 | 355 | 356 | 357 | 358 | 359 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | ${line} 378 | Name ${project.name} 379 | Version ${library.prettyVersion} (${library.version}) 380 | Compiled ${project.compile} 381 | Sketchbook ${sketchbook.location} 382 | ${line} 383 | done, finished. 384 | ${line} 385 | 386 | 387 | 388 | 389 | 390 | -------------------------------------------------------------------------------- /src/cc/arduino/btserial/BtSerial.java: -------------------------------------------------------------------------------- 1 | /** 2 | * ##project.name## 3 | * ##library.sentence## 4 | * 5 | * ##copyright## 6 | * 7 | * This file is part of BtSerial. 8 | * 9 | * BtSerial is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * BtSerial is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with BtSerial. If not, see . 21 | * 22 | * @author ##author## 23 | * @modified ##date## 24 | * @version ##library.prettyVersion## 25 | */ 26 | 27 | package cc.arduino.btserial; 28 | 29 | import java.io.IOException; 30 | import java.io.InputStream; 31 | import java.io.OutputStream; 32 | import java.util.Set; 33 | import java.util.UUID; 34 | import java.util.Vector; 35 | import java.lang.reflect.*; 36 | 37 | import android.bluetooth.BluetoothAdapter; 38 | import android.bluetooth.BluetoothDevice; 39 | import android.bluetooth.BluetoothServerSocket; 40 | import android.bluetooth.BluetoothSocket; 41 | import android.content.BroadcastReceiver; 42 | import android.content.Context; 43 | import android.content.Intent; 44 | import android.content.IntentFilter; 45 | import android.os.Handler; 46 | import android.os.Looper; 47 | import android.util.Log; 48 | 49 | /* TODO */ 50 | // ** buffer() 51 | // bufferUntil() 52 | // btSerialEvent() 53 | 54 | public class BtSerial { 55 | 56 | /* PApplet context */ 57 | private Context ctx; 58 | 59 | public final static String VERSION = "##library.prettyVersion##"; 60 | 61 | /* Bluetooth */ 62 | private BluetoothAdapter mAdapter; 63 | private BluetoothDevice mDevice; 64 | private UUID uuidSpp = UUID 65 | .fromString("00001101-0000-1000-8000-00805F9B34FB"); 66 | // private UUID uuidSecure = UUID 67 | // .fromString("fa87c0d0-afac-11de-8a39-0800200c9a66"); 68 | // private UUID uuidInecure = UUID 69 | // .fromString("8ce255c0-200a-11e0-ac64-0800200c9a66"); 70 | 71 | /* Socket & streams for BT communication */ 72 | private BluetoothSocket mSocket; 73 | private ConnectedThread mConnectedThread; 74 | private boolean connected = false; 75 | 76 | /* Buffer */ 77 | private int bufferlength = 128; 78 | private int available = 0; 79 | private byte[] buffer; 80 | private byte[] rawbuffer; 81 | private int bufferIndex; 82 | private int bufferLast; 83 | 84 | Method btSerialEventMethod; 85 | 86 | /* Debug variables */ 87 | public static boolean DEBUG = true; 88 | public static String DEBUGTAG = "##library.name## " + VERSION 89 | + " Debug message: "; 90 | 91 | private final String TAG = "System.out"; 92 | 93 | public BtSerial(Context ctx) { 94 | this.ctx = ctx; 95 | welcome(); 96 | 97 | Looper.prepare(); // this line is necessary to get BtSerial to 98 | // initialize on my Nook Color running Cyanogenmod, 99 | // but it is not required on my Galaxy Nexus running 100 | // ICS. I don't get it. 101 | 102 | try { 103 | mAdapter = BluetoothAdapter.getDefaultAdapter(); 104 | } catch (Exception e) { 105 | Log.e(TAG, Log.getStackTraceString(e)); 106 | } 107 | // Log.i(TAG, "BluetoothAdapter started"); 108 | 109 | // reflection to check whether host applet has a call for 110 | // public void serialEvent(processing.serial.Serial) 111 | // which would be called each time an event comes in 112 | try { 113 | btSerialEventMethod = ctx.getClass().getMethod("btSerialEvent", 114 | new Class[] { BtSerial.class }); 115 | } catch (Exception e) { 116 | // no such method, or an error.. which is fine, just ignore 117 | } 118 | } 119 | 120 | /* 121 | * Callback triggered whenever there is data in the buffer. 122 | */ 123 | 124 | public void btSerialEvent() { 125 | if (btSerialEventMethod != null) { 126 | try { 127 | btSerialEventMethod.invoke(ctx, new Object[] { this }); 128 | // Log.i(TAG, "btSerialEvent called from BtSerial"); 129 | } catch (Exception e) { 130 | String msg = "error, disabling btSerialEvent() for " 131 | + mDevice.getName(); 132 | Log.e(TAG, msg); 133 | e.printStackTrace(); 134 | btSerialEventMethod = null; 135 | } 136 | } 137 | } 138 | 139 | /** 140 | * Returns the status of the connection. 141 | * 142 | * @return true or false 143 | */ 144 | public boolean isConnected() { 145 | return connected; 146 | } 147 | 148 | /** 149 | * Returns whether the Bluetooth dapter is enabled. 150 | * 151 | * @return true of false 152 | */ 153 | public boolean isEnabled() { 154 | if (mAdapter != null) 155 | return mAdapter.isEnabled(); 156 | else 157 | return false; 158 | } 159 | 160 | /** 161 | * Returns a list of bonded (paired) devices. 162 | * 163 | * @param info 164 | * flag to control display of additional information (device 165 | * names and types) 166 | * @return String array 167 | */ 168 | public String[] list(boolean info) { 169 | Vector list = new Vector(); 170 | Set devices; 171 | 172 | try { 173 | devices = mAdapter.getBondedDevices(); 174 | // convert the devices 'set' into an array so that we can 175 | // perform string functions on it 176 | Object[] deviceArray = devices.toArray(); 177 | // step through it and assign each device in turn to 178 | // remoteDevice and then print it's name 179 | for (int i = 0; i < devices.size(); i++) { 180 | BluetoothDevice thisDevice = mAdapter 181 | .getRemoteDevice(deviceArray[i].toString()); 182 | String element = thisDevice.getAddress(); 183 | if (info) { 184 | element += "," 185 | + thisDevice.getName() 186 | + "," 187 | + thisDevice.getBluetoothClass() 188 | .getMajorDeviceClass(); // extended 189 | // information 190 | } 191 | list.addElement(element); 192 | } 193 | } catch (UnsatisfiedLinkError e) { 194 | Log.e(TAG, Log.getStackTraceString(e)); 195 | } catch (Exception e) { 196 | Log.e(TAG, Log.getStackTraceString(e)); 197 | } 198 | 199 | String outgoing[] = new String[list.size()]; 200 | list.copyInto(outgoing); 201 | return outgoing; 202 | } 203 | 204 | /** 205 | * Returns a list of hardware (MAC) addresses of bonded (paired) devices. 206 | * 207 | * @return String array 208 | */ 209 | 210 | public String[] list() { 211 | return list(false); 212 | } 213 | 214 | /** 215 | * Returns the name of the connected remote device It not connected, returns 216 | * "-1" 217 | */ 218 | 219 | public String getRemoteName() { 220 | if (connected) { 221 | String info = mDevice.getName(); 222 | return (info); 223 | } else { 224 | return ("-1"); 225 | } 226 | } 227 | 228 | /** 229 | * Returns the name of the connected remote device It not connected, returns 230 | * "-1" 231 | */ 232 | 233 | public String getRemoteAddress() { 234 | if (connected) { 235 | String info = mDevice.getAddress(); 236 | return (info); 237 | } else { 238 | return ("-1"); 239 | } 240 | } 241 | 242 | /* 243 | * Some stubs for future implementation: 244 | */ 245 | // public void startDiscovery() { 246 | // // this method will start a separate thread to handle discovery 247 | // } 248 | // 249 | // public void pairWith(String thisAddress) { 250 | // // this method will pair with a device given a MAC address 251 | // } 252 | // 253 | // public boolean discoveryComplete() { 254 | // // this method will return whether discovery is complete, 255 | // // so the user can then list devices 256 | // return false; 257 | // } 258 | 259 | /** 260 | * Returns the name of the currently connected device. 261 | * 262 | * @return String 263 | */ 264 | 265 | public String getName() { 266 | if (mDevice != null) 267 | return mDevice.getName(); 268 | else 269 | return "no device connected"; 270 | } 271 | 272 | /** 273 | * Connects to a Bluetooth device. 274 | * 275 | * The connect() method will attempt to determine what type of device is 276 | * currently specified by mac and will select one of the following Service 277 | * Profile UUIDs accordingly. 278 | *

279 | * Currently only Android-to-serial modem (Arduino) and Android- to-serial 280 | * port (computer) connections are supported. 281 | *

282 | * 283 | * @param mac 284 | * - hardware (MAC) address of the remote device 285 | * @return boolean flag for if connection was successful 286 | */ 287 | 288 | public synchronized boolean connect(String mac) { 289 | /* Before we connect, make sure to cancel any discovery! */ 290 | if (mAdapter.isDiscovering()) { 291 | mAdapter.cancelDiscovery(); 292 | Log.i(TAG, "Cancelled ongoing discovery"); 293 | } 294 | 295 | /* Make sure we're using a real bluetooth address to connect with */ 296 | if (BluetoothAdapter.checkBluetoothAddress(mac)) { 297 | /* Get the remote device we're trying to connect to */ 298 | mDevice = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(mac); 299 | /* Create the RFCOMM sockets */ 300 | try { 301 | 302 | mSocket = mDevice.createRfcommSocketToServiceRecord(uuidSpp); 303 | // Log.i(TAG, "connecting to uncategorized"); 304 | 305 | mSocket.connect(); 306 | 307 | // Start the thread to manage the connection and perform 308 | // transmissions 309 | mConnectedThread = new ConnectedThread(mSocket, bufferlength, 310 | this); 311 | mConnectedThread.start(); 312 | 313 | Log.i(TAG, "Connected to device " + mDevice.getName() + " [" 314 | + mDevice.getAddress() + "]"); 315 | // Set the status 316 | connected = true; 317 | return connected; 318 | } catch (IOException e) { 319 | Log.i(TAG, "Couldn't get a connection"); 320 | Log.e(TAG, e.getMessage()); 321 | connected = false; 322 | return connected; 323 | } 324 | 325 | } else { 326 | Log.i(TAG, "Address is not Bluetooth, please verify MAC."); 327 | connected = false; 328 | return connected; 329 | } 330 | } 331 | 332 | /** 333 | * Opens a BluetoothServerSocket to listen for connections Primarily 334 | * intended for Android-to-Android connections using UUID 335 | * fa87c0d0-afac-11de-8a39-0800200c9a66 336 | * 337 | * @return 338 | */ 339 | public synchronized void listen() { 340 | AcceptThread listenThread = new AcceptThread(); 341 | listenThread.start(); 342 | } 343 | 344 | /** 345 | * This thread runs while listening for incoming connections. It behaves 346 | * like a server-side client. It runs until a connection is accepted (or 347 | * until cancelled). 348 | * 349 | * Based on the Android BluetoothChat example 350 | */ 351 | private class AcceptThread extends Thread { 352 | // The local server socket 353 | private final BluetoothServerSocket mServerSocket; 354 | 355 | public AcceptThread() { 356 | BluetoothServerSocket tmp = null; 357 | // Create a new listening server socket 358 | try { 359 | tmp = mAdapter.listenUsingRfcommWithServiceRecord( 360 | "SerialPortProfile", uuidSpp); 361 | } catch (IOException e) { 362 | Log.e(TAG, "Socket listen() failed", e); 363 | } 364 | mServerSocket = tmp; 365 | } 366 | 367 | public void run() { 368 | 369 | mSocket = null; 370 | 371 | // Listen to the server socket if we're not connected 372 | while (!isConnected()) { 373 | try { 374 | // This is a blocking call and will only return on a 375 | // successful connection or an exception 376 | mSocket = mServerSocket.accept(); 377 | mDevice = mSocket.getRemoteDevice(); 378 | } catch (IOException e) { 379 | Log.e(TAG, "Socket accept() failed", e); 380 | break; 381 | } 382 | 383 | // If a connection was accepted 384 | if (mSocket != null) { 385 | synchronized (BtSerial.this) { 386 | if (!isConnected()) { 387 | try { 388 | // Situation normal. Start the connected thread. 389 | mConnectedThread = new ConnectedThread(mSocket, 390 | bufferlength, BtSerial.this); 391 | mConnectedThread.start(); 392 | Log.i(TAG, 393 | "Connected to device " 394 | + mDevice.getName() + " [" 395 | + mDevice.getAddress() + "]"); 396 | // Set the status 397 | connected = true; 398 | } catch (Exception ex) { 399 | Log.i(TAG, "Couldn't get a connection"); 400 | Log.e(TAG, ex.getMessage()); 401 | connected = false; 402 | } 403 | 404 | } else { 405 | try { 406 | mSocket.close(); 407 | } catch (IOException e) { 408 | Log.e(TAG, "Could not close unwanted socket", e); 409 | } 410 | break; 411 | } 412 | } 413 | } 414 | } 415 | } 416 | 417 | public void cancel() { 418 | try { 419 | mServerSocket.close(); 420 | } catch (IOException e) { 421 | Log.e(TAG, "Socket close() of server failed", e); 422 | } 423 | } 424 | } 425 | 426 | /** 427 | * Returns the available number of bytes in the buffer. 428 | * 429 | * @return 430 | */ 431 | public int available() { 432 | return mConnectedThread.available(); 433 | } 434 | 435 | /** 436 | * Displays the Library welcome message 437 | */ 438 | private void welcome() { 439 | Log.i(TAG, "##library.name## " + VERSION + " by ##author##"); 440 | } 441 | 442 | /** 443 | * return the version of the library. 444 | * 445 | * @return String 446 | */ 447 | public static String version() { 448 | return VERSION; 449 | } 450 | 451 | /** 452 | * Writes a byte[] buffer to the output stream. 453 | * 454 | * @param buffer 455 | */ 456 | public void write(byte[] buffer) { 457 | // Create temporary object 458 | ConnectedThread r; 459 | // Synchronize a copy of the ConnectedThread 460 | synchronized (this) { 461 | if (!connected) 462 | return; 463 | r = mConnectedThread; 464 | } 465 | // Perform the write unsynchronized 466 | r.write(buffer); 467 | } 468 | 469 | /** 470 | * Writes a String to the output stream. 471 | * 472 | * @param thisString 473 | */ 474 | public void write(String thisString) { 475 | byte[] thisBuffer = thisString.getBytes(); 476 | write(thisBuffer); 477 | } 478 | 479 | /** 480 | * Writes a String to the output stream. 481 | * 482 | * @param thisInt 483 | */ 484 | public void write(int thisInt) { 485 | byte[] thisBuffer = { (byte) thisInt }; 486 | write(thisBuffer); 487 | } 488 | 489 | /** 490 | * Returns the next byte in the buffer as an int (0-255); 491 | * 492 | * @return 493 | */ 494 | public int read() { 495 | return mConnectedThread.read(); 496 | } 497 | 498 | /** 499 | * Returns the whole byte buffer. 500 | * 501 | * @return 502 | */ 503 | public byte[] readBytes() { 504 | return mConnectedThread.readBytes(); 505 | } 506 | 507 | /** 508 | * Returns the available number of bytes in the buffer, and copies the 509 | * buffer contents to the passed byte[] 510 | * 511 | * @param outgoing 512 | * [] 513 | * @return 514 | */ 515 | public int readBytes(byte outgoing[]) { 516 | mConnectedThread.readBytes(outgoing); 517 | return outgoing.length; 518 | } 519 | 520 | /** 521 | * Returns a byte buffer until the byte interesting. If the byte interesting 522 | * doesn't exist in the current buffer, null is returned. 523 | * 524 | * @param interesting 525 | * @return array of bytes retreived from buffer 526 | */ 527 | public byte[] readBytesUntil(byte interesting) { 528 | return mConnectedThread.readBytesUntil(interesting); 529 | } 530 | 531 | // /** 532 | // * TODO 533 | // * 534 | // * @param b 535 | // * @param buffer 536 | // */ 537 | // public void readBytesUntil(byte b, byte[] buffer) { 538 | // Log.i(TAG, "Will do a.s.a.p."); 539 | // } 540 | 541 | /** 542 | * Read the next byte in the buffer as a char 543 | * 544 | * @return next byte in the buffer as a char; if nothing is there it returns 545 | * -1. 546 | */ 547 | public char readChar() { 548 | return (char) read(); 549 | } 550 | 551 | /** 552 | * Returns the buffer as a string. 553 | * 554 | * @return contents of the buffer as a String 555 | */ 556 | public String readString() { 557 | String returnstring = new String(readBytes()); 558 | return returnstring; 559 | } 560 | 561 | /** 562 | * Returns the buffer as string until character c. 563 | * 564 | * @param c 565 | * - character to read until 566 | * @return String data read before encountering c 567 | */ 568 | public String readStringUntil(char c) { 569 | /* Get the buffer as string */ 570 | String stringbuffer = readString(); 571 | 572 | int index; 573 | /* Make sure that the character exists in the string */ 574 | if ((index = stringbuffer.indexOf(c)) > 0) { 575 | return stringbuffer.substring(0, index); 576 | } else { 577 | return null; 578 | } 579 | } 580 | 581 | /** 582 | * Sets the number of bytes to buffer. 583 | * 584 | * @param bytes 585 | * new size of the buffer 586 | * @return 587 | */ 588 | public int buffer(int bytes) { 589 | return mConnectedThread.buffer(bytes); 590 | } 591 | 592 | /** 593 | * Returns the last byte in the buffer. 594 | * 595 | * @return the last byte in the buffer 596 | * @see char() 597 | */ 598 | public int last() { 599 | return buffer[buffer.length - 1]; 600 | } 601 | 602 | /** 603 | * Returns the last byte in the buffer as char. 604 | * 605 | * @return the last char in the buffer. 606 | * @see last() 607 | */ 608 | public char lastChar() { 609 | return (char) buffer[buffer.length - 1]; 610 | } 611 | 612 | /** 613 | * Clears the byte buffer. 614 | */ 615 | public void clear() { 616 | mConnectedThread.clear(); 617 | } 618 | 619 | /** 620 | * Disconnects the Bluetooth socket. 621 | * 622 | * This should be called in the pause() and stop() methods inside the sketch 623 | * in order to ensure that the socket is properly closed when the sketch is 624 | * not running. The connection should be re-established in a resume() method 625 | * if the sketch loses and then regains focus. 626 | * 627 | * @see connect() 628 | */ 629 | public synchronized void disconnect() { 630 | if (connected) { 631 | try { 632 | // kill the connected thread if it's running: 633 | if (mConnectedThread != null) { 634 | mConnectedThread.cancel(); 635 | mConnectedThread = null; 636 | } 637 | 638 | /* Close the socket */ 639 | mSocket.close(); 640 | 641 | /* Set the connected state */ 642 | connected = false; 643 | /* If it successfully closes I guess we just return a success? */ 644 | // return 0; 645 | // Log.i(TAG, "disconnected."); 646 | } catch (IOException e) { 647 | // TODO Auto-generated catch block 648 | Log.i(TAG, "whoops! disconnect() encountred an error."); 649 | e.printStackTrace(); 650 | /* Otherwise we'll go ahead and say "no, this didn't work well!" */ 651 | // return 1; 652 | } 653 | } 654 | } 655 | 656 | /** 657 | * Kills the main thread. Shouldn't stop when the connection disconnects. 658 | * 659 | * @return 660 | */ 661 | public void stop() { 662 | 663 | } 664 | } 665 | -------------------------------------------------------------------------------- /gpl.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------