Added an Ant build file and a small SPI test
authorTomas Wenström <tomas.wenstrom@gmail.com>
Sat, 22 Apr 2017 15:34:42 +0000 (17:34 +0200)
committerTomas Wenström <tomas.wenstrom@gmail.com>
Sat, 22 Apr 2017 15:34:42 +0000 (17:34 +0200)
build.xml [new file with mode: 0644]
config.properties
src/kaka/cakelight/CakeLight.java
src/kaka/cakelight/GuiTest.java
src/kaka/cakelight/LedController.java
src/kaka/cakelight/Main.java

diff --git a/build.xml b/build.xml
new file mode 100644 (file)
index 0000000..a0d21ec
--- /dev/null
+++ b/build.xml
@@ -0,0 +1,207 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="cakelight" default="all">
+  
+  
+  <property file="config.properties"/>
+  <property name="jdk.home.1.8" value="/usr/lib/jvm/java-8-openjdk-amd64" />
+  <!-- Uncomment the following property if no tests compilation is needed -->
+  <!-- 
+  <property name="skip.tests" value="true"/>
+   -->
+  
+  <!-- Compiler options -->
+  
+  <property name="compiler.debug" value="on"/>
+  <property name="compiler.generate.no.warnings" value="off"/>
+  <property name="compiler.args" value=""/>
+  <property name="compiler.max.memory" value="700m"/>
+  <patternset id="ignored.files">
+    <exclude name="**/*.hprof/**"/>
+    <exclude name="**/*.pyc/**"/>
+    <exclude name="**/*.pyo/**"/>
+    <exclude name="**/*.rbc/**"/>
+    <exclude name="**/*.yarb/**"/>
+    <exclude name="**/*~/**"/>
+    <exclude name="**/.DS_Store/**"/>
+    <exclude name="**/.git/**"/>
+    <exclude name="**/.hg/**"/>
+    <exclude name="**/.svn/**"/>
+    <exclude name="**/CVS/**"/>
+    <exclude name="**/__pycache__/**"/>
+    <exclude name="**/_svn/**"/>
+    <exclude name="**/vssver.scc/**"/>
+    <exclude name="**/vssver2.scc/**"/>
+  </patternset>
+  <patternset id="library.patterns">
+    <include name="*.war"/>
+    <include name="*.swc"/>
+    <include name="*.zip"/>
+    <include name="*.egg"/>
+    <include name="*.ane"/>
+    <include name="*.jar"/>
+    <include name="*.ear"/>
+  </patternset>
+  <patternset id="compiler.resources">
+    <exclude name="**/?*.java"/>
+    <exclude name="**/?*.form"/>
+    <exclude name="**/?*.class"/>
+    <exclude name="**/?*.groovy"/>
+    <exclude name="**/?*.scala"/>
+    <exclude name="**/?*.flex"/>
+    <exclude name="**/?*.kt"/>
+    <exclude name="**/?*.clj"/>
+    <exclude name="**/?*.aj"/>
+  </patternset>
+  
+  <!-- JDK definitions -->
+  
+  <property name="jdk.bin.1.8" value="${jdk.home.1.8}/bin"/>
+  <path id="jdk.classpath.1.8">
+    <fileset dir="${jdk.home.1.8}">
+      <include name="jre/lib/charsets.jar"/>
+      <include name="jre/lib/ext/cldrdata.jar"/>
+      <include name="jre/lib/ext/dnsns.jar"/>
+      <include name="jre/lib/ext/icedtea-sound.jar"/>
+      <include name="jre/lib/ext/jaccess.jar"/>
+      <include name="jre/lib/ext/localedata.jar"/>
+      <include name="jre/lib/ext/nashorn.jar"/>
+      <include name="jre/lib/ext/sunec.jar"/>
+      <include name="jre/lib/ext/sunjce_provider.jar"/>
+      <include name="jre/lib/ext/sunpkcs11.jar"/>
+      <include name="jre/lib/ext/zipfs.jar"/>
+      <include name="jre/lib/jce.jar"/>
+      <include name="jre/lib/jsse.jar"/>
+      <include name="jre/lib/management-agent.jar"/>
+      <include name="jre/lib/resources.jar"/>
+      <include name="jre/lib/rt.jar"/>
+      <include name="jre/lib/ext/jfxrt.jar"/>
+    </fileset>
+  </path>
+  
+  <property name="project.jdk.home" value="${jdk.home.1.8}"/>
+  <property name="project.jdk.bin" value="${jdk.bin.1.8}"/>
+  <property name="project.jdk.classpath" value="jdk.classpath.1.8"/>
+  
+  
+  <!-- Project Libraries -->
+  
+  <path id="library.opencv.classpath">
+    <pathelement location="/usr/share/java/opencv.jar"/>
+  </path>
+  
+  <path id="library.pi4j.classpath">
+    <fileset dir="${basedir}/lib/pi4j">
+      <patternset refid="library.patterns"/>
+    </fileset>
+  </path>
+  
+  <!-- Modules -->
+  
+  
+  <!-- Module CakeLight -->
+  
+  <dirname property="module.cakelight.basedir" file="${ant.file}"/>
+  
+  
+  <property name="module.jdk.home.cakelight" value="${project.jdk.home}"/>
+  <property name="module.jdk.bin.cakelight" value="${project.jdk.bin}"/>
+  <property name="module.jdk.classpath.cakelight" value="${project.jdk.classpath}"/>
+  
+  <property name="compiler.args.cakelight" value="-encoding UTF-8 -source 8 -target 8 ${compiler.args}"/>
+  
+  <property name="cakelight.output.dir" value="${module.cakelight.basedir}/out/production/CakeLight"/>
+  <property name="cakelight.testoutput.dir" value="${module.cakelight.basedir}/out/test/CakeLight"/>
+  
+  <path id="cakelight.module.bootclasspath">
+    <!-- Paths to be included in compilation bootclasspath -->
+  </path>
+  
+  <path id="cakelight.module.production.classpath">
+    <path refid="${module.jdk.classpath.cakelight}"/>
+    <path refid="library.opencv.classpath"/>
+    <path refid="library.pi4j.classpath"/>
+  </path>
+  
+  <path id="cakelight.runtime.production.module.classpath">
+    <pathelement location="${cakelight.output.dir}"/>
+    <path refid="library.opencv.classpath"/>
+    <path refid="library.pi4j.classpath"/>
+  </path>
+  
+  <path id="cakelight.module.classpath">
+    <path refid="${module.jdk.classpath.cakelight}"/>
+    <pathelement location="${cakelight.output.dir}"/>
+    <path refid="library.opencv.classpath"/>
+    <path refid="library.pi4j.classpath"/>
+  </path>
+  
+  <path id="cakelight.runtime.module.classpath">
+    <pathelement location="${cakelight.testoutput.dir}"/>
+    <pathelement location="${cakelight.output.dir}"/>
+    <path refid="library.opencv.classpath"/>
+    <path refid="library.pi4j.classpath"/>
+  </path>
+  
+  
+  <patternset id="excluded.from.module.cakelight">
+    <patternset refid="ignored.files"/>
+  </patternset>
+  
+  <patternset id="excluded.from.compilation.cakelight">
+    <patternset refid="excluded.from.module.cakelight"/>
+  </patternset>
+  
+  <path id="cakelight.module.sourcepath">
+    <dirset dir="${module.cakelight.basedir}">
+      <include name="src"/>
+    </dirset>
+  </path>
+  
+  
+  <target name="compile.module.cakelight" depends="compile.module.cakelight.production,compile.module.cakelight.tests" description="Compile module CakeLight"/>
+  
+  <target name="compile.module.cakelight.production" description="Compile module CakeLight; production classes">
+    <mkdir dir="${cakelight.output.dir}"/>
+    <javac destdir="${cakelight.output.dir}" debug="${compiler.debug}" nowarn="${compiler.generate.no.warnings}" memorymaximumsize="${compiler.max.memory}" fork="true" executable="${module.jdk.bin.cakelight}/javac">
+      <compilerarg line="${compiler.args.cakelight}"/>
+      <bootclasspath refid="cakelight.module.bootclasspath"/>
+      <classpath refid="cakelight.module.production.classpath"/>
+      <src refid="cakelight.module.sourcepath"/>
+      <patternset refid="excluded.from.compilation.cakelight"/>
+    </javac>
+    
+    <copy todir="${cakelight.output.dir}">
+      <fileset dir="${module.cakelight.basedir}/src">
+        <patternset refid="compiler.resources"/>
+        <type type="file"/>
+      </fileset>
+    </copy>
+
+    <jar destfile="${cakelight.output.dir}/cakelight.jar">
+      <fileset dir="${cakelight.output.dir}" />
+      <!-- TODO replace hard links -->
+      <zipfileset includes="**/*.class" src="${module.cakelight.basedir}/lib/pi4j/pi4j-core.jar" />
+      <zipfileset includes="**/*.class" src="/usr/share/java/opencv.jar" />
+      <manifest>
+        <attribute name="Main-Class" value="kaka.cakelight.LedController" />
+      </manifest>
+    </jar>
+  </target>
+  
+  <target name="compile.module.cakelight.tests" depends="compile.module.cakelight.production" description="compile module CakeLight; test classes" unless="skip.tests"/>
+  
+  <target name="clean.module.cakelight" description="cleanup module">
+    <delete dir="${cakelight.output.dir}"/>
+    <delete dir="${cakelight.testoutput.dir}"/>
+  </target>
+  
+  <target name="init" description="Build initialization">
+    <!-- Perform any build initialization in this target -->
+  </target>
+  
+  <target name="clean" depends="clean.module.cakelight" description="cleanup all"/>
+  
+  <target name="build.modules" depends="init, clean, compile.module.cakelight" description="build all modules"/>
+  
+  <target name="all" depends="build.modules" description="build all"/>
+</project>
\ No newline at end of file
index df7ee04..2e2934d 100644 (file)
@@ -1,3 +1,5 @@
+jdk.home.1.8=/usr/lib/jvm/java-8-openjdk-amd64
+
 # Video info can be found with 'v4l2-ctl --get-fmt-video'
 # Supported formats: UYVY, YUYV, YVYU
 video.format=UYVY
