first commit
This commit is contained in:
commit
a5a0434432
1126 changed files with 439481 additions and 0 deletions
31
Software/Java8/GrovePi-pi4j/.classpath
Normal file
31
Software/Java8/GrovePi-pi4j/.classpath
Normal 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>
|
||||
23
Software/Java8/GrovePi-pi4j/.project
Normal file
23
Software/Java8/GrovePi-pi4j/.project
Normal 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>
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
26
Software/Java8/GrovePi-pi4j/pom.xml
Normal file
26
Software/Java8/GrovePi-pi4j/pom.xml
Normal 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>
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue