first commit

This commit is contained in:
pandacraft 2025-03-21 16:04:17 +01:00
commit a5a0434432
1126 changed files with 439481 additions and 0 deletions

14
Software/Java8/.gitignore vendored Normal file
View file

@ -0,0 +1,14 @@
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
/examples/nbproject/private/
/examples/build/
/examples/dist/
/ProjectStub/nbproject/private/
/ProjectStub/build/
/ProjectStub/dist/

17
Software/Java8/.project Normal file
View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>GrovePi</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>GrovePi-pi4j</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8

View file

@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

View file

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.iot.raspberry</groupId>
<artifactId>GrovePi-pi4j</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.iot.raspberry</groupId>
<artifactId>GrovePi-spec</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-core</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,57 @@
package org.iot.raspberry.grovepi.pi4j;
import com.pi4j.io.i2c.I2CBus;
import com.pi4j.io.i2c.I2CDevice;
import com.pi4j.io.i2c.I2CFactory;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.GrovePiSequence;
import org.iot.raspberry.grovepi.GrovePiSequenceVoid;
import org.iot.raspberry.grovepi.devices.GroveRgbLcd;
/**
* Create a new GrovePi interface using the Pi4j library
*
* @author Eduardo Moranchel <emoranchel@asmatron.org>
*/
public class GrovePi4J implements GrovePi {
private static final int GROVEPI_ADDRESS = 4;
private final I2CBus bus;
private final I2CDevice device;
public GrovePi4J() throws IOException {
this.bus = I2CFactory.getInstance(I2CBus.BUS_1);
this.device = bus.getDevice(GROVEPI_ADDRESS);
}
@Override
public <T> T exec(GrovePiSequence<T> sequence) throws IOException {
synchronized (this) {
return sequence.execute(new IO(device));
}
}
@Override
public void execVoid(GrovePiSequenceVoid sequence) throws IOException {
synchronized (this) {
sequence.execute(new IO(device));
}
}
@Override
public void close() {
try {
bus.close();
} catch (IOException ex) {
Logger.getLogger("GrovePi").log(Level.SEVERE, null, ex);
}
}
@Override
public GroveRgbLcd getLCD() throws IOException {
return new GroveRgbLcdPi4J();
}
}

View file

@ -0,0 +1,48 @@
package org.iot.raspberry.grovepi.pi4j;
import com.pi4j.io.i2c.I2CBus;
import com.pi4j.io.i2c.I2CDevice;
import com.pi4j.io.i2c.I2CFactory;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.iot.raspberry.grovepi.GrovePiSequenceVoid;
import org.iot.raspberry.grovepi.devices.GroveRgbLcd;
public class GroveRgbLcdPi4J extends GroveRgbLcd {
private final I2CBus bus;
private final I2CDevice rgb;
private final I2CDevice text;
public GroveRgbLcdPi4J() throws IOException {
this.bus = I2CFactory.getInstance(I2CBus.BUS_1);
this.rgb = bus.getDevice(DISPLAY_RGB_ADDR);
this.text = bus.getDevice(DISPLAY_TEXT_ADDR);
init();
}
@Override
public void close() {
try {
bus.close();
} catch (IOException ex) {
Logger.getLogger("GrovePi").log(Level.SEVERE, null, ex);
}
}
@Override
public void execRGB(GrovePiSequenceVoid sequence) throws IOException {
synchronized (this) {
sequence.execute(new IO(rgb));
}
}
@Override
public void execTEXT(GrovePiSequenceVoid sequence) throws IOException {
synchronized (this) {
sequence.execute(new IO(text));
}
}
}

View file

@ -0,0 +1,42 @@
package org.iot.raspberry.grovepi.pi4j;
import com.pi4j.io.i2c.I2CDevice;
import java.io.IOException;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.iot.raspberry.grovepi.GroveIO;
public class IO implements GroveIO {
private final I2CDevice device;
public IO(I2CDevice device) {
this.device = device;
}
@Override
public void write(int... command) throws IOException {
byte[] buffer = new byte[command.length];
for (int i = 0; i < command.length; i++) {
buffer[i] = (byte) command[i];
}
Logger.getLogger("GrovePi").log(Level.INFO, "[Pi4J IO write]{0}", Arrays.toString(buffer));
device.write(buffer, 0, command.length);
}
@Override
public int read() throws IOException {
final int read = device.read();
Logger.getLogger("GrovePi").log(Level.INFO, "[Pi4J IO read]{0}", read);
return read;
}
@Override
public byte[] read(byte[] buffer) throws IOException {
device.read(buffer, 0, buffer.length);
Logger.getLogger("GrovePi").log(Level.INFO, "[Pi4J IO read]{0}", Arrays.toString(buffer));
return buffer;
}
}

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>GrovePi-spec</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8

View file

@ -0,0 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

View file

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.iot.raspberry</groupId>
<artifactId>GrovePi-spec</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>

View file

@ -0,0 +1,47 @@
package org.iot.raspberry.grovepi;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.iot.raspberry.grovepi.GrovePiCommands.*;
public class GroveAnalogIn implements Runnable {
private final GrovePi grovePi;
private final int pin;
private GroveAnalogInListener listener;
private final int bufferSize;
public GroveAnalogIn(GrovePi grovePi, int pin, int bufferSize) throws IOException {
this.grovePi = grovePi;
this.pin = pin;
grovePi.execVoid((io) -> io.write(pMode_cmd, pMode_in_arg, pin, unused));
this.bufferSize = bufferSize;
}
@Override
public void run() {
try {
get();
} catch (IOException ex) {
Logger.getLogger("GrovePi").log(Level.SEVERE, null, ex);
}
}
public byte[] get() throws IOException {
byte[] value = grovePi.exec((io) -> {
io.write(aRead_cmd, pin, unused, unused);
io.sleep(100);
return io.read(new byte[bufferSize]);
});
if (listener != null) {
listener.onChange(value);
}
return value;
}
public void setListener(GroveAnalogInListener listener) {
this.listener = listener;
}
}

View file

@ -0,0 +1,6 @@
package org.iot.raspberry.grovepi;
public interface GroveAnalogInListener {
void onChange(byte[] newValue);
}

View file

@ -0,0 +1,27 @@
package org.iot.raspberry.grovepi;
import java.io.IOException;
import static org.iot.raspberry.grovepi.GrovePiCommands.*;
public class GroveAnalogOut {
private final GrovePi grovePi;
private final int pin;
public GroveAnalogOut(GrovePi grovePi, int pin) throws IOException {
this.grovePi = grovePi;
this.pin = pin;
grovePi.execVoid((GroveIO io) -> io.write(pMode_cmd, pin, pMode_out_arg, unused));
}
public void set(double value) throws IOException {
int[] command = new int[8];
command[0] = aWrite_cmd;
command[1] = pin;
command[2] = 1;
command[3] = 3;
command[4] = unused;
grovePi.execVoid((GroveIO io) -> io.write(command));
}
}