index 5401c0f..9b32c02 100644 (file)
@@ -5,9 +5,9 @@ public class CakeLight {
     private Mode mode;
     private LedController ledController;
 
-    public CakeLight(Configuration config, LedController ledController) {
+    public CakeLight(Configuration config) {
         this.config = config;
-        this.ledController = ledController;
+        this.ledController = new LedController(config);
     }
 
     public void setMode(Mode mode) {
index 6dbb5ff..b73d37f 100644 (file)
@@ -56,12 +56,7 @@ public class GuiTest extends Application {
 
     private void setupCakeLight() {
         log("Running with config:\n" + config);
-        cakelight = new CakeLight(config, new LedController() {
-            @Override
-            public void onFrame(LedFrame ledFrame) {
-                if (!paused) drawLEDs(canvas.getGraphicsContext2D(), ledFrame);
-            }
-        });
+        cakelight = new CakeLight(config);
         VideoMode mode = new VideoMode();
         cakelight.setMode(mode);
         cakelight.startLoop();
index 201644d..9a23331 100644 (file)
@@ -1,6 +1,29 @@
 package kaka.cakelight;
 
+import com.pi4j.io.spi.SpiChannel;
+import com.pi4j.io.spi.SpiDevice;
+import com.pi4j.io.spi.SpiFactory;
+
+import java.io.IOException;
+
 public class LedController {
+    public static void main(String args[]) {
+        new LedController(null);
+    }
+
+    public LedController(Configuration config) {
+        try {
+            SpiDevice spi = SpiFactory.getInstance(SpiChannel.CS0);
+            spi.write(
+                    (byte)0xff, (byte)0x0, (byte)0x0,
+                    (byte)0x00, (byte)0xff, (byte)0x0,
+                    (byte)0x0, (byte)0x00, (byte)0xff
+            );
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
     public void onFrame(LedFrame ledFrame) {
        // TODO
     }
index e071fec..9786aac 100644 (file)
@@ -13,7 +13,7 @@ public class Main {
        Configuration config = Configuration.from("config.properties");
        log("Running with config:\n" + config);
 
-       CakeLight cakelight = new CakeLight(config, new LedController());
+       CakeLight cakelight = new CakeLight(config);
        cakelight.setMode(new VideoMode());
        cakelight.startLoop();
 //     try {