Skip to content

Commit

Permalink
Added GrovePi support\
Browse files Browse the repository at this point in the history
Signed-off-by: nicolatimeus <[email protected]>
  • Loading branch information
nicolatimeus committed Apr 7, 2017
1 parent 1bb3b44 commit 13e1bea
Show file tree
Hide file tree
Showing 151 changed files with 6,462 additions and 175 deletions.
14 changes: 14 additions & 0 deletions grovepi-libs/.gitignore
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions grovepi-libs/.project
Original file line number Diff line number Diff line change
@@ -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>
4 changes: 4 additions & 0 deletions grovepi-libs/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
31 changes: 31 additions & 0 deletions grovepi-libs/GrovePi-dio/.classpath
Original file line number Diff line number Diff line change
@@ -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 changes: 23 additions & 0 deletions grovepi-libs/GrovePi-dio/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>GrovePi-dio</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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8
5 changes: 5 additions & 0 deletions grovepi-libs/GrovePi-dio/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions grovepi-libs/GrovePi-dio/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
34 changes: 34 additions & 0 deletions grovepi-libs/GrovePi-dio/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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-dio</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>
<repositories>
<repository>
<id>kura-addons</id>
<name>Kura Addons</name>
<url>https://raw.github.com/eurotech/kura_addons/mvn-repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.iot.raspberry</groupId>
<artifactId>GrovePi-spec</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>jdk</groupId>
<artifactId>jdk.dio</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.iot.raspberry.grovepi.dio;

import java.io.IOException;
import jdk.dio.DeviceManager;
import jdk.dio.i2cbus.I2CDevice;
import jdk.dio.i2cbus.I2CDeviceConfig;
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 Device I/O
*
* @author Eduardo Moranchel <[email protected]>
*/
public class GrovePiDio implements GrovePi {

private final I2CDevice device;

public GrovePiDio() throws IOException {
final int i2cBus = 1; // Raspberry Pi's I2C bus
final int address = 0x04; // Device address
final int serialClock = 3400000; // 3.4MHz Max clock
final int addressSizeBits = 7; // Device address size in bits

I2CDeviceConfig config = new I2CDeviceConfig(i2cBus, address, addressSizeBits, serialClock);
device = DeviceManager.open(config);

}

@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() {
if (device != null) {
try {
device.close();
} catch (Exception e) {
// ignore for now
}
}
}

@Override
public GroveRgbLcd getLCD() throws IOException {
return new GroveRgbLcdDIO();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.iot.raspberry.grovepi.dio;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import jdk.dio.DeviceManager;
import jdk.dio.i2cbus.I2CDevice;
import jdk.dio.i2cbus.I2CDeviceConfig;
import org.iot.raspberry.grovepi.GrovePiSequenceVoid;
import org.iot.raspberry.grovepi.devices.GroveRgbLcd;

public class GroveRgbLcdDIO extends GroveRgbLcd {

private final I2CDevice rgb;
private final I2CDevice text;

public GroveRgbLcdDIO() throws IOException {
final int i2cBus = 1; // Raspberry Pi's I2C bus
final int serialClock = 3400000; // 3.4MHz Max clock
final int addressSizeBits = 7; // Device address size in bits

this.text = DeviceManager.open(new I2CDeviceConfig(i2cBus, DISPLAY_TEXT_ADDR, addressSizeBits, serialClock));

this.rgb = DeviceManager.open(new I2CDeviceConfig(i2cBus, DISPLAY_RGB_ADDR, addressSizeBits, serialClock));

init();
}

@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));
}
}

@Override
public void close() {
try {
rgb.close();
} catch (IOException ex) {
Logger.getLogger("GrovePi").log(Level.SEVERE, null, ex);
}
try {
text.close();
} catch (IOException ex) {
Logger.getLogger("GrovePi").log(Level.SEVERE, null, ex);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.iot.raspberry.grovepi.dio;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import jdk.dio.i2cbus.I2CDevice;
import org.iot.raspberry.grovepi.GroveIO;

public class IO implements GroveIO {

private final I2CDevice device;

public IO(I2CDevice device) {
this.device = device;
}

// IO
@Override
public void write(int... cmd) throws IOException {
ByteBuffer command = ByteBuffer.allocateDirect(cmd.length);
Arrays.stream(cmd).forEach((c) -> command.put((byte) c));
command.rewind();
Logger.getLogger("GrovePi").log(Level.INFO, "[DIO IO write]{0}", Arrays.toString(cmd));
device.write(command);
}

@Override
public int read() throws IOException {
final int read = device.read();
Logger.getLogger("GrovePi").log(Level.INFO, "[DIO IO read]{0}", read);
return read;
}

@Override
public byte[] read(byte[] buffer) throws IOException {
ByteBuffer bf = ByteBuffer.wrap(buffer);
bf.rewind();
device.read(bf);
Logger.getLogger("GrovePi").log(Level.INFO, "[DIO IO read]{0}", buffer);
return buffer;
}

}
31 changes: 31 additions & 0 deletions grovepi-libs/GrovePi-pi4j/.classpath
Original file line number Diff line number Diff line change
@@ -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 changes: 23 additions & 0 deletions grovepi-libs/GrovePi-pi4j/.project
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
Loading

0 comments on commit 13e1bea

Please sign in to comment.