View file

@ -0,0 +1,5 @@
package org.iot.raspberry.grovepi;
public @interface GroveAnalogPin {
}

View file

@ -0,0 +1,28 @@
package org.iot.raspberry.grovepi;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class GroveDevices implements AutoCloseable {
private final List<AutoCloseable> devices = new ArrayList<>();
public <T extends AutoCloseable> T add(T device) {
devices.add(device);
return device;
}
@Override
public void close() {
devices.stream().forEach((device) -> {
try {
device.close();
} catch (Exception ex) {
Logger.getLogger("RaspberryPi").log(Level.SEVERE, null, ex);
}
});
}
}

View file

@ -0,0 +1,47 @@
package org.iot.raspberry.grovepi;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.iot.raspberry.grovepi.GrovePiCommands.*;
public class GroveDigitalIn implements Runnable {
private final GrovePi grovePi;
private final int pin;
private boolean status = false;
private GroveDigitalInListener listener;
public GroveDigitalIn(GrovePi grovePi, int pin) throws IOException {
this.grovePi = grovePi;
this.pin = pin;
grovePi.execVoid((GroveIO io) -> io.write(pMode_cmd, pin, pMode_in_arg, unused));
}
public boolean get() throws IOException, InterruptedException {
boolean st = grovePi.exec((GroveIO io) -> {
io.write(dRead_cmd, pin, unused, unused);
io.sleep(100);
return io.read() == 1;
});
if (listener != null && status != st) {
listener.onChange(status, st);
}
this.status = st;
return st;
}
public void setListener(GroveDigitalInListener listener) {
this.listener = listener;
}
@Override
public void run() {
try {
get();
} catch (IOException | InterruptedException ex) {
Logger.getLogger("GrovePi").log(Level.SEVERE, null, ex);
}
}
}

View file

@ -0,0 +1,6 @@
package org.iot.raspberry.grovepi;
public interface GroveDigitalInListener {
void onChange(boolean oldValue, boolean newValue);
}

View file

@ -0,0 +1,22 @@
package org.iot.raspberry.grovepi;
import java.io.IOException;
import static org.iot.raspberry.grovepi.GrovePiCommands.*;
public class GroveDigitalOut {
private final GrovePi grovePi;
private final int pin;
public GroveDigitalOut(GrovePi grovePi, int pin) throws IOException {
this.grovePi = grovePi;
this.pin = pin;
grovePi.execVoid((GroveIO io) -> io.write(pMode_cmd, pin, pMode_out_arg, unused));
set(false);
}
public final void set(boolean value) throws IOException {
int val = value ? 1 : 0;
grovePi.execVoid((GroveIO io) -> io.write(dWrite_cmd, pin, val, unused));
}
}

View file

@ -0,0 +1,5 @@
package org.iot.raspberry.grovepi;
public @interface GroveDigitalPin {
}

View file

@ -0,0 +1,5 @@
package org.iot.raspberry.grovepi;
public @interface GroveI2CPin {
}

View file

@ -0,0 +1,19 @@
package org.iot.raspberry.grovepi;
import java.io.IOException;
public interface GroveIO {
public void write(int... command) throws IOException;
public int read() throws IOException;
public byte[] read(byte[] buffer) throws IOException;
default public void sleep(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException ex) {
}
}
}

View file

@ -0,0 +1,33 @@
package org.iot.raspberry.grovepi;
import org.iot.raspberry.grovepi.devices.GroveRgbLcd;
import java.io.IOException;
public interface GrovePi extends AutoCloseable {
default public GroveDigitalOut getDigitalOut(int digitalPort) throws IOException {
return new GroveDigitalOut(this, digitalPort);
}
default public GroveDigitalIn getDigitalIn(int digitalPort) throws IOException {
return new GroveDigitalIn(this, digitalPort);
}
default public GroveAnalogOut getAnalogOut(int digitalPort) throws IOException {
return new GroveAnalogOut(this, digitalPort);
}
default public GroveAnalogIn getAnalogIn(int digitalPort, int bufferSize) throws IOException {
return new GroveAnalogIn(this, digitalPort, bufferSize);
}
public GroveRgbLcd getLCD() throws IOException;
public <T> T exec(GrovePiSequence<T> sequence) throws IOException;
public void execVoid(GrovePiSequenceVoid sequence) throws IOException;
@Override
public void close();
}

View file

@ -0,0 +1,82 @@
package org.iot.raspberry.grovepi;
public class GrovePiCommands {
public static final int unused = 0;
// Command Format
// digitalRead()command format header
public static final int dRead_cmd = 1;
// digitalWrite() command format header
public static final int dWrite_cmd = 2;
// analogRead() command format header
public static final int aRead_cmd = 3;
// analogWrite() command format header
public static final int aWrite_cmd = 4;
// pinMode() command format header
public static final int pMode_cmd = 5;
// Ultrasonic read
public static final int uRead_cmd = 7;
// Get firmware version
public static final int version_cmd = 8;
// Accelerometer (+/- 1.5g) read
public static final int acc_xyz_cmd = 20;
// RTC get time
public static final int rtc_getTime_cmd = 30;
// DHT Pro sensor temperature
public static final int dht_temp_cmd = 40;
// Grove LED Bar commands
// Initialise
public static final int ledBarInit_cmd = 50;
// Set orientation
public static final int ledBarOrient_cmd = 51;
// Set level
public static final int ledBarLevel_cmd = 52;
// Set single LED
public static final int ledBarSetOne_cmd = 53;
// Toggle single LED
public static final int ledBarToggleOne_cmd = 54;
// Set all LEDs
public static final int ledBarSet_cmd = 55;
// Get current state
public static final int ledBarGet_cmd = 56;
// Grove 4 Digit Display commands
// Initialise
public static final int fourDigitInit_cmd = 70;
// Set brightness, not visible until next cmd
public static final int fourDigitBrightness_cmd = 71;
// Set numeric value without leading zeros
public static final int fourDigitValue_cmd = 72;
// Set numeric value with leading zeros
public static final int fourDigitValueZeros_cmd = 73;
// Set individual digit
public static final int fourDigitIndividualDigit_cmd = 74;
// Set individual leds of a segment
public static final int fourDigitIndividualLeds_cmd = 75;
// Set left and right values with colon
public static final int fourDigitScore_cmd = 76;
// Analog read for n seconds
public static final int fourDigitAnalogRead_cmd = 77;
// Entire display on
public static final int fourDigitAllOn_cmd = 78;
// Entire display off
public static final int fourDigitAllOff_cmd = 79;
// Grove Chainable RGB LED commands
// Store color for later use
public static final int storeColor_cmd = 90;
// Initialise
public static final int chainableRgbLedInit_cmd = 91;
// Initialise and test with a simple color
public static final int chainableRgbLedTest_cmd = 92;
// Set one or more leds to the stored color by pattern
public static final int chainableRgbLedSetPattern_cmd = 93;
// set one or more leds to the stored color by modulo
public static final int chainableRgbLedSetModulo_cmd = 94;
// sets leds similar to a bar graph, reversible
public static final int chainableRgbLedSetLevel_cmd = 95;
public static final int pMode_out_arg = 1;
public static final int pMode_in_arg = 0;
}

View file

@ -0,0 +1,9 @@
package org.iot.raspberry.grovepi;
import java.io.IOException;
public interface GrovePiSequence<T> {
T execute(GroveIO io) throws IOException;
}

View file

@ -0,0 +1,9 @@
package org.iot.raspberry.grovepi;
import java.io.IOException;
public interface GrovePiSequenceVoid<T> {
void execute(GroveIO io) throws IOException;
}

View file

@ -0,0 +1,16 @@
package org.iot.raspberry.grovepi;
public class GroveUtil {
public static int[] unsign(byte[] b) {
int[] v = new int[b.length];
for (int i = 0; i < b.length; i++) {
v[i] = unsign(b[i]);
}
return v;
}
public static int unsign(byte b) {
return b & 0xFF;
}
}

View file

@ -0,0 +1,38 @@
package org.iot.raspberry.grovepi.devices;
import java.io.IOException;
import org.iot.raspberry.grovepi.GroveAnalogIn;
import org.iot.raspberry.grovepi.GroveAnalogInListener;
public abstract class GroveAnalogInputDevice<T> implements Runnable, GroveAnalogInListener {
private final GroveAnalogIn in;
private GroveInputDeviceListener<T> listener;
public GroveAnalogInputDevice(GroveAnalogIn in) {
this.in = in;
in.setListener(this);
}
@Override
public void run() {
in.run();
}
@Override
public void onChange(byte[] newValue) {
if (listener != null) {
listener.onChange(get(newValue));
}
}
public void setListener(GroveInputDeviceListener listener) {
this.listener = listener;
}
public T get() throws IOException {
return get(in.get());
}
public abstract T get(byte[] data);
}

View file

@ -0,0 +1,6 @@
package org.iot.raspberry.grovepi.devices;
public interface GroveInputDeviceListener<T> {
void onChange(T t);
}

View file

@ -0,0 +1,34 @@
package org.iot.raspberry.grovepi.devices;
import java.io.IOException;
import org.iot.raspberry.grovepi.GroveDigitalPin;
import org.iot.raspberry.grovepi.GroveIO;
import org.iot.raspberry.grovepi.GrovePi;
import static org.iot.raspberry.grovepi.GrovePiCommands.*;
@GroveDigitalPin
public class GroveLed {
public static int MAX_BRIGTHNESS = 255;
private final GrovePi grovePi;
private final int pin;
public GroveLed(GrovePi grovePi, int pin) throws IOException {
this.grovePi = grovePi;
this.pin = pin;
grovePi.execVoid((GroveIO io) -> io.write(pMode_cmd, pin, pMode_out_arg, unused));
set(false);
}
public final void set(boolean value) throws IOException {
int val = value ? 1 : 0;
grovePi.execVoid((GroveIO io) -> io.write(dWrite_cmd, pin, val, unused));
}
public final void set(int value) throws IOException {
final int val = ((value > 255) ? 255 : (value < 0 ? 0 : value));
grovePi.execVoid((GroveIO io) -> io.write(aWrite_cmd, pin, val, unused));
}
}

View file

@ -0,0 +1,20 @@
package org.iot.raspberry.grovepi.devices;
import java.io.IOException;
import org.iot.raspberry.grovepi.GroveAnalogPin;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.GroveUtil;
@GroveAnalogPin
public class GroveLightSensor extends GroveAnalogInputDevice<Double> {
public GroveLightSensor(GrovePi grovePi, int pin) throws IOException {
super(grovePi.getAnalogIn(pin, 4));
}
@Override
public Double get(byte[] data) {
int[] v = GroveUtil.unsign(data);
return (double) (v[1] * 256) + v[2];
}
}

View file

@ -0,0 +1,30 @@
package org.iot.raspberry.grovepi.devices;
import java.io.IOException;
import org.iot.raspberry.grovepi.GroveDigitalPin;
import org.iot.raspberry.grovepi.GroveIO;
import org.iot.raspberry.grovepi.GrovePi;
import static org.iot.raspberry.grovepi.GrovePiCommands.dWrite_cmd;
import static org.iot.raspberry.grovepi.GrovePiCommands.pMode_cmd;
import static org.iot.raspberry.grovepi.GrovePiCommands.pMode_out_arg;
import static org.iot.raspberry.grovepi.GrovePiCommands.unused;
@GroveDigitalPin
public class GroveRelay {
private final GrovePi grovePi;
private final int pin;
public GroveRelay(GrovePi grovePi, int pin) throws IOException {
this.grovePi = grovePi;
this.pin = pin;
grovePi.execVoid((GroveIO io) -> io.write(pMode_cmd, pin, pMode_out_arg, unused));
set(false);
}
public final void set(boolean value) throws IOException {
int val = value ? 1 : 0;
grovePi.execVoid((GroveIO io) -> io.write(dWrite_cmd, pin, val, unused));
}
}

View file

@ -0,0 +1,78 @@
package org.iot.raspberry.grovepi.devices;
import java.io.IOException;
import org.iot.raspberry.grovepi.GroveI2CPin;
import org.iot.raspberry.grovepi.GrovePiSequenceVoid;
@GroveI2CPin
public abstract class GroveRgbLcd implements AutoCloseable {
public static final int DISPLAY_RGB_ADDR = 0x62;
public static final int DISPLAY_TEXT_ADDR = 0x3e;
private static final int LCD_COMMAND = 0x80;
private static final int LCD_WRITECHAR = 0x40;
private static final int LCD_CMD_CLEARDISPLAY = 0x01;
private static final int LCD_CMD_NEWLINE = 0xc0;
private static final int REG_RED = 0x04;
private static final int REG_GREEN = 0x03;
private static final int REG_BLUE = 0x02;
protected void init() throws IOException {
execRGB((io) -> {
io.write(0, 0);
io.write(1, 0);
io.write(0x08, 0xaa);
});
execTEXT((io) -> {
io.write(LCD_COMMAND, 0x08 | 0x04); // display on, no cursor
io.write(LCD_COMMAND, 0x28); // 2 Lines
io.write(LCD_COMMAND, LCD_CMD_CLEARDISPLAY); // clear Display
io.sleep(50);
});
}
public void setRGB(int r, int g, int b) throws IOException {
execRGB((io) -> {
io.write(REG_RED, r);
io.write(REG_GREEN, g);
io.write(REG_BLUE, b);
io.sleep(50);
});
}
public void setText(String text) throws IOException {
execTEXT((io) -> {
io.write(LCD_COMMAND, LCD_CMD_CLEARDISPLAY); // clear Display
io.sleep(50);
int count = 0;
int row = 0;
for (char c : text.toCharArray()) {
if (c == '\n' || count == 16) {
count = 0;
row += 1;
if (row == 2) {
break;
}
io.write(LCD_COMMAND, LCD_CMD_NEWLINE); // new line
if (c == '\n') {
continue;
}
}
count++;
io.write(LCD_WRITECHAR, c); // Write character
}
io.sleep(100);
});
}
public abstract void execRGB(GrovePiSequenceVoid sequence) throws IOException;
public abstract void execTEXT(GrovePiSequenceVoid sequence) throws IOException;
@Override
public abstract void close();
}

