Merge pull request #132 from designsystemsinternational/master

This commit is contained in:
Ben Fry
2020-09-17 12:26:35 -04:00
committed by GitHub
65 changed files with 7447 additions and 3702 deletions

View File

@@ -32,7 +32,10 @@ import java.util.Map;
/**
* @webref
* The GPIO class reads and writes from General Purpose I/O pins
*
* @webref GPIO
* @webBrief The GPIO class reads and writes from General Purpose I/O pins
*/
public class GPIO {
@@ -89,7 +92,19 @@ public class GPIO {
/**
* Calls a function when the value of an input pin changes
* Calls a function when the value of an input pin changes<br/>
* <br/>
* The sketch method provided must accept a single integer (int) parameter, which is the
* number of the GPIO pin that the interrupt occured on. As this method might be called
* at any time, including when drawing to the display window isn't permitted, it is best
* to only set simple variables that are being responded to in the next draw() call, as
* shown above. Calling functions of the Hardware I/O library at this point is certainly
* possible.<br/>
* <br/>
* The mode parameter determines when the function will be called: GPIO.FALLING occurs
* when the level changes from high to low, GPIO.RISING when the level changes from low
* to high, and GPIO.CHANGE when either occurs.
*
* @param pin GPIO pin
* @param parent typically use "this"
* @param method name of sketch method to call
@@ -97,7 +112,8 @@ public class GPIO {
* @see noInterrupts
* @see interrupts
* @see releaseInterrupt
* @webref
* @webref GPIO
* @webBrief Calls a function when the value of an input pin changes
*/
public static void attachInterrupt(int pin, PApplet parent, String method, int mode) {
if (irqThreads.containsKey(pin)) {
@@ -167,12 +183,18 @@ public class GPIO {
/**
* Returns the value of an input pin
* Returns the value of an input pin, which is either GPIO.HIGH (1)
* or GPIO.LOW (0)<br/>
* <br/>
* You need to set the pin to input by calling <a href="GPIO_pinMode_.html">
* pinMode()</a> before calling this function.
*
* @param pin GPIO pin
* @return GPIO.HIGH (1) or GPIO.LOW (0)
* @see pinMode
* @see digitalWrite
* @webref
* @webref GPIO
* @webBrief Returns the value of an input pin
*/
public static int digitalRead(int pin) {
checkValidPin(pin);
@@ -202,12 +224,18 @@ public class GPIO {
/**
* Sets an output pin to be either high or low
* Sets an output pin to be either high or low<br/>
* <br/>
* You need to set the pin to output by calling <a href="GPIO_pinMode_.html">pinMode()</a>
* before calling this function. Unlike on Arduino, it is not possible to set a input pin's
* internal pull-up resistor using this function.
*
* @param pin GPIO pin
* @param value GPIO.HIGH (1) or GPIO.LOW (0)
* @see pinMode
* @see digitalRead
* @webref
* @webref GPIO
* @webBrief Sets an output pin to be either high or low
*/
public static void digitalWrite(int pin, int value) {
checkValidPin(pin);
@@ -302,11 +330,18 @@ public class GPIO {
/**
* Allows interrupts to happen
* Allows interrupts to happen<br/>
* <br/>
* You can use <a href="GPIO_noInterrupts_.html">noInterrupts()</a>
* and interrupts() in tandem to make sure no interrupts are occuring
* while your sketch is doing a particular task. By default, interrupts
* are enabled.
*
* @see attachInterrupt
* @see noInterrupts
* @see releaseInterrupt
* @webref
* @webref GPIO
* @webBrief Allows interrupts to happen
*/
public static void interrupts() {
serveInterrupts = true;
@@ -314,11 +349,22 @@ public class GPIO {
/**
* Prevents interrupts from happpening
* Prevents interrupts from happpening<br/>
* <br/>
* You can use noInterrupts() and <a href="GPIO_interrupts_.html">interrupts()</a>
* in tandem to make sure no interrupts are occuring while your sketch is doing a
* particular task.<br/>
* br/>
* While a method associated with a pin's interrupt is being executed, interrupts
* from the same pin are automatically prevented from occurring. Interrupts from
* other pins can still happen, however. If you also want to prevent those, put
* noInterrupts() at the beginning of your callback function and interrupts() at its end.
*
* @see attachInterrupt
* @see interrupts
* @see releaseInterrupt
* @webref
* @webref GPIO
* @webBrief Prevents interrupts from happpening
*/
public static void noInterrupts() {
serveInterrupts = false;
@@ -326,13 +372,28 @@ public class GPIO {
/**
* Configures a pin to act either as input or output
* Configures a pin to act either as input (<b>INPUT</b>), or input with internal pull-up
* resistor (<b>INPUT_PULLUP</b>), or input with internal pull-down resistor (<b>INPUT_PULLDOWN</b>)
* or output (<b>OUTPUT</b>)<br/>
* <br/>
* Unlike on Arduino, where pins are implicitly set to inputs by default, it is necessary
* to call this function for any pin you want to access, including input pins.<br/>
* <br/>
* Pull-up and pull-down resistors are very useful when connecting buttons and switches,
* since they will force the value of the pin in a specified electrical state when no
* electrical connection is made, and the pin would otherwise be left "floating".<br/>
* <br/>
* The ability to set (and clear) pull-up and pull-down resistors is currently limited
* to the Raspberry Pi running the Raspbian distribution. On other systems, a warning
* will be shown.
*
* @param pin GPIO pin
* @param mode GPIO.INPUT, GPIO.INPUT_PULLUP, GPIO.INPUT_PULLDOWN, or GPIO.OUTPUT
* @see digitalRead
* @see digitalWrite
* @see releasePin
* @webref
* @webref GPIO
* @webBrief Configures a pin to act either as input or output
*/
public static void pinMode(int pin, int mode) {
checkValidPin(pin);
@@ -406,11 +467,13 @@ public class GPIO {
/**
* Stops listening for interrupts on an input pin
*
* @param pin GPIO pin
* @see attachInterrupt
* @see noInterrupts
* @see interrupts
* @webref
* @webref GPIO
* @webBrief Stops listening for interrupts on an input pin
*/
public static void releaseInterrupt(int pin) {
Thread t = irqThreads.get(pin);
@@ -432,10 +495,15 @@ public class GPIO {
/**
* Gives ownership of a pin back to the operating system
* Gives ownership of a pin back to the operating system<br/>
* <br/>
* Without calling this function, the pin will remain in the current
* state even after the sketch has been closed.
*
* @param pin GPIO pin
* @see pinMode
* @webref
* @webref GPIO
* @webBrief Gives ownership of a pin back to the operating system
*/
public static void releasePin(int pin) {
checkValidPin(pin);
@@ -459,10 +527,20 @@ public class GPIO {
/**
* Waits for the value of an input pin to change
* Waits for the value of an input pin to change<br/>
* <br/>
* The mode parameter determines when the function will return: GPIO.FALLING occurs
* when the level changes from high to low, GPIO.RISING when the level changes from
* low to high, and GPIO.CHANGE when either occurs.<br/>
* <br/>
* The optional timeout parameter determines how many milliseconds the function will
* wait at the most. If the value of the input pin hasn't changed at this point, an
* exception is raised for this line. Without a timeout parameter the function will
* wait indefinitely until the input pin has changed to the desired state.
* @param pin GPIO pin
* @param mode what to wait for: GPIO.CHANGE, GPIO.FALLING or GPIO.RISING
* @webref
* @webref GPIO
* @webBrief Waits for the value of an input pin to change
*/
public static void waitFor(int pin, int mode) {
waitFor(pin, mode, -1);
@@ -470,11 +548,21 @@ public class GPIO {
/**
* Waits for the value of an input pin to change
* Waits for the value of an input pin to change<br/>
* <br/>
* The mode parameter determines when the function will return: GPIO.FALLING occurs
* when the level changes from high to low, GPIO.RISING when the level changes from
* low to high, and GPIO.CHANGE when either occurs.<br/>
* <br/>
* The optional timeout parameter determines how many milliseconds the function will
* wait at the most. If the value of the input pin hasn't changed at this point, an
* exception is raised for this line. Without a timeout parameter the function will
* wait indefinitely until the input pin has changed to the desired state.
*
* This function will throw a RuntimeException in case of a timeout.
* @param timeout don't wait more than timeout milliseconds
* @webref
* @webref GPIO
* @webBrief Waits for the value of an input pin to change
*/
public static void waitFor(int pin, int mode, int timeout) {
enableInterrupt(pin, mode);

View File

@@ -30,7 +30,31 @@ import java.util.Arrays;
/**
* @webref
* Opens an I2C interface as master.<br/>
* <br/>
* I2C is a serial bus, commonly used to attach peripheral ICs (Integrated
* Circuits) to processors and microcontrollers. It uses two pins, SDA (for
* data) and SDL (for the clock signal). Multiple "slave" devices can be
* connected to the same bus, as long as they are responding to different
* addresses (see below).<br/>
* <br/>
* The I2C "master" device initiates a transmission, which includes sending the
* address of the desired "slave" device. I2C addresses consist of 7 bits plus
* one bit that indicates whether the device is being read from or written to.
* Some datasheets list the address in an 8 bit form (7 address bits + R/W bit),
* while others provide the address in a 7 bit form, with the address in the
* lower 7 bits.<br/>
* <br/>
* This library expects addresses in their 7 bit form, similar to Arduino's Wire
* library, and what is being output by the i2cdetect utility on Linux. If the
* address provided in a datasheet is greater than 127 (hex 0x7f) or there are
* separate addresses for read and write operations listed, which vary exactly
* by one, then you want to shift the this number by one bit to the right before
* passing it as an argument to
* <a href="I2C_beginTransmission_.html">beginTransmission()</a>.
*
* @webref I2C
* @webBrief Opens an I2C interface as master
*/
public class I2C {
@@ -45,7 +69,7 @@ public class I2C {
* Opens an I2C interface as master
* @param dev interface name
* @see list
* @webref
* @webref I2C
*/
public I2C(String dev) {
NativeInterface.loadLibrary();
@@ -63,11 +87,20 @@ public class I2C {
/**
* Begins a transmission to an attached device
* @see write
* @see read
* @see endTransmission
* @webref
* Begins a transmission to an attached device.<br/>
* <br/>
* This function expects the address in the lower 7 bits, the same way as in
* Arduino's Wire library, and as shown in the output of the i2cdetect tool. If
* the address provided in a datasheet is greater than 127 (hex 0x7f) or there
* are separate addresses for read and write operations listed, which vary
* exactly by one, then you want to shift the this number by one bit to the
* right before passing it as an argument to this function.
*
* @see write
* @see read
* @see endTransmission
* @webref I2C
* @webBrief Begins a transmission to an attached device
*/
public void beginTransmission(int slave) {
// addresses 120 (0x78) to 127 are additionally reserved
@@ -82,8 +115,16 @@ public class I2C {
/**
* Closes the I2C device
* @webref
* Closes the I2C device<br/>
* </br>
* It is normally not necessary to explicitly close I2C interfaces, as they are
* closed automatically by the operating system when the sketch exits.</br>
* </br>
* Note: It is possible to have two or more object using the same interface at a
* time.
*
* @webref I2C
* @webBrief Closes the I2C device.
*/
public void close() {
if (NativeInterface.isSimulated()) {
@@ -105,10 +146,16 @@ public class I2C {
/**
* Ends the current transmissions
* @see beginTransmission
* @see write
* @webref
* Ends the current transmissions<br/>
* <br/>
* This executes any queued writes. <a href="I2C_read_.html">Read()</a>
* implicitly ends the current transmission as well, hence calling
* endTransmission() afterwards is not necessary.
*
* @see beginTransmission
* @see write
* @webref I2C
* @webBrief Ends the current transmissions.
*/
public void endTransmission() {
if (!transmitting) {
@@ -136,7 +183,8 @@ public class I2C {
/**
* Lists all available I2C interfaces
* @return String array
* @webref
* @webref I2C
* @webBrief Lists all available I2C interfaces
*/
public static String[] list() {
if (NativeInterface.isSimulated()) {
@@ -162,13 +210,20 @@ public class I2C {
/**
* Reads bytes from the attached device
* @param len number of bytes to read
* @return bytes read from device
* @see beginTransmission
* @see write
* @see endTransmission
* @webref
* Read bytes from the attached device<br/>
* <br/>
* You must call beginTransmission() before calling this function. This function
* also ends the current transmission and sends any data that was queued using
* write() before. It is not necessary to call
* <a href="I2C_endTransmission_.html">endTransmission()</a> after read().
*
* @param len number of bytes to read
* @return bytes read from device
* @see beginTransmission
* @see write
* @see endTransmission
* @webref I2C
* @webBrief Read bytes from the attached device.
*/
public byte[] read(int len) {
if (!transmitting) {
@@ -196,12 +251,17 @@ public class I2C {
/**
* Adds bytes to be written to the device
* @param out bytes to be written
* @see beginTransmission
* @see read
* @see endTransmission
* @webref
* Add bytes to be written to the device<br/>
* <br/>
* You must call beginTransmission() before calling this function. The actual
* writing takes part when read() or endTransmission() is being called.
*
* @param out bytes to be written
* @see beginTransmission
* @see read
* @see endTransmission
* @webref I2C
* @webBrief Add bytes to be written to the device.
*/
public void write(byte[] out) {
if (!transmitting) {

View File

@@ -33,7 +33,19 @@ import java.util.Arrays;
/**
* @webref
* Opens a LED device.<br/>
* <br/>
* This class can control your computer's build-in LEDs, such as the ones
* commonly used to indicate the power status and disk activity.</br>
* <br/>
* Your operating system might not be set up to allow regular users to do this
* kind of modification. If this is the case you should install a so-called
* <i>udev rule</i> that relaxes the permissions for the files in
* /sys/class/leds. You can also try running Processing as root user using
* "sudo", but this is generally not recommended.
*
* @webref LED
* @webBrief Opens a LED device
*/
public class LED {
@@ -47,7 +59,8 @@ public class LED {
* Opens a LED device
* @param dev device name
* @see list
* @webref
* @webref LED
* @webBrief Opens a LED device
*/
public LED(String dev) {
NativeInterface.loadLibrary();
@@ -106,7 +119,8 @@ public class LED {
/**
* Sets the brightness
* @param bright 0.0 (off) to 1.0 (maximum)
* @webref
* @webref LED
* @webBrief Sets the brightness
*/
public void brightness(float bright) {
if (bright < 0.0 || 1.0 < bright) {
@@ -127,8 +141,13 @@ public class LED {
/**
* Restores the previous state
* @webref
* Restores the previous state<br/>
* <br/>
* Without calling this function the LED will remain in the current state even
* after the sketch has been closed.
*
* @webref LED
* @webBrief Restores the previous state
*/
public void close() {
if (NativeInterface.isSimulated()) {
@@ -153,7 +172,8 @@ public class LED {
/**
* Lists all available LED devices
* @return String array
* @webref
* @webref LED
* @webBrief Lists all available LED devices
*/
public static String[] list() {
if (NativeInterface.isSimulated()) {

View File

@@ -33,7 +33,10 @@ import java.util.Arrays;
/**
* @webref
* Opens a PWM channel
*
* @webref PWM
* @webBrief Opens a PWM channel
*/
public class PWM {
@@ -45,7 +48,8 @@ public class PWM {
* Opens a PWM channel
* @param channel PWM channel
* @see list
* @webref
* @webref PWM
* @webBrief Opens a PWM channel
*/
public PWM(String channel) {
NativeInterface.loadLibrary();
@@ -90,7 +94,9 @@ public class PWM {
/**
* Disables the PWM output
* @webref
*
* @webref PWM
* @webBrief Disables the PWM output
*/
public void clear() {
if (NativeInterface.isSimulated()) {
@@ -106,8 +112,13 @@ public class PWM {
/**
* Gives ownership of a channel back to the operating system
* @webref
* Gives ownership of a channel back to the operating system<br/>
* <br/>
* Without calling this function the channel will remain in the current state
* even after the sketch has been closed.
*
* @webref PWM
* @webBrief Gives ownership of a channel back to the operating system
*/
public void close() {
if (NativeInterface.isSimulated()) {
@@ -133,7 +144,8 @@ public class PWM {
/**
* Lists all available PWM channels
* @return String array
* @webref
* @webref PWM
* @webBrief Lists all available PWM channels
*/
public static String[] list() {
if (NativeInterface.isSimulated()) {
@@ -165,10 +177,14 @@ public class PWM {
/**
* Enables the PWM output
* @param period cycle period in Hz
* @param duty duty cycle, 0.0 (always off) to 1.0 (always on)
* @webref
* Enables the PWM output<br/>
* <br/>
* When no period is specified, a default 1 kHz (1000 Hz) is used.
*
* @param period cycle period in Hz
* @param duty duty cycle, 0.0 (always off) to 1.0 (always on)
* @webref PWM
* @webBrief Enables the PWM output
*/
public void set(int period, float duty) {
if (NativeInterface.isSimulated()) {
@@ -206,7 +222,7 @@ public class PWM {
/**
* Enables the PWM output with a preset period of 1 kHz
* @webref
* @nowebref
*/
public void set(float duty) {
set(1000, duty);

View File

@@ -32,7 +32,29 @@ import java.util.Map;
/**
* @webref
* Opens an SPI interface as master<br/>
* </br>
* Serial Peripheral Interface (SPI) is a serial bus, commonly used to
* communicate with sensors and memory devices. It uses four pins: MOSI (Master
* Out Slave In), MISO (Master In Slave Out), and SCLK (clock signal) - those
* three are shared among all devices on the bus - as well as one or more SS
* (Slave Select) pins, that are used for the master to signal to the slave
* device that it is the desired respondent for the transmission.<br/>
* <br/>
* The "master" device initiates a transfer by pulling the SS pin of the "slave"
* low, and begins outputting a clock signal. In SPI, both the "master" as well
* as the "slave" device output data at the same time. It is hence not possible
* to read data without writing some (even if it means outputting zeros or other
* dummy data).</br>
* </br>
* There are multiple possible configuration settings for SPI, see
* <a href="SPI_settings_.html">settings()</a> for details.</br>
* <br/>
* This library supports multiple SPI objects making use of the same SPI
* interface.
*
* @webref SPI
* @webBrief Opens an SPI interface as master
*/
public class SPI {
@@ -73,7 +95,8 @@ public class SPI {
* Opens an SPI interface as master
* @param dev device name
* @see list
* @webref
* @webref SPI
* @webBrief Opens an SPI interface as master
*/
public SPI(String dev) {
NativeInterface.loadLibrary();
@@ -91,8 +114,16 @@ public class SPI {
/**
* Closes the SPI interface
* @webref
* Closes the SPI interface</br>
* </br>
* It is normally not necessary to explicitly close SPI interfaces, as they are
* closed automatically by the operating system when the sketch exits.</br>
* </br>
* Note: It is possible to have two or more objects using the same interface at
* a time.
*
* @webref SPI
* @webBrief Closes the SPI interface
*/
public void close() {
if (NativeInterface.isSimulated()) {
@@ -116,7 +147,8 @@ public class SPI {
/**
* Lists all available SPI interfaces
* @return String array
* @webref
* @webref SPI
* @webBrief Lists all available SPI interfaces
*/
public static String[] list() {
if (NativeInterface.isSimulated()) {
@@ -142,11 +174,20 @@ public class SPI {
/**
* Configures the SPI interface
* @param maxSpeed maximum transmission rate in Hz, 500000 (500 kHz) is a resonable default
* @param dataOrder whether data is send with the first- or least-significant bit first (SPI.MSBFIRST or SPI.LSBFIRST, the former is more common)
* @param mode <a href="https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Clock_polarity_and_phase">SPI.MODE0 to SPI.MODE3</a>
* @webref
* Configures the SPI interface<br/>
* <br/>
* The default setting is: 500000, SPI.MSBFIRST, SPI.MODE0
*
* @param maxSpeed maximum transmission rate in Hz, 500000 (500 kHz) is a
* resonable default
* @param dataOrder whether data is send with the first- or least-significant
* bit first (SPI.MSBFIRST or SPI.LSBFIRST, the former is more
* common)
* @param mode <a href=
* "https://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus#Clock_polarity_and_phase">SPI.MODE0
* to SPI.MODE3</a>
* @webref SPI
* @webBrief Configures the SPI interface
*/
public void settings(int maxSpeed, int dataOrder, int mode) {
this.maxSpeed = maxSpeed;
@@ -156,10 +197,16 @@ public class SPI {
/**
* Transfers data over the SPI bus
* @param out bytes to send
* @return bytes read in (array is the same length as out)
* @webref
* Transfers data over the SPI bus<br/>
* <br/>
* With SPI, data is simultaneously being exchanged between the master device
* and the slave device. For every byte that is being sent out, there's also one
* byte being read in.
*
* @param out bytes to send
* @return bytes read in (array is the same length as out)
* @webref SPI
* @webBrief Transfers data over the SPI bus
*/
public byte[] transfer(byte[] out) {
if (NativeInterface.isSimulated()) {

View File

@@ -26,7 +26,17 @@ import processing.core.*;
/**
* @webref
* Opens an RC servo motor connected to a GPIO pin<br/>
* </br>
* This library uses timers to control RC servo motors by means of pulse width
* modulation (PWM). While not as accurate as dedicated PWM hardware, it has
* shown to be sufficient for many applications.<br/>
* <br/>
* Connect the signal wire (typically colored yellow) to any available GPIO pin
* and control the servo's angle as shown in the example sketch.
*
* @webref software_servo
* @webBrief Opens an RC servo motor connected to a GPIO pin
*/
public class SoftwareServo {
@@ -44,7 +54,8 @@ public class SoftwareServo {
/**
* Opens a servo motor
* @param parent typically use "this"
* @webref
* @webref software_servo
* @webBrief Opens a servo motor
*/
public SoftwareServo(PApplet parent) {
NativeInterface.loadLibrary();
@@ -53,7 +64,7 @@ public class SoftwareServo {
/**
* Closes a servo motor
* @webref
*
*/
public void close() {
detach();
@@ -70,9 +81,18 @@ public class SoftwareServo {
/**
* Attaches a servo motor to a GPIO pin
* @param pin GPIO pin
* @webref
* Attaches a servo motor to a GPIO pin<br/>
* <br/>
* You must call this function before calling write(). Note that the servo motor
* will only be instructed to move after the first time write() is called.<br/>
* <br/>
* The optional parameters minPulse and maxPulse control the minimum and maximum
* pulse width durations. The default values, identical to those of Arduino's
* Servo class, should be compatible with most servo motors.
*
* @param pin GPIO pin
* @webref software_servo
* @webBrief Attaches a servo motor to a GPIO pin
*/
public void attach(int pin) {
detach();
@@ -83,10 +103,18 @@ public class SoftwareServo {
/**
* Attaches a servo motor to a GPIO pin using custom pulse widths
* Attaches a servo motor to a GPIO pin<br/>
* <br/>
* You must call this function before calling write(). Note that the servo motor
* will only be instructed to move after the first time write() is called.<br/>
* <br/>
* The optional parameters minPulse and maxPulse control the minimum and maximum
* pulse width durations. The default values, identical to those of Arduino's
* Servo class, should be compatible with most servo motors.
*
* @param minPulse minimum pulse width in microseconds (default: 544, same as on Arduino)
* @param maxPulse maximum pulse width in microseconds (default: 2400, same as on Arduino)
* @webref
* @webref software_servo
*/
public void attach(int pin, int minPulse, int maxPulse) {
detach();
@@ -97,9 +125,17 @@ public class SoftwareServo {
/**
* Moves a servo motor to a given orientation
* @param angle angle in degrees (controls speed and direction on continuous-rotation servos)
* @webref
* Moves a servo motor to a given orientation<br/>
* <br/>
* If you are using this class in combination with a continuous rotation servo,
* different angles will result in the servo rotating forward or backward at
* different speeds. For regular servo motors, this will instruct the servo to
* rotate to and hold a specific angle.
*
* @param angle angle in degrees (controls speed and direction on
* continuous-rotation servos)
* @webref software_servo
* @webBrief Moves a servo motor to a given orientation
*/
public void write(float angle) {
if (attached() == false) {
@@ -136,7 +172,8 @@ public class SoftwareServo {
/**
* Returns whether a servo motor is attached to a pin
* @return true if attached, false is not
* @webref
* @webref software_servo
* @webBrief Returns whether a servo motor is attached to a pin
*/
public boolean attached() {
return (pin != -1);
@@ -144,8 +181,13 @@ public class SoftwareServo {
/**
* Detatches a servo motor from a GPIO pin
* @webref
* Detatches a servo motor from a GPIO pin<br/>
* <br/>
* Calling this method will stop the servo from moving or trying to hold the
* current orientation.
*
* @webref software_servo
* @webBrief Detatches a servo motor from a GPIO pin
*/
public void detach() {
if (0 <= handle) {

View File

@@ -31,15 +31,13 @@ import java.lang.reflect.*;
import java.net.*;
/**
* ( begin auto-generated from Client.xml )
*
* A client connects to a server and sends data back and forth. If anything
* goes wrong with the connection, for example the host is not there or is
* listening on a different port, an exception is thrown.
*
* ( end auto-generated )
* @webref net
* @brief The client class is used to create client Objects which connect to a server to exchange data.
* @webref client
* @webBrief The client class is used to create client Objects which connect to a server to exchange data.
* @instanceName client any variable of type Client
* @usage Application
* @see_external LIB_net/clientEvent
@@ -148,14 +146,12 @@ public class Client implements Runnable {
/**
* ( begin auto-generated from Client_stop.xml )
*
* Disconnects from the server. Use to shut the connection when you're
* finished with the Client.
*
* ( end auto-generated )
* @webref client:client
* @brief Disconnects from the server
* @webref client
* @webBrief Disconnects from the server
* @usage application
*/
public void stop() {
@@ -306,14 +302,12 @@ public class Client implements Runnable {
/**
* ( begin auto-generated from Client_active.xml )
*
* Returns true if this client is still active and hasn't run
* Returns <b>true</b> if this client is still active and hasn't run
* into any trouble.
*
* ( end auto-generated )
* @webref client:client
* @brief Returns true if this client is still active
* @webref client
* @webBrief Returns <b>true</b> if this client is still active
* @usage application
*/
public boolean active() {
@@ -322,14 +316,12 @@ public class Client implements Runnable {
/**
* ( begin auto-generated from Client_ip.xml )
*
* Returns the IP address of the computer to which the Client is attached.
*
* ( end auto-generated )
* @webref client:client
* @webref client
* @usage application
* @brief Returns the IP address of the machine as a String
* @webBrief Returns the IP address of the machine as a String
*/
public String ip() {
if (socket != null){
@@ -340,15 +332,13 @@ public class Client implements Runnable {
/**
* ( begin auto-generated from Client_available.xml )
*
* Returns the number of bytes available. When any client has bytes
* available from the server, it returns the number of bytes.
*
* ( end auto-generated )
* @webref client:client
* @webref client
* @usage application
* @brief Returns the number of bytes in the buffer waiting to be read
* @webBrief Returns the number of bytes in the buffer waiting to be read
*/
public int available() {
synchronized (bufferLock) {
@@ -358,14 +348,12 @@ public class Client implements Runnable {
/**
* ( begin auto-generated from Client_clear.xml )
*
* Empty the buffer, removes all the data stored there.
*
* ( end auto-generated )
* @webref client:client
* @webref client
* @usage application
* @brief Clears the buffer
* @webBrief Clears the buffer
*/
public void clear() {
synchronized (bufferLock) {
@@ -376,16 +364,14 @@ public class Client implements Runnable {
/**
* ( begin auto-generated from Client_read.xml )
*
* Returns a number between 0 and 255 for the next byte that's waiting in
* the buffer. Returns -1 if there is no byte, although this should be
* avoided by first cheacking <b>available()</b> to see if any data is available.
*
* ( end auto-generated )
* @webref client:client
* @webref client
* @usage application
* @brief Returns a value from the buffer
* @webBrief Returns a value from the buffer
*/
public int read() {
synchronized (bufferLock) {
@@ -402,15 +388,13 @@ public class Client implements Runnable {
/**
* ( begin auto-generated from Client_readChar.xml )
*
* Returns the next byte in the buffer as a char. Returns -1 or 0xffff if
* nothing is there.
* Returns the next byte in the buffer as a char. Returns <b>-1</b> or
* <b>0xffff</b> if nothing is there.
*
* ( end auto-generated )
* @webref client:client
* @webref client
* @usage application
* @brief Returns the next byte in the buffer as a char
* @webBrief Returns the next byte in the buffer as a char
*/
public char readChar() {
synchronized (bufferLock) {
@@ -421,7 +405,6 @@ public class Client implements Runnable {
/**
* ( begin auto-generated from Client_readBytes.xml )
*
* Reads a group of bytes from the buffer. The version with no parameters
* returns a byte array of all data in the buffer. This is not efficient,
@@ -431,16 +414,15 @@ public class Client implements Runnable {
* of bytes read. If more bytes are available than can fit into the
* <b>byteBuffer</b>, only those that fit are read.
*
* ( end auto-generated )
* <h3>Advanced</h3>
* Return a byte array of anything that's in the serial buffer.
* Not particularly memory/speed efficient, because it creates
* a byte array on each read, but it's easier to use than
* readBytes(byte b[]) (see below).
*
* @webref client:client
* @webref client
* @usage application
* @brief Reads everything in the buffer
* @webBrief Reads a group of bytes from the buffer.
*/
public byte[] readBytes() {
synchronized (bufferLock) {
@@ -518,7 +500,6 @@ public class Client implements Runnable {
/**
* ( begin auto-generated from Client_readBytesUntil.xml )
*
* Reads from the port into a buffer of bytes up to and including a
* particular character. If the character isn't in the buffer, 'null' is
@@ -531,10 +512,9 @@ public class Client implements Runnable {
* not large enough, -1 is returned and an error is printed to the message
* area. If nothing is in the buffer, 0 is returned.
*
* ( end auto-generated )
* @webref client:client
* @webref client
* @usage application
* @brief Reads from the buffer of bytes up to and including a particular character
* @webBrief Reads from the buffer of bytes up to and including a particular character
* @param interesting character designated to mark the end of the data
*/
public byte[] readBytesUntil(int interesting) {
@@ -615,7 +595,6 @@ public class Client implements Runnable {
/**
* ( begin auto-generated from Client_readString.xml )
*
* Returns the all the data from the buffer as a String. This method
* assumes the incoming characters are ASCII. If you want to transfer
@@ -623,10 +602,9 @@ public class Client implements Runnable {
* representation of your choice (i.e. UTF8 or two-byte Unicode data), and
* send it as a byte array.
*
* ( end auto-generated )
* @webref client:client
* @webref client
* @usage application
* @brief Returns the buffer as a String
* @webBrief Returns the buffer as a String
*/
public String readString() {
byte b[] = readBytes();
@@ -636,21 +614,19 @@ public class Client implements Runnable {
/**
* ( begin auto-generated from Client_readStringUntil.xml )
*
* Combination of <b>readBytesUntil()</b> and <b>readString()</b>. Returns
* <b>null</b> if it doesn't find what you're looking for.
*
* ( end auto-generated )
* <h3>Advanced</h3>
* <p/>
* If you want to move Unicode data, you can first convert the
* String to a byte stream in the representation of your choice
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
*
* @webref client:client
* @webref client
* @usage application
* @brief Returns the buffer as a String up to and including a particular character
* @webBrief Returns the buffer as a String up to and including a particular character
* @param interesting character designated to mark the end of the data
*/
public String readStringUntil(int interesting) {
@@ -661,14 +637,14 @@ public class Client implements Runnable {
/**
* ( begin auto-generated from Client_write.xml )
*
* Writes data to a server specified when constructing the client.
* Writes data to a server specified when constructing the client, or writes
* data to the specific client obtained from the Server <b>available()</b>
* method.
*
* ( end auto-generated )
* @webref client:client
* @webref client
* @usage application
* @brief Writes bytes, chars, ints, bytes[], Strings
* @webBrief Writes bytes, chars, ints, bytes[], Strings
* @param data data to write
*/
public void write(int data) { // will also cover char

View File

@@ -33,7 +33,6 @@ import java.net.*;
/**
* ( begin auto-generated from Server.xml )
*
* A server sends and receives data to and from its associated clients
* (other programs connected to it). When a server is started, it begins
@@ -42,10 +41,10 @@ import java.net.*;
* commonly used so be sure to not select one of these. For example, web
* servers usually use port 80 and POP mail uses port 110.
*
* ( end auto-generated )
* @webref net
* @webref server
* @usage application
* @brief The server class is used to create server objects which send and receives data to and from its associated clients (other programs connected to it).
* @webBrief The server class is used to create server objects which send
* and receives data to and from its associated clients (other programs connected to it).
* @instanceName server any variable of type Server
*/
public class Server implements Runnable {
@@ -115,13 +114,11 @@ public class Server implements Runnable {
/**
* ( begin auto-generated from Server_disconnect.xml )
*
* Disconnect a particular client.
*
* ( end auto-generated )
* @brief Disconnect a particular client.
* @webref server:server
* @webref server
* @webBrief Disconnect a particular client.
* @param client the client to disconnect
*/
public void disconnect(Client client) {
@@ -186,14 +183,12 @@ public class Server implements Runnable {
/**
* ( begin auto-generated from Server_active.xml )
*
* Returns true if this server is still active and hasn't run
* Returns <b>true</b> if this server is still active and hasn't run
* into any trouble.
*
* ( end auto-generated )
* @webref server:server
* @brief Return true if this server is still active.
* @webref server
* @webBrief Return true if this server is still active.
*/
public boolean active() {
return thread != null;
@@ -216,13 +211,11 @@ public class Server implements Runnable {
int lastAvailable = -1;
/**
* ( begin auto-generated from Server_available.xml )
*
* Returns the next client in line with a new message.
*
* ( end auto-generated )
* @brief Returns the next client in line with a new message.
* @webref server
* @webBrief Returns the next client in line with a new message.
* @usage application
*/
public Client available() {
@@ -254,17 +247,15 @@ public class Server implements Runnable {
/**
* ( begin auto-generated from Server_stop.xml )
*
* Disconnects all clients and stops the server.
*
* ( end auto-generated )
* <h3>Advanced</h3>
* Use this to shut down the server if you finish using it while your applet
* is still running. Otherwise, it will be automatically be shut down by the
* host PApplet using dispose(), which is identical.
* @brief Disconnects all clients and stops the server.
* @webref server
* @webBrief Disconnects all clients and stops the server.
* @usage application
*/
public void stop() {
@@ -332,14 +323,12 @@ public class Server implements Runnable {
/**
* ( begin auto-generated from Server_write.xml )
*
* Writes a value to all the connected clients. It sends bytes out from the
* Server object.
*
* ( end auto-generated )
* @webref server
* @brief Writes data to all connected clients
* @webBrief Writes data to all connected clients
* @param data data to write
*/
public void write(int data) { // will also cover char

View File

@@ -34,13 +34,11 @@ import jssc.*;
/**
* ( begin auto-generated from Serial.xml )
*
* Class for sending and receiving data using the serial communication protocol.
*
* ( end auto-generated )
* @webref serial
* @brief Class for sending and receiving data using the serial communication protocol.
* @webBrief Class for sending and receiving data using the serial communication protocol.
* @instanceName serial any variable of type Serial
* @usage Application
* @see_external LIB_serial/serialEvent
@@ -187,8 +185,11 @@ public class Serial implements SerialPortEventListener {
/**
* Returns the number of bytes available.
*
* @generate Serial_available.xml
* @webref serial:serial
* @webref serial
* @webBrief Returns the number of bytes available.
* @usage web_application
*/
public int available() {
@@ -197,8 +198,10 @@ public class Serial implements SerialPortEventListener {
/**
* Sets the number of bytes to buffer before calling serialEvent()
* @generate Serial_buffer.xml
* @webref serial:serial
* @webref serial
* @webBrief Sets the number of bytes to buffer before calling serialEvent()
* @usage web_application
* @param size number of bytes to buffer
*/
@@ -208,8 +211,11 @@ public class Serial implements SerialPortEventListener {
/**
* Sets a specific byte to buffer until before calling <b>serialEvent()</b>.
*
* @generate Serial_bufferUntil.xml
* @webref serial:serial
* @webref serial
* @webBrief Sets a specific byte to buffer until before calling <b>serialEvent()</b>.
* @usage web_application
* @param inByte the value to buffer until
*/
@@ -220,8 +226,11 @@ public class Serial implements SerialPortEventListener {
/**
* Empty the buffer, removes all the data stored there.
*
* @generate Serial_clear.xml
* @webref serial:serial
* @webref serial
* @webBrief Empty the buffer, removes all the data stored there.
* @usage web_application
*/
public void clear() {
@@ -256,12 +265,15 @@ public class Serial implements SerialPortEventListener {
/**
* Returns last byte received or -1 if there is none available.
*
* @generate Serial_last.xml
* <h3>Advanced</h3>
* Same as read() but returns the very last value received
* and clears the buffer. Useful when you just want the most
* recent value sent over the port.
* @webref serial:serial
* @webref serial
* @webBrief Returns last byte received or -1 if there is none available.
* @usage web_application
*/
public int last() {
@@ -279,8 +291,11 @@ public class Serial implements SerialPortEventListener {
/**
* Returns the last byte received as a char or -1 if there is none available.
*
* @generate Serial_lastChar.xml
* @webref serial:serial
* @webref serial
* @webBrief Returns the last byte received as a char or -1 if there is none available.
* @usage web_application
*/
public char lastChar() {
@@ -289,8 +304,12 @@ public class Serial implements SerialPortEventListener {
/**
* Gets a list of all available serial ports. Use <b>println()</b> to write the
* information to the text window.
*
* @generate Serial_list.xml
* @webref serial
* @webBrief Gets a list of all available serial ports.
* @usage web_application
*/
public static String[] list() {
@@ -301,8 +320,13 @@ public class Serial implements SerialPortEventListener {
/**
* Returns a number between 0 and 255 for the next byte that's waiting in the buffer.
* Returns -1 if there is no byte, although this should be avoided by first cheacking
* <b>available()</b> to see if data is available.
*
* @generate Serial_read.xml
* @webref serial:serial
* @webref serial
* @webBrief Returns a number between 0 and 255 for the next byte that's waiting in the buffer.
* @usage web_application
*/
public int read() {
@@ -322,8 +346,15 @@ public class Serial implements SerialPortEventListener {
/**
* Reads a group of bytes from the buffer or <b>null</b> if there are none available. The version
* with no parameters returns a byte array of all data in the buffer. This is not efficient, but
* is easy to use. The version with the <b>byteBuffer</b> parameter is more memory and time
* efficient. It grabs the data in the buffer and puts it into the byte array passed in and returns
* an int value for the number of bytes read. If more bytes are available than can fit into the
* <b>byteBuffer</b>, only those that fit are read.
* @generate Serial_readBytes.xml
* @webref serial:serial
* @webref serial
* @webBrief Reads a group of bytes from the buffer or <b>null</b> if there are none available.
* @usage web_application
*/
public byte[] readBytes() {
@@ -404,8 +435,18 @@ public class Serial implements SerialPortEventListener {
/**
* Reads from the port into a buffer of bytes up to and including a particular character. If the
* character isn't in the buffer, <b>null</b> is returned. The version with without the
* <b>byteBuffer</b> parameter returns a byte array of all data up to and including the
* <b>interesting</b> byte. This is not efficient, but is easy to use. The version with the
* <b>byteBuffer</b> parameter is more memory and time efficient. It grabs the data in the buffer
* and puts it into the byte array passed in and returns an int value for the number of bytes read.
* If the byte buffer is not large enough, -1 is returned and an error is printed to the message
* area. If nothing is in the buffer, 0 is returned.
*
* @generate Serial_readBytesUntil.xml
* @webref serial:serial
* @webref serial
* @webBrief Reads from the port into a buffer of bytes up to and including a particular character.
* @usage web_application
* @param inByte character designated to mark the end of the data
*/
@@ -486,8 +527,12 @@ public class Serial implements SerialPortEventListener {
/**
* Returns the next byte in the buffer as a char. Returns <b>-1</b> or <b>0xffff</b>
* if nothing is there.
*
* @generate Serial_readChar.xml
* @webref serial:serial
* @webref serial
* @webBrief Returns the next byte in the buffer as a char.
* @usage web_application
*/
public char readChar() {
@@ -496,8 +541,14 @@ public class Serial implements SerialPortEventListener {
/**
* Returns all the data from the buffer as a String or <b>null</b> if there is nothing available.
* This method assumes the incoming characters are ASCII. If you want to transfer Unicode data,
* first convert the String to a byte stream in the representation of your choice (i.e. UTF8 or
* two-byte Unicode data), and send it as a byte array.
*
* @generate Serial_readString.xml
* @webref serial:serial
* @webref serial
* @webBrief Returns all the data from the buffer as a String or <b>null</b> if there is nothing available.
* @usage web_application
*/
public String readString() {
@@ -509,13 +560,17 @@ public class Serial implements SerialPortEventListener {
/**
* Combination of <b>readBytesUntil()</b> and <b>readString()</b>. Returns <b>null</b>
* if it doesn't find what you're looking for.
*
* @generate Serial_readStringUntil.xml
*<h3>Advanced</h3>
* If you want to move Unicode data, you can first convert the
* String to a byte stream in the representation of your choice
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
*
* @webref serial:serial
* @webref serial
* @webBrief Combination of <b>readBytesUntil()</b> and <b>readString()</b>.
* @usage web_application
* @param inByte character designated to mark the end of the data
*/
@@ -530,8 +585,16 @@ public class Serial implements SerialPortEventListener {
/**
* Called when data is available. Use one of the <b>read()</b> methods to capture this data.
* The <b>serialEvent()</b> can be set with <b>buffer()</b> to only trigger after a certain
* number of data elements are read and can be set with <b>bufferUntil()</b> to only trigger
* after a specific character is read. The <b>which</b> parameter contains the name of the
* port where new data is available, but is only useful when there is more than one serial
* connection open and it's necessary to distinguish between the two.
*
* @generate serialEvent.xml
* @webref serial:events
* @webref serial_event
* @webBrief Called when data is available.
* @usage web_application
* @param event the port where new data is available
*/
@@ -612,8 +675,11 @@ public class Serial implements SerialPortEventListener {
/**
* Stops data communication on this port. Use to shut the connection when you're finished with the Serial.
*
* @generate Serial_stop.xml
* @webref serial:serial
* @webref serial
* @webBrief Stops data communication on this port.
* @usage web_application
*/
public void stop() {
@@ -656,7 +722,8 @@ public class Serial implements SerialPortEventListener {
/**
* @generate Serial_write.xml
* Writes bytes, chars, ints, bytes[], Strings to the serial port
*
* <h3>Advanced</h3>
* Write a String to the output. Note that this doesn't account
* for Unicode (two bytes per char), nor will it send UTF8
@@ -669,7 +736,8 @@ public class Serial implements SerialPortEventListener {
* String to a byte stream in the representation of your choice
* (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
*
* @webref serial:serial
* @webref serial
* @webBrief Writes bytes, chars, ints, bytes[], Strings to the serial port
* @usage web_application
* @param src data to write
*/