View file

@ -0,0 +1,31 @@
package org.iot.raspberry.grovepi.devices;
import java.io.IOException;
import org.iot.raspberry.grovepi.GroveAnalogPin;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.GroveUtil;
@GroveAnalogPin
public class GroveRotarySensor extends GroveAnalogInputDevice<GroveRotaryValue> {
//Reference voltage of ADC is 5v
public static final double ADC_REF = 5;
//Vcc of the grove interface is normally 5v
public static final double GROVE_VCC = 5;
//Full value of the rotary angle is 300 degrees, as per it's specs (0 to 300)
public static final double FULL_ANGLE = 300;
public GroveRotarySensor(GrovePi grovePi, int pin) throws IOException {
super(grovePi.getAnalogIn(pin, 4));
}
@Override
public GroveRotaryValue get(byte[] b) {
int[] v = GroveUtil.unsign(b);
double sensor_value = (v[1] * 256) + v[2];
double voltage = (sensor_value * ADC_REF / 1023);
double degrees = voltage * FULL_ANGLE / GROVE_VCC;
return new GroveRotaryValue(sensor_value, voltage, degrees);
}
}

View file

@ -0,0 +1,40 @@
package org.iot.raspberry.grovepi.devices;
public class GroveRotaryValue {
private final double sensorValue;
private final double voltage;
private final double degrees;
public GroveRotaryValue(double sensorValue, double voltage, double degrees) {
this.sensorValue = sensorValue;
this.voltage = voltage;
this.degrees = degrees;
}
public double getSensorValue() {
return sensorValue;
}
public double getVoltage() {
return voltage;
}
public double getDegrees() {
return degrees;
}
@Override
public String toString() {
return "S:" + sensorValue + ",V:" + voltage + ",D:" + getDegrees();
}
/**
* 0 to 1 factor
*
* @return a number between 0 and 1
*/
public double getFactor() {
return (getDegrees() / GroveRotarySensor.FULL_ANGLE);
}
}

View file

@ -0,0 +1,20 @@
package org.iot.raspberry.grovepi.devices;
import java.io.IOException;
import org.iot.raspberry.grovepi.GroveAnalogPin;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.GroveUtil;
@GroveAnalogPin
public class GroveSoundSensor extends GroveAnalogInputDevice<Double> {
public GroveSoundSensor(GrovePi grovePi, int pin) throws IOException {
super(grovePi.getAnalogIn(pin, 4));
}
@Override
public Double get(byte[] b) {
int[] v = GroveUtil.unsign(b);
return (double) (v[1] * 256) + v[2];
}
}

View file

@ -0,0 +1,50 @@
package org.iot.raspberry.grovepi.devices;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.iot.raspberry.grovepi.GroveDigitalPin;
import org.iot.raspberry.grovepi.GrovePi;
import static org.iot.raspberry.grovepi.GrovePiCommands.*;
@GroveDigitalPin
public class GroveTemperatureAndHumiditySensor {
public enum Type {
DHT11(0), //blue one
DHT22(1), //White one (PRO) AKA (AM2302)
DHT21(2), //Black One AKA (AM2301)
AM2301(3); //White one (PRO)
private final int moduleType;
private Type(int moduleType) {
this.moduleType = moduleType;
}
public int getModuleType() {
return moduleType;
}
}
private final GrovePi grovePi;
private final int pin;
private final Type dhtType;
public GroveTemperatureAndHumiditySensor(GrovePi grovePi, int pin, Type dhtType) {
this.grovePi = grovePi;
this.pin = pin;
this.dhtType = dhtType;
}
public GroveTemperatureAndHumidityValue get() throws IOException {
byte[] data = grovePi.exec((io) -> {
io.write(dht_temp_cmd, pin, dhtType.moduleType, unused);
io.sleep(600);
return io.read(new byte[9]);
});
double temp = ByteBuffer.wrap(new byte[]{data[4], data[3], data[2], data[1]}).getFloat();
double humid = ByteBuffer.wrap(new byte[]{data[8], data[7], data[6], data[5]}).getFloat();
return new GroveTemperatureAndHumidityValue(temp, humid);
}
}

View file

@ -0,0 +1,26 @@
package org.iot.raspberry.grovepi.devices;
public class GroveTemperatureAndHumidityValue {
private final double temperature;
private final double humidity;
public GroveTemperatureAndHumidityValue(double temperature, double humidity) {
this.temperature = temperature;
this.humidity = humidity;
}
public double getTemperature() {
return temperature;
}
public double getHumidity() {
return humidity;
}
@Override
public String toString() {
return "temperature=" + temperature + ", humidity=" + humidity;
}
}

View file

@ -0,0 +1,29 @@
package org.iot.raspberry.grovepi.devices;
import java.io.IOException;
import org.iot.raspberry.grovepi.GroveDigitalPin;
import org.iot.raspberry.grovepi.GrovePi;
import static org.iot.raspberry.grovepi.GrovePiCommands.*;
import org.iot.raspberry.grovepi.GroveUtil;
@GroveDigitalPin
public class GroveUltrasonicRanger {
private final GrovePi grovePi;
private final int pin;
public GroveUltrasonicRanger(GrovePi grovePi, int pin) {
this.grovePi = grovePi;
this.pin = pin;
}
public double get() throws IOException {
return grovePi.exec((io) -> {
io.write(uRead_cmd, pin, unused, unused);
io.sleep(200);
int[] v = GroveUtil.unsign(io.read(new byte[4]));
return (v[1] * 256) + v[2];
});
}
}

202
Software/Java8/LICENSE Normal file
View file

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="ProjectStub" default="default" basedir=".">
<description>Builds, tests, and runs the project ProjectStub.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="ProjectStub-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

View file

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
build.xml.data.CRC32=cc44bce6
build.xml.script.CRC32=01721d6d
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=cc44bce6
nbproject/build-impl.xml.script.CRC32=16e89664
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48

View file

@ -0,0 +1,80 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/ProjectStub.jar
dist.javadoc.dir=${dist.dir}/javadoc
excludes=
file.reference.GrovePi-dio-0.1.0-SNAPSHOT.jar=..\\GrovePi-dio\\target\\GrovePi-dio-0.1.0-SNAPSHOT.jar
file.reference.GrovePi-pi4j-0.1.0-SNAPSHOT.jar=..\\GrovePi-pi4j\\target\\GrovePi-pi4j-0.1.0-SNAPSHOT.jar
file.reference.GrovePi-spec-0.1.0-SNAPSHOT.jar=..\\GrovePi-spec\\target\\GrovePi-spec-0.1.0-SNAPSHOT.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.GrovePi-dio-0.1.0-SNAPSHOT.jar}:\
${file.reference.GrovePi-pi4j-0.1.0-SNAPSHOT.jar}:\
${file.reference.GrovePi-spec-0.1.0-SNAPSHOT.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>ProjectStub</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

View file

@ -0,0 +1,23 @@
package org.iot.stub;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.devices.GroveLed;
import org.iot.raspberry.grovepi.pi4j.GrovePi4J;
public class Main {
public static void main(String[] args) throws Exception {
GrovePi grovePi = new GrovePi4J();
//your stuff here
int pin = 4;
org.iot.raspberry.grovepi.devices.GroveLed led = new GroveLed(grovePi, pin);
led.set(true);
Thread.sleep(1000);
led.set(false);
//end program forcefully
System.exit(0);
}
}

101
Software/Java8/README.md Normal file
View file

@ -0,0 +1,101 @@
# IoTDevices
Grove Pi library
The grovepi for Java8 library is provided as maven projects.
Since you need native access to the raspberry pi device you have 2 choices:
- Use the Pi4J library (third party: http://pi4j.com/)
- Use the DeviceIO library (JDK: http://docs.oracle.com/javame/8.0/api/dio/api/index.html)
You may choose which one to use. If you want to use pi4j then you dont need to add the Device IO libraries. There is no difference in how to use the components, its just a matter of which implementation you want to use to interact with the GPIO ports of the raspberry pi.
## BUILD
run:
mvn install
This creates the .jar files inside the target folder of each of the following projects:
- GrovePi-Spec
- GrovePi-pi4j
- GrovePi-dio
## INCLUDING THE LIBRARIES IN YOUR PROJECTS
Include the GrovePi-Spec jar. This is the core of the library.
Include the implementation you want to use:
- GrovePi-pi4j and the pi4j jar
- Install running in the pi: curl -s get.pi4j.com | sudo bash
- Download the pi4j jar and add it to your project libraries
- GrovePi-dio and the DeviceIO jar
- Install in the pi and add the resulting jar to your project: https://wiki.openjdk.java.net/display/dio/Getting+Started
- To run using DIO remember to add: -Djava.library.path="/home/pi/dio/build/so" -Djava.security.policy="/home/pi/dio/dio.policy" to your Java command
Alternatively: Use maven dependencies:
Mandatory:
<dependency>
<groupId>org.iot.raspberry</groupId>
<artifactId>GrovePi-spec</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
Device Implementation:
<dependency>
<groupId>org.iot.raspberry</groupId>
<artifactId>GrovePi-pi4j</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
OR
<dependency>
<groupId>org.iot.raspberry</groupId>
<artifactId>GrovePi-dio</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
Remember to install pi4j or dio.
## RUNNING THE EXAMPLES
Examples are provided as a simple netbeans project, this is done to facilitate running it using the remote JVM feature: http://blog.weston-fl.com/configure-netbeans-to-test-and-deploy-raspberry-pi-project/
To run the project provide two parameters:
- the implementation: pi4j or dio
- the class to run:
You may build the project and copy the examples.jar, GrovePi-spec.jar, GrovePi-pi4j.jar, GrovePi-dio.jar, ( pi4j.jar and/or deviceIo.jar )
Then run the examples using all the jars as classpath and the main class: org.iot.raspberry.examples.Runner
Ex. java -cp lib/* org.iot.raspberry.examples.Runner pi4j BlinkingLed
All the examples contains instructions on how to connect the devices to the grovepi board.
To stop the examples (for those that run eternally)
- If running directly in the pi enter quit in the console.
- If running remotely using netbeans: run the project again. (first time you run it, starts the project, second time it stops it. (useful since you dont have a console to type to))
## STARTING YOUR OWN PROJECT
If using maven use the dependencies above otherwise add the jars to your project.
Alternatively you may copy all the classes in the GrovePi-Spec project and the deviceIo or Pi4J classes to a new project. (if you want a single jar). Be warned that you still need the pi4j or deviceIO libraries.
## USAGE
Simply create a new instance of the GrovePi class with the implementation you want:
GrovePi grovepi = new GrovePi4J();
OR
GrovePi grovepi = new GrovePiDio();
Then create the connected devices and provide the grovepi you created as parameter in constructors:
GroveTemperatureAndHumiditySensor dht = new GroveTemperatureAndHumiditySensor(grovePi, 4, GroveTemperatureAndHumiditySensor.Type.DHT11)
Or for simple digital in or out use
GroveDigitalOut led = grovePi.getDigitalOut(4);
The number in the parameters is usually the port number you are using.
*NOTE* YOU MUST NOT CREATE MULTIPLE GrovePi objects! use the same for all the devices connected to your board. using multiple may cause collisions in device access.

View file

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="examples" default="default" basedir=".">
<description>Builds, tests, and runs the project examples.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="examples-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

View file

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,8 @@
build.xml.data.CRC32=dc38a7f0
build.xml.script.CRC32=f1113447
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=dc38a7f0
nbproject/build-impl.xml.script.CRC32=e2a7c1a9
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48

View file

@ -0,0 +1,80 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=examples
application.vendor=ed_ze
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/examples.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.GrovePi-pi4j-0.1.0-SNAPSHOT.jar=..\\GrovePi-pi4j\\target\\GrovePi-pi4j-0.1.0-SNAPSHOT.jar
file.reference.GrovePi-spec-0.1.0-SNAPSHOT.jar=..\\GrovePi-spec\\target\\GrovePi-spec-0.1.0-SNAPSHOT.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.GrovePi-spec-0.1.0-SNAPSHOT.jar}:\
${file.reference.GrovePi-pi4j-0.1.0-SNAPSHOT.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.external.vm=true
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=org.iot.raspberry.examples.Runner
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

View file

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>examples</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

View file

@ -0,0 +1,73 @@
package org.iot.raspberry.examples;
import java.io.IOException;
import org.iot.raspberry.grovepi.GroveDigitalOut;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.devices.GroveRelay;
import org.iot.raspberry.grovepi.devices.GroveRgbLcd;
import org.iot.raspberry.grovepi.devices.GroveTemperatureAndHumiditySensor;
import org.iot.raspberry.grovepi.devices.GroveTemperatureAndHumidityValue;
import org.iot.raspberry.grovepi.devices.GroveUltrasonicRanger;
/**
* Connect:
* Digital 3 -> Red led
* Digital 4 -> Green led
* Digital 5 -> blue led
* Digital 6 -> Ultrasonic ranger
* Digital 7 -> TemperatureSensor DHT11
* Digital 8 -> Relay
* Any I2C -> LCD
* @author Eduardo Moranchel <emoranchel@asmatron.org>
*/
public class AutomaticAC implements Example {
@Override
public void run(GrovePi grovePi, Monitor monitor) throws Exception {
GroveDigitalOut redLed = grovePi.getDigitalOut(3);
GroveDigitalOut greenLed = grovePi.getDigitalOut(4);
GroveDigitalOut blueLed = grovePi.getDigitalOut(5);
GroveUltrasonicRanger ranger = new GroveUltrasonicRanger(grovePi, 6);
GroveTemperatureAndHumiditySensor tempSensor = new GroveTemperatureAndHumiditySensor(grovePi, 7, GroveTemperatureAndHumiditySensor.Type.DHT11);
GroveRelay relay = new GroveRelay(grovePi, 8);
GroveRgbLcd lcd = grovePi.getLCD();
while (monitor.isRunning()) {
try {
GroveTemperatureAndHumidityValue dht = tempSensor.get();
double temperature = dht.getTemperature();
double distance = ranger.get();
String message = String.format("TEMP:%.2f\nDistance%.2f", temperature, distance);
System.out.println(message);
lcd.setText(message);
if (temperature > 28) {
if (distance < 50) {
relay.set(true);
} else {
relay.set(false);
}
lcd.setRGB(255, 50, 50);
redLed.set(true);
blueLed.set(false);
greenLed.set(false);
} else if (temperature < 17) {
relay.set(false);
blueLed.set(true);
redLed.set(false);
greenLed.set(false);
lcd.setRGB(50, 50, 255);
} else {
relay.set(false);
blueLed.set(false);
greenLed.set(true);
lcd.setRGB(50, 255, 50);
}
} catch (IOException ioex) {
System.out.println("Error");
}
}
redLed.set(false);
greenLed.set(false);
blueLed.set(false);
relay.set(false);
}
}

View file

@ -0,0 +1,23 @@
package org.iot.raspberry.examples;
import org.iot.raspberry.grovepi.GroveDigitalOut;
import org.iot.raspberry.grovepi.GrovePi;
/*
Connect: Led to D4
*/
public class BlinkingLed implements Example {
@Override
public void run(GrovePi grovePi, Monitor monitor) throws Exception {
GroveDigitalOut led = grovePi.getDigitalOut(2);
boolean state = false;
while (monitor.isRunning()) {
state = !state;
led.set(state);
Thread.sleep(500);
}
led.set(false);
}
}

View file

@ -0,0 +1,25 @@
package org.iot.raspberry.examples;
import org.iot.raspberry.grovepi.GroveDigitalIn;
import org.iot.raspberry.grovepi.GroveDigitalOut;
import org.iot.raspberry.grovepi.GrovePi;
/*
Connect: Led to D4 and Button to D6
*/
public class ButtonLed implements Example {
@Override
public void run(GrovePi grovePi, Monitor monitor) throws Exception {
GroveDigitalIn button = grovePi.getDigitalIn(6);
GroveDigitalOut led = grovePi.getDigitalOut(4);
while (monitor.isRunning()) {
try {
led.set(button.get());
} catch (Exception e) {
}
}
led.set(false);
}
}

View file

@ -0,0 +1,28 @@
package org.iot.raspberry.examples;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.iot.raspberry.grovepi.GroveDigitalIn;
import org.iot.raspberry.grovepi.GrovePi;
/*
Connect: Button to D6
*/
public class ButtonListener implements Example {
@Override
public void run(GrovePi grovePi, Monitor monitor) throws Exception {
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
GroveDigitalIn button = grovePi.getDigitalIn(6);
button.setListener((boolean oldValue, boolean newValue) -> {
System.out.println("Button " + oldValue + "->" + newValue);
});
exec.scheduleAtFixedRate(button, 0, 200, TimeUnit.MILLISECONDS);
monitor.waitForStop();
exec.shutdown();
}
}

View file

@ -0,0 +1,9 @@
package org.iot.raspberry.examples;
import org.iot.raspberry.grovepi.GrovePi;
public interface Example {
public void run(GrovePi grovePi, Monitor monitor) throws Exception;
}

View file

@ -0,0 +1,30 @@
package org.iot.raspberry.examples;
import java.io.IOException;
import org.iot.raspberry.grovepi.GroveDigitalOut;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.devices.GroveLightSensor;
/*
Connect Light sensor to A2
Connect Red Led to D3 (emergency Light)
*/
public class LightSensor implements Example {
@Override
public void run(GrovePi grovePi, Monitor monitor) throws Exception {
GroveLightSensor lightSensor = new GroveLightSensor(grovePi, 2);
GroveDigitalOut emergencyLight = new GroveDigitalOut(grovePi, 3);
while (monitor.isRunning()) {
try {
Double value = lightSensor.get();
emergencyLight.set(value < 250);
System.out.println(value);
} catch (IOException ex) {
System.out.println("error");
}
}
emergencyLight.set(false);
}
}

View file

@ -0,0 +1,23 @@
package org.iot.raspberry.examples;
import java.util.concurrent.Semaphore;
public class Monitor {
private Semaphore semaphore = new Semaphore(0);
private boolean running = true;
public void waitForStop() throws InterruptedException {
semaphore.acquire();
semaphore.release();
}
public void stop() {
running = false;
semaphore.release();
}
public boolean isRunning() {
return running;
}
}

View file

@ -0,0 +1,33 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.iot.raspberry.examples;
import java.io.IOException;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.devices.GroveRelay;
/*
* Connect Relay to D8
*/
public class Relay implements Example {
@Override
public void run(GrovePi grovePi, Monitor monitor) throws Exception {
GroveRelay relay = new GroveRelay(grovePi, 8);
while (monitor.isRunning()) {
try {
relay.set(true);
Thread.sleep(10000);
relay.set(false);
Thread.sleep(5000);
} catch (IOException io) {
System.err.println("error");
}
}
relay.set(false);
}
}

View file

@ -0,0 +1,43 @@
package org.iot.raspberry.examples;
import java.io.IOException;
import java.util.Random;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.devices.GroveRgbLcd;
public class RgbLcd implements Example {
@Override
public void run(GrovePi grovePi, Monitor monitor) throws Exception {
GroveRgbLcd lcd = grovePi.getLCD();
String[] phrases = new String[]{
"Hi! ALL!",
"This should work just fine",
"A message\nA response",
"More data that you can handle for sure!",
"Welcome to the internet of things with java",
"Short\nMessage"
};
int[][] colors = new int[][]{
{50, 255, 30},
{15, 88, 245},
{248, 52, 100},
{48, 56, 190},
{178, 25, 180},
{210, 210, 210}
};
while (monitor.isRunning()) {
try {
String text = phrases[new Random().nextInt(phrases.length)];
int[] color = colors[new Random().nextInt(colors.length)];
lcd.setRGB(color[0], color[1], color[2]);
Thread.sleep(100);
lcd.setText(text);
Thread.sleep(2000);
} catch (IOException io) {
}
}
}
}

View file

@ -0,0 +1,50 @@
package org.iot.raspberry.examples;
import java.io.IOException;
import org.iot.raspberry.grovepi.GroveDigitalOut;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.devices.GroveRotarySensor;
import org.iot.raspberry.grovepi.devices.GroveRotaryValue;
/*
Connect:
RotarySensor to A1
Leds to D3 (red),D4 (green) and D5 (blue)
*/
public class RotarySensor3Led implements Example {
@Override
public void run(GrovePi grovePi, Monitor monitor) throws Exception {
GroveRotarySensor rotarySensor = new GroveRotarySensor(grovePi, 1);
GroveDigitalOut redLed = grovePi.getDigitalOut(3);
GroveDigitalOut greenLed = grovePi.getDigitalOut(4);
GroveDigitalOut blueLed = grovePi.getDigitalOut(5);
GroveDigitalOut onLed = null;
while (monitor.isRunning()) {
try {
GroveRotaryValue value = rotarySensor.get();
System.out.println(value);
GroveDigitalOut ledToTurn;
if (value.getDegrees() > 250) {
ledToTurn = redLed;
} else if (value.getDegrees() < 100) {
ledToTurn = blueLed;
} else {
ledToTurn = greenLed;
}
if (ledToTurn != onLed) {
redLed.set(ledToTurn == redLed);
blueLed.set(ledToTurn == blueLed);
greenLed.set(ledToTurn == greenLed);
onLed = ledToTurn;
}
} catch (IOException ex) {
System.out.println("Error");
}
}
blueLed.set(false);
greenLed.set(false);
redLed.set(false);
}
}

View file

@ -0,0 +1,32 @@
package org.iot.raspberry.examples;
import java.io.IOException;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.devices.GroveLed;
import org.iot.raspberry.grovepi.devices.GroveRotarySensor;
import org.iot.raspberry.grovepi.devices.GroveRotaryValue;
/*
Connect:
RotarySensor to A1
Led D5
*/
public class RotarySensorDimLed implements Example {
@Override
public void run(GrovePi grovePi, Monitor monitor) throws Exception {
GroveRotarySensor rotarySensor = new GroveRotarySensor(grovePi, 1);
GroveLed blueLed = new GroveLed(grovePi, 5);
while (monitor.isRunning()) {
try {
GroveRotaryValue value = rotarySensor.get();
int brightness = (int) (value.getFactor() * GroveLed.MAX_BRIGTHNESS);
blueLed.set(brightness);
} catch (IOException ex) {
System.out.println("Error");
}
}
blueLed.set(false);
}
}

View file

@ -0,0 +1,111 @@
package org.iot.raspberry.examples;
import java.io.File;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.pi4j.GrovePi4J;
public class Runner {
public static void main(String[] args) throws Exception {
Logger.getLogger("GrovePi").setLevel(Level.WARNING);
Logger.getLogger("RaspberryPi").setLevel(Level.WARNING);
File control = new File("RUNNINGSAMPLES");
control.deleteOnExit();
if (control.exists()) {
control.delete();
System.out.println("STOPING CURRENT SAMPLE");
System.exit(0);
}
/*
if (args.length != 2) {
System.err.println("You need to provide 2 arguments DIO|PI4J EXAMPLECLASS");
System.exit(-1);
}
*/
if (args.length != 1) {
System.err.println("You need to provide 1 argument - name of the class");
System.exit(-1);
}
control.createNewFile();
/*
String mode = args[0];
GrovePi grovePi;
switch (mode.toLowerCase()) {
case "pi4j":
grovePi = new GrovePi4J();
break;
case "test":
grovePi = createProxy(GrovePi.class);
break;
default:
throw new IllegalArgumentException("You must provide either DIO or PI4J implementation");
}
*/
GrovePi grovePi = new GrovePi4J();
Example example = (Example) Class.forName("org.iot.raspberry.examples." + args[0]).newInstance();
System.out.println("RUNNING EXAMPLE: " + args[0] + " USING: PI4J");
final ExecutorService runner = Executors.newSingleThreadExecutor();
final ExecutorService consoleMonitor = Executors.newSingleThreadExecutor();
final ExecutorService fileMonitor = Executors.newSingleThreadExecutor();
final Semaphore lock = new Semaphore(0);
final Monitor monitor = new Monitor();
runner.execute(() -> {
try {
example.run(grovePi, monitor);
} catch (Exception ex) {
Logger.getLogger(Runner.class.getName()).log(Level.SEVERE, null, ex);
}
lock.release();
});
consoleMonitor.execute(() -> {
try (Scanner scanner = new Scanner(System.in)) {
String command;
while (!(command = scanner.next()).equalsIgnoreCase("quit")) {
System.out.println("Command " + command + " not recognized, try quit");
}
}
monitor.stop();
lock.release();
});
fileMonitor.execute(() -> {
while (control.exists()) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
}
monitor.stop();
lock.release();
});
lock.acquire();
runner.shutdown();
consoleMonitor.shutdownNow();
fileMonitor.shutdownNow();
runner.awaitTermination(10, TimeUnit.SECONDS);
control.delete();
System.exit(0);
}
private static <T> T createProxy(Class<T> aClass) {
return (T) Proxy.newProxyInstance(aClass.getClassLoader(), new Class<?>[]{aClass}, (Object proxy, Method method, Object[] args1) -> {
throw new RuntimeException("Test class methods not allowed");
});
}
}

View file

@ -0,0 +1,14 @@
package org.iot.raspberry.examples;
import org.iot.raspberry.grovepi.GrovePi;
public class RunnerTest implements Example {
@Override
public void run(GrovePi grovePi, Monitor monitor) throws Exception {
while (monitor.isRunning()) {
Thread.sleep(1000);
System.out.println("Running...");
}
}
}

View file

@ -0,0 +1,49 @@
package org.iot.raspberry.examples;
import java.io.IOException;
import org.iot.raspberry.grovepi.GroveDigitalOut;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.devices.GroveSoundSensor;
/*
Connect:
SoundSensor to A0
Leds to D3 (red),D4 (green) and D5 (blue)
*/
public class SoundSensor implements Example {
@Override
public void run(GrovePi grovePi, Monitor monitor) throws Exception {
GroveSoundSensor soundSensor = new GroveSoundSensor(grovePi, 0);
GroveDigitalOut redLed = grovePi.getDigitalOut(3);
GroveDigitalOut greenLed = grovePi.getDigitalOut(4);
GroveDigitalOut blueLed = grovePi.getDigitalOut(5);
GroveDigitalOut onLed = null;
while (monitor.isRunning()) {
try {
double soundLevel = soundSensor.get();
System.out.println(soundLevel);
GroveDigitalOut ledToTurn;
if (soundLevel > 1000) {
ledToTurn = redLed;
} else if (soundLevel < 300) {
ledToTurn = blueLed;
} else {
ledToTurn = greenLed;
}
if (ledToTurn != onLed) {
redLed.set(ledToTurn == redLed);
blueLed.set(ledToTurn == blueLed);
greenLed.set(ledToTurn == greenLed);
onLed = ledToTurn;
}
} catch (IOException ex) {
System.out.println("Error");
}
}
blueLed.set(false);
greenLed.set(false);
redLed.set(false);
}
}

View file

@ -0,0 +1,22 @@
package org.iot.raspberry.examples;
import java.io.IOException;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.devices.GroveTemperatureAndHumiditySensor;
/*
Connect Temp & Humidity sensor to D4
*/
public class TemperatureAndHumidity implements Example {
@Override
public void run(GrovePi grovePi, Monitor monitor) throws Exception {
GroveTemperatureAndHumiditySensor dht = new GroveTemperatureAndHumiditySensor(grovePi, 4, GroveTemperatureAndHumiditySensor.Type.DHT11);
while (monitor.isRunning()) {
try {
System.out.println(dht.get());
} catch (IOException ex) {
}
}
}
}

View file

@ -0,0 +1,30 @@
package org.iot.raspberry.examples;
import java.io.IOException;
import org.iot.raspberry.grovepi.GroveDigitalOut;
import org.iot.raspberry.grovepi.GrovePi;
import org.iot.raspberry.grovepi.devices.GroveUltrasonicRanger;
/*
Connect ultrasonic ranger to port D6
buzzer to D7
*/
public class UltrasonicRanger implements Example {
@Override
public void run(GrovePi grovePi, Monitor monitor) throws Exception {
GroveUltrasonicRanger ranger = new GroveUltrasonicRanger(grovePi, 6);
GroveDigitalOut buzzer = grovePi.getDigitalOut(7);
while (monitor.isRunning()) {
try {
double distance = ranger.get();
System.out.println(distance);
buzzer.set(distance < 20);
} catch (IOException ex) {
System.out.println("error!");
}
}
}
}

16
Software/Java8/pom.xml Normal file
View file

@ -0,0 +1,16 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.iot.raspberry</groupId>
<artifactId>GrovePi</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>GrovePi-spec</module>
<module>GrovePi-pi4j</module>
</modules>
</project>

View file

@ -0,0 +1,139 @@
===== SSH Static IP connection.
+ Enable SSH access in the pi (usually on by default)
+ Set up Ethernet _static IP_ (connect to your local network)
PC <-> Rpi You know both IP addresses.
PC connects to the pi using PUTTY with the static IP.
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.127.1
netmask 255.255.255.0
+ Add "useDNS no" to the /etc/ssh/sshd_config file fixes slow login attempts.
Restart interfaces!
sudo service networking restart
====== WIFI =====
To configure wireless open the file
/etc/wpa_supplicant/wpa_supplicant.conf
file and add the settings for your network.
sudo ifdown wlan0
sudo ifup wlan0
Set up wireless
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="Aperture.Guests"
psk="123123123"
}
set default internet
iface default inet dhcp
===== /etc/network/interfaces =====
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.127.1
netmask 255.255.255.0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
===== SET UP DHCP SERVER ON THE PI
Putty to the pi and
sudo apt-get update
sudo apt-get install dnsmasq
cd /etc
sudo mv dnsmasq.conf dnsmasq.default
sudo nano dnsmasq.conf
interface=eth0
dhcp-range=192.168.127.11,192.168.127.254,255.255.255.0,12h
sudo service dnsmasq restart
MORE STUFF::
http://www.glennklockwood.com/sa/rpi-wifi-bridge.php
==== Enable I2C and install i2c utilities ====
==== JAVA SETUP ====
Download the JDK8 for ARM processors, install on the pi
Download the DeviceIO and install on the pi
DIO POLICY GPIO+i2C
grant {
permission jdk.dio.gpio.GPIOPinPermission "*:*";
permission jdk.dio.DeviceMgmtPermission "*:*", "open";
permission jdk.dio.i2cbus.I2CPermission "*:*";
};
==== GrovePi and python ====
CREATE BACKUP IMG
https://www.raspberrypi.org/forums/viewtopic.php?f=26&t=5947&start=25
http://www.richardsramblings.com/2013/02/minimalist-raspberry-pi-server-image/
Free Space
df -B1
Minimalist image::
Remove the GUI Modules
sudo apt-get purge xserver.* x11.* xarchiver xauth xkb-data console-setup xinit lightdm lxde.* python-tk python3-tk scratch gtk.* libgtk.* openbox libxt.* lxpanel gnome.* libqt.* libxcb.* libxfont.* lxmenu.* gvfs.* xdg-.* desktop.* tcl.* shared-mime-info penguinspuzzle omxplayer gsfonts
sudo apt-get --yes autoremove
sudo apt-get upgrade
Disable Memory Swapping
sudo swapoff -a
sudo rm /var/swap
Prepare for Final Imaging
sudo rm -f /var/cache/apt/*cache.bin
sudo apt-get --yes autoclean
sudo apt-get --yes clean
sudo find / -type f -name "*-old" |xargs sudo rm -rf
sudo rm -rf /var/backups/* /var/lib/apt/lists/* ~/.bash_history
find /var/log/ -type f |xargs sudo rm -rf
sudo cp /dev/null /etc/resolv.conf
dd if=/dev/mmcblk0 of=/home/YOUR_USERNAME/Desktop/backup.img bs=1M count=2048